Class EntityAccessor
Base class providing MVCC-correct entity access at a frozen TSN. Holds the minimum state needed for entity reads and SingleVersion/Transient writes: engine reference, epoch scope, component accessor cache, and ChangeSet.
Transaction extends this with spawn/destroy, commit/rollback, and TransactionChain insertion. PointInTimeAccessor wraps per-thread instances of this class for lock-free parallel entity access.
public class EntityAccessor : IDisposable
- Inheritance
-
EntityAccessor
- Implements
- Derived
- Inherited Members
Remarks
Who owns a chunk (rule TXT-01). Exactly one live row, or one contiguous run of revisions of a Versioned entity. So how a store treats the chunk it finds depends on whether anything else may still read it:
- In place — SingleVersion under the TickFence discipline, and Transient: the stored value is the only owner, a text is rewritten in its chunk and a clear frees it.
- Copy on write — Versioned, and SingleVersion under the Commit discipline: the committed value (an older revision, or the cluster HEAD that must not change before commit, CM-01) still names the chunk. The first store of a transaction therefore takes a fresh chunk, which the transaction owns until it ends; later stores of the same transaction rewrite that chunk in place. The chunk it replaced belongs to the committed value and goes with it: a Versioned one when revision cleanup drops the last revision naming it, a Commit HEAD's at publish.
Constructors
EntityAccessor()
Creates a new EntityAccessor with empty component-lookup caches; an internal init path binds it before use.
public EntityAccessor()
Properties
TSN
Transaction sequence number defining this accessor's MVCC read snapshot; entity visibility is evaluated against this value.
public long TSN { get; }
Property Value
Methods
Dispose()
Releases the accessor's cached chunk accessors, drops excess dirty-page marks, and resets its state for reuse. A bare accessor holds no persistent epoch scope, so none is exited here; Transaction overrides this to add a thread-affinity check and exit its own epoch scope.
public virtual void Dispose()
For<TArch>()
Create a fast-path ArchetypeAccessor<TArch> pre-bound to a specific archetype. Bypasses the epoch checks and archetype lookup of every Open/OpenMut call; MVCC visibility is still checked, and the transaction's pending destroys are misses. Its own spawns are not seen — they are not in the EntityMap until commit. Intended for PTA workers in parallel QuerySystems.
public ArchetypeAccessor<TArch> For<TArch>() where TArch : class
Returns
- ArchetypeAccessor<TArch>
Type Parameters
TArch
GetClusterEnumerator<TArch>()
Get a full cluster enumerator over all active clusters, bypassing ArchetypeAccessor<TArch>. See GetClusterEnumerator<TArch>(int, int) for details.
public ClusterEnumerator<TArch> GetClusterEnumerator<TArch>() where TArch : class
Returns
- ClusterEnumerator<TArch>
Type Parameters
TArch
GetClusterEnumerator<TArch>(int, int)
Get a scoped cluster enumerator for parallel iteration, bypassing ArchetypeAccessor<TArch>. Eliminates EntityMap accessor creation, duplicate cluster ChunkAccessors, and ComponentInfo pre-warming that are unnecessary for pure cluster-iteration systems (systems that only use GetSpan/GetReadOnlySpan, never Open/OpenMut).
public ClusterEnumerator<TArch> GetClusterEnumerator<TArch>(int startIndex, int endIndex) where TArch : class
Parameters
startIndexintInclusive start into Typhon.Engine.Internals.ArchetypeClusterState.ActiveClusterIds. Use StartClusterIndex.
endIndexintExclusive end index. Use EndClusterIndex.
Returns
- ClusterEnumerator<TArch>
Type Parameters
TArch
GetClusterEnumerator<TArch>(int[], int, int)
Get a scoped cluster enumerator over an explicit cluster-id source array (issue #231). Used by tier-filtered QuerySystems that read ClusterIds at dispatch time:
foreach (var cluster in ctx.Accessor.GetClusterEnumerator<Ant>(ctx.ClusterIds, ctx.StartClusterIndex, ctx.EndClusterIndex)) { ... }
When clusterIds is the archetype's ActiveClusterIds, this is semantically equivalent to
GetClusterEnumerator<TArch>(int, int). When it is a per-tier cluster list, the enumerator iterates only
the tier's clusters.
public ClusterEnumerator<TArch> GetClusterEnumerator<TArch>(int[] clusterIds, int startIndex, int endIndex) where TArch : class
Parameters
Returns
- ClusterEnumerator<TArch>
Type Parameters
TArch
GetClusterEnumerator<TArch>(RealmId)
An enumerator over the clusters of TArch in realm realm only (Realms), bypassing
ArchetypeAccessor<TArch>: O(clusters in that realm). An archetype without a [RealmKey] lives in realm 0.
public ClusterEnumerator<TArch> GetClusterEnumerator<TArch>(RealmId realm) where TArch : class
Parameters
realmRealmId
Returns
- ClusterEnumerator<TArch>
Type Parameters
TArch
Exceptions
- InvalidOperationException
The archetype does not use cluster storage, or
realmis not registered.
IsAlive(EntityId)
Check whether an entity is alive — exists and is visible at this accessor's TSN. The existence probe: one EntityMap lookup, without the component location, cluster page and enabled-bits resolution an open performs.
public virtual bool IsAlive(EntityId id)
Parameters
idEntityId
Returns
IsAlive<T>(EntityLink<T>)
Check whether an entity link target is alive.
public bool IsAlive<T>(EntityLink<T> link) where T : class
Parameters
linkEntityLink<T>
Returns
Type Parameters
T
Open(EntityId)
Open an entity for reading. Throws if not found or not visible.
public EntityRef Open(EntityId id)
Parameters
idEntityId
Returns
OpenMut(EntityId)
Open an entity for reading and writing. Throws if not found or not visible.
public EntityRefMut OpenMut(EntityId id)
Parameters
idEntityId
Returns
Remarks
Runs the accessor's mutation prep first (Typhon.Engine.EntityAccessor.PrepareOpenMut()), then resolves the entity's cluster page dirty.
Teleport<T>(EntityId, Comp<T>, RealmId, in T)
Moves entity id into realm realm, at value's position — a realm change (Realms C4). The
realm is validated here, before anything is written: an unregistered realm, or one that cannot hold the archetype, throws in the caller's code.
public void Teleport<T>(EntityId id, Comp<T> spatial, RealmId realm, in T value) where T : unmanaged
Parameters
Type Parameters
TThe archetype's spatial component, the one carrying
[RealmKey].
Remarks
Writes the whole spatial component — value with its [RealmKey] set to realm, whatever it held —
and the next tick fence moves the entity into the new realm's cell. Until then it answers neither realm's spatial queries: the narrowphase realm
filter hides it from the old one, and it is not yet in the new one.
A write through the cluster barrier (ClusterRef.WriteSpatial) with a new key is the same operation; this is its entity-level form.
Exceptions
- InvalidOperationException
The archetype is not realm-keyed through
spatial, or the realm is invalid for it.
TryOpen(EntityId, out EntityRef)
Try to open an entity for reading. Returns false if the entity doesn't exist or isn't visible.
public bool TryOpen(EntityId id, out EntityRef entity)
Parameters
Returns
TryOpenMut(EntityId, out EntityRefMut)
Try to open an entity for reading and writing. Returns false if the entity doesn't exist or isn't visible. One resolve — the writable counterpart of TryOpen(EntityId, out EntityRef), for a target that may be stale (a stored id, a link) and is written when present.
public bool TryOpenMut(EntityId id, out EntityRefMut entity)
Parameters
idEntityIdentityEntityRefMut
Returns
Remarks
Same preconditions as OpenMut(EntityId): the mutation prep runs whether or not the entity is found, so a read-only transaction throws here even for a missing id.