Table of Contents

Class ArchetypeProjectionBuilder

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

Declares the wire fields of one archetype: what a client may see of it, under what name, quantized how, and in which change group.

public sealed class ArchetypeProjectionBuilder
Inheritance
ArchetypeProjectionBuilder
Inherited Members

Remarks

Anything not named here never leaves the server. That is the whole point of declaring a projection rather than replicating components: the fields a simulation writes every tick for its own bookkeeping — cooldowns, think timers, tick counters — are simply never mentioned, and cost nothing.

Everything is resolved once. A selector (c => c.Mode) names a field; at Start that name becomes a component offset plus a field offset taken from the schema's measured layout, and the selector is never invoked again. Nothing here runs per entity.

The refusals are immediate. A duplicate wire name, a ninth change group or a 64-bit source with no explicit narrowing throws from the call that declared it, not from Start — the stack trace then points at the line that is wrong instead of at the line that noticed.

Methods

Field<TComponent, TField>(Comp<TComponent>, Expression<Func<TComponent, TField>>, Codec, string, string)

A field sent whenever it changes, in the change group it belongs to.

public ArchetypeProjectionBuilder Field<TComponent, TField>(Comp<TComponent> component, Expression<Func<TComponent, TField>> selector, Codec codec, string name = null, string group = null) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

selector Expression<Func<TComponent, TField>>

Selects the field — one member access, resolved once.

codec Codec

How the value travels.

name string

The wire name. null takes the field's own name.

group string

The change group. null takes DefaultGroup.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component holding the field.

TField

The field's type.

Fraction<TComponent, TValue>(Comp<TComponent>, Expression<Func<TComponent, TValue>>, Expression<Func<TComponent, TValue>>, int, string, string)

The ratio of two fields of one component, as a unorm — a health bar, a charge level, a durability.

public ArchetypeProjectionBuilder Fraction<TComponent, TValue>(Comp<TComponent> component, Expression<Func<TComponent, TValue>> value, Expression<Func<TComponent, TValue>> max, int bits, string name, string group = null) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

value Expression<Func<TComponent, TValue>>

Selects the numerator.

max Expression<Func<TComponent, TValue>>

Selects the denominator.

bits int

Width of the ratio: 8, 16, 24 or 32.

name string

The wire name. Required — neither field's name describes the ratio.

group string

The change group. null takes DefaultGroup.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component holding both fields.

TValue

The two fields' type.

Remarks

Sending the ratio rather than the two numbers is what makes it cheap and what makes it quiet: a creature whose maximum health grows on a level-up changes nothing on the wire, and a wound is one byte instead of two integers a client would have to divide anyway.

Heading<TComponent, TField>(Comp<TComponent>, Expression<Func<TComponent, TField>>, int, double, string, string)

An orientation that does not follow from movement: an entity turning in place. Sent as an angle when it moves by more than the tolerance, compared in code space so the wrap at ±π needs no special case.

public ArchetypeProjectionBuilder Heading<TComponent, TField>(Comp<TComponent> component, Expression<Func<TComponent, TField>> selector, int bits, double toleranceDeg, string name = null, string group = null) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

selector Expression<Func<TComponent, TField>>

Selects the heading field.

bits int

Width of the angle: 8, 16, 24 or 32.

toleranceDeg double

How far the heading may move before a new value is sent, in degrees.

name string

The wire name. null takes the field's own name.

group string

The change group. null takes DefaultGroup.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component holding the heading.

TField

The heading field's type.

Remarks

Declared now, built in Phase 2 — a runtime that starts with one of these refuses to start and says so. The verb exists here so an application that needs it writes it once: the shape it will have when it works is the shape it has today. A moving entity needs none of this; its heading follows from its velocity, which the client already has.

Motion<TComponent>(Comp<TComponent>, Action<MotionBuilder>)

Replicates this archetype's position as motion segments: the engine measures the displacement and sends a segment only when a client's own extrapolation would be wrong by more than the tolerance.

public ArchetypeProjectionBuilder Motion<TComponent>(Comp<TComponent> component, Action<MotionBuilder> configure = null) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

configure Action<MotionBuilder>

Tolerance, teleport threshold and heartbeat. null takes the engine defaults.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component carrying the position.

OnEnter<TComponent, TField>(Comp<TComponent>, Expression<Func<TComponent, TField>>, Codec, string)

A field sent in the enter record and never updated. For an identity a client needs once — a template id, a species, a model — and which the engine would otherwise spend a change-group tick slot watching for a change that never comes.

public ArchetypeProjectionBuilder OnEnter<TComponent, TField>(Comp<TComponent> component, Expression<Func<TComponent, TField>> selector, Codec codec, string name = null) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

selector Expression<Func<TComponent, TField>>

Selects the field.

codec Codec

How the value travels.

name string

The wire name. null takes the field's own name.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component holding the field.

TField

The field's type.

Owner(Action<OwnerBuilder>)

Fields visible only to the session controlling this entity — an inventory, a credit balance, a private waypoint. They travel in the archetype's own owner section, with their own group bit space, carried by SELF and unreachable from the public record by construction.

public ArchetypeProjectionBuilder Owner(Action<OwnerBuilder> configure)

Parameters

configure Action<OwnerBuilder>

Declares the owner fields.

Returns

ArchetypeProjectionBuilder

This builder.

Position<TComponent>(Comp<TComponent>)

Replicates this archetype's position once, on enter, and never again. For scenery: a rock that has never moved does not need a motion model to say so.

public ArchetypeProjectionBuilder Position<TComponent>(Comp<TComponent> component) where TComponent : unmanaged

Parameters

component Comp<TComponent>

The component handle.

Returns

ArchetypeProjectionBuilder

This builder.

Type Parameters

TComponent

The component carrying the position.