Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/soa

Index

Type aliases

AOSSpecs

AOSSpecs<K>: Record<K, Partial<AOSAttribSpec>>

Alias for main config object of attribute specs. Declares an object of partial SOAAttribSpec values (i.e. every item is made optional)

Type parameters

  • K: string

SOASpecs

SOASpecs<K>: Record<K, Partial<SOAAttribSpec>>

Alias for main config object of attribute specs. Declares an object of partial SOAAttribSpec values (i.e. every item is made optional)

Type parameters

  • K: string

SOATuple

SOATuple<K, V>: Record<K, V>

Mapped type for index lookups. Declares an object with all keys from given SOAAttribSpec and each value a Vec.

Type parameters

  • K: string

  • V

SerializedTuple

SerializedTuple<T>: { [ P in keyof T]: SerializedType<T, P> }

Type parameters

SerializedType

SerializedType<T, K>: ReturnType<T[K]["decode"]>

Type parameters

SerializerSpecs

SerializerSpecs: Record<string, SerializerPair<any>>

Variables

ident

ident: SerializerPair<Vec> = ...

Identity serializer pair (no op).

scalar

scalar: SerializerPair<number> = ...

Serializer pair for scalars.

Functions

Const aos

  • aos<K>(num: number, specs: AOSSpecs<K>, buf?: ArrayBuffer, byteOffset?: number): SOA<K>
  • Constructs SOA instance from given attrib specs and optional ArrayBuffer (w/ optional start address / byte offset, which MUST be properly pre-aligned). The resulting layout will be an underlying interleaved AOS buffer with each attrib configured to map that same array buffer relative to the given byteOffset (default: 0). If no array buffer is given, a properly sized one will be created.

    First computes attrib offsets, alignments and the overall struct size, then configures buffer views and strides for each attrib. This is to ensure each attrib is correctly mapped in its buffer view (e.g. float values need to be aligned to 4-byte boundaries). The overall inter-struct packing/stride length is dependent on the largest attrib type used. E.g. the following specs will cause a stride length of 16 bytes between each resulting SOA element, even though the actual struct size is only 13 bytes:

    example
    aos(
    1024,
    {
    a: { type: "u16", size: 1 }, // 2 bytes, align 2, offset 0
    b: { type: "f32", size: 2 }, // 8 bytes, align 4, offset 4
    c: { type: "u8", size: 1 }, // 1 byte, align 1, offset 12
    }
    );

    Type parameters

    • K: string

    Parameters

    • num: number
    • specs: AOSSpecs<K>
    • Optional buf: ArrayBuffer
    • byteOffset: number = 0

    Returns SOA<K>

Const serializer

Const soa

Const utf8z

  • Zero-terminated UTF-8 string serializer pair for given max length (incl. final \0 char).

    SerializerPair.encode throws error if resulting byte sequence is larger than configured maxLen.

    Parameters

    • maxLen: number

    Returns SerializerPair<string>

Generated using TypeDoc