Skip to content

1681-engine / index / FieldKind

Type Alias: FieldKind ​

ts
type FieldKind = "f32" | "f64" | "i8" | "i16" | "i32" | "u8" | "u16" | "u32";

Defined in: src/ecs/fields.ts:17

Numeric components stored as columns of typed arrays instead of one object per entity: Position.x and Position.y are two Float32Arrays indexed by the entity's slot. A system walking thousands of bodies then reads memory in order and makes no garbage, which is several times faster than objects at scale (see bench/).

ts
const Position = defineFields('Position', { x: 'f32', y: 'f32' });
world.add(e, Position, { x: 10, y: 20 });
const p = world.columns(Position); // fetch per run: columns grow (and are replaced) as entities are added
world.each(Position, (e, i) => { p.x[i] += 1; });

In each/query a field component's value is the entity's slot index i, the index into every column.

Released under the MIT License.