@oasys/oecs 0.4.0 → 0.5.1

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.
Files changed (273) hide show
  1. package/CHANGELOG.md +636 -0
  2. package/README.md +47 -32
  3. package/dist/core/ecs/access_check.d.cts +77 -0
  4. package/dist/core/ecs/access_check.d.ts +8 -8
  5. package/dist/core/ecs/access_check.d.ts.map +1 -1
  6. package/dist/core/ecs/archetype.d.cts +486 -0
  7. package/dist/core/ecs/archetype.d.ts +25 -13
  8. package/dist/core/ecs/archetype.d.ts.map +1 -1
  9. package/dist/core/ecs/archetype_graph.d.cts +96 -0
  10. package/dist/core/ecs/archetype_graph.d.ts +96 -0
  11. package/dist/core/ecs/archetype_graph.d.ts.map +1 -0
  12. package/dist/core/ecs/builtin_relations.d.cts +43 -0
  13. package/dist/core/ecs/builtin_relations.d.ts +8 -8
  14. package/dist/core/ecs/builtin_relations.d.ts.map +1 -1
  15. package/dist/core/ecs/command_log.d.cts +116 -0
  16. package/dist/core/ecs/command_log.d.ts +13 -10
  17. package/dist/core/ecs/command_log.d.ts.map +1 -1
  18. package/dist/core/ecs/component.d.cts +201 -0
  19. package/dist/core/ecs/component.d.ts +100 -5
  20. package/dist/core/ecs/component.d.ts.map +1 -1
  21. package/dist/core/ecs/compute_backend.d.cts +37 -0
  22. package/dist/core/ecs/compute_backend.d.ts +2 -2
  23. package/dist/core/ecs/debug_names.d.cts +7 -0
  24. package/dist/core/ecs/debug_names.d.ts +7 -0
  25. package/dist/core/ecs/debug_names.d.ts.map +1 -0
  26. package/dist/core/ecs/deferred_commands.d.cts +55 -0
  27. package/dist/core/ecs/deferred_commands.d.ts +55 -0
  28. package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
  29. package/dist/core/ecs/dispatch_trace.d.cts +93 -0
  30. package/dist/core/ecs/dispatch_trace.d.ts +3 -3
  31. package/dist/core/ecs/ecs.d.cts +580 -0
  32. package/dist/core/ecs/ecs.d.ts +340 -293
  33. package/dist/core/ecs/ecs.d.ts.map +1 -1
  34. package/dist/core/ecs/ecs_memory.d.cts +179 -0
  35. package/dist/core/ecs/ecs_memory.d.ts +1 -1
  36. package/dist/core/ecs/entity.d.cts +34 -0
  37. package/dist/core/ecs/entity.d.ts +8 -2
  38. package/dist/core/ecs/entity.d.ts.map +1 -1
  39. package/dist/core/ecs/entity_allocator.d.cts +59 -0
  40. package/dist/core/ecs/entity_allocator.d.ts +59 -0
  41. package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
  42. package/dist/core/ecs/event.d.cts +79 -0
  43. package/dist/core/ecs/event.d.ts +36 -11
  44. package/dist/core/ecs/event.d.ts.map +1 -1
  45. package/dist/core/ecs/event_registry.d.cts +22 -0
  46. package/dist/core/ecs/event_registry.d.ts +22 -0
  47. package/dist/core/ecs/event_registry.d.ts.map +1 -0
  48. package/dist/core/ecs/facades.d.cts +158 -0
  49. package/dist/core/ecs/facades.d.ts +158 -0
  50. package/dist/core/ecs/facades.d.ts.map +1 -0
  51. package/dist/core/ecs/frame_stepper.d.cts +58 -0
  52. package/dist/core/ecs/frame_stepper.d.ts +58 -0
  53. package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
  54. package/dist/core/ecs/frame_trace.d.cts +133 -0
  55. package/dist/core/ecs/frame_trace.d.ts +5 -5
  56. package/dist/core/ecs/frame_trace.d.ts.map +1 -1
  57. package/dist/core/ecs/host_commands.d.cts +284 -0
  58. package/dist/core/ecs/host_commands.d.ts +77 -45
  59. package/dist/core/ecs/host_commands.d.ts.map +1 -1
  60. package/dist/core/ecs/index.d.cts +46 -0
  61. package/dist/core/ecs/index.d.ts +45 -40
  62. package/dist/core/ecs/index.d.ts.map +1 -1
  63. package/dist/core/ecs/observer.d.cts +173 -0
  64. package/dist/core/ecs/observer.d.ts +44 -13
  65. package/dist/core/ecs/observer.d.ts.map +1 -1
  66. package/dist/core/ecs/query.d.cts +734 -0
  67. package/dist/core/ecs/query.d.ts +267 -90
  68. package/dist/core/ecs/query.d.ts.map +1 -1
  69. package/dist/core/ecs/ref.d.cts +31 -0
  70. package/dist/core/ecs/ref.d.ts +3 -3
  71. package/dist/core/ecs/ref.d.ts.map +1 -1
  72. package/dist/core/ecs/relation.d.cts +243 -0
  73. package/dist/core/ecs/relation.d.ts +26 -14
  74. package/dist/core/ecs/relation.d.ts.map +1 -1
  75. package/dist/core/ecs/relation_service.d.cts +235 -0
  76. package/dist/core/ecs/relation_service.d.ts +235 -0
  77. package/dist/core/ecs/relation_service.d.ts.map +1 -0
  78. package/dist/core/ecs/resource.d.cts +53 -0
  79. package/dist/core/ecs/resource.d.ts +25 -5
  80. package/dist/core/ecs/resource.d.ts.map +1 -1
  81. package/dist/core/ecs/resource_registry.d.cts +20 -0
  82. package/dist/core/ecs/resource_registry.d.ts +20 -0
  83. package/dist/core/ecs/resource_registry.d.ts.map +1 -0
  84. package/dist/core/ecs/resume.d.cts +85 -0
  85. package/dist/core/ecs/resume.d.ts +6 -6
  86. package/dist/core/ecs/resume.d.ts.map +1 -1
  87. package/dist/core/ecs/run_condition.d.cts +81 -0
  88. package/dist/core/ecs/run_condition.d.ts +16 -10
  89. package/dist/core/ecs/run_condition.d.ts.map +1 -1
  90. package/dist/core/ecs/schedule.d.cts +142 -0
  91. package/dist/core/ecs/schedule.d.ts +15 -6
  92. package/dist/core/ecs/schedule.d.ts.map +1 -1
  93. package/dist/core/ecs/snapshot_service.d.cts +94 -0
  94. package/dist/core/ecs/snapshot_service.d.ts +94 -0
  95. package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
  96. package/dist/core/ecs/sparse_store.d.cts +110 -0
  97. package/dist/core/ecs/sparse_store.d.ts +5 -2
  98. package/dist/core/ecs/sparse_store.d.ts.map +1 -1
  99. package/dist/core/ecs/store.d.cts +937 -0
  100. package/dist/core/ecs/store.d.ts +144 -356
  101. package/dist/core/ecs/store.d.ts.map +1 -1
  102. package/dist/core/ecs/store_layout_listener.d.cts +23 -0
  103. package/dist/core/ecs/system.d.cts +250 -0
  104. package/dist/core/ecs/system.d.ts +138 -22
  105. package/dist/core/ecs/system.d.ts.map +1 -1
  106. package/dist/{utils/arrays.d.ts → core/ecs/utils/arrays.d.cts} +1 -0
  107. package/dist/core/ecs/utils/error.d.cts +61 -0
  108. package/dist/core/ecs/utils/error.d.ts +12 -2
  109. package/dist/core/ecs/utils/error.d.ts.map +1 -1
  110. package/dist/core/store/action_ring.d.cts +136 -0
  111. package/dist/core/store/allocator.d.cts +238 -0
  112. package/dist/core/store/allocator.d.ts.map +1 -1
  113. package/dist/core/store/buffer_backed_column.d.cts +69 -0
  114. package/dist/core/store/buffer_backed_column.d.ts +2 -2
  115. package/dist/core/store/column_store.d.cts +273 -0
  116. package/dist/core/store/column_store.d.ts +18 -10
  117. package/dist/core/store/column_store.d.ts.map +1 -1
  118. package/dist/core/store/command_dispatch.d.cts +52 -0
  119. package/dist/core/store/command_ring.d.cts +107 -0
  120. package/dist/core/store/descriptor.d.cts +80 -0
  121. package/dist/core/store/descriptor.d.ts +1 -1
  122. package/dist/core/store/descriptor.d.ts.map +1 -1
  123. package/dist/core/store/entity_index.d.cts +108 -0
  124. package/dist/core/store/event_ring.d.cts +95 -0
  125. package/dist/core/store/extend.d.cts +39 -0
  126. package/dist/core/store/extend.d.ts +3 -73
  127. package/dist/core/store/extend.d.ts.map +1 -1
  128. package/dist/core/store/grow.d.cts +34 -0
  129. package/dist/core/store/grow.d.ts +4 -9
  130. package/dist/core/store/grow.d.ts.map +1 -1
  131. package/dist/core/store/header.d.cts +64 -0
  132. package/dist/core/store/header.d.ts +1 -1
  133. package/dist/core/store/header.d.ts.map +1 -1
  134. package/dist/core/store/index.d.cts +17 -0
  135. package/dist/core/store/index.d.ts +16 -15
  136. package/dist/core/store/index.d.ts.map +1 -1
  137. package/dist/core/store/layout_ops.d.cts +152 -0
  138. package/dist/core/store/layout_ops.d.ts +152 -0
  139. package/dist/core/store/layout_ops.d.ts.map +1 -0
  140. package/dist/core/store/region_table.d.cts +74 -0
  141. package/dist/core/store/region_table.d.ts +1 -1
  142. package/dist/core/store/region_table.d.ts.map +1 -1
  143. package/dist/core/store/snapshot.d.cts +43 -0
  144. package/dist/core/store/snapshot.d.ts +2 -2
  145. package/dist/core/store/state_hash.d.cts +38 -0
  146. package/dist/core/store/state_hash.d.ts +1 -1
  147. package/dist/core/store/store_regions.d.cts +38 -0
  148. package/dist/core/store/store_regions.d.ts +1 -1
  149. package/dist/core/store/vendored_abi/abi.d.ts +43 -0
  150. package/dist/core/store/{__generated__ → vendored_abi}/abi.d.ts.map +1 -1
  151. package/dist/dev_flag.d.cts +2 -0
  152. package/dist/dev_flag.d.ts +2 -0
  153. package/dist/dev_flag.d.ts.map +1 -0
  154. package/dist/extensions/editor/editor.d.cts +172 -0
  155. package/dist/extensions/editor/editor.d.ts +65 -42
  156. package/dist/extensions/editor/editor.d.ts.map +1 -1
  157. package/dist/extensions/editor/field_handle.d.cts +40 -0
  158. package/dist/extensions/editor/field_handle.d.ts +10 -5
  159. package/dist/extensions/editor/field_handle.d.ts.map +1 -1
  160. package/dist/extensions/editor/index.cjs +1 -1
  161. package/dist/extensions/editor/index.d.cts +21 -0
  162. package/dist/extensions/editor/index.d.ts +2 -2
  163. package/dist/extensions/editor/index.js +130 -100
  164. package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
  165. package/dist/extensions/reactive/ecs_sync.d.ts +26 -22
  166. package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -1
  167. package/dist/extensions/reactive/index.cjs +1 -1
  168. package/dist/extensions/reactive/index.d.cts +23 -0
  169. package/dist/extensions/reactive/index.d.ts +1 -1
  170. package/dist/extensions/reactive/index.js +106 -116
  171. package/dist/extensions/solid/index.cjs +1 -1
  172. package/dist/extensions/solid/index.d.cts +6 -0
  173. package/dist/extensions/solid/index.d.ts +2 -2
  174. package/dist/extensions/solid/index.js +8 -4
  175. package/dist/extensions/solid/kernel_solid.d.cts +45 -0
  176. package/dist/extensions/solid/kernel_solid.d.ts +6 -3
  177. package/dist/extensions/solid/kernel_solid.d.ts.map +1 -1
  178. package/dist/host_commands-BI8pEmjH.js +2326 -0
  179. package/dist/host_commands-CxhpzMx9.cjs +1 -0
  180. package/dist/index.cjs +1 -2
  181. package/dist/index.d.cts +66 -0
  182. package/dist/index.d.ts +50 -1
  183. package/dist/index.d.ts.map +1 -1
  184. package/dist/index.js +4489 -5898
  185. package/dist/internal.cjs +2 -0
  186. package/dist/internal.d.cts +20 -0
  187. package/dist/internal.d.ts +20 -0
  188. package/dist/internal.d.ts.map +1 -0
  189. package/dist/internal.js +141 -0
  190. package/dist/primitives.cjs +1 -1
  191. package/dist/primitives.d.cts +18 -0
  192. package/dist/primitives.d.ts +6 -6
  193. package/dist/primitives.js +24 -23
  194. package/dist/reactive/array.d.ts +24 -0
  195. package/dist/reactive/array.d.ts.map +1 -0
  196. package/dist/reactive/index.cjs +1 -0
  197. package/dist/reactive/index.d.cts +11 -0
  198. package/dist/reactive/index.d.ts +11 -0
  199. package/dist/reactive/index.d.ts.map +1 -0
  200. package/dist/reactive/index.js +18 -0
  201. package/dist/reactive/interop.d.cts +19 -0
  202. package/dist/{core/reactive → reactive}/interop.d.ts +1 -1
  203. package/dist/reactive/interop.d.ts.map +1 -0
  204. package/dist/reactive/kernel.d.cts +73 -0
  205. package/dist/{core/reactive → reactive}/kernel.d.ts +5 -3
  206. package/dist/reactive/kernel.d.ts.map +1 -0
  207. package/dist/reactive/map.d.ts +16 -0
  208. package/dist/reactive/map.d.ts.map +1 -0
  209. package/dist/reactive/shallow.d.cts +11 -0
  210. package/dist/reactive/shallow.d.ts +11 -0
  211. package/dist/reactive/shallow.d.ts.map +1 -0
  212. package/dist/reactive/struct.d.cts +10 -0
  213. package/dist/{core/reactive → reactive}/struct.d.ts +1 -1
  214. package/dist/reactive/struct.d.ts.map +1 -0
  215. package/dist/shallow-DQ8aG51_.cjs +1 -0
  216. package/dist/shallow-DfnAm9vG.js +150 -0
  217. package/dist/shared-BU1Cd40h.js +103 -0
  218. package/dist/shared-BymrGTyR.cjs +1 -0
  219. package/dist/shared.cjs +1 -1
  220. package/dist/shared.d.cts +22 -0
  221. package/dist/shared.d.ts +2 -2
  222. package/dist/shared.js +1 -1
  223. package/dist/topological_sort-BDvEyb9W.cjs +1 -0
  224. package/dist/topological_sort-DK6EjpWa.js +135 -0
  225. package/dist/type_primitives/assertions.d.cts +32 -0
  226. package/dist/type_primitives/assertions.d.ts +13 -1
  227. package/dist/type_primitives/assertions.d.ts.map +1 -1
  228. package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
  229. package/dist/type_primitives/bitset/bitset.d.cts +54 -0
  230. package/dist/type_primitives/brand.d.cts +23 -0
  231. package/dist/type_primitives/error.d.cts +16 -0
  232. package/dist/type_primitives/error.d.ts +4 -3
  233. package/dist/type_primitives/error.d.ts.map +1 -1
  234. package/dist/type_primitives/index.d.cts +13 -0
  235. package/dist/type_primitives/index.d.ts +9 -9
  236. package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
  237. package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
  238. package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
  239. package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
  240. package/dist/typed_arrays-BcXcnzB4.js +258 -0
  241. package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
  242. package/dist/utils/error.d.cts +6 -0
  243. package/dist/version.d.cts +10 -0
  244. package/dist/version.d.ts +10 -0
  245. package/dist/version.d.ts.map +1 -0
  246. package/package.json +102 -19
  247. package/dist/array-CxbPyiHO.cjs +0 -1
  248. package/dist/array-uFR7Q8fU.js +0 -132
  249. package/dist/core/reactive/array.d.ts.map +0 -1
  250. package/dist/core/reactive/index.cjs +0 -1
  251. package/dist/core/reactive/index.d.ts +0 -10
  252. package/dist/core/reactive/index.d.ts.map +0 -1
  253. package/dist/core/reactive/index.js +0 -17
  254. package/dist/core/reactive/interop.d.ts.map +0 -1
  255. package/dist/core/reactive/kernel.d.ts.map +0 -1
  256. package/dist/core/reactive/map.d.ts.map +0 -1
  257. package/dist/core/reactive/struct.d.ts.map +0 -1
  258. package/dist/log/console_sink.d.ts +0 -4
  259. package/dist/log/console_sink.d.ts.map +0 -1
  260. package/dist/log/index.d.ts +0 -3
  261. package/dist/log/index.d.ts.map +0 -1
  262. package/dist/log/logger.d.ts +0 -27
  263. package/dist/log/logger.d.ts.map +0 -1
  264. package/dist/shared-BXSZnxx4.cjs +0 -1
  265. package/dist/shared-C678TAPY.js +0 -99
  266. package/dist/topological_sort-DlRpSrxu.js +0 -391
  267. package/dist/topological_sort-WAT-VHb-.cjs +0 -1
  268. package/dist/utils/arrays.d.ts.map +0 -1
  269. package/dist/utils/constants.d.ts.map +0 -1
  270. /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
  271. /package/dist/core/store/{__generated__/abi.d.ts → vendored_abi/abi.d.cts} +0 -0
  272. /package/dist/{core/reactive/array.d.ts → reactive/array.d.cts} +0 -0
  273. /package/dist/{core/reactive/map.d.ts → reactive/map.d.cts} +0 -0
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Singleton buffer that captures `(callsite, channel, op, key)` per ECS /
5
5
  * action dispatch when `VISUAL_INTEL_TRACE=1` is set in the environment.
