@oasys/oecs 0.5.3 → 0.6.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 (510) hide show
  1. package/CHANGELOG.md +1399 -276
  2. package/README.md +327 -169
  3. package/dist/core/ecs/access_check.d.cts +31 -31
  4. package/dist/core/ecs/access_check.d.ts +31 -31
  5. package/dist/core/ecs/access_check.d.ts.map +1 -1
  6. package/dist/core/ecs/archetype.d.cts +273 -205
  7. package/dist/core/ecs/archetype.d.ts +273 -205
  8. package/dist/core/ecs/archetype.d.ts.map +1 -1
  9. package/dist/core/ecs/archetype_closure.d.cts +23 -0
  10. package/dist/core/ecs/archetype_closure.d.ts +23 -0
  11. package/dist/core/ecs/archetype_closure.d.ts.map +1 -0
  12. package/dist/core/ecs/archetype_graph.d.cts +34 -34
  13. package/dist/core/ecs/archetype_graph.d.ts +34 -34
  14. package/dist/core/ecs/archetype_graph.d.ts.map +1 -1
  15. package/dist/core/ecs/archetype_types.d.cts +55 -0
  16. package/dist/core/ecs/archetype_types.d.ts +55 -0
  17. package/dist/core/ecs/archetype_types.d.ts.map +1 -0
  18. package/dist/core/ecs/change_feed.d.cts +53 -0
  19. package/dist/core/ecs/change_feed.d.ts +53 -0
  20. package/dist/core/ecs/change_feed.d.ts.map +1 -0
  21. package/dist/core/ecs/changed_query.d.cts +36 -0
  22. package/dist/core/ecs/changed_query.d.ts +36 -0
  23. package/dist/core/ecs/changed_query.d.ts.map +1 -0
  24. package/dist/core/ecs/chunk_columns.d.cts +49 -0
  25. package/dist/core/ecs/chunk_columns.d.ts +49 -0
  26. package/dist/core/ecs/chunk_columns.d.ts.map +1 -0
  27. package/dist/core/ecs/command_log.d.cts +30 -30
  28. package/dist/core/ecs/command_log.d.ts +30 -30
  29. package/dist/core/ecs/command_log.d.ts.map +1 -1
  30. package/dist/core/ecs/component.d.cts +45 -44
  31. package/dist/core/ecs/component.d.ts +45 -44
  32. package/dist/core/ecs/component.d.ts.map +1 -1
  33. package/dist/core/ecs/component_registry.d.cts +53 -0
  34. package/dist/core/ecs/component_registry.d.ts +53 -0
  35. package/dist/core/ecs/component_registry.d.ts.map +1 -0
  36. package/dist/core/ecs/compute_backend.d.cts +18 -7
  37. package/dist/core/ecs/compute_backend.d.ts +18 -7
  38. package/dist/core/ecs/compute_backend.d.ts.map +1 -1
  39. package/dist/core/ecs/deferred_commands.d.cts +15 -14
  40. package/dist/core/ecs/deferred_commands.d.ts +15 -14
  41. package/dist/core/ecs/deferred_commands.d.ts.map +1 -1
  42. package/dist/core/ecs/dispatch_trace.d.cts +32 -31
  43. package/dist/core/ecs/dispatch_trace.d.ts +32 -31
  44. package/dist/core/ecs/dispatch_trace.d.ts.map +1 -1
  45. package/dist/core/ecs/ecs.d.cts +337 -276
  46. package/dist/core/ecs/ecs.d.ts +337 -276
  47. package/dist/core/ecs/ecs.d.ts.map +1 -1
  48. package/dist/core/ecs/ecs_memory.d.cts +134 -136
  49. package/dist/core/ecs/ecs_memory.d.ts +134 -136
  50. package/dist/core/ecs/ecs_memory.d.ts.map +1 -1
  51. package/dist/core/ecs/ecs_options.d.cts +89 -0
  52. package/dist/core/ecs/ecs_options.d.ts +89 -0
  53. package/dist/core/ecs/ecs_options.d.ts.map +1 -0
  54. package/dist/core/ecs/entity.d.cts +4 -4
  55. package/dist/core/ecs/entity.d.ts +4 -4
  56. package/dist/core/ecs/entity_allocator.d.cts +24 -22
  57. package/dist/core/ecs/entity_allocator.d.ts +24 -22
  58. package/dist/core/ecs/entity_allocator.d.ts.map +1 -1
  59. package/dist/core/ecs/event.d.cts +37 -23
  60. package/dist/core/ecs/event.d.ts +37 -23
  61. package/dist/core/ecs/event.d.ts.map +1 -1
  62. package/dist/core/ecs/facades.d.cts +12 -126
  63. package/dist/core/ecs/facades.d.ts +12 -126
  64. package/dist/core/ecs/facades.d.ts.map +1 -1
  65. package/dist/core/ecs/frame_stepper.d.cts +12 -12
  66. package/dist/core/ecs/frame_stepper.d.ts +12 -12
  67. package/dist/core/ecs/frame_stepper.d.ts.map +1 -1
  68. package/dist/core/ecs/frame_trace.d.cts +34 -34
  69. package/dist/core/ecs/frame_trace.d.ts +34 -34
  70. package/dist/core/ecs/frame_trace.d.ts.map +1 -1
  71. package/dist/core/ecs/host_commands.d.cts +107 -89
  72. package/dist/core/ecs/host_commands.d.ts +107 -89
  73. package/dist/core/ecs/host_commands.d.ts.map +1 -1
  74. package/dist/core/ecs/index.d.cts +22 -12
  75. package/dist/core/ecs/index.d.ts +22 -12
  76. package/dist/core/ecs/index.d.ts.map +1 -1
  77. package/dist/core/ecs/observer.d.cts +41 -122
  78. package/dist/core/ecs/observer.d.ts +41 -122
  79. package/dist/core/ecs/observer.d.ts.map +1 -1
  80. package/dist/core/ecs/phase.d.cts +79 -0
  81. package/dist/core/ecs/phase.d.ts +79 -0
  82. package/dist/core/ecs/phase.d.ts.map +1 -0
  83. package/dist/core/ecs/plugin.d.cts +125 -0
  84. package/dist/core/ecs/plugin.d.ts +125 -0
  85. package/dist/core/ecs/plugin.d.ts.map +1 -0
  86. package/dist/core/ecs/plugin_slots.d.cts +26 -0
  87. package/dist/core/ecs/plugin_slots.d.ts +26 -0
  88. package/dist/core/ecs/plugin_slots.d.ts.map +1 -0
  89. package/dist/core/ecs/query.d.cts +219 -568
  90. package/dist/core/ecs/query.d.ts +219 -568
  91. package/dist/core/ecs/query.d.ts.map +1 -1
  92. package/dist/core/ecs/query_cache.d.cts +130 -0
  93. package/dist/core/ecs/query_cache.d.ts +130 -0
  94. package/dist/core/ecs/query_cache.d.ts.map +1 -0
  95. package/dist/core/ecs/query_registry.d.cts +47 -0
  96. package/dist/core/ecs/query_registry.d.ts +47 -0
  97. package/dist/core/ecs/query_registry.d.ts.map +1 -0
  98. package/dist/core/ecs/query_terms.d.cts +126 -0
  99. package/dist/core/ecs/query_terms.d.ts +126 -0
  100. package/dist/core/ecs/query_terms.d.ts.map +1 -0
  101. package/dist/core/ecs/ref.d.cts +129 -16
  102. package/dist/core/ecs/ref.d.ts +129 -16
  103. package/dist/core/ecs/ref.d.ts.map +1 -1
  104. package/dist/core/ecs/relation.d.cts +105 -186
  105. package/dist/core/ecs/relation.d.ts +105 -186
  106. package/dist/core/ecs/relation.d.ts.map +1 -1
  107. package/dist/core/ecs/resource.d.cts +14 -14
  108. package/dist/core/ecs/resource.d.ts +14 -14
  109. package/dist/core/ecs/resource_registry.d.cts +6 -6
  110. package/dist/core/ecs/resource_registry.d.ts +6 -6
  111. package/dist/core/ecs/resource_registry.d.ts.map +1 -1
  112. package/dist/core/ecs/row_kinds.d.cts +24 -0
  113. package/dist/core/ecs/row_kinds.d.ts +24 -0
  114. package/dist/core/ecs/row_kinds.d.ts.map +1 -0
  115. package/dist/core/ecs/run_condition.d.cts +23 -23
  116. package/dist/core/ecs/run_condition.d.ts +23 -23
  117. package/dist/core/ecs/run_condition.d.ts.map +1 -1
  118. package/dist/core/ecs/schedule.d.cts +98 -114
  119. package/dist/core/ecs/schedule.d.ts +98 -114
  120. package/dist/core/ecs/schedule.d.ts.map +1 -1
  121. package/dist/core/ecs/schedule_plan.d.cts +33 -0
  122. package/dist/core/ecs/schedule_plan.d.ts +33 -0
  123. package/dist/core/ecs/schedule_plan.d.ts.map +1 -0
  124. package/dist/core/ecs/snapshot.d.cts +77 -0
  125. package/dist/core/ecs/snapshot.d.ts +77 -0
  126. package/dist/core/ecs/snapshot.d.ts.map +1 -0
  127. package/dist/core/ecs/snapshot_mount.d.cts +42 -0
  128. package/dist/core/ecs/snapshot_mount.d.ts +42 -0
  129. package/dist/core/ecs/snapshot_mount.d.ts.map +1 -0
  130. package/dist/core/ecs/sparse_store.d.cts +110 -53
  131. package/dist/core/ecs/sparse_store.d.ts +110 -53
  132. package/dist/core/ecs/sparse_store.d.ts.map +1 -1
  133. package/dist/core/ecs/store.d.cts +644 -511
  134. package/dist/core/ecs/store.d.ts +644 -511
  135. package/dist/core/ecs/store.d.ts.map +1 -1
  136. package/dist/core/ecs/store_layout_listener.d.cts +8 -8
  137. package/dist/core/ecs/store_layout_listener.d.ts +8 -8
  138. package/dist/core/ecs/store_types.d.cts +122 -0
  139. package/dist/core/ecs/store_types.d.ts +122 -0
  140. package/dist/core/ecs/store_types.d.ts.map +1 -0
  141. package/dist/core/ecs/system.d.cts +151 -66
  142. package/dist/core/ecs/system.d.ts +151 -66
  143. package/dist/core/ecs/system.d.ts.map +1 -1
  144. package/dist/core/ecs/system_context.d.cts +296 -0
  145. package/dist/core/ecs/system_context.d.ts +296 -0
  146. package/dist/core/ecs/system_context.d.ts.map +1 -0
  147. package/dist/core/ecs/system_set.d.cts +48 -0
  148. package/dist/core/ecs/system_set.d.ts +48 -0
  149. package/dist/core/ecs/system_set.d.ts.map +1 -0
  150. package/dist/core/ecs/utils/arrays.d.cts +15 -1
  151. package/dist/core/ecs/utils/arrays.d.ts +15 -1
  152. package/dist/core/ecs/utils/arrays.d.ts.map +1 -1
  153. package/dist/core/ecs/utils/error.d.cts +87 -4
  154. package/dist/core/ecs/utils/error.d.ts +87 -4
  155. package/dist/core/ecs/utils/error.d.ts.map +1 -1
  156. package/dist/core/ecs/utils/plugin_error.d.cts +10 -0
  157. package/dist/core/ecs/utils/plugin_error.d.ts +10 -0
  158. package/dist/core/ecs/utils/plugin_error.d.ts.map +1 -0
  159. package/dist/core/restore_errors.d.cts +30 -0
  160. package/dist/core/restore_errors.d.ts +30 -0
  161. package/dist/core/restore_errors.d.ts.map +1 -0
  162. package/dist/core/store/action_ring.d.cts +48 -49
  163. package/dist/core/store/action_ring.d.ts +48 -49
  164. package/dist/core/store/action_ring.d.ts.map +1 -1
  165. package/dist/core/store/allocator.d.cts +166 -114
  166. package/dist/core/store/allocator.d.ts +166 -114
  167. package/dist/core/store/allocator.d.ts.map +1 -1
  168. package/dist/core/store/buffer_backed_column.d.cts +21 -22
  169. package/dist/core/store/buffer_backed_column.d.ts +21 -22
  170. package/dist/core/store/buffer_backed_column.d.ts.map +1 -1
  171. package/dist/core/store/column_store.d.cts +138 -100
  172. package/dist/core/store/column_store.d.ts +138 -100
  173. package/dist/core/store/column_store.d.ts.map +1 -1
  174. package/dist/core/store/command_dispatch.d.cts +14 -15
  175. package/dist/core/store/command_dispatch.d.ts +14 -15
  176. package/dist/core/store/command_dispatch.d.ts.map +1 -1
  177. package/dist/core/store/command_ring.d.cts +41 -45
  178. package/dist/core/store/command_ring.d.ts +41 -45
  179. package/dist/core/store/command_ring.d.ts.map +1 -1
  180. package/dist/core/store/descriptor.d.cts +35 -18
  181. package/dist/core/store/descriptor.d.ts +35 -18
  182. package/dist/core/store/descriptor.d.ts.map +1 -1
  183. package/dist/core/store/entity_index.d.cts +34 -35
  184. package/dist/core/store/entity_index.d.ts +34 -35
  185. package/dist/core/store/entity_index.d.ts.map +1 -1
  186. package/dist/core/store/event_ring.d.cts +40 -42
  187. package/dist/core/store/event_ring.d.ts +40 -42
  188. package/dist/core/store/event_ring.d.ts.map +1 -1
  189. package/dist/core/store/extend.d.cts +15 -9
  190. package/dist/core/store/extend.d.ts +15 -9
  191. package/dist/core/store/extend.d.ts.map +1 -1
  192. package/dist/core/store/grow.d.cts +3 -3
  193. package/dist/core/store/grow.d.ts +3 -3
  194. package/dist/core/store/grow.d.ts.map +1 -1
  195. package/dist/core/store/header.d.cts +37 -33
  196. package/dist/core/store/header.d.ts +37 -33
  197. package/dist/core/store/header.d.ts.map +1 -1
  198. package/dist/core/store/index.d.cts +10 -10
  199. package/dist/core/store/index.d.ts +10 -10
  200. package/dist/core/store/index.d.ts.map +1 -1
  201. package/dist/core/store/layout_ops.d.cts +72 -63
  202. package/dist/core/store/layout_ops.d.ts +72 -63
  203. package/dist/core/store/layout_ops.d.ts.map +1 -1
  204. package/dist/core/store/region_table.d.cts +28 -21
  205. package/dist/core/store/region_table.d.ts +28 -21
  206. package/dist/core/store/region_table.d.ts.map +1 -1
  207. package/dist/core/store/snapshot.d.cts +31 -16
  208. package/dist/core/store/snapshot.d.ts +31 -16
  209. package/dist/core/store/snapshot.d.ts.map +1 -1
  210. package/dist/core/store/state_hash.d.cts +14 -14
  211. package/dist/core/store/state_hash.d.ts +14 -14
  212. package/dist/core/store/state_hash.d.ts.map +1 -1
  213. package/dist/core/store/store_regions.d.cts +10 -10
  214. package/dist/core/store/store_regions.d.ts +10 -10
  215. package/dist/core/store/store_regions.d.ts.map +1 -1
  216. package/dist/core/store/vendored_abi/abi.d.cts +27 -2
  217. package/dist/core/store/vendored_abi/abi.d.ts +27 -2
  218. package/dist/core/store/vendored_abi/abi.d.ts.map +1 -1
  219. package/dist/host_commands-B2KMx8O2.cjs +1 -0
  220. package/dist/host_commands-ClVPvhSa.cjs +2 -0
  221. package/dist/host_commands-CwxVQS1z.js +1524 -0
  222. package/dist/host_commands-nJvTy88E.js +1667 -0
  223. package/dist/index.cjs +1 -1
  224. package/dist/index.d.cts +16 -11
  225. package/dist/index.d.ts +16 -11
  226. package/dist/index.d.ts.map +1 -1
  227. package/dist/index.development.cjs +1 -1
  228. package/dist/index.development.js +6709 -5729
  229. package/dist/index.js +5664 -4743
  230. package/dist/internal.cjs +2 -2
  231. package/dist/internal.d.cts +5 -2
  232. package/dist/internal.d.ts +5 -2
  233. package/dist/internal.d.ts.map +1 -1
  234. package/dist/internal.development.cjs +1 -1
  235. package/dist/internal.development.js +70 -20
  236. package/dist/internal.js +138 -83
  237. package/dist/plugins/abi-D3V-QUSf.cjs +1 -0
  238. package/dist/plugins/abi-NP8pNxpd.js +42 -0
  239. package/dist/plugins/arrays-Dr_1hCjL.js +28 -0
  240. package/dist/plugins/arrays-Dt-Joc4i.cjs +1 -0
  241. package/dist/plugins/assertions-gtDVfbnQ.js +6 -0
  242. package/dist/plugins/assertions-z5GQd_bB.cjs +1 -0
  243. package/dist/{extensions → plugins}/editor/editor.d.cts +56 -56
  244. package/dist/{extensions → plugins}/editor/editor.d.ts +56 -56
  245. package/dist/plugins/editor/editor.d.ts.map +1 -0
  246. package/dist/{extensions → plugins}/editor/field_handle.d.cts +13 -13
  247. package/dist/{extensions → plugins}/editor/field_handle.d.ts +13 -13
  248. package/dist/plugins/editor/field_handle.d.ts.map +1 -0
  249. package/dist/plugins/editor/index.d.cts +22 -0
  250. package/dist/plugins/editor/index.d.ts +22 -0
  251. package/dist/plugins/editor/index.d.ts.map +1 -0
  252. package/dist/plugins/editor.cjs +1 -0
  253. package/dist/plugins/editor.d.cts +1 -0
  254. package/dist/plugins/editor.d.ts +1 -0
  255. package/dist/plugins/editor.development.cjs +1 -0
  256. package/dist/{extensions/editor/index.development.js → plugins/editor.development.js} +83 -66
  257. package/dist/{extensions/editor/index.js → plugins/editor.js} +83 -66
  258. package/dist/plugins/events/event_channel.d.cts +13 -0
  259. package/dist/plugins/events/event_channel.d.ts +13 -0
  260. package/dist/plugins/events/event_channel.d.ts.map +1 -0
  261. package/dist/plugins/events/event_registry.d.cts +22 -0
  262. package/dist/plugins/events/event_registry.d.ts +22 -0
  263. package/dist/plugins/events/event_registry.d.ts.map +1 -0
  264. package/dist/plugins/events/facade.d.cts +26 -0
  265. package/dist/plugins/events/facade.d.ts +26 -0
  266. package/dist/plugins/events/facade.d.ts.map +1 -0
  267. package/dist/plugins/events/index.d.cts +10 -0
  268. package/dist/plugins/events/index.d.ts +10 -0
  269. package/dist/plugins/events/index.d.ts.map +1 -0
  270. package/dist/plugins/events.cjs +1 -0
  271. package/dist/plugins/events.d.cts +1 -0
  272. package/dist/plugins/events.d.ts +1 -0
  273. package/dist/plugins/events.development.cjs +1 -0
  274. package/dist/plugins/events.development.js +174 -0
  275. package/dist/plugins/events.js +159 -0
  276. package/dist/plugins/observers/index.d.cts +23 -0
  277. package/dist/plugins/observers/index.d.ts +23 -0
  278. package/dist/plugins/observers/index.d.ts.map +1 -0
  279. package/dist/plugins/observers/observer_registry.d.cts +101 -0
  280. package/dist/plugins/observers/observer_registry.d.ts +101 -0
  281. package/dist/plugins/observers/observer_registry.d.ts.map +1 -0
  282. package/dist/plugins/observers.cjs +1 -0
  283. package/dist/plugins/observers.d.cts +1 -0
  284. package/dist/plugins/observers.d.ts +1 -0
  285. package/dist/plugins/observers.development.cjs +1 -0
  286. package/dist/plugins/observers.development.js +431 -0
  287. package/dist/plugins/observers.js +403 -0
  288. package/dist/plugins/relation_store-BsoegrZh.js +313 -0
  289. package/dist/plugins/relation_store-DQKSnxsm.cjs +1 -0
  290. package/dist/plugins/relation_store-RBhpcE28.cjs +1 -0
  291. package/dist/plugins/relation_store-RqW5Snx6.js +328 -0
  292. package/dist/plugins/relations/builtin_relations.d.cts +48 -0
  293. package/dist/plugins/relations/builtin_relations.d.ts +48 -0
  294. package/dist/plugins/relations/builtin_relations.d.ts.map +1 -0
  295. package/dist/plugins/relations/facade.d.cts +73 -0
  296. package/dist/plugins/relations/facade.d.ts +73 -0
  297. package/dist/plugins/relations/facade.d.ts.map +1 -0
  298. package/dist/plugins/relations/index.d.cts +11 -0
  299. package/dist/plugins/relations/index.d.ts +11 -0
  300. package/dist/plugins/relations/index.d.ts.map +1 -0
  301. package/dist/{core/ecs → plugins/relations}/relation_service.d.cts +93 -105
  302. package/dist/{core/ecs → plugins/relations}/relation_service.d.ts +93 -105
  303. package/dist/plugins/relations/relation_service.d.ts.map +1 -0
  304. package/dist/plugins/relations/relation_store.d.cts +177 -0
  305. package/dist/plugins/relations/relation_store.d.ts +177 -0
  306. package/dist/plugins/relations/relation_store.d.ts.map +1 -0
  307. package/dist/plugins/relations.cjs +1 -0
  308. package/dist/plugins/relations.d.cts +1 -0
  309. package/dist/plugins/relations.d.ts +1 -0
  310. package/dist/plugins/relations.development.cjs +1 -0
  311. package/dist/plugins/relations.development.js +603 -0
  312. package/dist/plugins/relations.js +553 -0
  313. package/dist/plugins/snapshots/index.d.cts +33 -0
  314. package/dist/plugins/snapshots/index.d.ts +33 -0
  315. package/dist/plugins/snapshots/index.d.ts.map +1 -0
  316. package/dist/plugins/snapshots/resume.d.cts +57 -0
  317. package/dist/plugins/snapshots/resume.d.ts +57 -0
  318. package/dist/plugins/snapshots/resume.d.ts.map +1 -0
  319. package/dist/plugins/snapshots/snapshot_service.d.cts +59 -0
  320. package/dist/plugins/snapshots/snapshot_service.d.ts +59 -0
  321. package/dist/plugins/snapshots/snapshot_service.d.ts.map +1 -0
  322. package/dist/plugins/snapshots.cjs +1 -0
  323. package/dist/plugins/snapshots.d.cts +1 -0
  324. package/dist/plugins/snapshots.d.ts +1 -0
  325. package/dist/plugins/snapshots.development.cjs +1 -0
  326. package/dist/plugins/snapshots.development.js +737 -0
  327. package/dist/plugins/snapshots.js +737 -0
  328. package/dist/plugins/solid/index.d.cts +8 -0
  329. package/dist/plugins/solid/index.d.ts +8 -0
  330. package/dist/plugins/solid/index.d.ts.map +1 -0
  331. package/dist/plugins/solid/solid.d.cts +97 -0
  332. package/dist/plugins/solid/solid.d.ts +97 -0
  333. package/dist/plugins/solid/solid.d.ts.map +1 -0
  334. package/dist/plugins/solid.cjs +1 -0
  335. package/dist/plugins/solid.d.cts +1 -0
  336. package/dist/plugins/solid.d.ts +1 -0
  337. package/dist/plugins/solid.development.cjs +1 -0
  338. package/dist/plugins/solid.development.js +319 -0
  339. package/dist/plugins/solid.js +319 -0
  340. package/dist/plugins/workers/index.d.cts +75 -0
  341. package/dist/plugins/workers/index.d.ts +75 -0
  342. package/dist/plugins/workers/index.d.ts.map +1 -0
  343. package/dist/plugins/workers/node_threads.d.cts +25 -0
  344. package/dist/plugins/workers/node_threads.d.ts +25 -0
  345. package/dist/plugins/workers/node_threads.d.ts.map +1 -0
  346. package/dist/plugins/workers/plan.d.cts +61 -0
  347. package/dist/plugins/workers/plan.d.ts +61 -0
  348. package/dist/plugins/workers/plan.d.ts.map +1 -0
  349. package/dist/plugins/workers/pool.d.cts +144 -0
  350. package/dist/plugins/workers/pool.d.ts +144 -0
  351. package/dist/plugins/workers/pool.d.ts.map +1 -0
  352. package/dist/plugins/workers/protocol.d.cts +112 -0
  353. package/dist/plugins/workers/protocol.d.ts +112 -0
  354. package/dist/plugins/workers/protocol.d.ts.map +1 -0
  355. package/dist/plugins/workers/worker_bind.d.cts +64 -0
  356. package/dist/plugins/workers/worker_bind.d.ts +64 -0
  357. package/dist/plugins/workers/worker_bind.d.ts.map +1 -0
  358. package/dist/plugins/workers/worker_loop.d.cts +14 -0
  359. package/dist/plugins/workers/worker_loop.d.ts +14 -0
  360. package/dist/plugins/workers/worker_loop.d.ts.map +1 -0
  361. package/dist/plugins/workers.cjs +1 -0
  362. package/dist/plugins/workers.d.cts +1 -0
  363. package/dist/plugins/workers.d.ts +1 -0
  364. package/dist/plugins/workers.development.cjs +1 -0
  365. package/dist/plugins/workers.development.js +596 -0
  366. package/dist/plugins/workers.js +474 -0
  367. package/dist/primitives.cjs +1 -1
  368. package/dist/primitives.d.cts +4 -4
  369. package/dist/primitives.d.ts +4 -4
  370. package/dist/primitives.development.cjs +1 -1
  371. package/dist/primitives.development.js +66 -22
  372. package/dist/primitives.js +66 -22
  373. package/dist/shared-BKl12xF1.js +132 -0
  374. package/dist/shared-Dk-pACZT.cjs +1 -0
  375. package/dist/shared.cjs +1 -1
  376. package/dist/shared.d.cts +7 -7
  377. package/dist/shared.d.ts +7 -7
  378. package/dist/shared.d.ts.map +1 -1
  379. package/dist/shared.development.cjs +1 -1
  380. package/dist/shared.development.js +4 -3
  381. package/dist/shared.js +4 -3
  382. package/dist/topological_sort-Cc_yXqPT.js +346 -0
  383. package/dist/topological_sort-vp1imU6D.cjs +1 -0
  384. package/dist/type_primitives/assertions.d.cts +12 -16
  385. package/dist/type_primitives/assertions.d.ts +12 -16
  386. package/dist/type_primitives/assertions.d.ts.map +1 -1
  387. package/dist/type_primitives/binary_heap/binary_heap.d.cts +2 -6
  388. package/dist/type_primitives/binary_heap/binary_heap.d.ts +2 -6
  389. package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -1
  390. package/dist/type_primitives/bitset/bitset.d.cts +7 -11
  391. package/dist/type_primitives/bitset/bitset.d.ts +7 -11
  392. package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
  393. package/dist/type_primitives/brand.d.cts +2 -7
  394. package/dist/type_primitives/brand.d.ts +2 -7
  395. package/dist/type_primitives/brand.d.ts.map +1 -1
  396. package/dist/type_primitives/error.d.cts +1 -2
  397. package/dist/type_primitives/error.d.ts +1 -2
  398. package/dist/type_primitives/error.d.ts.map +1 -1
  399. package/dist/type_primitives/index.d.cts +1 -1
  400. package/dist/type_primitives/index.d.ts +1 -1
  401. package/dist/type_primitives/sparse_map/sparse_map.d.cts +3 -7
  402. package/dist/type_primitives/sparse_map/sparse_map.d.ts +3 -7
  403. package/dist/type_primitives/sparse_map/sparse_map.d.ts.map +1 -1
  404. package/dist/type_primitives/sparse_set/sparse_set.d.cts +2 -6
  405. package/dist/type_primitives/sparse_set/sparse_set.d.ts +2 -6
  406. package/dist/type_primitives/sparse_set/sparse_set.d.ts.map +1 -1
  407. package/dist/type_primitives/topological_sort/topological_sort.d.cts +1 -5
  408. package/dist/type_primitives/topological_sort/topological_sort.d.ts +1 -5
  409. package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -1
  410. package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +18 -17
  411. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +18 -17
  412. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
  413. package/dist/utils/error.d.ts.map +1 -1
  414. package/dist/version.d.cts +4 -4
  415. package/dist/version.d.ts +4 -4
  416. package/dist/worker.cjs +1 -0
  417. package/dist/worker.d.cts +17 -0
  418. package/dist/worker.d.ts +17 -0
  419. package/dist/worker.d.ts.map +1 -0
  420. package/dist/worker.development.cjs +1 -0
  421. package/dist/worker.development.js +253 -0
  422. package/dist/worker.js +253 -0
  423. package/package.json +363 -191
  424. package/dist/core/ecs/builtin_relations.d.cts +0 -43
  425. package/dist/core/ecs/builtin_relations.d.ts +0 -43
  426. package/dist/core/ecs/builtin_relations.d.ts.map +0 -1
  427. package/dist/core/ecs/event_registry.d.cts +0 -22
  428. package/dist/core/ecs/event_registry.d.ts +0 -22
  429. package/dist/core/ecs/event_registry.d.ts.map +0 -1
  430. package/dist/core/ecs/relation_service.d.ts.map +0 -1
  431. package/dist/core/ecs/resume.d.cts +0 -85
  432. package/dist/core/ecs/resume.d.ts +0 -85
  433. package/dist/core/ecs/resume.d.ts.map +0 -1
  434. package/dist/core/ecs/snapshot_service.d.cts +0 -94
  435. package/dist/core/ecs/snapshot_service.d.ts +0 -94
  436. package/dist/core/ecs/snapshot_service.d.ts.map +0 -1
  437. package/dist/extensions/editor/editor.d.ts.map +0 -1
  438. package/dist/extensions/editor/field_handle.d.ts.map +0 -1
  439. package/dist/extensions/editor/index.cjs +0 -1
  440. package/dist/extensions/editor/index.d.cts +0 -21
  441. package/dist/extensions/editor/index.d.ts +0 -21
  442. package/dist/extensions/editor/index.d.ts.map +0 -1
  443. package/dist/extensions/editor/index.development.cjs +0 -1
  444. package/dist/extensions/reactive/ecs_sync.d.cts +0 -214
  445. package/dist/extensions/reactive/ecs_sync.d.ts +0 -214
  446. package/dist/extensions/reactive/ecs_sync.d.ts.map +0 -1
  447. package/dist/extensions/reactive/index.cjs +0 -1
  448. package/dist/extensions/reactive/index.d.cts +0 -23
  449. package/dist/extensions/reactive/index.d.ts +0 -23
  450. package/dist/extensions/reactive/index.d.ts.map +0 -1
  451. package/dist/extensions/reactive/index.development.cjs +0 -1
  452. package/dist/extensions/reactive/index.development.js +0 -215
  453. package/dist/extensions/reactive/index.js +0 -215
  454. package/dist/extensions/solid/index.cjs +0 -1
  455. package/dist/extensions/solid/index.d.cts +0 -6
  456. package/dist/extensions/solid/index.d.ts +0 -6
  457. package/dist/extensions/solid/index.d.ts.map +0 -1
  458. package/dist/extensions/solid/index.development.cjs +0 -1
  459. package/dist/extensions/solid/index.development.js +0 -40
  460. package/dist/extensions/solid/index.js +0 -36
  461. package/dist/extensions/solid/kernel_solid.d.cts +0 -45
  462. package/dist/extensions/solid/kernel_solid.d.ts +0 -45
  463. package/dist/extensions/solid/kernel_solid.d.ts.map +0 -1
  464. package/dist/host_commands-3jyFfWNg.js +0 -2326
  465. package/dist/host_commands-DNf0f6ko.cjs +0 -1
  466. package/dist/internal-C9jjL90H.js +0 -2485
  467. package/dist/internal-RZN14uMw.cjs +0 -2
  468. package/dist/interop-CT-REx0W.cjs +0 -1
  469. package/dist/interop-CcY6ASQc.js +0 -18
  470. package/dist/interop-DqxleBo7.js +0 -18
  471. package/dist/interop-T1HZ-Dpa.cjs +0 -1
  472. package/dist/kernel-Cz2Kxlwl.js +0 -240
  473. package/dist/kernel-DgyrLFjW.js +0 -227
  474. package/dist/kernel-sw7ScKWu.cjs +0 -1
  475. package/dist/kernel-yWV3XnAb.cjs +0 -1
  476. package/dist/reactive/array.d.cts +0 -24
  477. package/dist/reactive/array.d.ts +0 -24
  478. package/dist/reactive/array.d.ts.map +0 -1
  479. package/dist/reactive/index.cjs +0 -1
  480. package/dist/reactive/index.d.cts +0 -11
  481. package/dist/reactive/index.d.ts +0 -11
  482. package/dist/reactive/index.d.ts.map +0 -1
  483. package/dist/reactive/index.development.cjs +0 -1
  484. package/dist/reactive/index.development.js +0 -18
  485. package/dist/reactive/index.js +0 -18
  486. package/dist/reactive/interop.d.cts +0 -19
  487. package/dist/reactive/interop.d.ts +0 -19
  488. package/dist/reactive/interop.d.ts.map +0 -1
  489. package/dist/reactive/kernel.d.cts +0 -73
  490. package/dist/reactive/kernel.d.ts +0 -73
  491. package/dist/reactive/kernel.d.ts.map +0 -1
  492. package/dist/reactive/map.d.cts +0 -16
  493. package/dist/reactive/map.d.ts +0 -16
  494. package/dist/reactive/map.d.ts.map +0 -1
  495. package/dist/reactive/shallow.d.cts +0 -11
  496. package/dist/reactive/shallow.d.ts +0 -11
  497. package/dist/reactive/shallow.d.ts.map +0 -1
  498. package/dist/reactive/struct.d.cts +0 -10
  499. package/dist/reactive/struct.d.ts +0 -10
  500. package/dist/reactive/struct.d.ts.map +0 -1
  501. package/dist/shallow-9S1pY_Iw.js +0 -159
  502. package/dist/shallow-C5YmTbtb.cjs +0 -1
  503. package/dist/shallow-DQ8aG51_.cjs +0 -1
  504. package/dist/shallow-DfnAm9vG.js +0 -150
  505. package/dist/shared-BMXh9hxm.cjs +0 -1
  506. package/dist/shared-DQKK0i-E.js +0 -109
  507. package/dist/topological_sort-BDvEyb9W.cjs +0 -1
  508. package/dist/topological_sort-DK6EjpWa.js +0 -135
  509. package/dist/typed_arrays-BcXcnzB4.js +0 -258
  510. package/dist/typed_arrays-D3NmwtCG.cjs +0 -1
