World
- Module
- ECS
- Header
#include "ECS/World.h"- Namespace
Mowo
Constructors
Public functions
| Returns | Name | Description |
|---|---|---|
void | Initialize | |
void | Shutdown | |
void | Update | |
void | UpdateBefore | One Update split at a system: UpdateBefore runs every system ahead of split in update order and stops; UpdateFrom runs split and the rest (and flushes the deferred queue, as Update does). |
void | UpdateFrom | |
Entity | CreateEntity | |
Entity | CreateEntityWithID | Deserialization path — reuses a stored UUID |
void | DestroyEntity | |
void | DestroyEntity | |
void | DestroyEntities | Destroys a set in SortForStructuralBatch order under one lock, with one signature-version bump: the resulting layout is a function of the set, whatever order it was gathered in. |
void | SortForStructuralBatch | Reorders ids into the order a batch of structural changes to them (destroy, add or remove a component) should run in: archetype creation order, highest row first, then component-less ones in creation order. |
bool | IsEntityValid | |
T& | AddComponent | Header-only templates — no dllexport. |
void | RemoveComponent | |
T* | GetComponent | |
const T* | GetComponent | |
void | GetComponents | Resolves any number of components with ONE entity→archetype lookup — each out pointer is set to the live instance or nullptr. |
bool | HasComponent | |
FEntityHandle | GetHandle | Hash-free access for hot paths. |
bool | IsHandleValid | |
EntityID | GetEntityID | |
T* | GetComponent | |
const T* | GetComponent | |
void | GetComponents | |
bool | HasComponent | |
uint32_t | GetSlotHint | A slot hint is a cache for code that only has the UUID — a link field, a map value: the hinted lookup checks the slot against the id and pays the hash only when the hint is stale, refreshing it in place. |
T* | GetComponentHinted | |
void | GetComponentsHinted | |
bool | HasComponentHinted | |
void* | GetComponentRaw | For tools that walk the reflection registry without compile-time knowledge of the component type. |
const void* | GetComponentRaw | |
bool | HasComponentByID | |
void* | AddComponentByID | |
bool | RemoveComponentByID | |
T* | AddSystem | |
T* | GetSystem | |
void | RemoveSystem | |
void | SetParallelSystems | When enabled, Update runs each phase's conflict-free system batches on the job system. |
bool | GetParallelSystems | |
size_t | GetEntityCount | |
void | ForEach | |
void | ForEachWith | Any number of required components; the lambda receives (Entity, Ts&...) in declaration order. |
void | ForEachChunk | Archetype-at-a-time form of ForEachWith: the lambda receives (Archetype&, Ts*...) — the start of each required column, rows [0, arch.entities.size()). |
void | ParallelForEachWith | ForEachWith across the JobSystem: the rows of every matching archetype cut into runs of rowsPerJob and spread over the pool, the calling thread running its share (JobSystem::WaitForCounter helps). |
uint32_t | GetLastParallelRunCount | Row runs the most recent ParallelForEachWith handed to the job pool; 0 when it ran serially. |
void | ForEachEntity | Every living entity, unfiltered. |
auto | MakeQuery | Declared here so callers need no extra include; the body lives in Query.h. |
bool | IsIterating | True while a ForEach / ForEachWith pass is running on any thread. |
std::bitset<MAX_COMPONENTS> | GetSignature | Empty bitset if the entity has no components yet (the row only exists after the first AddComponent), which matches a no-requirements query. |
uint64_t | GetSignatureVersion | Bumped on every entity creation, destruction, AddComponent, RemoveComponent. |
uint64_t | GetArchetypeVersion | Bumped ONLY when a new archetype is created; archetypes are never pruned at runtime. |
void | ForEachMatchingArchetype | Every archetype whose signature is a superset of required, so a query rebuild walks matching archetypes instead of every entity's signature. |
void | SubmitDeferred | Threads that can't take the World mutex — because a ForEach is up the stack, or to batch many small mutations — submit a callable instead. |
void | FlushDeferred | |
void | SetOriginOffset | Where this world's local origin sits in absolute space (absolute = local + offset). |
const double* | GetOriginOffset | |
WorldSnapshot | CaptureSnapshot | |
void | RestoreSnapshot |
Function details
World
World()~World
~World()Initialize
void Initialize()Shutdown
void Shutdown()Update
void Update(float deltaTime)UpdateBefore
void UpdateBefore(float deltaTime, const System* split)One Update split at a system: UpdateBefore runs every system ahead of split in update order and stops; UpdateFrom runs split and the rest (and flushes the deferred queue, as Update does). The scene splits a frame at PhysicsSystem when the step overlaps the DuringPhysics tick: the systems ahead of it — input, movement intent, transforms — must run before the step is kicked or they act a step late. A system the world does not hold makes UpdateBefore run nothing and UpdateFrom run everything.
UpdateFrom
void UpdateFrom(float deltaTime, const System* split)CreateEntity
Entity CreateEntity()CreateEntityWithID
Entity CreateEntityWithID(EntityID id)Deserialization path — reuses a stored UUID
DestroyEntity
void DestroyEntity(Entity entity)DestroyEntity
void DestroyEntity(EntityID id)DestroyEntities
void DestroyEntities(std::vector<EntityID> ids)Destroys a set in SortForStructuralBatch order under one lock, with one signature-version bump: the resulting layout is a function of the set, whatever order it was gathered in. Unknown and dead ids are skipped.
SortForStructuralBatch
void SortForStructuralBatch(std::vector<EntityID>& ids) constReorders ids into the order a batch of structural changes to them (destroy, add or remove a component) should run in: archetype creation order, highest row first, then component-less ones in creation order. Leaving an archetype swap-removes the row, so which survivor lands where depends on the order the batch runs — and a set gathered from a hash container arrives in hash order. Running it in this order makes the resulting layout, and so every later ForEach, a function of the set alone. Unknown or dead ids go last in their given order.
IsEntityValid
bool IsEntityValid(EntityID id) constAddComponent
template<typename T, typename... Args> T& AddComponent(EntityID entity, Args&&... args)Header-only templates — no dllexport.
RemoveComponent
template<typename T> void RemoveComponent(EntityID entity)GetComponent
template<typename T> T* GetComponent(EntityID entity)GetComponent
template<typename T> const T* GetComponent(EntityID entity) constGetComponents
template<typename... Ts> void GetComponents(EntityID entity, Ts*&... out)Resolves any number of components with ONE entity→archetype lookup — each out pointer is set to the live instance or nullptr. The batched form of GetComponent for hot paths that need several components of the same entity per frame.
HasComponent
template<typename T> bool HasComponent(EntityID entity) constGetHandle
FEntityHandle GetHandle(EntityID entity) constHash-free access for hot paths. Every entity owns a slot in a dense table; the id → slot hash is the only hashed step left, and these skip it. A handle ({slot, generation}) is for code that keeps an entity across frames inside one World: it stops resolving the moment the entity dies. It is runtime-only — the UUID remains what is saved and replicated.
IsHandleValid
bool IsHandleValid(FEntityHandle handle) constGetEntityID
EntityID GetEntityID(FEntityHandle handle) constGetComponent
template<typename T> T* GetComponent(FEntityHandle handle)GetComponent
template<typename T> const T* GetComponent(FEntityHandle handle) constGetComponents
template<typename... Ts> void GetComponents(FEntityHandle handle, Ts*&... out)HasComponent
template<typename T> bool HasComponent(FEntityHandle handle) constGetSlotHint
uint32_t GetSlotHint(EntityID entity) constA slot hint is a cache for code that only has the UUID — a link field, a map value: the hinted lookup checks the slot against the id and pays the hash only when the hint is stale, refreshing it in place. Any uint32_t initialised to UINT32_MAX is a valid (cold) hint.
GetComponentHinted
template<typename T> T* GetComponentHinted(EntityID entity, uint32_t& slotHint)GetComponentsHinted
template<typename... Ts> void GetComponentsHinted(EntityID entity, uint32_t& slotHint, Ts*&... out)HasComponentHinted
template<typename T> bool HasComponentHinted(EntityID entity, uint32_t slotHint) constGetComponentRaw
void* GetComponentRaw(EntityID entity, ComponentID compId)For tools that walk the reflection registry without compile-time knowledge of the component type. Null if the entity has no archetype or the archetype doesn't carry that component.
GetComponentRaw
const void* GetComponentRaw(EntityID entity, ComponentID compId) constHasComponentByID
bool HasComponentByID(EntityID entity, ComponentID compId) constAddComponentByID
void* AddComponentByID(EntityID entity, ComponentID compId)RemoveComponentByID
bool RemoveComponentByID(EntityID entity, ComponentID compId)AddSystem
template<typename T, typename... Args> T* AddSystem(Args&&... args)GetSystem
template<typename T> T* GetSystem()RemoveSystem
template<typename T> void RemoveSystem()SetParallelSystems
void SetParallelSystems(bool enabled)When enabled, Update runs each phase's conflict-free system batches on the job system. Only systems that declare component access are eligible; an undeclared system conflicts with everything, so with none declared every batch is one system and Update matches the serial phase loop. Fan-out is also skipped when Update itself runs on a job worker.
GetParallelSystems
bool GetParallelSystems() constGetEntityCount
size_t GetEntityCount() constForEach
template<typename T, typename Func> void ForEach(Func&& func)ForEachWith
template<typename... Ts, typename Func> void ForEachWith(Func&& func)Any number of required components; the lambda receives (Entity, Ts&...) in declaration order. Widening a two-component pass to also fetch the extra components it needs per entity beats per-entity GetComponent calls inside the lambda.
ForEachChunk
template<typename... Ts, typename Func> void ForEachChunk(Func&& func)Archetype-at-a-time form of ForEachWith: the lambda receives (Archetype&, Ts*...) — the start of each required column, rows [0, arch.entities.size()). A pass that also wants an OPTIONAL component reads it once per archetype through arch.ColumnData<T>() instead of a hashed GetComponent per entity. Same thread and mutation rules as ForEach.
ParallelForEachWith
template<typename... Ts, typename Func> void ParallelForEachWith(uint32_t rowsPerJob, Func&& func)ForEachWith across the JobSystem: the rows of every matching archetype cut into runs of rowsPerJob and spread over the pool, the calling thread running its share (JobSystem::WaitForCounter helps). The lambda gets (Entity, Ts&...) like ForEachWith and must write only the row it is handed and read state nothing else writes meanwhile — the contract a declared system in a parallel batch already keeps. Runs serially when the pool is down, on a worker (a system already inside a parallel batch), or when everything fits one job. Main-thread only, like ForEach.
GetLastParallelRunCount
uint32_t GetLastParallelRunCount() constRow runs the most recent ParallelForEachWith handed to the job pool; 0 when it ran serially. Diagnostics and tests only.
ForEachEntity
template<typename Func> void ForEachEntity(Func&& func) constEvery living entity, unfiltered. Main-thread only. Order is defined: archetype creation order then row order, then component-less entities in creation order. It walks a snapshot, so the callback may add or remove components; an entity it destroys is skipped, one it creates is not visited.
MakeQuery
template<typename... Ts> auto MakeQuery()Declared here so callers need no extra include; the body lives in Query.h.
IsIterating
bool IsIterating() constTrue while a ForEach / ForEachWith pass is running on any thread. The structural mutators MOWO_CHECK this is false: mutating from inside a ForEach lambda swap-removes the very row the loop cached a raw column pointer into, so the guard aborts loudly instead of corrupting it.
GetSignature
std::bitset<MAX_COMPONENTS> GetSignature(EntityID id) constEmpty bitset if the entity has no components yet (the row only exists after the first AddComponent), which matches a no-requirements query.
GetSignatureVersion
uint64_t GetSignatureVersion() constBumped on every entity creation, destruction, AddComponent, RemoveComponent.
GetArchetypeVersion
uint64_t GetArchetypeVersion() constBumped ONLY when a new archetype is created; archetypes are never pruned at runtime. A Query's cached (archetype, columns) buckets go stale only when a new archetype appears, not when entities move between existing ones (Each() reads live entity counts), so queries key their cache on this instead of the per-mutation signature version.
ForEachMatchingArchetype
template<typename Func> void ForEachMatchingArchetype(const std::bitset<MAX_COMPONENTS>& required, Func&& func) constEvery archetype whose signature is a superset of required, so a query rebuild walks matching archetypes instead of every entity's signature.
SubmitDeferred
void SubmitDeferred(std::function<void(World*)> cmd)Threads that can't take the World mutex — because a ForEach is up the stack, or to batch many small mutations — submit a callable instead. Submit is thread-safe; the lambda runs on the main thread and may call any World API. FlushDeferred runs at the end of World::Update, after every system and outside any ForEach. Calling it manually elsewhere is fine, but never re-enter it from inside a ForEach lambda.
FlushDeferred
void FlushDeferred()SetOriginOffset
void SetOriginOffset(double x, double y, double z)Where this world's local origin sits in absolute space (absolute = local + offset). Scene origin rebasing keeps it current; code that exchanges positions with another world (replication) converts through it, so two worlds that rebased independently still agree on where things are. Doubles: a float offset past 2^24 m stops being exact.
GetOriginOffset
const double* GetOriginOffset() constCaptureSnapshot
WorldSnapshot CaptureSnapshot() constRestoreSnapshot
void RestoreSnapshot(const WorldSnapshot& snapshot)