@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,179 @@
1
+ import { InPlaceBufferAllocator } from '../store/index.cjs';
2
+ /** Default byte ceiling of the growable backing — mirrors
3
+ * `growableSabAllocator`'s default (see its doc comment for the measured
4
+ * footprint analysis that makes 256 MiB structurally unreachable). */
5
+ export declare const DEFAULT_ECS_CAP_BYTES: number;
6
+ /** Headroom multiplier applied to a budget's live column bytes: capacity
7
+ * doubling plus abandoned in-place holes bound worst-case footprint at ~3×
8
+ * live data (footprint analysis in `growableSabAllocator`'s doc). */
9
+ export declare const BUDGET_GROWTH_HEADROOM = 3;
10
+ /** Default average fully-populated row stride assumed by the budget arm.
11
+ * The instrumented 2-party workload measured ~49 B/entity; 64 rounds up. */
12
+ export declare const BUDGET_DEFAULT_BYTES_PER_ENTITY = 64;
13
+ /** Default archetype spread assumed by the budget arm when the consumer
14
+ * doesn't declare one. Drives only the derived per-archetype column
15
+ * capacity, not correctness — an under-declared spread just means earlier
16
+ * (amortised) column doubling. */
17
+ export declare const BUDGET_DEFAULT_ARCHETYPES = 8;
18
+ /** Sizing intent: "I expect a world about this big." The engine derives
19
+ * column capacity, entity-index reservation, and the byte cap from it, and
20
+ * cap errors are phrased against this budget. */
21
+ export interface EntityBudget {
22
+ /** Expected peak live entities — the one number most callers know.
23
+ * Bounded by the EntityID 20-bit index space (1<<20). */
24
+ readonly entities: number;
25
+ /** Expected distinct archetypes the entities spread across.
26
+ * Default `BUDGET_DEFAULT_ARCHETYPES`. */
27
+ readonly archetypes?: number;
28
+ /** Average fully-populated row stride in bytes.
29
+ * Default `BUDGET_DEFAULT_BYTES_PER_ENTITY`. */
30
+ readonly bytesPerEntity?: number;
31
+ }
32
+ /** WASM-backed memory, first-class (#682). Either bring your own shared
33
+ * `WebAssembly.Memory` (the server match context does — its sim factory
34
+ * owns the memory), or declare page bounds and let the engine construct
35
+ * it — replacing the hand-wired incantation that previously lived only in
36
+ * `workbench/ecs/scripts/run-memory.ts`. */
37
+ export type WasmMemoryArm = {
38
+ readonly memory: WebAssembly.Memory;
39
+ readonly initialPages?: never;
40
+ readonly maximumPages?: never;
41
+ } | {
42
+ readonly maximumPages: number;
43
+ readonly initialPages?: number;
44
+ readonly memory?: never;
45
+ };
46
+ /** Pure-TS **heap** backing (#643 / ADR-0018 §1B): a plain resizable
47
+ * `ArrayBuffer` instead of a `SharedArrayBuffer`. Needs no cross-origin
48
+ * isolation (COOP/COEP) and is the intended default for embedders that can't
49
+ * set those headers (the oecs profile). Trade-off: no worker offload and no
50
+ * WASM compute backend — both require a transferable `SharedArrayBuffer`. An
51
+ * empty `{}` takes the default 256 MiB growable cap. */
52
+ export interface HeapMemoryArm {
53
+ /** Byte ceiling of the growable heap backing. Default
54
+ * `DEFAULT_ECS_CAP_BYTES` (256 MiB), same hard-ceiling semantics as the
55
+ * SAB backing (#380). */
56
+ readonly maxBytes?: number;
57
+ }
58
+ /** Opt-in **shared-memory** backing (`@oasys/oecs/shared`): a growable
59
+ * `SharedArrayBuffer` instead of a plain `ArrayBuffer`. Required for worker
60
+ * offload and a WASM compute backend, but needs cross-origin isolation
61
+ * (COOP/COEP) in browsers. Empty `{}` takes the default 256 MiB growable cap. */
62
+ export interface SharedMemoryArm {
63
+ /** Byte ceiling of the growable shared backing. Default
64
+ * `DEFAULT_ECS_CAP_BYTES` (256 MiB), hard-ceiling semantics (#380). */
65
+ readonly maxBytes?: number;
66
+ }
67
+ /** Pinnable on every arm: exact initial rows per archetype column. The
68
+ * budget arm derives one when unpinned; every other arm defaults to
69
+ * `DEFAULT_COLUMN_CAPACITY`. */
70
+ interface ColumnCapacityPin {
71
+ readonly columnCapacity?: number;
72
+ }
73
+ /**
74
+ * The single sizing option on `ECSOptions.memory`. Key-discriminated —
75
+ * exactly one of `budget` | `maxBytes` | `wasm` | `allocator`, or none for
76
+ * default sizing. The `never` fields make a two-arm literal a type error;
77
+ * `resolveECSMemory` backstops untyped JS callers at runtime.
78
+ */
79
+ export type ECSMemoryOptions = ({
80
+ readonly budget: EntityBudget;
81
+ readonly maxBytes?: never;
82
+ readonly wasm?: never;
83
+ readonly allocator?: never;
84
+ readonly heap?: never;
85
+ readonly shared?: never;
86
+ } & ColumnCapacityPin) | ({
87
+ readonly maxBytes: number;
88
+ readonly budget?: never;
89
+ readonly wasm?: never;
90
+ readonly allocator?: never;
91
+ readonly heap?: never;
92
+ readonly shared?: never;
93
+ } & ColumnCapacityPin) | ({
94
+ readonly wasm: WasmMemoryArm;
95
+ readonly budget?: never;
96
+ readonly maxBytes?: never;
97
+ readonly allocator?: never;
98
+ readonly heap?: never;
99
+ readonly shared?: never;
100
+ } & ColumnCapacityPin) | ({
101
+ readonly heap: HeapMemoryArm;
102
+ readonly budget?: never;
103
+ readonly maxBytes?: never;
104
+ readonly wasm?: never;
105
+ readonly allocator?: never;
106
+ readonly shared?: never;
107
+ } & ColumnCapacityPin) | ({
108
+ readonly shared: SharedMemoryArm;
109
+ readonly budget?: never;
110
+ readonly maxBytes?: never;
111
+ readonly wasm?: never;
112
+ readonly allocator?: never;
113
+ readonly heap?: never;
114
+ } & ColumnCapacityPin) | ({
115
+ /** Expert escape hatch. Typed `InPlaceBufferAllocator` so only
116
+ * allocators that statically declare `isInPlace: true` compile —
117
+ * the ADR-0008 boundary. `DEFAULT_SAB_ALLOCATOR` is rejected by the
118
+ * type system; non-in-place allocators stay snapshot/test-sizing
119
+ * utilities. */
120
+ readonly allocator: InPlaceBufferAllocator;
121
+ /** The allocator owns its real ceiling; this hint only labels
122
+ * diagnostics (cap errors, `memoryPlan.derivation`). */
123
+ readonly capBytesHint?: number;
124
+ readonly budget?: never;
125
+ readonly maxBytes?: never;
126
+ readonly wasm?: never;
127
+ readonly heap?: never;
128
+ readonly shared?: never;
129
+ } & ColumnCapacityPin) | ({
130
+ /** No sizing arm: default growable backing (256 MiB cap), with the
131
+ * column capacity optionally pinned — the minimal migration from the
132
+ * removed `initialCapacity` knob. */
133
+ readonly budget?: never;
134
+ readonly maxBytes?: never;
135
+ readonly wasm?: never;
136
+ readonly allocator?: never;
137
+ readonly heap?: never;
138
+ readonly shared?: never;
139
+ } & ColumnCapacityPin);
140
+ /** What the caller's intent resolved to. Exposed as `ECS.memoryPlan` for
141
+ * diagnostics; `intentLabel`/`budgetEntities`/`capBytes` also travel
142
+ * into `Store` so cap errors speak the caller's language. */
143
+ export interface ResolvedECSMemory {
144
+ readonly source: "default" | "budget" | "max_bytes" | "wasm" | "allocator" | "heap" | "shared";
145
+ readonly allocator: InPlaceBufferAllocator;
146
+ readonly columnCapacity: number;
147
+ readonly entityIndexCapacity: number;
148
+ /** Byte ceiling of the backing, `null` when unknowable from JS (a
149
+ * bring-your-own `WebAssembly.Memory` hides its `maximum`; a custom
150
+ * allocator owns its own cap unless hinted). */
151
+ readonly capBytes: number | null;
152
+ /** Human phrasing of the declared intent — reused verbatim in cap
153
+ * errors so the failure names what the caller asked for. */
154
+ readonly intentLabel: string;
155
+ /** The declared entity budget when the budget arm was used — drives the
156
+ * "N× the declared budget" cap-error diagnostic. */
157
+ readonly budgetEntities: number | null;
158
+ /** How each derived number was arrived at, one line per decision. */
159
+ readonly derivation: readonly string[];
160
+ /** The backing `WebAssembly.Memory` when the wasm arm was used (both
161
+ * bring-your-own and engine-constructed) — the consumer hands this to
162
+ * its WASM `ComputeBackend` so the sim and the columns share bytes. */
163
+ readonly wasmMemory: WebAssembly.Memory | null;
164
+ }
165
+ /** Subset of the plan `Store` needs to phrase cap/overflow errors in the
166
+ * caller's terms. */
167
+ export interface ECSMemoryCapContext {
168
+ readonly capBytes: number | null;
169
+ readonly intentLabel: string;
170
+ readonly budgetEntities: number | null;
171
+ }
172
+ /**
173
+ * Turn a consumer's sizing intent into a concrete memory plan. Pure apart
174
+ * from allocator/Memory construction; throws `INVALID_MEMORY_OPTIONS` on a
175
+ * malformed option set — at construction, not first-grow.
176
+ */
177
+ export declare function resolveECSMemory(opts?: ECSMemoryOptions): ResolvedECSMemory;
178
+ export {};
179
+ //# sourceMappingURL=ecs_memory.d.ts.map
@@ -0,0 +1,179 @@
1
+ import { InPlaceBufferAllocator } from '../store/index.js';
2
+ /** Default byte ceiling of the growable backing — mirrors
3
+ * `growableSabAllocator`'s default (see its doc comment for the measured
4
+ * footprint analysis that makes 256 MiB structurally unreachable). */
5
+ export declare const DEFAULT_ECS_CAP_BYTES: number;
6
+ /** Headroom multiplier applied to a budget's live column bytes: capacity
7
+ * doubling plus abandoned in-place holes bound worst-case footprint at ~3×
8
+ * live data (footprint analysis in `growableSabAllocator`'s doc). */
9
+ export declare const BUDGET_GROWTH_HEADROOM = 3;
10
+ /** Default average fully-populated row stride assumed by the budget arm.
11
+ * The instrumented 2-party workload measured ~49 B/entity; 64 rounds up. */
12
+ export declare const BUDGET_DEFAULT_BYTES_PER_ENTITY = 64;
13
+ /** Default archetype spread assumed by the budget arm when the consumer
14
+ * doesn't declare one. Drives only the derived per-archetype column
15
+ * capacity, not correctness — an under-declared spread just means earlier
16
+ * (amortised) column doubling. */
17
+ export declare const BUDGET_DEFAULT_ARCHETYPES = 8;
18
+ /** Sizing intent: "I expect a world about this big." The engine derives
19
+ * column capacity, entity-index reservation, and the byte cap from it, and
20
+ * cap errors are phrased against this budget. */
21
+ export interface EntityBudget {
22
+ /** Expected peak live entities — the one number most callers know.
23
+ * Bounded by the EntityID 20-bit index space (1<<20). */
24
+ readonly entities: number;
25
+ /** Expected distinct archetypes the entities spread across.
26
+ * Default `BUDGET_DEFAULT_ARCHETYPES`. */
27
+ readonly archetypes?: number;
28
+ /** Average fully-populated row stride in bytes.
29
+ * Default `BUDGET_DEFAULT_BYTES_PER_ENTITY`. */
30
+ readonly bytesPerEntity?: number;
31
+ }
32
+ /** WASM-backed memory, first-class (#682). Either bring your own shared
33
+ * `WebAssembly.Memory` (the server match context does — its sim factory
34
+ * owns the memory), or declare page bounds and let the engine construct
35
+ * it — replacing the hand-wired incantation that previously lived only in
36
+ * `workbench/ecs/scripts/run-memory.ts`. */
37
+ export type WasmMemoryArm = {
38
+ readonly memory: WebAssembly.Memory;
39
+ readonly initialPages?: never;
40
+ readonly maximumPages?: never;
41
+ } | {
42
+ readonly maximumPages: number;
43
+ readonly initialPages?: number;
44
+ readonly memory?: never;
45
+ };
46
+ /** Pure-TS **heap** backing (#643 / ADR-0018 §1B): a plain resizable
47
+ * `ArrayBuffer` instead of a `SharedArrayBuffer`. Needs no cross-origin
48
+ * isolation (COOP/COEP) and is the intended default for embedders that can't
49
+ * set those headers (the oecs profile). Trade-off: no worker offload and no
50
+ * WASM compute backend — both require a transferable `SharedArrayBuffer`. An
51
+ * empty `{}` takes the default 256 MiB growable cap. */
52
+ export interface HeapMemoryArm {
53
+ /** Byte ceiling of the growable heap backing. Default
54
+ * `DEFAULT_ECS_CAP_BYTES` (256 MiB), same hard-ceiling semantics as the
55
+ * SAB backing (#380). */
56
+ readonly maxBytes?: number;
57
+ }
58
+ /** Opt-in **shared-memory** backing (`@oasys/oecs/shared`): a growable
59
+ * `SharedArrayBuffer` instead of a plain `ArrayBuffer`. Required for worker
60
+ * offload and a WASM compute backend, but needs cross-origin isolation
61
+ * (COOP/COEP) in browsers. Empty `{}` takes the default 256 MiB growable cap. */
62
+ export interface SharedMemoryArm {
63
+ /** Byte ceiling of the growable shared backing. Default
64
+ * `DEFAULT_ECS_CAP_BYTES` (256 MiB), hard-ceiling semantics (#380). */
65
+ readonly maxBytes?: number;
66
+ }
67
+ /** Pinnable on every arm: exact initial rows per archetype column. The
68
+ * budget arm derives one when unpinned; every other arm defaults to
69
+ * `DEFAULT_COLUMN_CAPACITY`. */
70
+ interface ColumnCapacityPin {
71
+ readonly columnCapacity?: number;
72
+ }
73
+ /**
74
+ * The single sizing option on `ECSOptions.memory`. Key-discriminated —
75
+ * exactly one of `budget` | `maxBytes` | `wasm` | `allocator`, or none for
76
+ * default sizing. The `never` fields make a two-arm literal a type error;
77
+ * `resolveECSMemory` backstops untyped JS callers at runtime.
78
+ */
79
+ export type ECSMemoryOptions = ({
80
+ readonly budget: EntityBudget;
81
+ readonly maxBytes?: never;
82
+ readonly wasm?: never;
83
+ readonly allocator?: never;
84
+ readonly heap?: never;
85
+ readonly shared?: never;
86
+ } & ColumnCapacityPin) | ({
87
+ readonly maxBytes: number;
88
+ readonly budget?: never;
89
+ readonly wasm?: never;
90
+ readonly allocator?: never;
91
+ readonly heap?: never;
92
+ readonly shared?: never;
93
+ } & ColumnCapacityPin) | ({
94
+ readonly wasm: WasmMemoryArm;
95
+ readonly budget?: never;
96
+ readonly maxBytes?: never;
97
+ readonly allocator?: never;
98
+ readonly heap?: never;
99
+ readonly shared?: never;
100
+ } & ColumnCapacityPin) | ({
101
+ readonly heap: HeapMemoryArm;
102
+ readonly budget?: never;
103
+ readonly maxBytes?: never;
104
+ readonly wasm?: never;
105
+ readonly allocator?: never;
106
+ readonly shared?: never;
107
+ } & ColumnCapacityPin) | ({
108
+ readonly shared: SharedMemoryArm;
109
+ readonly budget?: never;
110
+ readonly maxBytes?: never;
111
+ readonly wasm?: never;
112
+ readonly allocator?: never;
113
+ readonly heap?: never;
114
+ } & ColumnCapacityPin) | ({
115
+ /** Expert escape hatch. Typed `InPlaceBufferAllocator` so only
116
+ * allocators that statically declare `isInPlace: true` compile —
117
+ * the ADR-0008 boundary. `DEFAULT_SAB_ALLOCATOR` is rejected by the
118
+ * type system; non-in-place allocators stay snapshot/test-sizing
119
+ * utilities. */
120
+ readonly allocator: InPlaceBufferAllocator;
121
+ /** The allocator owns its real ceiling; this hint only labels
122
+ * diagnostics (cap errors, `memoryPlan.derivation`). */
123
+ readonly capBytesHint?: number;
124
+ readonly budget?: never;
125
+ readonly maxBytes?: never;
126
+ readonly wasm?: never;
127
+ readonly heap?: never;
128
+ readonly shared?: never;
129
+ } & ColumnCapacityPin) | ({
130
+ /** No sizing arm: default growable backing (256 MiB cap), with the
131
+ * column capacity optionally pinned — the minimal migration from the
132
+ * removed `initialCapacity` knob. */
133
+ readonly budget?: never;
134
+ readonly maxBytes?: never;
135
+ readonly wasm?: never;
136
+ readonly allocator?: never;
137
+ readonly heap?: never;
138
+ readonly shared?: never;
139
+ } & ColumnCapacityPin);
140
+ /** What the caller's intent resolved to. Exposed as `ECS.memoryPlan` for
141
+ * diagnostics; `intentLabel`/`budgetEntities`/`capBytes` also travel
142
+ * into `Store` so cap errors speak the caller's language. */
143
+ export interface ResolvedECSMemory {
144
+ readonly source: "default" | "budget" | "max_bytes" | "wasm" | "allocator" | "heap" | "shared";
145
+ readonly allocator: InPlaceBufferAllocator;
146
+ readonly columnCapacity: number;
147
+ readonly entityIndexCapacity: number;
148
+ /** Byte ceiling of the backing, `null` when unknowable from JS (a
149
+ * bring-your-own `WebAssembly.Memory` hides its `maximum`; a custom
150
+ * allocator owns its own cap unless hinted). */
151
+ readonly capBytes: number | null;
152
+ /** Human phrasing of the declared intent — reused verbatim in cap
153
+ * errors so the failure names what the caller asked for. */
154
+ readonly intentLabel: string;
155
+ /** The declared entity budget when the budget arm was used — drives the
156
+ * "N× the declared budget" cap-error diagnostic. */
157
+ readonly budgetEntities: number | null;
158
+ /** How each derived number was arrived at, one line per decision. */
159
+ readonly derivation: readonly string[];
160
+ /** The backing `WebAssembly.Memory` when the wasm arm was used (both
161
+ * bring-your-own and engine-constructed) — the consumer hands this to
162
+ * its WASM `ComputeBackend` so the sim and the columns share bytes. */
163
+ readonly wasmMemory: WebAssembly.Memory | null;
164
+ }
165
+ /** Subset of the plan `Store` needs to phrase cap/overflow errors in the
166
+ * caller's terms. */
167
+ export interface ECSMemoryCapContext {
168
+ readonly capBytes: number | null;
169
+ readonly intentLabel: string;
170
+ readonly budgetEntities: number | null;
171
+ }
172
+ /**
173
+ * Turn a consumer's sizing intent into a concrete memory plan. Pure apart
174
+ * from allocator/Memory construction; throws `INVALID_MEMORY_OPTIONS` on a
175
+ * malformed option set — at construction, not first-grow.
176
+ */
177
+ export declare function resolveECSMemory(opts?: ECSMemoryOptions): ResolvedECSMemory;
178
+ export {};
179
+ //# sourceMappingURL=ecs_memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecs_memory.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/ecs_memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAON,KAAK,sBAAsB,E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AQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC/F,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC;;oDAEgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;gEAC4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;wDACoD;IACpD,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;2EAEuE;IACvE,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC;CAC/C;AAED;qBACqB;AACrB,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC;AAkBD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CA4R3E"}
@@ -0,0 +1,34 @@
1
+ import { Brand } from '../../type_primitives/index.cjs';
2
+ import { ECSError } from './utils/error.cjs';
3
+ export type EntityID = Brand<number, "entity_id">;
4
+ /**
5
+ * Compile-time readonly view of a `Uint32Array` whose elements are packed
6
+ * `EntityID`s — `Archetype.entityIds` returns this, so `ids[i]` is already
7
+ * branded and consumers don't re-brand by hand. Blocks index writes at the
8
+ * type layer.
9
+ *
10
+ * **Advisory, not a runtime barrier** — same caveat as `ReadonlyColumn`: the
11
+ * underlying value is the live mutable buffer, and indexing past
12
+ * `totalCount - 1` reads stale slots (the brand can't catch that).
13
+ */
14
+ export interface ReadonlyEntityIdArray {
15
+ readonly [index: number]: EntityID;
16
+ readonly length: number;
17
+ }
18
+ export declare const INDEX_BITS = 20;
19
+ export declare const INDEX_MASK: number;
20
+ export declare const MAX_INDEX: number;
21
+ export declare const GENERATION_BITS: number;
22
+ export declare const MAX_GENERATION: number;
23
+ export declare const RETIRED_GENERATION: number;
24
+ export declare const MAX_LIVE_GENERATION: number;
25
+ export declare const MAX_ENTITY_ID: number;
26
+ export declare const createEntityId: (index: number, generation: number) => EntityID;
27
+ export declare const getEntityIndex: (id: EntityID) => number;
28
+ export declare const getEntityGeneration: (id: EntityID) => number;
29
+ /** Build the `ENTITY_NOT_ALIVE` error every dev-mode liveness guard throws:
30
+ * names the failing operation, the packed id, and its decoded index/generation
31
+ * so the user can see WHICH handle went stale without decoding by hand.
32
+ * `detail` appends op-specific context (e.g. the component being read). */
33
+ export declare const entityNotAliveError: (op: string, id: EntityID, detail?: string) => ECSError;
34
+ //# sourceMappingURL=entity.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { Brand } from '../../type_primitives/index.js';
2
+ import { ECSError } from './utils/error.js';
3
+ export type EntityID = Brand<number, "entity_id">;
4
+ /**
5
+ * Compile-time readonly view of a `Uint32Array` whose elements are packed
6
+ * `EntityID`s — `Archetype.entityIds` returns this, so `ids[i]` is already
7
+ * branded and consumers don't re-brand by hand. Blocks index writes at the
8
+ * type layer.
9
+ *
10
+ * **Advisory, not a runtime barrier** — same caveat as `ReadonlyColumn`: the
11
+ * underlying value is the live mutable buffer, and indexing past
12
+ * `totalCount - 1` reads stale slots (the brand can't catch that).
13
+ */
14
+ export interface ReadonlyEntityIdArray {
15
+ readonly [index: number]: EntityID;
16
+ readonly length: number;
17
+ }
18
+ export declare const INDEX_BITS = 20;
19
+ export declare const INDEX_MASK: number;
20
+ export declare const MAX_INDEX: number;
21
+ export declare const GENERATION_BITS: number;
22
+ export declare const MAX_GENERATION: number;
23
+ export declare const RETIRED_GENERATION: number;
24
+ export declare const MAX_LIVE_GENERATION: number;
25
+ export declare const MAX_ENTITY_ID: number;
26
+ export declare const createEntityId: (index: number, generation: number) => EntityID;
27
+ export declare const getEntityIndex: (id: EntityID) => number;
28
+ export declare const getEntityGeneration: (id: EntityID) => number;
29
+ /** Build the `ENTITY_NOT_ALIVE` error every dev-mode liveness guard throws:
30
+ * names the failing operation, the packed id, and its decoded index/generation
31
+ * so the user can see WHICH handle went stale without decoding by hand.
32
+ * `detail` appends op-specific context (e.g. the component being read). */
33
+ export declare const entityNotAliveError: (op: string, id: EntityID, detail?: string) => ECSError;
34
+ //# sourceMappingURL=entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2BK;AAEL,OAAO,EAAE,KAAK,EAAc,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAa,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACrC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,UAAU,QAAwB,CAAC;AAChD,eAAO,MAAM,SAAS,QAAa,CAAC;AACpC,eAAO,MAAM,eAAe,QAAiC,CAAC;AAC9D,eAAO,MAAM,cAAc,QAA6B,CAAC;AAQzD,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AAGjD,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAMtD,eAAO,MAAM,aAAa,QAA6C,CAAC;AAExE,eAAO,MAAM,cAAc,UAAW,MAAM,cAAc,MAAM,KAAG,QAWlE,CAAC;AAEF,eAAO,MAAM,cAAc,OAAQ,QAAQ,KAAG,MAAyB,CAAC;AAExE,eAAO,MAAM,mBAAmB,OAAQ,QAAQ,KAAG,MAAsC,CAAC;AAE1F;;;2EAG2E;AAC3E,eAAO,MAAM,mBAAmB,OAAQ,MAAM,MAAM,QAAQ,WAAW,MAAM,KAAG,QAO9E,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { EntityID } from './entity.cjs';
2
+ export declare class EntityAllocator {
3
+ /** SAB-backed per-slot generation counters — replanted on restore. */
4
+ private _generations;
5
+ /** Single-slot view over the entity-index region's `length` header field —
6
+ * replanted on restore. Written on every high-water bump (#368). */
7
+ private _lengthView;
8
+ private _highWater;
9
+ private readonly _freeIndices;
10
+ private _aliveCount;
11
+ private readonly _capacity;
12
+ /** Slot index of the entity allocated by the most recent `alloc` call —
13
+ * alloc-free out-param, read immediately after the call (the `_spawnIndex`
14
+ * pattern the pre-extraction Store used). */
15
+ lastIndex: number;
16
+ constructor(capacity: number, generations: Int32Array, lengthView: Uint32Array);
17
+ /** Re-point the SAB views after the backing buffer was reallocated
18
+ * (grow/extend/restore). Does NOT touch host-side counters. */
19
+ replantViews(generations: Int32Array, lengthView: Uint32Array): void;
20
+ /** The live generations view. Hot flush loops hoist this to a local once
21
+ * per flush; do not cache it across a potential SAB replant. */
22
+ get generations(): Int32Array;
23
+ get highWater(): number;
24
+ get aliveCount(): number;
25
+ get freeCount(): number;
26
+ /** Allocate a slot and return its packed id; the slot index is left in
27
+ * `lastIndex`. This *commits* the slot (bumps counts, stamps the generation
28
+ * so `isAliveIndex` is already true) — a caller placing the entity into an
29
+ * archetype row must have reserved column capacity first (#775). */
30
+ alloc(): EntityID;
31
+ /** Pre-check that `count` fresh slots fit, so a bulk-spawn commits
32
+ * all-or-nothing (#775): `alloc`'s own per-call guard would otherwise
33
+ * throw partway through the loop, leaving committed slots phantom-alive.
34
+ * Free-list reuse covers the first `freeCount` slots; only the remainder
35
+ * draws down the high-water headroom. */
36
+ ensureCapacity(count: number): void;
37
+ /** Recycle (or retire) a slot whose entity carried `generation`. Bumps the
38
+ * generation so stale IDs read dead; once the counter would reach the
39
+ * reserved tombstone the slot is RETIRED, not recycled (#376): stamp
40
+ * RETIRED_GENERATION (never issued to a live handle) and skip the
41
+ * free-list push, closing the ABA window. Burning one of 2^20 indices
42
+ * after 2047 reuses is cheap; the branch is predicted not-taken on
43
+ * essentially every destroy. */
44
+ recycle(index: number, generation: number): void;
45
+ /** Allocation-side liveness: the slot is in the issued range and its
46
+ * current generation matches the handle's. (`Store.isAlive` layers the
47
+ * malformed-handle guards (#778) on top of this.) */
48
+ isAliveIndex(index: number, generation: number): boolean;
49
+ /** Mirror the current high-water into the SAB `length` header — called
50
+ * after a buffer replant so the fresh region carries the host value. */
51
+ publishLength(): void;
52
+ snapshotFreeIndices(): number[];
53
+ /** Restore path, step 1: adopt the high-water recovered from the restored
54
+ * region's length header BEFORE the replant republishes it (#789). */
55
+ setHighWater(value: number): void;
56
+ /** Restore path, step 2: adopt the captured free-list + alive count. */
57
+ restoreHostState(freeIndices: readonly number[], aliveCount: number): void;
58
+ }
59
+ //# sourceMappingURL=entity_allocator.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { EntityID } from './entity.js';
2
+ export declare class EntityAllocator {
3
+ /** SAB-backed per-slot generation counters — replanted on restore. */
4
+ private _generations;
5
+ /** Single-slot view over the entity-index region's `length` header field —
6
+ * replanted on restore. Written on every high-water bump (#368). */
7
+ private _lengthView;
8
+ private _highWater;
9
+ private readonly _freeIndices;
10
+ private _aliveCount;
11
+ private readonly _capacity;
12
+ /** Slot index of the entity allocated by the most recent `alloc` call —
13
+ * alloc-free out-param, read immediately after the call (the `_spawnIndex`
14
+ * pattern the pre-extraction Store used). */
15
+ lastIndex: number;
16
+ constructor(capacity: number, generations: Int32Array, lengthView: Uint32Array);
17
+ /** Re-point the SAB views after the backing buffer was reallocated
18
+ * (grow/extend/restore). Does NOT touch host-side counters. */
19
+ replantViews(generations: Int32Array, lengthView: Uint32Array): void;
20
+ /** The live generations view. Hot flush loops hoist this to a local once
21
+ * per flush; do not cache it across a potential SAB replant. */
22
+ get generations(): Int32Array;
23
+ get highWater(): number;
24
+ get aliveCount(): number;
25
+ get freeCount(): number;
26
+ /** Allocate a slot and return its packed id; the slot index is left in
27
+ * `lastIndex`. This *commits* the slot (bumps counts, stamps the generation
28
+ * so `isAliveIndex` is already true) — a caller placing the entity into an
29
+ * archetype row must have reserved column capacity first (#775). */
30
+ alloc(): EntityID;
31
+ /** Pre-check that `count` fresh slots fit, so a bulk-spawn commits
32
+ * all-or-nothing (#775): `alloc`'s own per-call guard would otherwise
33
+ * throw partway through the loop, leaving committed slots phantom-alive.
34
+ * Free-list reuse covers the first `freeCount` slots; only the remainder
35
+ * draws down the high-water headroom. */
36
+ ensureCapacity(count: number): void;
37
+ /** Recycle (or retire) a slot whose entity carried `generation`. Bumps the
38
+ * generation so stale IDs read dead; once the counter would reach the
39
+ * reserved tombstone the slot is RETIRED, not recycled (#376): stamp
40
+ * RETIRED_GENERATION (never issued to a live handle) and skip the
41
+ * free-list push, closing the ABA window. Burning one of 2^20 indices
42
+ * after 2047 reuses is cheap; the branch is predicted not-taken on
43
+ * essentially every destroy. */
44
+ recycle(index: number, generation: number): void;
45
+ /** Allocation-side liveness: the slot is in the issued range and its
46
+ * current generation matches the handle's. (`Store.isAlive` layers the
47
+ * malformed-handle guards (#778) on top of this.) */
48
+ isAliveIndex(index: number, generation: number): boolean;
49
+ /** Mirror the current high-water into the SAB `length` header — called
50
+ * after a buffer replant so the fresh region carries the host value. */
51
+ publishLength(): void;
52
+ snapshotFreeIndices(): number[];
53
+ /** Restore path, step 1: adopt the high-water recovered from the restored
54
+ * region's length header BEFORE the replant republishes it (#789). */
55
+ setHighWater(value: number): void;
56
+ /** Restore path, step 2: adopt the captured free-list + alive count. */
57
+ restoreHostState(freeIndices: readonly number[], aliveCount: number): void;
58
+ }
59
+ //# sourceMappingURL=entity_allocator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity_allocator.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/entity_allocator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAsC,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAG7E,qBAAa,eAAe;IAC3B,sEAAsE;IACtE,OAAO,CAAC,YAAY,CAAa;IACjC;wEACoE;IACpE,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC;;iDAE6C;IACtC,SAAS,SAAK;gBAET,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW;IAM9E;mEAC+D;IACxD,YAAY,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,IAAI;IAK3E;oEACgE;IAChE,IAAW,WAAW,IAAI,UAAU,CAEnC;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED;;;wEAGoE;IAC7D,KAAK,IAAI,QAAQ;IA8BxB;;;;6CAIyC;IAClC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAY1C;;;;;;oCAMgC;IACzB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAWvD;;yDAEqD;IAC9C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAI/D;4EACwE;IACjE,aAAa,IAAI,IAAI;IAOrB,mBAAmB,IAAI,MAAM,EAAE;IAItC;0EACsE;IAC/D,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxC,wEAAwE;IACjE,gBAAgB,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;CAKjF"}
@@ -0,0 +1,79 @@
1
+ import { Brand } from '../../type_primitives/index.cjs';
2
+ export type EventID = Brand<number, "event_id">;
3
+ export declare const asEventId: (value: number) => EventID;
4
+ /** Event schema: field name → value type. Every value is a number at
5
+ * runtime; the declared type may be a branded number (e.g. `EntityID`)
6
+ * so the brand survives the emit → read round trip at the type layer.
7
+ * This is the erased/default schema type; the public surfaces constrain
8
+ * on `EventShape<S>` (below) instead, so schemas may be declared as type
9
+ * literals OR interfaces — an interface lacks the implicit index
10
+ * signature literals get (and so isn't assignable to this `Record`
11
+ * alias), but satisfies the homomorphic `EventShape` check. */
12
+ export type EventSchema = Readonly<Record<string, number>>;
13
+ /**
14
+ * Homomorphic constraint for event-schema type params (POLISH_AUDIT M9):
15
+ * `S extends EventShape<S>` checks every property of `S` is a number WITHOUT
16
+ * requiring an index signature, so `interface`-declared schemas (which lack
17
+ * the implicit index signature type literals get) are accepted too.
18
+ */
19
+ export type EventShape<S> = {
20
+ readonly [K in keyof S]: number;
21
+ };
22
+ /** Schema of a signal — a zero-field event. */
23
+ export type EmptyEventSchema = Readonly<Record<never, number>>;
24
+ declare const __eventSchema: unique symbol;
25
+ export type EventDef<S extends EventShape<S> = EventSchema> = EventID & {
26
+ readonly [__eventSchema]: (value: S) => S;
27
+ };
28
+ /**
29
+ * Reader view over an event channel's SoA columns. Columns are read-only
30
+ * arrays typed per the event schema: consumers index them and read
31
+ * `.length`. A field declared as a branded number (e.g. `EntityID`) reads
32
+ * back branded — no cast at the consumer.
33
+ *
34
+ * The "cannot mutate the live channel through the reader" property is
35
+ * **advisory** — the columns are the same live `number[]` objects the channel
36
+ * mutates (see `EventChannel` below), so the `readonly` typing blocks writes
37
+ * at the type layer only; a §10c-policed cast can still write through.
38
+ */
39
+ export type EventReader<S extends EventShape<S>> = {
40
+ readonly length: number;
41
+ } & {
42
+ readonly [K in keyof S]: ReadonlyArray<S[K]>;
43
+ };
44
+ export declare class EventChannel {
45
+ readonly fieldNames: string[];
46
+ readonly columns: number[][];
47
+ readonly reader: EventReader<any>;
48
+ private readonly _readerLen;
49
+ constructor(fieldNames: string[]);
50
+ emit(values: Record<string, number>): void;
51
+ /** Emit a signal (zero-field event). */
52
+ emitSignal(): void;
53
+ clear(): void;
54
+ }
55
+ declare const __eventKeySchema: unique symbol;
56
+ export type EventKey<S extends EventShape<S> = EventSchema> = symbol & {
57
+ readonly [__eventKeySchema]: (value: S) => S;
58
+ };
59
+ declare const __signalKey: unique symbol;
60
+ export type SignalKey = EventKey<EmptyEventSchema> & {
61
+ readonly [__signalKey]: true;
62
+ };
63
+ /**
64
+ * Compile-time exact-cover check for `registerEvent`'s `fields` list. The
65
+ * element type (`keyof S & string`) already rejects foreign fields; this
66
+ * catches the inverse mistake — an UNDER-registered channel. Registering
67
+ * `eventKey<{a; b}>` with `["a"]` used to compile, but `emit` requires the
68
+ * full payload while the channel only has an `a` column, so `b` was silently
69
+ * dropped and `reader.b` (typed as an array) was `undefined` at runtime.
70
+ * Resolves to `unknown` (intersection no-op) when `F` covers every key, and
71
+ * to an impossible tuple naming the missing fields otherwise. A schema with a
72
+ * string index signature (erased/untyped keys) skips the check — there is no
73
+ * finite key set to cover.
74
+ */
75
+ export type EventFieldsCover<S extends EventShape<S>, F extends readonly (keyof S & string)[]> = string extends keyof S ? unknown : Exclude<keyof S & string, F[number]> extends never ? unknown : readonly [`ERROR — missing event field: ${Exclude<keyof S & string, F[number]>}`];
76
+ export declare function eventKey<S extends EventShape<S>>(name: string): EventKey<S>;
77
+ export declare function signalKey(name: string): SignalKey;
78
+ export {};
79
+ //# sourceMappingURL=event.d.ts.map