@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,486 @@
1
+ import { Brand, AnyTypedArray, ColumnBacking, TypedArrayTag, BitSet } from '../../type_primitives/index.js';
2
+ import { ColumnStore } from '../store/column_store.js';
3
+ import { ComponentID, ComponentDef, ComponentSchema, SchemaOf, DeclaredQueryTerm, TagToTypedArray, ColumnsForSchema, MutableColumnsForSchema, ReadonlyColumn } from './component.js';
4
+ import { EntityID, ReadonlyEntityIdArray } from './entity.js';
5
+ export type ArchetypeID = Brand<number, "archetype_id">;
6
+ export declare const asArchetypeId: (value: number) => ArchetypeID;
7
+ export interface ArchetypeEdge {
8
+ add: ArchetypeID | null;
9
+ remove: ArchetypeID | null;
10
+ /** Pre-computed column mapping for add direction: this → add target. */
11
+ addMap: Int16Array | null;
12
+ /** Pre-computed column mapping for remove direction: this → remove target. */
13
+ removeMap: Int16Array | null;
14
+ }
15
+ /**
16
+ * Cached resolution of a *multi*-component add out of this archetype: the
17
+ * target archetype the union lands in, plus the pre-built src→target batch
18
+ * transition map. Keyed (on the source archetype) by an exact N-tagged pack of
19
+ * the added component ids — see `Store.addComponents` (#659).
20
+ *
21
+ * Where `ArchetypeEdge` is the per-*component* edge the single-add path indexes
22
+ * by `edges[component_id]`, this is the per-*set* edge the plural-add path looks
23
+ * up by packed key — folding the mask hash, `archLookup`, and batch-map fetch
24
+ * the final-mask resolve repeats every call into one `Map.get`. Never
25
+ * invalidated: the archetype graph is monotonic (archetypes outlive the Store).
26
+ */
27
+ export interface CompositeAddEdge {
28
+ target: ArchetypeID;
29
+ map: Int16Array;
30
+ }
31
+ export interface ArchetypeColumnLayout {
32
+ componentId: ComponentID;
33
+ fieldNames: string[];
34
+ fieldIndex: Record<string, number>;
35
+ fieldTypes: TypedArrayTag[];
36
+ }
37
+ interface ArchetypeColumnGroup {
38
+ layout: ArchetypeColumnLayout;
39
+ columns: ColumnBacking<AnyTypedArray>[];
40
+ }
41
+ /**
42
+ * Per-column allocator. Returns a `ColumnBacking` for the field at
43
+ * `fieldIdx` of component `component_id`. The default factory (when none
44
+ * is supplied to the constructor) allocates a `GrowableTypedArray` on the
45
+ * heap; `fromColumnStore` supplies a factory that wraps SAB views instead.
46
+ */
47
+ export type ColumnFactory = (componentId: ComponentID, fieldIdx: number, tag: TypedArrayTag) => ColumnBacking<AnyTypedArray>;
48
+ /**
49
+ * Hook the host installs on every SAB-backed archetype so the Archetype
50
+ * can request a SAB grow + refresh from the host BEFORE the insertion
51
+ * that would otherwise throw `StoreColumnOverflowError`. The host (Store)
52
+ * is responsible for running `growColumnStore` and `refreshViews`
53
+ * across every SAB-backed archetype; after the handler returns,
54
+ * `arch._flatColumns[i].buf.length` is guaranteed to be `>= arch.length +
55
+ * additional`. Heap-backed archetypes leave this unset — their
56
+ * `GrowableTypedArray` grows in place. (#171 §6.1.9 Phase 3)
57
+ */
58
+ export type ArchetypeGrowHandler = (arch: Archetype, additional: number) => void;
59
+ /**
60
+ * Public, read-only window onto an archetype's rows. This is the ONLY
61
+ * surface `Query.archetypes`, `Query.forEach`, and `ChangedQuery.forEach`
62
+ * hand to callers — the concrete `Archetype` (with its structural mutators
63
+ * `removeEntity`, `moveEntityFrom`, `writeFields`, `setEdge`, and the
64
+ * mutable `getColumn`) stays internal so query iteration can't bypass the
65
+ * deferred-flush path that prevents iterator invalidation. This is the same
66
+ * back door PR #163 closed for `Store`; issue #378 closed it again for
67
+ * `Query`.
68
+ *
69
+ * `id` is the archetype's opaque identity (not a mutator) — exposed so the
70
+ * public `ECS.batchAddComponent`/`batchRemoveComponent` API can target an
71
+ * archetype without the caller holding a concrete `Archetype` reference.
72
+ */
73
+ export interface ArchetypeView<out Defs extends readonly ComponentDef<any>[] = readonly ComponentDef<any>[]> {
74
+ /** Opaque archetype identity. Pass to `ECS.batch_*_component`. */
75
+ readonly id: ArchetypeID;
76
+ /** Number of **enabled** entities — the default-iteration bound (#577). Rows
77
+ * `0..entityCount-1` are enabled; disabled rows (if any) sit contiguously at
78
+ * `entityCount..totalCount-1`. `forEach` SoA loops read this, so they skip
79
+ * disabled rows for free. Use `totalCount` to span disabled rows too. */
80
+ readonly entityCount: number;
81
+ /** Total live rows, enabled + disabled (#577). Equal to `entityCount` unless
82
+ * some rows are disabled. Use for full-state work (serialization, snapshot,
83
+ * determinism) that must see every entity regardless of enabled state. */
84
+ readonly totalCount: number;
85
+ /** Number of disabled rows = `totalCount - entityCount` (#577). */
86
+ readonly disabledCount: number;
87
+ /** Raw entity ID buffer (packed `EntityID`s). Valid data at indices
88
+ * 0..totalCount-1 (enabled rows first, then disabled). */
89
+ readonly entityIds: ReadonlyEntityIdArray;
90
+ /** True if this archetype's mask includes the given component. */
91
+ hasComponent(id: ComponentID): boolean;
92
+ /** Get a single field's column (read-only). Valid data: indices
93
+ * 0..entityCount-1. `def` must be a term of the iterating query
94
+ * (POLISH_AUDIT #6); the bare-`ArchetypeView` default stays permissive. */
95
+ getColumnRead<D extends ComponentDef<any>, K extends string & keyof SchemaOf<D>>(def: D & DeclaredQueryTerm<Defs, D>, field: K): ReadonlyColumn;
96
+ /** Tuple fetch of several of one component's columns —
97
+ * `const [q, r] = arch.getColumnsRead(HexPos, "q", "r")`. One small
98
+ * array allocation per call; see the class doc on `Archetype`. */
99
+ getColumnsRead<D extends ComponentDef<any>, const K extends readonly (string & keyof SchemaOf<D>)[]>(def: D & DeclaredQueryTerm<Defs, D>, ...fields: K): {
100
+ [I in keyof K]: ReadonlyColumn;
101
+ };
102
+ /** Get a single field's column **if this archetype has the component**,
103
+ * else `undefined` — the optional-query fetch-if-present accessor (#575).
104
+ * The absent branch is expected (resolve the column pointer per archetype
105
+ * span: present ⇒ column, absent ⇒ `undefined`), not an error. Same
106
+ * advisory-readonly view and `reads`-access-check as `getColumnRead`. */
107
+ getOptionalColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn | undefined;
108
+ }
109
+ export declare class Archetype implements ArchetypeView {
110
+ readonly id: ArchetypeID;
111
+ readonly mask: BitSet;
112
+ readonly hasColumns: boolean;
113
+ /**
114
+ * Whether a member entity occupies a real row here. True for every archetype
115
+ * except the **empty archetype** (the one with no components), where a
116
+ * component-less entity is "alive but unplaced" — it points here via
117
+ * `entityArchetype` but carries `entityRow === UNASSIGNED` and holds no
118
+ * row, exactly like a freshly `createEntity`'d one. Keeping the empty
119
+ * archetype rowless gives a component-less entity a single canonical form
120
+ * regardless of how it got there (created bare vs. lost its last component),
121
+ * so `stateHash` and zero-require query iteration don't depend on add/remove
122
+ * history. The row-materialising methods below honour this flag.
123
+ */
124
+ readonly materializesRows: boolean;
125
+ private readonly _entityIds;
126
+ length: number;
127
+ /**
128
+ * Enabled/disabled row partition (#577 — entity enable/disable). Rows
129
+ * `[0, enabled_count)` are enabled, `[enabled_count, length)` are disabled.
130
+ * `enabled_count === length` (no disabled rows) is the common case — every
131
+ * fast path below short-circuits on it, so an archetype that never disables
132
+ * an entity pays nothing. Disable/enable swap a row across the boundary
133
+ * (`disableRow`/`enableRow`); appends place enabled rows in front of the
134
+ * disabled tail (`_placeTail`). `entityCount` (the query/iteration bound)
135
+ * returns this; `length`/`totalCount` span disabled rows too. Folded into
136
+ * `stateHash` and published to the SAB descriptor so the WASM sim and
137
+ * snapshot/restore honour it.
138
+ */
139
+ enabledCount: number;
140
+ /**
141
+ * Flush-epoch stamp + captured pre-counts for the Store's per-entity flush
142
+ * 0-crossing detector (#328, #812): `_flushAdds`/`_flushRemoves` stamp each
143
+ * archetype on first sight per flush (a few field accesses) instead of probing
144
+ * a `Map<archetype_id, pre_count>` per entity — the same per-entity Map
145
+ * cost the destroy drain shed in #457. Both `_flushPreLen` and
146
+ * `_flushPreEnabled` are recorded so the settle pass can detect a 0-crossing
147
+ * on either the total (`length`) or the enabled partition (`enabledCount`) —
148
+ * an enabled append into an all-disabled archetype crosses only the latter
149
+ * (#812). Owned by Store; pure scheduling bookkeeping, never folded into
150
+ * `stateHash`/snapshot.
151
+ */
152
+ _flushSeenEpoch: number;
153
+ _flushPreLen: number;
154
+ _flushPreEnabled: number;
155
+ /**
156
+ * DEV-only iteration guard: >0 while a dense query iterator (`forEach` /
157
+ * `eachChunk` / `forEachUntil` / `ChangedQuery.forEach`) is delivering this
158
+ * archetype to a user callback. The row-removing/reordering primitives
159
+ * (`removeRow` / `disableRow` / `enableRow`) check it so an immediate
160
+ * structural mutation from inside the walk — which would swap-remove under
161
+ * the iterator and silently skip or repeat entities — throws instead.
162
+ * Production builds never read or write it.
163
+ */
164
+ _iterDepth: number;
165
+ private readonly edges;
166
+ /**
167
+ * Cache of pre-computed transition maps for multi-component transitions
168
+ * (this → target). Single-component edges live on `edges[].addMap`/`removeMap`;
169
+ * multi-component pairs land here. Entries never need invalidation —
170
+ * archetypes live for the Store's lifetime.
171
+ */
172
+ private readonly batchTransitionMaps;
173
+ /**
174
+ * Per-set add-edge cache for `Store.addComponents` (#659), keyed by an
175
+ * exact pack of the added component ids. Lazily allocated: most archetypes
176
+ * never originate a plural add, so the Map stays `null` until the first one
177
+ * is resolved — the single-add `edges[]` path never touches it.
178
+ */
179
+ private compositeAddEdges;
180
+ readonly _flatColumns: ColumnBacking<AnyTypedArray>[];
181
+ /** Set by `fromColumnStore` to record which SAB archetype this Archetype
182
+ * draws its column views from. `null` for the default heap-backed path
183
+ * (no SAB linkage; `refreshViews` would be a no-op there and so
184
+ * isn't supported). */
185
+ private _storeArchetypeId;
186
+ readonly _colOffset: number[];
187
+ readonly _fieldCount: number[];
188
+ private readonly _fieldIndex;
189
+ private readonly _fieldNames;
190
+ readonly columnGroups: (ArchetypeColumnGroup | undefined)[];
191
+ readonly _columnIds: number[];
192
+ readonly _changedTick: number[];
193
+ private readonly _mutGroupCache;
194
+ private readonly _readGroupCache;
195
+ /** Host-installed grow hook. Set by `Store` on every SAB-backed
196
+ * archetype during construction; `null` on heap-backed archetypes (the
197
+ * default `GrowableTypedArray` grows in place). Insertion methods call
198
+ * `_invoke_grow(...)` below before any push that would overflow the
199
+ * current SAB row capacity. (#171 §6.1.9 Phase 3) */
200
+ growHandler: ArchetypeGrowHandler | null;
201
+ constructor(id: ArchetypeID, mask: BitSet, layouts?: ArchetypeColumnLayout[], initialCapacity?: number, columnFactory?: ColumnFactory);
202
+ /**
203
+ * Build an Archetype whose columns are TypedArray views into a single
204
+ * `ColumnStore`-managed `SharedArrayBuffer`. The store must contain an
205
+ * archetype entry whose id equals `storeArchetypeId` and whose columns
206
+ * cover every `(component_id, fieldIdx)` pair declared by `layouts`.
207
+ *
208
+ * The resulting archetype is fixed-capacity at the SAB row capacity —
209
+ * any operation that would push past it throws `StoreColumnOverflowError`.
210
+ * To grow capacity, call `growColumnStore(...)` between ticks and then
211
+ * `refreshViews(newStore)` on this archetype (#171 §6.1.4 / §8.1).
212
+ */
213
+ static fromColumnStore(id: ArchetypeID, mask: BitSet, layouts: ArchetypeColumnLayout[], columnStore: ColumnStore, storeArchetypeId: number): Archetype;
214
+ /** True iff this archetype was constructed via `fromColumnStore` and its
215
+ * `_flatColumns` are SAB-backed. Heap-backed archetypes return `false`
216
+ * and cannot be refreshed (their columns grow in place). */
217
+ get isBufferBacked(): boolean;
218
+ /**
219
+ * Repoint every column at the matching SAB view in `newColumnStore` after
220
+ * a host-side `growColumnStore` realloc. The archetype keeps its row
221
+ * count; each column's logical length is preserved. Caller is responsible
222
+ * for ensuring `newColumnStore` was built by `growColumnStore` over the
223
+ * SAB this archetype was originally drawn from — the matching
224
+ * `storeArchetypeId` was recorded in `fromColumnStore` and is reused here.
225
+ *
226
+ * Throws `ECSError` if this archetype is not SAB-backed, or if the new
227
+ * store lacks the recorded archetype id or any column the archetype
228
+ * expects.
229
+ */
230
+ refreshViews(newColumnStore: ColumnStore): void;
231
+ /** Enabled-row count — the default iteration bound (#577). See `enabled_count`.
232
+ * Equals `length` whenever no entity is disabled (the common case).
233
+ *
234
+ * During an `includeDisabled()` query's `forEach`, the module flag
235
+ * `_iterAllRows` is set so this returns `length` (enabled + disabled) — the
236
+ * user's `for i < arch.entityCount` loop then spans disabled rows
237
+ * transparently, with no change to the loop. Outside such iteration the flag is
238
+ * false and this is `enabled_count`. */
239
+ get entityCount(): number;
240
+ /** Total live rows incl. disabled (#577). */
241
+ get totalCount(): number;
242
+ /** Disabled-row count (#577). */
243
+ get disabledCount(): number;
244
+ /** Raw entity ID buffer (packed `EntityID`s). Valid data at indices
245
+ * 0..totalCount-1 (enabled rows first, then disabled). */
246
+ get entityIds(): ReadonlyEntityIdArray;
247
+ /**
248
+ * Swap the two rows `a` and `b` — entity ids and every column. Does NOT touch
249
+ * `entityRow`; the caller updates the entity→row map for whichever rows it
250
+ * cares about (it knows the two `entityIds` after the swap). The partition
251
+ * primitives (`disableRow`/`enableRow`/`removeRow`/`_placeTail`) build on
252
+ * this. Writes through each column's live backing buffer (`buf`), so it works
253
+ * for both heap- and SAB-backed columns. No-op when `a === b`. (#577) */
254
+ swapRows(a: number, b: number): void;
255
+ /**
256
+ * Place a freshly-appended ENABLED entity (currently at the tail row `tail`,
257
+ * already pushed, `length` already incremented) into the enabled region, and
258
+ * bump `enabled_count`. Returns its final row.
259
+ *
260
+ * Common case — no disabled rows (`enabled_count === tail`): the tail row IS
261
+ * the next enabled slot, so this is just `enabled_count++` and returns `tail`
262
+ * (byte-for-byte the pre-#577 behaviour, `entityRow` untouched). Rare case —
263
+ * disabled rows occupy `[enabled_count, tail)`: swap the appended row into the
264
+ * first disabled slot and push that disabled occupant to the tail, updating
265
+ * its `entityRow`. Requires `entityRow` in that case (a `DEV` guard fires
266
+ * if a caller appends into a disabled-bearing archetype without passing it). (#577) */
267
+ private _placeTail;
268
+ /**
269
+ * Bulk analog of `_placeTail` for `count` freshly-appended enabled rows at
270
+ * `[start, start+count)`. Common case (no disabled rows, `enabled_count ===
271
+ * start`): `enabled_count += count`, return `start`. The bulk callers
272
+ * (`spawnMany`, batch ops) fall back to a per-entity append loop when the
273
+ * target already has disabled rows, so the rare branch is a `DEV` guard
274
+ * rather than a block-rotation. (#577) */
275
+ private _placeTailBulk;
276
+ /**
277
+ * Disable the entity at `row` (precondition: enabled, `row < enabled_count`).
278
+ * Swaps it to the end of the enabled region and shrinks the region, so it
279
+ * lands in the disabled tail with its data intact — no archetype transition,
280
+ * O(1)+one row swap. Updates `entityRow` for both rows touched. (#577) */
281
+ disableRow(row: number, entityRow: Int32Array): void;
282
+ /**
283
+ * Enable the entity at `row` (precondition: disabled, `row >= enabled_count`).
284
+ * Swaps it to the front of the disabled region and grows the enabled region.
285
+ * Updates `entityRow` for both rows touched. (#577) */
286
+ enableRow(row: number, entityRow: Int32Array): void;
287
+ /**
288
+ * Partition-aware swap-remove that owns its `entityRow` updates (#577). The
289
+ * Store's destroy/move paths call this instead of `removeEntity`; it keeps the
290
+ * enabled prefix contiguous in every case:
291
+ * - disabled row (`row >= enabled_count`): swap-remove within the disabled
292
+ * tail (the last row is disabled) — `enabled_count` unchanged.
293
+ * - last enabled row: swap-remove with the global last; `enabled_count--`.
294
+ * - middle enabled row: move the last enabled row into the hole (so the
295
+ * enabled prefix stays packed), then swap-remove that vacated enabled slot
296
+ * with the global last; `enabled_count--`.
297
+ * Updates `entityRow` for every relocated entity (never for the removed one —
298
+ * the caller frees/repoints it). */
299
+ removeRow(row: number, entityRow: Int32Array): void;
300
+ /** @internal — cold partition-aware tail of `removeRow` (#577): the
301
+ * disabled-bearing archetype case. Split out so the no-disabled fast path
302
+ * above stays small enough to inline (#649); see the doc on `removeRow`. */
303
+ private _removeRowPartitioned;
304
+ get entityList(): Uint32Array;
305
+ hasComponent(id: ComponentID): boolean;
306
+ matches(required: BitSet): boolean;
307
+ /**
308
+ * Get a single field's column (read-only — use when not mutating). Valid
309
+ * data: indices 0..entityCount-1. The `ReadonlyColumn` return is an
310
+ * *advisory* compile-time barrier: it is the live mutable backing buffer,
311
+ * so the `readonly` index signature blocks writes at the type layer only
312
+ * (a §10c-policed cast can still write through). For writes use the
313
+ * mutable `getColumn` (tick-bumping) below.
314
+ */
315
+ getColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn;
316
+ /**
317
+ * Tuple fetch of several of one component's columns —
318
+ * `const [q, r] = arch.getColumnsRead(HexPos, "q", "r")` collapses the
319
+ * per-field `getColumnRead` preamble at the top of an iteration callback
320
+ * to one line. Same advisory-readonly views and `reads` access-check as
321
+ * `getColumnRead`. Allocates one small array per call — fine once per
322
+ * archetype per tick; in a per-row loop fetch columns individually.
323
+ */
324
+ getColumnsRead<S extends ComponentSchema, const K extends readonly (string & keyof S)[]>(def: ComponentDef<S>, ...fields: K): {
325
+ [I in keyof K]: ReadonlyColumn;
326
+ };
327
+ /**
328
+ * Get a single field's column **if this archetype has the component**, else
329
+ * `undefined` — the fetch-if-present accessor for optional query terms (#575,
330
+ * Bevy `Option<&T>` / flecs `?`). An optional query (`q.optional(T)`) spans
331
+ * archetypes both with and without `T`; the caller branches once per
332
+ * archetype span on the return:
333
+ *
334
+ * q.forEach((arch) => {
335
+ * const vx = arch.getOptionalColumnRead(Vel, "vx");
336
+ * for (let i = 0; i < arch.entityCount; i++) {
337
+ * px[i] += vx ? vx[i] : 0; // absent span ⇒ vx === undefined
338
+ * }
339
+ * });
340
+ *
341
+ * Unlike `getColumnRead`, a component the archetype lacks is the expected
342
+ * **absent** branch, not a thrown error. The `DEV` checks still run
343
+ * **first** (before the absent short-circuit), so the requirements don't
344
+ * depend on whether the current span happens to hold `T`. Two checks fire:
345
+ * (1) `accessCheck.checkRead` — an optional read needs `reads:[T]` coverage
346
+ * exactly as a required read does; (2) `accessCheck.checkOptionalFetch` —
347
+ * the iterating query must have declared `.optional(T)` (#592), the read-side
348
+ * analog that makes the query term the fetch's authorization rather than inert
349
+ * decoration. The return is the same advisory-readonly view `getColumnRead`
350
+ * hands back.
351
+ */
352
+ getOptionalColumnRead<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K): ReadonlyColumn | undefined;
353
+ /** Get a single field's column (mutable — the default). Marks the component as changed at the given tick. */
354
+ getColumn<S extends ComponentSchema, K extends string & keyof S>(def: ComponentDef<S>, field: K, tick: number): TagToTypedArray[S[K]];
355
+ /** Mutable field-keyed column group; stamps the change tick once. */
356
+ columnGroupMut<S extends ComponentSchema>(def: ComponentDef<S>, tick: number): MutableColumnsForSchema<S>;
357
+ /** Read-only field-keyed column group (no tick bump). */
358
+ columnGroupRead<S extends ComponentSchema>(def: ComponentDef<S>): ColumnsForSchema<S>;
359
+ writeFields(row: number, componentId: ComponentID, values: Record<string, number>, tick: number): void;
360
+ /**
361
+ * Bulk variant of `writeFields` — fills `count` consecutive rows starting
362
+ * at `dstStart` with the same field values via per-field `TypedArray.fill`.
363
+ * For N rows of an F-field component, this is F native fill calls instead
364
+ * of N×F per-row JS writes. The change-tick is bumped once for the range,
365
+ * not once per row. Used by `Store.batchAddComponent` after a bulk move,
366
+ * where every freshly-added row shares the same field values.
367
+ */
368
+ bulkWriteFields(dstStart: number, count: number, componentId: ComponentID, values: Record<string, number>, tick: number): void;
369
+ /** Fast positional write: values[i] → field[i] in declaration order. No string lookup. */
370
+ writeFieldsPositional(row: number, componentId: ComponentID, values: ArrayLike<number>, tick: number): void;
371
+ readField(row: number, componentId: ComponentID, field: string): number;
372
+ /** Copy all shared component columns from source archetype at srcRow into dstRow. */
373
+ copySharedFrom(source: Archetype, srcRow: number, dstRow: number, tick: number): void;
374
+ /**
375
+ * Add an entity. Pushes zeroes into all columns and returns the assigned row.
376
+ * Store is responsible for tracking entityIndex → row.
377
+ */
378
+ addEntity(entityId: EntityID, entityRow?: Int32Array): number;
379
+ /**
380
+ * Remove entity at row via swap-and-pop. Swaps the last entity into the
381
+ * vacated row to keep data dense. Returns the entityIndex of the swapped
382
+ * entity (so Store can update its row), or NO_SWAP if no swap was needed.
383
+ */
384
+ removeEntity(row: number): number;
385
+ /** Tag-optimized add: skip column push entirely (no data to store). */
386
+ addEntityTag(entityId: EntityID, entityRow?: Int32Array): number;
387
+ /**
388
+ * Bulk add `count` entities, zero-initialising all columns. Returns the
389
+ * starting dstRow for the batch. Caller is responsible for tracking
390
+ * entityIndex → row for every entity in the batch.
391
+ *
392
+ * Collapses the N×C `push(0)` cost of N sequential `addEntity` calls
393
+ * into C `bulkAppendZeroes(count)` calls — the same pattern
394
+ * `bulkMoveAllFrom` (`:580`) uses for the move-with-data case (#330).
395
+ */
396
+ addEntities(entityIds: Uint32Array, count?: number): number;
397
+ /** Tag-optimized bulk add: skip the per-column zero-fill entirely. */
398
+ addEntitiesTag(entityIds: Uint32Array, count?: number): number;
399
+ /** Grow column capacity to fit `additional` more rows if the next append
400
+ * would overflow — the exact grow trigger the `addEntityWithValues` /
401
+ * `addEntitiesWithValues` appends run internally, lifted out so the spawn
402
+ * path can pre-reserve capacity BEFORE it commits an entity slot. A SAB-cap
403
+ * grow throws here (with the world untouched) instead of mid-append after the
404
+ * slot is already live — see `Store.spawn`/`spawnMany` (#775). No-op for a
405
+ * tag-only archetype (no SAB columns) or when no grow handler is installed. */
406
+ ensureRowCapacity(additional: number): void;
407
+ /** Append one entity, writing `flatValues[i]` straight into column `i`
408
+ * (in `_flatColumns` order) — no zero-fill-then-overwrite. Bumps every
409
+ * column's change tick once. Returns the assigned row. */
410
+ addEntityWithValues(entityId: EntityID, flatValues: number[], tick: number, entityRow?: Int32Array): number;
411
+ /** Bulk append `count` entities, filling column `i` with `flatValues[i]`
412
+ * in a single `TypedArray.fill` per column (no zero pass). Returns the
413
+ * starting row. */
414
+ addEntitiesWithValues(entityIds: Uint32Array, count: number, flatValues: number[], tick: number): number;
415
+ /** Tag-optimized remove via swap-and-pop: skip column swap/pop entirely. */
416
+ removeEntityTag(row: number): number;
417
+ /**
418
+ * Move an entity from src archetype into this archetype in a single pass.
419
+ * Combines addEntity + copySharedFrom + removeEntity(src).
420
+ * Uses a pre-computed transition map for branchless column copy.
421
+ * Writes dstRow to _moveResult[0], swapped entity index to _moveResult[1].
422
+ */
423
+ moveEntityFrom(src: Archetype, srcRow: number, entityId: EntityID, transitionMap: Int16Array, tick: number, entityRow: Int32Array): void;
424
+ /**
425
+ * Move an entity from src into this archetype (tag-only: no columns to copy).
426
+ * Writes dstRow to _moveResult[0]; _moveResult[1] is always NO_SWAP (the
427
+ * partition-aware src/dst updates are owned internally, #577).
428
+ */
429
+ moveEntityFromTag(src: Archetype, srcRow: number, entityId: EntityID, entityRow: Int32Array): void;
430
+ /**
431
+ * Bulk-move ALL entities from src into this archetype using TypedArray.set().
432
+ * Much faster than per-entity moveEntityFrom when the entire source is moving.
433
+ * After this call, src is empty. Returns the starting dstRow for the batch.
434
+ */
435
+ bulkMoveAllFrom(src: Archetype, transitionMap: Int16Array, tick: number): number;
436
+ /**
437
+ * Drop every row at once — length → 0, entity-id list and all columns
438
+ * cleared — without copying into a destination. Used when an archetype's
439
+ * entire population leaves in one move: `bulkMoveAllFrom` clears the
440
+ * source this way, and `Store.batchRemoveComponent` calls it directly when
441
+ * the destination is the rowless empty archetype (batch-removing the last
442
+ * component), where there is nothing to copy into.
443
+ */
444
+ clearRows(): void;
445
+ /**
446
+ * Re-derive the host-side row bookkeeping after a snapshot is mounted onto a
447
+ * live world (#789, `Store.restoreInto`). A snapshot reloads the column bytes
448
+ * (dense SAB) but NOT the host-side `length` / `enabledCount` / `_entityIds`
449
+ * back-reference — those are reconstructed here. `refreshViews` must have
450
+ * already repointed the columns at the restored SAB.
451
+ *
452
+ * The caller scans the restored entity-index region to learn which entity
453
+ * occupies each row and passes them in row order (`rowEntityIds[r]` is the
454
+ * packed `EntityID` at row `r`; rows `[0, length)` are dense, enabled rows
455
+ * first then disabled per the #577 partition). `enabledCount` is the restored
456
+ * partition boundary. This is the inverse of the per-row `addEntity` /
457
+ * `disableRow` bookkeeping the live run accumulated.
458
+ */
459
+ restoreHostRows(rowEntityIds: readonly number[], enabledCount: number): void;
460
+ getEdge(componentId: ComponentID): ArchetypeEdge | undefined;
461
+ setEdge(componentId: ComponentID, edge: ArchetypeEdge): void;
462
+ /**
463
+ * Get the transition map from this archetype to `target`, building and caching
464
+ * it on miss. Used by Store.addComponents / removeComponents — the per-edge
465
+ * cache only covers single-component steps.
466
+ */
467
+ getBatchTransitionMap(target: Archetype): Int16Array;
468
+ /** Look up a cached plural-add transition by its packed key (#659). Returns
469
+ * `undefined` until the first composite add out of this archetype plants the
470
+ * lazy Map — the common case for archetypes that only ever see single adds. */
471
+ getCompositeAddEdge(key: number): CompositeAddEdge | undefined;
472
+ /** Cache a resolved plural-add transition (target + src→target map) under its
473
+ * packed key (#659), allocating the backing Map on first use. */
474
+ cacheCompositeAddEdge(key: number, target: ArchetypeID, map: Int16Array): void;
475
+ }
476
+ /** Reusable result buffer for move_entity_from/move_entity_from_tag. [dstRow, swapped_index] */
477
+ export declare const _moveResult: [number, number];
478
+ export declare function _setIterAllRows(value: boolean): boolean;
479
+ /**
480
+ * Build a transition map from src archetype to dst archetype.
481
+ * For each column in dst, stores the index of the corresponding column in src,
482
+ * or -1 if the column is new (no source).
483
+ */
484
+ export declare function buildTransitionMap(src: Archetype, dst: Archetype): Int16Array;
485
+ export {};
486
+ //# sourceMappingURL=archetype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archetype.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/archetype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;KAmBK;AAEL,OAAO,EACN,KAAK,EAIL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAExD,eAAO,MAAM,aAAa,UAAW,MAAM,gBAKzC,CAAC;AAEH,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,WAAW,GA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D,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIvD;AAiDD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,UAAU,CA6B7E"}
@@ -0,0 +1,96 @@
1
+ import { BitSet } from '../../type_primitives/index.cjs';
2
+ import { Archetype, ArchetypeColumnLayout, ArchetypeID } from './archetype.cjs';
3
+ import { ComponentID } from './component.cjs';
4
+ import { ComponentMeta } from './store.cjs';
5
+ import { ArchetypeSpec } from '../store/index.cjs';
6
+ /** What the graph needs from `Store` — closure-injected. `extendStore` and
7
+ * `materialize` bind the storage lifecycle (SAB extend + column-store views
8
+ * + grow handler) on the Store side; `fanIntoQueries` binds query-registry
9
+ * state. All are creation-path only — never called on an edge-cache hit. */
10
+ export interface ArchetypeGraphHost {
11
+ /** Component field metadata, indexed by ComponentID — for building a new
12
+ * archetype's column layouts. */
13
+ readonly componentMetas: () => readonly ComponentMeta[];
14
+ /** Row capacity for a new archetype's column region. */
15
+ readonly initialCapacity: () => number;
16
+ /** Extend the SAB with the new archetypes' column regions (one call for
17
+ * the whole batch — the bulk path's O(N²)→O(N) win, #213). */
18
+ readonly extendStore: (specs: ArchetypeSpec[]) => void;
19
+ /** Materialise the `Archetype` over the live column store and attach the
20
+ * store's grow handler. */
21
+ readonly materialize: (id: ArchetypeID, ownedMask: BitSet, layouts: ArchetypeColumnLayout[]) => Archetype;
22
+ /** Push a newly-installed archetype into every registered query whose
23
+ * masks it satisfies. */
24
+ readonly fanIntoQueries: (archetype: Archetype) => void;
25
+ }
26
+ export declare class ArchetypeGraph {
27
+ /** All archetypes, indexed by `ArchetypeID` (ids are minted monotonically
28
+ * and never removed). Store's flush loops hoist this array to a local. */
29
+ readonly archetypes: Archetype[];
30
+ /** Inverted index: ComponentID → ascending list of ArchetypeIDs that contain
31
+ * that component. Indexed POSITIONALLY by component id (a small, dense id
32
+ * space, 0..STORE_DESCRIPTOR_COMPONENT_LIMIT-1), so a lookup is an array
33
+ * index, not a Map hash. Used by `getMatchingArchetypes` to start the
34
+ * superset scan from the smallest bucket. Each bucket is a plain push-only
35
+ * array — NOT a Set — and deliberately does NOT dedup: a (component,
36
+ * archetype) pair can be inserted here at most once (see the "no duplicate
37
+ * pair" invariant on `install` + ADR-0015), so there is nothing for a Set
38
+ * to collapse. Archetypes are never removed from a Store, so buckets only
39
+ * grow, in ascending archetype-id order — which is canonical order,
40
+ * exploited by `_forEachChangedArchetype` to skip a sort. */
41
+ readonly componentIndex: ArchetypeID[][];
42
+ private readonly archetypeMap;
43
+ private nextArchetypeId;
44
+ private readonly host;
45
+ constructor(host: ArchetypeGraphHost);
46
+ get(id: ArchetypeID): Archetype;
47
+ /**
48
+ * Find or create an archetype for the given component mask.
49
+ * Also updates the componentIndex and pushes into matching registered queries.
50
+ *
51
+ * Hot single-mask path. The bulk batched variant — used by Phase C
52
+ * pre-warming at `ecs.startup()` — is `createManyFromMasks`;
53
+ * see #213 / `ECS.startup()` for how it gets called and why.
54
+ */
55
+ getOrCreateFromMask(mask: BitSet): ArchetypeID;
56
+ /**
57
+ * Bulk variant of `getOrCreateFromMask` — Phase C of issue #213.
58
+ *
59
+ * Given a set of masks, creates Archetypes for the ones not already
60
+ * planted, in a SINGLE `extendColumnStore` call (instead of one per
61
+ * archetype). Single-mask creation is O(N) in archetypes-so-far because
62
+ * the extend has to copy every existing archetype's live rows forward;
63
+ * N such calls compound to O(N²). Batching collapses the per-archetype
64
+ * setup-and-copy down to one pass — the per-startup cost the design doc
65
+ * §5.2 calls out as "O(N²) → O(N)" for in-tree systems whose archetype
66
+ * set is known at registration time via `spawns` + `transitions`.
67
+ *
68
+ * Masks already in the map are skipped. Returns the resolved
69
+ * `ArchetypeID` per input mask in input order — callers that don't need
70
+ * the ids can ignore the return value.
71
+ */
72
+ createManyFromMasks(masks: readonly BitSet[]): ArchetypeID[];
73
+ /** Hash-bucketed mask → ArchetypeID lookup; null when the mask isn't planted. */
74
+ private lookup;
75
+ /** Walk the mask's set bits and resolve each non-tag component to its
76
+ * layout. Used by both single and bulk archetype-create paths. */
77
+ private buildLayouts;
78
+ /** Materialise the `Archetype` for `id` (via the host, which binds the
79
+ * live column store + grow handler), register in the archetype map +
80
+ * component index, and fan into any matching registered queries.
81
+ *
82
+ * Clones `mask` before storing — callers may pass scratch BitSets that
83
+ * they intend to reuse (e.g. `addComponents` / `removeComponents`'s
84
+ * `_scratchTargetMask`). The Archetype and the archetypeMap bucket
85
+ * both keep references long-term, so the clone is required for
86
+ * correctness — and is the previously-implicit guarantee made by the
87
+ * mask-allocating callers (`copyWithSet`, `copyWithClear`, etc.). */
88
+ private install;
89
+ /** Resolve "add component_id to archetype_id" → target ArchetypeID. Caches the edge. */
90
+ resolveAdd(archetypeId: ArchetypeID, componentId: ComponentID): ArchetypeID;
91
+ /** Resolve "remove component_id from archetype_id" → target ArchetypeID. Caches the edge. */
92
+ resolveRemove(archetypeId: ArchetypeID, componentId: ComponentID): ArchetypeID;
93
+ /** Cache a bidirectional add/remove edge between two archetypes. */
94
+ private cacheEdge;
95
+ }
96
+ //# sourceMappingURL=archetype_graph.d.ts.map