@oasys/oecs 0.5.4 → 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 +1223 -266
  2. package/README.md +217 -112
  3. package/dist/core/ecs/access_check.d.cts +29 -29
  4. package/dist/core/ecs/access_check.d.ts +29 -29
  5. package/dist/core/ecs/access_check.d.ts.map +1 -1
  6. package/dist/core/ecs/archetype.d.cts +217 -209
  7. package/dist/core/ecs/archetype.d.ts +217 -209
  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 +33 -33
  13. package/dist/core/ecs/archetype_graph.d.ts +33 -33
  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 +26 -26
  28. package/dist/core/ecs/command_log.d.ts +26 -26
  29. package/dist/core/ecs/command_log.d.ts.map +1 -1
  30. package/dist/core/ecs/component.d.cts +43 -42
  31. package/dist/core/ecs/component.d.ts +43 -42
  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 +289 -270
  46. package/dist/core/ecs/ecs.d.ts +289 -270
  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 +20 -18
  57. package/dist/core/ecs/entity_allocator.d.ts +20 -18
  58. package/dist/core/ecs/entity_allocator.d.ts.map +1 -1
  59. package/dist/core/ecs/event.d.cts +36 -22
  60. package/dist/core/ecs/event.d.ts +36 -22
  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 +32 -32
  69. package/dist/core/ecs/frame_trace.d.ts +32 -32
  70. package/dist/core/ecs/frame_trace.d.ts.map +1 -1
  71. package/dist/core/ecs/host_commands.d.cts +103 -85
  72. package/dist/core/ecs/host_commands.d.ts +103 -85
  73. package/dist/core/ecs/host_commands.d.ts.map +1 -1
  74. package/dist/core/ecs/index.d.cts +21 -11
  75. package/dist/core/ecs/index.d.ts +21 -11
  76. package/dist/core/ecs/index.d.ts.map +1 -1
  77. package/dist/core/ecs/observer.d.cts +39 -120
  78. package/dist/core/ecs/observer.d.ts +39 -120
  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 +208 -578
  90. package/dist/core/ecs/query.d.ts +208 -578
  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 +100 -39
  102. package/dist/core/ecs/ref.d.ts +100 -39
  103. package/dist/core/ecs/ref.d.ts.map +1 -1
  104. package/dist/core/ecs/relation.d.cts +101 -182
  105. package/dist/core/ecs/relation.d.ts +101 -182
  106. package/dist/core/ecs/relation.d.ts.map +1 -1
  107. package/dist/core/ecs/resource.d.cts +13 -13
  108. package/dist/core/ecs/resource.d.ts +13 -13
  109. package/dist/core/ecs/resource_registry.d.cts +5 -5
  110. package/dist/core/ecs/resource_registry.d.ts +5 -5
  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 +91 -120
  119. package/dist/core/ecs/schedule.d.ts +91 -120
  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 +108 -51
  131. package/dist/core/ecs/sparse_store.d.ts +108 -51
  132. package/dist/core/ecs/sparse_store.d.ts.map +1 -1
  133. package/dist/core/ecs/store.d.cts +527 -473
  134. package/dist/core/ecs/store.d.ts +527 -473
  135. package/dist/core/ecs/store.d.ts.map +1 -1
  136. package/dist/core/ecs/store_layout_listener.d.cts +6 -6
  137. package/dist/core/ecs/store_layout_listener.d.ts +6 -6
  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 +146 -61
  142. package/dist/core/ecs/system.d.ts +146 -61
  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 +82 -6
  154. package/dist/core/ecs/utils/error.d.ts +82 -6
  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 +44 -44
  163. package/dist/core/store/action_ring.d.ts +44 -44
  164. package/dist/core/store/action_ring.d.ts.map +1 -1
  165. package/dist/core/store/allocator.d.cts +149 -95
  166. package/dist/core/store/allocator.d.ts +149 -95
  167. package/dist/core/store/allocator.d.ts.map +1 -1
  168. package/dist/core/store/buffer_backed_column.d.cts +17 -17
  169. package/dist/core/store/buffer_backed_column.d.ts +17 -17
  170. package/dist/core/store/buffer_backed_column.d.ts.map +1 -1
  171. package/dist/core/store/column_store.d.cts +124 -86
  172. package/dist/core/store/column_store.d.ts +124 -86
  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 +36 -39
  178. package/dist/core/store/command_ring.d.ts +36 -39
  179. package/dist/core/store/command_ring.d.ts.map +1 -1
  180. package/dist/core/store/descriptor.d.cts +34 -17
  181. package/dist/core/store/descriptor.d.ts +34 -17
  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 +36 -38
  187. package/dist/core/store/event_ring.d.ts +36 -38
  188. package/dist/core/store/event_ring.d.ts.map +1 -1
  189. package/dist/core/store/extend.d.cts +13 -7
  190. package/dist/core/store/extend.d.ts +13 -7
  191. package/dist/core/store/extend.d.ts.map +1 -1
  192. package/dist/core/store/grow.d.cts +2 -2
  193. package/dist/core/store/grow.d.ts +2 -2
  194. package/dist/core/store/grow.d.ts.map +1 -1
  195. package/dist/core/store/header.d.cts +31 -27
  196. package/dist/core/store/header.d.ts +31 -27
  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 +71 -62
  202. package/dist/core/store/layout_ops.d.ts +71 -62
  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 +12 -12
  211. package/dist/core/store/state_hash.d.ts +12 -12
  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 +15 -10
  225. package/dist/index.d.ts +15 -10
  226. package/dist/index.d.ts.map +1 -1
  227. package/dist/index.development.cjs +1 -1
  228. package/dist/index.development.js +5804 -5203
  229. package/dist/index.js +5323 -4764
  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 +54 -54
  244. package/dist/{extensions → plugins}/editor/editor.d.ts +54 -54
  245. package/dist/plugins/editor/editor.d.ts.map +1 -0
  246. package/dist/{extensions → plugins}/editor/field_handle.d.cts +12 -12
  247. package/dist/{extensions → plugins}/editor/field_handle.d.ts +12 -12
  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} +81 -64
  257. package/dist/{extensions/editor/index.js → plugins/editor.js} +81 -64
  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 +85 -97
  302. package/dist/{core/ecs → plugins/relations}/relation_service.d.ts +85 -97
  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 +16 -15
  411. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +16 -15
  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 +3 -3
  415. package/dist/version.d.ts +3 -3
  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-BlR3oZ3x.js +0 -2406
  465. package/dist/host_commands-C2cpU3yC.cjs +0 -1
  466. package/dist/internal-BoxWl4dG.js +0 -2565
  467. package/dist/internal-CGBEwfeB.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-Bs39EPh1.js +0 -150
  502. package/dist/shallow-C5YmTbtb.cjs +0 -1
  503. package/dist/shallow-CiFC70Dz.js +0 -159
  504. package/dist/shallow-DQ8aG51_.cjs +0 -1
  505. package/dist/shared-B4v0L1cw.js +0 -109
  506. package/dist/shared-DU78k0pU.cjs +0 -1
  507. package/dist/topological_sort-BDvEyb9W.cjs +0 -1
  508. package/dist/topological_sort-DK6EjpWa.js +0 -135
  509. package/dist/typed_arrays-D3NmwtCG.cjs +0 -1
  510. package/dist/typed_arrays-DIVwVy5_.js +0 -258
