@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.
Files changed (324) hide show
  1. package/CHANGELOG.md +553 -0
  2. package/README.md +207 -267
  3. package/dist/core/ecs/access_check.d.cts +77 -0
  4. package/dist/core/ecs/access_check.d.ts +77 -0
  5. package/dist/core/ecs/access_check.d.ts.map +1 -0
  6. package/dist/core/ecs/archetype.d.cts +486 -0
  7. package/dist/core/ecs/archetype.d.ts +486 -0
  8. package/dist/core/ecs/archetype.d.ts.map +1 -0
  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 +43 -0
  14. package/dist/core/ecs/builtin_relations.d.ts.map +1 -0
  15. package/dist/core/ecs/command_log.d.cts +116 -0
  16. package/dist/core/ecs/command_log.d.ts +116 -0
  17. package/dist/core/ecs/command_log.d.ts.map +1 -0
  18. package/dist/core/ecs/component.d.cts +176 -0
  19. package/dist/core/ecs/component.d.ts +176 -0
  20. package/dist/core/ecs/component.d.ts.map +1 -0
  21. package/dist/core/ecs/compute_backend.d.cts +37 -0
  22. package/dist/core/ecs/compute_backend.d.ts +37 -0
  23. package/dist/core/ecs/compute_backend.d.ts.map +1 -0
  24. package/dist/core/ecs/debug_names.d.cts +7 -0
  25. package/dist/core/ecs/debug_names.d.ts +7 -0
  26. package/dist/core/ecs/debug_names.d.ts.map +1 -0
  27. package/dist/core/ecs/deferred_commands.d.cts +55 -0
  28. package/dist/core/ecs/deferred_commands.d.ts +55 -0
  29. package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
  30. package/dist/core/ecs/dispatch_trace.d.cts +93 -0
  31. package/dist/core/ecs/dispatch_trace.d.ts +93 -0
  32. package/dist/core/ecs/dispatch_trace.d.ts.map +1 -0
  33. package/dist/core/ecs/ecs.d.cts +562 -0
  34. package/dist/core/ecs/ecs.d.ts +562 -0
  35. package/dist/core/ecs/ecs.d.ts.map +1 -0
  36. package/dist/core/ecs/ecs_memory.d.cts +179 -0
  37. package/dist/core/ecs/ecs_memory.d.ts +179 -0
  38. package/dist/core/ecs/ecs_memory.d.ts.map +1 -0
  39. package/dist/core/ecs/entity.d.cts +34 -0
  40. package/dist/core/ecs/entity.d.ts +34 -0
  41. package/dist/core/ecs/entity.d.ts.map +1 -0
  42. package/dist/core/ecs/entity_allocator.d.cts +59 -0
  43. package/dist/core/ecs/entity_allocator.d.ts +59 -0
  44. package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
  45. package/dist/core/ecs/event.d.cts +79 -0
  46. package/dist/core/ecs/event.d.ts +79 -0
  47. package/dist/core/ecs/event.d.ts.map +1 -0
  48. package/dist/core/ecs/event_registry.d.cts +22 -0
  49. package/dist/core/ecs/event_registry.d.ts +22 -0
  50. package/dist/core/ecs/event_registry.d.ts.map +1 -0
  51. package/dist/core/ecs/facades.d.cts +158 -0
  52. package/dist/core/ecs/facades.d.ts +158 -0
  53. package/dist/core/ecs/facades.d.ts.map +1 -0
  54. package/dist/core/ecs/frame_stepper.d.cts +58 -0
  55. package/dist/core/ecs/frame_stepper.d.ts +58 -0
  56. package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
  57. package/dist/core/ecs/frame_trace.d.cts +133 -0
  58. package/dist/core/ecs/frame_trace.d.ts +133 -0
  59. package/dist/core/ecs/frame_trace.d.ts.map +1 -0
  60. package/dist/core/ecs/host_commands.d.cts +274 -0
  61. package/dist/core/ecs/host_commands.d.ts +274 -0
  62. package/dist/core/ecs/host_commands.d.ts.map +1 -0
  63. package/dist/core/ecs/index.d.cts +46 -0
  64. package/dist/core/ecs/index.d.ts +46 -0
  65. package/dist/core/ecs/index.d.ts.map +1 -0
  66. package/dist/core/ecs/observer.d.cts +173 -0
  67. package/dist/core/ecs/observer.d.ts +173 -0
  68. package/dist/core/ecs/observer.d.ts.map +1 -0
  69. package/dist/core/ecs/query.d.cts +718 -0
  70. package/dist/core/ecs/query.d.ts +718 -0
  71. package/dist/core/ecs/query.d.ts.map +1 -0
  72. package/dist/core/ecs/ref.d.cts +31 -0
  73. package/dist/core/ecs/ref.d.ts +31 -0
  74. package/dist/core/ecs/ref.d.ts.map +1 -0
  75. package/dist/core/ecs/relation.d.cts +243 -0
  76. package/dist/core/ecs/relation.d.ts +243 -0
  77. package/dist/core/ecs/relation.d.ts.map +1 -0
  78. package/dist/core/ecs/relation_service.d.cts +235 -0
  79. package/dist/core/ecs/relation_service.d.ts +235 -0
  80. package/dist/core/ecs/relation_service.d.ts.map +1 -0
  81. package/dist/core/ecs/resource.d.cts +53 -0
  82. package/dist/core/ecs/resource.d.ts +53 -0
  83. package/dist/core/ecs/resource.d.ts.map +1 -0
  84. package/dist/core/ecs/resource_registry.d.cts +20 -0
  85. package/dist/core/ecs/resource_registry.d.ts +20 -0
  86. package/dist/core/ecs/resource_registry.d.ts.map +1 -0
  87. package/dist/core/ecs/resume.d.cts +85 -0
  88. package/dist/core/ecs/resume.d.ts +85 -0
  89. package/dist/core/ecs/resume.d.ts.map +1 -0
  90. package/dist/core/ecs/run_condition.d.cts +81 -0
  91. package/dist/core/ecs/run_condition.d.ts +81 -0
  92. package/dist/core/ecs/run_condition.d.ts.map +1 -0
  93. package/dist/core/ecs/schedule.d.cts +142 -0
  94. package/dist/core/ecs/schedule.d.ts +142 -0
  95. package/dist/core/ecs/schedule.d.ts.map +1 -0
  96. package/dist/core/ecs/snapshot_service.d.cts +94 -0
  97. package/dist/core/ecs/snapshot_service.d.ts +94 -0
  98. package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
  99. package/dist/core/ecs/sparse_store.d.cts +110 -0
  100. package/dist/core/ecs/sparse_store.d.ts +110 -0
  101. package/dist/core/ecs/sparse_store.d.ts.map +1 -0
  102. package/dist/core/ecs/store.d.cts +950 -0
  103. package/dist/core/ecs/store.d.ts +950 -0
  104. package/dist/core/ecs/store.d.ts.map +1 -0
  105. package/dist/core/ecs/store_layout_listener.d.cts +23 -0
  106. package/dist/core/ecs/store_layout_listener.d.ts +23 -0
  107. package/dist/core/ecs/store_layout_listener.d.ts.map +1 -0
  108. package/dist/core/ecs/system.d.cts +250 -0
  109. package/dist/core/ecs/system.d.ts +250 -0
  110. package/dist/core/ecs/system.d.ts.map +1 -0
  111. package/dist/core/ecs/utils/arrays.d.cts +7 -0
  112. package/dist/{utils → core/ecs/utils}/arrays.d.ts +2 -1
  113. package/dist/core/ecs/utils/arrays.d.ts.map +1 -0
  114. package/dist/core/ecs/utils/constants.d.ts +12 -0
  115. package/dist/core/ecs/utils/constants.d.ts.map +1 -0
  116. package/dist/core/ecs/utils/error.d.cts +61 -0
  117. package/dist/core/ecs/utils/error.d.ts +61 -0
  118. package/dist/core/ecs/utils/error.d.ts.map +1 -0
  119. package/dist/core/store/action_ring.d.cts +136 -0
  120. package/dist/core/store/action_ring.d.ts +136 -0
  121. package/dist/core/store/action_ring.d.ts.map +1 -0
  122. package/dist/core/store/allocator.d.cts +238 -0
  123. package/dist/core/store/allocator.d.ts +238 -0
  124. package/dist/core/store/allocator.d.ts.map +1 -0
  125. package/dist/core/store/buffer_backed_column.d.cts +69 -0
  126. package/dist/core/store/buffer_backed_column.d.ts +69 -0
  127. package/dist/core/store/buffer_backed_column.d.ts.map +1 -0
  128. package/dist/core/store/column_store.d.cts +273 -0
  129. package/dist/core/store/column_store.d.ts +273 -0
  130. package/dist/core/store/column_store.d.ts.map +1 -0
  131. package/dist/core/store/command_dispatch.d.cts +52 -0
  132. package/dist/core/store/command_dispatch.d.ts +52 -0
  133. package/dist/core/store/command_dispatch.d.ts.map +1 -0
  134. package/dist/core/store/command_ring.d.cts +107 -0
  135. package/dist/core/store/command_ring.d.ts +107 -0
  136. package/dist/core/store/command_ring.d.ts.map +1 -0
  137. package/dist/core/store/descriptor.d.cts +80 -0
  138. package/dist/core/store/descriptor.d.ts +80 -0
  139. package/dist/core/store/descriptor.d.ts.map +1 -0
  140. package/dist/core/store/entity_index.d.cts +108 -0
  141. package/dist/core/store/entity_index.d.ts +108 -0
  142. package/dist/core/store/entity_index.d.ts.map +1 -0
  143. package/dist/core/store/event_ring.d.cts +95 -0
  144. package/dist/core/store/event_ring.d.ts +95 -0
  145. package/dist/core/store/event_ring.d.ts.map +1 -0
  146. package/dist/core/store/extend.d.cts +39 -0
  147. package/dist/core/store/extend.d.ts +39 -0
  148. package/dist/core/store/extend.d.ts.map +1 -0
  149. package/dist/core/store/grow.d.cts +34 -0
  150. package/dist/core/store/grow.d.ts +34 -0
  151. package/dist/core/store/grow.d.ts.map +1 -0
  152. package/dist/core/store/header.d.cts +64 -0
  153. package/dist/core/store/header.d.ts +64 -0
  154. package/dist/core/store/header.d.ts.map +1 -0
  155. package/dist/core/store/index.d.cts +17 -0
  156. package/dist/core/store/index.d.ts +17 -0
  157. package/dist/core/store/index.d.ts.map +1 -0
  158. package/dist/core/store/layout_ops.d.cts +152 -0
  159. package/dist/core/store/layout_ops.d.ts +152 -0
  160. package/dist/core/store/layout_ops.d.ts.map +1 -0
  161. package/dist/core/store/region_table.d.cts +74 -0
  162. package/dist/core/store/region_table.d.ts +74 -0
  163. package/dist/core/store/region_table.d.ts.map +1 -0
  164. package/dist/core/store/snapshot.d.cts +43 -0
  165. package/dist/core/store/snapshot.d.ts +43 -0
  166. package/dist/core/store/snapshot.d.ts.map +1 -0
  167. package/dist/core/store/state_hash.d.cts +38 -0
  168. package/dist/core/store/state_hash.d.ts +38 -0
  169. package/dist/core/store/state_hash.d.ts.map +1 -0
  170. package/dist/core/store/store_regions.d.cts +38 -0
  171. package/dist/core/store/store_regions.d.ts +38 -0
  172. package/dist/core/store/store_regions.d.ts.map +1 -0
  173. package/dist/core/store/vendored_abi/abi.d.cts +43 -0
  174. package/dist/core/store/vendored_abi/abi.d.ts +43 -0
  175. package/dist/core/store/vendored_abi/abi.d.ts.map +1 -0
  176. package/dist/dev_flag.d.cts +17 -0
  177. package/dist/dev_flag.d.ts +17 -0
  178. package/dist/dev_flag.d.ts.map +1 -0
  179. package/dist/extensions/editor/editor.d.cts +170 -0
  180. package/dist/extensions/editor/editor.d.ts +170 -0
  181. package/dist/extensions/editor/editor.d.ts.map +1 -0
  182. package/dist/extensions/editor/field_handle.d.cts +40 -0
  183. package/dist/extensions/editor/field_handle.d.ts +40 -0
  184. package/dist/extensions/editor/field_handle.d.ts.map +1 -0
  185. package/dist/extensions/editor/index.cjs +1 -0
  186. package/dist/extensions/editor/index.d.cts +21 -0
  187. package/dist/extensions/editor/index.d.ts +21 -0
  188. package/dist/extensions/editor/index.d.ts.map +1 -0
  189. package/dist/extensions/editor/index.js +237 -0
  190. package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
  191. package/dist/extensions/reactive/ecs_sync.d.ts +214 -0
  192. package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -0
  193. package/dist/extensions/reactive/index.cjs +1 -0
  194. package/dist/extensions/reactive/index.d.cts +23 -0
  195. package/dist/extensions/reactive/index.d.ts +23 -0
  196. package/dist/extensions/reactive/index.d.ts.map +1 -0
  197. package/dist/extensions/reactive/index.js +215 -0
  198. package/dist/extensions/solid/index.cjs +1 -0
  199. package/dist/extensions/solid/index.d.cts +6 -0
  200. package/dist/extensions/solid/index.d.ts +6 -0
  201. package/dist/extensions/solid/index.d.ts.map +1 -0
  202. package/dist/extensions/solid/index.js +36 -0
  203. package/dist/extensions/solid/kernel_solid.d.cts +45 -0
  204. package/dist/extensions/solid/kernel_solid.d.ts +45 -0
  205. package/dist/extensions/solid/kernel_solid.d.ts.map +1 -0
  206. package/dist/host_commands-BF8QMi3c.cjs +1 -0
  207. package/dist/host_commands-i4cAeyL5.js +2318 -0
  208. package/dist/index.cjs +1 -1
  209. package/dist/index.d.cts +66 -0
  210. package/dist/index.d.ts +65 -12
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +7080 -1289
  213. package/dist/internal.cjs +2 -0
  214. package/dist/internal.d.cts +20 -0
  215. package/dist/internal.d.ts +20 -0
  216. package/dist/internal.d.ts.map +1 -0
  217. package/dist/internal.js +141 -0
  218. package/dist/interop-CT-REx0W.cjs +1 -0
  219. package/dist/interop-CcY6ASQc.js +18 -0
  220. package/dist/kernel-DgyrLFjW.js +227 -0
  221. package/dist/kernel-yWV3XnAb.cjs +1 -0
  222. package/dist/primitives.cjs +1 -0
  223. package/dist/primitives.d.cts +18 -0
  224. package/dist/primitives.d.ts +18 -0
  225. package/dist/primitives.d.ts.map +1 -0
  226. package/dist/primitives.js +45 -0
  227. package/dist/reactive/array.d.cts +24 -0
  228. package/dist/reactive/array.d.ts +24 -0
  229. package/dist/reactive/array.d.ts.map +1 -0
  230. package/dist/reactive/index.cjs +1 -0
  231. package/dist/reactive/index.d.cts +11 -0
  232. package/dist/reactive/index.d.ts +11 -0
  233. package/dist/reactive/index.d.ts.map +1 -0
  234. package/dist/reactive/index.js +18 -0
  235. package/dist/reactive/interop.d.cts +19 -0
  236. package/dist/reactive/interop.d.ts +19 -0
  237. package/dist/reactive/interop.d.ts.map +1 -0
  238. package/dist/reactive/kernel.d.cts +73 -0
  239. package/dist/reactive/kernel.d.ts +73 -0
  240. package/dist/reactive/kernel.d.ts.map +1 -0
  241. package/dist/reactive/map.d.cts +16 -0
  242. package/dist/reactive/map.d.ts +16 -0
  243. package/dist/reactive/map.d.ts.map +1 -0
  244. package/dist/reactive/shallow.d.cts +11 -0
  245. package/dist/reactive/shallow.d.ts +11 -0
  246. package/dist/reactive/shallow.d.ts.map +1 -0
  247. package/dist/reactive/struct.d.cts +10 -0
  248. package/dist/reactive/struct.d.ts +10 -0
  249. package/dist/reactive/struct.d.ts.map +1 -0
  250. package/dist/shallow-DQ8aG51_.cjs +1 -0
  251. package/dist/shallow-DfnAm9vG.js +150 -0
  252. package/dist/shared-BU1Cd40h.js +103 -0
  253. package/dist/shared-BymrGTyR.cjs +1 -0
  254. package/dist/shared.cjs +1 -0
  255. package/dist/shared.d.cts +22 -0
  256. package/dist/shared.d.ts +22 -0
  257. package/dist/shared.d.ts.map +1 -0
  258. package/dist/shared.js +7 -0
  259. package/dist/topological_sort-BDvEyb9W.cjs +1 -0
  260. package/dist/topological_sort-DK6EjpWa.js +135 -0
  261. package/dist/type_primitives/assertions.d.cts +32 -0
  262. package/dist/type_primitives/assertions.d.ts +25 -9
  263. package/dist/type_primitives/assertions.d.ts.map +1 -1
  264. package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
  265. package/dist/type_primitives/binary_heap/binary_heap.d.ts +6 -2
  266. package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -1
  267. package/dist/type_primitives/bitset/bitset.d.cts +54 -0
  268. package/dist/type_primitives/bitset/bitset.d.ts +16 -4
  269. package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
  270. package/dist/type_primitives/brand.d.cts +23 -0
  271. package/dist/type_primitives/brand.d.ts +6 -1
  272. package/dist/type_primitives/brand.d.ts.map +1 -1
  273. package/dist/type_primitives/error.d.cts +16 -0
  274. package/dist/type_primitives/error.d.ts +8 -3
  275. package/dist/type_primitives/error.d.ts.map +1 -1
  276. package/dist/type_primitives/index.d.cts +13 -0
  277. package/dist/type_primitives/index.d.ts +12 -9
  278. package/dist/type_primitives/index.d.ts.map +1 -1
  279. package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
  280. package/dist/type_primitives/sparse_map/sparse_map.d.ts +7 -3
  281. package/dist/type_primitives/sparse_map/sparse_map.d.ts.map +1 -1
  282. package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
  283. package/dist/type_primitives/sparse_set/sparse_set.d.ts +4 -0
  284. package/dist/type_primitives/sparse_set/sparse_set.d.ts.map +1 -1
  285. package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
  286. package/dist/type_primitives/topological_sort/topological_sort.d.ts +7 -3
  287. package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -1
  288. package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
  289. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +53 -16
  290. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
  291. package/dist/typed_arrays-BcXcnzB4.js +258 -0
  292. package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
  293. package/dist/utils/error.d.cts +6 -0
  294. package/dist/utils/error.d.ts +2 -20
  295. package/dist/utils/error.d.ts.map +1 -1
  296. package/dist/version.d.cts +10 -0
  297. package/dist/version.d.ts +10 -0
  298. package/dist/version.d.ts.map +1 -0
  299. package/package.json +115 -5
  300. package/dist/archetype.d.ts +0 -108
  301. package/dist/archetype.d.ts.map +0 -1
  302. package/dist/component.d.ts +0 -45
  303. package/dist/component.d.ts.map +0 -1
  304. package/dist/ecs.d.ts +0 -104
  305. package/dist/ecs.d.ts.map +0 -1
  306. package/dist/entity.d.ts +0 -11
  307. package/dist/entity.d.ts.map +0 -1
  308. package/dist/event.d.ts +0 -30
  309. package/dist/event.d.ts.map +0 -1
  310. package/dist/query.d.ts +0 -94
  311. package/dist/query.d.ts.map +0 -1
  312. package/dist/ref.d.ts +0 -23
  313. package/dist/ref.d.ts.map +0 -1
  314. package/dist/resource.d.ts +0 -23
  315. package/dist/resource.d.ts.map +0 -1
  316. package/dist/schedule.d.ts +0 -45
  317. package/dist/schedule.d.ts.map +0 -1
  318. package/dist/store.d.ts +0 -118
  319. package/dist/store.d.ts.map +0 -1
  320. package/dist/system.d.ts +0 -16
  321. package/dist/system.d.ts.map +0 -1
  322. package/dist/utils/arrays.d.ts.map +0 -1
  323. package/dist/utils/constants.d.ts.map +0 -1
  324. /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