@@ -0,0 +1,1524 @@
1
+ import { D as Ve, w as ce, g as He, h as Ge } from "./shared-BKl12xF1.js";
2
+ class we extends Error {
3
+ constructor(t, n, o) {
4
+ super(t), this.isOperational = n, this.context = o, this.name = this.constructor.name, typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, this.constructor);
5
+ }
6
+ }
7
+ var be = /* @__PURE__ */ ((e) => (e.ASSERTION_FAIL_CONDITION = "ASSERTION_FAIL_CONDITION", e.VALIDATION_FAIL_CONDITION = "VALIDATION_FAIL_CONDITION", e.ASSERTION_FAIL_NON_NULLABLE = "ASSERTION_FAIL_NON_NULLABLE", e.ASSERTION_FAIL_UNREACHABLE = "ASSERTION_FAIL_UNREACHABLE", e))(be || {});
8
+ class ke extends we {
9
+ constructor(t, n, o) {
10
+ super(n, !1, o), this.category = t, this.name = "AssertionError";
11
+ }
12
+ }
13
+ function Zt(e, t, n) {
14
+ return e;
15
+ }
16
+ function en(e) {
17
+ return e;
18
+ }
19
+ function We(e, t) {
20
+ throw new ke(
21
+ be.ASSERTION_FAIL_UNREACHABLE,
22
+ `Unhandled ${t}: ${String(e)}`
23
+ );
24
+ }
25
+ var m = /* @__PURE__ */ ((e) => (e.EID_MAX_INDEX_OVERFLOW = "EID_MAX_INDEX_OVERFLOW", e.EID_MAX_GEN_OVERFLOW = "EID_MAX_GEN_OVERFLOW", e.COMPONENT_NOT_REGISTERED = "COMPONENT_NOT_REGISTERED", e.COMPONENT_LIMIT_EXCEEDED = "COMPONENT_LIMIT_EXCEEDED", e.ENTITY_NOT_ALIVE = "ENTITY_NOT_ALIVE", e.CIRCULAR_SYSTEM_DEPENDENCY = "CIRCULAR_SYSTEM_DEPENDENCY", e.DUPLICATE_SYSTEM = "DUPLICATE_SYSTEM", e.UNKNOWN_PHASE = "UNKNOWN_PHASE", e.CIRCULAR_PHASE_DEPENDENCY = "CIRCULAR_PHASE_DEPENDENCY", e.ARCHETYPE_NOT_FOUND = "ARCHETYPE_NOT_FOUND", e.RESOURCE_NOT_REGISTERED = "RESOURCE_NOT_REGISTERED", e.RESOURCE_ALREADY_REGISTERED = "RESOURCE_ALREADY_REGISTERED", e.EVENT_ALREADY_REGISTERED = "EVENT_ALREADY_REGISTERED", e.EVENT_NOT_REGISTERED = "EVENT_NOT_REGISTERED", e.INVALID_EVENT_ID = "INVALID_EVENT_ID", e.FIELD_NOT_REGISTERED = "FIELD_NOT_REGISTERED", e.RELATION_NOT_REGISTERED = "RELATION_NOT_REGISTERED", e.RELATION_MODE_INVALID = "RELATION_MODE_INVALID", e.RELATION_MODE_MISMATCH = "RELATION_MODE_MISMATCH", e.RELATION_CYCLE = "RELATION_CYCLE", e.SPARSE_CACHE_KEY_OVERFLOW = "SPARSE_CACHE_KEY_OVERFLOW", e.SPARSE_QUERY_DENSE_PATH = "SPARSE_QUERY_DENSE_PATH", e.QUERY_TERM_DENSE_PATH = "QUERY_TERM_DENSE_PATH", e.HIERARCHY_ALREADY_SET = "HIERARCHY_ALREADY_SET", e.HIERARCHY_INVALID_MAX_DEPTH = "HIERARCHY_INVALID_MAX_DEPTH", e.OBSERVER_NON_CONVERGENT = "OBSERVER_NON_CONVERGENT", e.OBSERVER_INVALID_CONFIG = "OBSERVER_INVALID_CONFIG", e.OBSERVER_ONSET_EMIT = "OBSERVER_ONSET_EMIT", e.ROW_TICKS_NOT_TRACKED = "ROW_TICKS_NOT_TRACKED", e.INVALID_FIXED_TIMESTEP = "INVALID_FIXED_TIMESTEP", e.INVALID_MAX_FIXED_STEPS = "INVALID_MAX_FIXED_STEPS", e.INVALID_RECORDER_SCHEDULE = "INVALID_RECORDER_SCHEDULE", e.EMPTY_ARCHETYPE_MATERIALIZE = "EMPTY_ARCHETYPE_MATERIALIZE", e.COMPONENT_INDEX_INVARIANT = "COMPONENT_INDEX_INVARIANT", e.ARCHETYPE_ROW_INVARIANT = "ARCHETYPE_ROW_INVARIANT", e.OPTIONAL_TERM_NOT_DECLARED = "OPTIONAL_TERM_NOT_DECLARED", e.QUERY_ACCESS_UNDECLARED = "QUERY_ACCESS_UNDECLARED", e.ACCESS_UNDECLARED = "ACCESS_UNDECLARED", e.QUERY_NOT_SINGLETON = "QUERY_NOT_SINGLETON", e.INVALID_RUN_CONDITION = "INVALID_RUN_CONDITION", e.SYSTEM_FN_ARITY = "SYSTEM_FN_ARITY", e.INVALID_SYSTEM_ID = "INVALID_SYSTEM_ID", e.PARTITION_APPEND_NEEDS_ENTITY_ROW = "PARTITION_APPEND_NEEDS_ENTITY_ROW", e.PARTITION_BULK_INTO_DISABLED = "PARTITION_BULK_INTO_DISABLED", e.STRUCTURAL_DURING_ITERATION = "STRUCTURAL_DURING_ITERATION", e.BACKEND_ALREADY_ATTACHED = "BACKEND_ALREADY_ATTACHED", e.DETERMINISM_DISABLED = "DETERMINISM_DISABLED", e.SNAPSHOT_RESTORE_FAILED = "SNAPSHOT_RESTORE_FAILED", e.NON_DETERMINISTIC_COLUMN_TYPE = "NON_DETERMINISTIC_COLUMN_TYPE", e.INVALID_MEMORY_OPTIONS = "INVALID_MEMORY_OPTIONS", e.STORE_CAP_EXCEEDED = "STORE_CAP_EXCEEDED", e.REGION_NOT_DECLARED = "REGION_NOT_DECLARED", e.COMMAND_LOG_TAG_COLLISION = "COMMAND_LOG_TAG_COLLISION", e.INVALID_FRAME_STEP = "INVALID_FRAME_STEP", e.INVALID_TEMPLATE = "INVALID_TEMPLATE", e.PLUGIN_NOT_INSTALLED = "PLUGIN_NOT_INSTALLED", e.PLUGIN_ALREADY_INSTALLED = "PLUGIN_ALREADY_INSTALLED", e.PLUGIN_SURFACE_COLLISION = "PLUGIN_SURFACE_COLLISION", e.WORKERS_ATTACHED = "WORKERS_ATTACHED", e.WORKERS_NEED_SHARED_BACKING = "WORKERS_NEED_SHARED_BACKING", e.WORKERS_HOST_CANNOT_PARK = "WORKERS_HOST_CANNOT_PARK", e.WORKERS_COUNT_INVALID = "WORKERS_COUNT_INVALID", e.WORKERS_ENTRY_UNREACHABLE = "WORKERS_ENTRY_UNREACHABLE", e.PARALLEL_ACCESS = "PARALLEL_ACCESS", e.PARALLEL_KERNEL_MODULE = "PARALLEL_KERNEL_MODULE", e.PARALLEL_KERNEL_FAILED = "PARALLEL_KERNEL_FAILED", e))(m || {});
26
+ class E extends we {
27
+ constructor(t, n, o) {
28
+ super(n ?? t, !0, o), this.category = t, this.name = "ECSError";
29
+ }
30
+ }
31
+ function tn(e) {
32
+ return e instanceof E;
33
+ }
34
+ class nn extends E {
35
+ constructor(t) {
36
+ super("SNAPSHOT_RESTORE_FAILED", t), this.name = "ECSRestoreError";
37
+ }
38
+ }
39
+ const on = -1, sn = -1, rn = Object.freeze(/* @__PURE__ */ Object.create(null)), an = 2654435769, cn = 1367130551, Xe = 1024, dn = 0, Ke = 31, _n = 1 / 60, ln = 4, un = 0, F = 20, Le = (1 << F) - 1, ze = Le, je = Ke - F, oe = (1 << je) - 1, En = oe, mn = oe - 1, fn = oe << F | ze, An = (e, t) => t << F | e, de = (e) => e & Le, _e = (e) => e >> F, In = (e, t, n) => new E(
40
+ m.ENTITY_NOT_ALIVE,
41
+ `${e}: entity ${t} (index ${de(t)}, generation ${_e(
42
+ t
43
+ )}) is not alive${n ? `, ${n}` : ""}. It was destroyed, never created, or the handle is stale. Guard with isAlive() first`,
44
+ { entity: t, index: de(t), generation: _e(t), op: e }
45
+ ), se = /* @__PURE__ */ new WeakMap();
46
+ function Tn(e, t) {
47
+ se.set(e, t);
48
+ }
49
+ function pn(e) {
50
+ return se.get(e);
51
+ }
52
+ function Qe(e) {
53
+ const t = se.get(e);
54
+ return t !== void 0 ? `'${t}' (component ${e.id})` : `component ${e.id}`;
55
+ }
56
+ const qe = 827148627, Je = 1, Re = 4, Ze = 52, g = {
57
+ magic: 0,
58
+ sim_abi_version: 4,
59
+ view_stamp: 8,
60
+ capacity: 12,
61
+ archetype_count: 16,
62
+ layout_descriptor_off: 20,
63
+ command_ring_off: 24,
64
+ action_ring_off: 28,
65
+ entity_index_off: 32,
66
+ event_ring_off: 36,
67
+ region_table_off: 40,
68
+ region_table_count: 44,
69
+ bindings_off: 48
70
+ }, V = 12, C = {
71
+ region_id: 0,
72
+ byte_offset: 4,
73
+ byte_length: 8
74
+ }, Ce = 16, x = {
75
+ component_id: 0,
76
+ field_id: 2,
77
+ type_tag: 4,
78
+ byte_off: 8,
79
+ stride: 12
80
+ }, Pe = 40, P = {
81
+ archetype_id: 0,
82
+ component_mask: 4,
83
+ row_count: 20,
84
+ row_capacity: 24,
85
+ column_count: 28,
86
+ enabled_count: 32,
87
+ entity_ids_off: 36
88
+ }, A = {
89
+ u8: 0,
90
+ i8: 1,
91
+ u16: 2,
92
+ i16: 3,
93
+ u32: 4,
94
+ i32: 5,
95
+ f32: 6,
96
+ f64: 7
97
+ }, le = Object.freeze({
98
+ [A.u8]: 1,
99
+ [A.i8]: 1,
100
+ [A.u16]: 2,
101
+ [A.i16]: 2,
102
+ [A.u32]: 4,
103
+ [A.i32]: 4,
104
+ [A.f32]: 4,
105
+ [A.f64]: 8
106
+ }), hn = {
107
+ u8: A.u8,
108
+ i8: A.i8,
109
+ u16: A.u16,
110
+ i16: A.i16,
111
+ u32: A.u32,
112
+ i32: A.i32,
113
+ f32: A.f32,
114
+ f64: A.f64
115
+ };
116
+ function et(e, t, n) {
117
+ e.setUint16(t + x.component_id, n.componentId, !0), e.setUint16(t + x.field_id, n.fieldId, !0), e.setUint8(t + x.type_tag, n.typeTag), e.setUint32(t + x.byte_off, n.byteOff, !0), e.setUint16(t + x.stride, n.stride, !0);
118
+ }
119
+ const gn = Re * 32;
120
+ function Me(e, t = Pe) {
121
+ return t + e * Ce;
122
+ }
123
+ function tt(e, t, n) {
124
+ e.setUint32(t + P.archetype_id, n.archetypeId, !0);
125
+ for (let s = 0; s < Re; s++)
126
+ e.setUint32(
127
+ t + P.component_mask + s * 4,
128
+ n.componentMask[s] ?? 0,
129
+ !0
130
+ );
131
+ e.setUint32(t + P.row_count, n.rowCount, !0), e.setUint32(t + P.row_capacity, n.rowCapacity, !0), e.setUint32(t + P.column_count, n.columns.length, !0), e.setUint32(t + P.enabled_count, n.enabledCount, !0), e.setUint32(t + P.entity_ids_off, 0, !0);
132
+ let o = t + Pe;
133
+ for (let s = 0; s < n.columns.length; s++)
134
+ et(e, o, n.columns[s]), o += Ce;
135
+ return o;
136
+ }
137
+ function nt(e, t, n) {
138
+ let o = t;
139
+ for (let s = 0; s < n.length; s++)
140
+ o = tt(e, o, n[s]);
141
+ return o;
142
+ }
143
+ function ot(e) {
144
+ let t = 0;
145
+ for (let n = 0; n < e.length; n++)
146
+ t += Me(e[n].columns.length);
147
+ return t;
148
+ }
149
+ function st(e, t) {
150
+ e.setUint32(g.magic, t.magic, !0), e.setUint32(g.sim_abi_version, t.simAbiVersion, !0), e.setUint32(g.view_stamp, t.viewStamp, !0), e.setUint32(g.capacity, t.capacity, !0), e.setUint32(g.archetype_count, t.archetypeCount, !0), e.setUint32(g.layout_descriptor_off, t.layoutDescriptorOff, !0), e.setUint32(g.command_ring_off, t.commandRingOff, !0), e.setUint32(g.action_ring_off, t.actionRingOff, !0), e.setUint32(g.entity_index_off, t.entityIndexOff, !0), e.setUint32(g.event_ring_off, t.eventRingOff, !0), e.setUint32(g.region_table_off, t.regionTableOff, !0), e.setUint32(g.region_table_count, t.regionTableCount, !0), e.setUint32(g.bindings_off, t.bindingsOff, !0);
151
+ }
152
+ const Ue = 16, U = 16, Nn = 256, O = {
153
+ write_head: 0,
154
+ read_head: 4,
155
+ capacity_slots: 8,
156
+ overflow_flag: 12
157
+ }, re = 0;
158
+ function ue(e) {
159
+ return Ue + e * U;
160
+ }
161
+ function rt(e) {
162
+ return e > 0 && (e & e - 1) === 0;
163
+ }
164
+ class b extends Error {
165
+ constructor(t) {
166
+ super(t), this.name = "CommandRingError";
167
+ }
168
+ }
169
+ function it(e, t, n) {
170
+ if (!rt(n))
171
+ throw new b(
172
+ `command ring capacity_slots must be a positive power of two (got ${n})`
173
+ );
174
+ e.setUint32(t + O.write_head, 0, !0), e.setUint32(t + O.read_head, 0, !0), e.setUint32(t + O.capacity_slots, n, !0), e.setUint32(t + O.overflow_flag, 0, !0);
175
+ }
176
+ function at(e, t) {
177
+ return e.getUint32(t + O.write_head, !0);
178
+ }
179
+ function ct(e, t) {
180
+ return e.getUint32(t + O.read_head, !0);
181
+ }
182
+ function dt(e, t) {
183
+ return e.getUint32(t + O.capacity_slots, !0);
184
+ }
185
+ function _t(e, t, n) {
186
+ if (n.byteLength !== U - 1)
187
+ throw new b(
188
+ `outPayload must be ${U - 1} bytes (got ${n.byteLength})`
189
+ );
190
+ const o = at(e, t), s = ct(e, t);
191
+ if (o === s) return re;
192
+ const i = dt(e, t), _ = s & i - 1, d = t + Ue + _ * U, c = e.getUint8(d), l = new Uint8Array(
193
+ e.buffer,
194
+ e.byteOffset + d + 1,
195
+ U - 1
196
+ );
197
+ return n.set(l), e.setUint32(t + O.read_head, s + 1 >>> 0, !0), c;
198
+ }
199
+ function lt(e, t, n) {
200
+ let o = 0;
201
+ const s = new Uint8Array(U - 1);
202
+ for (; ; ) {
203
+ const i = _t(e, t, s);
204
+ if (i === re) return o;
205
+ n(i, s.slice()), o++;
206
+ }
207
+ }
208
+ const z = 16, R = 12, k = {
209
+ length: 0,
210
+ capacity: 4
211
+ // 8..16: pad to 16-byte alignment so the i32 arrays start aligned.
212
+ }, Ee = 1 << 20;
213
+ function me(e) {
214
+ if (e < 0 || !Number.isInteger(e))
215
+ throw new ve(
216
+ `entity index capacity must be a non-negative integer (got ${e})`
217
+ );
218
+ return z + e * R;
219
+ }
220
+ function ut(e) {
221
+ return e + z;
222
+ }
223
+ function Et(e, t) {
224
+ return e + z + t * 4;
225
+ }
226
+ function mt(e, t) {
227
+ return e + z + t * 8;
228
+ }
229
+ class ve extends Error {
230
+ constructor(t) {
231
+ super(t), this.name = "EntityIndexError";
232
+ }
233
+ }
234
+ function ft(e, t, n) {
235
+ if (n < 0 || !Number.isInteger(n))
236
+ throw new ve(
237
+ `entity index capacity must be a non-negative integer (got ${n})`
238
+ );
239
+ e.setUint32(t + k.length, 0, !0), e.setUint32(t + k.capacity, n, !0);
240
+ }
241
+ function yn(e, t, n) {
242
+ return {
243
+ generations: new Int32Array(e, ut(t), n),
244
+ archetypes: new Int32Array(e, Et(t, n), n),
245
+ rows: new Int32Array(e, mt(t, n), n)
246
+ };
247
+ }
248
+ const At = 16, It = 16, Sn = 256, v = {
249
+ write_head: 0,
250
+ read_head: 4,
251
+ capacity_slots: 8,
252
+ overflow_flag: 12
253
+ };
254
+ function fe(e) {
255
+ return At + e * It;
256
+ }
257
+ function Tt(e) {
258
+ return e > 0 && (e & e - 1) === 0;
259
+ }
260
+ class pt extends Error {
261
+ constructor(t) {
262
+ super(t), this.name = "EventRingError";
263
+ }
264
+ }
265
+ function ht(e, t, n) {
266
+ if (!Tt(n))
267
+ throw new pt(
268
+ `event ring capacity_slots must be a positive power of two (got ${n})`
269
+ );
270
+ e.setUint32(t + v.write_head, 0, !0), e.setUint32(t + v.read_head, 0, !0), e.setUint32(t + v.capacity_slots, n, !0), e.setUint32(t + v.overflow_flag, 0, !0);
271
+ }
272
+ const gt = 16, Nt = 16, Dn = 256, $ = {
273
+ write_head: 0,
274
+ read_head: 4,
275
+ capacity_slots: 8,
276
+ overflow_flag: 12
277
+ }, yt = $.write_head / 4, St = $.read_head / 4, Dt = $.capacity_slots / 4, Ot = $.overflow_flag / 4;
278
+ function wt(e, t) {
279
+ return new Int32Array(e.buffer, e.byteOffset + t, 4);
280
+ }
281
+ function Ae(e) {
282
+ return gt + e * Nt;
283
+ }
284
+ function bt(e) {
285
+ return e > 0 && (e & e - 1) === 0;
286
+ }
287
+ class Ie extends Error {
288
+ constructor(t) {
289
+ super(t), this.name = "ActionRingError";
290
+ }
291
+ }
292
+ function Lt(e, t, n) {
293
+ if (!bt(n))
294
+ throw new Ie(
295
+ `action ring capacity_slots must be a positive power of two (got ${n})`
296
+ );
297
+ if ((e.byteOffset + t) % 4 !== 0)
298
+ throw new Ie(
299
+ `action ring header must be 4-byte aligned for Atomics (view.byteOffset ${e.byteOffset} + ringOff ${t} is not a multiple of 4)`
300
+ );
301
+ const o = wt(e, t);
302
+ Atomics.store(o, yt, 0), Atomics.store(o, St, 0), Atomics.store(o, Dt, n), Atomics.store(o, Ot, 0);
303
+ }
304
+ const H = [
305
+ {
306
+ name: "command_ring",
307
+ headerOff: "command_ring_off",
308
+ sizeFromOptions: (e) => e.commandRingCapacitySlots !== void 0 ? ue(e.commandRingCapacitySlots) : 0,
309
+ init: (e, t, n) => it(e, t, n.commandRingCapacitySlots),
310
+ regionBytes: (e, t) => ue(e.getUint32(t + O.capacity_slots, !0)),
311
+ readOptions: (e, t, n) => {
312
+ n.commandRingCapacitySlots = e.getUint32(
313
+ t + O.capacity_slots,
314
+ !0
315
+ );
316
+ }
317
+ },
318
+ {
319
+ name: "entity_index",
320
+ headerOff: "entity_index_off",
321
+ sizeFromOptions: (e) => e.entityIndexCapacity !== void 0 ? me(e.entityIndexCapacity) : 0,
322
+ init: (e, t, n) => ft(e, t, n.entityIndexCapacity),
323
+ regionBytes: (e, t) => me(e.getUint32(t + k.capacity, !0)),
324
+ readOptions: (e, t, n) => {
325
+ n.entityIndexCapacity = e.getUint32(t + k.capacity, !0);
326
+ }
327
+ },
328
+ {
329
+ name: "event_ring",
330
+ headerOff: "event_ring_off",
331
+ sizeFromOptions: (e) => e.eventRingCapacitySlots !== void 0 ? fe(e.eventRingCapacitySlots) : 0,
332
+ init: (e, t, n) => ht(e, t, n.eventRingCapacitySlots),
333
+ regionBytes: (e, t) => fe(e.getUint32(t + v.capacity_slots, !0)),
334
+ readOptions: (e, t, n) => {
335
+ n.eventRingCapacitySlots = e.getUint32(
336
+ t + v.capacity_slots,
337
+ !0
338
+ );
339
+ }
340
+ },
341
+ {
342
+ name: "action_ring",
343
+ headerOff: "action_ring_off",
344
+ sizeFromOptions: (e) => e.actionRingCapacitySlots !== void 0 ? Ae(e.actionRingCapacitySlots) : 0,
345
+ init: (e, t, n) => Lt(e, t, n.actionRingCapacitySlots),
346
+ regionBytes: (e, t) => Ae(e.getUint32(t + $.capacity_slots, !0)),
347
+ readOptions: (e, t, n) => {
348
+ n.actionRingCapacitySlots = e.getUint32(
349
+ t + $.capacity_slots,
350
+ !0
351
+ );
352
+ }
353
+ }
354
+ ];
355
+ class G extends Error {
356
+ constructor(t) {
357
+ super(t), this.name = "RegionRegistryError";
358
+ }
359
+ }
360
+ function Be(e) {
361
+ return e * V;
362
+ }
363
+ function ie(e, t) {
364
+ const n = e.getUint32(g.region_table_count, !0);
365
+ if (t + Be(n) > e.byteLength)
366
+ throw new G(
367
+ `region table of ${n} entries at byte ${t} overruns the buffer (${e.byteLength} bytes)`
368
+ );
369
+ return n;
370
+ }
371
+ function Rt(e) {
372
+ const t = /* @__PURE__ */ new Set();
373
+ for (let n = 0; n < e.length; n++) {
374
+ const o = e[n];
375
+ if (!Number.isInteger(o.id) || o.id <= 0)
376
+ throw new G(
377
+ `region "${o.name}" has invalid id ${o.id}, region ids must be positive integers (0 is the absent sentinel)`
378
+ );
379
+ if (t.has(o.id))
380
+ throw new G(
381
+ `duplicate region id ${o.id} (region "${o.name}"), ids must be distinct within a consumer's region set`
382
+ );
383
+ if (t.add(o.id), !Number.isInteger(o.bytes) || o.bytes <= 0)
384
+ throw new G(
385
+ `region "${o.name}" (id ${o.id}) has invalid byte size ${o.bytes}, must be a positive integer`
386
+ );
387
+ }
388
+ }
389
+ function Ct(e, t, n) {
390
+ e.setUint32(t + C.region_id, n.regionId, !0), e.setUint32(t + C.byte_offset, n.byteOffset, !0), e.setUint32(t + C.byte_length, n.byteLength, !0);
391
+ }
392
+ function $e(e, t) {
393
+ return {
394
+ regionId: e.getUint32(t + C.region_id, !0),
395
+ byteOffset: e.getUint32(t + C.byte_offset, !0),
396
+ byteLength: e.getUint32(t + C.byte_length, !0)
397
+ };
398
+ }
399
+ function Pt(e, t, n) {
400
+ for (let o = 0; o < n.length; o++)
401
+ Ct(e, t + o * V, n[o]);
402
+ }
403
+ function Mt(e, t, n) {
404
+ const o = new Array(n);
405
+ for (let s = 0; s < n; s++)
406
+ o[s] = $e(e, t + s * V);
407
+ return o;
408
+ }
409
+ function On(e) {
410
+ const t = e.getUint32(g.region_table_off, !0);
411
+ if (t === 0) return [];
412
+ const n = ie(e, t);
413
+ return Mt(e, t, n);
414
+ }
415
+ function wn(e, t) {
416
+ const n = e.getUint32(g.region_table_off, !0);
417
+ if (n === 0) return 0;
418
+ const o = ie(e, n);
419
+ for (let s = 0; s < o; s++) {
420
+ const i = n + s * V;
421
+ if (e.getUint32(i + C.region_id, !0) === t)
422
+ return e.getUint32(i + C.byte_offset, !0);
423
+ }
424
+ return 0;
425
+ }
426
+ function bn(e, t) {
427
+ const n = e.getUint32(g.region_table_off, !0);
428
+ if (n === 0) return null;
429
+ const o = ie(e, n);
430
+ for (let s = 0; s < o; s++) {
431
+ const i = $e(e, n + s * V);
432
+ if (i.regionId === t) return i;
433
+ }
434
+ return null;
435
+ }
436
+ function Ut(e, t) {
437
+ return e << 16 | t;
438
+ }
439
+ const ae = 2 ** 31;
440
+ class Ye extends Error {
441
+ constructor(t) {
442
+ super(
443
+ `SAB column layout offset ${t} reaches or exceeds the 2³¹ (${ae}-byte) ceiling. Past 2 GiB the signed-32-bit bitwise alignment math wraps to a negative or misaligned offset. This is a structural limit independent of the allocator cap, so a single store cannot back more than 2 GiB of column data.`
444
+ ), this.name = "StoreLayoutOverflowError";
445
+ }
446
+ }
447
+ function xe(e, t) {
448
+ if (e + t > ae)
449
+ throw new Ye(e);
450
+ return e + (t - 1) & ~(t - 1);
451
+ }
452
+ function vt(e, t, n, o, s) {
453
+ const i = t + o;
454
+ switch (n) {
455
+ case A.u8:
456
+ return new Uint8Array(e, i, s);
457
+ case A.i8:
458
+ return new Int8Array(e, i, s);
459
+ case A.u16:
460
+ return new Uint16Array(e, i, s);
461
+ case A.i16:
462
+ return new Int16Array(e, i, s);
463
+ case A.u32:
464
+ return new Uint32Array(e, i, s);
465
+ case A.i32:
466
+ return new Int32Array(e, i, s);
467
+ case A.f32:
468
+ return new Float32Array(e, i, s);
469
+ case A.f64:
470
+ return new Float64Array(e, i, s);
471
+ }
472
+ }
473
+ function Bt(e, t, n = 0) {
474
+ const s = ot(
475
+ e.map((d) => ({
476
+ archetypeId: d.archetypeId,
477
+ componentMask: d.componentMask,
478
+ rowCount: 0,
479
+ enabledCount: 0,
480
+ rowCapacity: d.rowCapacity,
481
+ columns: d.columns.map((c) => ({
482
+ componentId: c.componentId,
483
+ fieldId: c.fieldId,
484
+ typeTag: c.typeTag,
485
+ byteOff: 0,
486
+ stride: le[c.typeTag]
487
+ }))
488
+ }))
489
+ ) + n;
490
+ let i = t + s;
491
+ const _ = new Array(e.length);
492
+ for (let d = 0; d < e.length; d++) {
493
+ const c = e[d], l = new Array(c.columns.length);
494
+ for (let f = 0; f < c.columns.length; f++) {
495
+ const p = c.columns[f], T = le[p.typeTag];
496
+ i = xe(i, T), l[f] = {
497
+ componentId: p.componentId,
498
+ fieldId: p.fieldId,
499
+ typeTag: p.typeTag,
500
+ byteOff: i,
501
+ stride: T
502
+ }, i += T * c.rowCapacity;
503
+ }
504
+ _[d] = {
505
+ archetypeId: c.archetypeId,
506
+ componentMask: c.componentMask,
507
+ rowCount: 0,
508
+ enabledCount: 0,
509
+ rowCapacity: c.rowCapacity,
510
+ columns: l
511
+ };
512
+ }
513
+ if (i > ae)
514
+ throw new Ye(i);
515
+ return { descriptors: _, totalBytes: i, regionBytes: s };
516
+ }
517
+ const W = 16;
518
+ function $t(e) {
519
+ if (!Number.isInteger(e) || e < 0)
520
+ throw new RangeError(`createColumnStore: storeBase must be an integer >= 0, got ${e}`);
521
+ if (e % W !== 0)
522
+ throw new RangeError(
523
+ `createColumnStore: storeBase must be a multiple of ${W}, got ${e}`
524
+ );
525
+ }
526
+ function Yt(e) {
527
+ let t = 0;
528
+ for (const [, n] of e) t += Me(n.columnsInOrder.length);
529
+ return t;
530
+ }
531
+ function Ln(e) {
532
+ const t = e;
533
+ return typeof t._regionBytes == "number" && typeof t._allocator == "function" && typeof t._reservedDescriptorBytes == "number";
534
+ }
535
+ function Rn(e, t = Ve, n = {}) {
536
+ const o = n.storeBase ?? 0;
537
+ $t(o);
538
+ const s = {};
539
+ let i = Ze;
540
+ for (let h = 0; h < H.length; h++) {
541
+ const w = H[h], Y = w.sizeFromOptions(n);
542
+ s[w.headerOff] = Y === 0 ? 0 : i, i += Y;
543
+ }
544
+ const _ = n.regions ?? [];
545
+ Rt(_);
546
+ const d = _.length, c = d > 0 ? i : 0;
547
+ i += Be(d);
548
+ const l = new Array(d);
549
+ for (let h = 0; h < _.length; h++) {
550
+ const w = _[h];
551
+ l[h] = { regionId: w.id, byteOffset: i, byteLength: w.bytes }, i += w.bytes;
552
+ }
553
+ const f = n.bindingsRegionBytes ?? 0, p = f === 0 ? 0 : i;
554
+ i += f;
555
+ const T = i, { descriptors: S, totalBytes: N, regionBytes: a } = Bt(
556
+ e,
557
+ T,
558
+ n.reservedDescriptorBytes ?? 0
559
+ ), r = t(o + N), u = new DataView(r, o), D = {
560
+ magic: qe,
561
+ simAbiVersion: Je,
562
+ viewStamp: 0,
563
+ capacity: N,
564
+ archetypeCount: e.length,
565
+ layoutDescriptorOff: T,
566
+ bindingsOff: p,
567
+ regionTableOff: c,
568
+ regionTableCount: d,
569
+ // `regionOffsets` stays keyed by the snake ABI field names (it also indexes
570
+ // `STORE_HEADER_OFFSETS`). Map its 4 entries onto the camelCase header fields.
571
+ commandRingOff: s.command_ring_off,
572
+ entityIndexOff: s.entity_index_off,
573
+ eventRingOff: s.event_ring_off,
574
+ actionRingOff: s.action_ring_off
575
+ };
576
+ st(u, D), f > 0 && new Uint8Array(r, o + p, f).fill(0);
577
+ for (let h = 0; h < H.length; h++) {
578
+ const w = H[h], Y = s[w.headerOff];
579
+ Y !== 0 && w.init(u, Y, n);
580
+ }
581
+ c !== 0 && Pt(u, c, l);
582
+ for (let h = 0; h < _.length; h++)
583
+ _[h].init(u, l[h].byteOffset);
584
+ nt(u, T, S);
585
+ const y = xt(r, o, S);
586
+ return {
587
+ buffer: r,
588
+ view: u,
589
+ header: D,
590
+ storeBase: o,
591
+ archetypes: y,
592
+ _regionBytes: a,
593
+ _allocator: t,
594
+ // Carry the headroom policy with the store so the realloc slow path
595
+ // (`optionsFromOld`) can re-reserve the same margin.
596
+ _reservedDescriptorBytes: n.reservedDescriptorBytes ?? 0,
597
+ _usedDescriptorBytes: Yt(y)
598
+ };
599
+ }
600
+ function xt(e, t, n) {
601
+ const o = /* @__PURE__ */ new Map();
602
+ for (let s = 0; s < n.length; s++) {
603
+ const i = n[s], _ = new Array(i.columns.length), d = /* @__PURE__ */ new Map();
604
+ for (let c = 0; c < i.columns.length; c++) {
605
+ const l = i.columns[c], f = {
606
+ componentId: l.componentId,
607
+ fieldId: l.fieldId,
608
+ typeTag: l.typeTag,
609
+ byteOff: l.byteOff,
610
+ stride: l.stride,
611
+ view: vt(e, t, l.typeTag, l.byteOff, i.rowCapacity)
612
+ };
613
+ _[c] = f, d.set(Ut(l.componentId, l.fieldId), f);
614
+ }
615
+ o.set(i.archetypeId, {
616
+ archetypeId: i.archetypeId,
617
+ componentMask: i.componentMask,
618
+ rowCapacity: i.rowCapacity,
619
+ columns: d,
620
+ columnsInOrder: _
621
+ });
622
+ }
623
+ return o;
624
+ }
625
+ const Te = 2147483647, pe = /* @__PURE__ */ new WeakMap();
626
+ function Ft(e) {
627
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
628
+ for (let a = 0; a < e.writes.length; a++) {
629
+ const r = e.writes[a].id;
630
+ n.add(r), t.add(r), o.add(r);
631
+ }
632
+ for (let a = 0; a < e.reads.length; a++)
633
+ t.add(e.reads[a].id);
634
+ for (let a = 0; a < e.spawns.length; a++) {
635
+ const r = e.spawns[a];
636
+ for (let u = 0; u < r.length; u++)
637
+ o.add(r[u].id);
638
+ }
639
+ for (let a = 0; a < e.transitions.length; a++) {
640
+ const r = e.transitions[a];
641
+ if (r.add)
642
+ for (let u = 0; u < r.add.length; u++)
643
+ o.add(r.add[u].id);
644
+ if (r.remove)
645
+ for (let u = 0; u < r.remove.length; u++)
646
+ s.add(r.remove[u].id);
647
+ }
648
+ for (let a = 0; a < e.despawns.length; a++)
649
+ s.add(e.despawns[a].id);
650
+ for (let a = 0; a < e.resourceReads.length; a++)
651
+ i.add(e.resourceReads[a]);
652
+ for (let a = 0; a < e.resourceWrites.length; a++) {
653
+ const r = e.resourceWrites[a];
654
+ _.add(r), i.add(r);
655
+ }
656
+ const p = e.sparseWrites;
657
+ if (p !== void 0)
658
+ for (let a = 0; a < p.length; a++) {
659
+ const r = p[a];
660
+ c.add(r), d.add(r);
661
+ }
662
+ const T = e.sparseReads;
663
+ if (T !== void 0)
664
+ for (let a = 0; a < T.length; a++) d.add(T[a]);
665
+ const S = e.relationWrites;
666
+ if (S !== void 0)
667
+ for (let a = 0; a < S.length; a++) {
668
+ const r = S[a];
669
+ f.add(r), l.add(r);
670
+ }
671
+ const N = e.relationReads;
672
+ if (N !== void 0)
673
+ for (let a = 0; a < N.length; a++) l.add(N[a]);
674
+ return {
675
+ reads: t,
676
+ writes: n,
677
+ addAllowed: o,
678
+ removeAllowed: s,
679
+ hasDespawns: e.despawns.length > 0,
680
+ resourceReads: i,
681
+ resourceWrites: _,
682
+ sparseReads: d,
683
+ sparseWrites: c,
684
+ relationReads: l,
685
+ relationWrites: f
686
+ };
687
+ }
688
+ function Vt(e) {
689
+ const t = pe.get(e);
690
+ if (t !== void 0) return t;
691
+ const n = Ft(e);
692
+ return pe.set(e, n), n;
693
+ }
694
+ const he = /* @__PURE__ */ new WeakMap();
695
+ function Ht(e) {
696
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
697
+ if (e.reads !== void 0)
698
+ for (let o = 0; o < e.reads.length; o++) t.add(e.reads[o].id);
699
+ if (e.resourceReads !== void 0)
700
+ for (let o = 0; o < e.resourceReads.length; o++)
701
+ n.add(e.resourceReads[o]);
702
+ return {
703
+ reads: t,
704
+ writes: /* @__PURE__ */ new Set(),
705
+ addAllowed: /* @__PURE__ */ new Set(),
706
+ removeAllowed: /* @__PURE__ */ new Set(),
707
+ hasDespawns: !1,
708
+ resourceReads: n,
709
+ resourceWrites: /* @__PURE__ */ new Set(),
710
+ sparseReads: /* @__PURE__ */ new Set(),
711
+ sparseWrites: /* @__PURE__ */ new Set(),
712
+ relationReads: /* @__PURE__ */ new Set(),
713
+ relationWrites: /* @__PURE__ */ new Set()
714
+ };
715
+ }
716
+ function Gt(e) {
717
+ const t = he.get(e);
718
+ if (t !== void 0) return t;
719
+ const n = Ht(e);
720
+ return he.set(e, n), n;
721
+ }
722
+ class kt {
723
+ _activeSystem = null;
724
+ _activeSets = null;
725
+ // The label used in violation messages. Tracks `_activeSystem` for a system span,
726
+ // but a run-condition span has no descriptor, only this name, so the
727
+ // failure helpers read the label here rather than off `_activeSystem`.
728
+ _activeName = null;
729
+ // An `_exclusive` system has full world access: every check_* below
730
+ // passes for the whole span. Kept as an explicit flag (rather than leaving
731
+ // `_activeSets` null) so `isActive()` stays truthful inside the span.
732
+ _exclusive = !1;
733
+ enter(t) {
734
+ this._activeSystem = t, this._activeName = t.name ?? `system_${t.id}`, this._exclusive = t.exclusive === !0, this._activeSets = this._exclusive ? null : Vt(t);
735
+ }
736
+ /** Open a reads-only span for a run condition. No descriptor, a
737
+ * condition can gate a whole SystemSet, so it isn't attributable to one
738
+ * system, only its declared `reads` and `resourceReads` and a name for diagnostics.
739
+ * Paired with `leave()`. */
740
+ enterCondition(t) {
741
+ this._activeSystem = null, this._activeName = t.name, this._activeSets = Gt(t);
742
+ }
743
+ leave() {
744
+ this._activeSystem = null, this._activeName = null, this._activeSets = null, this._exclusive = !1;
745
+ }
746
+ isActive() {
747
+ return this._activeSets !== null || this._exclusive;
748
+ }
749
+ /** Current system descriptor, if any. Null during a run-condition span. */
750
+ current() {
751
+ return this._activeSystem;
752
+ }
753
+ assertRead(t) {
754
+ this._activeSets !== null && (this._activeSets.reads.has(t.id) || this._failComponent("read", t, "reads"));
755
+ }
756
+ assertWrite(t) {
757
+ this._activeSets !== null && (this._activeSets.writes.has(t.id) || this._failComponent("write", t, "writes"));
758
+ }
759
+ assertAdd(t) {
760
+ this._activeSets !== null && (this._activeSets.addAllowed.has(t.id) || this._failComponent("addComponent", t, "spawns, transitions.add or writes"));
761
+ }
762
+ assertRemove(t) {
763
+ this._activeSets !== null && (this._activeSets.removeAllowed.has(t.id) || this._failComponent("removeComponent", t, "despawns or transitions.remove"));
764
+ }
765
+ assertDespawn() {
766
+ if (this._activeSets === null || this._activeSets.hasDespawns) return;
767
+ const t = this._activeName;
768
+ throw new E(
769
+ m.ACCESS_UNDECLARED,
770
+ `system '${t}' called despawn but did not declare any despawns. Name the components it removes in 'despawns'`,
771
+ { system: t, op: "despawn" }
772
+ );
773
+ }
774
+ assertResourceRead(t) {
775
+ if (this._activeSets === null) return;
776
+ const n = t;
777
+ this._activeSets.resourceReads.has(n) || this._failResource("read", t, "resourceReads");
778
+ }
779
+ assertResourceWrite(t) {
780
+ if (this._activeSets === null) return;
781
+ const n = t;
782
+ this._activeSets.resourceWrites.has(n) || this._failResource("write", t, "resourceWrites");
783
+ }
784
+ // --- Sparse component and relation checks ---
785
+ // Keyed against the dedicated sparse and relation sets, not the dense
786
+ // `reads` and `writes` sets, the id spaces are disjoint by construction (see
787
+ // file header). `def as unknown as number` recovers the SparseComponentID or
788
+ // the RelationID the branded handle erases to at runtime.
789
+ assertSparseRead(t) {
790
+ if (this._activeSets === null) return;
791
+ const n = t;
792
+ this._activeSets.sparseReads.has(n) || this._failSparse("read", n, "sparseReads");
793
+ }
794
+ assertSparseWrite(t) {
795
+ if (this._activeSets === null) return;
796
+ const n = t;
797
+ this._activeSets.sparseWrites.has(n) || this._failSparse("write", n, "sparseWrites");
798
+ }
799
+ assertRelationRead(t) {
800
+ if (this._activeSets === null) return;
801
+ const n = t;
802
+ this._activeSets.relationReads.has(n) || this._failRelation("read", n, "relationReads");
803
+ }
804
+ assertRelationWrite(t) {
805
+ if (this._activeSets === null) return;
806
+ const n = t;
807
+ this._activeSets.relationWrites.has(n) || this._failRelation("write", n, "relationWrites");
808
+ }
809
+ /** A `(*, T)` wildcard (`Query.forEachRelatedTo`) reads every
810
+ * relation's reverse index, so it can't name a specific relation. It is
811
+ * authorised by the `ANY_RELATION` sentinel in `relationReads`. Honoured here
812
+ * exactly like a per-relation read, only keyed on the reserved sentinel id
813
+ * (which computeSets folds into `relationReads` like any other entry). */
814
+ assertRelationReadAny() {
815
+ this._activeSets !== null && (this._activeSets.relationReads.has(Te) || this._failRelation(
816
+ "(*, T) wildcard read",
817
+ Te,
818
+ "relationReads (as ANY_RELATION)"
819
+ ));
820
+ }
821
+ // --- Optional query-term scope ---
822
+ // The dense iterators of `Query` and `ChangedQuery` push the iterating
823
+ // query's `terms.optionalTerms` list for the span of the callback.
824
+ // `Archetype.getOptionalColumnRead` then verifies the fetched component was
825
+ // declared via `.optional(T)`, the term that authorizes the optional fetch.
826
+ // This is what makes the optional term *consumed* rather than decorative: like
827
+ // `reads:[T]` for required access, `.optional(T)` is the fetch's declaration,
828
+ // checked here in `DEV`. A stack (not a single slot) handles a re-entrant or
829
+ // nested `forEach`. The optional scope is independent of the per-system
830
+ // `enter` and `leave` above, a host-side `ecs.query(...).forEach` outside any
831
+ // system still establishes one. No active scope ⇒ lenient: a manual
832
+ // `query.archetypes` walk can't be attributed to an optional declaration, so it
833
+ // isn't checked, mirroring the unchecked outside-of-system calls in the header.
834
+ //
835
+ // Caveat: the gate always attributes to the innermost active
836
+ // `forEach`. If you nest `forEach` and call `getOptionalColumnRead` on an
837
+ // outer query's archetype inside the inner loop, it is checked against the inner
838
+ // query's terms (a false throw or false pass). Per-query attribution isn't worth
839
+ // the complexity for a dev-only assertion. Iterate one query at a time, or read
840
+ // the outer span before entering the inner loop.
841
+ _optionalScopes = [];
842
+ enterOptionalScope(t) {
843
+ this._optionalScopes.push(t);
844
+ }
845
+ leaveOptionalScope() {
846
+ this._optionalScopes.pop();
847
+ }
848
+ assertOptionalFetch(t) {
849
+ const n = this._optionalScopes.length;
850
+ if (n === 0) return;
851
+ const o = this._optionalScopes[n - 1], s = t.id;
852
+ for (let i = 0; i < o.length; i++)
853
+ if (o[i] === s) return;
854
+ throw new E(
855
+ m.OPTIONAL_TERM_NOT_DECLARED,
856
+ `getOptionalColumnRead fetched optional component ${s} but the iterating query did not declare it. Add .optional(component) to the query before the fetch`
857
+ );
858
+ }
859
+ _failComponent(t, n, o) {
860
+ const s = this._activeName, i = Qe(n);
861
+ throw new E(
862
+ m.ACCESS_UNDECLARED,
863
+ `system '${s}' performed ${t} on ${i} but did not declare it. Add it to '${o}'`,
864
+ { system: s, op: t, component: n.id }
865
+ );
866
+ }
867
+ _failSparse(t, n, o) {
868
+ const s = this._activeName;
869
+ throw new E(
870
+ m.ACCESS_UNDECLARED,
871
+ `system '${s}' performed ${t} on sparse component ${n} but did not declare it. Add it to '${o}'`,
872
+ { system: s, op: t, sparse: n }
873
+ );
874
+ }
875
+ _failRelation(t, n, o) {
876
+ const s = this._activeName;
877
+ throw new E(
878
+ m.ACCESS_UNDECLARED,
879
+ `system '${s}' performed ${t} on relation ${n} but did not declare it. Add it to '${o}'`,
880
+ { system: s, op: t, relation: n }
881
+ );
882
+ }
883
+ _failResource(t, n, o) {
884
+ const s = this._activeName, i = n.description ?? "<unnamed>";
885
+ throw new E(
886
+ m.ACCESS_UNDECLARED,
887
+ `system '${s}' performed resource ${t} on '${i}' but did not declare it. Add the resource key to '${o}'`,
888
+ { system: s, op: t, resource: i }
889
+ );
890
+ }
891
+ }
892
+ const Cn = new kt();
893
+ function Pn(e, t) {
894
+ return new E(
895
+ m.PLUGIN_NOT_INSTALLED,
896
+ `${t} needs the ${e} plugin, which this world did not install. Pass it at construction: ECS.create({ plugins: [${e}()] }), imported from @oasys/oecs/${e}`,
897
+ { plugin: e }
898
+ );
899
+ }
900
+ function Mn(e) {
901
+ return new E(
902
+ m.PLUGIN_ALREADY_INSTALLED,
903
+ `${e} is already installed on this world. Pass each plugin once to ECS.create`,
904
+ { plugin: e }
905
+ );
906
+ }
907
+ var Z = /* @__PURE__ */ ((e) => (e.PRE_STARTUP = "PRE_STARTUP", e.STARTUP = "STARTUP", e.POST_STARTUP = "POST_STARTUP", e.FIXED_UPDATE = "FIXED_UPDATE", e.PRE_UPDATE = "PRE_UPDATE", e.UPDATE = "UPDATE", e.POST_UPDATE = "POST_UPDATE", e))(Z || {});
908
+ function ge(e) {
909
+ if (typeof e != "string") return e.loop;
910
+ switch (e) {
911
+ case "PRE_STARTUP":
912
+ case "STARTUP":
913
+ case "POST_STARTUP":
914
+ return "startup";
915
+ case "FIXED_UPDATE":
916
+ return "fixed";
917
+ case "PRE_UPDATE":
918
+ case "UPDATE":
919
+ case "POST_UPDATE":
920
+ return "update";
921
+ }
922
+ }
923
+ function Ne(e) {
924
+ return typeof e == "string" ? e : e.name;
925
+ }
926
+ const X = 1024, K = 1024 * X, B = 64 * X, ee = B;
927
+ function Un(e, t = 0) {
928
+ if (!Number.isFinite(t) || t < 0)
929
+ throw new E(
930
+ m.INVALID_MEMORY_OPTIONS,
931
+ `storeBaseAbove: extraBytes must be a finite number >= 0, got ${String(t)}`
932
+ );
933
+ const n = e?.__heap_base, o = typeof n == "object" && n !== null && "value" in n ? n.value : n;
934
+ if (typeof o != "number" || !Number.isFinite(o))
935
+ throw new E(
936
+ m.INVALID_MEMORY_OPTIONS,
937
+ `storeBaseAbove: the module exports no numeric '__heap_base', got ${String(o)}. Link with --export=__heap_base, or pass memory.storeBase by hand.`
938
+ );
939
+ const s = Math.ceil((o + t) / B) * B;
940
+ return Math.max(ee, s);
941
+ }
942
+ const q = 256 * K, ye = 3, Wt = 64, Xt = 8, Se = 4 * K, De = (e) => 2 ** Math.ceil(Math.log2(Math.max(1, e))), Kt = (e) => 2 ** Math.floor(Math.log2(Math.max(1, e))), J = (e, t, n) => Math.min(n, Math.max(t, e)), I = (e) => e >= K ? `${(e / K).toFixed(1)} MiB` : e >= X ? `${(e / X).toFixed(0)} KiB` : `${e} B`;
943
+ function zt(e, t) {
944
+ if (e === void 0) return t ? ee : 0;
945
+ if (!Number.isInteger(e) || e < 0)
946
+ throw new E(
947
+ m.INVALID_MEMORY_OPTIONS,
948
+ `memory.storeBase must be an integer >= 0, got ${e}`
949
+ );
950
+ if (e % W !== 0)
951
+ throw new E(
952
+ m.INVALID_MEMORY_OPTIONS,
953
+ `memory.storeBase must be a multiple of ${W}, got ${e}. The alignment keeps every column on its element boundary.`
954
+ );
955
+ if (t && e === 0)
956
+ throw new E(
957
+ m.INVALID_MEMORY_OPTIONS,
958
+ `memory.storeBase is 0, and a header at address 0 is unreadable from a safe build of a WASM module. Pass a storeBase of at least one page (${ee}), above the module's own data.`
959
+ );
960
+ return e;
961
+ }
962
+ function M(e, t) {
963
+ if (!Number.isInteger(t) || t <= 0)
964
+ throw new E(
965
+ m.INVALID_MEMORY_OPTIONS,
966
+ `memory.${e} must be a positive integer (got ${t})`
967
+ );
968
+ }
969
+ const Oe = {
970
+ budget: "{ budget: { entities: N } } → { entities: N }",
971
+ heap: '{ heap: { maxBytes: X } } → { maxBytes: X, backing: "heap" }',
972
+ shared: '{ shared: { maxBytes: X } } → { maxBytes: X, backing: "shared" }',
973
+ wasm: "{ wasm: W } → { backing: { wasm: W } }",
974
+ allocator: "{ allocator: A } → { backing: { allocator: A } }",
975
+ capBytesHint: "{ capBytesHint: X } → { maxBytes: X }"
976
+ };
977
+ function jt(e) {
978
+ const t = Object.prototype.hasOwnProperty, n = Object.keys(Oe).filter((o) => t.call(e, o));
979
+ if (n.length !== 0)
980
+ throw new E(
981
+ m.INVALID_MEMORY_OPTIONS,
982
+ `${n.map((o) => `memory.${o}`).join(" and ")} ${n.length > 1 ? "were" : "was"} removed in 0.6. Sizing and backing are now two independent fields, so every combination of them is expressible. Rewrite as: ` + n.map((o) => Oe[o]).join(". ")
983
+ );
984
+ }
985
+ function vn(e) {
986
+ e !== void 0 && jt(e);
987
+ const t = e?.entities, n = e?.maxBytes, o = e?.columnCapacity, s = e?.backing ?? "heap", i = typeof s == "object" && s.wasm !== void 0, _ = zt(e?.storeBase, i);
988
+ if (o !== void 0 && M("columnCapacity", o), n !== void 0 && M("maxBytes", n), t === void 0) {
989
+ for (const r of ["archetypes", "bytesPerEntity"])
990
+ if (e?.[r] !== void 0)
991
+ throw new E(
992
+ m.INVALID_MEMORY_OPTIONS,
993
+ `memory.${r} shapes the sizing derived from memory.entities, which was not given. Add memory.entities, or drop memory.${r}.`
994
+ );
995
+ }
996
+ let d, c, l = null;
997
+ const f = [];
998
+ if (t !== void 0) {
999
+ const r = e?.archetypes ?? Xt, u = e?.bytesPerEntity ?? Wt;
1000
+ if (M("entities", t), M("archetypes", r), M("bytesPerEntity", u), t > 1 << 20)
1001
+ throw new E(
1002
+ m.INVALID_MEMORY_OPTIONS,
1003
+ `memory.entities=${t} exceeds the EntityID index space (1<<20 = ${1 << 20})`
1004
+ );
1005
+ d = o ?? J(De(Math.ceil(t / r)), 64, 1 << 20), c = J(De(t * 2), 4096, 1 << 20);
1006
+ const D = c * R, y = t * u * ye;
1007
+ l = xe(
1008
+ Math.max(D + y, Se),
1009
+ B
1010
+ ), f.push(
1011
+ `columnCapacity = ${o !== void 0 ? `${d} (pinned)` : `pow2(${t}/${r} per archetype) = ${d}`}`,
1012
+ `entityIndex = pow2(2 × ${t}) = ${c} slots × ${R} B = ${I(D)}`,
1013
+ `columns = ${t} × ${u} B × ${ye} (double+holes headroom) = ${I(y)}`
1014
+ );
1015
+ } else
1016
+ d = o ?? Xe, c = Ee, f.push(
1017
+ `columnCapacity = ${d} (${o !== void 0 ? "pinned" : "default"})`
1018
+ );
1019
+ const p = (r) => J(Kt(r / 4 / R), 4096, Ee), T = t !== void 0 ? n !== void 0 ? "entities+maxBytes" : "entities" : n !== void 0 ? "maxBytes" : "default", S = (r) => n !== void 0 ? `${I(r)} (caller-declared maxBytes; the ${I(l ?? r)} the entity count implies is overridden)` : `align64K(max(index + columns, ${I(Se)} floor)) = ${I(r)}`, N = (r, u, D, y, L) => (t === void 0 && (c = p(r)), {
1020
+ source: u,
1021
+ sizing: T,
1022
+ allocator: D,
1023
+ columnCapacity: d,
1024
+ entityIndexCapacity: c,
1025
+ capBytes: r,
1026
+ storeBase: _,
1027
+ intentLabel: y,
1028
+ budgetEntities: t ?? null,
1029
+ derivation: [
1030
+ ...L,
1031
+ ..._ > 0 ? [`storeBase = ${I(_)}, the store writes nothing below it`] : [],
1032
+ ...f,
1033
+ t === void 0 ? `entityIndex = floor_pow2(cap/4 ÷ ${R} B) = ${c} slots` : `cap = ${S(r)}`
1034
+ ],
1035
+ wasmMemory: null
1036
+ });
1037
+ if (typeof s == "object" && s.wasm !== void 0) {
1038
+ const r = s.wasm;
1039
+ if (r.memory !== void 0) {
1040
+ if (!(r.memory.buffer instanceof SharedArrayBuffer))
1041
+ throw new E(
1042
+ m.INVALID_MEMORY_OPTIONS,
1043
+ "memory.backing.wasm.memory must be constructed with `shared: true`, the SAB substrate requires a SharedArrayBuffer-backed WebAssembly.Memory"
1044
+ );
1045
+ const L = n ?? q;
1046
+ return t === void 0 && (c = p(Math.max(L - _, 0))), {
1047
+ source: "wasm",
1048
+ sizing: T,
1049
+ allocator: ce(r.memory),
1050
+ columnCapacity: d,
1051
+ entityIndexCapacity: c,
1052
+ capBytes: L,
1053
+ storeBase: _,
1054
+ intentLabel: `caller-supplied WebAssembly.Memory (declared cap ${I(L)})`,
1055
+ budgetEntities: t ?? null,
1056
+ derivation: [
1057
+ "backing = wasm_memory_allocator(memory), zero-copy with a WASM compute backend (is_in_place ✓)",
1058
+ n !== void 0 ? `cap = ${I(L)} (caller-declared maxBytes; the Memory's own maximum is not readable from JS)` : `cap = ${I(L)} (default; the Memory's own maximum is not readable from JS)`,
1059
+ `storeBase = ${I(_)}, the module owns every byte below it`,
1060
+ ...f,
1061
+ t === void 0 ? `entityIndex = floor_pow2((cap - storeBase)/4 ÷ ${R} B) = ${c} slots` : "entityIndex sized from the entity count above"
1062
+ ],
1063
+ wasmMemory: r.memory
1064
+ };
1065
+ }
1066
+ M("backing.wasm.maximumPages", r.maximumPages);
1067
+ const u = r.initialPages ?? Math.min(32, r.maximumPages);
1068
+ if (M("backing.wasm.initialPages", u), u > r.maximumPages)
1069
+ throw new E(
1070
+ m.INVALID_MEMORY_OPTIONS,
1071
+ `memory.backing.wasm.initialPages (${u}) exceeds maximumPages (${r.maximumPages})`
1072
+ );
1073
+ if (n !== void 0)
1074
+ throw new E(
1075
+ m.INVALID_MEMORY_OPTIONS,
1076
+ `memory.maxBytes (${I(n)}) cannot be given beside memory.backing.wasm.maximumPages (${r.maximumPages} pages = ${I(r.maximumPages * B)}), the Memory's page maximum IS the ceiling. Declare it once, in pages.`
1077
+ );
1078
+ const D = new WebAssembly.Memory({
1079
+ initial: u,
1080
+ maximum: r.maximumPages,
1081
+ shared: !0
1082
+ }), y = r.maximumPages * B;
1083
+ return t === void 0 && (c = p(Math.max(y - _, 0))), {
1084
+ source: "wasm",
1085
+ sizing: T,
1086
+ allocator: ce(D),
1087
+ columnCapacity: d,
1088
+ entityIndexCapacity: c,
1089
+ capBytes: y,
1090
+ storeBase: _,
1091
+ intentLabel: `engine-constructed WebAssembly.Memory (max ${r.maximumPages} pages)`,
1092
+ budgetEntities: t ?? null,
1093
+ derivation: [
1094
+ `cap = ${r.maximumPages} pages × 64 KiB = ${I(y)} (Memory maximum)`,
1095
+ `initial = ${u} pages (${r.initialPages !== void 0 ? "declared" : "default"})`,
1096
+ `storeBase = ${I(_)}, the module owns every byte below it`,
1097
+ ...f,
1098
+ t === void 0 ? `entityIndex = floor_pow2((cap - storeBase)/4 ÷ ${R} B) = ${c} slots` : "entityIndex sized from the entity count above"
1099
+ ],
1100
+ wasmMemory: D
1101
+ };
1102
+ }
1103
+ if (typeof s == "object" && s.allocator !== void 0) {
1104
+ if (s.allocator.isInPlace !== !0)
1105
+ throw new E(
1106
+ m.INVALID_MEMORY_OPTIONS,
1107
+ "memory.backing.allocator must declare `isInPlace: true`. A live Store's flush loops hoist entity-index views across grows, so an allocator that is not in-place (DEFAULT_SAB_ALLOCATOR, for example) corrupts the entity→row mapping. Use growableSabAllocator, fixedSabAllocator or wasmMemoryAllocator. An allocator that is not in-place is for snapshot and test sizing only."
1108
+ );
1109
+ const r = n ?? null;
1110
+ return t === void 0 && r !== null && (c = p(r)), {
1111
+ source: "allocator",
1112
+ sizing: T,
1113
+ allocator: s.allocator,
1114
+ columnCapacity: d,
1115
+ entityIndexCapacity: c,
1116
+ capBytes: r,
1117
+ storeBase: _,
1118
+ intentLabel: r !== null ? `custom in-place allocator (declared cap ${I(r)})` : "custom in-place allocator",
1119
+ budgetEntities: t ?? null,
1120
+ derivation: [
1121
+ "backing = caller allocator (is_in_place ✓ checked at construction)",
1122
+ r !== null ? `cap = ${I(r)} (caller-declared; the allocator owns the real ceiling)` : "cap = allocator-owned (no maxBytes declared)",
1123
+ ...f,
1124
+ t !== void 0 ? "entityIndex sized from the entity count above" : r !== null ? `entityIndex = floor_pow2(cap/4 ÷ ${R} B) = ${c} slots` : `entityIndex = ${c} slots (default, no entity count and no declared cap)`
1125
+ ],
1126
+ wasmMemory: null
1127
+ };
1128
+ }
1129
+ if (s === "shared") {
1130
+ const r = n ?? l ?? q;
1131
+ return N(
1132
+ r,
1133
+ "shared",
1134
+ He(r),
1135
+ `shared SharedArrayBuffer backing (${I(r)} growable cap, needs COOP and COEP)`,
1136
+ [
1137
+ `backing = growable_sab_allocator(${I(r)}), growable SharedArrayBuffer (is_in_place ✓), needs cross-origin isolation`,
1138
+ "enables worker offload + a WASM compute backend (transferable SharedArrayBuffer)"
1139
+ ]
1140
+ );
1141
+ }
1142
+ if (s !== "heap")
1143
+ throw new E(
1144
+ m.INVALID_MEMORY_OPTIONS,
1145
+ `memory.backing must be "heap", "shared", { wasm }, or { allocator } (got ${JSON.stringify(s)})`
1146
+ );
1147
+ const a = n ?? l ?? q;
1148
+ return N(
1149
+ a,
1150
+ "heap",
1151
+ Ge(a),
1152
+ T === "default" ? `default sizing (${I(a)} reserved cap)` : t !== void 0 ? `budget of ${t} entities` : `explicit cap of ${I(a)}`,
1153
+ [
1154
+ `backing = heap_arraybuffer_allocator(${I(a)}), fixed ArrayBuffer reserved at the cap, no SAB and no COOP+COEP (is_in_place ✓)`,
1155
+ "trade-off: no worker offload and no WASM backend (both need a transferable SharedArrayBuffer)"
1156
+ ]
1157
+ );
1158
+ }
1159
+ function Bn(e, t) {
1160
+ return { def: e, values: t };
1161
+ }
1162
+ function te(e, t) {
1163
+ switch (t.kind) {
1164
+ case "spawn": {
1165
+ const n = e.commands.spawn();
1166
+ for (const o of t.components)
1167
+ e.commands.add(n, o.def, o.values);
1168
+ return t.onSpawned?.(n), n;
1169
+ }
1170
+ case "despawn":
1171
+ e.commands.despawn(t.eid);
1172
+ return;
1173
+ case "add_component":
1174
+ e.commands.add(t.eid, t.def, t.values);
1175
+ return;
1176
+ case "remove_component":
1177
+ e.commands.remove(t.eid, t.def);
1178
+ return;
1179
+ case "set_field":
1180
+ e.setField(t.eid, t.def, t.field, t.value);
1181
+ return;
1182
+ case "disable":
1183
+ e.commands.disable(t.eid);
1184
+ return;
1185
+ case "enable":
1186
+ e.commands.enable(t.eid);
1187
+ return;
1188
+ default:
1189
+ return We(t, "HostCommand kind");
1190
+ }
1191
+ }
1192
+ class Qt {
1193
+ _pending = [];
1194
+ spawn(t, n) {
1195
+ return this._pending.push({ kind: "spawn", components: t, onSpawned: n }), this;
1196
+ }
1197
+ despawn(t) {
1198
+ return this._pending.push({ kind: "despawn", eid: t }), this;
1199
+ }
1200
+ /** Attach `def` (with complete `values`) to `entityId` (deferred to the
1201
+ * drain). The namespaced-handle grammar, the queue is a commands buffer, so
1202
+ * it drops the noun (`add`, not `addComponent`), matching `ctx.commands.add`
1203
+ * and the queue's own bare `spawn`, `despawn`, `disable` and `enable`. Values are
1204
+ * complete (transport carries explicit intent per field, see `spawnEntry`),
1205
+ * unlike the authoring-side bundle sugar. */
1206
+ add(t, n, o) {
1207
+ return this._pending.push({ kind: "add_component", eid: t, def: n, values: o }), this;
1208
+ }
1209
+ /** Detach `def` from `entityId` (deferred to the drain). Bare `remove`
1210
+ * matching `ctx.commands.remove`, see `add`. */
1211
+ remove(t, n) {
1212
+ return this._pending.push({ kind: "remove_component", eid: t, def: n }), this;
1213
+ }
1214
+ /** Set `field` of `def` on `entityId`. Applied immediately at the drain, unlike
1215
+ * the deferred structural ops, so `def` must already be on `entityId`. Do not
1216
+ * `add` and `spawn` `def` and `setField` it in the same frame: the add is
1217
+ * still pending its flush when the immediate set runs (carry the value in
1218
+ * `add` or `spawnEntry` instead). `applyHostCommand` throws an
1219
+ * actionable error in `DEV` if you do. */
1220
+ setField(t, n, o, s) {
1221
+ return this._pending.push({
1222
+ kind: "set_field",
1223
+ eid: t,
1224
+ def: n,
1225
+ field: o,
1226
+ value: s
1227
+ }), this;
1228
+ }
1229
+ disable(t) {
1230
+ return this._pending.push({ kind: "disable", eid: t }), this;
1231
+ }
1232
+ enable(t) {
1233
+ return this._pending.push({ kind: "enable", eid: t }), this;
1234
+ }
1235
+ /** Enqueue a pre-built command. The path for a SAB-ring codec, an editor's
1236
+ * reified inverse, or a replay log, all of which produce `HostCommand` data
1237
+ * directly rather than calling the typed sugar above. */
1238
+ push(t) {
1239
+ return this._pending.push(t), this;
1240
+ }
1241
+ /** Commands buffered but not yet applied. */
1242
+ get pendingCount() {
1243
+ return this._pending.length;
1244
+ }
1245
+ /** Drop every buffered command without applying it, e.g. abandoning
1246
+ * queued edits on a scene unload. Returns how many were dropped. Does not
1247
+ * touch commands already drained into the world. */
1248
+ clear() {
1249
+ const t = this._pending.length;
1250
+ return this._pending.length = 0, t;
1251
+ }
1252
+ /**
1253
+ * Apply and clear every buffered command. Called by the blessed apply system
1254
+ * inside its schedule span. Not part of the host-facing surface. Returns the
1255
+ * count applied.
1256
+ *
1257
+ * `tap`, when present, is invoked with each command in apply order immediately before
1258
+ * it is applied, the record and replay hook ({@link HostCommandRecorder}). It is
1259
+ * an opt-in observer: the tap-free path keeps the original tight loop, so an
1260
+ * un-recorded drain pays nothing.
1261
+ */
1262
+ drain(t, n) {
1263
+ const o = this._pending.length;
1264
+ if (o === 0) return 0;
1265
+ if (n === void 0)
1266
+ for (let s = 0; s < o; s++) te(t, this._pending[s]);
1267
+ else
1268
+ for (let s = 0; s < o; s++) {
1269
+ const i = this._pending[s];
1270
+ n(i), te(t, i);
1271
+ }
1272
+ return this._pending.splice(0, o), o;
1273
+ }
1274
+ }
1275
+ const Fe = U - 1;
1276
+ function qt(e) {
1277
+ if (e === re)
1278
+ throw new b(
1279
+ "cannot bind opCode 0 (reserved as the command-ring empty-slot marker)"
1280
+ );
1281
+ if (e < 0 || e > 255 || !Number.isInteger(e))
1282
+ throw new b(`command opCode must be a u8 in [1, 255] (got ${e})`);
1283
+ }
1284
+ function j(e) {
1285
+ const t = new Uint8Array(Fe);
1286
+ return new DataView(t.buffer).setUint32(0, e, !0), t;
1287
+ }
1288
+ function Q(e) {
1289
+ return new DataView(e.buffer, e.byteOffset, e.byteLength).getUint32(0, !0);
1290
+ }
1291
+ function $n(e, t) {
1292
+ return {
1293
+ encode(n) {
1294
+ if (n.kind !== "set_field")
1295
+ throw new b(
1296
+ `ringSetFieldCodec encodes a "set_field" command (got "${n.kind}")`
1297
+ );
1298
+ const o = new Uint8Array(Fe), s = new DataView(o.buffer);
1299
+ return s.setUint32(0, n.eid, !0), s.setFloat64(4, n.value, !0), o;
1300
+ },
1301
+ decode(n) {
1302
+ const o = new DataView(n.buffer, n.byteOffset, n.byteLength);
1303
+ return {
1304
+ kind: "set_field",
1305
+ // boundary: branded-ID bridging, a decoded `u32` is an `EntityID` handle.
1306
+ eid: o.getUint32(0, !0),
1307
+ // schema-erased into the flat HostCommand union (the callable def is invariant in S).
1308
+ def: e,
1309
+ field: t,
1310
+ value: o.getFloat64(4, !0)
1311
+ };
1312
+ }
1313
+ };
1314
+ }
1315
+ function Yn() {
1316
+ return {
1317
+ encode(e) {
1318
+ if (e.kind !== "despawn")
1319
+ throw new b(
1320
+ `ringDespawnCodec encodes a "despawn" command (got "${e.kind}")`
1321
+ );
1322
+ return j(e.eid);
1323
+ },
1324
+ decode: (e) => ({ kind: "despawn", eid: Q(e) })
1325
+ };
1326
+ }
1327
+ function xn() {
1328
+ return {
1329
+ encode(e) {
1330
+ if (e.kind !== "disable")
1331
+ throw new b(
1332
+ `ringDisableCodec encodes a "disable" command (got "${e.kind}")`
1333
+ );
1334
+ return j(e.eid);
1335
+ },
1336
+ decode: (e) => ({ kind: "disable", eid: Q(e) })
1337
+ };
1338
+ }
1339
+ function Fn() {
1340
+ return {
1341
+ encode(e) {
1342
+ if (e.kind !== "enable")
1343
+ throw new b(
1344
+ `ringEnableCodec encodes an "enable" command (got "${e.kind}")`
1345
+ );
1346
+ return j(e.eid);
1347
+ },
1348
+ decode: (e) => ({ kind: "enable", eid: Q(e) })
1349
+ };
1350
+ }
1351
+ function Vn(e) {
1352
+ return {
1353
+ encode(t) {
1354
+ if (t.kind !== "remove_component")
1355
+ throw new b(
1356
+ `ringRemoveComponentCodec encodes a "remove_component" command (got "${t.kind}")`
1357
+ );
1358
+ return j(t.eid);
1359
+ },
1360
+ decode: (t) => ({ kind: "remove_component", eid: Q(t), def: e })
1361
+ };
1362
+ }
1363
+ class Hn {
1364
+ _appliers = /* @__PURE__ */ new Map();
1365
+ /** Bind a raw ctx-aware applier to `opCode`. Re-binding replaces. */
1366
+ on(t, n) {
1367
+ return qt(t), this._appliers.set(t, n), this;
1368
+ }
1369
+ /** Unbind `opCode`. Returns whether a binding was removed. Subsequent
1370
+ * slots carrying it hit the unknown-opcode path. */
1371
+ off(t) {
1372
+ return this._appliers.delete(t);
1373
+ }
1374
+ /** Bind a `HostCommand` codec to `opCode`: each matching slot is decoded and
1375
+ * run through `applyHostCommand`, the same dispatch the typed queue uses.
1376
+ * A drain-time `tap` (record and replay) sees the decoded command before it
1377
+ * applies, so ring-sourced commands share one log with the typed transport. */
1378
+ onCommand(t, n) {
1379
+ return this.on(t, (o, s, i) => {
1380
+ const _ = n.decode(s);
1381
+ i?.(_), te(o, _);
1382
+ });
1383
+ }
1384
+ /** Drain every pending slot, dispatching each to its bound applier. Unbound
1385
+ * opcodes are skipped (the read head still advances, matching
1386
+ * `drainCommandRing` and `CommandDispatcher`). Returns slots drained. `tap`,
1387
+ * when present, is forwarded to each applier as the record and replay hook.
1388
+ * Only an `onCommand`-bound (generic `HostCommand`) opcode surfaces to it. */
1389
+ drain(t, n, o, s) {
1390
+ return lt(n, o, (i, _) => {
1391
+ const d = this._appliers.get(i);
1392
+ d !== void 0 && d(t, _, s);
1393
+ });
1394
+ }
1395
+ }
1396
+ const ne = /* @__PURE__ */ new WeakMap();
1397
+ function Gn(e, t) {
1398
+ const n = ne.get(t);
1399
+ if (n === void 0) return !1;
1400
+ for (const o of n) e.removeSystem(o);
1401
+ return ne.delete(t), t.clear(), !0;
1402
+ }
1403
+ function kn(e, t) {
1404
+ const n = new Qt(), o = [];
1405
+ ne.set(n, o);
1406
+ const s = t?.name ?? "host_command_apply", i = t?.ring, _ = t?.recorder, d = _?.record, c = t?.schedules ?? [
1407
+ Z.PRE_STARTUP,
1408
+ Z.PRE_UPDATE
1409
+ ];
1410
+ if (_ !== void 0) {
1411
+ for (const l of c)
1412
+ if (ge(l) === "fixed")
1413
+ throw new E(
1414
+ m.INVALID_RECORDER_SCHEDULE,
1415
+ `installHostCommandSeam: a recorder cannot drain at ${Ne(l)}, a phase of the fixed loop. It would log the fixed timestep and not the host update dt, so a replay would diverge. Drain at a phase of the update loop instead.`
1416
+ );
1417
+ }
1418
+ for (const l of c) {
1419
+ const f = ge(l) !== "startup", p = e.registerSystem({
1420
+ name: `${s}:${Ne(l)}`,
1421
+ // `reads` and `writes` are required by `SystemConfig` but empty here: the
1422
+ // apply system declares nothing because it mutates components not known
1423
+ // at registration. Full world access: the host may queue mutations to
1424
+ // anything. The deferred-flush apply point is unchanged, so structural
1425
+ // safety holds. `exclusive` only waives the DEV access check.
1426
+ reads: [],
1427
+ writes: [],
1428
+ exclusive: !0,
1429
+ fn: (T, S) => {
1430
+ if (_ !== void 0 && f && _.openTick(T.ecsTick, S), n.drain(T, d), i !== void 0) {
1431
+ const N = e.columnStore, a = N.header.commandRingOff;
1432
+ a !== 0 && i.drain(T, N.view, a, d);
1433
+ }
1434
+ }
1435
+ });
1436
+ e.addSystems(l, p), o.push(p);
1437
+ }
1438
+ return n;
1439
+ }
1440
+ export {
1441
+ Re as $,
1442
+ dn as A,
1443
+ ye as B,
1444
+ g as C,
1445
+ q as D,
1446
+ E,
1447
+ Rn as F,
1448
+ xe as G,
1449
+ Hn as H,
1450
+ Le as I,
1451
+ ae as J,
1452
+ Ye as K,
1453
+ H as L,
1454
+ ze as M,
1455
+ sn as N,
1456
+ On as O,
1457
+ Ln as P,
1458
+ wn as Q,
1459
+ En as R,
1460
+ gn as S,
1461
+ A as T,
1462
+ on as U,
1463
+ tt as V,
1464
+ ee as W,
1465
+ Me as X,
1466
+ xt as Y,
1467
+ Yt as Z,
1468
+ le as _,
1469
+ m as a,
1470
+ k as a0,
1471
+ Ee as a1,
1472
+ yn as a2,
1473
+ bn as a3,
1474
+ P as a4,
1475
+ Pe as a5,
1476
+ Ce as a6,
1477
+ rn as a7,
1478
+ en as a8,
1479
+ In as a9,
1480
+ F as aa,
1481
+ Dn as ab,
1482
+ Nn as ac,
1483
+ Sn as ad,
1484
+ Z as ae,
1485
+ un as af,
1486
+ _n as ag,
1487
+ ln as ah,
1488
+ an as ai,
1489
+ cn as aj,
1490
+ Un as ak,
1491
+ kn as al,
1492
+ Gn as am,
1493
+ te as an,
1494
+ Qt as ao,
1495
+ Bn as ap,
1496
+ nn as aq,
1497
+ Te as ar,
1498
+ tn as as,
1499
+ Wt as b,
1500
+ Xt as c,
1501
+ Cn as d,
1502
+ $n as e,
1503
+ Yn as f,
1504
+ xn as g,
1505
+ Fn as h,
1506
+ Vn as i,
1507
+ Fe as j,
1508
+ An as k,
1509
+ _e as l,
1510
+ oe as m,
1511
+ mn as n,
1512
+ fn as o,
1513
+ Pn as p,
1514
+ Mn as q,
1515
+ vn as r,
1516
+ Tn as s,
1517
+ pn as t,
1518
+ Qe as u,
1519
+ Zt as v,
1520
+ hn as w,
1521
+ Xe as x,
1522
+ de as y,
1523
+ Ut as z
1524
+ };