Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Schema

A module used to create schema—component templates.

Index

Type aliases

Id

Id<$Schema>: Opaque<Entity.Id, $Schema>

An entity id wrapped in a generic type that allows Harmony to infer the component shape from the underlying primitive type.

Type parameters

  • $Schema: AnySchema = AnySchema

NativeSchema

NativeSchema<$Shape>: $Shape extends Shape<NativeScalarSchema> ? Schema.Id<NativeScalarSchema<$Shape>> : $Shape extends Shape<NativeObjectSchema> ? Schema.Id<NativeObjectSchema<$Shape>> : never

A schema whose components are standard JavaScript objects or scalar values. Unlike binary components, native components are stored in an array-of- structs architecture.

Type parameters

  • $Shape: Shape<AnyNativeSchema>

BinarySchema

BinarySchema<$Shape>: $Shape extends Shape<BinaryScalarSchema> ? Schema.Id<BinaryScalarSchema<$Shape>> : $Shape extends Shape<BinaryStructSchema> ? Schema.Id<BinaryStructSchema<$Shape>> : never

A schema whose components are stored in one or more TypedArrays. If the schema shape is complex (i.e non-scalar), derived components will be stored in a struct-of-array architecture, where each component field is allocated a separate, tightly-packed TypedArray.

Type parameters

  • $Shape: Shape<AnyBinarySchema>

Functions

make

  • Create a native schema. Returns an id that can be used to reference the schema throughout Harmony's API.

    example

    Create a scalar native schema

    const Health = Schema.make(world, Format.uint32)
    
    example

    Create a complex native schema

    const Position = Schema.make(world, {
    x: Format.float64,
    y: Format.float64
    })

    Type parameters

    Parameters

    • world: World.Struct
    • shape: $Shape
    • Optional reserve: number

    Returns NativeSchema<$Shape>

makeBinary

  • Create a binary schema. Returns an id that is used to reference the schema throughout Harmony's API.

    example

    Create a scalar binary schema

    const Health = Schema.makeBinary(world, Format.uint32)
    
    example

    Create a complex binary schema

    const Position = Schema.makeBinary(world, {
    x: Format.float64,
    y: Format.float64
    })

    Type parameters

    Parameters

    • world: World.Struct
    • shape: $Shape
    • Optional reserve: number

    Returns BinarySchema<$Shape>

makeTag

  • Create a tag schema – a data-less, lightweight component type that is faster than complex or scalar components since there is no data to copy when moving an entity between archetypes.

    Returns an id that is used to reference the schema throughout Harmony's API.

    example

    Create a tag schema

    const Frozen = Schema.makeTag(world)
    

    Parameters

    Returns Schema.Id<TagSchema>

Generated using TypeDoc