Skip to main content

EntityMutationManager Class Template

Receives submitted ECS mutation commands and applies them during flush. More...

Declaration

template <typename TEntityManager> class helios::engine::runtime::world::EntityMutationManager<TEntityManager> { ... }

Public Member Typedefs Index

template <typename TEntityManager>
usingHandle_type = THandle

The entity handle type this manager operates on. More...

template <typename TEntityManager>
usingEngineRoleTag = ManagerRole

Role tag identifying this as a manager in the engine registry. More...

Private Member Typedefs Index

template <typename TEntityManager>
usingTHandle = typename TEntityManager::Handle_type

Shorthand for the entity handle type derived from TEntityManager. More...

Public Constructors Index

template <typename TEntityManager>
EntityMutationManager (TEntityManager &entity_manager, JobSystem &jobSystem)

Constructs the manager bound to entityManager and jobSystem. More...

Public Member Functions Index

template <typename TCommand>
boolsubmit (TCommand &&command)

Accepts a command from the CommandHandlerRegistry and enqueues it. More...

template <typename TEntityManager>
voidinit (CommandHandlerRegistry &commandHandlerRegistry)

Initialises the manager. Currently a no-op. More...

template <typename TEntityManager>
voidflush (UpdateContext &updateContext)

Flushes all internal buffers sequentially, applying every queued mutation. More...

template <typename TEntityManager>
voidflushParallel (UpdateContext &updateContext)

Flushes independent buffer groups concurrently via the JobSystem. More...

Private Member Functions Index

template <typename TCommand>
auto *modelFor ()

Returns (or lazily creates) the InternalBuffer for TCommand. More...

Private Member Attributes Index

template <typename TEntityManager>
TEntityManager &entityManager_

Reference to the entity manager mutations are applied to. More...

template <typename TEntityManager>
CommandBufferRegistrycommandBufferRegistry_ {}

Registry of lazily created per-command-type InternalBuffer instances. More...

template <typename TEntityManager>
CommandHandlerRegistry *commandHandlerRegistry_ {nullptr}

Unused; retained for interface uniformity. More...

template <typename TEntityManager>
JobSystem &jobSystem_

Job system used by flushParallel() for concurrent buffer execution. More...

template <typename TEntityManager>
std::vector< std::vector< CommandBufferTypeId > >componentToBufferGroups_ {}

Maps component type IDs to the CommandBufferTypeIds of their associated buffers. More...

template <typename TEntityManager>
std::vector< std::size_t >bufferGroupIndices_

Ordered list of component type IDs that have at least one registered buffer. More...

Private Static Attributes Index

template <typename TEntityManager>
static auto &logger_ = helios::engine::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Module-scoped logger. More...

Description

Receives submitted ECS mutation commands and applies them during flush.

Acts as the write-back stage for EntityMutationCommandBuffer: commands queued there are routed here via the CommandHandlerRegistry and buffered per command type. On flush() each command is resolved against the live UpdateContext and executed (add/remove component, activate/deactivate entity).

Template Parameters
TEntityManager

Entity manager type identifying the target ECS registry.

Definition at line 68 of file EntityMutationManager.ixx.

Public Member Typedefs

EngineRoleTag

template <typename TEntityManager>
using helios::engine::runtime::world::EntityMutationManager< TEntityManager >::EngineRoleTag = ManagerRole

Role tag identifying this as a manager in the engine registry.

Definition at line 225 of file EntityMutationManager.ixx.

Handle_type

template <typename TEntityManager>
using helios::engine::runtime::world::EntityMutationManager< TEntityManager >::Handle_type = THandle

The entity handle type this manager operates on.

Definition at line 222 of file EntityMutationManager.ixx.

222 using Handle_type = THandle;

Private Member Typedefs

THandle

template <typename TEntityManager>
using helios::engine::runtime::world::EntityMutationManager< TEntityManager >::THandle = typename TEntityManager::Handle_type

Shorthand for the entity handle type derived from TEntityManager.

Definition at line 71 of file EntityMutationManager.ixx.

71 using THandle = typename TEntityManager::Handle_type;