@@ -0,0 +1,85 @@
1
+ import { ArchetypeViews } from '../store/index.cjs';
2
+ /** Magic for the combined world-snapshot frame (`"WRS0"` little-endian). Distinct
3
+ * from the SAB `STORE_MAGIC` so a bare dense snapshot fed to `restoreInto` is
4
+ * rejected with a clear error instead of being mis-parsed as a combined frame. */
5
+ export declare const WORLD_SNAPSHOT_MAGIC = 810766935;
6
+ /** Combined-frame format version. Bumped if the section framing or host-state
7
+ * layout changes. Independent of `SIM_ABI_VERSION` (which gates the dense bytes). */
8
+ export declare const ECS_SNAPSHOT_VERSION = 1;
9
+ /** Thrown by `Store.restoreInto` (and the helpers here) when a combined snapshot
10
+ * is malformed, carries the wrong magic/version, or targets a world whose
11
+ * archetype/component registration doesn't match the snapshot. Mirrors
12
+ * `StoreRestoreError` / `SparseRestoreError` so callers see one error class per
13
+ * restore failure mode. */
14
+ export declare class ECSRestoreError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ /** Per-archetype host-side row bookkeeping the SAB doesn't carry authoritatively. */
18
+ export interface ArchetypeRowState {
19
+ readonly archetypeId: number;
20
+ /** Total live rows (enabled + disabled). */
21
+ readonly length: number;
22
+ /** Enabled-row partition boundary (#577): rows `[0, enabledCount)` enabled. */
23
+ readonly enabledCount: number;
24
+ }
25
+ /** The host-side state a snapshot captures alongside the dense + sparse bytes. */
26
+ export interface HostState {
27
+ /** World tick at snapshot time (`Store._tick`). */
28
+ readonly tick: number;
29
+ /** Entity-index high-water (count of slots ever issued). Also mirrored in the
30
+ * SAB region's `length` header; carried here for a cross-check on restore. */
31
+ readonly entityHighWater: number;
32
+ /** Live entity count. */
33
+ readonly entityAliveCount: number;
34
+ /** Recycle free-list in live order (LIFO: the last element is the next slot
35
+ * `createEntity` hands out). */
36
+ readonly freeIndices: readonly number[];
37
+ /** Per-archetype row state, one entry per SAB-backed archetype. */
38
+ readonly archetypeRows: readonly ArchetypeRowState[];
39
+ }
40
+ /** Serialize host-state to a self-contained little-endian byte buffer. Layout:
41
+ *
42
+ * [u32 tick][u32 highWater][u32 alive_count]
43
+ * [u32 freeCount][u32 free_index × freeCount]
44
+ * [u32 archCount][(u32 id, u32 length, u32 enabled_count) × archCount]
45
+ */
46
+ export declare function serializeHostState(hs: HostState): Uint8Array;
47
+ /** Parse host-state bytes produced by `serializeHostState`. Throws
48
+ * `ECSRestoreError` on truncation or a trailing-byte (non-canonical) buffer. */
49
+ export declare function parseHostState(bytes: Uint8Array): HostState;
50
+ /** Assemble the combined world-snapshot frame from its three sections. Layout:
51
+ *
52
+ * [u32 magic][u32 version][u32 denseLen][u32 sparseLen][u32 hostLen]
53
+ * [dense][sparse][host]
54
+ */
55
+ export declare function frameWorldSnapshot(dense: Uint8Array, sparse: Uint8Array, host: Uint8Array): Uint8Array;
56
+ /** The three sections of a combined frame, as zero-copy subviews over `bytes`. */
57
+ export interface WorldSnapshotSections {
58
+ readonly dense: Uint8Array;
59
+ readonly sparse: Uint8Array;
60
+ readonly host: Uint8Array;
61
+ }
62
+ /** Split a combined frame back into its sections. Validates magic, version, and
63
+ * an exact (no trailing bytes) frame; throws `ECSRestoreError` otherwise. */
64
+ export declare function unframeWorldSnapshot(bytes: Uint8Array): WorldSnapshotSections;
65
+ /**
66
+ * Fail-closed registration guard, read **directly from the snapshot's dense
67
+ * bytes** so it can run BEFORE the dense backing is touched. `restoreInto`
68
+ * builds the restored store through the live world's in-place allocator
69
+ * (ADR-0008), which reuses the live backing buffer — so validating a
70
+ * *materialised* `ColumnStore` would already have overwritten live column data
71
+ * (the buffer is overwritten inside `restoreColumnStore`, before any post-build
72
+ * check could run). Parsing the descriptors off the raw `dense` `Uint8Array`
73
+ * keeps the check non-mutating, so a mismatch leaves the live world untouched.
74
+ *
75
+ * Asserts: the dense section's SAB magic + ABI, that its archetype set +
76
+ * per-archetype `componentMask` + per-column `(componentId, fieldId, typeTag)`
77
+ * match the live store's exactly (so every live `Archetype.refreshViews` finds
78
+ * its region and no snapshot archetype is orphaned), and that the entity-index
79
+ * capacity matches (the region is sized once at construction). The archetype
80
+ * graph is rebuilt from registration code, not the snapshot (mirroring
81
+ * `restoreSparse`'s "registered in the same order" contract). Throws
82
+ * `ECSRestoreError` on any mismatch / malformed section.
83
+ */
84
+ export declare function assertDenseLayoutMatchesLive(dense: Uint8Array, live: ReadonlyMap<number, ArchetypeViews>, liveEntityIndexCapacity: number): void;
85
+ //# sourceMappingURL=resume.d.ts.map
@@ -0,0 +1,85 @@
1
+ import { ArchetypeViews } from '../store/index.js';
2
+ /** Magic for the combined world-snapshot frame (`"WRS0"` little-endian). Distinct
3
+ * from the SAB `STORE_MAGIC` so a bare dense snapshot fed to `restoreInto` is
4
+ * rejected with a clear error instead of being mis-parsed as a combined frame. */
5
+ export declare const WORLD_SNAPSHOT_MAGIC = 810766935;
6
+ /** Combined-frame format version. Bumped if the section framing or host-state
7
+ * layout changes. Independent of `SIM_ABI_VERSION` (which gates the dense bytes). */
8
+ export declare const ECS_SNAPSHOT_VERSION = 1;
9
+ /** Thrown by `Store.restoreInto` (and the helpers here) when a combined snapshot
10
+ * is malformed, carries the wrong magic/version, or targets a world whose
11
+ * archetype/component registration doesn't match the snapshot. Mirrors
12
+ * `StoreRestoreError` / `SparseRestoreError` so callers see one error class per
13
+ * restore failure mode. */
14
+ export declare class ECSRestoreError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ /** Per-archetype host-side row bookkeeping the SAB doesn't carry authoritatively. */
18
+ export interface ArchetypeRowState {
19
+ readonly archetypeId: number;
20
+ /** Total live rows (enabled + disabled). */
21
+ readonly length: number;
22
+ /** Enabled-row partition boundary (#577): rows `[0, enabledCount)` enabled. */
23
+ readonly enabledCount: number;
24
+ }
25
+ /** The host-side state a snapshot captures alongside the dense + sparse bytes. */
26
+ export interface HostState {
27
+ /** World tick at snapshot time (`Store._tick`). */
28
+ readonly tick: number;
29
+ /** Entity-index high-water (count of slots ever issued). Also mirrored in the
30
+ * SAB region's `length` header; carried here for a cross-check on restore. */
31
+ readonly entityHighWater: number;
32
+ /** Live entity count. */
33
+ readonly entityAliveCount: number;
34
+ /** Recycle free-list in live order (LIFO: the last element is the next slot
35
+ * `createEntity` hands out). */
36
+ readonly freeIndices: readonly number[];
37
+ /** Per-archetype row state, one entry per SAB-backed archetype. */
38
+ readonly archetypeRows: readonly ArchetypeRowState[];
39
+ }
40
+ /** Serialize host-state to a self-contained little-endian byte buffer. Layout:
41
+ *
42
+ * [u32 tick][u32 highWater][u32 alive_count]
43
+ * [u32 freeCount][u32 free_index × freeCount]
44
+ * [u32 archCount][(u32 id, u32 length, u32 enabled_count) × archCount]
45
+ */
46
+ export declare function serializeHostState(hs: HostState): Uint8Array;
47
+ /** Parse host-state bytes produced by `serializeHostState`. Throws
48
+ * `ECSRestoreError` on truncation or a trailing-byte (non-canonical) buffer. */
49
+ export declare function parseHostState(bytes: Uint8Array): HostState;
50
+ /** Assemble the combined world-snapshot frame from its three sections. Layout:
51
+ *
52
+ * [u32 magic][u32 version][u32 denseLen][u32 sparseLen][u32 hostLen]
53
+ * [dense][sparse][host]
54
+ */
55
+ export declare function frameWorldSnapshot(dense: Uint8Array, sparse: Uint8Array, host: Uint8Array): Uint8Array;
56
+ /** The three sections of a combined frame, as zero-copy subviews over `bytes`. */
57
+ export interface WorldSnapshotSections {
58
+ readonly dense: Uint8Array;
59
+ readonly sparse: Uint8Array;
60
+ readonly host: Uint8Array;
61
+ }
62
+ /** Split a combined frame back into its sections. Validates magic, version, and
63
+ * an exact (no trailing bytes) frame; throws `ECSRestoreError` otherwise. */
64
+ export declare function unframeWorldSnapshot(bytes: Uint8Array): WorldSnapshotSections;
65
+ /**
66
+ * Fail-closed registration guard, read **directly from the snapshot's dense
67
+ * bytes** so it can run BEFORE the dense backing is touched. `restoreInto`
68
+ * builds the restored store through the live world's in-place allocator
69
+ * (ADR-0008), which reuses the live backing buffer — so validating a
70
+ * *materialised* `ColumnStore` would already have overwritten live column data
71
+ * (the buffer is overwritten inside `restoreColumnStore`, before any post-build
72
+ * check could run). Parsing the descriptors off the raw `dense` `Uint8Array`
73
+ * keeps the check non-mutating, so a mismatch leaves the live world untouched.
74
+ *
75
+ * Asserts: the dense section's SAB magic + ABI, that its archetype set +
76
+ * per-archetype `componentMask` + per-column `(componentId, fieldId, typeTag)`
77
+ * match the live store's exactly (so every live `Archetype.refreshViews` finds
78
+ * its region and no snapshot archetype is orphaned), and that the entity-index
79
+ * capacity matches (the region is sized once at construction). The archetype
80
+ * graph is rebuilt from registration code, not the snapshot (mirroring
81
+ * `restoreSparse`'s "registered in the same order" contract). Throws
82
+ * `ECSRestoreError` on any mismatch / malformed section.
83
+ */
84
+ export declare function assertDenseLayoutMatchesLive(dense: Uint8Array, live: ReadonlyMap<number, ArchetypeViews>, liveEntityIndexCapacity: number): void;
85
+ //# sourceMappingURL=resume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAUN,KAAK,cAAc,EACnB,MAAM,UAAU,CAAC;AAElB;;kFAEkF;AAClF,eAAO,MAAM,oBAAoB,YAAa,CAAC;AAE/C;qFACqF;AACrF,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;;2BAI2B;AAC3B,qBAAa,eAAgB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI3B;AAED,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACzB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;kFAC8E;IAC9E,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,yBAAyB;IACzB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC;oCACgC;IAChC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,mEAAmE;IACnE,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACrD;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,SAAS,GAAG,UAAU,CAwB5D;AAED;gFACgF;AAChF,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAqC3D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,GACd,UAAU,CAaZ;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC1B;AAED;6EAC6E;AAC7E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,qBAAqB,CAuC7E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,EACzC,uBAAuB,EAAE,MAAM,GAC7B,IAAI,CAoGN"}
@@ -0,0 +1,81 @@
1
+ import { ComponentDef } from './component.cjs';
2
+ import { ResourceKey } from './resource.cjs';
3
+ import { Query } from './query.cjs';
4
+ /**
5
+ * The read-only slice of `SystemContext` a run condition is handed. Deliberately
6
+ * narrow — a condition can read the ECS tick and resources, but has no path to
7
+ * mutate the world or read component columns directly (component reads go
8
+ * through a captured `Query`). `SystemContext` structurally satisfies this, so
9
+ * the schedule passes the live context unchanged.
10
+ */
11
+ export interface ConditionContext {
12
+ /** Current ECS tick — the deterministic clock built-ins key off. */
13
+ readonly ecsTick: number;
14
+ /** Read a resource value (checked against `resourceReads` in `DEV`). */
15
+ resource<T>(key: ResourceKey<T>): T;
16
+ /** Membership probe for a resource — unchecked, mirrors `hasComponent`. */
17
+ hasResource<T>(key: ResourceKey<T>): boolean;
18
+ }
19
+ /**
20
+ * A per-tick gate. `evaluate` returns `true` to run the gated system(s), `false`
21
+ * to skip them this tick. `reads` / `resourceReads` declare the predicate's
22
+ * read surface for `accessCheck` (dev) and the future parallel scheduler's
23
+ * read-edge graph; both are optional (absent reads as empty).
24
+ */
25
+ export interface RunCondition {
26
+ /** Human-readable label, surfaced in dev access-violation diagnostics. */
27
+ readonly name: string;
28
+ /** Pure, deterministic predicate. See the two hard rules in the file header. */
29
+ readonly evaluate: (ctx: ConditionContext) => boolean;
30
+ /** Components the predicate reads (via a captured query). Forward-looking
31
+ * metadata — `ConditionContext` exposes no direct column read, so this is
32
+ * not runtime-checkable today, but it is the read-edge a parallel scheduler
33
+ * will consume. */
34
+ readonly reads?: readonly ComponentDef[];
35
+ /** Resources the predicate reads. Validated at runtime in `DEV` when the
36
+ * condition evaluates inside `accessCheck.enterCondition`. */
37
+ readonly resourceReads?: readonly ResourceKey<any>[];
38
+ }
39
+ /**
40
+ * Run the gated system(s) only while a resource equals `expected` (strict `===`,
41
+ * so reference identity for objects). The canonical "feature flag / game phase"
42
+ * gate — flip `ecs.resources.set(key, …)` and the whole group toggles.
43
+ */
44
+ export declare function runIfResourceEq<T>(key: ResourceKey<T>, expected: T): RunCondition;
45
+ /**
46
+ * Run the gated system(s) once every `n` ticks — on ticks congruent to `offset`
47
+ * mod `n`. Keyed off the deterministic ECS tick, so it carries no private
48
+ * state and replays bit-identically. `offset` is a **phase shift taken mod `n`**
49
+ * (default `0` ⇒ fires on tick 0, n, 2n, …; `offset` and `offset + n` are the
50
+ * same phase, and a negative offset wraps), normalized once here into `[0, n)`.
51
+ * `n` must be a positive integer and `offset` an integer.
52
+ *
53
+ * The normalization isn't cosmetic: `(ecsTick - offset) % n` with a raw
54
+ * `offset ≥ n` (or negative) leans on JS's signed `%` yielding `-0` for a
55
+ * negative multiple (and `-0 === 0`) to stay congruent — correct, but load-
56
+ * bearing on a quirk. Folding `offset` into `[0, n)` up front makes the phase
57
+ * explicit: the per-tick dividend `ecsTick - phase` may still be negative
58
+ * (when `ecsTick < phase`), but with `phase ∈ [0, n)` it is never a *negative
59
+ * multiple* of `n` — it lands in `[-(n-1), -1]`, which holds no multiple of `n`
60
+ * — so `%` never produces `-0` and the check needs no signed-zero reliance.
61
+ */
62
+ export declare function runEveryNTicks(n: number, offset?: number): RunCondition;
63
+ /**
64
+ * Run the gated system(s) only when a query matches at least one (enabled)
65
+ * entity — flecs `runIf` over a query. The query is captured at config time;
66
+ * its component defs are declared as `reads`. `count()` is a membership sum over
67
+ * matching archetypes (no column reads), so it trips no `accessCheck` read.
68
+ *
69
+ * The query must be **dense-only**: `entityCount` asserts this in `DEV`
70
+ * (`_assertDenseOnly`), so pass a plain `ecs.query(...)` — a query carrying
71
+ * `.optional(...)` or sparse terms throws. Gate on sparse membership with a
72
+ * custom predicate over `forEachEntity` instead.
73
+ */
74
+ export declare function runIfAnyMatch(query: Query<readonly ComponentDef[]>): RunCondition;
75
+ /** Invert a condition: run exactly when `cond` would skip. */
76
+ export declare function not(cond: RunCondition): RunCondition;
77
+ /** Run only when EVERY condition passes (`&&`, short-circuit). */
78
+ export declare function allOf(...conds: RunCondition[]): RunCondition;
79
+ /** Run when ANY condition passes (`||`, short-circuit). */
80
+ export declare function anyOf(...conds: RunCondition[]): RunCondition;
81
+ //# sourceMappingURL=run_condition.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { ComponentDef } from './component.js';
2
+ import { ResourceKey } from './resource.js';
3
+ import { Query } from './query.js';
4
+ /**
5
+ * The read-only slice of `SystemContext` a run condition is handed. Deliberately
6
+ * narrow — a condition can read the ECS tick and resources, but has no path to
7
+ * mutate the world or read component columns directly (component reads go
8
+ * through a captured `Query`). `SystemContext` structurally satisfies this, so
9
+ * the schedule passes the live context unchanged.
10
+ */
11
+ export interface ConditionContext {
12
+ /** Current ECS tick — the deterministic clock built-ins key off. */
13
+ readonly ecsTick: number;
14
+ /** Read a resource value (checked against `resourceReads` in `DEV`). */
15
+ resource<T>(key: ResourceKey<T>): T;
16
+ /** Membership probe for a resource — unchecked, mirrors `hasComponent`. */
17
+ hasResource<T>(key: ResourceKey<T>): boolean;
18
+ }
19
+ /**
20
+ * A per-tick gate. `evaluate` returns `true` to run the gated system(s), `false`
21
+ * to skip them this tick. `reads` / `resourceReads` declare the predicate's
22
+ * read surface for `accessCheck` (dev) and the future parallel scheduler's
23
+ * read-edge graph; both are optional (absent reads as empty).
24
+ */
25
+ export interface RunCondition {
26
+ /** Human-readable label, surfaced in dev access-violation diagnostics. */
27
+ readonly name: string;
28
+ /** Pure, deterministic predicate. See the two hard rules in the file header. */
29
+ readonly evaluate: (ctx: ConditionContext) => boolean;
30
+ /** Components the predicate reads (via a captured query). Forward-looking
31
+ * metadata — `ConditionContext` exposes no direct column read, so this is
32
+ * not runtime-checkable today, but it is the read-edge a parallel scheduler
33
+ * will consume. */
34
+ readonly reads?: readonly ComponentDef[];
35
+ /** Resources the predicate reads. Validated at runtime in `DEV` when the
36
+ * condition evaluates inside `accessCheck.enterCondition`. */
37
+ readonly resourceReads?: readonly ResourceKey<any>[];
38
+ }
39
+ /**
40
+ * Run the gated system(s) only while a resource equals `expected` (strict `===`,
41
+ * so reference identity for objects). The canonical "feature flag / game phase"
42
+ * gate — flip `ecs.resources.set(key, …)` and the whole group toggles.
43
+ */
44
+ export declare function runIfResourceEq<T>(key: ResourceKey<T>, expected: T): RunCondition;
45
+ /**
46
+ * Run the gated system(s) once every `n` ticks — on ticks congruent to `offset`
47
+ * mod `n`. Keyed off the deterministic ECS tick, so it carries no private
48
+ * state and replays bit-identically. `offset` is a **phase shift taken mod `n`**
49
+ * (default `0` ⇒ fires on tick 0, n, 2n, …; `offset` and `offset + n` are the
50
+ * same phase, and a negative offset wraps), normalized once here into `[0, n)`.
51
+ * `n` must be a positive integer and `offset` an integer.
52
+ *
53
+ * The normalization isn't cosmetic: `(ecsTick - offset) % n` with a raw
54
+ * `offset ≥ n` (or negative) leans on JS's signed `%` yielding `-0` for a
55
+ * negative multiple (and `-0 === 0`) to stay congruent — correct, but load-
56
+ * bearing on a quirk. Folding `offset` into `[0, n)` up front makes the phase
57
+ * explicit: the per-tick dividend `ecsTick - phase` may still be negative
58
+ * (when `ecsTick < phase`), but with `phase ∈ [0, n)` it is never a *negative
59
+ * multiple* of `n` — it lands in `[-(n-1), -1]`, which holds no multiple of `n`
60
+ * — so `%` never produces `-0` and the check needs no signed-zero reliance.
61
+ */
62
+ export declare function runEveryNTicks(n: number, offset?: number): RunCondition;
63
+ /**
64
+ * Run the gated system(s) only when a query matches at least one (enabled)
65
+ * entity — flecs `runIf` over a query. The query is captured at config time;
66
+ * its component defs are declared as `reads`. `count()` is a membership sum over
67
+ * matching archetypes (no column reads), so it trips no `accessCheck` read.
68
+ *
69
+ * The query must be **dense-only**: `entityCount` asserts this in `DEV`
70
+ * (`_assertDenseOnly`), so pass a plain `ecs.query(...)` — a query carrying
71
+ * `.optional(...)` or sparse terms throws. Gate on sparse membership with a
72
+ * custom predicate over `forEachEntity` instead.
73
+ */
74
+ export declare function runIfAnyMatch(query: Query<readonly ComponentDef[]>): RunCondition;
75
+ /** Invert a condition: run exactly when `cond` would skip. */
76
+ export declare function not(cond: RunCondition): RunCondition;
77
+ /** Run only when EVERY condition passes (`&&`, short-circuit). */
78
+ export declare function allOf(...conds: RunCondition[]): RunCondition;
79
+ /** Run when ANY condition passes (`||`, short-circuit). */
80
+ export declare function anyOf(...conds: RunCondition[]): RunCondition;
81
+ //# sourceMappingURL=run_condition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run_condition.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/run_condition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BK;AAEL,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIrC;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,2EAA2E;IAC3E,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC;IACtD;;;wBAGoB;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IACzC;mEAC+D;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;CACrD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,YAAY,CAcjF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,YAAY,CAoBlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,YAAY,EAAE,CAAC,GAAG,YAAY,CAMjF;AA4BD,8DAA8D;AAC9D,wBAAgB,GAAG,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAMpD;AAED,kEAAkE;AAClE,wBAAgB,KAAK,CAAC,GAAG,KAAK,EAAE,YAAY,EAAE,GAAG,YAAY,CAM5D;AAED,2DAA2D;AAC3D,wBAAgB,KAAK,CAAC,GAAG,KAAK,EAAE,YAAY,EAAE,GAAG,YAAY,CAM5D"}
@@ -0,0 +1,142 @@
1
+ import { SystemContext } from './query.cjs';
2
+ import { SystemDescriptor } from './system.cjs';
3
+ import { ComputeBackend } from './compute_backend.cjs';
4
+ import { RunCondition } from './run_condition.cjs';
5
+ export declare enum SCHEDULE {
6
+ PRE_STARTUP = "PRE_STARTUP",
7
+ STARTUP = "STARTUP",
8
+ POST_STARTUP = "POST_STARTUP",
9
+ FIXED_UPDATE = "FIXED_UPDATE",
10
+ PRE_UPDATE = "PRE_UPDATE",
11
+ UPDATE = "UPDATE",
12
+ POST_UPDATE = "POST_UPDATE"
13
+ }
14
+ /**
15
+ * An opaque handle for a named group of systems (#576). A set carries a shared
16
+ * run condition and shared ordering that every member inherits. Sets are
17
+ * identified by **object identity**, not by name — create one with
18
+ * `systemSet(name)`, hold the handle, and reuse it across `addSystems`
19
+ * (`SystemEntry.set`) and `Schedule.configureSet`. The `name` is for
20
+ * diagnostics only.
21
+ */
22
+ export interface SystemSet {
23
+ readonly name: string;
24
+ }
25
+ /** Create a `SystemSet` handle (#576). Two calls with the same name are two
26
+ * distinct sets — keep the returned handle and pass it around. */
27
+ export declare function systemSet(name: string): SystemSet;
28
+ /** A `before`/`after` ordering target: either a concrete system or a whole set
29
+ * (expanded to its members within the same phase at sort time). */
30
+ export type SystemOrderingTarget = SystemDescriptor | SystemSet;
31
+ /** Shared configuration applied to a `SystemSet` via `configureSet` (#576).
32
+ * Accumulates across calls — conditions AND together, ordering targets union. */
33
+ export interface SystemSetConfig {
34
+ /** Condition(s) every member is gated by (ANDed with each member's own). */
35
+ runIf?: RunCondition | readonly RunCondition[];
36
+ /** Every member runs before each of these targets. */
37
+ before?: readonly SystemOrderingTarget[];
38
+ /** Every member runs after each of these targets. */
39
+ after?: readonly SystemOrderingTarget[];
40
+ }
41
+ export interface SystemOrdering {
42
+ before?: readonly SystemOrderingTarget[];
43
+ after?: readonly SystemOrderingTarget[];
44
+ }
45
+ export interface SystemEntry {
46
+ system: SystemDescriptor;
47
+ ordering?: SystemOrdering;
48
+ /** Run condition(s) gating just this system — ANDed with any set conditions
49
+ * it inherits (#576). A `false` verdict skips the body that tick. */
50
+ runIf?: RunCondition | readonly RunCondition[];
51
+ /** Set membership — the system inherits each set's shared condition and
52
+ * ordering (#576). */
53
+ set?: SystemSet | readonly SystemSet[];
54
+ }
55
+ export declare class Schedule {
56
+ private readonly labelSystems;
57
+ private readonly sortedCache;
58
+ private readonly systemIndex;
59
+ private readonly systemLastRun;
60
+ private readonly gatedSystems;
61
+ private readonly setConditions;
62
+ private readonly setOrdering;
63
+ private nextInsertionOrder;
64
+ private _backend;
65
+ /** Dev-diagnostic sink (`ECSOptions.onWarn`); defaults to `console.warn`.
66
+ * The only schedule diagnostic today is `warnDroppedEdge`. */
67
+ private readonly onWarn;
68
+ constructor(onWarn?: (message: string) => void);
69
+ addSystems(label: SCHEDULE, ...entries: (SystemDescriptor | SystemEntry)[]): void;
70
+ /**
71
+ * Configure a `SystemSet` (#576) — its shared run condition(s) and/or
72
+ * ordering, inherited by every member. Additive and order-independent w.r.t.
73
+ * `addSystems`: conditions accumulate (ANDed), ordering targets union, and
74
+ * a member added before or after this call picks the configuration up.
75
+ */
76
+ configureSet(set: SystemSet, config: SystemSetConfig): void;
77
+ removeSystem(system: SystemDescriptor): void;
78
+ /** Attach (or, with `null`, detach) the opt-in compute backend (#622). Driven
79
+ * by `ECS.attachBackend`; routes any scheduled system carrying a
80
+ * `backendHandle` to `backend.run(handle)` in place of its `fn`. */
81
+ setBackend(backend: ComputeBackend | null): void;
82
+ runStartup(ctx: SystemContext, tick: number): void;
83
+ runUpdate(ctx: SystemContext, deltaTime: number, tick: number): void;
84
+ runFixedUpdate(ctx: SystemContext, fixedDt: number, tick: number): void;
85
+ hasFixedSystems(): boolean;
86
+ getAllSystems(): SystemDescriptor[];
87
+ hasSystem(system: SystemDescriptor): boolean;
88
+ clear(): void;
89
+ private runLabel;
90
+ /**
91
+ * Whether a gated system runs this tick — the AND of its own conditions and
92
+ * every set it belongs to. A set's conditions are evaluated at most once per
93
+ * phase (memoized in `setVerdicts`) and the verdict gates every member of the
94
+ * set uniformly; a `configureSet` between phases is still honored because the
95
+ * memo lives only for a single `runLabel` pass. Short-circuits on the first
96
+ * `false`. The system's own conditions evaluate per system, in canonical order.
97
+ *
98
+ * #731 SEMANTIC NOTE: this evaluates a set's conditions once-per-set-per-phase
99
+ * rather than once-per-member. Equivalent for pure RunConditions; observably
100
+ * different only if a set condition reads state mutated earlier in the SAME
101
+ * phase (resources write immediately). That is intentional — the set gates as a
102
+ * unit, so all its members share one verdict for the phase.
103
+ */
104
+ private shouldRun;
105
+ /** Evaluate a condition list with AND semantics. Each predicate runs inside a
106
+ * reads-only `accessCheck` span (dev), so a condition that reads an
107
+ * undeclared resource — or attempts any mutation — throws. */
108
+ private evalConditions;
109
+ private getSorted;
110
+ /**
111
+ * Delegates to the shared topologicalSort utility.
112
+ * Builds the dependency edge map from before/after constraints, then
113
+ * catches any cycle TypeError and re-throws as ECSError.
114
+ */
115
+ private sortSystems;
116
+ /**
117
+ * Add the topo edges for one ordering list (#576). For `"before"` the source
118
+ * runs before each target (edge source→target); for `"after"` it runs after
119
+ * each target (edge target→source). A `SystemSet` target expands to every
120
+ * member within this phase (self-edges skipped, so a member ordered against
121
+ * its own set is a no-op); a descriptor target absent from this phase is
122
+ * dropped — with a dev warning only for a concrete system, since a set
123
+ * legitimately expands to nothing when its members live in another phase.
124
+ */
125
+ private resolveEdges;
126
+ /** Push one directed edge into the adjacency map. Both endpoints are known to
127
+ * be in this phase (callers guard), so `edges.get(...)` is non-null. */
128
+ private addDirectedEdge;
129
+ /**
130
+ * Dev-only diagnostic for an ordering edge that was dropped during sort.
131
+ *
132
+ * Cross-label ordering is impossible by design (`nodeSet` is per-label), so
133
+ * a target registered in *another* phase is skipped silently — that's the
134
+ * intended isolation. But a target unknown to *every* phase is almost
135
+ * certainly a typo or a system that was never scheduled; without this warning
136
+ * the constraint vanishes and the system runs in insertion-order tiebreak as
137
+ * if unconstrained, with nothing to distinguish mistake from intent. Compiled
138
+ * out of production builds by the `DEV` guards at the call sites.
139
+ */
140
+ private warnDroppedEdge;
141
+ }
142
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1,142 @@
1
+ import { SystemContext } from './query.js';
2
+ import { SystemDescriptor } from './system.js';
3
+ import { ComputeBackend } from './compute_backend.js';
4
+ import { RunCondition } from './run_condition.js';
5
+ export declare enum SCHEDULE {
6
+ PRE_STARTUP = "PRE_STARTUP",
7
+ STARTUP = "STARTUP",
8
+ POST_STARTUP = "POST_STARTUP",
9
+ FIXED_UPDATE = "FIXED_UPDATE",
10
+ PRE_UPDATE = "PRE_UPDATE",
11
+ UPDATE = "UPDATE",
12
+ POST_UPDATE = "POST_UPDATE"
13
+ }
14
+ /**
15
+ * An opaque handle for a named group of systems (#576). A set carries a shared
16
+ * run condition and shared ordering that every member inherits. Sets are
17
+ * identified by **object identity**, not by name — create one with
18
+ * `systemSet(name)`, hold the handle, and reuse it across `addSystems`
19
+ * (`SystemEntry.set`) and `Schedule.configureSet`. The `name` is for
20
+ * diagnostics only.
21
+ */
22
+ export interface SystemSet {
23
+ readonly name: string;
24
+ }
25
+ /** Create a `SystemSet` handle (#576). Two calls with the same name are two
26
+ * distinct sets — keep the returned handle and pass it around. */
27
+ export declare function systemSet(name: string): SystemSet;
28
+ /** A `before`/`after` ordering target: either a concrete system or a whole set
29
+ * (expanded to its members within the same phase at sort time). */
30
+ export type SystemOrderingTarget = SystemDescriptor | SystemSet;
31
+ /** Shared configuration applied to a `SystemSet` via `configureSet` (#576).
32
+ * Accumulates across calls — conditions AND together, ordering targets union. */
33
+ export interface SystemSetConfig {
34
+ /** Condition(s) every member is gated by (ANDed with each member's own). */
35
+ runIf?: RunCondition | readonly RunCondition[];
36
+ /** Every member runs before each of these targets. */
37
+ before?: readonly SystemOrderingTarget[];
38
+ /** Every member runs after each of these targets. */
39
+ after?: readonly SystemOrderingTarget[];
40
+ }
41
+ export interface SystemOrdering {
42
+ before?: readonly SystemOrderingTarget[];
43
+ after?: readonly SystemOrderingTarget[];
44
+ }
45
+ export interface SystemEntry {
46
+ system: SystemDescriptor;
47
+ ordering?: SystemOrdering;
48
+ /** Run condition(s) gating just this system — ANDed with any set conditions
49
+ * it inherits (#576). A `false` verdict skips the body that tick. */
50
+ runIf?: RunCondition | readonly RunCondition[];
51
+ /** Set membership — the system inherits each set's shared condition and
52
+ * ordering (#576). */
53
+ set?: SystemSet | readonly SystemSet[];
54
+ }
55
+ export declare class Schedule {
56
+ private readonly labelSystems;
57
+ private readonly sortedCache;
58
+ private readonly systemIndex;
59
+ private readonly systemLastRun;
60
+ private readonly gatedSystems;
61
+ private readonly setConditions;
62
+ private readonly setOrdering;
63
+ private nextInsertionOrder;
64
+ private _backend;
65
+ /** Dev-diagnostic sink (`ECSOptions.onWarn`); defaults to `console.warn`.
66
+ * The only schedule diagnostic today is `warnDroppedEdge`. */
67
+ private readonly onWarn;
68
+ constructor(onWarn?: (message: string) => void);
69
+ addSystems(label: SCHEDULE, ...entries: (SystemDescriptor | SystemEntry)[]): void;
70
+ /**
71
+ * Configure a `SystemSet` (#576) — its shared run condition(s) and/or
72
+ * ordering, inherited by every member. Additive and order-independent w.r.t.
73
+ * `addSystems`: conditions accumulate (ANDed), ordering targets union, and
74
+ * a member added before or after this call picks the configuration up.
75
+ */
76
+ configureSet(set: SystemSet, config: SystemSetConfig): void;
77
+ removeSystem(system: SystemDescriptor): void;
78
+ /** Attach (or, with `null`, detach) the opt-in compute backend (#622). Driven
79
+ * by `ECS.attachBackend`; routes any scheduled system carrying a
80
+ * `backendHandle` to `backend.run(handle)` in place of its `fn`. */
81
+ setBackend(backend: ComputeBackend | null): void;
82
+ runStartup(ctx: SystemContext, tick: number): void;
83
+ runUpdate(ctx: SystemContext, deltaTime: number, tick: number): void;
84
+ runFixedUpdate(ctx: SystemContext, fixedDt: number, tick: number): void;
85
+ hasFixedSystems(): boolean;
86
+ getAllSystems(): SystemDescriptor[];
87
+ hasSystem(system: SystemDescriptor): boolean;
88
+ clear(): void;
89
+ private runLabel;
90
+ /**
91
+ * Whether a gated system runs this tick — the AND of its own conditions and
92
+ * every set it belongs to. A set's conditions are evaluated at most once per
93
+ * phase (memoized in `setVerdicts`) and the verdict gates every member of the
94
+ * set uniformly; a `configureSet` between phases is still honored because the
95
+ * memo lives only for a single `runLabel` pass. Short-circuits on the first
96
+ * `false`. The system's own conditions evaluate per system, in canonical order.
97
+ *
98
+ * #731 SEMANTIC NOTE: this evaluates a set's conditions once-per-set-per-phase
99
+ * rather than once-per-member. Equivalent for pure RunConditions; observably
100
+ * different only if a set condition reads state mutated earlier in the SAME
101
+ * phase (resources write immediately). That is intentional — the set gates as a
102
+ * unit, so all its members share one verdict for the phase.
103
+ */
104
+ private shouldRun;
105
+ /** Evaluate a condition list with AND semantics. Each predicate runs inside a
106
+ * reads-only `accessCheck` span (dev), so a condition that reads an
107
+ * undeclared resource — or attempts any mutation — throws. */
108
+ private evalConditions;
109
+ private getSorted;
110
+ /**
111
+ * Delegates to the shared topologicalSort utility.
112
+ * Builds the dependency edge map from before/after constraints, then
113
+ * catches any cycle TypeError and re-throws as ECSError.
114
+ */
115
+ private sortSystems;
116
+ /**
117
+ * Add the topo edges for one ordering list (#576). For `"before"` the source
118
+ * runs before each target (edge source→target); for `"after"` it runs after
119
+ * each target (edge target→source). A `SystemSet` target expands to every
120
+ * member within this phase (self-edges skipped, so a member ordered against
121
+ * its own set is a no-op); a descriptor target absent from this phase is
122
+ * dropped — with a dev warning only for a concrete system, since a set
123
+ * legitimately expands to nothing when its members live in another phase.
124
+ */
125
+ private resolveEdges;
126
+ /** Push one directed edge into the adjacency map. Both endpoints are known to
127
+ * be in this phase (callers guard), so `edges.get(...)` is non-null. */
128
+ private addDirectedEdge;
129
+ /**
130
+ * Dev-only diagnostic for an ordering edge that was dropped during sort.
131
+ *
132
+ * Cross-label ordering is impossible by design (`nodeSet` is per-label), so
133
+ * a target registered in *another* phase is skipped silently — that's the
134
+ * intended isolation. But a target unknown to *every* phase is almost
135
+ * certainly a typo or a system that was never scheduled; without this warning
136
+ * the constraint vanishes and the system runs in insertion-order tiebreak as
137
+ * if unconstrained, with nothing to distinguish mistake from intent. Compiled
138
+ * out of production builds by the `DEV` guards at the call sites.
139
+ */
140
+ private warnDroppedEdge;
141
+ }
142
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/schedule.ts"],"names":[],"mappings":"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"}