@@ -0,0 +1,57 @@
1
+ import { ECS_SNAPSHOT_VERSION, ArchetypeRowState, HostState } from '../../core/ecs/snapshot.js';
2
+ import { ArchetypeViews } from '../../core/store/index.js';
3
+ import { ECSRestoreError } from '../../core/ecs/utils/error.js';
4
+ /** Magic for the combined world-snapshot frame (`"WRS0"` little-endian). Distinct
5
+ * from the SAB `STORE_MAGIC` so a bare dense snapshot fed to `restore` is
6
+ * rejected with a clear error instead of being mis-parsed as a combined frame. */
7
+ export declare const WORLD_SNAPSHOT_MAGIC = 810766935;
8
+ export { ECSRestoreError };
9
+ export { ECS_SNAPSHOT_VERSION };
10
+ export type { ArchetypeRowState, HostState };
11
+ /** Serialize host-state to a self-contained little-endian byte buffer. Layout:
12
+ *
13
+ * [u32 tick][u32 highWater][u32 alive_count]
14
+ * [u32 freeCount][u32 free_index × freeCount]
15
+ * [u32 archCount][(u32 id, u32 length, u32 enabled_count) × archCount]
16
+ */
17
+ export declare function serializeHostState(hs: HostState): Uint8Array;
18
+ /** Parse host-state bytes produced by `serializeHostState`. Throws
19
+ * `ECSRestoreError` on truncation or a trailing-byte (non-canonical) buffer. */
20
+ export declare function parseHostState(bytes: Uint8Array): HostState;
21
+ /** Assemble the combined world-snapshot frame from its three sections. Layout:
22
+ *
23
+ * [u32 magic][u32 version][u32 denseLen][u32 sparseLen][u32 hostLen]
24
+ * [dense][sparse][host]
25
+ */
26
+ export declare function frameWorldSnapshot(dense: Uint8Array, sparse: Uint8Array, host: Uint8Array): Uint8Array;
27
+ /** The three sections of a combined frame, as zero-copy subviews over `bytes`. */
28
+ export interface WorldSnapshotSections {
29
+ readonly dense: Uint8Array;
30
+ readonly sparse: Uint8Array;
31
+ readonly host: Uint8Array;
32
+ }
33
+ /** Split a combined frame back into its sections. Validates magic, version, and
34
+ * an exact (no trailing bytes) frame. Throws `ECSRestoreError` otherwise. */
35
+ export declare function unframeWorldSnapshot(bytes: Uint8Array): WorldSnapshotSections;
36
+ /**
37
+ * Fail-closed registration guard, read **directly from the snapshot's dense
38
+ * bytes** so it can run before the dense backing is touched. `restore`
39
+ * builds the restored store through the live world's in-place allocator,
40
+ * which reuses the live backing buffer, so validating a
41
+ * *materialised* `ColumnStore` would already have overwritten live column data
42
+ * (the buffer is overwritten inside `restoreColumnStore`, before any post-build
43
+ * check could run). Parsing the descriptors off the raw `dense` `Uint8Array`
44
+ * keeps the check non-mutating, so a mismatch leaves the live world untouched.
45
+ *
46
+ * Asserts: the dense section's SAB magic and ABI, and that its archetype set,
47
+ * its per-archetype `componentMask` and its per-column
48
+ * `(componentId, fieldId, typeTag)`
49
+ * match the live store's exactly (so every live `Archetype.refreshViews` finds
50
+ * its region and no snapshot archetype is orphaned), and that the entity-index
51
+ * capacity matches (the region is sized once at construction). The archetype
52
+ * graph is rebuilt from registration code, not the snapshot (mirroring
53
+ * `restoreSparse`'s "registered in the same order" contract). Throws
54
+ * `ECSRestoreError` on any mismatch and malformed section.
55
+ */
56
+ export declare function assertDenseMatchesLive(dense: Uint8Array, live: ReadonlyMap<number, ArchetypeViews>, liveEntityIndexCapacity: number): void;
57
+ //# sourceMappingURL=resume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume.d.ts","sourceRoot":"","sources":["../../../src/plugins/snapshots/resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EACN,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAaN,KAAK,cAAc,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;kFAEkF;AAClF,eAAO,MAAM,oBAAoB,YAAa,CAAC;AAM/C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,CAAC;AAI3B,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC;AAI7C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,SAAS,GAAG,UAAU,CAwB5D;AAED;gFACgF;AAChF,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAqC3D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,GACd,UAAU,CAaZ;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC1B;AAED;6EAC6E;AAC7E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,qBAAqB,CAuC7E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,EACzC,uBAAuB,EAAE,MAAM,GAC7B,IAAI,CA4GN"}
@@ -0,0 +1,59 @@
1
+ import { EntityAllocator } from '../../core/ecs/entity_allocator.cjs';
2
+ import { SnapshotHooks, SnapshotHost } from '../../core/ecs/snapshot.cjs';
3
+ export declare class SnapshotService implements SnapshotHooks {
4
+ private readonly _host;
5
+ /** The allocator is its own snapshot seam: a free-list copy on
6
+ * capture, `setHighWater` and `restoreHostState` on mount. */
7
+ private readonly _allocator;
8
+ constructor(host: SnapshotHost, allocator: EntityAllocator);
9
+ /** Serialize the sparse stores **and** relation side data to a self-contained
10
+ * byte buffer, the sparse half of a world snapshot (the dense half is the
11
+ * SAB snapshot). Two framed sections: the sparse stores (`snapshotSparseStores`,
12
+ * where the exclusive relation targets and the multi membership ride) followed
13
+ * by the relation side data (`snapshotRelations`, multi forward target
14
+ * sets, which live outside the sparse store). Both are written in canonical
15
+ * entity-index order, so two worlds with identical contents inserted in
16
+ * different orders snapshot byte-for-byte the same. The reverse index
17
+ * is derived and never serialized, `restoreSparse` rebuilds it. */
18
+ snapshotSparse(): Uint8Array;
19
+ /** Repopulate the sparse stores from `snapshotSparse` bytes, replacing all
20
+ * current sparse data (full-equality round-trip of membership and data), then
21
+ * rebuild every relation's derived side indices: multi forward sets from the
22
+ * relation section, and the reverse index for both cardinalities (exclusive
23
+ * from the newly restored sparse target field, multi from the rebuilt forward
24
+ * sets). The sparse components and relations must already be registered in
25
+ * the same order, restore carries data, not the registration (which is
26
+ * code). Throws `SparseRestoreError` if the snapshot's shape, field identity,
27
+ * entity-index bounds, or frame length don't validate. */
28
+ restoreSparse(bytes: Uint8Array): void;
29
+ /** Rebuild every relation's derived side indices after the sparse stores have
30
+ * been restored. `restoreRelations` resets all relations, rebuilds the multi
31
+ * forward sets and their reverse edges from `relBytes`, and validates shape.
32
+ * The exclusive reverse index can't be carried in the bytes (it's derivable),
33
+ * so it's rebuilt here from the backing sparse store: every member row holds
34
+ * `(source index → target EntityID)`, which is exactly one reverse edge. */
35
+ private _rebuildRelationIndices;
36
+ /** Capture the full live world to one self-contained byte buffer that
37
+ * `restore` can mount back onto a live, ticking world. Three
38
+ * sections (see `resume.ts`): the dense SAB column bytes, the sparse and
39
+ * relation bytes, and the host-side bookkeeping the SAB omits. */
40
+ snapshot(): Uint8Array;
41
+ /** Gather the host-side state a snapshot carries alongside the dense and
42
+ * sparse bytes, see `snapshot()`. The free-list is copied, because it is a
43
+ * live mutable. */
44
+ private _collectHostState;
45
+ /** Mount a `snapshot()` buffer onto the live world and leave it ready to keep
46
+ * ticking. Fails closed on a malformed frame or a registration mismatch
47
+ * before any live state is touched. */
48
+ restore(bytes: Uint8Array): void;
49
+ /** Read-only validation of a `snapshotSparse` Section (the framed
50
+ * `[sparseLen][relLen][sparse][rel]` buffer) against the live registry, used
51
+ * by `restore` to fail closed on a sparse-registration mismatch before the
52
+ * dense mount commits. Mirrors `restoreSparse`'s frame check, then validates the
53
+ * sparse-stores sub-section without mutating. A relation-registration difference
54
+ * surfaces here too: every `registerRelation` adds a backing sparse store, so a
55
+ * differing relation set changes the sparse store count or its schema. Throws
56
+ * `SparseRestoreError` on a mismatch. */
57
+ private _assertSparseMatchesLive;
58
+ }
59
+ //# sourceMappingURL=snapshot_service.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { EntityAllocator } from '../../core/ecs/entity_allocator.js';
2
+ import { SnapshotHooks, SnapshotHost } from '../../core/ecs/snapshot.js';
3
+ export declare class SnapshotService implements SnapshotHooks {
4
+ private readonly _host;
5
+ /** The allocator is its own snapshot seam: a free-list copy on
6
+ * capture, `setHighWater` and `restoreHostState` on mount. */
7
+ private readonly _allocator;
8
+ constructor(host: SnapshotHost, allocator: EntityAllocator);
9
+ /** Serialize the sparse stores **and** relation side data to a self-contained
10
+ * byte buffer, the sparse half of a world snapshot (the dense half is the
11
+ * SAB snapshot). Two framed sections: the sparse stores (`snapshotSparseStores`,
12
+ * where the exclusive relation targets and the multi membership ride) followed
13
+ * by the relation side data (`snapshotRelations`, multi forward target
14
+ * sets, which live outside the sparse store). Both are written in canonical
15
+ * entity-index order, so two worlds with identical contents inserted in
16
+ * different orders snapshot byte-for-byte the same. The reverse index
17
+ * is derived and never serialized, `restoreSparse` rebuilds it. */
18
+ snapshotSparse(): Uint8Array;
19
+ /** Repopulate the sparse stores from `snapshotSparse` bytes, replacing all
20
+ * current sparse data (full-equality round-trip of membership and data), then
21
+ * rebuild every relation's derived side indices: multi forward sets from the
22
+ * relation section, and the reverse index for both cardinalities (exclusive
23
+ * from the newly restored sparse target field, multi from the rebuilt forward
24
+ * sets). The sparse components and relations must already be registered in
25
+ * the same order, restore carries data, not the registration (which is
26
+ * code). Throws `SparseRestoreError` if the snapshot's shape, field identity,
27
+ * entity-index bounds, or frame length don't validate. */
28
+ restoreSparse(bytes: Uint8Array): void;
29
+ /** Rebuild every relation's derived side indices after the sparse stores have
30
+ * been restored. `restoreRelations` resets all relations, rebuilds the multi
31
+ * forward sets and their reverse edges from `relBytes`, and validates shape.
32
+ * The exclusive reverse index can't be carried in the bytes (it's derivable),
33
+ * so it's rebuilt here from the backing sparse store: every member row holds
34
+ * `(source index → target EntityID)`, which is exactly one reverse edge. */
35
+ private _rebuildRelationIndices;
36
+ /** Capture the full live world to one self-contained byte buffer that
37
+ * `restore` can mount back onto a live, ticking world. Three
38
+ * sections (see `resume.ts`): the dense SAB column bytes, the sparse and
39
+ * relation bytes, and the host-side bookkeeping the SAB omits. */
40
+ snapshot(): Uint8Array;
41
+ /** Gather the host-side state a snapshot carries alongside the dense and
42
+ * sparse bytes, see `snapshot()`. The free-list is copied, because it is a
43
+ * live mutable. */
44
+ private _collectHostState;
45
+ /** Mount a `snapshot()` buffer onto the live world and leave it ready to keep
46
+ * ticking. Fails closed on a malformed frame or a registration mismatch
47
+ * before any live state is touched. */
48
+ restore(bytes: Uint8Array): void;
49
+ /** Read-only validation of a `snapshotSparse` Section (the framed
50
+ * `[sparseLen][relLen][sparse][rel]` buffer) against the live registry, used
51
+ * by `restore` to fail closed on a sparse-registration mismatch before the
52
+ * dense mount commits. Mirrors `restoreSparse`'s frame check, then validates the
53
+ * sparse-stores sub-section without mutating. A relation-registration difference
54
+ * surfaces here too: every `registerRelation` adds a backing sparse store, so a
55
+ * differing relation set changes the sparse store count or its schema. Throws
56
+ * `SparseRestoreError` on a mismatch. */
57
+ private _assertSparseMatchesLive;
58
+ }
59
+ //# sourceMappingURL=snapshot_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot_service.d.ts","sourceRoot":"","sources":["../../../src/plugins/snapshots/snapshot_service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAOvE,OAAO,KAAK,EAGX,aAAa,EACb,YAAY,EACZ,MAAM,yBAAyB,CAAC;AAWjC,qBAAa,eAAgB,YAAW,aAAa;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC;kEAC8D;IAC9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;gBAEjC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe;IAK1D;;;;;;;;uEAQmE;IAC5D,cAAc,IAAI,UAAU;IAanC;;;;;;;;8DAQ0D;IACnD,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAuB7C;;;;;gFAK4E;IAC5E,OAAO,CAAC,uBAAuB;IAW/B;;;sEAGkE;IAC3D,QAAQ,IAAI,UAAU;IAa7B;;uBAEmB;IACnB,OAAO,CAAC,iBAAiB;IAqBzB;;2CAEuC;IAChC,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IA+CvC;;;;;;;6CAOyC;IACzC,OAAO,CAAC,wBAAwB;CAgBhC"}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./relation_store-DQKSnxsm.cjs"),u=require("../index.cjs"),a=require("./abi-D3V-QUSf.cjs"),P=require("../internal.cjs");function F(t){return{magic:t.getUint32(a.STORE_HEADER_OFFSETS.magic,!0),simAbiVersion:t.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0),viewStamp:t.getUint32(a.STORE_HEADER_OFFSETS.view_stamp,!0),capacity:t.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0),archetypeCount:t.getUint32(a.STORE_HEADER_OFFSETS.archetype_count,!0),layoutDescriptorOff:t.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0),commandRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.command_ring_off,!0),actionRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.action_ring_off,!0),entityIndexOff:t.getUint32(a.STORE_HEADER_OFFSETS.entity_index_off,!0),eventRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.event_ring_off,!0),regionTableOff:t.getUint32(a.STORE_HEADER_OFFSETS.region_table_off,!0),regionTableCount:t.getUint32(a.STORE_HEADER_OFFSETS.region_table_count,!0),bindingsOff:t.getUint32(a.STORE_HEADER_OFFSETS.bindings_off,!0)}}const g={u8:0,i8:1,u16:2,i16:3,u32:4,i32:5,f32:6,f64:7},B=Object.freeze({[g.u8]:1,[g.i8]:1,[g.u16]:2,[g.i16]:2,[g.u32]:4,[g.i32]:4,[g.f32]:4,[g.f64]:8});function N(t,e,n){t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.component_id,n.componentId,!0),t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.field_id,n.fieldId,!0),t.setUint8(e+a.COLUMN_DESCRIPTOR_OFFSETS.type_tag,n.typeTag),t.setUint32(e+a.COLUMN_DESCRIPTOR_OFFSETS.byte_off,n.byteOff,!0),t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.stride,n.stride,!0)}function M(t,e){return{componentId:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.component_id,!0),fieldId:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.field_id,!0),typeTag:t.getUint8(e+a.COLUMN_DESCRIPTOR_OFFSETS.type_tag),byteOff:t.getUint32(e+a.COLUMN_DESCRIPTOR_OFFSETS.byte_off,!0),stride:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.stride,!0)}}function Y(t,e=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){return e+t*a.COLUMN_DESCRIPTOR_BYTES}function V(t,e,n){t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.archetype_id,n.archetypeId,!0);for(let r=0;r<a.COMPONENT_MASK_WORDS;r++)t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.component_mask+r*4,n.componentMask[r]??0,!0);t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_count,n.rowCount,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_capacity,n.rowCapacity,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.column_count,n.columns.length,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.enabled_count,n.enabledCount,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.entity_ids_off,0,!0);let o=e+a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES;for(let r=0;r<n.columns.length;r++)N(t,o,n.columns[r]),o+=a.COLUMN_DESCRIPTOR_BYTES;return o}function v(t,e,n=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){const o=t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.column_count,!0),r=new Array(o);let s=e+n;for(let i=0;i<o;i++)r[i]=M(t,s),s+=a.COLUMN_DESCRIPTOR_BYTES;const c=new Array(a.COMPONENT_MASK_WORDS);for(let i=0;i<a.COMPONENT_MASK_WORDS;i++)c[i]=t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.component_mask+i*4,!0);return{archetypeId:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.archetype_id,!0),componentMask:c,rowCount:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_count,!0),rowCapacity:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_capacity,!0),enabledCount:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.enabled_count,!0),columns:r}}function x(t,e,n){let o=e;for(let r=0;r<n.length;r++)o=V(t,o,n[r]);return o}function C(t,e,n,o=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){const r=new Array(n);let s=e;for(let c=0;c<n;c++){const i=v(t,s,o);r[c]=i,s+=Y(i.columns.length,o)}return r}class k extends Error{constructor(){super('SharedArrayBuffer is not available in this runtime. The chosen world backing is SAB-based and cannot start without it. In browsers this requires cross-origin isolation: serve the page with `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (or `credentialless`). Alternatively choose the pure-TS heap profile (`memory: { backing: "heap" }`), which is backed by a plain ArrayBuffer and needs no SAB and no COOP+COEP. In Bun or Node SAB is available unconditionally. If you see this there, the runtime is older than expected, or the global was shadowed.'),this.name="SabUnavailableError"}}const G=t=>{if(typeof SharedArrayBuffer>"u")throw new k;return new SharedArrayBuffer(t)},X=16,W={capacity:4};function q(t,e){return t<<16|e}const $=2**31;class z extends Error{constructor(e){super(`SAB column layout offset ${e} reaches or exceeds the 2³¹ (${$}-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.`),this.name="StoreLayoutOverflowError"}}function j(t,e){if(t+e>$)throw new z(t);return t+(e-1)&~(e-1)}function K(t,e,n,o,r){const s=e+o;switch(n){case g.u8:return new Uint8Array(t,s,r);case g.i8:return new Int8Array(t,s,r);case g.u16:return new Uint16Array(t,s,r);case g.i16:return new Int16Array(t,s,r);case g.u32:return new Uint32Array(t,s,r);case g.i32:return new Int32Array(t,s,r);case g.f32:return new Float32Array(t,s,r);case g.f64:return new Float64Array(t,s,r)}}const U=16;function J(t){if(!Number.isInteger(t)||t<0)throw new RangeError(`createColumnStore: storeBase must be an integer >= 0, got ${t}`);if(t%U!==0)throw new RangeError(`createColumnStore: storeBase must be a multiple of ${U}, got ${t}`)}function Q(t,e,n){const o=new Map;for(let r=0;r<n.length;r++){const s=n[r],c=new Array(s.columns.length),i=new Map;for(let h=0;h<s.columns.length;h++){const E=s.columns[h],S={componentId:E.componentId,fieldId:E.fieldId,typeTag:E.typeTag,byteOff:E.byteOff,stride:E.stride,view:K(t,e,E.typeTag,E.byteOff,s.rowCapacity)};c[h]=S,i.set(q(E.componentId,E.fieldId),S)}o.set(s.archetypeId,{archetypeId:s.archetypeId,componentMask:s.componentMask,rowCapacity:s.rowCapacity,columns:i,columnsInOrder:c})}return o}function Z(t){const e=t.view.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0);return new Uint8Array(t.buffer,t.storeBase,e)}const tt=Math.max(...Object.values(B));function et(t){const e=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES-a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES;return j(t*e,tt)}function rt(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=e.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0),o=e.getUint32(a.STORE_HEADER_OFFSETS.archetype_count,!0),r=et(o);if(r===0)return t;const s=C(e,n,o,a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES),c=new Uint8Array(t.byteLength+r);c.set(t.subarray(0,n),0),c.set(t.subarray(n),n+r);const i=new DataView(c.buffer),h=s.map(S=>({...S,columns:S.columns.map(f=>({...f,byteOff:f.byteOff+r}))}));x(i,n,h);const E=e.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0);return i.setUint32(a.STORE_HEADER_OFFSETS.capacity,E+r,!0),c}function nt(t,e=G,n={}){const o=n.storeBase??0;J(o);const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<a.STORE_HEADER_BYTES)throw new u.StoreRestoreError(`snapshot too small: ${t.byteLength} bytes (header alone needs ${a.STORE_HEADER_BYTES})`);const s=r.getUint32(a.STORE_HEADER_OFFSETS.magic,!0);if(s!==a.STORE_MAGIC)throw new u.StoreRestoreError(`bad magic: 0x${s.toString(16).padStart(8,"0")} (expected 0x${a.STORE_MAGIC.toString(16).padStart(8,"0")})`);const c=r.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0);if(c!==a.SIM_ABI_VERSION&&c!==a.LEGACY_ABSOLUTE_ABI_VERSION)throw new u.StoreRestoreError(`incompatible sim_abi_version: snapshot=${c}, build=${a.SIM_ABI_VERSION}`);const i=r.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0);if(i>t.byteLength)throw new u.StoreRestoreError(`layout_descriptor_off ${i} is outside the snapshot (${t.byteLength} bytes)`);let h=t;if(c===a.LEGACY_ABSOLUTE_ABI_VERSION)try{h=rt(t)}catch(_){throw _ instanceof RangeError?new u.StoreRestoreError(`snapshot layout is corrupt or truncated: a version 0 descriptor reads past the ${t.byteLength}-byte span (${_.message})`):_}const E=e(o+h.byteLength);new Uint8Array(E,o,h.byteLength).set(h);const S=new DataView(E,o);S.setUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,a.SIM_ABI_VERSION,!0);const f=F(S);if(f.layoutDescriptorOff<0||f.layoutDescriptorOff>h.byteLength)throw new u.StoreRestoreError(`layout_descriptor_off ${f.layoutDescriptorOff} is outside the snapshot (${h.byteLength} bytes)`);try{const _=C(S,f.layoutDescriptorOff,f.archetypeCount),l=Q(E,o,_);return{buffer:E,view:S,header:f,storeBase:o,archetypes:l}}catch(_){throw _ instanceof RangeError?new u.StoreRestoreError(`snapshot layout is corrupt or truncated: a descriptor offset or column extent reads past the ${h.byteLength}-byte span (${_.message})`):_}}const ot=2166136261,st=16777619;function w(t,e){return t=(t^e&255)>>>0,Math.imul(t,st)>>>0}const I=12,b=4,O=8;function D(t,e){let n=ot;const o=r=>{for(let s=0;s<r.length;s++)n=w(n,r.charCodeAt(s))};for(let r=0;r<t.length;r++)o(t[r]),n=w(n,31),o(e[r]),n=w(n,30);return n>>>0}function at(t){let e=4;for(let s=0;s<t.length;s++){const c=t[s],i=c.fieldNames.length;e+=I+c.size*(b+i*O)}const n=new Uint8Array(e),o=new DataView(n.buffer);let r=0;o.setUint32(r,t.length,!0),r+=4;for(let s=0;s<t.length;s++){const c=t[s],i=c.fieldNames.length,h=c.canonicalIndices();o.setUint32(r,i,!0),r+=4,o.setUint32(r,D(c.fieldNames,c.fieldTypes),!0),r+=4,o.setUint32(r,h.length,!0),r+=4;for(let E=0;E<h.length;E++){const S=h[E];o.setUint32(r,S,!0),r+=4;const f=c.getRow(S);for(let _=0;_<i;_++)o.setFloat64(r,f[_],!0),r+=O}}return n}function it(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),o=e.byteLength;let r=0;const s=i=>{if(r+i>o)throw new u.SparseRestoreError(`sparse snapshot truncated: need ${i} more bytes at offset ${r}, have ${o-r}`)};s(4);const c=n.getUint32(r,!0);if(r+=4,c!==t.length)throw new u.SparseRestoreError(`sparse store count mismatch: snapshot=${c}, registered=${t.length}`);for(let i=0;i<t.length;i++){const h=t[i];s(I);const E=n.getUint32(r,!0);r+=4;const S=n.getUint32(r,!0);r+=4;const f=n.getUint32(r,!0);if(r+=4,E!==h.fieldNames.length)throw new u.SparseRestoreError(`sparse store ${i} field-count mismatch: snapshot=${E}, registered=${h.fieldNames.length}`);const _=D(h.fieldNames,h.fieldTypes);if(S!==_)throw new u.SparseRestoreError(`sparse store ${i} schema identity mismatch: snapshot hash=${S}, registered=${_} (same field count, different field names or types, likely a registration-order divergence between the snapshot and restore worlds)`);h.clear();for(let l=0;l<f;l++){s(b+E*O);const d=n.getUint32(r,!0);if(r+=4,d>R.MAX_INDEX)throw new u.SparseRestoreError(`sparse store ${i} member ${l} entity index ${d} exceeds MAX_INDEX (${R.MAX_INDEX})`);const p=new Array(E);for(let T=0;T<E;T++)p[T]=n.getFloat64(r,!0),r+=O;h.setRawRow(d,p)}}if(r!==o)throw new u.SparseRestoreError(`sparse snapshot has ${o-r} trailing bytes after the last store (not a canonical encoding)`)}function ct(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),o=e.byteLength;let r=0;const s=i=>{if(r+i>o)throw new u.SparseRestoreError(`sparse snapshot truncated: need ${i} more bytes at offset ${r}, have ${o-r}`)};s(4);const c=n.getUint32(r,!0);if(r+=4,c!==t.length)throw new u.SparseRestoreError(`sparse store count mismatch: snapshot=${c}, registered=${t.length}`);for(let i=0;i<t.length;i++){const h=t[i];s(I);const E=n.getUint32(r,!0);r+=4;const S=n.getUint32(r,!0);r+=4;const f=n.getUint32(r,!0);if(r+=4,E!==h.fieldNames.length)throw new u.SparseRestoreError(`sparse store ${i} field-count mismatch: snapshot=${E}, registered=${h.fieldNames.length}`);const _=D(h.fieldNames,h.fieldTypes);if(S!==_)throw new u.SparseRestoreError(`sparse store ${i} schema identity mismatch: snapshot hash=${S}, registered=${_} (same field count, different field names or types, likely a registration-order divergence between the snapshot and restore worlds)`);for(let l=0;l<f;l++){s(b+E*O);const d=n.getUint32(r,!0);if(r+=4,d>R.MAX_INDEX)throw new u.SparseRestoreError(`sparse store ${i} member ${l} entity index ${d} exceeds MAX_INDEX (${R.MAX_INDEX})`);r+=E*O}}if(r!==o)throw new u.SparseRestoreError(`sparse snapshot has ${o-r} trailing bytes after the last store (not a canonical encoding)`)}const m=1,A=810766935,y=4;function ht(t){const e=t.freeIndices.length,n=t.archetypeRows.length,o=y*(4+e+1+n*3),r=new Uint8Array(o),s=new DataView(r.buffer);let c=0;const i=h=>{s.setUint32(c,h,!0),c+=y};i(t.tick),i(t.entityHighWater),i(t.entityAliveCount),i(e);for(let h=0;h<e;h++)i(t.freeIndices[h]);i(n);for(let h=0;h<n;h++){const E=t.archetypeRows[h];i(E.archetypeId),i(E.length),i(E.enabledCount)}return r}function Et(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=t.byteLength;let o=0;const r=l=>{if(o+l>n)throw new u.ECSRestoreError(`host-state truncated: need ${l} more bytes at offset ${o}, have ${n-o}`)},s=()=>{r(y);const l=e.getUint32(o,!0);return o+=y,l},c=s(),i=s(),h=s(),E=s(),S=new Array(E);for(let l=0;l<E;l++)S[l]=s();const f=s(),_=new Array(f);for(let l=0;l<f;l++){const d=s(),p=s(),T=s();_[l]={archetypeId:d,length:p,enabledCount:T}}if(o!==n)throw new u.ECSRestoreError(`host-state has ${n-o} trailing bytes after the last archetype (not a canonical encoding)`);return{tick:c,entityHighWater:i,entityAliveCount:h,freeIndices:S,archetypeRows:_}}function ut(t,e,n){const o=y*5,r=new Uint8Array(o+t.length+e.length+n.length),s=new DataView(r.buffer);return s.setUint32(0,A,!0),s.setUint32(4,m,!0),s.setUint32(8,t.length,!0),s.setUint32(12,e.length,!0),s.setUint32(16,n.length,!0),r.set(t,o),r.set(e,o+t.length),r.set(n,o+t.length+e.length),r}function lt(t){const e=y*5;if(t.byteLength<e)throw new u.ECSRestoreError(`world snapshot too small: ${t.byteLength} bytes (frame header needs ${e})`);const n=new DataView(t.buffer,t.byteOffset,t.byteLength),o=n.getUint32(0,!0);if(o!==A)throw new u.ECSRestoreError(`bad world-snapshot magic: 0x${o.toString(16).padStart(8,"0")} (expected 0x${A.toString(16).padStart(8,"0")}). A bare dense (SAB) snapshot is not a combined world snapshot, pass the bytes from ECS.snapshot(), not columnStoreBytesView().`);const r=n.getUint32(4,!0);if(r!==m)throw new u.ECSRestoreError(`incompatible world-snapshot version: snapshot=${r}, build=${m}`);const s=n.getUint32(8,!0),c=n.getUint32(12,!0),i=n.getUint32(16,!0);if(e+s+c+i!==t.byteLength)throw new u.ECSRestoreError(`world-snapshot frame mismatch: header declares ${e}+${s}+${c}+${i}=${e+s+c+i} bytes, buffer is ${t.byteLength}`);const h=t.byteOffset,E=t.buffer;return{dense:new Uint8Array(E,h+e,s),sparse:new Uint8Array(E,h+e+s,c),host:new Uint8Array(E,h+e+s+c,i)}}function St(t,e,n){if(t.byteLength<a.STORE_HEADER_BYTES)throw new u.ECSRestoreError(`dense section too small: ${t.byteLength} bytes (SAB header needs ${a.STORE_HEADER_BYTES})`);const o=new DataView(t.buffer,t.byteOffset,t.byteLength),r=o.getUint32(a.STORE_HEADER_OFFSETS.magic,!0);if(r!==a.STORE_MAGIC)throw new u.ECSRestoreError(`dense section bad magic: 0x${r.toString(16).padStart(8,"0")} (expected SAB magic 0x${a.STORE_MAGIC.toString(16).padStart(8,"0")})`);const s=o.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0);if(s!==a.SIM_ABI_VERSION&&s!==a.LEGACY_ABSOLUTE_ABI_VERSION)throw new u.ECSRestoreError(`dense section incompatible sim_abi_version: snapshot=${s}, build=${a.SIM_ABI_VERSION}`);const c=F(o);if(c.layoutDescriptorOff<0||c.layoutDescriptorOff>t.byteLength)throw new u.ECSRestoreError(`dense layoutDescriptorOff ${c.layoutDescriptorOff} is outside the section (${t.byteLength} bytes)`);const i=c.entityIndexOff;if(i<0||i+X>t.byteLength)throw new u.ECSRestoreError(`dense entityIndexOff ${i} is outside the section (${t.byteLength} bytes)`);const h=o.getUint32(i+W.capacity,!0);if(h!==n)throw new u.ECSRestoreError(`entity-index capacity mismatch: live=${n}, snapshot=${h}`);let E;try{E=C(o,c.layoutDescriptorOff,c.archetypeCount,s===a.LEGACY_ABSOLUTE_ABI_VERSION?a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES:a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES)}catch(S){throw S instanceof RangeError?new u.ECSRestoreError(`dense section layout is corrupt or truncated: a descriptor reads past the ${t.byteLength}-byte section (${S.message})`):S}if(e.size!==E.length)throw new u.ECSRestoreError(`archetype-set mismatch: the live world has ${e.size} SAB archetypes, the snapshot has ${E.length}. restore requires an identical archetype set. Prewarm the world so its archetype set is stable.`);for(let S=0;S<E.length;S++){const f=E[S],_=e.get(f.archetypeId);if(_===void 0)throw new u.ECSRestoreError(`archetype-set mismatch: snapshot archetype ${f.archetypeId} is absent from the live world`);if(!ft(_.componentMask,f.componentMask))throw new u.ECSRestoreError(`archetype ${f.archetypeId} component-mask mismatch between the live world and the snapshot (different component registration)`);const l=_.columnsInOrder,d=f.columns;if(l.length!==d.length)throw new u.ECSRestoreError(`archetype ${f.archetypeId} column-count mismatch: live=${l.length}, snapshot=${d.length}`);for(let p=0;p<l.length;p++)if(l[p].componentId!==d[p].componentId||l[p].fieldId!==d[p].fieldId||l[p].typeTag!==d[p].typeTag)throw new u.ECSRestoreError(`archetype ${f.archetypeId} column ${p} layout mismatch: live=(c${l[p].componentId},f${l[p].fieldId},t${l[p].typeTag}), snapshot=(c${d[p].componentId},f${d[p].fieldId},t${d[p].typeTag})`)}}function ft(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}class _t{_host;_allocator;constructor(e,n){this._host=e,this._allocator=n}snapshotSparse(){const e=at(this._host.sparseStores()),n=R.snapshotRelations(this._host.relationStores()),o=new Uint8Array(8+e.length+n.length),r=new DataView(o.buffer);return r.setUint32(0,e.length,!0),r.setUint32(4,n.length,!0),o.set(e,8),o.set(n,8+e.length),o}restoreSparse(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw new u.SparseRestoreError(`sparse snapshot truncated: need 8 header bytes, have ${e.byteLength}`);const o=n.getUint32(0,!0),r=n.getUint32(4,!0);if(8+o+r!==e.byteLength)throw new u.SparseRestoreError(`sparse snapshot frame mismatch: header declares 8+${o}+${r}=${8+o+r} bytes, buffer is ${e.byteLength}`);it(this._host.sparseStores(),e.subarray(8,8+o)),this._rebuildRelationIndices(e.subarray(8+o,8+o+r))}_rebuildRelationIndices(e){const n=this._host.generations(),o=s=>R.createEntityId(s,n[s]),r=this._host.relationStores();R.restoreRelations(r,e,o);for(let s=0;s<r.length;s++)r[s].rebuildReverse(o)}snapshot(){this._host.publishRowCounts();const e=new Uint8Array(Z(this._host.columnStore())),n=this.snapshotSparse(),o=ht(this._collectHostState());return ut(e,n,o)}_collectHostState(){const e=[],n=this._host.archetypes();for(let o=0;o<n.length;o++){const r=n[o];r.isBufferBacked&&e.push({archetypeId:r.id,length:r.length,enabledCount:r.enabledCount})}return{tick:this._host.tick(),entityHighWater:this._allocator.highWater,entityAliveCount:this._allocator.aliveCount,freeIndices:this._allocator.snapshotFreeIndices(),archetypeRows:e}}restore(e){const n=lt(e),o=Et(n.host);St(n.dense,this._host.columnStore().archetypes,this._host.entityIndexCapacity()),this._assertSparseMatchesLive(n.sparse);const r=nt(n.dense,this._host.bufferAllocator(),{storeBase:this._host.columnStore().storeBase});this._host.mountRestoredDense(r),this._host.reconstructHostRows(o),this._allocator.restoreHostState(o.freeIndices,o.entityAliveCount),this._host.setTick(o.tick),this._host.invalidateCaches(),this.restoreSparse(n.sparse)}_assertSparseMatchesLive(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw new u.SparseRestoreError(`sparse snapshot truncated: need 8 header bytes, have ${e.byteLength}`);const o=n.getUint32(0,!0),r=n.getUint32(4,!0);if(8+o+r!==e.byteLength)throw new u.SparseRestoreError(`sparse snapshot frame mismatch: header declares 8+${o}+${r}=${8+o+r} bytes, buffer is ${e.byteLength}`);ct(this._host.sparseStores(),e.subarray(8,8+o))}}class L{_store;constructor(e){this._store=e}get deterministic(){return this._store.deterministic}stateHash(){return this._store.stateHash()}}for(const t of["capture","restore","captureSparse","restoreSparse"])L.prototype[t]=function(){throw P.pluginMissingError("snapshots",`ecs.snapshots.${t}`)};class H extends L{capture(){return this._store.snapshot()}restore(e){this._store.restore(e)}captureSparse(){return this._store.snapshotSparse()}restoreSparse(e){this._store.restoreSparse(e)}}function pt(){return{name:"snapshots",install(t){const e=t.store;return e.installSnapshots(new _t(e.snapshotHost(),e.entityAllocator)),{snapshots:new H(e)}}}}exports.ECSSnapshotsFull=H;exports.snapshots=pt;
@@ -0,0 +1 @@
1
+ export * from "./snapshots/index.cjs";
@@ -0,0 +1 @@
1
+ export * from "./snapshots/index.js";
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./relation_store-RBhpcE28.cjs"),u=require("../index.development.cjs"),a=require("./abi-D3V-QUSf.cjs"),P=require("../internal.development.cjs");function F(t){return{magic:t.getUint32(a.STORE_HEADER_OFFSETS.magic,!0),simAbiVersion:t.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0),viewStamp:t.getUint32(a.STORE_HEADER_OFFSETS.view_stamp,!0),capacity:t.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0),archetypeCount:t.getUint32(a.STORE_HEADER_OFFSETS.archetype_count,!0),layoutDescriptorOff:t.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0),commandRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.command_ring_off,!0),actionRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.action_ring_off,!0),entityIndexOff:t.getUint32(a.STORE_HEADER_OFFSETS.entity_index_off,!0),eventRingOff:t.getUint32(a.STORE_HEADER_OFFSETS.event_ring_off,!0),regionTableOff:t.getUint32(a.STORE_HEADER_OFFSETS.region_table_off,!0),regionTableCount:t.getUint32(a.STORE_HEADER_OFFSETS.region_table_count,!0),bindingsOff:t.getUint32(a.STORE_HEADER_OFFSETS.bindings_off,!0)}}const g={u8:0,i8:1,u16:2,i16:3,u32:4,i32:5,f32:6,f64:7},B=Object.freeze({[g.u8]:1,[g.i8]:1,[g.u16]:2,[g.i16]:2,[g.u32]:4,[g.i32]:4,[g.f32]:4,[g.f64]:8});function N(t,e,n){t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.component_id,n.componentId,!0),t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.field_id,n.fieldId,!0),t.setUint8(e+a.COLUMN_DESCRIPTOR_OFFSETS.type_tag,n.typeTag),t.setUint32(e+a.COLUMN_DESCRIPTOR_OFFSETS.byte_off,n.byteOff,!0),t.setUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.stride,n.stride,!0)}function M(t,e){return{componentId:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.component_id,!0),fieldId:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.field_id,!0),typeTag:t.getUint8(e+a.COLUMN_DESCRIPTOR_OFFSETS.type_tag),byteOff:t.getUint32(e+a.COLUMN_DESCRIPTOR_OFFSETS.byte_off,!0),stride:t.getUint16(e+a.COLUMN_DESCRIPTOR_OFFSETS.stride,!0)}}function Y(t,e=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){return e+t*a.COLUMN_DESCRIPTOR_BYTES}function V(t,e,n){t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.archetype_id,n.archetypeId,!0);for(let r=0;r<a.COMPONENT_MASK_WORDS;r++)t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.component_mask+r*4,n.componentMask[r]??0,!0);t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_count,n.rowCount,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_capacity,n.rowCapacity,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.column_count,n.columns.length,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.enabled_count,n.enabledCount,!0),t.setUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.entity_ids_off,0,!0);let o=e+a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES;for(let r=0;r<n.columns.length;r++)N(t,o,n.columns[r]),o+=a.COLUMN_DESCRIPTOR_BYTES;return o}function v(t,e,n=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){const o=t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.column_count,!0),r=new Array(o);let s=e+n;for(let i=0;i<o;i++)r[i]=M(t,s),s+=a.COLUMN_DESCRIPTOR_BYTES;const c=new Array(a.COMPONENT_MASK_WORDS);for(let i=0;i<a.COMPONENT_MASK_WORDS;i++)c[i]=t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.component_mask+i*4,!0);return{archetypeId:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.archetype_id,!0),componentMask:c,rowCount:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_count,!0),rowCapacity:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.row_capacity,!0),enabledCount:t.getUint32(e+a.ARCHETYPE_DESCRIPTOR_OFFSETS.enabled_count,!0),columns:r}}function x(t,e,n){let o=e;for(let r=0;r<n.length;r++)o=V(t,o,n[r]);return o}function C(t,e,n,o=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES){const r=new Array(n);let s=e;for(let c=0;c<n;c++){const i=v(t,s,o);r[c]=i,s+=Y(i.columns.length,o)}return r}class k extends Error{constructor(){super('SharedArrayBuffer is not available in this runtime. The chosen world backing is SAB-based and cannot start without it. In browsers this requires cross-origin isolation: serve the page with `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (or `credentialless`). Alternatively choose the pure-TS heap profile (`memory: { backing: "heap" }`), which is backed by a plain ArrayBuffer and needs no SAB and no COOP+COEP. In Bun or Node SAB is available unconditionally. If you see this there, the runtime is older than expected, or the global was shadowed.'),this.name="SabUnavailableError"}}const G=t=>{if(typeof SharedArrayBuffer>"u")throw new k;return new SharedArrayBuffer(t)},X=16,W={capacity:4};function q(t,e){return t<<16|e}const $=2**31;class z extends Error{constructor(e){super(`SAB column layout offset ${e} reaches or exceeds the 2³¹ (${$}-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.`),this.name="StoreLayoutOverflowError"}}function j(t,e){if(t+e>$)throw new z(t);return t+(e-1)&~(e-1)}function K(t,e,n,o,r){const s=e+o;switch(n){case g.u8:return new Uint8Array(t,s,r);case g.i8:return new Int8Array(t,s,r);case g.u16:return new Uint16Array(t,s,r);case g.i16:return new Int16Array(t,s,r);case g.u32:return new Uint32Array(t,s,r);case g.i32:return new Int32Array(t,s,r);case g.f32:return new Float32Array(t,s,r);case g.f64:return new Float64Array(t,s,r)}}const U=16;function J(t){if(!Number.isInteger(t)||t<0)throw new RangeError(`createColumnStore: storeBase must be an integer >= 0, got ${t}`);if(t%U!==0)throw new RangeError(`createColumnStore: storeBase must be a multiple of ${U}, got ${t}`)}function Q(t,e,n){const o=new Map;for(let r=0;r<n.length;r++){const s=n[r],c=new Array(s.columns.length),i=new Map;for(let h=0;h<s.columns.length;h++){const E=s.columns[h],S={componentId:E.componentId,fieldId:E.fieldId,typeTag:E.typeTag,byteOff:E.byteOff,stride:E.stride,view:K(t,e,E.typeTag,E.byteOff,s.rowCapacity)};c[h]=S,i.set(q(E.componentId,E.fieldId),S)}o.set(s.archetypeId,{archetypeId:s.archetypeId,componentMask:s.componentMask,rowCapacity:s.rowCapacity,columns:i,columnsInOrder:c})}return o}function Z(t){const e=t.view.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0);return new Uint8Array(t.buffer,t.storeBase,e)}const tt=Math.max(...Object.values(B));function et(t){const e=a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES-a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES;return j(t*e,tt)}function rt(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=e.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0),o=e.getUint32(a.STORE_HEADER_OFFSETS.archetype_count,!0),r=et(o);if(r===0)return t;const s=C(e,n,o,a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES),c=new Uint8Array(t.byteLength+r);c.set(t.subarray(0,n),0),c.set(t.subarray(n),n+r);const i=new DataView(c.buffer),h=s.map(S=>({...S,columns:S.columns.map(f=>({...f,byteOff:f.byteOff+r}))}));x(i,n,h);const E=e.getUint32(a.STORE_HEADER_OFFSETS.capacity,!0);return i.setUint32(a.STORE_HEADER_OFFSETS.capacity,E+r,!0),c}function nt(t,e=G,n={}){const o=n.storeBase??0;J(o);const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<a.STORE_HEADER_BYTES)throw new u.StoreRestoreError(`snapshot too small: ${t.byteLength} bytes (header alone needs ${a.STORE_HEADER_BYTES})`);const s=r.getUint32(a.STORE_HEADER_OFFSETS.magic,!0);if(s!==a.STORE_MAGIC)throw new u.StoreRestoreError(`bad magic: 0x${s.toString(16).padStart(8,"0")} (expected 0x${a.STORE_MAGIC.toString(16).padStart(8,"0")})`);const c=r.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0);if(c!==a.SIM_ABI_VERSION&&c!==a.LEGACY_ABSOLUTE_ABI_VERSION)throw new u.StoreRestoreError(`incompatible sim_abi_version: snapshot=${c}, build=${a.SIM_ABI_VERSION}`);const i=r.getUint32(a.STORE_HEADER_OFFSETS.layout_descriptor_off,!0);if(i>t.byteLength)throw new u.StoreRestoreError(`layout_descriptor_off ${i} is outside the snapshot (${t.byteLength} bytes)`);let h=t;if(c===a.LEGACY_ABSOLUTE_ABI_VERSION)try{h=rt(t)}catch(_){throw _ instanceof RangeError?new u.StoreRestoreError(`snapshot layout is corrupt or truncated: a version 0 descriptor reads past the ${t.byteLength}-byte span (${_.message})`):_}const E=e(o+h.byteLength);new Uint8Array(E,o,h.byteLength).set(h);const S=new DataView(E,o);S.setUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,a.SIM_ABI_VERSION,!0);const f=F(S);if(f.layoutDescriptorOff<0||f.layoutDescriptorOff>h.byteLength)throw new u.StoreRestoreError(`layout_descriptor_off ${f.layoutDescriptorOff} is outside the snapshot (${h.byteLength} bytes)`);try{const _=C(S,f.layoutDescriptorOff,f.archetypeCount),l=Q(E,o,_);return{buffer:E,view:S,header:f,storeBase:o,archetypes:l}}catch(_){throw _ instanceof RangeError?new u.StoreRestoreError(`snapshot layout is corrupt or truncated: a descriptor offset or column extent reads past the ${h.byteLength}-byte span (${_.message})`):_}}const ot=2166136261,st=16777619;function w(t,e){return t=(t^e&255)>>>0,Math.imul(t,st)>>>0}const I=12,b=4,O=8;function D(t,e){let n=ot;const o=r=>{for(let s=0;s<r.length;s++)n=w(n,r.charCodeAt(s))};for(let r=0;r<t.length;r++)o(t[r]),n=w(n,31),o(e[r]),n=w(n,30);return n>>>0}function at(t){let e=4;for(let s=0;s<t.length;s++){const c=t[s],i=c.fieldNames.length;e+=I+c.size*(b+i*O)}const n=new Uint8Array(e),o=new DataView(n.buffer);let r=0;o.setUint32(r,t.length,!0),r+=4;for(let s=0;s<t.length;s++){const c=t[s],i=c.fieldNames.length,h=c.canonicalIndices();o.setUint32(r,i,!0),r+=4,o.setUint32(r,D(c.fieldNames,c.fieldTypes),!0),r+=4,o.setUint32(r,h.length,!0),r+=4;for(let E=0;E<h.length;E++){const S=h[E];o.setUint32(r,S,!0),r+=4;const f=c.getRow(S);for(let _=0;_<i;_++)o.setFloat64(r,f[_],!0),r+=O}}return n}function it(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),o=e.byteLength;let r=0;const s=i=>{if(r+i>o)throw new u.SparseRestoreError(`sparse snapshot truncated: need ${i} more bytes at offset ${r}, have ${o-r}`)};s(4);const c=n.getUint32(r,!0);if(r+=4,c!==t.length)throw new u.SparseRestoreError(`sparse store count mismatch: snapshot=${c}, registered=${t.length}`);for(let i=0;i<t.length;i++){const h=t[i];s(I);const E=n.getUint32(r,!0);r+=4;const S=n.getUint32(r,!0);r+=4;const f=n.getUint32(r,!0);if(r+=4,E!==h.fieldNames.length)throw new u.SparseRestoreError(`sparse store ${i} field-count mismatch: snapshot=${E}, registered=${h.fieldNames.length}`);const _=D(h.fieldNames,h.fieldTypes);if(S!==_)throw new u.SparseRestoreError(`sparse store ${i} schema identity mismatch: snapshot hash=${S}, registered=${_} (same field count, different field names or types, likely a registration-order divergence between the snapshot and restore worlds)`);h.clear();for(let l=0;l<f;l++){s(b+E*O);const d=n.getUint32(r,!0);if(r+=4,d>R.MAX_INDEX)throw new u.SparseRestoreError(`sparse store ${i} member ${l} entity index ${d} exceeds MAX_INDEX (${R.MAX_INDEX})`);const p=new Array(E);for(let T=0;T<E;T++)p[T]=n.getFloat64(r,!0),r+=O;h.setRawRow(d,p)}}if(r!==o)throw new u.SparseRestoreError(`sparse snapshot has ${o-r} trailing bytes after the last store (not a canonical encoding)`)}function ct(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),o=e.byteLength;let r=0;const s=i=>{if(r+i>o)throw new u.SparseRestoreError(`sparse snapshot truncated: need ${i} more bytes at offset ${r}, have ${o-r}`)};s(4);const c=n.getUint32(r,!0);if(r+=4,c!==t.length)throw new u.SparseRestoreError(`sparse store count mismatch: snapshot=${c}, registered=${t.length}`);for(let i=0;i<t.length;i++){const h=t[i];s(I);const E=n.getUint32(r,!0);r+=4;const S=n.getUint32(r,!0);r+=4;const f=n.getUint32(r,!0);if(r+=4,E!==h.fieldNames.length)throw new u.SparseRestoreError(`sparse store ${i} field-count mismatch: snapshot=${E}, registered=${h.fieldNames.length}`);const _=D(h.fieldNames,h.fieldTypes);if(S!==_)throw new u.SparseRestoreError(`sparse store ${i} schema identity mismatch: snapshot hash=${S}, registered=${_} (same field count, different field names or types, likely a registration-order divergence between the snapshot and restore worlds)`);for(let l=0;l<f;l++){s(b+E*O);const d=n.getUint32(r,!0);if(r+=4,d>R.MAX_INDEX)throw new u.SparseRestoreError(`sparse store ${i} member ${l} entity index ${d} exceeds MAX_INDEX (${R.MAX_INDEX})`);r+=E*O}}if(r!==o)throw new u.SparseRestoreError(`sparse snapshot has ${o-r} trailing bytes after the last store (not a canonical encoding)`)}const m=1,A=810766935,y=4;function ht(t){const e=t.freeIndices.length,n=t.archetypeRows.length,o=y*(4+e+1+n*3),r=new Uint8Array(o),s=new DataView(r.buffer);let c=0;const i=h=>{s.setUint32(c,h,!0),c+=y};i(t.tick),i(t.entityHighWater),i(t.entityAliveCount),i(e);for(let h=0;h<e;h++)i(t.freeIndices[h]);i(n);for(let h=0;h<n;h++){const E=t.archetypeRows[h];i(E.archetypeId),i(E.length),i(E.enabledCount)}return r}function Et(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=t.byteLength;let o=0;const r=l=>{if(o+l>n)throw new u.ECSRestoreError(`host-state truncated: need ${l} more bytes at offset ${o}, have ${n-o}`)},s=()=>{r(y);const l=e.getUint32(o,!0);return o+=y,l},c=s(),i=s(),h=s(),E=s(),S=new Array(E);for(let l=0;l<E;l++)S[l]=s();const f=s(),_=new Array(f);for(let l=0;l<f;l++){const d=s(),p=s(),T=s();_[l]={archetypeId:d,length:p,enabledCount:T}}if(o!==n)throw new u.ECSRestoreError(`host-state has ${n-o} trailing bytes after the last archetype (not a canonical encoding)`);return{tick:c,entityHighWater:i,entityAliveCount:h,freeIndices:S,archetypeRows:_}}function ut(t,e,n){const o=y*5,r=new Uint8Array(o+t.length+e.length+n.length),s=new DataView(r.buffer);return s.setUint32(0,A,!0),s.setUint32(4,m,!0),s.setUint32(8,t.length,!0),s.setUint32(12,e.length,!0),s.setUint32(16,n.length,!0),r.set(t,o),r.set(e,o+t.length),r.set(n,o+t.length+e.length),r}function lt(t){const e=y*5;if(t.byteLength<e)throw new u.ECSRestoreError(`world snapshot too small: ${t.byteLength} bytes (frame header needs ${e})`);const n=new DataView(t.buffer,t.byteOffset,t.byteLength),o=n.getUint32(0,!0);if(o!==A)throw new u.ECSRestoreError(`bad world-snapshot magic: 0x${o.toString(16).padStart(8,"0")} (expected 0x${A.toString(16).padStart(8,"0")}). A bare dense (SAB) snapshot is not a combined world snapshot, pass the bytes from ECS.snapshot(), not columnStoreBytesView().`);const r=n.getUint32(4,!0);if(r!==m)throw new u.ECSRestoreError(`incompatible world-snapshot version: snapshot=${r}, build=${m}`);const s=n.getUint32(8,!0),c=n.getUint32(12,!0),i=n.getUint32(16,!0);if(e+s+c+i!==t.byteLength)throw new u.ECSRestoreError(`world-snapshot frame mismatch: header declares ${e}+${s}+${c}+${i}=${e+s+c+i} bytes, buffer is ${t.byteLength}`);const h=t.byteOffset,E=t.buffer;return{dense:new Uint8Array(E,h+e,s),sparse:new Uint8Array(E,h+e+s,c),host:new Uint8Array(E,h+e+s+c,i)}}function St(t,e,n){if(t.byteLength<a.STORE_HEADER_BYTES)throw new u.ECSRestoreError(`dense section too small: ${t.byteLength} bytes (SAB header needs ${a.STORE_HEADER_BYTES})`);const o=new DataView(t.buffer,t.byteOffset,t.byteLength),r=o.getUint32(a.STORE_HEADER_OFFSETS.magic,!0);if(r!==a.STORE_MAGIC)throw new u.ECSRestoreError(`dense section bad magic: 0x${r.toString(16).padStart(8,"0")} (expected SAB magic 0x${a.STORE_MAGIC.toString(16).padStart(8,"0")})`);const s=o.getUint32(a.STORE_HEADER_OFFSETS.sim_abi_version,!0);if(s!==a.SIM_ABI_VERSION&&s!==a.LEGACY_ABSOLUTE_ABI_VERSION)throw new u.ECSRestoreError(`dense section incompatible sim_abi_version: snapshot=${s}, build=${a.SIM_ABI_VERSION}`);const c=F(o);if(c.layoutDescriptorOff<0||c.layoutDescriptorOff>t.byteLength)throw new u.ECSRestoreError(`dense layoutDescriptorOff ${c.layoutDescriptorOff} is outside the section (${t.byteLength} bytes)`);const i=c.entityIndexOff;if(i<0||i+X>t.byteLength)throw new u.ECSRestoreError(`dense entityIndexOff ${i} is outside the section (${t.byteLength} bytes)`);const h=o.getUint32(i+W.capacity,!0);if(h!==n)throw new u.ECSRestoreError(`entity-index capacity mismatch: live=${n}, snapshot=${h}`);let E;try{E=C(o,c.layoutDescriptorOff,c.archetypeCount,s===a.LEGACY_ABSOLUTE_ABI_VERSION?a.LEGACY_ARCHETYPE_DESCRIPTOR_HEADER_BYTES:a.ARCHETYPE_DESCRIPTOR_HEADER_BYTES)}catch(S){throw S instanceof RangeError?new u.ECSRestoreError(`dense section layout is corrupt or truncated: a descriptor reads past the ${t.byteLength}-byte section (${S.message})`):S}if(e.size!==E.length)throw new u.ECSRestoreError(`archetype-set mismatch: the live world has ${e.size} SAB archetypes, the snapshot has ${E.length}. restore requires an identical archetype set. Prewarm the world so its archetype set is stable.`);for(let S=0;S<E.length;S++){const f=E[S],_=e.get(f.archetypeId);if(_===void 0)throw new u.ECSRestoreError(`archetype-set mismatch: snapshot archetype ${f.archetypeId} is absent from the live world`);if(!ft(_.componentMask,f.componentMask))throw new u.ECSRestoreError(`archetype ${f.archetypeId} component-mask mismatch between the live world and the snapshot (different component registration)`);const l=_.columnsInOrder,d=f.columns;if(l.length!==d.length)throw new u.ECSRestoreError(`archetype ${f.archetypeId} column-count mismatch: live=${l.length}, snapshot=${d.length}`);for(let p=0;p<l.length;p++)if(l[p].componentId!==d[p].componentId||l[p].fieldId!==d[p].fieldId||l[p].typeTag!==d[p].typeTag)throw new u.ECSRestoreError(`archetype ${f.archetypeId} column ${p} layout mismatch: live=(c${l[p].componentId},f${l[p].fieldId},t${l[p].typeTag}), snapshot=(c${d[p].componentId},f${d[p].fieldId},t${d[p].typeTag})`)}}function ft(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}class _t{_host;_allocator;constructor(e,n){this._host=e,this._allocator=n}snapshotSparse(){const e=at(this._host.sparseStores()),n=R.snapshotRelations(this._host.relationStores()),o=new Uint8Array(8+e.length+n.length),r=new DataView(o.buffer);return r.setUint32(0,e.length,!0),r.setUint32(4,n.length,!0),o.set(e,8),o.set(n,8+e.length),o}restoreSparse(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw new u.SparseRestoreError(`sparse snapshot truncated: need 8 header bytes, have ${e.byteLength}`);const o=n.getUint32(0,!0),r=n.getUint32(4,!0);if(8+o+r!==e.byteLength)throw new u.SparseRestoreError(`sparse snapshot frame mismatch: header declares 8+${o}+${r}=${8+o+r} bytes, buffer is ${e.byteLength}`);it(this._host.sparseStores(),e.subarray(8,8+o)),this._rebuildRelationIndices(e.subarray(8+o,8+o+r))}_rebuildRelationIndices(e){const n=this._host.generations(),o=s=>R.createEntityId(s,n[s]),r=this._host.relationStores();R.restoreRelations(r,e,o);for(let s=0;s<r.length;s++)r[s].rebuildReverse(o)}snapshot(){this._host.publishRowCounts();const e=new Uint8Array(Z(this._host.columnStore())),n=this.snapshotSparse(),o=ht(this._collectHostState());return ut(e,n,o)}_collectHostState(){const e=[],n=this._host.archetypes();for(let o=0;o<n.length;o++){const r=n[o];r.isBufferBacked&&e.push({archetypeId:r.id,length:r.length,enabledCount:r.enabledCount})}return{tick:this._host.tick(),entityHighWater:this._allocator.highWater,entityAliveCount:this._allocator.aliveCount,freeIndices:this._allocator.snapshotFreeIndices(),archetypeRows:e}}restore(e){const n=lt(e),o=Et(n.host);St(n.dense,this._host.columnStore().archetypes,this._host.entityIndexCapacity()),this._assertSparseMatchesLive(n.sparse);const r=nt(n.dense,this._host.bufferAllocator(),{storeBase:this._host.columnStore().storeBase});this._host.mountRestoredDense(r),this._host.reconstructHostRows(o),this._allocator.restoreHostState(o.freeIndices,o.entityAliveCount),this._host.setTick(o.tick),this._host.invalidateCaches(),this.restoreSparse(n.sparse)}_assertSparseMatchesLive(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw new u.SparseRestoreError(`sparse snapshot truncated: need 8 header bytes, have ${e.byteLength}`);const o=n.getUint32(0,!0),r=n.getUint32(4,!0);if(8+o+r!==e.byteLength)throw new u.SparseRestoreError(`sparse snapshot frame mismatch: header declares 8+${o}+${r}=${8+o+r} bytes, buffer is ${e.byteLength}`);ct(this._host.sparseStores(),e.subarray(8,8+o))}}class L{_store;constructor(e){this._store=e}get deterministic(){return this._store.deterministic}stateHash(){return this._store.stateHash()}}for(const t of["capture","restore","captureSparse","restoreSparse"])L.prototype[t]=function(){throw P.pluginMissingError("snapshots",`ecs.snapshots.${t}`)};class H extends L{capture(){return this._store.snapshot()}restore(e){this._store.restore(e)}captureSparse(){return this._store.snapshotSparse()}restoreSparse(e){this._store.restoreSparse(e)}}function pt(){return{name:"snapshots",install(t){const e=t.store;return e.installSnapshots(new _t(e.snapshotHost(),e.entityAllocator)),{snapshots:new H(e)}}}}exports.ECSSnapshotsFull=H;exports.snapshots=pt;