@oasys/oecs 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +553 -0
- package/README.md +207 -267
- package/dist/core/ecs/access_check.d.cts +77 -0
- package/dist/core/ecs/access_check.d.ts +77 -0
- package/dist/core/ecs/access_check.d.ts.map +1 -0
- package/dist/core/ecs/archetype.d.cts +486 -0
- package/dist/core/ecs/archetype.d.ts +486 -0
- package/dist/core/ecs/archetype.d.ts.map +1 -0
- package/dist/core/ecs/archetype_graph.d.cts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts.map +1 -0
- package/dist/core/ecs/builtin_relations.d.cts +43 -0
- package/dist/core/ecs/builtin_relations.d.ts +43 -0
- package/dist/core/ecs/builtin_relations.d.ts.map +1 -0
- package/dist/core/ecs/command_log.d.cts +116 -0
- package/dist/core/ecs/command_log.d.ts +116 -0
- package/dist/core/ecs/command_log.d.ts.map +1 -0
- package/dist/core/ecs/component.d.cts +176 -0
- package/dist/core/ecs/component.d.ts +176 -0
- package/dist/core/ecs/component.d.ts.map +1 -0
- package/dist/core/ecs/compute_backend.d.cts +37 -0
- package/dist/core/ecs/compute_backend.d.ts +37 -0
- package/dist/core/ecs/compute_backend.d.ts.map +1 -0
- package/dist/core/ecs/debug_names.d.cts +7 -0
- package/dist/core/ecs/debug_names.d.ts +7 -0
- package/dist/core/ecs/debug_names.d.ts.map +1 -0
- package/dist/core/ecs/deferred_commands.d.cts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
- package/dist/core/ecs/dispatch_trace.d.cts +93 -0
- package/dist/core/ecs/dispatch_trace.d.ts +93 -0
- package/dist/core/ecs/dispatch_trace.d.ts.map +1 -0
- package/dist/core/ecs/ecs.d.cts +562 -0
- package/dist/core/ecs/ecs.d.ts +562 -0
- package/dist/core/ecs/ecs.d.ts.map +1 -0
- package/dist/core/ecs/ecs_memory.d.cts +179 -0
- package/dist/core/ecs/ecs_memory.d.ts +179 -0
- package/dist/core/ecs/ecs_memory.d.ts.map +1 -0
- package/dist/core/ecs/entity.d.cts +34 -0
- package/dist/core/ecs/entity.d.ts +34 -0
- package/dist/core/ecs/entity.d.ts.map +1 -0
- package/dist/core/ecs/entity_allocator.d.cts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
- package/dist/core/ecs/event.d.cts +79 -0
- package/dist/core/ecs/event.d.ts +79 -0
- package/dist/core/ecs/event.d.ts.map +1 -0
- package/dist/core/ecs/event_registry.d.cts +22 -0
- package/dist/core/ecs/event_registry.d.ts +22 -0
- package/dist/core/ecs/event_registry.d.ts.map +1 -0
- package/dist/core/ecs/facades.d.cts +158 -0
- package/dist/core/ecs/facades.d.ts +158 -0
- package/dist/core/ecs/facades.d.ts.map +1 -0
- package/dist/core/ecs/frame_stepper.d.cts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
- package/dist/core/ecs/frame_trace.d.cts +133 -0
- package/dist/core/ecs/frame_trace.d.ts +133 -0
- package/dist/core/ecs/frame_trace.d.ts.map +1 -0
- package/dist/core/ecs/host_commands.d.cts +274 -0
- package/dist/core/ecs/host_commands.d.ts +274 -0
- package/dist/core/ecs/host_commands.d.ts.map +1 -0
- package/dist/core/ecs/index.d.cts +46 -0
- package/dist/core/ecs/index.d.ts +46 -0
- package/dist/core/ecs/index.d.ts.map +1 -0
- package/dist/core/ecs/observer.d.cts +173 -0
- package/dist/core/ecs/observer.d.ts +173 -0
- package/dist/core/ecs/observer.d.ts.map +1 -0
- package/dist/core/ecs/query.d.cts +718 -0
- package/dist/core/ecs/query.d.ts +718 -0
- package/dist/core/ecs/query.d.ts.map +1 -0
- package/dist/core/ecs/ref.d.cts +31 -0
- package/dist/core/ecs/ref.d.ts +31 -0
- package/dist/core/ecs/ref.d.ts.map +1 -0
- package/dist/core/ecs/relation.d.cts +243 -0
- package/dist/core/ecs/relation.d.ts +243 -0
- package/dist/core/ecs/relation.d.ts.map +1 -0
- package/dist/core/ecs/relation_service.d.cts +235 -0
- package/dist/core/ecs/relation_service.d.ts +235 -0
- package/dist/core/ecs/relation_service.d.ts.map +1 -0
- package/dist/core/ecs/resource.d.cts +53 -0
- package/dist/core/ecs/resource.d.ts +53 -0
- package/dist/core/ecs/resource.d.ts.map +1 -0
- package/dist/core/ecs/resource_registry.d.cts +20 -0
- package/dist/core/ecs/resource_registry.d.ts +20 -0
- package/dist/core/ecs/resource_registry.d.ts.map +1 -0
- package/dist/core/ecs/resume.d.cts +85 -0
- package/dist/core/ecs/resume.d.ts +85 -0
- package/dist/core/ecs/resume.d.ts.map +1 -0
- package/dist/core/ecs/run_condition.d.cts +81 -0
- package/dist/core/ecs/run_condition.d.ts +81 -0
- package/dist/core/ecs/run_condition.d.ts.map +1 -0
- package/dist/core/ecs/schedule.d.cts +142 -0
- package/dist/core/ecs/schedule.d.ts +142 -0
- package/dist/core/ecs/schedule.d.ts.map +1 -0
- package/dist/core/ecs/snapshot_service.d.cts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
- package/dist/core/ecs/sparse_store.d.cts +110 -0
- package/dist/core/ecs/sparse_store.d.ts +110 -0
- package/dist/core/ecs/sparse_store.d.ts.map +1 -0
- package/dist/core/ecs/store.d.cts +950 -0
- package/dist/core/ecs/store.d.ts +950 -0
- package/dist/core/ecs/store.d.ts.map +1 -0
- package/dist/core/ecs/store_layout_listener.d.cts +23 -0
- package/dist/core/ecs/store_layout_listener.d.ts +23 -0
- package/dist/core/ecs/store_layout_listener.d.ts.map +1 -0
- package/dist/core/ecs/system.d.cts +250 -0
- package/dist/core/ecs/system.d.ts +250 -0
- package/dist/core/ecs/system.d.ts.map +1 -0
- package/dist/core/ecs/utils/arrays.d.cts +7 -0
- package/dist/{utils → core/ecs/utils}/arrays.d.ts +2 -1
- package/dist/core/ecs/utils/arrays.d.ts.map +1 -0
- package/dist/core/ecs/utils/constants.d.ts +12 -0
- package/dist/core/ecs/utils/constants.d.ts.map +1 -0
- package/dist/core/ecs/utils/error.d.cts +61 -0
- package/dist/core/ecs/utils/error.d.ts +61 -0
- package/dist/core/ecs/utils/error.d.ts.map +1 -0
- package/dist/core/store/action_ring.d.cts +136 -0
- package/dist/core/store/action_ring.d.ts +136 -0
- package/dist/core/store/action_ring.d.ts.map +1 -0
- package/dist/core/store/allocator.d.cts +238 -0
- package/dist/core/store/allocator.d.ts +238 -0
- package/dist/core/store/allocator.d.ts.map +1 -0
- package/dist/core/store/buffer_backed_column.d.cts +69 -0
- package/dist/core/store/buffer_backed_column.d.ts +69 -0
- package/dist/core/store/buffer_backed_column.d.ts.map +1 -0
- package/dist/core/store/column_store.d.cts +273 -0
- package/dist/core/store/column_store.d.ts +273 -0
- package/dist/core/store/column_store.d.ts.map +1 -0
- package/dist/core/store/command_dispatch.d.cts +52 -0
- package/dist/core/store/command_dispatch.d.ts +52 -0
- package/dist/core/store/command_dispatch.d.ts.map +1 -0
- package/dist/core/store/command_ring.d.cts +107 -0
- package/dist/core/store/command_ring.d.ts +107 -0
- package/dist/core/store/command_ring.d.ts.map +1 -0
- package/dist/core/store/descriptor.d.cts +80 -0
- package/dist/core/store/descriptor.d.ts +80 -0
- package/dist/core/store/descriptor.d.ts.map +1 -0
- package/dist/core/store/entity_index.d.cts +108 -0
- package/dist/core/store/entity_index.d.ts +108 -0
- package/dist/core/store/entity_index.d.ts.map +1 -0
- package/dist/core/store/event_ring.d.cts +95 -0
- package/dist/core/store/event_ring.d.ts +95 -0
- package/dist/core/store/event_ring.d.ts.map +1 -0
- package/dist/core/store/extend.d.cts +39 -0
- package/dist/core/store/extend.d.ts +39 -0
- package/dist/core/store/extend.d.ts.map +1 -0
- package/dist/core/store/grow.d.cts +34 -0
- package/dist/core/store/grow.d.ts +34 -0
- package/dist/core/store/grow.d.ts.map +1 -0
- package/dist/core/store/header.d.cts +64 -0
- package/dist/core/store/header.d.ts +64 -0
- package/dist/core/store/header.d.ts.map +1 -0
- package/dist/core/store/index.d.cts +17 -0
- package/dist/core/store/index.d.ts +17 -0
- package/dist/core/store/index.d.ts.map +1 -0
- package/dist/core/store/layout_ops.d.cts +152 -0
- package/dist/core/store/layout_ops.d.ts +152 -0
- package/dist/core/store/layout_ops.d.ts.map +1 -0
- package/dist/core/store/region_table.d.cts +74 -0
- package/dist/core/store/region_table.d.ts +74 -0
- package/dist/core/store/region_table.d.ts.map +1 -0
- package/dist/core/store/snapshot.d.cts +43 -0
- package/dist/core/store/snapshot.d.ts +43 -0
- package/dist/core/store/snapshot.d.ts.map +1 -0
- package/dist/core/store/state_hash.d.cts +38 -0
- package/dist/core/store/state_hash.d.ts +38 -0
- package/dist/core/store/state_hash.d.ts.map +1 -0
- package/dist/core/store/store_regions.d.cts +38 -0
- package/dist/core/store/store_regions.d.ts +38 -0
- package/dist/core/store/store_regions.d.ts.map +1 -0
- package/dist/core/store/vendored_abi/abi.d.cts +43 -0
- package/dist/core/store/vendored_abi/abi.d.ts +43 -0
- package/dist/core/store/vendored_abi/abi.d.ts.map +1 -0
- package/dist/dev_flag.d.cts +17 -0
- package/dist/dev_flag.d.ts +17 -0
- package/dist/dev_flag.d.ts.map +1 -0
- package/dist/extensions/editor/editor.d.cts +170 -0
- package/dist/extensions/editor/editor.d.ts +170 -0
- package/dist/extensions/editor/editor.d.ts.map +1 -0
- package/dist/extensions/editor/field_handle.d.cts +40 -0
- package/dist/extensions/editor/field_handle.d.ts +40 -0
- package/dist/extensions/editor/field_handle.d.ts.map +1 -0
- package/dist/extensions/editor/index.cjs +1 -0
- package/dist/extensions/editor/index.d.cts +21 -0
- package/dist/extensions/editor/index.d.ts +21 -0
- package/dist/extensions/editor/index.d.ts.map +1 -0
- package/dist/extensions/editor/index.js +237 -0
- package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
- package/dist/extensions/reactive/ecs_sync.d.ts +214 -0
- package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -0
- package/dist/extensions/reactive/index.cjs +1 -0
- package/dist/extensions/reactive/index.d.cts +23 -0
- package/dist/extensions/reactive/index.d.ts +23 -0
- package/dist/extensions/reactive/index.d.ts.map +1 -0
- package/dist/extensions/reactive/index.js +215 -0
- package/dist/extensions/solid/index.cjs +1 -0
- package/dist/extensions/solid/index.d.cts +6 -0
- package/dist/extensions/solid/index.d.ts +6 -0
- package/dist/extensions/solid/index.d.ts.map +1 -0
- package/dist/extensions/solid/index.js +36 -0
- package/dist/extensions/solid/kernel_solid.d.cts +45 -0
- package/dist/extensions/solid/kernel_solid.d.ts +45 -0
- package/dist/extensions/solid/kernel_solid.d.ts.map +1 -0
- package/dist/host_commands-BF8QMi3c.cjs +1 -0
- package/dist/host_commands-i4cAeyL5.js +2318 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +65 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7080 -1289
- package/dist/internal.cjs +2 -0
- package/dist/internal.d.cts +20 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +141 -0
- package/dist/interop-CT-REx0W.cjs +1 -0
- package/dist/interop-CcY6ASQc.js +18 -0
- package/dist/kernel-DgyrLFjW.js +227 -0
- package/dist/kernel-yWV3XnAb.cjs +1 -0
- package/dist/primitives.cjs +1 -0
- package/dist/primitives.d.cts +18 -0
- package/dist/primitives.d.ts +18 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +45 -0
- package/dist/reactive/array.d.cts +24 -0
- package/dist/reactive/array.d.ts +24 -0
- package/dist/reactive/array.d.ts.map +1 -0
- package/dist/reactive/index.cjs +1 -0
- package/dist/reactive/index.d.cts +11 -0
- package/dist/reactive/index.d.ts +11 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/index.js +18 -0
- package/dist/reactive/interop.d.cts +19 -0
- package/dist/reactive/interop.d.ts +19 -0
- package/dist/reactive/interop.d.ts.map +1 -0
- package/dist/reactive/kernel.d.cts +73 -0
- package/dist/reactive/kernel.d.ts +73 -0
- package/dist/reactive/kernel.d.ts.map +1 -0
- package/dist/reactive/map.d.cts +16 -0
- package/dist/reactive/map.d.ts +16 -0
- package/dist/reactive/map.d.ts.map +1 -0
- package/dist/reactive/shallow.d.cts +11 -0
- package/dist/reactive/shallow.d.ts +11 -0
- package/dist/reactive/shallow.d.ts.map +1 -0
- package/dist/reactive/struct.d.cts +10 -0
- package/dist/reactive/struct.d.ts +10 -0
- package/dist/reactive/struct.d.ts.map +1 -0
- package/dist/shallow-DQ8aG51_.cjs +1 -0
- package/dist/shallow-DfnAm9vG.js +150 -0
- package/dist/shared-BU1Cd40h.js +103 -0
- package/dist/shared-BymrGTyR.cjs +1 -0
- package/dist/shared.cjs +1 -0
- package/dist/shared.d.cts +22 -0
- package/dist/shared.d.ts +22 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +7 -0
- package/dist/topological_sort-BDvEyb9W.cjs +1 -0
- package/dist/topological_sort-DK6EjpWa.js +135 -0
- package/dist/type_primitives/assertions.d.cts +32 -0
- package/dist/type_primitives/assertions.d.ts +25 -9
- package/dist/type_primitives/assertions.d.ts.map +1 -1
- package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
- package/dist/type_primitives/binary_heap/binary_heap.d.ts +6 -2
- package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -1
- package/dist/type_primitives/bitset/bitset.d.cts +54 -0
- package/dist/type_primitives/bitset/bitset.d.ts +16 -4
- package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
- package/dist/type_primitives/brand.d.cts +23 -0
- package/dist/type_primitives/brand.d.ts +6 -1
- package/dist/type_primitives/brand.d.ts.map +1 -1
- package/dist/type_primitives/error.d.cts +16 -0
- package/dist/type_primitives/error.d.ts +8 -3
- package/dist/type_primitives/error.d.ts.map +1 -1
- package/dist/type_primitives/index.d.cts +13 -0
- package/dist/type_primitives/index.d.ts +12 -9
- package/dist/type_primitives/index.d.ts.map +1 -1
- package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
- package/dist/type_primitives/sparse_map/sparse_map.d.ts +7 -3
- package/dist/type_primitives/sparse_map/sparse_map.d.ts.map +1 -1
- package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
- package/dist/type_primitives/sparse_set/sparse_set.d.ts +4 -0
- package/dist/type_primitives/sparse_set/sparse_set.d.ts.map +1 -1
- package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
- package/dist/type_primitives/topological_sort/topological_sort.d.ts +7 -3
- package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -1
- package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +53 -16
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
- package/dist/typed_arrays-BcXcnzB4.js +258 -0
- package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
- package/dist/utils/error.d.cts +6 -0
- package/dist/utils/error.d.ts +2 -20
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/version.d.cts +10 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +115 -5
- package/dist/archetype.d.ts +0 -108
- package/dist/archetype.d.ts.map +0 -1
- package/dist/component.d.ts +0 -45
- package/dist/component.d.ts.map +0 -1
- package/dist/ecs.d.ts +0 -104
- package/dist/ecs.d.ts.map +0 -1
- package/dist/entity.d.ts +0 -11
- package/dist/entity.d.ts.map +0 -1
- package/dist/event.d.ts +0 -30
- package/dist/event.d.ts.map +0 -1
- package/dist/query.d.ts +0 -94
- package/dist/query.d.ts.map +0 -1
- package/dist/ref.d.ts +0 -23
- package/dist/ref.d.ts.map +0 -1
- package/dist/resource.d.ts +0 -23
- package/dist/resource.d.ts.map +0 -1
- package/dist/schedule.d.ts +0 -45
- package/dist/schedule.d.ts.map +0 -1
- package/dist/store.d.ts +0 -118
- package/dist/store.d.ts.map +0 -1
- package/dist/system.d.ts +0 -16
- package/dist/system.d.ts.map +0 -1
- package/dist/utils/arrays.d.ts.map +0 -1
- package/dist/utils/constants.d.ts.map +0 -1
- /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { Template, TemplateEntries, TemplateOverrides } from './store.cjs';
|
|
2
|
+
import { FrameTraceSink } from './frame_trace.cjs';
|
|
3
|
+
import { ObserverHandle, EntitySetObserverConfig, ArchetypeSetObserverConfig, StructuralObserverConfig } from './observer.cjs';
|
|
4
|
+
import { ColumnStore, ColumnStoreRegionHandle, StoreRegionSpec } from '../store/index.cjs';
|
|
5
|
+
import { ECSRelations, ECSEvents, ECSResources, ECSSnapshots } from './facades.cjs';
|
|
6
|
+
import { SCHEDULE, SystemEntry, SystemSet, SystemSetConfig } from './schedule.cjs';
|
|
7
|
+
import { Archetype, ArchetypeID } from './archetype.cjs';
|
|
8
|
+
import { SystemContext, Query, QueryBuilder, QueryCache, QueryResolver } from './query.cjs';
|
|
9
|
+
import { EntityID } from './entity.cjs';
|
|
10
|
+
import { ReadonlyComponentRef } from './ref.cjs';
|
|
11
|
+
import { ComponentDef, ComponentHandle, ComponentRegisterOptions, ComponentSchema, CompleteFieldValues, Bundle, BundleOrDef } from './component.cjs';
|
|
12
|
+
import { SparseComponentDef, SparseComponentID } from './sparse_store.cjs';
|
|
13
|
+
import { RelationDef } from './relation.cjs';
|
|
14
|
+
import { SystemFn, SystemConfig, SystemDescriptor, TypedSystemConfig, DenseAccessDecl, SpawnsAccessDecl, DespawnsAccessDecl, TransitionsAccessDecl, SparseAccessDecl, RelationsAccessDecl, ResourcesAccessDecl } from './system.cjs';
|
|
15
|
+
import { BitSet, TypedArrayTag } from '../../type_primitives/index.cjs';
|
|
16
|
+
import { StoreLayoutListener } from './store_layout_listener.cjs';
|
|
17
|
+
import { ComputeBackend } from './compute_backend.cjs';
|
|
18
|
+
import { ResolvedECSMemory, ECSMemoryOptions } from './ecs_memory.cjs';
|
|
19
|
+
export interface ECSOptions {
|
|
20
|
+
fixedTimestep?: number;
|
|
21
|
+
maxFixedSteps?: number;
|
|
22
|
+
/** Sink for dev-mode engine diagnostics (currently the schedule's
|
|
23
|
+
* dropped-ordering-edge warning). Defaults to `console.warn`. Mirrors the
|
|
24
|
+
* `FrameTraceSink` seam's injectable style — no global logger. */
|
|
25
|
+
onWarn?: (message: string) => void;
|
|
26
|
+
/** How the world's memory is sized and backed (#682) — the single
|
|
27
|
+
* sizing surface, replacing the pre-release `initialCapacity` +
|
|
28
|
+
* `bufferAllocator` pair. Express intent through exactly one arm:
|
|
29
|
+
* `{ budget: { entities } }` (derive everything), `{ maxBytes }`
|
|
30
|
+
* (explicit cap), `{ wasm: { memory } | { maximumPages } }` (the SAB
|
|
31
|
+
* IS a WebAssembly.Memory — zero-copy with a WASM `ComputeBackend`), or
|
|
32
|
+
* `{ allocator }` (expert escape hatch, in-place-typed per ADR-0008).
|
|
33
|
+
* Omitted ⇒ growable backing with a 256 MiB cap and 1024-row columns.
|
|
34
|
+
* The resolved plan is exposed as `ECS.memoryPlan`. */
|
|
35
|
+
memory?: ECSMemoryOptions;
|
|
36
|
+
/** Consumer-declared SAB regions (#623), forwarded to `Store`. Each
|
|
37
|
+
* `StoreRegionSpec` carries an opaque `region_id`, a precomputed byte size,
|
|
38
|
+
* and an `init` closure; the engine lays them out generically and exposes
|
|
39
|
+
* them via `regionHandle(id)` / `regionOffset(id)`. A game (e.g.
|
|
40
|
+
* `@internal/sim`'s region specs) supplies these — the engine ships no
|
|
41
|
+
* game regions of its own. Replaces the eight game-named region options
|
|
42
|
+
* (`terrain_map_radius`, `spatial_grid_*`, `army_*`, `flow_field_*`,
|
|
43
|
+
* `actionRingCapacitySlots`) the ECS used to carry. (ADR-0018.) */
|
|
44
|
+
regions?: readonly StoreRegionSpec[];
|
|
45
|
+
/** Byte size of the opt-in sim-bindings region (#625), forwarded to `Store`.
|
|
46
|
+
* A consumer that attaches a WASM `ComputeBackend` passes its own size — for
|
|
47
|
+
* this game, `@internal/sim`'s `SIM_BINDINGS_BYTES` (computed from the binding
|
|
48
|
+
* manifest) — so the host can publish the `(component_id, field_id)` IDs the
|
|
49
|
+
* accelerated systems read. Omitted / 0 ⇒ no region: a pure-TS world pays
|
|
50
|
+
* nothing for the WASM seam. The size is a runtime input, not an engine ABI
|
|
51
|
+
* constant, since #625 de-welded it from the generated ABI. */
|
|
52
|
+
bindingsRegionBytes?: number;
|
|
53
|
+
/** Opt into the **determinism surface** (#626 / ADR-0020), forwarded to
|
|
54
|
+
* `Store`. Default `false`. When `false`, the canonical-ordering methods
|
|
55
|
+
* (`stateHash`, `snapshotSparse`, `restoreSparse`) throw
|
|
56
|
+
* `DETERMINISM_DISABLED`; when `true`, today's replay/hash behavior is
|
|
57
|
+
* reproduced bit-for-bit. Determinism is the implementer's choice — our
|
|
58
|
+
* server match opts in (replay verification), the client stays off (it rolls
|
|
59
|
+
* back via diffs, not re-sim). The flag gates ONLY that surface: memory-safety
|
|
60
|
+
* invariants (the in-place SAB allocator, ADR-0008) and the `enabled_count`
|
|
61
|
+
* partition are always-on regardless. */
|
|
62
|
+
deterministic?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export declare class ECS implements QueryResolver {
|
|
65
|
+
private readonly store;
|
|
66
|
+
private readonly schedule;
|
|
67
|
+
private readonly ctx;
|
|
68
|
+
/** Component observers (#517 §1 / ADR-0013). Inert until `observe(...)` is
|
|
69
|
+
* called — the structural-flush fast path is byte-for-byte unchanged. */
|
|
70
|
+
private readonly _observers;
|
|
71
|
+
/** Relations: register/add/remove/has, wildcard + traversal reads,
|
|
72
|
+
* reverse-index compaction. See `ECSRelations`. */
|
|
73
|
+
readonly relations: ECSRelations;
|
|
74
|
+
/** Host-side event channels + signals: register/registerSignal/emit/read
|
|
75
|
+
* (system-side `ctx.emit` is unchanged). See `ECSEvents`. */
|
|
76
|
+
readonly events: ECSEvents;
|
|
77
|
+
/** World resources: register/get/set/remove/has. See `ECSResources`. */
|
|
78
|
+
readonly resources: ECSResources;
|
|
79
|
+
/** Determinism surface: capture/restore (full + sparse), stateHash,
|
|
80
|
+
* the `deterministic` flag. See `ECSSnapshots`. */
|
|
81
|
+
readonly snapshots: ECSSnapshots;
|
|
82
|
+
private readonly systems;
|
|
83
|
+
private nextSystemId;
|
|
84
|
+
private _tick;
|
|
85
|
+
private _updating;
|
|
86
|
+
private _fixedTimestep;
|
|
87
|
+
private _accumulator;
|
|
88
|
+
private _maxFixedSteps;
|
|
89
|
+
private readonly scratchMask;
|
|
90
|
+
private _nextQueryIdCounter;
|
|
91
|
+
/** @internal Query-composition caches (QueryResolver seam) — not public API. */
|
|
92
|
+
readonly _caches: QueryCache;
|
|
93
|
+
private readonly _layoutSubscribers;
|
|
94
|
+
private _backend;
|
|
95
|
+
private readonly _memory;
|
|
96
|
+
/** What `ECSOptions.memory` resolved to (#682): backing allocator kind,
|
|
97
|
+
* column capacity, entity-index reservation, byte cap, and a
|
|
98
|
+
* human-readable derivation trace. Diagnostics surface — log it when
|
|
99
|
+
* sizing questions come up instead of reverse-engineering the SAB. */
|
|
100
|
+
get memoryPlan(): ResolvedECSMemory;
|
|
101
|
+
/** The backing `WebAssembly.Memory` when `memory.wasm` was used (both
|
|
102
|
+
* bring-your-own and engine-constructed), else `null`. A consumer hands
|
|
103
|
+
* this to its WASM `ComputeBackend` so the sim and the live columns
|
|
104
|
+
* share the same bytes. */
|
|
105
|
+
get wasmMemory(): WebAssembly.Memory | null;
|
|
106
|
+
constructor(options?: ECSOptions);
|
|
107
|
+
/** Batch variant of `regionHandle` for hosts wiring several consumer
|
|
108
|
+
* regions at startup: returns the handles in argument order, never null —
|
|
109
|
+
* throws ONE `REGION_NOT_DECLARED` naming every missing region id instead
|
|
110
|
+
* of a null-guard per region. Same staleness rule as `regionHandle`:
|
|
111
|
+
* re-fetch after a SAB grow. */
|
|
112
|
+
regionHandles(...regionIds: number[]): ColumnStoreRegionHandle[];
|
|
113
|
+
/** Subscribe to SAB-layout publications. `listener.setLayout(0)` is
|
|
114
|
+
* called immediately to seed the initial layout, then again after
|
|
115
|
+
* every SAB grow / extend (the `view_stamp` republish protocol).
|
|
116
|
+
* Returns an unsubscribe function.
|
|
117
|
+
*
|
|
118
|
+
* The engine has no concept of what subscribes — it publishes SAB layouts
|
|
119
|
+
* and walks away. A consumer subscribes whatever wrapper it owns (a compute
|
|
120
|
+
* backend, a Worker proxy, a debug recorder) and drives it from its own
|
|
121
|
+
* code. A `ComputeBackend` is subscribed automatically by `attachBackend`,
|
|
122
|
+
* so most consumers call that rather than this directly. */
|
|
123
|
+
onStoreLayoutPublished(listener: StoreLayoutListener): () => void;
|
|
124
|
+
/** Attach an opt-in compute backend (#622). Default is none: a bare `ECS`
|
|
125
|
+
* runs pure-TS systems and the schedule's dispatch is byte-for-byte the
|
|
126
|
+
* no-backend path. Once attached, a scheduled system carrying a
|
|
127
|
+
* `backendHandle` (its `SystemConfig`) is executed via `backend.run(handle)`
|
|
128
|
+
* instead of its `fn` closure; systems without a handle are unaffected.
|
|
129
|
+
*
|
|
130
|
+
* The backend is also subscribed as a SAB-layout listener (seeded now, then
|
|
131
|
+
* republished on every grow), folding in the `onStoreLayoutPublished` seam.
|
|
132
|
+
* Returns a detach function that unsubscribes the layout listener and reverts
|
|
133
|
+
* the schedule to the pure-TS path.
|
|
134
|
+
*
|
|
135
|
+
* One backend per ECS: attaching while one is already attached throws in
|
|
136
|
+
* `DEV` (detach first). The engine never inspects the backend beyond
|
|
137
|
+
* `setLayout` / `run` — it carries no game vocabulary. */
|
|
138
|
+
attachBackend(backend: ComputeBackend): () => void;
|
|
139
|
+
get fixedTimestep(): number;
|
|
140
|
+
set fixedTimestep(value: number);
|
|
141
|
+
get fixedAlpha(): number;
|
|
142
|
+
/** Attach (or detach with `null`) a per-world frame-trace sink (ADR-0030):
|
|
143
|
+
* the engine then fires structured `FrameTraceSink` events at each system,
|
|
144
|
+
* flush, command, observer firing, and event during `update()`, so a consumer
|
|
145
|
+
* can reconstruct exactly what travelled through the ECS each frame. The sink
|
|
146
|
+
* also receives a `phaseBoundary(phase)` at each phase's post-flush settle
|
|
147
|
+
* point — the safe seam to read `stateHash()` between phases of one frame and
|
|
148
|
+
* bisect a divergence to the exact phase (#797 / ADR-0032). The seam is
|
|
149
|
+
* `DEV`-gated end to end — in a production build this setter keeps an empty
|
|
150
|
+
* body and the world never retains a sink. The sink only observes; it does not
|
|
151
|
+
* perturb `stateHash`, ordering, or any behaviour. */
|
|
152
|
+
setTrace(sink: FrameTraceSink | null): void;
|
|
153
|
+
/**
|
|
154
|
+
* Register a dense component and get back its typed handle. Record syntax
|
|
155
|
+
* gives per-field type control; the array shorthand types every field the
|
|
156
|
+
* same (default `"f64"` — rejected on a `{ deterministic: true }` world
|
|
157
|
+
* (#777), pass an explicit integer type there). An empty schema `{}` is a
|
|
158
|
+
* tag. `opts.name` labels dev-mode diagnostics (`'Pos' (component 5)`
|
|
159
|
+
* instead of `component 5`) — diagnostic only, no behavioural effect.
|
|
160
|
+
*
|
|
161
|
+
* The handle is *callable*: `Pos({ x: 1 })` mints a `Bundle` for the
|
|
162
|
+
* attach surfaces (`spawnBundle`, `ctx.commands.spawn`, `addComponent`).
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const Pos = ecs.registerComponent({ x: "f64", y: "f64" });
|
|
166
|
+
* const Hp = ecs.registerComponent(["current", "max"], "i32");
|
|
167
|
+
* const Frozen = ecs.registerComponent({}, { name: "Frozen" }); // tag
|
|
168
|
+
* ecs.getField(e, Pos, "x"); // field names/types flow from the schema
|
|
169
|
+
*/
|
|
170
|
+
registerComponent<S extends Record<string, TypedArrayTag>>(schema: S, opts?: ComponentRegisterOptions): ComponentDef<S>;
|
|
171
|
+
registerComponent<const F extends readonly string[], T extends TypedArrayTag = "f64">(fields: F, type?: T, opts?: ComponentRegisterOptions): ComponentDef<{
|
|
172
|
+
readonly [K in F[number]]: T;
|
|
173
|
+
}>;
|
|
174
|
+
registerSparseComponent<S extends Record<string, TypedArrayTag>>(schema: S, opts?: ComponentRegisterOptions): SparseComponentDef<S>;
|
|
175
|
+
registerSparseComponent<const F extends readonly string[], T extends TypedArrayTag = "f64">(fields: F, type?: T, opts?: ComponentRegisterOptions): SparseComponentDef<{
|
|
176
|
+
readonly [K in F[number]]: T;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Spawn an entity, immediately. Bare `spawn()` creates an empty entity —
|
|
180
|
+
* attach components afterward. `spawn(template, overrides?)` lands
|
|
181
|
+
* directly in the template's archetype with zero archetype transitions,
|
|
182
|
+
* applying optional flat per-field overrides on top of the template
|
|
183
|
+
* defaults. Inside a system use `ctx.commands.spawn(...)` instead.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const e = ecs.spawn();
|
|
187
|
+
* ecs.addComponent(e, Pos, { x: 0, y: 0 });
|
|
188
|
+
*
|
|
189
|
+
* const Bullet = ecs.template([{ def: Pos, values: { x: 0, y: 0 } }]);
|
|
190
|
+
* const b = ecs.spawn(Bullet, { x: 5 }); // override a template default
|
|
191
|
+
*/
|
|
192
|
+
spawn(): EntityID;
|
|
193
|
+
spawn<Defs extends readonly ComponentDef[]>(template: Template<Defs>, overrides?: TemplateOverrides<Defs>): EntityID;
|
|
194
|
+
/**
|
|
195
|
+
* Spawn an entity from varargs bundles (§bundles) — the immediate
|
|
196
|
+
* host-side analog of `ctx.commands.spawn`. `ecs.spawnBundle(bundle(Pos,{x,y}),
|
|
197
|
+
* bundle(Vel,{vx:1}), IsEnemy)` collapses the five attach shapes into one. Each
|
|
198
|
+
* bundle is applied immediately; a single combined-archetype insertion (one
|
|
199
|
+
* transition instead of one-per-component) is a later optimization — for the
|
|
200
|
+
* prototype this mirrors the existing per-component `addComponent` path.
|
|
201
|
+
*/
|
|
202
|
+
spawnBundle(...items: BundleOrDef[]): EntityID;
|
|
203
|
+
/** DEV-only: throw when an *immediate* host structural mutator is called
|
|
204
|
+
* from inside one of THIS world's system bodies (or an observer / onAdded
|
|
205
|
+
* hook — they run in the same access spans). One rule for every host
|
|
206
|
+
* mutator, not just despawn: an immediate structural op mid-schedule can
|
|
207
|
+
* move or swap rows a running query is walking, and it is invisible to
|
|
208
|
+
* observers. The archetype-level `_iterDepth` guard only catches mutations
|
|
209
|
+
* touching the archetype currently being iterated — an op landing elsewhere
|
|
210
|
+
* would silently skip observers, so the receiver rule ("inside a system,
|
|
211
|
+
* use ctx.commands") is enforced wholesale here.
|
|
212
|
+
*
|
|
213
|
+
* `_updating` scopes the guard to THIS world: the accessCheck slot is
|
|
214
|
+
* process-global, so without it a system of world A mutating world B (a
|
|
215
|
+
* supported #785 pattern — B is not mid-iteration) would false-throw. */
|
|
216
|
+
private _assertHostMutationOutsideSystem;
|
|
217
|
+
/** Immediately destroy an entity — `ecs.despawn(e); ecs.isAlive(e)` is
|
|
218
|
+
* `false` on the next line, matching the immediacy of every other host
|
|
219
|
+
* facade mutation. Inside a system the buffered path is
|
|
220
|
+
* `ctx.commands.despawn` (applied at the phase flush); calling this from
|
|
221
|
+
* a system body throws in DEV, since an immediate destroy mid-iteration
|
|
222
|
+
* can invalidate rows the running query is walking. */
|
|
223
|
+
despawn(id: EntityID): void;
|
|
224
|
+
/** Disable `id` (idempotent). Excluded from default queries until re-enabled. */
|
|
225
|
+
disable(id: EntityID): this;
|
|
226
|
+
/** Re-enable a disabled `id` (idempotent). */
|
|
227
|
+
enable(id: EntityID): this;
|
|
228
|
+
/**
|
|
229
|
+
* Attach a component to an entity, immediately (inside a system, use the
|
|
230
|
+
* deferred `ctx.commands.add`). Three shapes: a bare def attaches a tag; a
|
|
231
|
+
* bundle (`Pos({ x: 1 })`) zero-fills omitted fields; the explicit
|
|
232
|
+
* `(e, def, values)` form demands every field, so a typo'd or missing
|
|
233
|
+
* field is a compile error.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ecs.addComponent(e, Frozen); // tag
|
|
237
|
+
* ecs.addComponent(e, Pos({ x: 1 })); // bundle — y zero-fills
|
|
238
|
+
* ecs.addComponent(e, Pos, { x: 1, y: 2 }); // complete values
|
|
239
|
+
*/
|
|
240
|
+
addComponent(entityId: EntityID, def: ComponentDef<Record<string, never>>): this;
|
|
241
|
+
addComponent<S extends ComponentSchema>(entityId: EntityID, bundle: Bundle<S>): this;
|
|
242
|
+
addComponent<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
243
|
+
/** Batch-attach several components in one archetype transition. Each
|
|
244
|
+
* entry's `values` is checked against its own def's schema (a misspelled
|
|
245
|
+
* field is a compile error; tags refuse `values`) — same typing as
|
|
246
|
+
* `ECS.template` entries. Omitted fields zero-fill. */
|
|
247
|
+
addComponents<Defs extends readonly ComponentDef[]>(entityId: EntityID, entries: TemplateEntries<Defs>): this;
|
|
248
|
+
removeComponent(entityId: EntityID, def: ComponentDef): this;
|
|
249
|
+
removeComponents(entityId: EntityID, defs: ComponentDef[]): this;
|
|
250
|
+
/**
|
|
251
|
+
* Bulk add a component to ALL entities in the given archetype.
|
|
252
|
+
* O(columns) via TypedArray.set() instead of O(N×columns).
|
|
253
|
+
*
|
|
254
|
+
* Takes an `ArchetypeID` (from `ArchetypeView.id`) rather than a concrete
|
|
255
|
+
* `Archetype` — the concrete type is internal (issue #378).
|
|
256
|
+
*/
|
|
257
|
+
batchAddComponent(src: ArchetypeID, def: ComponentDef<Record<string, never>>): this;
|
|
258
|
+
batchAddComponent<S extends ComponentSchema>(src: ArchetypeID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
259
|
+
/**
|
|
260
|
+
* Bulk remove a component from ALL entities in the given archetype.
|
|
261
|
+
* O(columns) via TypedArray.set() instead of O(N×columns).
|
|
262
|
+
*
|
|
263
|
+
* Takes an `ArchetypeID` (from `ArchetypeView.id`); see `batchAddComponent`.
|
|
264
|
+
*/
|
|
265
|
+
batchRemoveComponent(src: ArchetypeID, def: ComponentDef): this;
|
|
266
|
+
getField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S): number;
|
|
267
|
+
/** Host-side parity with `SystemContext.refRead` (POLISH_AUDIT M7): a
|
|
268
|
+
* read-only whole-component view for tooling/tests, instead of reading
|
|
269
|
+
* field-by-field. Same advisory-`readonly` semantics as the ctx variant;
|
|
270
|
+
* no `_changedTick` bump. Dev-throws on a dead entity, or when the entity
|
|
271
|
+
* doesn't hold the component (tags included — no fields, nothing to ref).
|
|
272
|
+
*
|
|
273
|
+
* **Staleness:** unlike ctx refs (protected by deferred structural changes
|
|
274
|
+
* until the phase flush), host-side structural mutations apply immediately —
|
|
275
|
+
* any `addComponent`/`removeComponent`/`despawn` after creating the ref can
|
|
276
|
+
* row-swap so the old ref silently reads *another entity's* data. The ref is
|
|
277
|
+
* only valid until the next structural mutation; treat it as an immediate
|
|
278
|
+
* single-expression read and re-create it after any structural change. */
|
|
279
|
+
refRead<S extends ComponentSchema>(def: ComponentDef<S>, entityId: EntityID): ReadonlyComponentRef<S>;
|
|
280
|
+
/** Total sibling of {@link getField} (POLISH_AUDIT #9): `undefined` when the
|
|
281
|
+
* entity is dead or doesn't hold the component, instead of a dev throw /
|
|
282
|
+
* prod garbage read. The safe way to probe-and-read in one call:
|
|
283
|
+
* `ecs.tryGetField(e, Health, "current") ?? 0`. */
|
|
284
|
+
tryGetField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S): number | undefined;
|
|
285
|
+
setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): void;
|
|
286
|
+
/** Read-modify-write one field: `updateField(e, Gold, "value", v => v - cost)`
|
|
287
|
+
* is the one-line form of the `getField` → compute → `setField` round trip.
|
|
288
|
+
* Returns the written value. Same access-check and observer semantics as the
|
|
289
|
+
* two calls it composes. */
|
|
290
|
+
updateField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, fn: (current: number) => number): number;
|
|
291
|
+
/**
|
|
292
|
+
* Get the live, cached query matching entities that have **all** of
|
|
293
|
+
* `defs`. Queries are deduplicated by mask — calling this twice with the
|
|
294
|
+
* same terms returns the same instance — so build once at setup and reuse;
|
|
295
|
+
* the view stays live as archetypes appear. Refine with `.and()` /
|
|
296
|
+
* `.without()` / `.anyOf()`; iterate with `eachChunk` (mutating hot path),
|
|
297
|
+
* `forEach` (per-archetype), or `forEachEntity` (per-entity).
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* const movers = ecs.query(Pos, Vel);
|
|
301
|
+
* movers.eachChunk((cols, count) => {
|
|
302
|
+
* const { x, y } = cols.mut(Pos);
|
|
303
|
+
* const { vx, vy } = cols.read(Vel);
|
|
304
|
+
* for (let i = 0; i < count; i++) { x[i] += vx[i]; y[i] += vy[i]; }
|
|
305
|
+
* });
|
|
306
|
+
*/
|
|
307
|
+
query<T extends ComponentDef[]>(...defs: T): Query<T>;
|
|
308
|
+
_nextQueryId(): number;
|
|
309
|
+
/** QueryResolver implementation — creates or retrieves a cached Query. */
|
|
310
|
+
_resolveQuery(include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, defs: readonly ComponentDef[]): Query<any>;
|
|
311
|
+
/**
|
|
312
|
+
* Register a system and get its scheduling handle. The config form is the
|
|
313
|
+
* production shape: it declares the access surface (`reads` / `writes` are
|
|
314
|
+
* mandatory; `spawns` / `despawns` / resource and sparse/relation terms
|
|
315
|
+
* optional), which is enforced at runtime in dev *and* narrows `ctx` at
|
|
316
|
+
* the type level so undeclared access fails to compile. Registration does
|
|
317
|
+
* not schedule — pass the returned descriptor to
|
|
318
|
+
* `ecs.addSystems(SCHEDULE.UPDATE, ...)`.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* // Full config — declared access, dev-checked and compile-checked
|
|
322
|
+
* const move = ecs.registerSystem({
|
|
323
|
+
* reads: [Vel],
|
|
324
|
+
* writes: [Pos],
|
|
325
|
+
* fn(ctx, dt) {
|
|
326
|
+
* movers.eachChunk((cols, count) => { ... });
|
|
327
|
+
* },
|
|
328
|
+
* });
|
|
329
|
+
* ecs.addSystems(SCHEDULE.UPDATE, move);
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* // Bare function (no declared access — any component touch throws in dev)
|
|
333
|
+
* ecs.registerSystem((ctx, dt) => { ... });
|
|
334
|
+
* // Function + query builder (query resolved at registration time)
|
|
335
|
+
* ecs.registerSystem((q, ctx, dt) => { q.forEach((arch) => { ... }); }, (qb) => qb.with(Pos, Vel));
|
|
336
|
+
*/
|
|
337
|
+
registerSystem(fn: SystemFn): SystemDescriptor;
|
|
338
|
+
registerSystem<Defs extends readonly ComponentDef[]>(fn: (q: Query<Defs>, ctx: SystemContext, dt: number) => void, queryFn: (qb: QueryBuilder) => Query<Defs>): SystemDescriptor;
|
|
339
|
+
/** `exclusive: true` grants full world access at runtime (§system.ts), so
|
|
340
|
+
* the context stays fully permissive at the type layer too. Declared BEFORE
|
|
341
|
+
* the typed-config overload so exclusive configs never get narrowed. */
|
|
342
|
+
registerSystem(config: SystemConfig & {
|
|
343
|
+
readonly exclusive: true;
|
|
344
|
+
}): SystemDescriptor;
|
|
345
|
+
/** Config form (§typestate, system.ts): the declaration lists are inferred
|
|
346
|
+
* as literal tuples and `fn` / `onAdded` receive
|
|
347
|
+
* `SystemContext<DeclaredAccess<…>>` — undeclared access fails to compile
|
|
348
|
+
* with the same taxonomy the runtime `accessCheck` throws with in
|
|
349
|
+
* `DEV`. A config VALUE typed as plain `SystemConfig` (dynamically
|
|
350
|
+
* built) still matches: its erased declaration lists compute a permissive
|
|
351
|
+
* access record. Escape hatch: annotate `fn(ctx: SystemContext, dt)`
|
|
352
|
+
* explicitly to keep a system permissive at compile time. */
|
|
353
|
+
registerSystem<R extends DenseAccessDecl, W extends DenseAccessDecl, Sp extends SpawnsAccessDecl = readonly never[], De extends DespawnsAccessDecl = readonly never[], Tr extends TransitionsAccessDecl = readonly never[], SR extends SparseAccessDecl = readonly never[], SW extends SparseAccessDecl = readonly never[], RR extends RelationsAccessDecl = readonly never[], RW extends RelationsAccessDecl = readonly never[], QR extends ResourcesAccessDecl = readonly never[], QW extends ResourcesAccessDecl = readonly never[]>(config: TypedSystemConfig<R, W, Sp, De, Tr, SR, SW, RR, RW, QR, QW>): SystemDescriptor;
|
|
354
|
+
removeSystem(system: SystemDescriptor): void;
|
|
355
|
+
get systemCount(): number;
|
|
356
|
+
/**
|
|
357
|
+
* Run the startup phases, once, before the first `update()`. Prewarms
|
|
358
|
+
* every archetype the registered systems/observers can produce, runs each
|
|
359
|
+
* system's `onAdded` hook, then the `PRE_STARTUP` → `STARTUP` →
|
|
360
|
+
* `POST_STARTUP` schedule. Events emitted during startup are drained at
|
|
361
|
+
* its tail — they do not leak into frame 1.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ecs.addSystems(SCHEDULE.UPDATE, move);
|
|
365
|
+
* ecs.startup();
|
|
366
|
+
* ecs.update(1 / 60); // now tick every frame
|
|
367
|
+
*/
|
|
368
|
+
startup(): void;
|
|
369
|
+
/** Compute the archetype closure from every registered system's AND
|
|
370
|
+
* observer's `spawns` + `transitions` and ask the store to plant the
|
|
371
|
+
* whole set in one `extendColumnStore` call. Observers carry the same
|
|
372
|
+
* access shape systems do (a synthesized `SystemDescriptor`), so an
|
|
373
|
+
* observer that spawns/transitions gets its target archetype prewarmed
|
|
374
|
+
* too rather than first-touching lazily mid-tick (#768). Exposed as
|
|
375
|
+
* `private` because the only caller is `startup()`; visible to tests via
|
|
376
|
+
* the `archetype_count` delta on the public ECS facade. */
|
|
377
|
+
private prewarmArchetypes;
|
|
378
|
+
/**
|
|
379
|
+
* Advance the world one frame. Runs the fixed-timestep accumulator loop
|
|
380
|
+
* (`FIXED_UPDATE`, when any fixed system is registered), then
|
|
381
|
+
* `PRE_UPDATE` → `UPDATE` → `POST_UPDATE`, flushing deferred structural
|
|
382
|
+
* commands at each phase boundary. Events emitted this tick are readable
|
|
383
|
+
* for the rest of the tick and cleared at the tail. `dt` is in seconds.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* let last = performance.now();
|
|
387
|
+
* function frame(now: number) {
|
|
388
|
+
* ecs.update((now - last) / 1000);
|
|
389
|
+
* last = now;
|
|
390
|
+
* requestAnimationFrame(frame);
|
|
391
|
+
* }
|
|
392
|
+
* requestAnimationFrame(frame);
|
|
393
|
+
*/
|
|
394
|
+
update(dt: number): void;
|
|
395
|
+
dispose(): void;
|
|
396
|
+
/** Resolve a consumer-declared SAB region's byte offset by `region_id`, or
|
|
397
|
+
* 0 when absent. Generic, de-gamed replacement (#623) for the removed
|
|
398
|
+
* game-named accessors; pair with the consumer's own region module to
|
|
399
|
+
* materialise a typed view. Delegates to `Store.regionOffset`. */
|
|
400
|
+
regionOffset(regionId: number): number;
|
|
401
|
+
/** A handle (`{ buffer, view, offset, bytes }`) to a consumer-declared SAB
|
|
402
|
+
* region resolved by `region_id`, or `null` when absent. A consumer's
|
|
403
|
+
* region module builds a TypedArray view over the region's span from this.
|
|
404
|
+
* Re-fetch after a SAB grow. Delegates to `Store.regionHandle`. (#623) */
|
|
405
|
+
regionHandle(regionId: number): ColumnStoreRegionHandle | null;
|
|
406
|
+
/** Look up the field index a component reserves for `fieldName`. The
|
|
407
|
+
* index is assigned by `registerComponent` in insertion order and is
|
|
408
|
+
* stable for the lifetime of the ECS. Used by systems that need to
|
|
409
|
+
* pass `(component_id, field_id)` pairs across the WASM FFI — the Zig
|
|
410
|
+
* side identifies columns by these numeric IDs. */
|
|
411
|
+
fieldId<S extends Record<string, TypedArrayTag>>(def: ComponentDef<S>, fieldName: Extract<keyof S, string>): number;
|
|
412
|
+
/** Resolve an archetype's row index to the `EntityID` at that slot.
|
|
413
|
+
* A WASM system that drains events from the event ring as
|
|
414
|
+
* `(archId, row, …)` payloads uses this to convert the (archId, row)
|
|
415
|
+
* pair into the `EntityID` the `ctx.emit(...)` API expects.
|
|
416
|
+
* Throws if the (archId, row) pair is out of range. (#250 / Phase 4
|
|
417
|
+
* PR 4D) */
|
|
418
|
+
entityIdAtRow(archetypeId: number, row: number): EntityID;
|
|
419
|
+
/** The single SAB backing every archetype's column views. Exposed for
|
|
420
|
+
* snapshot/restore, `columnStoreStateHash`-based determinism checks, and
|
|
421
|
+
* Phase 2+ WASM/worker hand-off paths. Mutation flows through the
|
|
422
|
+
* usual `addComponent` / `removeComponent` / `flush` APIs; readers
|
|
423
|
+
* that hold a column view across a grow must consult
|
|
424
|
+
* `header.view_stamp` to detect a republish (#171 §8.1). */
|
|
425
|
+
get columnStore(): ColumnStore;
|
|
426
|
+
/** Count of live archetypes (including the empty one). Surfaces the
|
|
427
|
+
* Store-side `archetype_count` so Phase C tests can assert the
|
|
428
|
+
* pre-warmed closure was materialised; equally useful for diagnostics. */
|
|
429
|
+
get archetypeCount(): number;
|
|
430
|
+
registerTag(): ComponentDef<Record<string, never>>;
|
|
431
|
+
/** Register a sparse tag (empty schema) — membership only, no data. */
|
|
432
|
+
registerSparseTag(): SparseComponentDef<Record<string, never>>;
|
|
433
|
+
/** Register an archetype template (#462). Resolves the component set +
|
|
434
|
+
* default field values to a target archetype once (creating it if absent —
|
|
435
|
+
* fits the prewarm model), so later `spawn` / `spawnMany` calls land
|
|
436
|
+
* entities directly in that archetype with **zero archetype transitions**.
|
|
437
|
+
*
|
|
438
|
+
* const Bullet = ecs.template([
|
|
439
|
+
* { def: Position, values: { x: 0, y: 0 } },
|
|
440
|
+
* { def: Velocity, values: { vx: 0, vy: 0 } },
|
|
441
|
+
* ]);
|
|
442
|
+
*
|
|
443
|
+
* The big win is multi-component entities and bulk spawns; a single-
|
|
444
|
+
* component spawn is no faster than `spawn` + `addComponent`, which
|
|
445
|
+
* already bump-allocates a fresh entity into the target archetype. See
|
|
446
|
+
* ADR-0010. */
|
|
447
|
+
template<Defs extends readonly ComponentDef[]>(entries: TemplateEntries<Defs>): Template<Defs>;
|
|
448
|
+
/** Bulk-spawn `count` entities from `template`, optionally applying one
|
|
449
|
+
* shared `overrides` object to every spawned row (same typed keys as
|
|
450
|
+
* `spawn`). Field writes are O(columns) (one `TypedArray.fill` per
|
|
451
|
+
* column), not O(count×columns). Returns the new ids in spawn order. */
|
|
452
|
+
spawnMany<Defs extends readonly ComponentDef[]>(template: Template<Defs>, count: number, overrides?: TemplateOverrides<Defs>): EntityID[];
|
|
453
|
+
isAlive(id: EntityID): boolean;
|
|
454
|
+
get entityCount(): number;
|
|
455
|
+
hasComponent(entityId: EntityID, def: ComponentDef): boolean;
|
|
456
|
+
/** Whether `id` is currently disabled. Toggle via `disable` / `enable`
|
|
457
|
+
* (immediate, above the band — they carry the in-system dev guard). */
|
|
458
|
+
isDisabled(id: EntityID): boolean;
|
|
459
|
+
addSparse(entityId: EntityID, def: SparseComponentDef<Record<string, never>>): this;
|
|
460
|
+
addSparse<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
461
|
+
removeSparse(entityId: EntityID, def: SparseComponentDef): this;
|
|
462
|
+
hasSparse(entityId: EntityID, def: SparseComponentDef): boolean;
|
|
463
|
+
getSparseField<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, field: string & keyof S): number;
|
|
464
|
+
setSparseField<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, field: string & keyof S, value: number): void;
|
|
465
|
+
_getLastRunTick(): number;
|
|
466
|
+
/** Current ECS write tick — the tick `eachChunk` stamps via `cols.mut` (§eachChunk). */
|
|
467
|
+
_getCurrentTick(): number;
|
|
468
|
+
_getQueryDirtyEpoch(): number;
|
|
469
|
+
/** QueryResolver implementation — sparse-membership match path (#469). */
|
|
470
|
+
_forEachSparseMatch(include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, sparseInclude: readonly SparseComponentID[], sparseExclude: readonly SparseComponentID[], denseArchetypes: readonly Archetype[], cb: (entityId: EntityID) => void, includeDisabled: boolean): void;
|
|
471
|
+
/** QueryResolver implementation — backing sparse id of a relation, for the
|
|
472
|
+
* `(R, *)` wildcard term (`Query.withRelation`, #579). */
|
|
473
|
+
_relationBackingSparseId(def: RelationDef): SparseComponentID;
|
|
474
|
+
/** QueryResolver implementation — `(*, T)` wildcard match path (#579). */
|
|
475
|
+
_forEachRelationTargetMatch(target: EntityID, include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, sparseInclude: readonly SparseComponentID[], sparseExclude: readonly SparseComponentID[], includeDisabled: boolean, cb: (entityId: EntityID) => void): void;
|
|
476
|
+
/** QueryResolver implementation — depth-ordered hierarchy match path (#581). */
|
|
477
|
+
_forEachHierarchyMatch(include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, sparseInclude: readonly SparseComponentID[], sparseExclude: readonly SparseComponentID[], denseArchetypes: readonly Archetype[], relation: RelationDef, maxDepth: number, includeDisabled: boolean, cb: (entityId: EntityID) => void): void;
|
|
478
|
+
addSystems(label: SCHEDULE, ...entries: (SystemDescriptor | SystemEntry)[]): this;
|
|
479
|
+
/**
|
|
480
|
+
* Configure a `SystemSet` (#576) — the shared run condition and/or ordering
|
|
481
|
+
* every member inherits. Additive and order-independent with respect to
|
|
482
|
+
* `addSystems`: see `Schedule.configureSet`. Returns `this` to chain.
|
|
483
|
+
*/
|
|
484
|
+
configureSet(set: SystemSet, config: SystemSetConfig): this;
|
|
485
|
+
/**
|
|
486
|
+
* Register a per-component observer (#517 §1 / ADR-0013). Reactions that were
|
|
487
|
+
* hand-polled every tick — "on `Death` added → spawn corpse", "on `HexPos`
|
|
488
|
+
* set → mark the spatial index" — become declarative.
|
|
489
|
+
*
|
|
490
|
+
* - **`onAdd` / `onRemove`** `(eid, ctx)` fire at the structural-flush
|
|
491
|
+
* boundary, after the batch commits, in canonical order (access-topological
|
|
492
|
+
* across observers, entity-id order within), looping to a fixed point so
|
|
493
|
+
* cascades settle. Determinism: a `stateHash` replay reproduces regardless
|
|
494
|
+
* of the order ops were queued.
|
|
495
|
+
* - **`onDisable` / `onEnable`** `(eid, ctx)` fire at the same flush boundary
|
|
496
|
+
* when an entity carrying the component is *disabled* / *enabled* (#577,
|
|
497
|
+
* ADR-0023), once per net transition, for every component the entity carries
|
|
498
|
+
* (a disable is a soft remove of the whole mask from default queries). Like
|
|
499
|
+
* `onAdd`/`onRemove`, an *immediate* `ecs.disable()` does not fire — only
|
|
500
|
+
* the deferred `ctx.commands.disable()` toggle does. `yieldExisting` seeds enabled
|
|
501
|
+
* members only, so a disabled entity is correctly absent at seed.
|
|
502
|
+
* - **`onSet`** fires at the post-update detection point. Default
|
|
503
|
+
* `granularity: "archetype"` fires `(arch, ctx)` once per changed
|
|
504
|
+
* archetype-column (the consumer iterates `arch.entityCount` rows) — free,
|
|
505
|
+
* reusing the change tick. `granularity: "entity"` fires `(eid, ctx)` once
|
|
506
|
+
* per changed entity, draining the opt-in per-row dirty list (registering it
|
|
507
|
+
* enables dirty tracking for the component; the producer records via
|
|
508
|
+
* `ctx.setField` automatically, or `ctx.markChanged` in a `getColumn`
|
|
509
|
+
* hot loop).
|
|
510
|
+
*
|
|
511
|
+
* Observer callbacks that touch ECS state must declare it via `access`
|
|
512
|
+
* (merged over an all-empty declaration) — undeclared access throws in
|
|
513
|
+
* `DEV`, and those decls drive the firing order. `yieldExisting` replays
|
|
514
|
+
* `onAdd` over current matches on registration. Register at world-build time
|
|
515
|
+
* (before `startup()`); the returned handle's `dispose()` unregisters.
|
|
516
|
+
*/
|
|
517
|
+
observe(def: ComponentHandle, config: StructuralObserverConfig): ObserverHandle;
|
|
518
|
+
observe(def: ComponentHandle, config: EntitySetObserverConfig): ObserverHandle;
|
|
519
|
+
observe(def: ComponentHandle, config: ArchetypeSetObserverConfig): ObserverHandle;
|
|
520
|
+
/**
|
|
521
|
+
* Stamp every SAB-backed archetype's live `length` into its SAB
|
|
522
|
+
* descriptor's `row_count` field. **You usually don't need to call
|
|
523
|
+
* this directly** — `update()` publishes at tick start and
|
|
524
|
+
* `SystemContext.flush()` publishes at every phase boundary, so any
|
|
525
|
+
* WASM scan running inside the schedule sees fresh counts for free.
|
|
526
|
+
* This is an escape hatch for code that mutates archetype state
|
|
527
|
+
* outside the system framework and wants to force a republish without
|
|
528
|
+
* going through `flush()`. No in-repo callers today.
|
|
529
|
+
*
|
|
530
|
+
* Cheap: walks the descriptor region once, does no column I/O.
|
|
531
|
+
*/
|
|
532
|
+
publishArchetypeRowCounts(): void;
|
|
533
|
+
flush(): void;
|
|
534
|
+
}
|
|
535
|
+
/** Phase C of issue #213 — archetype closure from a descriptor set.
|
|
536
|
+
*
|
|
537
|
+
* Each descriptor is a system or an observer's synthesized `SystemDescriptor`
|
|
538
|
+
* (#768) — both carry `spawns` + `transitions`. Seeds the worklist with every
|
|
539
|
+
* descriptor's `spawns`; iteratively applies every descriptor's `transitions`
|
|
540
|
+
* to every discovered mask whose components cover the transition's `whenHas`.
|
|
541
|
+
* Returns the union of seeds + reachable targets, deduplicated by hash-bucketed
|
|
542
|
+
* mask equality.
|
|
543
|
+
*
|
|
544
|
+
* Termination: every transition either monotonically grows the mask (add
|
|
545
|
+
* outpacing remove), monotonically shrinks it, or returns a mask the
|
|
546
|
+
* `seen` map already holds. Because the universe of masks is bounded by
|
|
547
|
+
* `2^|components|` (and in practice the in-tree spawn/transition set is
|
|
548
|
+
* tiny — ~20 masks at most), the worklist is finite and we exit when it
|
|
549
|
+
* empties.
|
|
550
|
+
*
|
|
551
|
+
* Liberal `whenHas` per design doc §6.6 — over-approximation is fine; an
|
|
552
|
+
* unreachable transition target costs one descriptor row at the SAB tail,
|
|
553
|
+
* not column bytes. Empty `spawns` + `transitions` short-circuit to zero.
|
|
554
|
+
*/
|
|
555
|
+
declare function computeArchetypeClosure(descriptors: Iterable<SystemDescriptor>): BitSet[];
|
|
556
|
+
/** @internal — test seam for the closure walk. Exposed so the prewarm
|
|
557
|
+
* tests can exercise the BFS without standing up a full Store. */
|
|
558
|
+
export declare const _ecsInternals: {
|
|
559
|
+
computeArchetypeClosure: typeof computeArchetypeClosure;
|
|
560
|
+
};
|
|
561
|
+
export {};
|
|
562
|
+
//# sourceMappingURL=ecs.d.ts.map
|