wallhammer-web 0.0.0-stage → 0.4.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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,11 @@
1
+ export { TIMELINE, TIMELINE_TICK_S, applyEvent, applyEventToAll, destructionEvent, fallTimeline } from './apply.ts';
2
+ export type { ChangeCause, DestructionOptions, DestructionResult, PartChange } from './apply.ts';
3
+ export { compileStructure, solveSupport, UNSUPPORTED } from './structure.ts';
4
+ export type { CompiledStructure } from './structure.ts';
5
+ export { partRubble, rubbleFootprints, ruinRubble } from './rubble.ts';
6
+ export { decodeStates, encodeStates, intactState, isIntact, sortedEntries, stateHash } from './state.ts';
7
+ export { raycastParts } from './pick.ts';
8
+ export type { PartHit } from './pick.ts';
9
+ export { octant, pieceDistSq } from './int-geometry.ts';
10
+ export { CELL_STATES_CHARS_PER_UNIT, CellStates, DEFAULT_MAX_UNITS, decodeCellStates } from './cell-states.ts';
11
+ export type { CommitResult } from './cell-states.ts';
@@ -0,0 +1,10 @@
1
+ // sim/destruction: tier A destruction. Pure functions over structure descriptions (base/destructible.ts) and their
2
+ // damage states: what an event breaks, what loses support, where rubble lies, and the compact, hashable state.
3
+ // No GPU, no DOM, no clock; runs in Node. Feeding events from the simulation's queue is a later step.
4
+ export { TIMELINE, TIMELINE_TICK_S, applyEvent, applyEventToAll, destructionEvent, fallTimeline } from './apply.js';
5
+ export { compileStructure, solveSupport, UNSUPPORTED } from './structure.js';
6
+ export { partRubble, rubbleFootprints, ruinRubble } from './rubble.js';
7
+ export { decodeStates, encodeStates, intactState, isIntact, sortedEntries, stateHash } from './state.js';
8
+ export { raycastParts } from './pick.js';
9
+ export { octant, pieceDistSq } from './int-geometry.js';
10
+ export { CELL_STATES_CHARS_PER_UNIT, CellStates, DEFAULT_MAX_UNITS, decodeCellStates } from './cell-states.js';
@@ -0,0 +1,17 @@
1
+ import type { ConvexPiece } from '../../base/destructible.ts';
2
+ /** Floor of the square root of a non-negative integer below 2^53. Exact: the float estimate is corrected with integers. */
3
+ export declare function isqrt(n: number): number;
4
+ /** Integer division rounded toward zero. */
5
+ export declare function idiv(a: number, b: number): number;
6
+ /** Squared distance from a point to a convex prism, 0 inside. Centimetres in, cm² out. */
7
+ export declare function pieceDistSq(piece: ConvexPiece, px: number, py: number, pz: number): number;
8
+ /** Centroid of the corners (x, z) and the middle height, integers. */
9
+ export declare function pieceCentre(piece: ConvexPiece): [number, number, number];
10
+ /** Longest edge of the polygon as an integer vector. */
11
+ export declare function longestEdge(xz: Int32Array): [number, number];
12
+ /** Unit vector scaled by 1024, from an integer vector. (1024, 0) for a zero vector. */
13
+ export declare function unit1024(dx: number, dz: number): [number, number];
14
+ /** Compass octant of a direction (0 = +x, counted toward +z), or 8 when the vector is shorter than `minLen`. */
15
+ export declare function octant(dx: number, dz: number, minLen: number): number;
16
+ /** Octant directions scaled by 1024 (724 ≈ 1024 / √2). */
17
+ export declare const OCTANT_DIRS: readonly (readonly [number, number])[];
@@ -0,0 +1,131 @@
1
+ // Integer geometry for decisions: square roots, distances from a point to a convex prism, octants. Every result is an
2
+ // exact function of integer input (centimetres), so it is the same on every machine. The one division that could
3
+ // leave the exactly representable range runs on BigInt.
4
+ /** Floor of the square root of a non-negative integer below 2^53. Exact: the float estimate is corrected with integers. */
5
+ export function isqrt(n) {
6
+ if (n < 2)
7
+ return n < 0 ? 0 : n;
8
+ let x = Math.floor(Math.sqrt(n));
9
+ while (x * x > n)
10
+ x--;
11
+ while ((x + 1) * (x + 1) <= n)
12
+ x++;
13
+ return x;
14
+ }
15
+ /** Integer division rounded toward zero. */
16
+ export function idiv(a, b) {
17
+ return Math.trunc(a / b);
18
+ }
19
+ /** Squared distance from point p to the segment a–b in the x, z plane (all integers, result floored). */
20
+ function segmentDistSq(ax, az, bx, bz, px, pz) {
21
+ const rx = ax - px;
22
+ const rz = az - pz;
23
+ const ex = bx - ax;
24
+ const ez = bz - az;
25
+ const tNum = -(rx * ex + rz * ez);
26
+ const len2 = ex * ex + ez * ez;
27
+ if (tNum <= 0 || len2 === 0)
28
+ return rx * rx + rz * rz;
29
+ if (tNum >= len2) {
30
+ const sx = bx - px;
31
+ const sz = bz - pz;
32
+ return sx * sx + sz * sz;
33
+ }
34
+ const cross = BigInt(rx * ez - rz * ex);
35
+ return Number((cross * cross) / BigInt(len2));
36
+ }
37
+ /** Squared distance from a point to a convex prism, 0 inside. Centimetres in, cm² out. */
38
+ export function pieceDistSq(piece, px, py, pz) {
39
+ const dy = py < piece.y0 ? piece.y0 - py : py > piece.y1 ? py - piece.y1 : 0;
40
+ const c = piece.xz;
41
+ const n = c.length / 2;
42
+ let inside = true;
43
+ for (let i = 0; i < n; i++) {
44
+ const j = (i + 1) % n;
45
+ const ax = c[i * 2];
46
+ const az = c[i * 2 + 1];
47
+ const cross = (c[j * 2] - ax) * (pz - az) - (c[j * 2 + 1] - az) * (px - ax);
48
+ if (cross < 0) {
49
+ inside = false;
50
+ break;
51
+ }
52
+ }
53
+ let dxz = 0;
54
+ if (!inside) {
55
+ dxz = Infinity;
56
+ for (let i = 0; i < n; i++) {
57
+ const j = (i + 1) % n;
58
+ const d = segmentDistSq(c[i * 2], c[i * 2 + 1], c[j * 2], c[j * 2 + 1], px, pz);
59
+ if (d < dxz)
60
+ dxz = d;
61
+ }
62
+ }
63
+ return dxz + dy * dy;
64
+ }
65
+ /** Centroid of the corners (x, z) and the middle height, integers. */
66
+ export function pieceCentre(piece) {
67
+ const c = piece.xz;
68
+ const n = c.length / 2;
69
+ let sx = 0;
70
+ let sz = 0;
71
+ for (let i = 0; i < n; i++) {
72
+ sx += c[i * 2];
73
+ sz += c[i * 2 + 1];
74
+ }
75
+ return [idiv(sx, n), idiv(piece.y0 + piece.y1, 2), idiv(sz, n)];
76
+ }
77
+ /** Longest edge of the polygon as an integer vector. */
78
+ export function longestEdge(xz) {
79
+ const n = xz.length / 2;
80
+ let best = -1;
81
+ let bx = 1;
82
+ let bz = 0;
83
+ for (let i = 0; i < n; i++) {
84
+ const j = (i + 1) % n;
85
+ const dx = xz[j * 2] - xz[i * 2];
86
+ const dz = xz[j * 2 + 1] - xz[i * 2 + 1];
87
+ const l = dx * dx + dz * dz;
88
+ if (l > best) {
89
+ best = l;
90
+ bx = dx;
91
+ bz = dz;
92
+ }
93
+ }
94
+ return [bx, bz];
95
+ }
96
+ /** Unit vector scaled by 1024, from an integer vector. (1024, 0) for a zero vector. */
97
+ export function unit1024(dx, dz) {
98
+ const l = isqrt(dx * dx + dz * dz);
99
+ if (l === 0)
100
+ return [1024, 0];
101
+ return [idiv(dx * 1024, l), idiv(dz * 1024, l)];
102
+ }
103
+ /** Compass octant of a direction (0 = +x, counted toward +z), or 8 when the vector is shorter than `minLen`. */
104
+ export function octant(dx, dz, minLen) {
105
+ if (dx * dx + dz * dz < minLen * minLen)
106
+ return 8;
107
+ const ax = Math.abs(dx);
108
+ const az = Math.abs(dz);
109
+ // tan(22.5°) ≈ 0.4142: 2416 / 5832 = 0.41427 (exact integer comparison).
110
+ let o;
111
+ if (az * 5832 <= ax * 2416)
112
+ o = dx >= 0 ? 0 : 4;
113
+ else if (ax * 5832 <= az * 2416)
114
+ o = dz >= 0 ? 2 : 6;
115
+ else if (dx >= 0)
116
+ o = dz >= 0 ? 1 : 7;
117
+ else
118
+ o = dz >= 0 ? 3 : 5;
119
+ return o;
120
+ }
121
+ /** Octant directions scaled by 1024 (724 ≈ 1024 / √2). */
122
+ export const OCTANT_DIRS = [
123
+ [1024, 0],
124
+ [724, 724],
125
+ [0, 1024],
126
+ [-724, 724],
127
+ [-1024, 0],
128
+ [-724, -724],
129
+ [0, -1024],
130
+ [724, -724],
131
+ ];
@@ -0,0 +1,13 @@
1
+ import type { StructureDesc } from '../../base/destructible.ts';
2
+ export interface PartHit {
3
+ structure: number;
4
+ part: number;
5
+ /** Ray parameter and the hit point in metres. */
6
+ t: number;
7
+ point: [number, number, number];
8
+ }
9
+ /**
10
+ * First part piece hit by the ray (origin and direction in metres), with `t > 0`. Clips the ray against the half
11
+ * spaces of each convex prism (Cyrus–Beck). `skip` leaves out parts, for example the gone ones.
12
+ */
13
+ export declare function raycastParts(structures: readonly StructureDesc[], origin: readonly [number, number, number], dir: readonly [number, number, number], skip?: (structure: number, part: number) => boolean): PartHit | null;
@@ -0,0 +1,59 @@
1
+ // Picking parts with a ray, for turning a click into an event position. Input side, not a decision: plain floats.
2
+ /**
3
+ * First part piece hit by the ray (origin and direction in metres), with `t > 0`. Clips the ray against the half
4
+ * spaces of each convex prism (Cyrus–Beck). `skip` leaves out parts, for example the gone ones.
5
+ */
6
+ export function raycastParts(structures, origin, dir, skip) {
7
+ let best = null;
8
+ const [ox, oy, oz] = origin;
9
+ const [dx, dy, dz] = dir;
10
+ for (const s of structures) {
11
+ for (const p of s.parts) {
12
+ if (skip?.(s.id, p.key))
13
+ continue;
14
+ let t0 = 1e-6;
15
+ let t1 = best ? best.t : Infinity;
16
+ // Bottom and top planes.
17
+ const y0 = p.piece.y0 / 100;
18
+ const y1 = p.piece.y1 / 100;
19
+ if (Math.abs(dy) < 1e-12) {
20
+ if (oy < y0 || oy > y1)
21
+ continue;
22
+ }
23
+ else {
24
+ let a = (y0 - oy) / dy;
25
+ let b = (y1 - oy) / dy;
26
+ if (a > b)
27
+ [a, b] = [b, a];
28
+ t0 = Math.max(t0, a);
29
+ t1 = Math.min(t1, b);
30
+ }
31
+ // Side planes: inside is where the cross product with the edge is not negative.
32
+ const c = p.piece.xz;
33
+ const n = c.length / 2;
34
+ for (let i = 0; i < n && t0 <= t1; i++) {
35
+ const j = (i + 1) % n;
36
+ const ax = c[i * 2] / 100;
37
+ const az = c[i * 2 + 1] / 100;
38
+ const ex = c[j * 2] / 100 - ax;
39
+ const ez = c[j * 2 + 1] / 100 - az;
40
+ // f(t) = ex·(z − az) − ez·(x − ax) ≥ 0
41
+ const f0 = ex * (oz - az) - ez * (ox - ax);
42
+ const fd = ex * dz - ez * dx;
43
+ if (Math.abs(fd) < 1e-12) {
44
+ if (f0 < 0)
45
+ t1 = -Infinity;
46
+ continue;
47
+ }
48
+ const t = -f0 / fd;
49
+ if (fd > 0)
50
+ t0 = Math.max(t0, t);
51
+ else
52
+ t1 = Math.min(t1, t);
53
+ }
54
+ if (t0 <= t1 && t0 < (best?.t ?? Infinity))
55
+ best = { structure: s.id, part: p.key, t: t0, point: [ox + dx * t0, oy + dy * t0, oz + dz * t0] };
56
+ }
57
+ }
58
+ return best;
59
+ }
@@ -0,0 +1,8 @@
1
+ import type { DamageEntry, RubbleFootprint, StructurePart, StructureState } from '../../base/destructible.ts';
2
+ import type { CompiledStructure } from './structure.ts';
3
+ /** Rubble of one gone part. */
4
+ export declare function partRubble(s: CompiledStructure, part: StructurePart, entry: DamageEntry): RubbleFootprint;
5
+ /** One mound over the whole outline: the rubble of a structure coarsened into a ruin. */
6
+ export declare function ruinRubble(s: CompiledStructure): RubbleFootprint;
7
+ /** All rubble of a structure in its state, in part key order. This is what navigation and saves may read. */
8
+ export declare function rubbleFootprints(s: CompiledStructure, state: StructureState): RubbleFootprint[];
@@ -0,0 +1,159 @@
1
+ // Rubble footprints: where a gone part lies. The footprint is a pure function of the part, its damage entry (fall
2
+ // direction and variant, both chosen at the moment of the event) and the structure, so it can be rebuilt from the
3
+ // saved state alone. Integer arithmetic only.
4
+ import { DAMAGE, PART_FLAG, PART_ROLE, RUBBLE, entryDir, entryVariant } from '../../base/destructible.js';
5
+ import { hashInts } from '../../gen-core/hash.js';
6
+ import { OCTANT_DIRS, idiv, isqrt, longestEdge, pieceCentre, unit1024 } from './int-geometry.js';
7
+ /** Small turns of the footprint axis picked by the variant: cos and sin scaled by 1024 (0°, ±8°, ±16°). */
8
+ const TURNS = [
9
+ [1024, 0],
10
+ [1014, 143],
11
+ [1014, -143],
12
+ [984, 282],
13
+ [984, -282],
14
+ ];
15
+ /** Footprint limits in centimetres. */
16
+ const MIN_LEN = 80;
17
+ const MAX_LEN = 700;
18
+ const MIN_HEIGHT = 12;
19
+ const MAX_HEIGHT = 160;
20
+ /** Rubble takes more room than the solid: share of voids, as a fraction 3/2. */
21
+ const BULK_NUM = 3;
22
+ const BULK_DEN = 2;
23
+ function archetypeOf(part) {
24
+ if (part.role === PART_ROLE.span)
25
+ return RUBBLE.slabs;
26
+ if (part.role === PART_ROLE.attached || part.role === PART_ROLE.fixture)
27
+ return RUBBLE.scatter;
28
+ return RUBBLE.heap;
29
+ }
30
+ /** Oriented rectangle corners, counter-clockwise (x right, z down). */
31
+ function corners(cx, cz, ux, uz, halfL, halfW) {
32
+ const out = new Int32Array(8);
33
+ const signs = [
34
+ [-1, -1],
35
+ [1, -1],
36
+ [1, 1],
37
+ [-1, 1],
38
+ ];
39
+ signs.forEach(([su, sv], k) => {
40
+ out[k * 2] = cx + idiv(ux * halfL * su, 1024) + idiv(-uz * halfW * sv, 1024);
41
+ out[k * 2 + 1] = cz + idiv(uz * halfL * su, 1024) + idiv(ux * halfW * sv, 1024);
42
+ });
43
+ return out;
44
+ }
45
+ /** Extent of a polygon across the unit direction (bx, bz) scaled by 1024. */
46
+ function shortSide(xz, bx, bz) {
47
+ let lo = Infinity;
48
+ let hi = -Infinity;
49
+ for (let k = 0; k < xz.length; k += 2) {
50
+ const v = idiv(-xz[k] * bz + xz[k + 1] * bx, 1024);
51
+ lo = Math.min(lo, v);
52
+ hi = Math.max(hi, v);
53
+ }
54
+ return hi - lo;
55
+ }
56
+ /** Rubble of one gone part. */
57
+ export function partRubble(s, part, entry) {
58
+ const desc = s.desc;
59
+ const variant = entryVariant(entry);
60
+ const dir = entryDir(entry);
61
+ const [pcx, , pcz] = pieceCentre(part.piece);
62
+ // Falls away from the blast or out of the structure, further the higher it stood.
63
+ const above = Math.max(0, part.piece.y1 - desc.groundY);
64
+ const inner = (part.flags & PART_FLAG.inner) !== 0;
65
+ const reach = dir < 8 && !inner ? Math.min(idiv(above * 35, 100), 300) + 40 : 0;
66
+ const d = OCTANT_DIRS[dir < 8 ? dir : 0];
67
+ const cx = pcx + idiv(d[0] * reach, 1024);
68
+ const cz = pcz + idiv(d[1] * reach, 1024);
69
+ const [ex, ez] = longestEdge(part.piece.xz);
70
+ const [bx, bz] = unit1024(ex, ez);
71
+ const turn = inner ? TURNS[0] : TURNS[variant % TURNS.length];
72
+ const ux = idiv(bx * turn[0] - bz * turn[1], 1024);
73
+ const uz = idiv(bx * turn[1] + bz * turn[0], 1024);
74
+ // Size from the volume of the solid: length along the part, width and height of a low mound.
75
+ const material = desc.materials[part.material];
76
+ const density = material && material.density > 0 ? material.density : 2000;
77
+ const volume = idiv(idiv(part.mass * 1_000_000, density) * BULK_NUM, BULK_DEN);
78
+ const len = Math.min(MAX_LEN, Math.max(MIN_LEN, isqrt(ex * ex + ez * ez)));
79
+ let width = Math.min(400, Math.max(MIN_LEN, idiv(len, 2)));
80
+ let height = idiv(2 * volume, len * width);
81
+ if (height > MAX_HEIGHT) {
82
+ width = Math.min(MAX_LEN, idiv(2 * volume, len * MAX_HEIGHT));
83
+ height = MAX_HEIGHT;
84
+ }
85
+ height = Math.max(MIN_HEIGHT, height);
86
+ // An inner part keeps its rubble within its own footprint (shrunk a little, so it never pokes through the shell).
87
+ const halfL = inner ? Math.max(20, idiv(len, 2) - 30) : idiv(len, 2) + 30;
88
+ const halfW = inner ? Math.max(20, Math.min(idiv(width, 2), idiv(shortSide(part.piece.xz, bx, bz), 2) - 30)) : idiv(width, 2) + 20;
89
+ return {
90
+ structure: desc.id,
91
+ part: part.key,
92
+ archetype: archetypeOf(part),
93
+ material: part.material,
94
+ cx,
95
+ cz,
96
+ y: desc.groundY,
97
+ ux,
98
+ uz,
99
+ halfL,
100
+ halfW,
101
+ height,
102
+ corners: corners(cx, cz, ux, uz, halfL, halfW),
103
+ seed: hashInts(desc.id, part.key, entry),
104
+ };
105
+ }
106
+ /** One mound over the whole outline: the rubble of a structure coarsened into a ruin. */
107
+ export function ruinRubble(s) {
108
+ const desc = s.desc;
109
+ const o = desc.outline;
110
+ const [ex, ez] = longestEdge(o);
111
+ const [ux, uz] = unit1024(ex, ez);
112
+ let halfL = 0;
113
+ let halfW = 0;
114
+ for (let k = 0; k < o.length; k += 2) {
115
+ const rx = o[k] - desc.cx;
116
+ const rz = o[k + 1] - desc.cz;
117
+ halfL = Math.max(halfL, Math.abs(idiv(rx * ux + rz * uz, 1024)));
118
+ halfW = Math.max(halfW, Math.abs(idiv(-rx * uz + rz * ux, 1024)));
119
+ }
120
+ let volume = 0;
121
+ for (const p of desc.parts) {
122
+ if (p.flags & PART_FLAG.indestructible)
123
+ continue;
124
+ const m = desc.materials[p.material];
125
+ volume += idiv(p.mass * 1_000_000, m && m.density > 0 ? m.density : 2000);
126
+ }
127
+ halfL += 60;
128
+ halfW += 60;
129
+ const area = Math.max(1, 4 * halfL * halfW);
130
+ const height = Math.min(450, Math.max(60, idiv(2 * idiv(volume * BULK_NUM, BULK_DEN), area)));
131
+ return {
132
+ structure: desc.id,
133
+ part: 0,
134
+ archetype: RUBBLE.ruin,
135
+ material: 0,
136
+ cx: desc.cx,
137
+ cz: desc.cz,
138
+ y: desc.groundY,
139
+ ux,
140
+ uz,
141
+ halfL,
142
+ halfW,
143
+ height,
144
+ corners: corners(desc.cx, desc.cz, ux, uz, halfL, halfW),
145
+ seed: hashInts(desc.id, 0x7275696e),
146
+ };
147
+ }
148
+ /** All rubble of a structure in its state, in part key order. This is what navigation and saves may read. */
149
+ export function rubbleFootprints(s, state) {
150
+ if (state.ruin)
151
+ return [ruinRubble(s)];
152
+ const out = [];
153
+ for (const part of s.desc.parts) {
154
+ const e = state.parts.get(part.key);
155
+ if (e !== undefined && (e & 3) === DAMAGE.gone)
156
+ out.push(partRubble(s, part, e));
157
+ }
158
+ return out;
159
+ }
@@ -0,0 +1,15 @@
1
+ import type { DamageEntry, StructureState } from '../../base/destructible.ts';
2
+ export declare function intactState(structure: number): StructureState;
3
+ /** Entries in ascending key order. */
4
+ export declare function sortedEntries(state: StructureState): [number, DamageEntry][];
5
+ /** True when nothing is damaged. */
6
+ export declare function isIntact(state: StructureState | undefined): boolean;
7
+ /** 64-bit hash of one or more structure states as 16 hex digits. Independent of map insertion order. */
8
+ export declare function stateHash(states: StructureState | readonly StructureState[]): string;
9
+ /** Compact text of several structure states (structures in id order; intact ones are left out). */
10
+ export declare function encodeStates(states: Iterable<StructureState>): string;
11
+ /** Parses the text of `encodeStates`. Malformed pieces are skipped (and reported in `errors`), never guessed. */
12
+ export declare function decodeStates(text: string): {
13
+ states: Map<number, StructureState>;
14
+ errors: string[];
15
+ };
@@ -0,0 +1,83 @@
1
+ // The authoritative damage state of structures: a small map `part key → entry` per structure, a hash of it, and a
2
+ // compact text form that fits into a URL or a save.
3
+ //
4
+ // Text form (URL-safe): structures joined by `_`, each `<id>[!]~<entries>` with the id in base 36, `!` for a ruin,
5
+ // and entries `<key delta>.<entry>` joined by `,` (keys ascending, each as the difference to the previous key, both in
6
+ // base 36). Example: `1~2h4k.c3,1.3_2!~`.
7
+ import { hashInts } from '../../gen-core/hash.js';
8
+ export function intactState(structure) {
9
+ return { structure, ruin: false, parts: new Map() };
10
+ }
11
+ /** Entries in ascending key order. */
12
+ export function sortedEntries(state) {
13
+ return [...state.parts.entries()].sort((p, q) => p[0] - q[0]);
14
+ }
15
+ /** True when nothing is damaged. */
16
+ export function isIntact(state) {
17
+ return !state || (!state.ruin && state.parts.size === 0);
18
+ }
19
+ /** 64-bit hash of one or more structure states as 16 hex digits. Independent of map insertion order. */
20
+ export function stateHash(states) {
21
+ const list = (Array.isArray(states) ? [...states] : [states]).sort((p, q) => p.structure - q.structure);
22
+ let h1 = 0x2545f491;
23
+ let h2 = 0x6c8e9cf5;
24
+ for (const s of list) {
25
+ h1 = hashInts(h1, s.structure, s.ruin ? 1 : 0);
26
+ h2 = hashInts(h2, s.structure ^ 0x5bd1e995, s.ruin ? 3 : 2);
27
+ for (const [k, e] of sortedEntries(s)) {
28
+ h1 = hashInts(h1, k, e);
29
+ h2 = hashInts(h2, e, k);
30
+ }
31
+ }
32
+ return h1.toString(16).padStart(8, '0') + h2.toString(16).padStart(8, '0');
33
+ }
34
+ /** Compact text of several structure states (structures in id order; intact ones are left out). */
35
+ export function encodeStates(states) {
36
+ const list = [...states].filter((s) => !isIntact(s)).sort((p, q) => p.structure - q.structure);
37
+ return list
38
+ .map((s) => {
39
+ let prev = 0;
40
+ const entries = s.ruin
41
+ ? []
42
+ : sortedEntries(s).map(([k, e]) => {
43
+ const d = k - prev;
44
+ prev = k;
45
+ return `${d.toString(36)}.${e.toString(36)}`;
46
+ });
47
+ return `${(s.structure >>> 0).toString(36)}${s.ruin ? '!' : ''}~${entries.join(',')}`;
48
+ })
49
+ .join('_');
50
+ }
51
+ /** Parses the text of `encodeStates`. Malformed pieces are skipped (and reported in `errors`), never guessed. */
52
+ export function decodeStates(text) {
53
+ const states = new Map();
54
+ const errors = [];
55
+ for (const chunk of text.split('_')) {
56
+ if (!chunk)
57
+ continue;
58
+ const m = /^([0-9a-z]+)(!?)~([0-9a-z.,]*)$/.exec(chunk);
59
+ if (!m) {
60
+ errors.push(`bad structure "${chunk.slice(0, 24)}"`);
61
+ continue;
62
+ }
63
+ const structure = parseInt(m[1], 36);
64
+ const parts = new Map();
65
+ let key = 0;
66
+ let ok = true;
67
+ for (const item of m[3] ? m[3].split(',') : []) {
68
+ const [d, e] = item.split('.');
69
+ const dk = parseInt(d ?? '', 36);
70
+ const en = parseInt(e ?? '', 36);
71
+ if (!Number.isFinite(dk) || !Number.isFinite(en) || dk <= 0 && key > 0) {
72
+ errors.push(`bad entry "${item}" in structure ${structure}`);
73
+ ok = false;
74
+ break;
75
+ }
76
+ key += dk;
77
+ parts.set(key >>> 0, en);
78
+ }
79
+ if (ok)
80
+ states.set(structure, { structure, ruin: m[2] === '!', parts });
81
+ }
82
+ return { states, errors };
83
+ }
@@ -0,0 +1,30 @@
1
+ import type { StructureDesc } from '../../base/destructible.ts';
2
+ /** A part with no supported path. */
3
+ export declare const UNSUPPORTED = 65535;
4
+ export interface CompiledStructure {
5
+ readonly desc: StructureDesc;
6
+ /** Part index by key. Parts keep the order of `desc.parts` (sorted by key). */
7
+ readonly index: ReadonlyMap<number, number>;
8
+ /** Neighbours by part index, each list sorted by index: parts resting on it, parts it rests on, lateral ties. */
9
+ readonly above: readonly number[][];
10
+ readonly below: readonly number[][];
11
+ readonly lateral: readonly number[][];
12
+ /** Allowed hang per part: the larger of `maxSpan` and the hang it already has when intact. */
13
+ readonly span: Uint16Array;
14
+ /** Bounding boxes (cm): min x, max x, min y, max y, min z, max z per part. */
15
+ readonly box: Int32Array;
16
+ /** Integer centre of each part's piece. */
17
+ readonly centre: Int32Array;
18
+ /** Bounding box of the whole structure. */
19
+ readonly bounds: readonly [number, number, number, number, number, number];
20
+ /** Parts that are not connected to any anchor even when intact (a generator fault); they are treated as anchors. */
21
+ readonly floating: number;
22
+ }
23
+ /** Prepares a structure description (cached per description object). Throws on unsorted or dangling data. */
24
+ export declare function compileStructure(desc: StructureDesc): CompiledStructure;
25
+ /**
26
+ * Smallest hang of every part (0 = rests on something, UNSUPPORTED = no path to an anchor) for the parts marked in
27
+ * `alive`. `limits` caps the hang per part (the compiled spans); `null` means no cap. Parts that are floating even when
28
+ * intact count as anchors.
29
+ */
30
+ export declare function solveSupport(s: CompiledStructure, alive: Uint8Array, limits: Uint16Array | null): Uint16Array;