Skip to content

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.

C#
public sealed class SceneWorld : IWorld, IStateHashed

Inheritance

object ← SceneWorld

Implements

IWorld, IStateHashed

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()

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

C#
public float Blend { get; }

Property Value

float

Clock

The world’s clock: scaled time, time scale and freezes (hitstop).

C#
public WorldClock Clock { get; }

Property Value

WorldClock

Count

Live entities (destroyed ones not counted).

C#
public int Count { get; }

Property Value

int

SteppedAt

The engine step this world last stepped in (-1: never).

C#
public long SteppedAt { get; }

Property Value

long

Methods

All<T>()

The attachments of type T of live entities, in attach order; foreach allocates nothing.

C#
public Attachments<T> All<T>() where T : class

Returns

Attachments<T>

Type Parameters

T

Attach<T>(EntityId, T)

Attaches attachment under the type T; replaces one already there, in its place.

C#
public T Attach<T>(EntityId entity, T attachment) where T : class

Parameters

entity EntityId

attachment T

Returns

T

Type Parameters

T

Exceptions

InvalidOperationException

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

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

C#
public float BeginStep(long engineStep, float dt)

Parameters

engineStep long

dt float

Returns

float

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.

C#
public EntityChildren Children(EntityId parent)

Parameters

parent EntityId

Returns

EntityChildren

Create(EntityId)

Creates an entity at Identity, under parent when given.

C#
public EntityId Create(EntityId parent = default)

Parameters

parent EntityId

Returns

EntityId

Exceptions

InvalidOperationException

parent is stale or destroyed.

Destroy(EntityId)

Destroys the entity and its subtree (see the rules); nothing for a destroyed, stale or none id.

C#
public void Destroy(EntityId entity)

Parameters

entity EntityId

Detach<T>(EntityId)

Removes the attachment of type T; false when there was none.

C#
public bool Detach<T>(EntityId entity) where T : class

Parameters

entity EntityId

Returns

bool

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.

C#
public Vector2 DrawPosition2D(EntityId entity)

Parameters

entity EntityId

Returns

Vector2

EndStep()

Ends the step: tells IDestroyedCallback attachments and releases destroyed entities.

C#
public void EndStep()

Get<T>(EntityId)

The attachment of type T.

C#
public T Get<T>(EntityId entity) where T : class

Parameters

entity EntityId

Returns

T

Type Parameters

T

Exceptions

InvalidOperationException

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.

C#
public void HashState(StateHasher hash)

Parameters

hash StateHasher

IsAlive(EntityId)

Whether entity exists and was not destroyed.

C#
public bool IsAlive(EntityId entity)

Parameters

entity EntityId

Returns

bool

Local(EntityId)

The transform relative to the parent, by reference (write through it).

C#
public ref Transform Local(EntityId entity)

Parameters

entity EntityId

Returns

Transform

ParentOf(EntityId)

The parent, or None for a root.

C#
public EntityId ParentOf(EntityId entity)

Parameters

entity EntityId

Returns

EntityId

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.

C#
public void SetParent(EntityId entity, EntityId parent)

Parameters

entity EntityId

parent EntityId

Exceptions

InvalidOperationException

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.

C#
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).

C#
public bool TryGet<T>(EntityId entity, out T? attachment) where T : class

Parameters

entity EntityId

attachment T?

Returns

bool

Type Parameters

T

WorldMatrix(EntityId)

The world matrix drawn this frame (at Blend).

C#
public Matrix4x4 WorldMatrix(EntityId entity)

Parameters

entity EntityId

Returns

Matrix4x4