KernelAPI reference
Class SceneWorld
Namespace: MicroEngine.Scenes
Assembly: MicroEngine.Scene.dll
Guide: Scenes
The engine’s IWorld: entity slots with generations, local and step-start transforms, a parent/child tree, and one dense array per attachment type. Games program against IWorld; whoever owns the world (its scene) calls BeginStep before the world’s step, EndStep after it and BeginDraw before drawing it.
public sealed class SceneWorld : IWorld, IStateHashedInheritance
Implements
Remarks
Not thread-safe. Allocates only when it grows (entities, attachment types, per-type capacity). Its simulation state (ids, hierarchy, transforms, which attachments each entity has, the state of attachments that are IStateHashed, and the clock) takes part in the per-step state hash; step-start transforms, teleports and the blend are drawing state and do not.
Constructors
SceneWorld()
public SceneWorld()Properties
Blend
The blend drawing uses this frame: the engine’s, or 1 when this world did not step in the latest engine step.
public float Blend { get; }Property Value
Clock
The world’s clock: scaled time, time scale and freezes (hitstop).
public WorldClock Clock { get; }Property Value
Count
Live entities (destroyed ones not counted).
public int Count { get; }Property Value
SteppedAt
The engine step this world last stepped in (-1: never).
public long SteppedAt { get; }Property Value
Methods
All<T>()
The attachments of type T of live entities, in attach order; foreach allocates nothing.
public 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.
public 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.
BeginDraw(long, float)
Sets Blend for this frame: engineBlend when this world stepped in
latestEngineStep, otherwise 1 (the world is frozen: drawn as its last step).
public void BeginDraw(long latestEngineStep, float engineBlend)Parameters
latestEngineStep long
engineBlend float
BeginStep(long, float)
Starts a step of this world inside engine step engineStep (the engine’s update count): releases
what is still pending, keeps every transform as the step’s start (the blend origin), ends every teleport and
advances Clock by dt.
public float BeginStep(long engineStep, float dt)Parameters
engineStep long
dt float
Returns
The scaled length of the step: dt exactly at scale 1, 0 while frozen.
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.
public EntityChildren Children(EntityId parent)Parameters
parent EntityId
Returns
Create(EntityId)
Creates an entity at Identity, under parent when given.
public 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.
public void Destroy(EntityId entity)Parameters
entity EntityId
Detach<T>(EntityId)
Removes the attachment of type T; false when there was none.
public 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.
public Vector2 DrawPosition2D(EntityId entity)Parameters
entity EntityId
Returns
EndStep()
Ends the step: tells IDestroyedCallback attachments and releases destroyed entities.
public void EndStep()Get<T>(EntityId)
The attachment of type T.
public T Get<T>(EntityId entity) where T : classParameters
entity EntityId
Returns
T
Type Parameters
T
Exceptions
There is none, or the id is stale.
HashState(StateHasher)
Adds the world’s simulation state: the clock, then each entity in creation order (id, state, parent, local transform, and each attachment’s type in the order the world first stored that type, followed by the attachment’s own state when it is IStateHashed). Drawing never changes it.
public void HashState(StateHasher hash)Parameters
hash StateHasher
IsAlive(EntityId)
Whether entity exists and was not destroyed.
public bool IsAlive(EntityId entity)Parameters
entity EntityId
Returns
Local(EntityId)
The transform relative to the parent, by reference (write through it).
public ref Transform Local(EntityId entity)Parameters
entity EntityId
Returns
ParentOf(EntityId)
The parent, or None for a root.
public 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.
public 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.
public 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).
public 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).
public Matrix4x4 WorldMatrix(EntityId entity)Parameters
entity EntityId