6
- * Compile-time gated by `__DEV__`, so production builds dead-code-eliminate
6
+ * Compile-time gated by `DEV`, so production builds dead-code-eliminate
7
7
  * every record() call. Output is a deterministic JSON snapshot the
8
8
  * `visual-intel` service can ingest as a third channel of evidence
9
9
  * alongside the existing static + symbol-propagation scans.
@@ -30,9 +30,9 @@
30
30
  *
31
31
  * Activation. `record()` is *unconditional* — it records on every call. The
32
32
  * `isActive()` env-var gate is applied by the *callers* (`ecs.ts` /
33
- * `query.ts`, all `if (__DEV__ && dispatchTrace.isActive())`), not inside
33
+ * `query.ts`, all `if (DEV && dispatchTrace.isActive())`), not inside
34
34
  * `record()`. This keeps the gate in one place — the dispatch hot path —
35
- * where `__DEV__ === false` dead-code-eliminates the whole branch in prod.
35
+ * where `DEV === false` dead-code-eliminates the whole branch in prod.
36
36
  */
37
37
  export type DispatchChannel = "ecs-events" | "actions" | "resources";
38
38
  export type EcsEventOp = "emit" | "read";
@@ -0,0 +1,580 @@
1
+ import { Template, 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, StrictBundles, DefsOf } 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`, and the same callable-bundle
197
+ * grammar as `addComponents` / `template`. `ecs.spawnBundle(Pos({x,y}),
198
+ * Vel({vx:1}), IsEnemy)` collapses the attach shapes into one; each item is
199
+ * checked against its own def's schema (`StrictBundles`). Bundles are applied
200
+ * immediately; a single combined-archetype insertion (one transition instead
201
+ * of one-per-component) is a later optimization — for now this mirrors the
202
+ * per-component `addComponent` path (unlike `addComponents`, which batches).
203
+ *
204
+ * Immediate — inside a system use the deferred `ctx.commands.spawn(...)`
205
+ * (calling this from a system body throws in DEV). Note the redirect trades
206
+ * timing: `commands.spawn` returns the id now but defers the attaches to the
207
+ * phase flush, so the entity sits in its empty/partial archetype until then —
208
+ * unlike `spawnBundle`'s immediate, fully-populated archetype.
209
+ */
210
+ spawnBundle<Items extends readonly BundleOrDef[]>(...items: StrictBundles<Items>): EntityID;
211
+ /** Bulk-spawn `count` entities from `template`, optionally applying one
212
+ * shared `overrides` object to every spawned row (same typed keys as
213
+ * `spawn`). Field writes are O(columns) (one `TypedArray.fill` per
214
+ * column), not O(count×columns). Returns the new ids in spawn order.
215
+ * Immediate — inside a system use `ctx.commands.spawn` per entity (calling
216
+ * this from a system body throws in DEV). */
217
+ spawnMany<Defs extends readonly ComponentDef[]>(template: Template<Defs>, count: number, overrides?: TemplateOverrides<Defs>): EntityID[];
218
+ /** DEV-only: throw when an *immediate* host structural mutator is called
219
+ * from inside one of THIS world's system bodies (or an observer / onAdded
220
+ * hook — they run in the same access spans). One rule for every host
221
+ * structural mutator — despawn, add/remove(Components), batchAdd/Remove,
222
+ * disable/enable, AND the spawn family (spawn/spawnBundle/spawnMany): an
223
+ * immediate structural op mid-schedule can move or swap rows a running query
224
+ * is walking — or, for a spawn-append into that archetype, trip a column
225
+ * realloc under it — and it is invisible to observers. The archetype-level
226
+ * `_iterDepth` guard only catches mutations touching the archetype currently
227
+ * being iterated (and the append paths skip even that), so an op landing
228
+ * elsewhere would silently skip observers; the receiver rule ("inside a
229
+ * system, use ctx.commands") is enforced wholesale here.
230
+ *
231
+ * `_updating` scopes the guard to THIS world: the accessCheck slot is
232
+ * process-global, so without it a system of world A mutating world B (a
233
+ * supported #785 pattern — B is not mid-iteration) would false-throw. */
234
+ private _assertHostMutationOutsideSystem;
235
+ /** Immediately destroy an entity — `ecs.despawn(e); ecs.isAlive(e)` is
236
+ * `false` on the next line, matching the immediacy of every other host
237
+ * facade mutation. Inside a system the buffered path is
238
+ * `ctx.commands.despawn` (applied at the phase flush); calling this from
239
+ * a system body throws in DEV, since an immediate destroy mid-iteration
240
+ * can invalidate rows the running query is walking. */
241
+ despawn(entityId: EntityID): this;
242
+ /** Disable `entityId` (idempotent). Excluded from default queries until re-enabled. */
243
+ disable(entityId: EntityID): this;
244
+ /** Re-enable a disabled `entityId` (idempotent). */
245
+ enable(entityId: EntityID): this;
246
+ /**
247
+ * Attach a component to an entity, immediately (inside a system, use the
248
+ * deferred `ctx.commands.add`). Three shapes: a bare def attaches a tag; a
249
+ * bundle (`Pos({ x: 1 })`) zero-fills omitted fields; the explicit
250
+ * `(e, def, values)` form demands every field, so a typo'd or missing
251
+ * field is a compile error.
252
+ *
253
+ * @example
254
+ * ecs.addComponent(e, Frozen); // tag
255
+ * ecs.addComponent(e, Pos({ x: 1 })); // bundle — y zero-fills
256
+ * ecs.addComponent(e, Pos, { x: 1, y: 2 }); // complete values
257
+ */
258
+ addComponent(entityId: EntityID, def: ComponentDef<Record<string, never>>): this;
259
+ addComponent<S extends ComponentSchema>(entityId: EntityID, bundle: Bundle<S>): this;
260
+ addComponent<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
261
+ /** Batch-attach several components in one archetype transition. Takes the
262
+ * same callable-bundle varargs as `spawnBundle` — `world.addComponents(e,
263
+ * Pos({ x, y }), Vel({ vx }), Frozen)` — each item checked against its own
264
+ * def's schema (a misspelled or cross-component field is a compile error;
265
+ * tags refuse values). Omitted fields zero-fill. */
266
+ addComponents<Items extends readonly BundleOrDef[]>(entityId: EntityID, ...items: StrictBundles<Items>): this;
267
+ removeComponent(entityId: EntityID, def: ComponentDef): this;
268
+ /** Detach several components in one archetype transition — the varargs
269
+ * mirror of `addComponents` (bare defs; removing needs no values). */
270
+ removeComponents(entityId: EntityID, ...defs: ComponentDef[]): this;
271
+ /**
272
+ * Bulk add a component to ALL entities in the given archetype.
273
+ * O(columns) via TypedArray.set() instead of O(N×columns).
274
+ *
275
+ * Takes an `ArchetypeID` (from `ArchetypeView.id`) rather than a concrete
276
+ * `Archetype` — the concrete type is internal (issue #378).
277
+ */
278
+ batchAddComponent(src: ArchetypeID, def: ComponentDef<Record<string, never>>): this;
279
+ batchAddComponent<S extends ComponentSchema>(src: ArchetypeID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
280
+ /**
281
+ * Bulk remove a component from ALL entities in the given archetype.
282
+ * O(columns) via TypedArray.set() instead of O(N×columns).
283
+ *
284
+ * Takes an `ArchetypeID` (from `ArchetypeView.id`); see `batchAddComponent`.
285
+ */
286
+ batchRemoveComponent(src: ArchetypeID, def: ComponentDef): this;
287
+ getField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S): number;
288
+ /** Host-side parity with `SystemContext.refRead` (POLISH_AUDIT M7): a
289
+ * read-only whole-component view for tooling/tests, instead of reading
290
+ * field-by-field. Same advisory-`readonly` semantics as the ctx variant;
291
+ * no `_changedTick` bump. Dev-throws on a dead entity, or when the entity
292
+ * doesn't hold the component (tags included — no fields, nothing to ref).
293
+ *
294
+ * **Staleness:** unlike ctx refs (protected by deferred structural changes
295
+ * until the phase flush), host-side structural mutations apply immediately —
296
+ * any `addComponent`/`removeComponent`/`despawn` after creating the ref can
297
+ * row-swap so the old ref silently reads *another entity's* data. The ref is
298
+ * only valid until the next structural mutation; treat it as an immediate
299
+ * single-expression read and re-create it after any structural change. */
300
+ refRead<S extends ComponentSchema>(def: ComponentDef<S>, entityId: EntityID): ReadonlyComponentRef<S>;
301
+ /** Total sibling of {@link getField} (POLISH_AUDIT #9): `undefined` when the
302
+ * entity is dead or doesn't hold the component, instead of a dev throw /
303
+ * prod garbage read. The safe way to probe-and-read in one call:
304
+ * `ecs.tryGetField(e, Health, "current") ?? 0`. */
305
+ tryGetField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S): number | undefined;
306
+ setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): void;
307
+ /** Read-modify-write one field: `updateField(e, Gold, "value", v => v - cost)`
308
+ * is the one-line form of the `getField` → compute → `setField` round trip.
309
+ * Returns the written value. Same access-check and observer semantics as the
310
+ * two calls it composes. */
311
+ updateField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, fn: (current: number) => number): number;
312
+ /**
313
+ * Get the live, cached query matching entities that have **all** of
314
+ * `defs`. Queries are deduplicated by mask — calling this twice with the
315
+ * same terms returns the same instance — so build once at setup and reuse;
316
+ * the view stays live as archetypes appear. Refine with `.and()` /
317
+ * `.without()` / `.anyOf()`; iterate with `eachChunk` (mutating hot path),
318
+ * `forEach` (per-archetype), or `forEachEntity` (per-entity).
319
+ *
320
+ * @example
321
+ * const movers = ecs.query(Pos, Vel);
322
+ * movers.eachChunk((cols, count) => {
323
+ * const { x, y } = cols.mut(Pos);
324
+ * const { vx, vy } = cols.read(Vel);
325
+ * for (let i = 0; i < count; i++) { x[i] += vx[i]; y[i] += vy[i]; }
326
+ * });
327
+ */
328
+ query<T extends ComponentDef[]>(...defs: T): Query<T>;
329
+ _nextQueryId(): number;
330
+ /** QueryResolver implementation — creates or retrieves a cached Query. */
331
+ _resolveQuery(include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, defs: readonly ComponentDef[]): Query<any>;
332
+ /**
333
+ * Register a system and get its scheduling handle. The config form is the
334
+ * production shape: it declares the access surface (`reads` / `writes` are
335
+ * mandatory; `spawns` / `despawns` / resource and sparse/relation terms
336
+ * optional), which is enforced at runtime in dev *and* narrows `ctx` at
337
+ * the type level so undeclared access fails to compile. Registration does
338
+ * not schedule — pass the returned descriptor to
339
+ * `ecs.addSystems(SCHEDULE.UPDATE, ...)`.
340
+ *
341
+ * @example
342
+ * // Full config — declared access, dev-checked and compile-checked
343
+ * const move = ecs.registerSystem({
344
+ * reads: [Vel],
345
+ * writes: [Pos],
346
+ * fn(ctx, dt) {
347
+ * movers.eachChunk((cols, count) => { ... });
348
+ * },
349
+ * });
350
+ * ecs.addSystems(SCHEDULE.UPDATE, move);
351
+ *
352
+ * @example
353
+ * // Bare function (no declared access — any component touch throws in dev)
354
+ * ecs.registerSystem((ctx, dt) => { ... });
355
+ * // Function + query builder (query resolved at registration time)
356
+ * ecs.registerSystem((q, ctx, dt) => { q.forEach((arch) => { ... }); }, (qb) => qb.with(Pos, Vel));
357
+ */
358
+ registerSystem(fn: SystemFn): SystemDescriptor;
359
+ registerSystem<Defs extends readonly ComponentDef[]>(fn: (q: Query<Defs>, ctx: SystemContext, dt: number) => void, queryFn: (qb: QueryBuilder) => Query<Defs>): SystemDescriptor;
360
+ /** `exclusive: true` grants full world access at runtime (§system.ts), so
361
+ * the context stays fully permissive at the type layer too. Declared BEFORE
362
+ * the typed-config overload so exclusive configs never get narrowed. */
363
+ registerSystem(config: SystemConfig & {
364
+ readonly exclusive: true;
365
+ }): SystemDescriptor;
366
+ /** Config form (§typestate, system.ts): the declaration lists are inferred
367
+ * as literal tuples and `fn` / `onAdded` receive
368
+ * `SystemContext<DeclaredAccess<…>>` — undeclared access fails to compile
369
+ * with the same taxonomy the runtime `accessCheck` throws with in
370
+ * `DEV`. A config VALUE typed as plain `SystemConfig` (dynamically
371
+ * built) still matches: its erased declaration lists compute a permissive
372
+ * access record. Escape hatch: annotate `fn(ctx: SystemContext, dt)`
373
+ * explicitly to keep a system permissive at compile time. */
374
+ 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;
375
+ removeSystem(system: SystemDescriptor): this;
376
+ get systemCount(): number;
377
+ /**
378
+ * Run the startup phases, once, before the first `update()`. Prewarms
379
+ * every archetype the registered systems/observers can produce, runs each
380
+ * system's `onAdded` hook, then the `PRE_STARTUP` → `STARTUP` →
381
+ * `POST_STARTUP` schedule. Events emitted during startup are drained at
382
+ * its tail — they do not leak into frame 1.
383
+ *
384
+ * @example
385
+ * ecs.addSystems(SCHEDULE.UPDATE, move);
386
+ * ecs.startup();
387
+ * ecs.update(1 / 60); // now tick every frame
388
+ */
389
+ startup(): void;
390
+ /** Compute the archetype closure from every registered system's AND
391
+ * observer's `spawns` + `transitions` and ask the store to plant the
392
+ * whole set in one `extendColumnStore` call. Observers carry the same
393
+ * access shape systems do (a synthesized `SystemDescriptor`), so an
394
+ * observer that spawns/transitions gets its target archetype prewarmed
395
+ * too rather than first-touching lazily mid-tick (#768). Exposed as
396
+ * `private` because the only caller is `startup()`; visible to tests via
397
+ * the `archetype_count` delta on the public ECS facade. */
398
+ private prewarmArchetypes;
399
+ /**
400
+ * Advance the world one frame. Runs the fixed-timestep accumulator loop
401
+ * (`FIXED_UPDATE`, when any fixed system is registered), then
402
+ * `PRE_UPDATE` → `UPDATE` → `POST_UPDATE`, flushing deferred structural
403
+ * commands at each phase boundary. Events emitted this tick are readable
404
+ * for the rest of the tick and cleared at the tail. `dt` is in seconds.
405
+ *
406
+ * @example
407
+ * let last = performance.now();
408
+ * function frame(now: number) {
409
+ * ecs.update((now - last) / 1000);
410
+ * last = now;
411
+ * requestAnimationFrame(frame);
412
+ * }
413
+ * requestAnimationFrame(frame);
414
+ */
415
+ update(dt: number): void;
416
+ dispose(): void;
417
+ /** Register an archetype template (#462). Resolves the component set +
418
+ * default field values to a target archetype once (creating it if absent —
419
+ * fits the prewarm model), so later `spawn` / `spawnMany` calls land
420
+ * entities directly in that archetype with **zero archetype transitions**.
421
+ *
422
+ * const Bullet = ecs.template(Position({ x: 0, y: 0 }), Velocity({ vx: 0, vy: 0 }));
423
+ *
424
+ * Takes the same callable-bundle varargs as `spawnBundle` / `addComponents`
425
+ * (each item schema-checked against its own def); the resulting
426
+ * `Template<[Position, Velocity]>` keeps the typed key set that `spawn`'s
427
+ * `overrides` map over. Not a pass-through — it normalizes bundles to the
428
+ * store's entry shape, so it lives here with the other real logic, not in the
429
+ * delegation band. The big win is multi-component entities and bulk spawns; a
430
+ * single-component spawn is no faster than `spawn` + `addComponent`, which
431
+ * already bump-allocates a fresh entity into the target archetype. See
432
+ * ADR-0010. */
433
+ template<Items extends readonly BundleOrDef[]>(...items: StrictBundles<Items>): Template<DefsOf<Items>>;
434
+ /** Resolve a consumer-declared SAB region's byte offset by `region_id`, or
435
+ * 0 when absent. Generic, de-gamed replacement (#623) for the removed
436
+ * game-named accessors; pair with the consumer's own region module to
437
+ * materialise a typed view. Delegates to `Store.regionOffset`. */
438
+ regionOffset(regionId: number): number;
439
+ /** A handle (`{ buffer, view, offset, bytes }`) to a consumer-declared SAB
440
+ * region resolved by `region_id`, or `null` when absent. A consumer's
441
+ * region module builds a TypedArray view over the region's span from this.
442
+ * Re-fetch after a SAB grow. Delegates to `Store.regionHandle`. (#623) */
443
+ regionHandle(regionId: number): ColumnStoreRegionHandle | null;
444
+ /** Look up the field index a component reserves for `fieldName`. The
445
+ * index is assigned by `registerComponent` in insertion order and is
446
+ * stable for the lifetime of the ECS. Used by systems that need to
447
+ * pass `(component_id, field_id)` pairs across the WASM FFI — the Zig
448
+ * side identifies columns by these numeric IDs. */
449
+ fieldId<S extends Record<string, TypedArrayTag>>(def: ComponentDef<S>, fieldName: Extract<keyof S, string>): number;
450
+ /** Resolve an archetype's row index to the `EntityID` at that slot.
451
+ * A WASM system that drains events from the event ring as
452
+ * `(archId, row, …)` payloads uses this to convert the (archId, row)
453
+ * pair into the `EntityID` the `ctx.emit(...)` API expects.
454
+ * Throws if the (archId, row) pair is out of range. (#250 / Phase 4
455
+ * PR 4D) */
456
+ entityIdAtRow(archetypeId: number, row: number): EntityID;
457
+ /** The single SAB backing every archetype's column views. Exposed for
458
+ * snapshot/restore, `columnStoreStateHash`-based determinism checks, and
459
+ * Phase 2+ WASM/worker hand-off paths. Mutation flows through the
460
+ * usual `addComponent` / `removeComponent` / `flush` APIs; readers
461
+ * that hold a column view across a grow must consult
462
+ * `header.view_stamp` to detect a republish (#171 §8.1). */
463
+ get columnStore(): ColumnStore;
464
+ /** Count of live archetypes (including the empty one). Surfaces the
465
+ * Store-side `archetype_count` so Phase C tests can assert the
466
+ * pre-warmed closure was materialised; equally useful for diagnostics. */
467
+ get archetypeCount(): number;
468
+ registerTag(): ComponentDef<Record<string, never>>;
469
+ /** Register a sparse tag (empty schema) — membership only, no data. */
470
+ registerSparseTag(): SparseComponentDef<Record<string, never>>;
471
+ isAlive(entityId: EntityID): boolean;
472
+ get entityCount(): number;
473
+ hasComponent(entityId: EntityID, def: ComponentDef): boolean;
474
+ /** Whether `entityId` is currently disabled. Toggle via `disable` / `enable`
475
+ * (immediate, above the band — they carry the in-system dev guard). */
476
+ isDisabled(entityId: EntityID): boolean;
477
+ addSparse(entityId: EntityID, def: SparseComponentDef<Record<string, never>>): this;
478
+ addSparse<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, values: CompleteFieldValues<S>): this;
479
+ removeSparse(entityId: EntityID, def: SparseComponentDef): this;
480
+ hasSparse(entityId: EntityID, def: SparseComponentDef): boolean;
481
+ getSparseField<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, field: string & keyof S): number;
482
+ setSparseField<S extends ComponentSchema>(entityId: EntityID, def: SparseComponentDef<S>, field: string & keyof S, value: number): void;
483
+ _getLastRunTick(): number;
484
+ /** Current ECS write tick — the tick `eachChunk` stamps via `cols.mut` (§eachChunk). */
485
+ _getCurrentTick(): number;
486
+ _getQueryDirtyEpoch(): number;
487
+ /** QueryResolver implementation — sparse-membership match path (#469). */
488
+ _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;
489
+ /** QueryResolver implementation — backing sparse id of a relation, for the
490
+ * `(R, *)` wildcard term (`Query.withRelation`, #579). */
491
+ _relationBackingSparseId(def: RelationDef): SparseComponentID;
492
+ /** QueryResolver implementation — `(*, T)` wildcard match path (#579). */
493
+ _forEachRelationTargetMatch(target: EntityID, include: BitSet, exclude: BitSet | null, anyOf: BitSet | null, sparseInclude: readonly SparseComponentID[], sparseExclude: readonly SparseComponentID[], includeDisabled: boolean, cb: (entityId: EntityID) => void): void;
494
+ /** QueryResolver implementation — depth-ordered hierarchy match path (#581). */
495
+ _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;
496
+ addSystems(label: SCHEDULE, ...entries: (SystemDescriptor | SystemEntry)[]): this;
497
+ /**
498
+ * Configure a `SystemSet` (#576) — the shared run condition and/or ordering
499
+ * every member inherits. Additive and order-independent with respect to
500
+ * `addSystems`: see `Schedule.configureSet`. Returns `this` to chain.
501
+ */
502
+ configureSet(set: SystemSet, config: SystemSetConfig): this;
503
+ /**
504
+ * Register a per-component observer (#517 §1 / ADR-0013). Reactions that were
505
+ * hand-polled every tick — "on `Death` added → spawn corpse", "on `HexPos`
506
+ * set → mark the spatial index" — become declarative.
507
+ *
508
+ * - **`onAdd` / `onRemove`** `(eid, ctx)` fire at the structural-flush
509
+ * boundary, after the batch commits, in canonical order (access-topological
510
+ * across observers, entity-id order within), looping to a fixed point so
511
+ * cascades settle. Determinism: a `stateHash` replay reproduces regardless
512
+ * of the order ops were queued.
513
+ * - **`onDisable` / `onEnable`** `(eid, ctx)` fire at the same flush boundary
514
+ * when an entity carrying the component is *disabled* / *enabled* (#577,
515
+ * ADR-0023), once per net transition, for every component the entity carries
516
+ * (a disable is a soft remove of the whole mask from default queries). Like
517
+ * `onAdd`/`onRemove`, an *immediate* `ecs.disable()` does not fire — only
518
+ * the deferred `ctx.commands.disable()` toggle does. `yieldExisting` seeds enabled
519
+ * members only, so a disabled entity is correctly absent at seed.
520
+ * - **`onSet`** fires at the post-update detection point. Default
521
+ * `granularity: "archetype"` fires `(arch, ctx)` once per changed
522
+ * archetype-column (the consumer iterates `arch.entityCount` rows) — free,
523
+ * reusing the change tick. `granularity: "entity"` fires `(eid, ctx)` once
524
+ * per changed entity, draining the opt-in per-row dirty list (registering it
525
+ * enables dirty tracking for the component; the producer records via
526
+ * `ctx.setField` automatically, or `ctx.markChanged` in a `getColumn`
527
+ * hot loop).
528
+ *
529
+ * Observer callbacks that touch ECS state must declare it via `access`
530
+ * (merged over an all-empty declaration) — undeclared access throws in
531
+ * `DEV`, and those decls drive the firing order. `yieldExisting` replays
532
+ * `onAdd` over current matches on registration. Register at world-build time
533
+ * (before `startup()`); the returned handle's `dispose()` unregisters.
534
+ */
535
+ observe(def: ComponentHandle, config: StructuralObserverConfig): ObserverHandle;
536
+ observe(def: ComponentHandle, config: EntitySetObserverConfig): ObserverHandle;
537
+ observe(def: ComponentHandle, config: ArchetypeSetObserverConfig): ObserverHandle;
538
+ /**
539
+ * Stamp every SAB-backed archetype's live `length` into its SAB
540
+ * descriptor's `row_count` field. **You usually don't need to call
541
+ * this directly** — `update()` publishes at tick start and
542
+ * `SystemContext.flush()` publishes at every phase boundary, so any
543
+ * WASM scan running inside the schedule sees fresh counts for free.
544
+ * This is an escape hatch for code that mutates archetype state
545
+ * outside the system framework and wants to force a republish without
546
+ * going through `flush()`. No in-repo callers today.
547
+ *
548
+ * Cheap: walks the descriptor region once, does no column I/O.
549
+ */
550
+ publishArchetypeRowCounts(): void;
551
+ flush(): void;
552
+ }
553
+ /** Phase C of issue #213 — archetype closure from a descriptor set.
554
+ *
555
+ * Each descriptor is a system or an observer's synthesized `SystemDescriptor`
556
+ * (#768) — both carry `spawns` + `transitions`. Seeds the worklist with every
557
+ * descriptor's `spawns`; iteratively applies every descriptor's `transitions`
558
+ * to every discovered mask whose components cover the transition's `whenHas`.
559
+ * Returns the union of seeds + reachable targets, deduplicated by hash-bucketed
560
+ * mask equality.
561
+ *
562
+ * Termination: every transition either monotonically grows the mask (add
563
+ * outpacing remove), monotonically shrinks it, or returns a mask the
564
+ * `seen` map already holds. Because the universe of masks is bounded by
565
+ * `2^|components|` (and in practice the in-tree spawn/transition set is
566
+ * tiny — ~20 masks at most), the worklist is finite and we exit when it
567
+ * empties.
568
+ *
569
+ * Liberal `whenHas` per design doc §6.6 — over-approximation is fine; an
570
+ * unreachable transition target costs one descriptor row at the SAB tail,
571
+ * not column bytes. Empty `spawns` + `transitions` short-circuit to zero.
572
+ */
573
+ declare function computeArchetypeClosure(descriptors: Iterable<SystemDescriptor>): BitSet[];
574
+ /** @internal — test seam for the closure walk. Exposed so the prewarm
575
+ * tests can exercise the BFS without standing up a full Store. */
576
+ export declare const _ecsInternals: {
577
+ computeArchetypeClosure: typeof computeArchetypeClosure;
578
+ };
579
+ export {};
580
+ //# sourceMappingURL=ecs.d.ts.map