class

World

Module
ECS
Header
#include "ECS/World.h"
Namespace
Mowo

Constructors

SignatureNameDescription
World()World
~World()~World

Public functions

ReturnsNameDescription
voidInitialize
voidShutdown
voidUpdate
voidUpdateBeforeOne 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).
voidUpdateFrom
EntityCreateEntity
EntityCreateEntityWithIDDeserialization path — reuses a stored UUID
voidDestroyEntity
voidDestroyEntity
voidDestroyEntitiesDestroys 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.
voidSortForStructuralBatchReorders 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.
boolIsEntityValid
T&AddComponentHeader-only templates — no dllexport.
voidRemoveComponent
T*GetComponent
const T*GetComponent
voidGetComponentsResolves any number of components with ONE entity→archetype lookup — each out pointer is set to the live instance or nullptr.
boolHasComponent
FEntityHandleGetHandleHash-free access for hot paths.
boolIsHandleValid
EntityIDGetEntityID
T*GetComponent
const T*GetComponent
voidGetComponents
boolHasComponent
uint32_tGetSlotHintA 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
voidGetComponentsHinted
boolHasComponentHinted
void*GetComponentRawFor tools that walk the reflection registry without compile-time knowledge of the component type.
const void*GetComponentRaw
boolHasComponentByID
void*AddComponentByID
boolRemoveComponentByID
T*AddSystem
T*GetSystem
voidRemoveSystem
voidSetParallelSystemsWhen enabled, Update runs each phase's conflict-free system batches on the job system.
boolGetParallelSystems
size_tGetEntityCount
voidForEach
voidForEachWithAny number of required components; the lambda receives (Entity, Ts&...) in declaration order.
voidForEachChunkArchetype-at-a-time form of ForEachWith: the lambda receives (Archetype&, Ts*...) — the start of each required column, rows [0, arch.entities.size()).
voidParallelForEachWithForEachWith 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_tGetLastParallelRunCountRow runs the most recent ParallelForEachWith handed to the job pool; 0 when it ran serially.
voidForEachEntityEvery living entity, unfiltered.
autoMakeQueryDeclared here so callers need no extra include; the body lives in Query.h.
boolIsIteratingTrue while a ForEach / ForEachWith pass is running on any thread.
std::bitset<MAX_COMPONENTS>GetSignatureEmpty bitset if the entity has no components yet (the row only exists after the first AddComponent), which matches a no-requirements query.
uint64_tGetSignatureVersionBumped on every entity creation, destruction, AddComponent, RemoveComponent.
uint64_tGetArchetypeVersionBumped ONLY when a new archetype is created; archetypes are never pruned at runtime.
voidForEachMatchingArchetypeEvery archetype whose signature is a superset of required, so a query rebuild walks matching archetypes instead of every entity's signature.
voidSubmitDeferredThreads that can't take the World mutex — because a ForEach is up the stack, or to batch many small mutations — submit a callable instead.
voidFlushDeferred
voidSetOriginOffsetWhere this world's local origin sits in absolute space (absolute = local + offset).
const double*GetOriginOffset
WorldSnapshotCaptureSnapshot
voidRestoreSnapshot

Function details

World

C++
World()

~World

C++
~World()

Initialize

C++
void Initialize()

Shutdown

C++
void Shutdown()

Update

C++
void Update(float deltaTime)

UpdateBefore

C++
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

C++
void UpdateFrom(float deltaTime, const System* split)

CreateEntity

C++
Entity CreateEntity()

CreateEntityWithID

C++
Entity CreateEntityWithID(EntityID id)

Deserialization path — reuses a stored UUID

DestroyEntity

C++
void DestroyEntity(Entity entity)

DestroyEntity

C++
void DestroyEntity(EntityID id)

DestroyEntities

C++
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

C++
void SortForStructuralBatch(std::vector<EntityID>& ids) const

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. 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

C++
bool IsEntityValid(EntityID id) const

AddComponent

C++
template<typename T, typename... Args> T& AddComponent(EntityID entity, Args&&... args)