Public Constructors

EntityMutationManager()

template <typename TEntityManager>
helios::engine::runtime::world::EntityMutationManager< TEntityManager >::EntityMutationManager (TEntityManager & entity_manager, JobSystem & jobSystem)
inline explicit

Constructs the manager bound to entityManager and jobSystem.

Parameters
entity_manager

Entity manager mutations are applied to.

jobSystem

Job system used for parallel flush execution.

Definition at line 233 of file EntityMutationManager.ixx.

234 : entityManager_(entity_manager), jobSystem_(jobSystem) {}

Public Member Functions

flush()

template <typename TEntityManager>
void helios::engine::runtime::world::EntityMutationManager< TEntityManager >::flush (UpdateContext & updateContext)
inline

Flushes all internal buffers sequentially, applying every queued mutation.

Parameters
updateContext

Frame-local ECS context forwarded to each buffer's flush.

Definition at line 306 of file EntityMutationManager.ixx.

307 for (auto* buffer : commandBufferRegistry_.items()) {
308 buffer->flush(updateContext);
309 }
310
311 }

Reference helios::engine::runtime::registerComponents.

flushParallel()

template <typename TEntityManager>
void helios::engine::runtime::world::EntityMutationManager< TEntityManager >::flushParallel (UpdateContext & updateContext)
inline

Flushes independent buffer groups concurrently via the JobSystem.

Each component-type group is dispatched as a separate job; groups that operate on different component types are assumed to be executable in parallel without contention.

Parameters
updateContext

Frame-local ECS context forwarded to each buffer's flush.

Definition at line 321 of file EntityMutationManager.ixx.

322
323 std::vector<std::size_t> activeIndices;
324 for (const auto idx : bufferGroupIndices_) {
325 if (!componentToBufferGroups_[idx].empty()) {
326 activeIndices.push_back(idx);
327 }
328 }
329 jobSystem_.runAndWait(activeIndices.size(), [&](const std::size_t groupIndex) {
330 for (const auto bufferTypeId : componentToBufferGroups_[activeIndices[groupIndex]]) {
331 logger_.info("Processing MutationCommandBuffer {0}", bufferTypeId.value());
332 auto* buffer = commandBufferRegistry_.item(bufferTypeId);
333 buffer->flush(updateContext);
334 }
335 });
336 }

References helios::engine::runtime::registerComponents and helios::engine::core::thread::JobSystem::runAndWait.

init()

template <typename TEntityManager>
void helios::engine::runtime::world::EntityMutationManager< TEntityManager >::init (CommandHandlerRegistry & commandHandlerRegistry)
inline

Initialises the manager. Currently a no-op.

Parameters
commandHandlerRegistry

Unused; kept for interface uniformity.

Definition at line 299 of file EntityMutationManager.ixx.

299 void init(CommandHandlerRegistry& commandHandlerRegistry) {}

submit()

template <typename TCommand>
bool helios::engine::runtime::world::EntityMutationManager< TEntityManager >::submit (TCommand && command)
inline

Accepts a command from the CommandHandlerRegistry and enqueues it.

TCommand::Handle_type must match THandle.

Template Parameters
TCommand

Deduced ECS command type.

Parameters
command

Command instance forwarded into the internal buffer.

Returns

true unconditionally (reserved for future error reporting).

Definition at line 247 of file EntityMutationManager.ixx.

247 bool submit(TCommand&& command) {
248
249 using Command_type = std::remove_cvref_t<TCommand>;
250
262
263
268
269 modelAddAct->add(AddActive_type(command.handle));
270 modelAddActiveDirty->add(AddActiveDirty_type(command.handle));
271 modelRemoveInact->add(RemoveInactive_type(command.handle));
272
273 } else {
274
278
279 modelRemoveAct->add(RemoveActive_type(command.handle));
280 modelAddInactiveDirty->add(AddInactiveDirty_type(command.handle));
281 modelAddInact->add(AddInactive_type(command.handle));
282 }
283
284 } else {
285 auto* model = modelFor<Command_type>();
286 model->add(std::forward<TCommand>(command));
287 }
288
289
290
291 return true;
292 }

