@thunderclap-engine/engine 0.0.0-stage → 1.1.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 (566) hide show
  1. package/CHANGELOG.md +390 -0
  2. package/LICENSE +21 -0
  3. package/README.md +333 -2
  4. package/dist/analytics/analytics.d.ts +80 -0
  5. package/dist/analytics/analytics.js +129 -0
  6. package/dist/analytics/index.d.ts +1 -0
  7. package/dist/analytics/index.js +1 -0
  8. package/dist/anim/aim.d.ts +43 -0
  9. package/dist/anim/aim.js +157 -0
  10. package/dist/anim/clip.d.ts +98 -0
  11. package/dist/anim/clip.js +282 -0
  12. package/dist/anim/compress.d.ts +65 -0
  13. package/dist/anim/compress.js +339 -0
  14. package/dist/anim/foot-ik.d.ts +74 -0
  15. package/dist/anim/foot-ik.js +241 -0
  16. package/dist/anim/graph.d.ts +153 -0
  17. package/dist/anim/graph.js +532 -0
  18. package/dist/anim/ik.d.ts +105 -0
  19. package/dist/anim/ik.js +435 -0
  20. package/dist/anim/index.d.ts +36 -0
  21. package/dist/anim/index.js +21 -0
  22. package/dist/anim/match.d.ts +66 -0
  23. package/dist/anim/match.js +153 -0
  24. package/dist/anim/mixer.d.ts +113 -0
  25. package/dist/anim/mixer.js +314 -0
  26. package/dist/anim/morph.d.ts +41 -0
  27. package/dist/anim/morph.js +94 -0
  28. package/dist/anim/pose.d.ts +74 -0
  29. package/dist/anim/pose.js +254 -0
  30. package/dist/anim/quat.d.ts +44 -0
  31. package/dist/anim/quat.js +187 -0
  32. package/dist/anim/retarget.d.ts +97 -0
  33. package/dist/anim/retarget.js +366 -0
  34. package/dist/anim/root-motion.d.ts +44 -0
  35. package/dist/anim/root-motion.js +224 -0
  36. package/dist/anim/skin-pose.d.ts +39 -0
  37. package/dist/anim/skin-pose.js +53 -0
  38. package/dist/anim/socket.d.ts +47 -0
  39. package/dist/anim/socket.js +84 -0
  40. package/dist/anim/spring-chain.d.ts +73 -0
  41. package/dist/anim/spring-chain.js +294 -0
  42. package/dist/assets/atlas.d.ts +90 -0
  43. package/dist/assets/atlas.js +212 -0
  44. package/dist/assets/baked.d.ts +33 -0
  45. package/dist/assets/baked.js +38 -0
  46. package/dist/assets/bundle.d.ts +88 -0
  47. package/dist/assets/bundle.js +464 -0
  48. package/dist/assets/cache.d.ts +56 -0
  49. package/dist/assets/cache.js +123 -0
  50. package/dist/assets/gltf-load.d.ts +252 -0
  51. package/dist/assets/gltf-load.js +661 -0
  52. package/dist/assets/gltf-skin.d.ts +36 -0
  53. package/dist/assets/gltf-skin.js +109 -0
  54. package/dist/assets/gltf.d.ts +706 -0
  55. package/dist/assets/gltf.js +1376 -0
  56. package/dist/assets/index.d.ts +20 -0
  57. package/dist/assets/index.js +10 -0
  58. package/dist/assets/ktx2.d.ts +71 -0
  59. package/dist/assets/ktx2.js +213 -0
  60. package/dist/assets/manifest.d.ts +79 -0
  61. package/dist/assets/manifest.js +7 -0
  62. package/dist/assets/meshopt.d.ts +23 -0
  63. package/dist/assets/meshopt.js +403 -0
  64. package/dist/audio/audio.d.ts +733 -0
  65. package/dist/audio/audio.js +2013 -0
  66. package/dist/audio/dsp.d.ts +61 -0
  67. package/dist/audio/dsp.js +159 -0
  68. package/dist/audio/duck.d.ts +44 -0
  69. package/dist/audio/duck.js +101 -0
  70. package/dist/audio/envelope.d.ts +53 -0
  71. package/dist/audio/envelope.js +106 -0
  72. package/dist/audio/index.d.ts +13 -0
  73. package/dist/audio/index.js +14 -0
  74. package/dist/audio/music.d.ts +113 -0
  75. package/dist/audio/music.js +548 -0
  76. package/dist/audio/occlusion.d.ts +55 -0
  77. package/dist/audio/occlusion.js +61 -0
  78. package/dist/audio/persist.d.ts +23 -0
  79. package/dist/audio/persist.js +27 -0
  80. package/dist/audio/recipes.d.ts +55 -0
  81. package/dist/audio/recipes.js +227 -0
  82. package/dist/audio/send.d.ts +41 -0
  83. package/dist/audio/send.js +118 -0
  84. package/dist/audio/sprites.d.ts +59 -0
  85. package/dist/audio/sprites.js +43 -0
  86. package/dist/audio/synth.d.ts +103 -0
  87. package/dist/audio/synth.js +197 -0
  88. package/dist/audio/variations.d.ts +25 -0
  89. package/dist/audio/variations.js +55 -0
  90. package/dist/audio/zones.d.ts +100 -0
  91. package/dist/audio/zones.js +167 -0
  92. package/dist/core/detached-surface.d.ts +44 -0
  93. package/dist/core/detached-surface.js +104 -0
  94. package/dist/core/events.d.ts +24 -0
  95. package/dist/core/events.js +43 -0
  96. package/dist/core/game.d.ts +409 -0
  97. package/dist/core/game.js +530 -0
  98. package/dist/core/hash.d.ts +24 -0
  99. package/dist/core/hash.js +49 -0
  100. package/dist/core/index.d.ts +17 -0
  101. package/dist/core/index.js +9 -0
  102. package/dist/core/loop.d.ts +113 -0
  103. package/dist/core/loop.js +185 -0
  104. package/dist/core/math.d.ts +58 -0
  105. package/dist/core/math.js +210 -0
  106. package/dist/core/noise.d.ts +40 -0
  107. package/dist/core/noise.js +247 -0
  108. package/dist/core/pool.d.ts +42 -0
  109. package/dist/core/pool.js +85 -0
  110. package/dist/core/random.d.ts +61 -0
  111. package/dist/core/random.js +199 -0
  112. package/dist/core/scene.d.ts +79 -0
  113. package/dist/core/scene.js +195 -0
  114. package/dist/core/timer.d.ts +66 -0
  115. package/dist/core/timer.js +286 -0
  116. package/dist/fx/billboard-wgsl.d.ts +29 -0
  117. package/dist/fx/billboard-wgsl.js +158 -0
  118. package/dist/fx/billboard.d.ts +249 -0
  119. package/dist/fx/billboard.js +702 -0
  120. package/dist/fx/debug-draw.d.ts +127 -0
  121. package/dist/fx/debug-draw.js +523 -0
  122. package/dist/fx/debug-wgsl.d.ts +7 -0
  123. package/dist/fx/debug-wgsl.js +32 -0
  124. package/dist/fx/decals-wgsl.d.ts +15 -0
  125. package/dist/fx/decals-wgsl.js +173 -0
  126. package/dist/fx/decals.d.ts +216 -0
  127. package/dist/fx/decals.js +607 -0
  128. package/dist/fx/effect.d.ts +129 -0
  129. package/dist/fx/effect.js +349 -0
  130. package/dist/fx/effects/hit-spark.json +48 -0
  131. package/dist/fx/effects/index.d.ts +8 -0
  132. package/dist/fx/effects/index.js +9 -0
  133. package/dist/fx/effects/magic-aura.json +47 -0
  134. package/dist/fx/effects/smoke-puff.json +34 -0
  135. package/dist/fx/emit-surface.d.ts +40 -0
  136. package/dist/fx/emit-surface.js +124 -0
  137. package/dist/fx/flicker.d.ts +30 -0
  138. package/dist/fx/flicker.js +42 -0
  139. package/dist/fx/index.d.ts +31 -0
  140. package/dist/fx/index.js +20 -0
  141. package/dist/fx/particles-wgsl.d.ts +57 -0
  142. package/dist/fx/particles-wgsl.js +828 -0
  143. package/dist/fx/particles.d.ts +566 -0
  144. package/dist/fx/particles.js +1533 -0
  145. package/dist/fx/random.d.ts +15 -0
  146. package/dist/fx/random.js +20 -0
  147. package/dist/fx/sky-wgsl.d.ts +23 -0
  148. package/dist/fx/sky-wgsl.js +127 -0
  149. package/dist/fx/sky.d.ts +96 -0
  150. package/dist/fx/sky.js +175 -0
  151. package/dist/fx/text-atlas.d.ts +143 -0
  152. package/dist/fx/text-atlas.js +327 -0
  153. package/dist/fx/trail-wgsl.d.ts +11 -0
  154. package/dist/fx/trail-wgsl.js +42 -0
  155. package/dist/fx/trail.d.ts +194 -0
  156. package/dist/fx/trail.js +555 -0
  157. package/dist/fx/water-wgsl.d.ts +34 -0
  158. package/dist/fx/water-wgsl.js +197 -0
  159. package/dist/fx/water.d.ts +176 -0
  160. package/dist/fx/water.js +371 -0
  161. package/dist/geom/collide/bvh.d.ts +151 -0
  162. package/dist/geom/collide/bvh.js +493 -0
  163. package/dist/geom/collide/debug.d.ts +14 -0
  164. package/dist/geom/collide/debug.js +74 -0
  165. package/dist/geom/collide/grid.d.ts +26 -0
  166. package/dist/geom/collide/grid.js +91 -0
  167. package/dist/geom/collide/index.d.ts +8 -0
  168. package/dist/geom/collide/index.js +8 -0
  169. package/dist/geom/collide/queries.d.ts +70 -0
  170. package/dist/geom/collide/queries.js +583 -0
  171. package/dist/geom/collide/serialize.d.ts +14 -0
  172. package/dist/geom/collide/serialize.js +145 -0
  173. package/dist/geom/collide/shapes.d.ts +161 -0
  174. package/dist/geom/collide/shapes.js +686 -0
  175. package/dist/geom/collide/slide.d.ts +66 -0
  176. package/dist/geom/collide/slide.js +375 -0
  177. package/dist/geom/collide/tile-slide.d.ts +88 -0
  178. package/dist/geom/collide/tile-slide.js +255 -0
  179. package/dist/geom/geometry.d.ts +95 -0
  180. package/dist/geom/geometry.js +322 -0
  181. package/dist/geom/heightfield.d.ts +72 -0
  182. package/dist/geom/heightfield.js +295 -0
  183. package/dist/geom/hull.d.ts +27 -0
  184. package/dist/geom/hull.js +279 -0
  185. package/dist/geom/index.d.ts +35 -0
  186. package/dist/geom/index.js +23 -0
  187. package/dist/geom/iso.d.ts +74 -0
  188. package/dist/geom/iso.js +89 -0
  189. package/dist/geom/lod.d.ts +29 -0
  190. package/dist/geom/lod.js +27 -0
  191. package/dist/geom/ops.d.ts +47 -0
  192. package/dist/geom/ops.js +285 -0
  193. package/dist/geom/primitives.d.ts +97 -0
  194. package/dist/geom/primitives.js +359 -0
  195. package/dist/geom/shapes.d.ts +43 -0
  196. package/dist/geom/shapes.js +88 -0
  197. package/dist/geom/simplify.d.ts +38 -0
  198. package/dist/geom/simplify.js +519 -0
  199. package/dist/geom/split.d.ts +37 -0
  200. package/dist/geom/split.js +413 -0
  201. package/dist/geom/sweep.d.ts +83 -0
  202. package/dist/geom/sweep.js +534 -0
  203. package/dist/geom/tangents.d.ts +16 -0
  204. package/dist/geom/tangents.js +124 -0
  205. package/dist/geom/triangulate.d.ts +19 -0
  206. package/dist/geom/triangulate.js +147 -0
  207. package/dist/host/default.d.ts +10 -0
  208. package/dist/host/default.js +10 -0
  209. package/dist/host/index.d.ts +4 -0
  210. package/dist/host/index.js +3 -0
  211. package/dist/host/types.d.ts +144 -0
  212. package/dist/host/types.js +1 -0
  213. package/dist/host/web-links.d.ts +38 -0
  214. package/dist/host/web-links.js +110 -0
  215. package/dist/host/web.d.ts +30 -0
  216. package/dist/host/web.js +216 -0
  217. package/dist/host/xr.d.ts +24 -0
  218. package/dist/host/xr.js +59 -0
  219. package/dist/i18n/i18n.d.ts +59 -0
  220. package/dist/i18n/i18n.js +241 -0
  221. package/dist/i18n/index.d.ts +3 -0
  222. package/dist/i18n/index.js +3 -0
  223. package/dist/i18n/message.d.ts +72 -0
  224. package/dist/i18n/message.js +369 -0
  225. package/dist/i18n/negotiate.d.ts +17 -0
  226. package/dist/i18n/negotiate.js +58 -0
  227. package/dist/index.d.ts +7 -0
  228. package/dist/index.js +1 -0
  229. package/dist/input/bindings.d.ts +31 -0
  230. package/dist/input/bindings.js +141 -0
  231. package/dist/input/clock.d.ts +44 -0
  232. package/dist/input/clock.js +49 -0
  233. package/dist/input/follow.d.ts +133 -0
  234. package/dist/input/follow.js +218 -0
  235. package/dist/input/gestures.d.ts +281 -0
  236. package/dist/input/gestures.js +662 -0
  237. package/dist/input/glyphs.d.ts +35 -0
  238. package/dist/input/glyphs.js +216 -0
  239. package/dist/input/gyro.d.ts +85 -0
  240. package/dist/input/gyro.js +140 -0
  241. package/dist/input/index.d.ts +19 -0
  242. package/dist/input/index.js +16 -0
  243. package/dist/input/input.d.ts +543 -0
  244. package/dist/input/input.js +1492 -0
  245. package/dist/input/look.d.ts +327 -0
  246. package/dist/input/look.js +681 -0
  247. package/dist/input/magnify.d.ts +177 -0
  248. package/dist/input/magnify.js +131 -0
  249. package/dist/input/pointer-dispatch.d.ts +138 -0
  250. package/dist/input/pointer-dispatch.js +180 -0
  251. package/dist/input/pointer-router.d.ts +204 -0
  252. package/dist/input/pointer-router.js +533 -0
  253. package/dist/input/pointer-sources.d.ts +164 -0
  254. package/dist/input/pointer-sources.js +306 -0
  255. package/dist/input/rays.d.ts +138 -0
  256. package/dist/input/rays.js +615 -0
  257. package/dist/input/record.d.ts +209 -0
  258. package/dist/input/record.js +601 -0
  259. package/dist/input/touch-zones.d.ts +147 -0
  260. package/dist/input/touch-zones.js +300 -0
  261. package/dist/input/types.d.ts +158 -0
  262. package/dist/input/types.js +1 -0
  263. package/dist/input/xr-source.d.ts +53 -0
  264. package/dist/input/xr-source.js +164 -0
  265. package/dist/nav/astar.d.ts +45 -0
  266. package/dist/nav/astar.js +182 -0
  267. package/dist/nav/corridor.d.ts +40 -0
  268. package/dist/nav/corridor.js +95 -0
  269. package/dist/nav/crowd.d.ts +94 -0
  270. package/dist/nav/crowd.js +624 -0
  271. package/dist/nav/flow.d.ts +61 -0
  272. package/dist/nav/flow.js +193 -0
  273. package/dist/nav/grid.d.ts +108 -0
  274. package/dist/nav/grid.js +210 -0
  275. package/dist/nav/heap.d.ts +22 -0
  276. package/dist/nav/heap.js +92 -0
  277. package/dist/nav/index.d.ts +37 -0
  278. package/dist/nav/index.js +19 -0
  279. package/dist/nav/mesh/areas.d.ts +44 -0
  280. package/dist/nav/mesh/areas.js +98 -0
  281. package/dist/nav/mesh/bake-options.d.ts +33 -0
  282. package/dist/nav/mesh/bake-options.js +76 -0
  283. package/dist/nav/mesh/contour.d.ts +22 -0
  284. package/dist/nav/mesh/contour.js +323 -0
  285. package/dist/nav/mesh/flow3.d.ts +35 -0
  286. package/dist/nav/mesh/flow3.js +229 -0
  287. package/dist/nav/mesh/links.d.ts +38 -0
  288. package/dist/nav/mesh/links.js +72 -0
  289. package/dist/nav/mesh/mesh-path.d.ts +152 -0
  290. package/dist/nav/mesh/mesh-path.js +643 -0
  291. package/dist/nav/mesh/mesh-reach.d.ts +78 -0
  292. package/dist/nav/mesh/mesh-reach.js +450 -0
  293. package/dist/nav/mesh/navmesh.d.ts +117 -0
  294. package/dist/nav/mesh/navmesh.js +647 -0
  295. package/dist/nav/mesh/polymesh.d.ts +24 -0
  296. package/dist/nav/mesh/polymesh.js +384 -0
  297. package/dist/nav/mesh/regions.d.ts +12 -0
  298. package/dist/nav/mesh/regions.js +367 -0
  299. package/dist/nav/mesh/serialize.d.ts +13 -0
  300. package/dist/nav/mesh/serialize.js +197 -0
  301. package/dist/nav/mesh/voxelize.d.ts +111 -0
  302. package/dist/nav/mesh/voxelize.js +552 -0
  303. package/dist/nav/obstacles.d.ts +75 -0
  304. package/dist/nav/obstacles.js +294 -0
  305. package/dist/nav/path.d.ts +59 -0
  306. package/dist/nav/path.js +177 -0
  307. package/dist/nav/query-queue.d.ts +46 -0
  308. package/dist/nav/query-queue.js +308 -0
  309. package/dist/nav/reach.d.ts +53 -0
  310. package/dist/nav/reach.js +148 -0
  311. package/dist/nav/steer.d.ts +36 -0
  312. package/dist/nav/steer.js +78 -0
  313. package/dist/platform/boot.d.ts +28 -0
  314. package/dist/platform/boot.js +43 -0
  315. package/dist/platform/device-mode.d.ts +40 -0
  316. package/dist/platform/device-mode.js +104 -0
  317. package/dist/platform/device.d.ts +31 -0
  318. package/dist/platform/device.js +91 -0
  319. package/dist/platform/environment.d.ts +42 -0
  320. package/dist/platform/environment.js +82 -0
  321. package/dist/platform/gpu.d.ts +40 -0
  322. package/dist/platform/gpu.js +57 -0
  323. package/dist/platform/index.d.ts +18 -0
  324. package/dist/platform/index.js +10 -0
  325. package/dist/platform/letterbox.d.ts +43 -0
  326. package/dist/platform/letterbox.js +57 -0
  327. package/dist/platform/links.d.ts +20 -0
  328. package/dist/platform/links.js +43 -0
  329. package/dist/platform/screens.d.ts +36 -0
  330. package/dist/platform/screens.js +138 -0
  331. package/dist/platform/surface.d.ts +72 -0
  332. package/dist/platform/surface.js +157 -0
  333. package/dist/platform/xr-fake.d.ts +168 -0
  334. package/dist/platform/xr-fake.js +434 -0
  335. package/dist/platform/xr-surface.d.ts +120 -0
  336. package/dist/platform/xr-surface.js +214 -0
  337. package/dist/platform/xr-types.d.ts +262 -0
  338. package/dist/post/ao.d.ts +12 -0
  339. package/dist/post/ao.js +136 -0
  340. package/dist/post/blend.d.ts +27 -0
  341. package/dist/post/blend.js +129 -0
  342. package/dist/post/depth-pass.d.ts +43 -0
  343. package/dist/post/depth-pass.js +118 -0
  344. package/dist/post/dof.d.ts +1 -0
  345. package/dist/post/dof.js +66 -0
  346. package/dist/post/exposure.d.ts +80 -0
  347. package/dist/post/exposure.js +322 -0
  348. package/dist/post/index.d.ts +12 -0
  349. package/dist/post/index.js +11 -0
  350. package/dist/post/lens-dirt.d.ts +13 -0
  351. package/dist/post/lens-dirt.js +91 -0
  352. package/dist/post/lut.d.ts +19 -0
  353. package/dist/post/lut.js +50 -0
  354. package/dist/post/motion-blur.d.ts +9 -0
  355. package/dist/post/motion-blur.js +78 -0
  356. package/dist/post/post-stack.d.ts +302 -0
  357. package/dist/post/post-stack.js +1137 -0
  358. package/dist/post/settings.d.ts +485 -0
  359. package/dist/post/settings.js +416 -0
  360. package/dist/post/shaders.d.ts +25 -0
  361. package/dist/post/shaders.js +410 -0
  362. package/dist/post/ssr.d.ts +16 -0
  363. package/dist/post/ssr.js +155 -0
  364. package/dist/post/taa.d.ts +74 -0
  365. package/dist/post/taa.js +235 -0
  366. package/dist/post/white-balance.d.ts +25 -0
  367. package/dist/post/white-balance.js +98 -0
  368. package/dist/render/bindings.d.ts +98 -0
  369. package/dist/render/bindings.js +281 -0
  370. package/dist/render/blend.d.ts +13 -0
  371. package/dist/render/blend.js +26 -0
  372. package/dist/render/camera-2d.d.ts +72 -0
  373. package/dist/render/camera-2d.js +92 -0
  374. package/dist/render/camera.d.ts +302 -0
  375. package/dist/render/camera.js +671 -0
  376. package/dist/render/color.d.ts +16 -0
  377. package/dist/render/color.js +41 -0
  378. package/dist/render/compressed.d.ts +104 -0
  379. package/dist/render/compressed.js +248 -0
  380. package/dist/render/diagnostics.d.ts +15 -0
  381. package/dist/render/diagnostics.js +43 -0
  382. package/dist/render/dynamic-resolution.d.ts +70 -0
  383. package/dist/render/dynamic-resolution.js +126 -0
  384. package/dist/render/fake-gpu.d.ts +204 -0
  385. package/dist/render/fake-gpu.js +426 -0
  386. package/dist/render/flipbook.d.ts +56 -0
  387. package/dist/render/flipbook.js +87 -0
  388. package/dist/render/frame.d.ts +278 -0
  389. package/dist/render/frame.js +174 -0
  390. package/dist/render/fullscreen.d.ts +54 -0
  391. package/dist/render/fullscreen.js +91 -0
  392. package/dist/render/gpu-timer.d.ts +73 -0
  393. package/dist/render/gpu-timer.js +186 -0
  394. package/dist/render/index.d.ts +53 -0
  395. package/dist/render/index.js +29 -0
  396. package/dist/render/instance-list.d.ts +185 -0
  397. package/dist/render/instance-list.js +547 -0
  398. package/dist/render/lights.d.ts +181 -0
  399. package/dist/render/lights.js +233 -0
  400. package/dist/render/lod.d.ts +54 -0
  401. package/dist/render/lod.js +52 -0
  402. package/dist/render/material.d.ts +165 -0
  403. package/dist/render/material.js +292 -0
  404. package/dist/render/mesh.d.ts +284 -0
  405. package/dist/render/mesh.js +472 -0
  406. package/dist/render/mipmap.d.ts +16 -0
  407. package/dist/render/mipmap.js +121 -0
  408. package/dist/render/parallax.d.ts +50 -0
  409. package/dist/render/parallax.js +47 -0
  410. package/dist/render/pbr-wgsl.d.ts +31 -0
  411. package/dist/render/pbr-wgsl.js +119 -0
  412. package/dist/render/ping-pong.d.ts +42 -0
  413. package/dist/render/ping-pong.js +74 -0
  414. package/dist/render/renderer.d.ts +741 -0
  415. package/dist/render/renderer.js +2486 -0
  416. package/dist/render/scene-pipelines.d.ts +44 -0
  417. package/dist/render/scene-pipelines.js +92 -0
  418. package/dist/render/scene-target.d.ts +170 -0
  419. package/dist/render/scene-target.js +450 -0
  420. package/dist/render/shadow.d.ts +74 -0
  421. package/dist/render/shadow.js +208 -0
  422. package/dist/render/skin.d.ts +112 -0
  423. package/dist/render/skin.js +240 -0
  424. package/dist/render/snapshot.d.ts +36 -0
  425. package/dist/render/snapshot.js +34 -0
  426. package/dist/render/standard.d.ts +162 -0
  427. package/dist/render/standard.js +263 -0
  428. package/dist/render/texture.d.ts +142 -0
  429. package/dist/render/texture.js +228 -0
  430. package/dist/render/tile-layer.d.ts +110 -0
  431. package/dist/render/tile-layer.js +304 -0
  432. package/dist/render/transform.d.ts +115 -0
  433. package/dist/render/transform.js +318 -0
  434. package/dist/render/wgsl.d.ts +131 -0
  435. package/dist/render/wgsl.js +528 -0
  436. package/dist/save/codec.d.ts +49 -0
  437. package/dist/save/codec.js +169 -0
  438. package/dist/save/index.d.ts +8 -0
  439. package/dist/save/index.js +8 -0
  440. package/dist/save/journal.d.ts +24 -0
  441. package/dist/save/journal.js +102 -0
  442. package/dist/save/migrate.d.ts +15 -0
  443. package/dist/save/migrate.js +37 -0
  444. package/dist/save/schema.d.ts +72 -0
  445. package/dist/save/schema.js +154 -0
  446. package/dist/save/settings.d.ts +28 -0
  447. package/dist/save/settings.js +59 -0
  448. package/dist/save/slots.d.ts +56 -0
  449. package/dist/save/slots.js +200 -0
  450. package/dist/save/storage.d.ts +35 -0
  451. package/dist/save/storage.js +62 -0
  452. package/dist/save/store.d.ts +114 -0
  453. package/dist/save/store.js +269 -0
  454. package/dist/testing/fake-host.d.ts +103 -0
  455. package/dist/testing/fake-host.js +163 -0
  456. package/dist/testing/fixed-clock.d.ts +25 -0
  457. package/dist/testing/fixed-clock.js +30 -0
  458. package/dist/testing/index.d.ts +4 -0
  459. package/dist/testing/index.js +5 -0
  460. package/dist/testing/test-game.d.ts +76 -0
  461. package/dist/testing/test-game.js +92 -0
  462. package/dist/tween/ease.d.ts +77 -0
  463. package/dist/tween/ease.js +192 -0
  464. package/dist/tween/index.d.ts +8 -0
  465. package/dist/tween/index.js +7 -0
  466. package/dist/tween/timeline.d.ts +78 -0
  467. package/dist/tween/timeline.js +269 -0
  468. package/dist/tween/tween.d.ts +168 -0
  469. package/dist/tween/tween.js +320 -0
  470. package/dist/ui/anchor.d.ts +206 -0
  471. package/dist/ui/anchor.js +307 -0
  472. package/dist/ui/caption.d.ts +122 -0
  473. package/dist/ui/caption.js +286 -0
  474. package/dist/ui/cursor.d.ts +105 -0
  475. package/dist/ui/cursor.js +261 -0
  476. package/dist/ui/dom.d.ts +30 -0
  477. package/dist/ui/dom.js +92 -0
  478. package/dist/ui/floats.d.ts +86 -0
  479. package/dist/ui/floats.js +260 -0
  480. package/dist/ui/hud.d.ts +198 -0
  481. package/dist/ui/hud.js +431 -0
  482. package/dist/ui/index.d.ts +37 -0
  483. package/dist/ui/index.js +34 -0
  484. package/dist/ui/inventory-card.d.ts +52 -0
  485. package/dist/ui/inventory-card.js +173 -0
  486. package/dist/ui/inventory-context.d.ts +29 -0
  487. package/dist/ui/inventory-context.js +125 -0
  488. package/dist/ui/inventory-drag.d.ts +63 -0
  489. package/dist/ui/inventory-drag.js +394 -0
  490. package/dist/ui/inventory-grid.d.ts +66 -0
  491. package/dist/ui/inventory-grid.js +625 -0
  492. package/dist/ui/inventory-radial.d.ts +39 -0
  493. package/dist/ui/inventory-radial.js +168 -0
  494. package/dist/ui/inventory.d.ts +128 -0
  495. package/dist/ui/inventory.js +154 -0
  496. package/dist/ui/layout.d.ts +356 -0
  497. package/dist/ui/layout.js +856 -0
  498. package/dist/ui/link.d.ts +64 -0
  499. package/dist/ui/link.js +155 -0
  500. package/dist/ui/loading.d.ts +40 -0
  501. package/dist/ui/loading.js +157 -0
  502. package/dist/ui/loupe.d.ts +74 -0
  503. package/dist/ui/loupe.js +164 -0
  504. package/dist/ui/menu-nav.d.ts +33 -0
  505. package/dist/ui/menu-nav.js +28 -0
  506. package/dist/ui/minimap-canvas.d.ts +145 -0
  507. package/dist/ui/minimap-canvas.js +460 -0
  508. package/dist/ui/notify.d.ts +40 -0
  509. package/dist/ui/notify.js +141 -0
  510. package/dist/ui/orb.d.ts +53 -0
  511. package/dist/ui/orb.js +304 -0
  512. package/dist/ui/overlay.d.ts +213 -0
  513. package/dist/ui/overlay.js +394 -0
  514. package/dist/ui/padnav.d.ts +53 -0
  515. package/dist/ui/padnav.js +146 -0
  516. package/dist/ui/perf.d.ts +130 -0
  517. package/dist/ui/perf.js +329 -0
  518. package/dist/ui/rotate-card.d.ts +54 -0
  519. package/dist/ui/rotate-card.js +97 -0
  520. package/dist/ui/stack.d.ts +128 -0
  521. package/dist/ui/stack.js +312 -0
  522. package/dist/ui/styles.d.ts +13 -0
  523. package/dist/ui/styles.js +200 -0
  524. package/dist/ui/text-scale.d.ts +67 -0
  525. package/dist/ui/text-scale.js +102 -0
  526. package/dist/ui/theme.d.ts +70 -0
  527. package/dist/ui/theme.js +98 -0
  528. package/dist/ui/toast.d.ts +23 -0
  529. package/dist/ui/toast.js +46 -0
  530. package/dist/ui/tooltip.d.ts +89 -0
  531. package/dist/ui/tooltip.js +333 -0
  532. package/dist/ui/widgets-2.d.ts +134 -0
  533. package/dist/ui/widgets-2.js +399 -0
  534. package/dist/ui/widgets-3.d.ts +91 -0
  535. package/dist/ui/widgets-3.js +212 -0
  536. package/dist/ui/widgets.d.ts +34 -0
  537. package/dist/ui/widgets.js +50 -0
  538. package/dist/ui/world-panel/index.d.ts +5 -0
  539. package/dist/ui/world-panel/index.js +5 -0
  540. package/dist/ui/world-panel/layout.d.ts +38 -0
  541. package/dist/ui/world-panel/layout.js +68 -0
  542. package/dist/ui/world-panel/paint.d.ts +96 -0
  543. package/dist/ui/world-panel/paint.js +136 -0
  544. package/dist/ui/world-panel/panel.d.ts +235 -0
  545. package/dist/ui/world-panel/panel.js +762 -0
  546. package/dist/ui/world-panel/wgsl.d.ts +10 -0
  547. package/dist/ui/world-panel/wgsl.js +52 -0
  548. package/dist/ui/world-panel/widgets.d.ts +207 -0
  549. package/dist/ui/world-panel/widgets.js +569 -0
  550. package/dist/voxel/chunks.d.ts +77 -0
  551. package/dist/voxel/chunks.js +149 -0
  552. package/dist/voxel/grid.d.ts +84 -0
  553. package/dist/voxel/grid.js +223 -0
  554. package/dist/voxel/index.d.ts +22 -0
  555. package/dist/voxel/index.js +7 -0
  556. package/dist/voxel/mesher-worker.d.ts +14 -0
  557. package/dist/voxel/mesher-worker.js +47 -0
  558. package/dist/voxel/mesher.d.ts +73 -0
  559. package/dist/voxel/mesher.js +306 -0
  560. package/dist/voxel/ray.d.ts +32 -0
  561. package/dist/voxel/ray.js +73 -0
  562. package/dist/voxel/wgsl.d.ts +16 -0
  563. package/dist/voxel/wgsl.js +28 -0
  564. package/dist/voxel/worker-client.d.ts +79 -0
  565. package/dist/voxel/worker-client.js +122 -0
  566. package/package.json +177 -3
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Seeded coherent noise (ws/core-2): value, Perlin (gradient) and simplex noise in 2D and 3D,
3
+ * plus fractal Brownian motion over any of them.
4
+ *
5
+ * `createNoise(seed)` shuffles a 256-entry permutation table with `createRandom(seed)` (the same
6
+ * seed hash as `Random`) and fills a 256-entry lattice value table in [-1, 1]. Every function
7
+ * returns a value in [-1, 1] (gradient and simplex noise are scaled to that span and clamped),
8
+ * is continuous in its inputs, and allocates nothing. The functions are plain closures, so
9
+ * `noise.perlin2` can be passed around unbound (`fbm(noise.perlin2, x, y)`).
10
+ */
11
+ import { createRandom } from './random.js';
12
+ /** Unit gradients at eight angles for 2D Perlin. */
13
+ const G2X = new Float64Array(8);
14
+ const G2Y = new Float64Array(8);
15
+ for (let i = 0; i < 8; i++) {
16
+ G2X[i] = Math.cos((i * Math.PI) / 4);
17
+ G2Y[i] = Math.sin((i * Math.PI) / 4);
18
+ }
19
+ /** The twelve cube-edge gradients of improved Perlin and 3D simplex. */
20
+ const G3 = [
21
+ 1, 1, 0, -1, 1, 0, 1, -1, 0, -1, -1, 0, 1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, -1, 0, 1, 1, 0, -1, 1,
22
+ 0, 1, -1, 0, -1, -1,
23
+ ];
24
+ /** Twelve directions for 2D simplex (the 3D set projected, as in Gustavson). */
25
+ const S2 = [1, 1, -1, 1, 1, -1, -1, -1, 1, 0, -1, 0, 0, 1, 0, -1];
26
+ // 2D Perlin with unit gradients peaks at sqrt(2)/2; 3D with the edge set at about 1.
27
+ const PERLIN2_SCALE = Math.SQRT2;
28
+ const PERLIN3_SCALE = 1;
29
+ const SIMPLEX2_SCALE = 70;
30
+ const SIMPLEX3_SCALE = 32;
31
+ const F2 = 0.5 * (Math.sqrt(3) - 1);
32
+ const G2 = (3 - Math.sqrt(3)) / 6;
33
+ const F3 = 1 / 3;
34
+ const G3C = 1 / 6;
35
+ const DEFAULT_FBM = { octaves: 4, lacunarity: 2, gain: 0.5 };
36
+ function fade(t) {
37
+ return t * t * t * (t * (t * 6 - 15) + 10);
38
+ }
39
+ function lerp(a, b, t) {
40
+ return a + (b - a) * t;
41
+ }
42
+ function clamp1(v) {
43
+ return Math.max(-1, Math.min(1, v));
44
+ }
45
+ /** Seeded noise; see the module comment. Builds two small tables (allocates once). */
46
+ export function createNoise(seed) {
47
+ const random = createRandom(seed);
48
+ const perm = new Uint8Array(512);
49
+ for (let i = 0; i < 256; i++)
50
+ perm[i] = i;
51
+ random.shuffle(perm.subarray(0, 256));
52
+ for (let i = 0; i < 256; i++)
53
+ perm[i + 256] = perm[i];
54
+ const values = new Float64Array(256);
55
+ for (let i = 0; i < 256; i++)
56
+ values[i] = random.next() * 2 - 1;
57
+ const h2 = (x, y) => perm[perm[x & 255] + (y & 255)];
58
+ const h3 = (x, y, z) => perm[perm[perm[x & 255] + (y & 255)] + (z & 255)];
59
+ const value2 = (x, y) => {
60
+ const x0 = Math.floor(x);
61
+ const y0 = Math.floor(y);
62
+ const u = fade(x - x0);
63
+ const v = fade(y - y0);
64
+ const a = values[h2(x0, y0)];
65
+ const b = values[h2(x0 + 1, y0)];
66
+ const c = values[h2(x0, y0 + 1)];
67
+ const d = values[h2(x0 + 1, y0 + 1)];
68
+ return lerp(lerp(a, b, u), lerp(c, d, u), v);
69
+ };
70
+ const value3 = (x, y, z) => {
71
+ const x0 = Math.floor(x);
72
+ const y0 = Math.floor(y);
73
+ const z0 = Math.floor(z);
74
+ const u = fade(x - x0);
75
+ const v = fade(y - y0);
76
+ const w = fade(z - z0);
77
+ const c000 = values[h3(x0, y0, z0)];
78
+ const c100 = values[h3(x0 + 1, y0, z0)];
79
+ const c010 = values[h3(x0, y0 + 1, z0)];
80
+ const c110 = values[h3(x0 + 1, y0 + 1, z0)];
81
+ const c001 = values[h3(x0, y0, z0 + 1)];
82
+ const c101 = values[h3(x0 + 1, y0, z0 + 1)];
83
+ const c011 = values[h3(x0, y0 + 1, z0 + 1)];
84
+ const c111 = values[h3(x0 + 1, y0 + 1, z0 + 1)];
85
+ return lerp(lerp(lerp(c000, c100, u), lerp(c010, c110, u), v), lerp(lerp(c001, c101, u), lerp(c011, c111, u), v), w);
86
+ };
87
+ const grad2 = (h, x, y) => G2X[h & 7] * x + G2Y[h & 7] * y;
88
+ const grad3 = (h, x, y, z) => {
89
+ const g = (h % 12) * 3;
90
+ return G3[g] * x + G3[g + 1] * y + G3[g + 2] * z;
91
+ };
92
+ const perlin2 = (x, y) => {
93
+ const x0 = Math.floor(x);
94
+ const y0 = Math.floor(y);
95
+ const fx = x - x0;
96
+ const fy = y - y0;
97
+ const u = fade(fx);
98
+ const v = fade(fy);
99
+ const n00 = grad2(h2(x0, y0), fx, fy);
100
+ const n10 = grad2(h2(x0 + 1, y0), fx - 1, fy);
101
+ const n01 = grad2(h2(x0, y0 + 1), fx, fy - 1);
102
+ const n11 = grad2(h2(x0 + 1, y0 + 1), fx - 1, fy - 1);
103
+ return clamp1(PERLIN2_SCALE * lerp(lerp(n00, n10, u), lerp(n01, n11, u), v));
104
+ };
105
+ const perlin3 = (x, y, z) => {
106
+ const x0 = Math.floor(x);
107
+ const y0 = Math.floor(y);
108
+ const z0 = Math.floor(z);
109
+ const fx = x - x0;
110
+ const fy = y - y0;
111
+ const fz = z - z0;
112
+ const u = fade(fx);
113
+ const v = fade(fy);
114
+ const w = fade(fz);
115
+ const n000 = grad3(h3(x0, y0, z0), fx, fy, fz);
116
+ const n100 = grad3(h3(x0 + 1, y0, z0), fx - 1, fy, fz);
117
+ const n010 = grad3(h3(x0, y0 + 1, z0), fx, fy - 1, fz);
118
+ const n110 = grad3(h3(x0 + 1, y0 + 1, z0), fx - 1, fy - 1, fz);
119
+ const n001 = grad3(h3(x0, y0, z0 + 1), fx, fy, fz - 1);
120
+ const n101 = grad3(h3(x0 + 1, y0, z0 + 1), fx - 1, fy, fz - 1);
121
+ const n011 = grad3(h3(x0, y0 + 1, z0 + 1), fx, fy - 1, fz - 1);
122
+ const n111 = grad3(h3(x0 + 1, y0 + 1, z0 + 1), fx - 1, fy - 1, fz - 1);
123
+ return clamp1(PERLIN3_SCALE *
124
+ lerp(lerp(lerp(n000, n100, u), lerp(n010, n110, u), v), lerp(lerp(n001, n101, u), lerp(n011, n111, u), v), w));
125
+ };
126
+ const corner2 = (h, x, y) => {
127
+ let t = 0.5 - x * x - y * y;
128
+ if (t < 0)
129
+ return 0;
130
+ t *= t;
131
+ const g = (h & 7) * 2;
132
+ return t * t * (S2[g] * x + S2[g + 1] * y);
133
+ };
134
+ const simplex2 = (x, y) => {
135
+ const s = (x + y) * F2;
136
+ const i = Math.floor(x + s);
137
+ const j = Math.floor(y + s);
138
+ const t = (i + j) * G2;
139
+ const x0 = x - (i - t);
140
+ const y0 = y - (j - t);
141
+ const i1 = x0 > y0 ? 1 : 0;
142
+ const j1 = 1 - i1;
143
+ const x1 = x0 - i1 + G2;
144
+ const y1 = y0 - j1 + G2;
145
+ const x2 = x0 - 1 + 2 * G2;
146
+ const y2 = y0 - 1 + 2 * G2;
147
+ const n = corner2(h2(i, j), x0, y0) +
148
+ corner2(h2(i + i1, j + j1), x1, y1) +
149
+ corner2(h2(i + 1, j + 1), x2, y2);
150
+ return clamp1(SIMPLEX2_SCALE * n);
151
+ };
152
+ const corner3 = (h, x, y, z) => {
153
+ let t = 0.6 - x * x - y * y - z * z;
154
+ if (t < 0)
155
+ return 0;
156
+ t *= t;
157
+ return t * t * grad3(h, x, y, z);
158
+ };
159
+ const simplex3 = (x, y, z) => {
160
+ const s = (x + y + z) * F3;
161
+ const i = Math.floor(x + s);
162
+ const j = Math.floor(y + s);
163
+ const k = Math.floor(z + s);
164
+ const t = (i + j + k) * G3C;
165
+ const x0 = x - (i - t);
166
+ const y0 = y - (j - t);
167
+ const z0 = z - (k - t);
168
+ let i1;
169
+ let j1;
170
+ let k1;
171
+ let i2;
172
+ let j2;
173
+ let k2;
174
+ if (x0 >= y0) {
175
+ if (y0 >= z0) {
176
+ i1 = 1;
177
+ j1 = 0;
178
+ k1 = 0;
179
+ i2 = 1;
180
+ j2 = 1;
181
+ k2 = 0;
182
+ }
183
+ else if (x0 >= z0) {
184
+ i1 = 1;
185
+ j1 = 0;
186
+ k1 = 0;
187
+ i2 = 1;
188
+ j2 = 0;
189
+ k2 = 1;
190
+ }
191
+ else {
192
+ i1 = 0;
193
+ j1 = 0;
194
+ k1 = 1;
195
+ i2 = 1;
196
+ j2 = 0;
197
+ k2 = 1;
198
+ }
199
+ }
200
+ else if (y0 < z0) {
201
+ i1 = 0;
202
+ j1 = 0;
203
+ k1 = 1;
204
+ i2 = 0;
205
+ j2 = 1;
206
+ k2 = 1;
207
+ }
208
+ else if (x0 < z0) {
209
+ i1 = 0;
210
+ j1 = 1;
211
+ k1 = 0;
212
+ i2 = 0;
213
+ j2 = 1;
214
+ k2 = 1;
215
+ }
216
+ else {
217
+ i1 = 0;
218
+ j1 = 1;
219
+ k1 = 0;
220
+ i2 = 1;
221
+ j2 = 1;
222
+ k2 = 0;
223
+ }
224
+ const n = corner3(h3(i, j, k), x0, y0, z0) +
225
+ corner3(h3(i + i1, j + j1, k + k1), x0 - i1 + G3C, y0 - j1 + G3C, z0 - k1 + G3C) +
226
+ corner3(h3(i + i2, j + j2, k + k2), x0 - i2 + 2 * G3C, y0 - j2 + 2 * G3C, z0 - k2 + 2 * G3C) +
227
+ corner3(h3(i + 1, j + 1, k + 1), x0 - 1 + 3 * G3C, y0 - 1 + 3 * G3C, z0 - 1 + 3 * G3C);
228
+ return clamp1(SIMPLEX3_SCALE * n);
229
+ };
230
+ const fbm = (fn, x, y, z = 0, opts = DEFAULT_FBM) => {
231
+ const octaves = Math.max(1, Math.floor(opts.octaves ?? DEFAULT_FBM.octaves));
232
+ const lacunarity = opts.lacunarity ?? DEFAULT_FBM.lacunarity;
233
+ const gain = opts.gain ?? DEFAULT_FBM.gain;
234
+ let freq = 1;
235
+ let amp = 1;
236
+ let sum = 0;
237
+ let norm = 0;
238
+ for (let o = 0; o < octaves; o++) {
239
+ sum += amp * fn(x * freq, y * freq, z * freq);
240
+ norm += amp;
241
+ freq *= lacunarity;
242
+ amp *= gain;
243
+ }
244
+ return norm > 0 ? sum / norm : 0;
245
+ };
246
+ return { value2, value3, perlin2, perlin3, simplex2, simplex3, fbm };
247
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A typed object pool (ws/core-2): reuse effect records, projectiles, labels or scratch objects
3
+ * instead of allocating per event.
4
+ *
5
+ * - `acquire()` takes the most recently released free item (LIFO), or creates one while `size`
6
+ * is below `max`. Past `max` it returns `undefined`: that is how a game caps its effects (drop
7
+ * the spawn, or recycle its own oldest), never by growing without bound.
8
+ * - `release(item)` calls `reset(item)` and returns the item to the free list; releasing an item
9
+ * that is not live (twice, or foreign) does nothing and returns false.
10
+ * - `forEach(fn)` visits the live items only, newest index last, iterating backwards so `fn` may
11
+ * release the item it is given. Release swaps the last live item into the freed place, so the
12
+ * visit order is not acquisition order.
13
+ *
14
+ * Nothing allocates after the pool has grown to its peak (items are created by `create`, the
15
+ * lists keep their capacity).
16
+ */
17
+ export interface PoolOptions<T> {
18
+ /** Make a new item. */
19
+ create: () => T;
20
+ /** Return an item to its idle state; called on `release` and `drain`. */
21
+ reset?: (item: T) => void;
22
+ /** Items created up front. Default 0. */
23
+ initial?: number;
24
+ /** Most items the pool will ever create. Default unbounded. */
25
+ max?: number;
26
+ }
27
+ export interface Pool<T> {
28
+ /** Items created so far (live plus free). */
29
+ readonly size: number;
30
+ /** Items acquired and not yet released. */
31
+ readonly live: number;
32
+ /** A free item, a new one while under `max`, or `undefined` at the cap. */
33
+ acquire(): T | undefined;
34
+ /** Reset `item` and make it free again; false when it was not live. */
35
+ release(item: T): boolean;
36
+ /** Visit live items (backwards; `fn` may release its item). No allocation. */
37
+ forEach(fn: (item: T, index: number) => void): void;
38
+ /** Release every live item. */
39
+ drain(): void;
40
+ }
41
+ /** A pool of `T` (an object type: items are tracked by identity); see the module comment. */
42
+ export declare function createPool<T extends object>(opts: PoolOptions<T>): Pool<T>;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * A typed object pool (ws/core-2): reuse effect records, projectiles, labels or scratch objects
3
+ * instead of allocating per event.
4
+ *
5
+ * - `acquire()` takes the most recently released free item (LIFO), or creates one while `size`
6
+ * is below `max`. Past `max` it returns `undefined`: that is how a game caps its effects (drop
7
+ * the spawn, or recycle its own oldest), never by growing without bound.
8
+ * - `release(item)` calls `reset(item)` and returns the item to the free list; releasing an item
9
+ * that is not live (twice, or foreign) does nothing and returns false.
10
+ * - `forEach(fn)` visits the live items only, newest index last, iterating backwards so `fn` may
11
+ * release the item it is given. Release swaps the last live item into the freed place, so the
12
+ * visit order is not acquisition order.
13
+ *
14
+ * Nothing allocates after the pool has grown to its peak (items are created by `create`, the
15
+ * lists keep their capacity).
16
+ */
17
+ class PoolImpl {
18
+ freeItems = [];
19
+ liveItems = [];
20
+ /** item → index in `liveItems`, or -1 when free. */
21
+ index = new Map();
22
+ create;
23
+ reset;
24
+ max;
25
+ constructor(opts) {
26
+ this.create = opts.create;
27
+ this.reset = opts.reset;
28
+ this.max = opts.max ?? Number.POSITIVE_INFINITY;
29
+ const initial = Math.min(opts.initial ?? 0, this.max);
30
+ for (let i = 0; i < initial; i++) {
31
+ const item = this.create();
32
+ this.index.set(item, -1);
33
+ this.freeItems.push(item);
34
+ }
35
+ }
36
+ get size() {
37
+ return this.index.size;
38
+ }
39
+ get live() {
40
+ return this.liveItems.length;
41
+ }
42
+ acquire() {
43
+ let item = this.freeItems.pop();
44
+ if (item === undefined) {
45
+ if (this.index.size >= this.max)
46
+ return undefined;
47
+ item = this.create();
48
+ }
49
+ this.index.set(item, this.liveItems.length);
50
+ this.liveItems.push(item);
51
+ return item;
52
+ }
53
+ release(item) {
54
+ const i = this.index.get(item);
55
+ if (i === undefined || i < 0)
56
+ return false;
57
+ const live = this.liveItems;
58
+ const last = live.pop();
59
+ if (last !== item) {
60
+ live[i] = last;
61
+ this.index.set(last, i);
62
+ }
63
+ this.index.set(item, -1);
64
+ this.reset?.(item);
65
+ this.freeItems.push(item);
66
+ return true;
67
+ }
68
+ forEach(fn) {
69
+ const live = this.liveItems;
70
+ for (let i = live.length - 1; i >= 0; i--) {
71
+ if (i >= live.length)
72
+ continue;
73
+ fn(live[i], i);
74
+ }
75
+ }
76
+ drain() {
77
+ const live = this.liveItems;
78
+ while (live.length > 0)
79
+ this.release(live[live.length - 1]);
80
+ }
81
+ }
82
+ /** A pool of `T` (an object type: items are tracked by identity); see the module comment. */
83
+ export function createPool(opts) {
84
+ return new PoolImpl(opts);
85
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Seeded random numbers with named streams (ws/core-2).
3
+ *
4
+ * Generator: xoshiro128** (Blackman and Vigna), 128 bits of state in a `Uint32Array(4)`, period
5
+ * 2^128 − 1, 32-bit output. A seed is turned into a 32-bit key (a number seed that is an integer
6
+ * is taken `>>> 0`; any other number, and every string, is hashed with 32-bit FNV-1a over its
7
+ * UTF-8 bytes: offset basis 0x811c9dc5, prime 0x01000193), and the key is expanded into the four
8
+ * state words with splitmix32. The same seed gives the same sequence on every engine.
9
+ *
10
+ * `fork(name)` derives a child key from the stream's own key and the name (FNV-1a of the name
11
+ * started from the parent key), never from the parent's current state, so how often one stream is
12
+ * used never changes another. Every draw, and `seedKey` itself, allocates nothing; `fork` and the
13
+ * `state` getter do.
14
+ */
15
+ export type Seed = number | string;
16
+ /** Anything indexable by number that a vector helper can write into (`Float32Array`, `number[]`). */
17
+ export interface NumberSink {
18
+ [index: number]: number;
19
+ }
20
+ export interface Random {
21
+ /** The 32-bit key this stream was seeded from (a fork's key is derived from its parent's). */
22
+ readonly key: number;
23
+ /** A float in [0, 1). */
24
+ next(): number;
25
+ /** An integer in [min, max], both ends included; unbiased (rejection sampling). */
26
+ int(min: number, max: number): number;
27
+ /** A float in [min, max). */
28
+ float(min: number, max: number): number;
29
+ /** True with probability `p` (default 0.5). */
30
+ bool(p?: number): boolean;
31
+ /** A uniformly chosen element. Throws a `RangeError` on an empty array. */
32
+ pick<T>(array: ArrayLike<T>): T;
33
+ /** An index chosen with probability `weights[i] / sum`; -1 when the sum is not positive. */
34
+ weighted(weights: ArrayLike<number>): number;
35
+ /** Fisher–Yates in place; returns `array`. */
36
+ shuffle<T, A extends {
37
+ [index: number]: T;
38
+ length: number;
39
+ }>(array: A): A;
40
+ /** A normal sample (Box–Muller; two uniforms per call, nothing cached, so `state` is complete). */
41
+ gaussian(mean?: number, sd?: number): number;
42
+ /** A uniformly distributed unit vector into `out[0..1]`; returns `out`. */
43
+ unitVec2<T extends NumberSink>(out: T): T;
44
+ /** A uniformly distributed unit vector on the sphere into `out[0..2]`; returns `out`. */
45
+ unitVec3<T extends NumberSink>(out: T): T;
46
+ /** A child stream keyed by this stream's key and `name`; independent of draws on this one. */
47
+ fork(name: string): Random;
48
+ /** The four state words. Reading copies; writing copies in (an all-zero state is rejected). */
49
+ state: Uint32Array;
50
+ }
51
+ /**
52
+ * The 32-bit key of a seed: the key `createRandom(seed)` is seeded from (`random.key`) and the
53
+ * one `hash2`/`hash3` mix their coordinates into. An integer number seed is taken `>>> 0`; any
54
+ * other number, and every string, is hashed with 32-bit FNV-1a over its UTF-8 bytes. A game uses
55
+ * it to derive its own stable hashes from the same seed the engine does, for example
56
+ * `seedKey('level-3') ^ chunkId`. Pure and allocation-free; the value never changes between
57
+ * engine versions (the FNV-1a reference values are tested).
58
+ */
59
+ export declare function seedKey(seed: Seed): number;
60
+ /** A seeded stream; see the module comment for the generator, the seed hash and `fork`. */
61
+ export declare function createRandom(seed: Seed): Random;
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Seeded random numbers with named streams (ws/core-2).
3
+ *
4
+ * Generator: xoshiro128** (Blackman and Vigna), 128 bits of state in a `Uint32Array(4)`, period
5
+ * 2^128 − 1, 32-bit output. A seed is turned into a 32-bit key (a number seed that is an integer
6
+ * is taken `>>> 0`; any other number, and every string, is hashed with 32-bit FNV-1a over its
7
+ * UTF-8 bytes: offset basis 0x811c9dc5, prime 0x01000193), and the key is expanded into the four
8
+ * state words with splitmix32. The same seed gives the same sequence on every engine.
9
+ *
10
+ * `fork(name)` derives a child key from the stream's own key and the name (FNV-1a of the name
11
+ * started from the parent key), never from the parent's current state, so how often one stream is
12
+ * used never changes another. Every draw, and `seedKey` itself, allocates nothing; `fork` and the
13
+ * `state` getter do.
14
+ */
15
+ const FNV_OFFSET = 0x811c9dc5;
16
+ const FNV_PRIME = 0x01000193;
17
+ const INV_2_32 = 1 / 4294967296;
18
+ /** 32-bit FNV-1a over the UTF-8 bytes of `s`, starting from `basis`. No allocation. */
19
+ function fnv1a(s, basis = FNV_OFFSET) {
20
+ let h = basis >>> 0;
21
+ for (let i = 0; i < s.length; i++) {
22
+ let c = s.charCodeAt(i);
23
+ if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length) {
24
+ const d = s.charCodeAt(i + 1);
25
+ if (d >= 0xdc00 && d <= 0xdfff) {
26
+ c = 0x10000 + ((c - 0xd800) << 10) + (d - 0xdc00);
27
+ i++;
28
+ }
29
+ }
30
+ if (c < 0x80)
31
+ h = Math.imul(h ^ c, FNV_PRIME);
32
+ else if (c < 0x800) {
33
+ h = Math.imul(h ^ (0xc0 | (c >> 6)), FNV_PRIME);
34
+ h = Math.imul(h ^ (0x80 | (c & 63)), FNV_PRIME);
35
+ }
36
+ else if (c < 0x10000) {
37
+ h = Math.imul(h ^ (0xe0 | (c >> 12)), FNV_PRIME);
38
+ h = Math.imul(h ^ (0x80 | ((c >> 6) & 63)), FNV_PRIME);
39
+ h = Math.imul(h ^ (0x80 | (c & 63)), FNV_PRIME);
40
+ }
41
+ else {
42
+ h = Math.imul(h ^ (0xf0 | (c >> 18)), FNV_PRIME);
43
+ h = Math.imul(h ^ (0x80 | ((c >> 12) & 63)), FNV_PRIME);
44
+ h = Math.imul(h ^ (0x80 | ((c >> 6) & 63)), FNV_PRIME);
45
+ h = Math.imul(h ^ (0x80 | (c & 63)), FNV_PRIME);
46
+ }
47
+ }
48
+ return h >>> 0;
49
+ }
50
+ /**
51
+ * The 32-bit key of a seed: the key `createRandom(seed)` is seeded from (`random.key`) and the
52
+ * one `hash2`/`hash3` mix their coordinates into. An integer number seed is taken `>>> 0`; any
53
+ * other number, and every string, is hashed with 32-bit FNV-1a over its UTF-8 bytes. A game uses
54
+ * it to derive its own stable hashes from the same seed the engine does, for example
55
+ * `seedKey('level-3') ^ chunkId`. Pure and allocation-free; the value never changes between
56
+ * engine versions (the FNV-1a reference values are tested).
57
+ */
58
+ export function seedKey(seed) {
59
+ if (typeof seed === 'number' && Number.isInteger(seed))
60
+ return seed >>> 0;
61
+ return fnv1a(String(seed));
62
+ }
63
+ /** Expand a 32-bit key into four xoshiro words with splitmix32 (never all zero). */
64
+ function expand(key, out) {
65
+ let s = key | 0;
66
+ for (let i = 0; i < 4; i++) {
67
+ s = (s + 0x9e3779b9) | 0;
68
+ let z = s;
69
+ z = Math.imul(z ^ (z >>> 16), 0x85ebca6b);
70
+ z = Math.imul(z ^ (z >>> 13), 0xc2b2ae35);
71
+ out[i] = (z ^ (z >>> 16)) >>> 0;
72
+ }
73
+ if ((out[0] | out[1] | out[2] | out[3]) === 0)
74
+ out[0] = 1;
75
+ }
76
+ class XoshiroRandom {
77
+ key;
78
+ s = new Uint32Array(4);
79
+ constructor(key) {
80
+ this.key = key;
81
+ expand(key, this.s);
82
+ }
83
+ /** The next 32-bit output (xoshiro128**). */
84
+ u32() {
85
+ const s = this.s;
86
+ const s0 = s[0];
87
+ const s1 = s[1];
88
+ const s2 = s[2];
89
+ const s3 = s[3];
90
+ const m = Math.imul(s1, 5);
91
+ const result = Math.imul((m << 7) | (m >>> 25), 9) >>> 0;
92
+ const t = s1 << 9;
93
+ const n2 = s2 ^ s0;
94
+ const n3 = s3 ^ s1;
95
+ s[1] = s1 ^ n2;
96
+ s[0] = s0 ^ n3;
97
+ s[2] = n2 ^ t;
98
+ s[3] = (n3 << 11) | (n3 >>> 21);
99
+ return result;
100
+ }
101
+ next() {
102
+ return this.u32() * INV_2_32;
103
+ }
104
+ int(min, max) {
105
+ const lo = Math.ceil(Math.min(min, max));
106
+ const hi = Math.floor(Math.max(min, max));
107
+ const n = hi - lo + 1;
108
+ if (n <= 1)
109
+ return lo;
110
+ if (n > 4294967296)
111
+ return lo + Math.floor(this.next() * n);
112
+ // Reject the top sliver of 2^32 that does not divide evenly by n.
113
+ const limit = 4294967296 - (4294967296 % n);
114
+ let u = this.u32();
115
+ while (u >= limit)
116
+ u = this.u32();
117
+ return lo + (u % n);
118
+ }
119
+ float(min, max) {
120
+ return min + this.next() * (max - min);
121
+ }
122
+ bool(p = 0.5) {
123
+ return this.next() < p;
124
+ }
125
+ pick(array) {
126
+ if (array.length === 0)
127
+ throw new RangeError('Random.pick: empty array');
128
+ return array[this.int(0, array.length - 1)];
129
+ }
130
+ weighted(weights) {
131
+ let sum = 0;
132
+ for (let i = 0; i < weights.length; i++) {
133
+ const w = weights[i];
134
+ if (w > 0)
135
+ sum += w;
136
+ }
137
+ if (!(sum > 0))
138
+ return -1;
139
+ let r = this.next() * sum;
140
+ let last = -1;
141
+ for (let i = 0; i < weights.length; i++) {
142
+ const w = weights[i];
143
+ if (!(w > 0))
144
+ continue;
145
+ last = i;
146
+ if (r < w)
147
+ return i;
148
+ r -= w;
149
+ }
150
+ return last;
151
+ }
152
+ shuffle(array) {
153
+ for (let i = array.length - 1; i > 0; i--) {
154
+ const j = this.int(0, i);
155
+ const tmp = array[i];
156
+ array[i] = array[j];
157
+ array[j] = tmp;
158
+ }
159
+ return array;
160
+ }
161
+ gaussian(mean = 0, sd = 1) {
162
+ const u1 = 1 - this.next(); // (0, 1]: log stays finite
163
+ const u2 = this.next();
164
+ return mean + sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
165
+ }
166
+ unitVec2(out) {
167
+ const a = this.next() * 2 * Math.PI;
168
+ out[0] = Math.cos(a);
169
+ out[1] = Math.sin(a);
170
+ return out;
171
+ }
172
+ unitVec3(out) {
173
+ const z = this.next() * 2 - 1;
174
+ const a = this.next() * 2 * Math.PI;
175
+ const r = Math.sqrt(1 - z * z);
176
+ out[0] = r * Math.cos(a);
177
+ out[1] = r * Math.sin(a);
178
+ out[2] = z;
179
+ return out;
180
+ }
181
+ fork(name) {
182
+ return new XoshiroRandom(fnv1a(name, this.key ^ 0x9e3779b9));
183
+ }
184
+ get state() {
185
+ return this.s.slice();
186
+ }
187
+ set state(words) {
188
+ if (words.length !== 4)
189
+ throw new RangeError('Random.state: expected 4 words');
190
+ if ((words[0] | words[1] | words[2] | words[3]) === 0) {
191
+ throw new RangeError('Random.state: an all-zero state is invalid for xoshiro128**');
192
+ }
193
+ this.s.set(words);
194
+ }
195
+ }
196
+ /** A seeded stream; see the module comment for the generator, the seed hash and `fork`. */
197
+ export function createRandom(seed) {
198
+ return new XoshiroRandom(seedKey(seed));
199
+ }