/** * ECS -- Entity, Part, System, World. * * Composition over inheritance. Entities are bags of parts, * systems operate on entities matching part queries. * * @module */ import type { Scope, Schema } from 'effect'; import { Effect } from 'effect'; /** Nominal-typed identifier for an ECS entity — a branded string minted via the {@link EntityId} helper. */ export type EntityId = string & { readonly _brand: 'EntityId'; }; /** Brand an arbitrary string as an `EntityId`. Sanctioned single-site cast. */ export declare const EntityId: (value: string) => EntityId; interface EntityShape { readonly id: EntityId; readonly components: ReadonlyMap; } interface PartShape { readonly name: string; readonly schema: Schema.Schema; } interface DenseStoreShape { readonly name: string; readonly capacity: number; readonly _dense: true; /** Entity ID `->` index in the data array */ readonly entityToIndex: Map; /** Index `->` Entity ID (for iteration) */ readonly indexToEntity: EntityId[]; /** The raw Float64Array backing store */ readonly data: Float64Array; /** Current number of live entries */ count: number; get(entityId: EntityId): number | undefined; set(entityId: EntityId, value: number): void; has(entityId: EntityId): boolean; delete(entityId: EntityId): boolean; reset(): void; /** Direct typed array view for tight-loop iteration (length = count) */ view(): Float64Array; /** All entity IDs with values, in dense order */ entities(): readonly EntityId[]; } interface DenseSystemShape { readonly name: string; readonly query: readonly string[]; readonly _denseSystem: true; /** * Execute receives dense stores keyed by component name. * Systems iterate the typed arrays directly -- zero allocation per tick. */ execute(stores: ReadonlyMap): Effect.Effect; } interface SystemShape { readonly name: string; readonly query: readonly string[]; readonly _denseSystem?: undefined; /** Second argument is the world — use it to write computed output components back. */ execute(entities: readonly EntityShape[], world?: WorldShape): Effect.Effect; } type AnySystemShape = SystemShape | DenseSystemShape; interface WorldShape { spawn(components?: Record): Effect.Effect; despawn(id: EntityId): Effect.Effect; addComponent(id: EntityId, component: PartShape, value: T): Effect.Effect; /** Schema-free component write — used by systems to persist computed output values. */ setComponent(id: EntityId, name: string, value: unknown): Effect.Effect; removeComponent(id: EntityId, name: string): Effect.Effect; query(...componentNames: string[]): Effect.Effect; addSystem(system: AnySystemShape): Effect.Effect; tick(): Effect.Effect; /** Register a dense store so the world can wire it into dense systems */ addDenseStore(store: DenseStoreShape): Effect.Effect; } declare function _makeWorld(): Effect.Effect; /** * Part namespace — factories for ECS component stores. * * Currently exposes the dense `Float64Array`-backed store used for hot-path * numeric state; sparse/object-valued parts are registered ad-hoc via * {@link World}.`addComponent`. */ export declare const Part: { dense: (name: string, capacity: number) => DenseStoreShape; } & Record; /** World namespace — construct the ECS world that ticks systems over entities. */ export declare const World: { /** Scoped Effect that produces a fresh ECS {@link World.Shape}. */ make: typeof _makeWorld; }; export declare namespace Part { /** Structural shape of a typed component definition (`name` + schema). */ type Shape = PartShape; /** Alias for the dense `Float64Array`-backed store. */ type Dense = DenseStoreShape; } export declare namespace World { /** Structural shape of an ECS world: spawn/despawn, components, queries, systems, tick. */ type Shape = WorldShape; } export type { EntityShape as Entity, SystemShape as System, DenseSystemShape as DenseSystem, DenseStoreShape as DenseStore, }; //# sourceMappingURL=ecs.d.ts.map