KernelAPI reference
Interface IWorld
Namespace: MicroEngine.Scenes
Assembly: MicroEngine.Scene.dll
Guide: Scenes
The objects of a scene: entities with an id, a transform (with an optional parent) and typed attachments. The world runs no game logic: it stores, identifies, orders, interpolates and destroys. Game code programs against this interface; the scene that owns the world drives its step and draw hooks (SceneWorld).
public interface IWorldRemarks
The rules of the contract:
- Ids are generation-checked; a released slot is reused with a new generation. For a stale id [IsAlive](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_IsAlive_MicroEngine_Scenes_EntityId_) and [TryGet``1](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_TryGet__1_MicroEngine_Scenes_EntityId___0__) are false; [Local](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Local_MicroEngine_Scenes_EntityId_), [Get``1](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Get__1_MicroEngine_Scenes_EntityId_) and [ParentOf](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_ParentOf_MicroEngine_Scenes_EntityId_) throw `InvalidOperationException` naming the id and why.
- Destroy takes effect at once for queries ([IsAlive](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_IsAlive_MicroEngine_Scenes_EntityId_) false, [Count](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Count) drops, every iteration skips it and its subtree). Its transform and attachments stay readable through its id until the world ends the step; then [IDestroyedCallback](/docs/api/microengine.scenes.idestroyedcallback/) attachments are told in destroy order and the slot is released, never during an iteration. Destroying a destroyed, stale or [None](/docs/api/microengine.scenes.entityid/#MicroEngine_Scenes_EntityId_None) id does nothing.
- Creation takes effect at once: the id is valid and its transform writable. An iteration already running does not visit it; every later one does. There is no spawn queue.
- Iteration: [All``1](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_All__1) walks the attachments of one type of live entities in
attach order, stable under removal. Attachments are keyed by the type argument, not the runtime type.
foreachallocates nothing. - Interpolation: drawing reads [WorldMatrix](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_WorldMatrix_MicroEngine_Scenes_EntityId_) or [DrawPosition2D](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_DrawPosition2D_MicroEngine_Scenes_EntityId_) at the world's [Blend](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Blend), from each entity's transform at the start of the step to its current one; at blend 1, or when nothing moved, the result is exactly the simulated transform. A child's matrix is its interpolated local matrix times its parent's.
- Teleport: a new, teleported or re-parented entity is drawn at its current transform until the next step starts; a teleported parent carries its children.
- Step tracking: [Blend](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Blend) is the engine's blend when this world stepped in the engine's latest fixed step, otherwise 1 (paused, under an overlay, in a transition), so a frozen world is drawn as its last step.
- Clock: [Clock](/docs/api/microengine.scenes.iworld/#MicroEngine_Scenes_IWorld_Clock) advances once per step of this world; at scale 1 the scaled step is the engine's step bit for bit.
Properties
Blend
The blend drawing uses this frame: the engine’s, or 1 when this world did not step in the latest engine step.
float Blend { get; }Property Value
Clock
The world’s clock: scaled time, time scale and freezes (hitstop).
WorldClock Clock { get; }Property Value
Count
Live entities (destroyed ones not counted).
int Count { get; }Property Value
Methods
All<T>()
The attachments of type T of live entities, in attach order; foreach allocates nothing.
Attachments<T> All<T>() where T : classReturns
Attachments<T>
Type Parameters
T
Attach<T>(EntityId, T)
Attaches attachment under the type T; replaces one already there, in its place.
T Attach<T>(EntityId entity, T attachment) where T : classParameters
entity EntityId
attachment T
Returns
T
Type Parameters
T
Exceptions
The entity is stale or destroyed.
Children(EntityId)
The live direct children of parent, in the order they were given that parent; foreach
allocates nothing. A child created during the walk is visited by the next one; re-parenting during it throws.
EntityChildren Children(EntityId parent)Parameters
parent EntityId
Returns
Create(EntityId)
Creates an entity at Identity, under parent when given.
EntityId Create(EntityId parent = default)Parameters
parent EntityId
Returns
Exceptions
parent is stale or destroyed.
Destroy(EntityId)
Destroys the entity and its subtree (see the rules); nothing for a destroyed, stale or none id.
void Destroy(EntityId entity)Parameters
entity EntityId
Detach<T>(EntityId)
Removes the attachment of type T; false when there was none.
bool Detach<T>(EntityId entity) where T : classParameters
entity EntityId
Returns
Type Parameters
T
DrawPosition2D(EntityId)
The world X/Y drawn this frame (at Blend); no matrix work for a root or under translation-only parents.
Vector2 DrawPosition2D(EntityId entity)Parameters
entity EntityId
Returns
Get<T>(EntityId)
The attachment of type T.
T Get<T>(EntityId entity) where T : classParameters
entity EntityId
Returns
T
Type Parameters
T
Exceptions
There is none, or the id is stale.
IsAlive(EntityId)
Whether entity exists and was not destroyed.
bool IsAlive(EntityId entity)Parameters
entity EntityId
Returns
Local(EntityId)
The transform relative to the parent, by reference (write through it).
ref Transform Local(EntityId entity)Parameters
entity EntityId
Returns
ParentOf(EntityId)
The parent, or None for a root.
EntityId ParentOf(EntityId entity)Parameters
entity EntityId
Returns
SetParent(EntityId, EntityId)
Moves the entity under parent (None: to the root), keeping its local
transform; it is drawn at its current transform until the next step starts.
void SetParent(EntityId entity, EntityId parent)Parameters
entity EntityId
parent EntityId
Exceptions
The move would make the entity its own ancestor, or an id is stale or destroyed.
Teleport(EntityId)
Draws the entity (and so its children) at its current transform until the next step starts.
void Teleport(EntityId entity)Parameters
entity EntityId
TryGet<T>(EntityId, out T?)
The attachment of type T, if any (also of an entity destroyed this step).
bool TryGet<T>(EntityId entity, out T? attachment) where T : classParameters
entity EntityId
attachment T?
Returns
Type Parameters
T
WorldMatrix(EntityId)
The world matrix drawn this frame (at Blend).
Matrix4x4 WorldMatrix(EntityId entity)Parameters
entity EntityId