EntityMutationManager.ixx File
Applies deferred entity-mutation commands to the ECS world. More...
Included Headers
#include <vector>
#include <format>
#include "helios-engine-config.h"
#include <optional>
#include <algorithm>
#include <iterator>
#include <cassert>
#include <helios.engine.util.log>
#include <helios.ecs.concepts.Traits>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.ecs.commands>
#include <helios.engine.runtime.messaging.command.types.CommandBufferTypeId>
#include <helios.ecs.types.ComponentTypeId>
#include <helios.engine.core.thread.JobSystem>
#include <helios.engine.runtime.messaging.command.tags.CommandBufferRole>
#include <helios.engine.runtime.world.tags.ManagerRole>
#include <helios.engine.runtime.messaging.command.CommandBuffer>
#include <helios.ecs.types>
#include <helios.engine.runtime.world.ManagerRegistry>
#include <helios.engine.runtime.messaging.command.CommandBufferRegistry>
#include <helios.engine.runtime.messaging.command.CommandHandlerRegistry>
#include <helios.ecs.components>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | runtime |
| namespace | world |
| namespace | commands |
Classes Index
| class | EntityMutationManager<TEntityManager> |
|
Receives submitted ECS mutation commands and applies them during flush. More... | |
| class | InternalBuffer<TCommandType> |
|
Per-command-type buffer that applies mutations on flush. More... | |
Macro Definitions Index
| #define | HELIOS_LOG_SCOPE "helios::engine::runtime::world::EntityMutationManager" |
Description
Applies deferred entity-mutation commands to the ECS world.
Macro Definitions
HELIOS_LOG_SCOPE
|
Definition at line 53 of file EntityMutationManager.ixx.
53#define HELIOS_LOG_SCOPE "helios::engine::runtime::world::EntityMutationManager"
File Listing
The file content with the documentation metadata removed is:
9#include "helios-engine-config.h"
42using namespace helios::engine::core::thread;
43using namespace helios::engine::runtime::world;
44using namespace helios::engine::runtime::world::tags;
45using namespace helios::engine::runtime::messaging::command;
46using namespace helios::engine::runtime::messaging::command::types;
50using namespace helios::engine::util::log;
51using namespace helios::engine::runtime::messaging::command::tags;
53#define HELIOS_LOG_SCOPE "helios::engine::runtime::world::EntityMutationManager"
54export namespace helios::engine::runtime::world {
68 class EntityMutationManager {
74 TEntityManager& entityManager_;
77 CommandBufferRegistry commandBufferRegistry_{};
80 CommandHandlerRegistry* commandHandlerRegistry_{nullptr};
83 JobSystem& jobSystem_;
97 static inline auto& logger_ = helios::engine::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE);
110 CommandHandlerRegistry* commandHandlerRegistry_{nullptr};
114 TEntityManager& entityManager_;
118 using EngineRoleTag = CommandBufferRole;
121 using Command_type = TCommandType;
127 InternalBuffer(TEntityManager& entityManager) : entityManager_(entityManager) {
128 commands_.reserve(DEFAULT_ENTITY_MUTATION_COMMAND_BUFFER_CAPACITY);
138 void flush(UpdateContext& updateContext)
149 if constexpr (IsAddComponentCommand_v<TCommandType>) {
150 entityManager_.template emplace<Component_type>(command.handle, std::move(command.component));
152 entityManager_.template remove<Component_type>(command.handle);
166 void init(CommandHandlerRegistry& commandHandlerRegistry, ManagerRegistry& managerRegistry) {/* noop*/ }
173 void add(TCommandType commandType) {
174 commands_.emplace_back(std::forward<TCommandType>(commandType));
188 auto* model = commandBufferRegistry_.item<InternalBuffer<TCommand>>();
191 auto& created =
192 commandBufferRegistry_.add<InternalBuffer<TCommand>>(
193 CommandBuffer(InternalBuffer<TCommand>{entityManager_})
197 const auto cv = ComponentTypeId<THandle>::template id<Component_type>().value();
199 if (componentToBufferGroups_.size() <= cv) {
200 componentToBufferGroups_.resize(cv + 1);
204 bufferGroupIndices_.push_back(cv);
206 componentToBufferGroups_[cv].push_back(CommandBufferTypeId::template id<InternalBuffer<TCommand>>());
208 if constexpr (IsDirtyComponentSpec_v<Component_type>) {
209 entityManager_.template trackDirty<typename Component_type::Component_type>();
211 std::ignore = entityManager_.template ensureSparseSet<Component_type>();
213 return &created;
222 using Handle_type = THandle;
225 using EngineRoleTag = ManagerRole;
233 explicit EntityMutationManager(TEntityManager& entity_manager, JobSystem& jobSystem)
234 : entityManager_(entity_manager), jobSystem_(jobSystem) {}
255 if constexpr (IsActivateEntityCommand_v<Command_type> || IsDeactivateEntityCommand_v<Command_type>) {
259 using RemoveInactive_type = RemoveComponentCommand<Inactive<typename Command_type::Handle_type>>;
260 using AddActiveDirty_type = AddComponentCommand<DirtyComponentSpec<Active<typename Command_type::Handle_type>>>;
261 using AddInactiveDirty_type = AddComponentCommand<DirtyComponentSpec<Inactive<typename Command_type::Handle_type>>>;
264 if constexpr (IsActivateEntityCommand_v<Command_type>) {
265 auto* modelAddAct = modelFor<AddActive_type>();
266 auto* modelAddActiveDirty = modelFor<AddActiveDirty_type>();
267 auto* modelRemoveInact = modelFor<RemoveInactive_type>();
269 modelAddAct->add(AddActive_type(command.handle));
270 modelAddActiveDirty->add(AddActiveDirty_type(command.handle));
271 modelRemoveInact->add(RemoveInactive_type(command.handle));
275 auto* modelAddInact = modelFor<AddInactive_type>();
276 auto* modelRemoveAct = modelFor<RemoveActive_type>();
277 auto* modelAddInactiveDirty = modelFor<AddInactiveDirty_type>();
279 modelRemoveAct->add(RemoveActive_type(command.handle));
280 modelAddInactiveDirty->add(AddInactiveDirty_type(command.handle));
281 modelAddInact->add(AddInactive_type(command.handle));
285 auto* model = modelFor<Command_type>();
299 void init(CommandHandlerRegistry& commandHandlerRegistry) {}
306 void flush(UpdateContext& updateContext) {
308 buffer->flush(updateContext);
321 void flushParallel(UpdateContext& updateContext) {
324 for (const auto idx : bufferGroupIndices_) {
326 activeIndices.push_back(idx);
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);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.