Header-only templates — no dllexport.

RemoveComponent

C++
template<typename T> void RemoveComponent(EntityID entity)

GetComponent

C++
template<typename T> T* GetComponent(EntityID entity)

GetComponent

C++
template<typename T> const T* GetComponent(EntityID entity) const

GetComponents

C++
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

C++
template<typename T> bool HasComponent(EntityID entity) const

GetHandle

C++
FEntityHandle GetHandle(EntityID entity) const

Hash-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

C++
bool IsHandleValid(FEntityHandle handle) const

GetEntityID

C++
EntityID GetEntityID(FEntityHandle handle) const

GetComponent

C++
template<typename T> T* GetComponent(FEntityHandle handle)

GetComponent

C++
template<typename T> const T* GetComponent(FEntityHandle handle) const

GetComponents

C++
template<typename... Ts> void GetComponents(FEntityHandle handle, Ts*&... out)

HasComponent

C++
template<typename T> bool HasComponent(FEntityHandle handle) const

GetSlotHint

C++
uint32_t GetSlotHint(EntityID entity) const

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. Any uint32_t initialised to UINT32_MAX is a valid (cold) hint.

GetComponentHinted

C++
template<typename T> T* GetComponentHinted(EntityID entity, uint32_t& slotHint)

GetComponentsHinted

C++
template<typename... Ts> void GetComponentsHinted(EntityID entity, uint32_t& slotHint, Ts*&... out)

HasComponentHinted

C++
template<typename T> bool HasComponentHinted(EntityID entity, uint32_t slotHint) const

GetComponentRaw

C++
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

C++
const void* GetComponentRaw(EntityID entity, ComponentID compId) const

HasComponentByID

C++
bool HasComponentByID(EntityID entity, ComponentID compId) const

AddComponentByID

C++
void* AddComponentByID(EntityID entity, ComponentID compId)

RemoveComponentByID

C++
bool RemoveComponentByID(EntityID entity, ComponentID compId)

AddSystem

C++
template<typename T, typename... Args> T* AddSystem(Args&&... args)

GetSystem

C++
template<typename T> T* GetSystem()

RemoveSystem

C++
template<typename T> void RemoveSystem()

SetParallelSystems

C++
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

C++
bool GetParallelSystems() const

GetEntityCount

C++
size_t GetEntityCount() const

ForEach

C++
template<typename T, typename Func> void ForEach(Func&& func)

ForEachWith

C++
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

C++
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

C++
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

C++
uint32_t GetLastParallelRunCount() const

Row runs the most recent ParallelForEachWith handed to the job pool; 0 when it ran serially. Diagnostics and tests only.

ForEachEntity

C++
template<typename Func> void ForEachEntity(Func&& func) const

Every 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

C++
template<typename... Ts> auto MakeQuery()

Declared here so callers need no extra include; the body lives in Query.h.

IsIterating

C++
bool IsIterating() const

True 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

C++
std::bitset<MAX_COMPONENTS> GetSignature(EntityID id) const

Empty bitset if the entity has no components yet (the row only exists after the first AddComponent), which matches a no-requirements query.

GetSignatureVersion

C++
uint64_t GetSignatureVersion() const

Bumped on every entity creation, destruction, AddComponent, RemoveComponent.

GetArchetypeVersion

C++
uint64_t GetArchetypeVersion() const

Bumped 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

C++
template<typename Func> void ForEachMatchingArchetype(const std::bitset<MAX_COMPONENTS>& required, Func&& func) const

Every archetype whose signature is a superset of required, so a query rebuild walks matching archetypes instead of every entity's signature.

SubmitDeferred

C++
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

C++
void FlushDeferred()

SetOriginOffset

C++
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

C++
const double* GetOriginOffset() const

CaptureSnapshot

C++
WorldSnapshot CaptureSnapshot() const

RestoreSnapshot

C++
void RestoreSnapshot(const WorldSnapshot& snapshot)
Generated from ECS/World.h via ecs.json · Nov 4, 2026Version 1.0.0