Table of Contents

Class Archetype<TSelf>

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

CRTP base class for ECS archetypes. Concrete archetypes inherit from this and declare components as static readonly Comp<T> fields via Register<T>().

public abstract class Archetype<TSelf> where TSelf : Archetype<TSelf>

Type Parameters

TSelf

The concrete archetype type (CRTP pattern).

Inheritance
Archetype<TSelf>
Derived
Inherited Members

Remarks

Finalization (slot assignment, validation, metadata creation) is lazy — triggered on first access to Typhon.Engine.Archetype`1.Metadata. This avoids static constructor ordering issues between the base class and derived class field initializers.

Constructors

Archetype()

protected Archetype()

Properties

CatalogId

This archetype's catalog id: the engine-assigned number that identifies it among all archetypes registered in this process, and the id every per-archetype engine API takes — GetSpatialTelemetry(int) among them.

public static ushort CatalogId { get; }

Property Value

ushort

Remarks

This is not ArchetypeId. Typhon has two archetype id spaces and they are easy to confuse: the catalog id here is process-global and assigned when the archetype registers, while the low 16 bits of an EntityId hold the routing id, which is per-database, numbered from 1 in registration order within that database, and persisted as ArchetypeR1.RoutingId so a reopen can re-match it by name. Comparing one to the other compiles — both are ushort — and silently never matches.

They may coincide by accident, which is the dangerous case. An application that registers its archetypes in one process and routes them all into one database gives both counters the same order, so the two ids commonly agree — and code that confuses them appears to work until a second database, or an archetype registered and not routed, pulls them apart. Use this value only where a catalog id is asked for.

Reading it finalizes the archetype if that has not happened yet, so it is safe from any thread at any time — but it is a dictionary key and a table index, not a hot-path value: cache it in a field rather than re-reading it per entity.

The id is assigned by the engine, not by the author (#514 D1), and it reflects this process's registration order. Do not persist it or hard-code a literal — use the archetype's name for anything durable.

Methods

Register<T>()

Declare a component for this archetype. Must be called as a static field initializer.

protected static Comp<T> Register<T>() where T : unmanaged

Returns

Comp<T>

Type Parameters

T