Skip to main content

WorldLifecycleManager.ixx File

Manager for deferred world-level lifecycle operations. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacelifecycle

Lifecycle management for entity components and world-level operations. More...

Classes Index

classWorldLifecycleManager

Manager that processes deferred world lifecycle commands. More...

Description

Manager for deferred world-level lifecycle operations.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file WorldLifecycleManager.ixx
3 * @brief Manager for deferred world-level lifecycle operations.
4 */
5module;
6
7#include <vector>
8
9export module helios.engine.mechanics.lifecycle.WorldLifecycleManager;
10
11import helios.engine.runtime.world.GameWorld;
12import helios.engine.runtime.world.UpdateContext;
13
14import helios.engine.mechanics.lifecycle.types;
15import helios.engine.mechanics.lifecycle.commands.WorldLifecycleCommand;
16import helios.engine.common;
17
22
24
25 /**
26 * @brief Manager that processes deferred world lifecycle commands.
27 *
28 * @details WorldLifecycleManager collects WorldLifecycleCommands via
29 * submit() and executes them during flush(). This allows systems to
30 * request world-level operations (e.g. reset) through the command
31 * pipeline instead of calling GameWorld methods directly.
32 *
33 * On Reset, the pending queue is moved to a local variable before
34 * processing. This prevents re-entrant issues since GameWorld::reset()
35 * calls Manager::reset() on all managers, including this one.
36 *
37 * @see WorldLifecycleCommand
38 * @see WorldLifecycleAction
39 * @see GameWorld::reset
40 */
42
43 /**
44 * @brief Pending commands queued for the next flush.
45 */
46 std::vector<WorldLifecycleCommand> pending_;
47
48 /**
49 * @brief Cached pointer to the GameWorld, set during init().
50 */
51 GameWorld* gameWorld_ = nullptr;
52
53 public:
54
56
57 /**
58 * @brief Enqueues a lifecycle command for deferred processing.
59 *
60 * @param cmd The command to enqueue.
61 *
62 * @return True if the command was accepted.
63 */
64 bool submit(WorldLifecycleCommand cmd) noexcept {
65 pending_.push_back(cmd);
66 return true;
67 }
68
69 /**
70 * @brief Registers this manager as the WorldLifecycleCommand handler.
71 *
72 * @param gameWorld The GameWorld to register with.
73 */
74 void init(GameWorld& gameWorld) {
75 gameWorld_ = &gameWorld;
77 }
78
79 /**
80 * @brief Processes all pending lifecycle commands.
81 *
82 * @details Moves the pending queue to a local variable before
83 * iterating. This is necessary because a Reset action triggers
84 * GameWorld::reset(), which in turn calls reset() on this manager,
85 * clearing pending_.
86 *
87 * @param updateContext The current frame's update context.
88 */
89 void flush(UpdateContext& updateContext) noexcept {
90 if (pending_.empty() || gameWorld_ == nullptr) {
91 return;
92 }
93
94 std::vector<WorldLifecycleCommand> queue = std::move(pending_);
95 pending_.clear();
96
97 for (const auto& cmd : queue) {
98 switch (cmd.action()) {
100 gameWorld_->reset();
101 // reset complete, do not process further commands.
102 return;
103 }
104 }
105
106 }
107
108 /**
109 * @brief Clears all pending commands.
110 */
111 void reset() {
112 pending_.clear();
113 }
114 };
115
116}
117

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.