FEntityCommandBuffer
Structural changes recorded now and applied later, on the main thread, in one go — the Mass command buffer. A worker or a ForEach that needs to add, remove or destroy records here instead of submitting one std::function per change (a heap allocation and an indirect call each): consecutive records of the same kind and component type share one typed batch.
- Module
- ECS
- Header
#include "ECS/EntityCommandBuffer.h"- Namespace
Mowo
Playback runs the batches in recording order, with World::AddComponent / RemoveComponent semantics per record — adding a component the entity already carries leaves the existing value alone. A run of destroys goes through World::DestroyEntities, which takes the lock once and orders the run with SortForStructuralBatch, so the surviving layout depends on which entities died, not on the order a worker happened to record them in.
A buffer is not thread-safe: one per recording thread.
Constructors
| Signature | Name | Description |
|---|---|---|
FEntityCommandBuffer() = default | FEntityCommandBuffer | |
FEntityCommandBuffer(FEntityCommandBuffer&&) = default | FEntityCommandBuffer | |
FEntityCommandBuffer(const FEntityCommandBuffer&) = delete | FEntityCommandBuffer |
Public functions
| Returns | Name | Description |
|---|---|---|
FEntityCommandBuffer& | operator= | |
FEntityCommandBuffer& | operator= | |
void | AddComponent | |
void | RemoveComponent | |
void | DestroyEntity | |
size_t | Num | |
bool | IsEmpty | |
size_t | NumBatches | Number of typed batches the records collapsed into. |
void | Playback | Main thread, outside any ForEach — the same rule as the World calls it makes. |
void | SubmitTo | Queues the whole buffer on the World's deferred queue, which plays it back at the end of World::Update. |
Function details
FEntityCommandBuffer
FEntityCommandBuffer() = defaultFEntityCommandBuffer
FEntityCommandBuffer(FEntityCommandBuffer&&) = defaultFEntityCommandBuffer
FEntityCommandBuffer(const FEntityCommandBuffer&) = deleteoperator=
FEntityCommandBuffer& operator=(FEntityCommandBuffer&&) = defaultoperator=
FEntityCommandBuffer& operator=(const FEntityCommandBuffer&) = deleteAddComponent
template<typename T> void AddComponent(EntityID entity, T value = T())RemoveComponent
template<typename T> void RemoveComponent(EntityID entity)DestroyEntity
void DestroyEntity(EntityID entity)Num
size_t Num() constIsEmpty
bool IsEmpty() constNumBatches
size_t NumBatches() constNumber of typed batches the records collapsed into.
Playback
void Playback(World& world)Main thread, outside any ForEach — the same rule as the World calls it makes. The buffer is empty afterwards and can be recorded into again.
SubmitTo
void SubmitTo(World& world)Queues the whole buffer on the World's deferred queue, which plays it back at the end of World::Update. Safe from any thread, like World::SubmitDeferred; this buffer is left empty.