Reference helios::engine::runtime::registerComponents.

Private Member Functions

modelFor()

template <typename TCommand>
auto * helios::engine::runtime::world::EntityMutationManager< TEntityManager >::modelFor ()
inline

Returns (or lazily creates) the InternalBuffer for TCommand.

Template Parameters
TCommand

Command type whose buffer is requested.

Returns

Non-owning pointer to the buffer.

Definition at line 186 of file EntityMutationManager.ixx.

186 auto* modelFor() {
187
188 auto* model = commandBufferRegistry_.item<InternalBuffer<TCommand>>();
189
190 if (!model) {
191 auto& created =
192 commandBufferRegistry_.add<InternalBuffer<TCommand>>(
194 );
195
196 using Component_type = typename TCommand::Component_type;
197 const auto cv = ComponentTypeId<THandle>::template id<Component_type>().value();
198
199 if (componentToBufferGroups_.size() <= cv) {
200 componentToBufferGroups_.resize(cv + 1);
201 }
202
203 if (componentToBufferGroups_[cv].empty()) {
204 bufferGroupIndices_.push_back(cv);
205 }
206 componentToBufferGroups_[cv].push_back(CommandBufferTypeId::template id<InternalBuffer<TCommand>>());
207
210 }
211 std::ignore = entityManager_.template ensureSparseSet<Component_type>();
212
213 return &created;
214 }
215
216 return model;
217 }

Private Member Attributes

bufferGroupIndices_

template <typename TEntityManager>
std::vector<std::size_t> helios::engine::runtime::world::EntityMutationManager< TEntityManager >::bufferGroupIndices_

Ordered list of component type IDs that have at least one registered buffer.

Definition at line 94 of file EntityMutationManager.ixx.

94 std::vector<std::size_t> bufferGroupIndices_;

commandBufferRegistry_

template <typename TEntityManager>
CommandBufferRegistry helios::engine::runtime::world::EntityMutationManager< TEntityManager >::commandBufferRegistry_ {}

Registry of lazily created per-command-type InternalBuffer instances.

Definition at line 77 of file EntityMutationManager.ixx.

77 CommandBufferRegistry commandBufferRegistry_{};

commandHandlerRegistry_

template <typename TEntityManager>
CommandHandlerRegistry* helios::engine::runtime::world::EntityMutationManager< TEntityManager >::commandHandlerRegistry_ {nullptr}

Unused; retained for interface uniformity.

Definition at line 80 of file EntityMutationManager.ixx.

80 CommandHandlerRegistry* commandHandlerRegistry_{nullptr};

componentToBufferGroups_

template <typename TEntityManager>
std::vector<std::vector<CommandBufferTypeId> > helios::engine::runtime::world::EntityMutationManager< TEntityManager >::componentToBufferGroups_ {}

Maps component type IDs to the CommandBufferTypeIds of their associated buffers.

Indexed by component type ID; each slot holds one or more buffer IDs that can be flushed independently in parallel.

Definition at line 91 of file EntityMutationManager.ixx.

91 std::vector<std::vector<CommandBufferTypeId>> componentToBufferGroups_{};

entityManager_

template <typename TEntityManager>
TEntityManager& helios::engine::runtime::world::EntityMutationManager< TEntityManager >::entityManager_

Reference to the entity manager mutations are applied to.

Definition at line 74 of file EntityMutationManager.ixx.

74 TEntityManager& entityManager_;

jobSystem_

template <typename TEntityManager>
JobSystem& helios::engine::runtime::world::EntityMutationManager< TEntityManager >::jobSystem_

Job system used by flushParallel() for concurrent buffer execution.

Definition at line 83 of file EntityMutationManager.ixx.

83 JobSystem& jobSystem_;

Private Static Attributes

logger_

template <typename TEntityManager>
auto& helios::engine::runtime::world::EntityMutationManager< TEntityManager >::logger_ = helios::engine::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)
static

Module-scoped logger.

Definition at line 97 of file EntityMutationManager.ixx.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.