@cimplify/sdk 0.108.0 → 0.110.2

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 (608) hide show
  1. package/LICENSE +21 -0
  2. package/dist/advanced.d.mts +4 -3
  3. package/dist/advanced.d.ts +4 -3
  4. package/dist/advanced.js +24 -24
  5. package/dist/advanced.mjs +5 -5
  6. package/dist/animation-4EXBXRVX.js +27 -0
  7. package/dist/animation-6DICNWUP.mjs +6 -0
  8. package/dist/audio-DhvyjqdA.d.mts +249 -0
  9. package/dist/audio-m0w8cnxq.d.ts +249 -0
  10. package/dist/avatars.d.mts +110 -0
  11. package/dist/avatars.d.ts +110 -0
  12. package/dist/avatars.js +82 -0
  13. package/dist/avatars.mjs +5 -0
  14. package/dist/backend-gUCzs5Kg.d.mts +3866 -0
  15. package/dist/backend-gUCzs5Kg.d.ts +3866 -0
  16. package/dist/{catalogue-B4eLL8Mi.d.ts → catalogue-CPTMyBUz.d.mts} +109 -221
  17. package/dist/catalogue-DzrTXP3v.d.mts +541 -0
  18. package/dist/catalogue-DzrTXP3v.d.ts +541 -0
  19. package/dist/{catalogue-OT89_Ifs.d.mts → catalogue-OTuS5zp-.d.ts} +109 -221
  20. package/dist/chunk-22BD3RHN.mjs +1809 -0
  21. package/dist/chunk-25T4JHEA.mjs +21 -0
  22. package/dist/chunk-2AQ237Y4.js +508 -0
  23. package/dist/chunk-2IC4H6OV.mjs +48 -0
  24. package/dist/chunk-2LHLG4OB.mjs +71 -0
  25. package/dist/chunk-2O2CG465.js +1709 -0
  26. package/dist/chunk-2Q4DTHXK.js +316 -0
  27. package/dist/chunk-2QTQ6BUH.mjs +46 -0
  28. package/dist/chunk-2UN4SFLR.mjs +100 -0
  29. package/dist/chunk-2V75I7K3.js +454 -0
  30. package/dist/chunk-2V7IL4HC.js +10 -0
  31. package/dist/chunk-34XBXUMW.js +296 -0
  32. package/dist/chunk-3C4C654I.js +71 -0
  33. package/dist/chunk-3DAD2LDF.mjs +72 -0
  34. package/dist/chunk-3GXH2NFD.mjs +4 -0
  35. package/dist/chunk-3O47ZFW3.js +961 -0
  36. package/dist/chunk-3OY3VYNF.mjs +11 -0
  37. package/dist/chunk-3S6WPBZL.js +2936 -0
  38. package/dist/chunk-3TUOUP5T.js +399 -0
  39. package/dist/chunk-3VEH23I5.mjs +1380 -0
  40. package/dist/chunk-3ZYSAW2T.mjs +263 -0
  41. package/dist/chunk-4ANVF274.js +103 -0
  42. package/dist/chunk-4C7I3ELN.js +388 -0
  43. package/dist/chunk-4DYKAYFO.mjs +8 -0
  44. package/dist/chunk-4ZDR72SG.js +329 -0
  45. package/dist/chunk-52YS45RR.js +1066 -0
  46. package/dist/chunk-5325XSCH.js +107 -0
  47. package/dist/chunk-5AD5X6AV.js +13 -0
  48. package/dist/chunk-5BYDGGWO.mjs +197 -0
  49. package/dist/chunk-5C3C7VDM.mjs +55 -0
  50. package/dist/chunk-5HFMY3D7.js +660 -0
  51. package/dist/chunk-5LH2QN3T.js +1862 -0
  52. package/dist/chunk-5PJEXSOW.js +44 -0
  53. package/dist/chunk-5SXDH3Y7.js +90 -0
  54. package/dist/chunk-5YFBGGCK.mjs +502 -0
  55. package/dist/chunk-5YWN6H5Q.mjs +133 -0
  56. package/dist/chunk-66QP3SMN.js +402 -0
  57. package/dist/chunk-6DAEZKIG.mjs +385 -0
  58. package/dist/chunk-6DATW7TB.mjs +420 -0
  59. package/dist/{chunk-JRGK3NXR.mjs → chunk-6ETDAU62.mjs} +72 -212
  60. package/dist/chunk-6H254EVP.mjs +178 -0
  61. package/dist/chunk-6PFNJPBJ.mjs +820 -0
  62. package/dist/chunk-6PJWXIFX.mjs +357 -0
  63. package/dist/chunk-6SWKWCMS.js +80 -0
  64. package/dist/chunk-6VVXXX7S.js +808 -0
  65. package/dist/chunk-6WUBSMTX.js +1403 -0
  66. package/dist/chunk-73SGZLAQ.mjs +35 -0
  67. package/dist/chunk-76L2V6KD.mjs +4 -0
  68. package/dist/chunk-7AAIAVAA.js +1531 -0
  69. package/dist/chunk-7ARSJPV3.mjs +93 -0
  70. package/dist/chunk-7BHW5GTC.mjs +1234 -0
  71. package/dist/chunk-7DQSDKDU.js +6 -0
  72. package/dist/chunk-7IQQQENP.mjs +401 -0
  73. package/dist/chunk-7KFTYENS.js +11357 -0
  74. package/dist/chunk-7SM6XSPZ.js +3171 -0
  75. package/dist/chunk-7SXOHAIR.mjs +28 -0
  76. package/dist/chunk-A2MAX6S4.js +90 -0
  77. package/dist/chunk-A33OORT7.mjs +1530 -0
  78. package/dist/{chunk-U6ACF76H.mjs → chunk-A36JRXXH.mjs} +1075 -1845
  79. package/dist/chunk-A7BU3BK4.js +52 -0
  80. package/dist/chunk-A7MQSN2V.mjs +77 -0
  81. package/dist/chunk-A7V4L2IT.mjs +416 -0
  82. package/dist/chunk-AABEK6XU.js +226 -0
  83. package/dist/chunk-AGV33FWC.mjs +5005 -0
  84. package/dist/chunk-AHNR3BXI.js +108 -0
  85. package/dist/chunk-AQ5RLBU2.mjs +286 -0
  86. package/dist/chunk-AQOE6WCG.js +1270 -0
  87. package/dist/chunk-ATAWRACV.mjs +62 -0
  88. package/dist/chunk-ATCURNUV.js +14 -0
  89. package/dist/chunk-AWPV33OO.js +6 -0
  90. package/dist/chunk-AYJPHKYV.js +337 -0
  91. package/dist/chunk-AZ5BGWHB.js +162 -0
  92. package/dist/chunk-AZAXD44P.js +1373 -0
  93. package/dist/chunk-BBGKQIJJ.mjs +406 -0
  94. package/dist/chunk-BP4JLSUA.js +1453 -0
  95. package/dist/{chunk-SUCE7FWA.mjs → chunk-BTUSVHIE.mjs} +539 -978
  96. package/dist/chunk-BU6OK542.mjs +818 -0
  97. package/dist/chunk-CVSRWM6W.js +418 -0
  98. package/dist/chunk-CYBMFMJD.mjs +247 -0
  99. package/dist/chunk-DDJLDOUX.mjs +217 -0
  100. package/dist/{chunk-V32BCG7M.js → chunk-DFZWHNRG.js} +75 -215
  101. package/dist/chunk-DJ2C7AVG.js +644 -0
  102. package/dist/chunk-DS2VU4WW.mjs +102 -0
  103. package/dist/chunk-DSAG7T5P.js +7290 -0
  104. package/dist/chunk-E2QPPH7I.js +327 -0
  105. package/dist/chunk-E65WCTIG.mjs +1187 -0
  106. package/dist/{chunk-33VCYWVL.mjs → chunk-E6QQKDNE.mjs} +30 -42
  107. package/dist/chunk-ECDK6QBF.mjs +981 -0
  108. package/dist/chunk-EIB4OWVQ.mjs +620 -0
  109. package/dist/chunk-EQUZYCGO.js +250 -0
  110. package/dist/chunk-F3UJ6ZRM.mjs +313 -0
  111. package/dist/chunk-F63N2ZTQ.js +7023 -0
  112. package/dist/chunk-F6XRYEM3.mjs +26 -0
  113. package/dist/chunk-FE6VCE4K.js +5030 -0
  114. package/dist/chunk-FLWD6GRR.js +1372 -0
  115. package/dist/chunk-FQBFWJBS.mjs +110 -0
  116. package/dist/chunk-FXVJ2HFU.js +26 -0
  117. package/dist/chunk-FZMQMQBW.js +312 -0
  118. package/dist/chunk-G3EEC44R.js +53 -0
  119. package/dist/{chunk-KG3WT4PR.mjs → chunk-GCKWKLZF.mjs} +73 -104
  120. package/dist/chunk-GCX7TY4D.mjs +6826 -0
  121. package/dist/chunk-GDB6TCSD.js +450 -0
  122. package/dist/chunk-GDCV4IWO.mjs +21 -0
  123. package/dist/chunk-GDZT5LZ5.js +170 -0
  124. package/dist/chunk-GHPUYD4I.mjs +213 -0
  125. package/dist/chunk-GHS6MIL6.mjs +1432 -0
  126. package/dist/chunk-GPS2THCL.mjs +11 -0
  127. package/dist/{chunk-EV2EVOYS.js → chunk-GTJWQAGU.js} +31 -42
  128. package/dist/chunk-GVTI6UJQ.mjs +130 -0
  129. package/dist/chunk-GXKI64OT.mjs +1138 -0
  130. package/dist/chunk-GYDYF2WX.js +275 -0
  131. package/dist/chunk-GYLP6UG4.mjs +705 -0
  132. package/dist/chunk-H3OQKK6X.js +1158 -0
  133. package/dist/chunk-H5DFSCJ6.js +40 -0
  134. package/dist/chunk-HAGEIC2L.mjs +186 -0
  135. package/dist/chunk-HAJ4JRFO.js +293 -0
  136. package/dist/chunk-HDR72GB6.js +188 -0
  137. package/dist/chunk-HF5HPS4T.mjs +40 -0
  138. package/dist/chunk-HK6LOFDS.js +218 -0
  139. package/dist/chunk-HMWYTXCY.mjs +143 -0
  140. package/dist/chunk-HPCSRCMA.js +89 -0
  141. package/dist/chunk-HSEO6TPU.js +247 -0
  142. package/dist/chunk-I5FOHCLH.js +132 -0
  143. package/dist/chunk-IDLW4NWA.mjs +85 -0
  144. package/dist/chunk-IIDZ5WUX.js +61 -0
  145. package/dist/chunk-IR74FJHU.js +2332 -0
  146. package/dist/chunk-IRVFYAKP.mjs +100 -0
  147. package/dist/{chunk-XBL3TMPC.mjs → chunk-IZDWAL53.mjs} +1795 -3287
  148. package/dist/chunk-J2KZXIU3.js +51 -0
  149. package/dist/chunk-J2U6PJSO.js +91 -0
  150. package/dist/chunk-J5AJNY2N.js +283 -0
  151. package/dist/chunk-J6KQZ4FO.mjs +821 -0
  152. package/dist/{chunk-OWW5GUSB.js → chunk-JGBCIKJV.js} +7 -6
  153. package/dist/chunk-JKGTBMU7.mjs +25 -0
  154. package/dist/chunk-JR3TNEQC.js +422 -0
  155. package/dist/chunk-JURRXY2J.mjs +29 -0
  156. package/dist/chunk-K3HW5I2A.mjs +317 -0
  157. package/dist/chunk-K46SMZ66.mjs +103 -0
  158. package/dist/chunk-K4UDGE3Z.mjs +6 -0
  159. package/dist/chunk-KDQOR4QQ.mjs +350 -0
  160. package/dist/chunk-KDTVOLHI.mjs +288 -0
  161. package/dist/chunk-KGHJH5KJ.mjs +35 -0
  162. package/dist/chunk-KIZOA5LX.mjs +140 -0
  163. package/dist/chunk-KK6HYVBI.mjs +242 -0
  164. package/dist/chunk-KMKWGXMK.js +856 -0
  165. package/dist/chunk-KPA6K5IB.js +80 -0
  166. package/dist/chunk-KU7O4IXU.mjs +260 -0
  167. package/dist/chunk-KVFNRJOR.mjs +11142 -0
  168. package/dist/chunk-KZJRSXHK.js +2432 -0
  169. package/dist/chunk-LHWPRUJL.js +79 -0
  170. package/dist/chunk-LIV3KXJG.mjs +369 -0
  171. package/dist/chunk-LKV4LACG.js +21 -0
  172. package/dist/chunk-LUY45X3U.mjs +263 -0
  173. package/dist/chunk-LYEZZEEF.mjs +17 -0
  174. package/dist/chunk-M5EXQZYY.mjs +1519 -0
  175. package/dist/chunk-ME6HGG4I.mjs +1338 -0
  176. package/dist/chunk-MEXP6DA6.js +31 -0
  177. package/dist/chunk-MG52AW3H.js +902 -0
  178. package/dist/chunk-MIPO6F72.js +334 -0
  179. package/dist/{chunk-5QW7CQBA.js → chunk-MKIJQL5Q.js} +211 -321
  180. package/dist/chunk-MN3YETVN.mjs +17 -0
  181. package/dist/chunk-MOBSBXVE.mjs +2391 -0
  182. package/dist/chunk-MOMOZEUM.mjs +88 -0
  183. package/dist/chunk-MRFUNRAP.js +62 -0
  184. package/dist/chunk-MTIHEW2M.js +433 -0
  185. package/dist/chunk-N4RGGDEL.mjs +73 -0
  186. package/dist/chunk-NH654HAT.js +10 -0
  187. package/dist/chunk-NHJUGZUR.mjs +253 -0
  188. package/dist/chunk-NMQT4HG3.mjs +757 -0
  189. package/dist/chunk-NPSYB6DC.mjs +906 -0
  190. package/dist/chunk-NW2GPMSO.js +857 -0
  191. package/dist/chunk-NXKQOQ6L.js +76 -0
  192. package/dist/chunk-NXLAZIJZ.js +309 -0
  193. package/dist/chunk-NYWNA5CF.js +148 -0
  194. package/dist/chunk-NZTKLY2W.js +1442 -0
  195. package/dist/chunk-O2ICABUD.js +36 -0
  196. package/dist/chunk-OIVVQQ22.js +862 -0
  197. package/dist/chunk-OKC2B4O3.mjs +312 -0
  198. package/dist/chunk-OLWFPDBK.js +2220 -0
  199. package/dist/chunk-OMTVH334.js +3779 -0
  200. package/dist/chunk-OQRVEM56.mjs +362 -0
  201. package/dist/chunk-OXMIBOD4.js +337 -0
  202. package/dist/chunk-PBL6YL5L.mjs +288 -0
  203. package/dist/chunk-PDOELNNQ.js +97 -0
  204. package/dist/chunk-PDQJY2GZ.js +136 -0
  205. package/dist/chunk-PKOZXD2Q.js +1274 -0
  206. package/dist/chunk-PPF2BYFL.mjs +2191 -0
  207. package/dist/chunk-PQTQKNKD.js +539 -0
  208. package/dist/chunk-PRSR4FAV.mjs +81 -0
  209. package/dist/chunk-PTRNO5UD.js +95 -0
  210. package/dist/chunk-Q2Y3VMKH.js +2000 -0
  211. package/dist/chunk-QCZOE65N.js +96 -0
  212. package/dist/chunk-QDYFLATW.mjs +52 -0
  213. package/dist/chunk-QQABGCMM.js +22 -0
  214. package/dist/chunk-QS6TRHMR.js +345 -0
  215. package/dist/chunk-R56P64LB.mjs +208 -0
  216. package/dist/chunk-RCQ2MPBV.js +428 -0
  217. package/dist/chunk-RFVRPYR2.mjs +856 -0
  218. package/dist/chunk-RKBLPGPV.js +11521 -0
  219. package/dist/chunk-RM2V4IND.mjs +327 -0
  220. package/dist/chunk-RQXN5A34.mjs +613 -0
  221. package/dist/chunk-RUVGVNOF.mjs +2687 -0
  222. package/dist/chunk-SAFJIGYB.mjs +165 -0
  223. package/dist/chunk-SKQFLBDD.js +263 -0
  224. package/dist/chunk-SMK6JU2F.mjs +2092 -0
  225. package/dist/{chunk-UVRPC2P7.js → chunk-SNNEOS5Z.js} +1984 -3476
  226. package/dist/chunk-SPCRQ6NO.mjs +1246 -0
  227. package/dist/chunk-SWX4SALA.mjs +19 -0
  228. package/dist/{chunk-JVODCGFP.mjs → chunk-SYEO2WV4.mjs} +128 -238
  229. package/dist/chunk-T2QQMX2N.js +10 -0
  230. package/dist/chunk-T3AFF3L7.mjs +57 -0
  231. package/dist/chunk-T6Z2EXYL.js +712 -0
  232. package/dist/chunk-T7LOXGYX.js +118 -0
  233. package/dist/chunk-TJCAE7RC.mjs +1315 -0
  234. package/dist/chunk-TJI3K6RP.js +137 -0
  235. package/dist/chunk-TL2SVO4P.mjs +55 -0
  236. package/dist/chunk-TM63CYGN.mjs +399 -0
  237. package/dist/chunk-TU5RYTYU.mjs +13 -0
  238. package/dist/chunk-TVJZ4GPS.js +1553 -0
  239. package/dist/chunk-TWM6DLYF.js +371 -0
  240. package/dist/chunk-U63OC4TQ.js +30 -0
  241. package/dist/{chunk-L5GKVQVJ.js → chunk-U6BVSJZ6.js} +25 -57
  242. package/dist/chunk-U6UVWEAK.mjs +792 -0
  243. package/dist/chunk-UCEPNO6N.mjs +11048 -0
  244. package/dist/{chunk-ANT574FD.js → chunk-UCR5HRYM.js} +74 -105
  245. package/dist/chunk-UG5BTOTF.mjs +334 -0
  246. package/dist/chunk-UGH37BQW.mjs +157 -0
  247. package/dist/chunk-V7ZRH3PY.mjs +271 -0
  248. package/dist/chunk-VBGHBL3E.mjs +1394 -0
  249. package/dist/chunk-VRBDAS5I.js +920 -0
  250. package/dist/chunk-VVE3Y76O.js +230 -0
  251. package/dist/chunk-W65JIRI4.mjs +1182 -0
  252. package/dist/chunk-WHYKAT7G.js +62 -0
  253. package/dist/{chunk-YOIVZ6OA.mjs → chunk-WIZRUIZB.mjs} +25 -57
  254. package/dist/chunk-WKWTDZS7.js +385 -0
  255. package/dist/chunk-WLMINRC4.mjs +78 -0
  256. package/dist/chunk-WOF3AD3J.js +22 -0
  257. package/dist/chunk-WWKMOA76.js +1262 -0
  258. package/dist/chunk-X5A5FOWW.js +615 -0
  259. package/dist/chunk-X6CN6KQF.mjs +192 -0
  260. package/dist/chunk-XD2PMH46.mjs +517 -0
  261. package/dist/chunk-XJA2NGTI.mjs +88 -0
  262. package/dist/chunk-XJIHN3BY.mjs +8 -0
  263. package/dist/chunk-XK6UDWJS.js +203 -0
  264. package/dist/chunk-XPG3N5CF.mjs +415 -0
  265. package/dist/chunk-XVZ2NKSU.mjs +74 -0
  266. package/dist/chunk-XYP45OLE.js +117 -0
  267. package/dist/chunk-XZSDGZX6.mjs +301 -0
  268. package/dist/chunk-Y2EMGN4T.mjs +120 -0
  269. package/dist/chunk-Y3XWP5XW.mjs +298 -0
  270. package/dist/chunk-Y4K22JL6.js +228 -0
  271. package/dist/chunk-Y65LXQGA.mjs +3164 -0
  272. package/dist/chunk-Y66WVMO5.mjs +87 -0
  273. package/dist/chunk-Y7JWLB25.mjs +7280 -0
  274. package/dist/chunk-YCDXAJKU.js +175 -0
  275. package/dist/chunk-YRDQCCIS.js +152 -0
  276. package/dist/chunk-YV52DGSA.js +111 -0
  277. package/dist/chunk-YXGZQPUD.js +94 -0
  278. package/dist/chunk-Z3A3AFVU.mjs +102 -0
  279. package/dist/chunk-ZCY6YKKP.mjs +475 -0
  280. package/dist/chunk-ZEQHXVU5.js +215 -0
  281. package/dist/chunk-ZF7JCXCI.js +284 -0
  282. package/dist/chunk-ZJBRUH6V.js +29 -0
  283. package/dist/chunk-ZMIL4ZOA.js +365 -0
  284. package/dist/chunk-ZR5ULMN2.mjs +337 -0
  285. package/dist/chunk-ZXREOYOW.js +87 -0
  286. package/dist/{client-BSP9U1O1.d.mts → client-CX_WR0-J.d.mts} +2 -2
  287. package/dist/client-Dytx_ZTC.d.ts +230 -0
  288. package/dist/{client-B878xeAP.d.ts → client-dqOhP9Nc.d.ts} +2 -2
  289. package/dist/client-hTKbCuhG.d.mts +230 -0
  290. package/dist/clock-B-UAjkKa.d.mts +5 -0
  291. package/dist/clock-B-UAjkKa.d.ts +5 -0
  292. package/dist/config-BlXQluJR.d.mts +36 -0
  293. package/dist/config-BlXQluJR.d.ts +36 -0
  294. package/dist/courier-Cnn-edJ4.d.ts +95 -0
  295. package/dist/courier-FmGfkvIN.d.mts +95 -0
  296. package/dist/crowd-DdHFbqKK.d.ts +186 -0
  297. package/dist/crowd-hOVSAmA3.d.mts +186 -0
  298. package/dist/danfo-BEBapFlX.d.mts +146 -0
  299. package/dist/danfo-UQ_PTIIx.d.ts +146 -0
  300. package/dist/{elements-Bty6Qs_N.d.mts → elements-DdsRig-2.d.mts} +1548 -257
  301. package/dist/{elements-Bty6Qs_N.d.ts → elements-DdsRig-2.d.ts} +1548 -257
  302. package/dist/engines/godot.d.mts +56 -0
  303. package/dist/engines/godot.d.ts +56 -0
  304. package/dist/engines/godot.js +28 -0
  305. package/dist/engines/godot.mjs +3 -0
  306. package/dist/engines/wasm.d.mts +11 -0
  307. package/dist/engines/wasm.d.ts +11 -0
  308. package/dist/engines/wasm.js +178 -0
  309. package/dist/engines/wasm.mjs +176 -0
  310. package/dist/fallback-CrG_lTFk.d.mts +270 -0
  311. package/dist/fallback-CrG_lTFk.d.ts +270 -0
  312. package/dist/fallback-KDB4Y2CE.mjs +6 -0
  313. package/dist/fallback-Y26TQENE.js +19 -0
  314. package/dist/features-CZB4rmcD.d.mts +118 -0
  315. package/dist/features-CZB4rmcD.d.ts +118 -0
  316. package/dist/fit-BWiE7rgA.d.mts +44 -0
  317. package/dist/fit-DK0oT7zO.d.ts +44 -0
  318. package/dist/five-a-side-Bv1AOUy3.d.mts +115 -0
  319. package/dist/five-a-side-EC51SJY1.d.ts +115 -0
  320. package/dist/fluid-ARr0qUIL.d.ts +939 -0
  321. package/dist/fluid-DLlEj2cs.d.mts +939 -0
  322. package/dist/game/conformance.d.mts +84 -0
  323. package/dist/game/conformance.d.ts +84 -0
  324. package/dist/game/conformance.js +1025 -0
  325. package/dist/game/conformance.mjs +994 -0
  326. package/dist/game/heap.d.mts +40 -0
  327. package/dist/game/heap.d.ts +40 -0
  328. package/dist/game/heap.js +48 -0
  329. package/dist/game/heap.mjs +7 -0
  330. package/dist/game/kit/canvas.d.mts +240 -0
  331. package/dist/game/kit/canvas.d.ts +240 -0
  332. package/dist/game/kit/canvas.js +3566 -0
  333. package/dist/game/kit/canvas.mjs +1039 -0
  334. package/dist/game/kit/courier.d.mts +17 -0
  335. package/dist/game/kit/courier.d.ts +17 -0
  336. package/dist/game/kit/courier.js +66 -0
  337. package/dist/game/kit/courier.mjs +49 -0
  338. package/dist/game/kit/danfo.d.mts +11 -0
  339. package/dist/game/kit/danfo.d.ts +11 -0
  340. package/dist/game/kit/danfo.js +109 -0
  341. package/dist/game/kit/danfo.mjs +44 -0
  342. package/dist/game/kit/engine.d.mts +29 -0
  343. package/dist/game/kit/engine.d.ts +29 -0
  344. package/dist/game/kit/engine.js +183 -0
  345. package/dist/game/kit/engine.mjs +30 -0
  346. package/dist/game/kit/five-a-side.d.mts +11 -0
  347. package/dist/game/kit/five-a-side.d.ts +11 -0
  348. package/dist/game/kit/five-a-side.js +86 -0
  349. package/dist/game/kit/five-a-side.mjs +41 -0
  350. package/dist/game/kit/frontier.d.mts +344 -0
  351. package/dist/game/kit/frontier.d.ts +344 -0
  352. package/dist/game/kit/frontier.js +435 -0
  353. package/dist/game/kit/frontier.mjs +14 -0
  354. package/dist/game/kit/genesis.d.mts +752 -0
  355. package/dist/game/kit/genesis.d.ts +752 -0
  356. package/dist/game/kit/genesis.js +380 -0
  357. package/dist/game/kit/genesis.mjs +15 -0
  358. package/dist/game/kit/ludo.d.mts +15 -0
  359. package/dist/game/kit/ludo.d.ts +15 -0
  360. package/dist/game/kit/ludo.js +87 -0
  361. package/dist/game/kit/ludo.mjs +42 -0
  362. package/dist/game/kit/runner.d.mts +12 -0
  363. package/dist/game/kit/runner.d.ts +12 -0
  364. package/dist/game/kit/runner.js +83 -0
  365. package/dist/game/kit/runner.mjs +46 -0
  366. package/dist/game/kit/shootout.d.mts +13 -0
  367. package/dist/game/kit/shootout.d.ts +13 -0
  368. package/dist/game/kit/shootout.js +122 -0
  369. package/dist/game/kit/shootout.mjs +57 -0
  370. package/dist/game/kit/slots.d.mts +392 -0
  371. package/dist/game/kit/slots.d.ts +392 -0
  372. package/dist/game/kit/slots.js +215 -0
  373. package/dist/game/kit/slots.mjs +6 -0
  374. package/dist/game/kit/tycoon.d.mts +16 -0
  375. package/dist/game/kit/tycoon.d.ts +16 -0
  376. package/dist/game/kit/tycoon.js +145 -0
  377. package/dist/game/kit/tycoon.mjs +44 -0
  378. package/dist/game/kit/word.d.mts +11 -0
  379. package/dist/game/kit/word.d.ts +11 -0
  380. package/dist/game/kit/word.js +78 -0
  381. package/dist/game/kit/word.mjs +41 -0
  382. package/dist/game/kit/worlds.d.mts +18 -0
  383. package/dist/game/kit/worlds.d.ts +18 -0
  384. package/dist/game/kit/worlds.js +74 -0
  385. package/dist/game/kit/worlds.mjs +49 -0
  386. package/dist/game/kit.d.mts +53 -0
  387. package/dist/game/kit.d.ts +53 -0
  388. package/dist/game/kit.js +2610 -0
  389. package/dist/game/kit.mjs +101 -0
  390. package/dist/game/prepared.d.mts +14 -0
  391. package/dist/game/prepared.d.ts +14 -0
  392. package/dist/game/prepared.js +81 -0
  393. package/dist/game/prepared.mjs +32 -0
  394. package/dist/game-Bx8onkhX.d.mts +1451 -0
  395. package/dist/game-fgQy2YIm.d.ts +1451 -0
  396. package/dist/game-theme-CBTw1b_d.d.mts +35 -0
  397. package/dist/game-theme-Dg-ict5A.d.ts +35 -0
  398. package/dist/game.d.mts +3546 -0
  399. package/dist/game.d.ts +3546 -0
  400. package/dist/game.js +4455 -0
  401. package/dist/game.mjs +50 -0
  402. package/dist/graphics-C6YjWYvP.d.ts +5 -0
  403. package/dist/graphics-Dk2yQnYN.d.mts +5 -0
  404. package/dist/guest-DrsA00XD.d.mts +732 -0
  405. package/dist/guest-wIdfoT05.d.ts +732 -0
  406. package/dist/hit-stop-BKkVwTq7.d.mts +43 -0
  407. package/dist/hit-stop-D-8pPYnM.d.ts +43 -0
  408. package/dist/hot-Crn9XpHJ.d.ts +29 -0
  409. package/dist/hot-DH3nOhQD.d.mts +29 -0
  410. package/dist/{index-CQStGb3B.d.mts → index-6gkHMGAq.d.mts} +2 -2
  411. package/dist/index-B8ybCKJI.d.ts +41 -0
  412. package/dist/{index-DJwXmoaP.d.ts → index-B98Xac8e.d.ts} +2 -2
  413. package/dist/{index-B7oA_1XI.d.ts → index-B_ByTtIT.d.ts} +2 -2
  414. package/dist/index-DHjNHb1c.d.mts +41 -0
  415. package/dist/{index-DhUSTAhT.d.mts → index-DbAN_VQE.d.mts} +2 -2
  416. package/dist/index.d.mts +134 -24
  417. package/dist/index.d.ts +134 -24
  418. package/dist/index.js +407 -248
  419. package/dist/index.mjs +184 -58
  420. package/dist/interactives-authoring.d.mts +231 -0
  421. package/dist/interactives-authoring.d.ts +231 -0
  422. package/dist/interactives-authoring.js +1743 -0
  423. package/dist/interactives-authoring.mjs +1704 -0
  424. package/dist/interactives-canvas.global.js +148 -0
  425. package/dist/interactives-guest.d.mts +20 -0
  426. package/dist/interactives-guest.d.ts +20 -0
  427. package/dist/interactives-guest.js +63 -0
  428. package/dist/interactives-guest.json +1 -0
  429. package/dist/interactives-guest.mjs +61 -0
  430. package/dist/interactives-jsc.global.js +9357 -0
  431. package/dist/interactives-meters.d.mts +93 -0
  432. package/dist/interactives-meters.d.ts +93 -0
  433. package/dist/interactives-meters.js +252 -0
  434. package/dist/interactives-meters.mjs +68 -0
  435. package/dist/interactives-production.d.mts +430 -0
  436. package/dist/interactives-production.d.ts +430 -0
  437. package/dist/interactives-production.js +1231 -0
  438. package/dist/interactives-production.mjs +1170 -0
  439. package/dist/interactives-record.d.mts +112 -0
  440. package/dist/interactives-record.d.ts +112 -0
  441. package/dist/interactives-record.js +302 -0
  442. package/dist/interactives-record.mjs +295 -0
  443. package/dist/interactives-runtime.d.mts +61 -0
  444. package/dist/interactives-runtime.d.ts +61 -0
  445. package/dist/interactives-runtime.js +442 -0
  446. package/dist/interactives-runtime.mjs +25 -0
  447. package/dist/interactives-studio-kernel.global.js +1 -0
  448. package/dist/interactives-studio.d.mts +806 -0
  449. package/dist/interactives-studio.d.ts +806 -0
  450. package/dist/interactives-studio.js +5741 -0
  451. package/dist/interactives-studio.mjs +5651 -0
  452. package/dist/interactives-tick.d.mts +90 -0
  453. package/dist/interactives-tick.d.ts +90 -0
  454. package/dist/interactives-tick.js +203 -0
  455. package/dist/interactives-tick.mjs +6 -0
  456. package/dist/interactives-web.d.mts +762 -0
  457. package/dist/interactives-web.d.ts +762 -0
  458. package/dist/interactives-web.js +5000 -0
  459. package/dist/interactives-web.mjs +4628 -0
  460. package/dist/interactives.d.mts +2430 -0
  461. package/dist/interactives.d.ts +2430 -0
  462. package/dist/interactives.js +5723 -0
  463. package/dist/interactives.mjs +4333 -0
  464. package/dist/juice-CoHxlpKA.d.ts +42 -0
  465. package/dist/juice-DQztFS43.d.mts +42 -0
  466. package/dist/launch-T2f4_Di4.d.mts +151 -0
  467. package/dist/launch-d6oreMzR.d.ts +151 -0
  468. package/dist/library-DXYaMFhi.d.mts +69 -0
  469. package/dist/library-DXYaMFhi.d.ts +69 -0
  470. package/dist/link-BUTqGmyi.d.mts +38 -0
  471. package/dist/link-BUTqGmyi.d.ts +38 -0
  472. package/dist/lint.js +104 -204
  473. package/dist/lint.mjs +103 -203
  474. package/dist/local-D8_I6UeL.d.mts +6967 -0
  475. package/dist/local-VZkqsCzR.d.ts +6967 -0
  476. package/dist/lockstep-BLf6dglI.d.mts +321 -0
  477. package/dist/lockstep-D50Ia0JW.d.ts +321 -0
  478. package/dist/ludo-B8ClkDqr.d.ts +205 -0
  479. package/dist/ludo-BOuohQ-M.d.mts +205 -0
  480. package/dist/mock/cli.mjs +200 -56
  481. package/dist/mock/library.js +200 -56
  482. package/dist/mock/library.mjs +200 -56
  483. package/dist/mock/msw.js +200 -56
  484. package/dist/mock/msw.mjs +200 -56
  485. package/dist/native-BodxSh03.d.mts +16 -0
  486. package/dist/native-DUHMT8gA.d.ts +16 -0
  487. package/dist/network-ZXLD7l1b.d.mts +19 -0
  488. package/dist/network-ZXLD7l1b.d.ts +19 -0
  489. package/dist/online-XeymeM9s.d.ts +381 -0
  490. package/dist/online-d7W_Al9a.d.mts +381 -0
  491. package/dist/params-DxFb5G_U.d.mts +155 -0
  492. package/dist/params-DxFb5G_U.d.ts +155 -0
  493. package/dist/play-BRRlfLhX.d.ts +940 -0
  494. package/dist/play-ClrMd_e8.d.mts +940 -0
  495. package/dist/policy-CCw8tXLm.d.mts +3078 -0
  496. package/dist/policy-CMqOSQIu.d.ts +3078 -0
  497. package/dist/ports-B_0v_P3A.d.mts +13 -0
  498. package/dist/ports-CGU_3e_0.d.ts +13 -0
  499. package/dist/prefetch-BHnicOQj.d.ts +117 -0
  500. package/dist/prefetch-CBXgYacv.d.mts +117 -0
  501. package/dist/{price-CSztR02F.d.mts → price-BOzexBww.d.mts} +1 -1
  502. package/dist/{price-C_vasx9A.d.ts → price-C1h9sPxE.d.ts} +1 -1
  503. package/dist/protocol-C8qbpUbT.d.mts +242 -0
  504. package/dist/protocol-C8qbpUbT.d.ts +242 -0
  505. package/dist/rapier-AZHT4YI7.js +7886 -0
  506. package/dist/rapier-ODEPCQA6.mjs +7792 -0
  507. package/dist/react.d.mts +157 -15
  508. package/dist/react.d.ts +157 -15
  509. package/dist/react.js +5564 -5904
  510. package/dist/react.mjs +5451 -5808
  511. package/dist/runner-CQcLL7By.d.ts +189 -0
  512. package/dist/runner-D46Yj-wE.d.mts +189 -0
  513. package/dist/runtime-BRWfkf_q.d.mts +51 -0
  514. package/dist/runtime-DyuBMkKM.d.ts +51 -0
  515. package/dist/scheduling-D2ajXpMC.d.ts +224 -0
  516. package/dist/scheduling-DSRbbaZb.d.mts +224 -0
  517. package/dist/schema-BrWxzKp6.d.mts +63 -0
  518. package/dist/schema-BrWxzKp6.d.ts +63 -0
  519. package/dist/server/evict.js +34 -37
  520. package/dist/server/evict.mjs +34 -37
  521. package/dist/server/tanstack.d.mts +49 -3
  522. package/dist/server/tanstack.d.ts +49 -3
  523. package/dist/server/tanstack.js +169 -117
  524. package/dist/server/tanstack.mjs +166 -118
  525. package/dist/{server-Dckg4Vdr.d.ts → server-D29IIuDV.d.ts} +136 -130
  526. package/dist/{server-B6dW7-Lj.d.mts → server-DQMWPnc8.d.mts} +136 -130
  527. package/dist/server.d.mts +45 -5
  528. package/dist/server.d.ts +45 -5
  529. package/dist/server.js +171 -227
  530. package/dist/server.mjs +165 -225
  531. package/dist/session-grant-CJ27DwrT.d.mts +19 -0
  532. package/dist/session-grant-CJ27DwrT.d.ts +19 -0
  533. package/dist/shootout-BJZeX6FG.d.ts +140 -0
  534. package/dist/shootout-tcZd1Rxt.d.mts +140 -0
  535. package/dist/state-replica-stMtdkVD.d.mts +42 -0
  536. package/dist/state-replica-stMtdkVD.d.ts +42 -0
  537. package/dist/studio-CowqWqez.d.mts +14 -0
  538. package/dist/studio-CowqWqez.d.ts +14 -0
  539. package/dist/styles.css +1 -1
  540. package/dist/template-AhCdB1kW.d.mts +190 -0
  541. package/dist/template-BkEGVTQj.d.ts +190 -0
  542. package/dist/terrain-BMxEc6Oc.d.ts +429 -0
  543. package/dist/terrain-C-XC1Oui.d.mts +429 -0
  544. package/dist/testing/msw.d.mts +28 -4
  545. package/dist/testing/msw.d.ts +28 -4
  546. package/dist/testing/msw.js +15 -21
  547. package/dist/testing/msw.mjs +15 -21
  548. package/dist/testing/suite.d.mts +6 -5
  549. package/dist/testing/suite.d.ts +6 -5
  550. package/dist/testing/suite.js +89 -124
  551. package/dist/testing/suite.mjs +81 -116
  552. package/dist/testing.d.mts +27 -1227
  553. package/dist/testing.d.ts +27 -1227
  554. package/dist/testing.js +127 -131
  555. package/dist/testing.mjs +19 -23
  556. package/dist/tick-transport-C8QEh8Uw.d.mts +50 -0
  557. package/dist/tick-transport-UjHY3xK1.d.ts +50 -0
  558. package/dist/timeline-protocol-hp6e8zFB.d.mts +47 -0
  559. package/dist/timeline-protocol-hp6e8zFB.d.ts +47 -0
  560. package/dist/tokens-DhanQRQS.d.mts +21 -0
  561. package/dist/tokens-K8yxwd6G.d.ts +21 -0
  562. package/dist/tree-C-Io2Hbx.d.mts +35 -0
  563. package/dist/tree-CP_qSW4H.d.ts +35 -0
  564. package/dist/tycoon-B5KHk2Xx.d.mts +255 -0
  565. package/dist/tycoon-hmHo-3HX.d.ts +255 -0
  566. package/dist/types-BQkxPwZP.d.mts +219 -0
  567. package/dist/types-D_f6UUxM.d.ts +219 -0
  568. package/dist/ui-DwHicuFv.d.mts +563 -0
  569. package/dist/ui-hi7S2YcH.d.ts +563 -0
  570. package/dist/{sign-in-DQlIdqsi.d.mts → url-52ndUruG.d.mts} +15 -1
  571. package/dist/{sign-in-DQlIdqsi.d.ts → url-52ndUruG.d.ts} +15 -1
  572. package/dist/utils.d.mts +3 -3
  573. package/dist/utils.d.ts +3 -3
  574. package/dist/utils.js +37 -37
  575. package/dist/utils.mjs +4 -4
  576. package/dist/vars-Dc_PrhBK.d.mts +511 -0
  577. package/dist/vars-Dc_PrhBK.d.ts +511 -0
  578. package/dist/vm-IUARFFAI.mjs +63 -0
  579. package/dist/vm-N7L6MGGH.js +65 -0
  580. package/dist/weave-delivery-CW-Kstut.d.mts +360 -0
  581. package/dist/weave-delivery-CW-Kstut.d.ts +360 -0
  582. package/dist/web-Dss74a7v.d.ts +883 -0
  583. package/dist/web-f9ZQPoyw.d.mts +883 -0
  584. package/dist/web-transport-C7MkBL0a.d.ts +19 -0
  585. package/dist/web-transport-aYEqXMd9.d.mts +19 -0
  586. package/dist/weight-CPGjsgjV.d.ts +92 -0
  587. package/dist/weight-tF1ODR1p.d.mts +92 -0
  588. package/dist/word-BcX9Jcmv.d.mts +70 -0
  589. package/dist/word-C7sVPLHm.d.ts +70 -0
  590. package/dist/world-PvILHDR1.d.ts +2285 -0
  591. package/dist/world-qekkXjJv.d.mts +2285 -0
  592. package/dist/worlds-Br2Pb0Cs.d.ts +109 -0
  593. package/dist/worlds-D5ydYr7d.d.mts +109 -0
  594. package/engines/c/cimplify.h +108 -0
  595. package/engines/c/cimplify.lib.js +11 -0
  596. package/engines/godot/addons/cimplify/cimplify.gd +97 -0
  597. package/engines/rust/interactives-ctx/Cargo.toml +9 -0
  598. package/engines/rust/interactives-ctx/src/lib.rs +189 -0
  599. package/package.json +189 -3
  600. package/vendor/rapier3d-compat/LICENSE +201 -0
  601. package/vendor/rapier3d-compat/PATCHES.md +61 -0
  602. package/dist/chunk-2P4KXFB6.js +0 -274
  603. package/dist/chunk-3G6RQLXK.mjs +0 -21
  604. package/dist/chunk-3V4DVXV3.mjs +0 -254
  605. package/dist/chunk-EDK3LNM6.js +0 -2436
  606. package/dist/chunk-F7J3HK27.js +0 -4549
  607. package/dist/chunk-U4MW6PYU.mjs +0 -23
  608. package/dist/chunk-XREIZ56K.js +0 -26
@@ -0,0 +1,1862 @@
1
+ 'use strict';
2
+
3
+ var chunkVVE3Y76O_js = require('./chunk-VVE3Y76O.js');
4
+ var chunkRCQ2MPBV_js = require('./chunk-RCQ2MPBV.js');
5
+ var chunkX5A5FOWW_js = require('./chunk-X5A5FOWW.js');
6
+ var chunkKZJRSXHK_js = require('./chunk-KZJRSXHK.js');
7
+ var chunkIR74FJHU_js = require('./chunk-IR74FJHU.js');
8
+ var chunkT7LOXGYX_js = require('./chunk-T7LOXGYX.js');
9
+ var chunk4ZDR72SG_js = require('./chunk-4ZDR72SG.js');
10
+ var chunk2V7IL4HC_js = require('./chunk-2V7IL4HC.js');
11
+
12
+ // src/game/random.ts
13
+ var LITTLE_ENDIAN = new Uint8Array(Uint16Array.of(1).buffer)[0] === 1, HALF_INDEX = LITTLE_ENDIAN ? Int32Array.of(0, 1, 2, 3) : Int32Array.of(3, 2, 1, 0), CENTERED_MAX_EXTENT = 16384, CENTERED_FIXED_UNITS = 256;
14
+ function add32(a, b) {
15
+ let lo = (a & 65535) + (b & 65535);
16
+ return (a >>> 16) + (b >>> 16) + (lo >>> 16) << 16 | lo & 65535;
17
+ }
18
+ var SeededRandom = class {
19
+ constructor(seed) {
20
+ this.state = new Uint32Array(4);
21
+ this.output = new Uint32Array(2);
22
+ this.words = new Int32Array(this.state.buffer);
23
+ this.drawn = new Int32Array(this.output.buffer);
24
+ this.limbs = new Int32Array(7);
25
+ this.cell = new Float64Array(1);
26
+ this.halves = new Uint16Array(this.cell.buffer);
27
+ this.views = [this.state, this.output];
28
+ this.reseed(seed);
29
+ }
30
+ rollbackViews() {
31
+ return this.views;
32
+ }
33
+ get seed() {
34
+ return this.output[1];
35
+ }
36
+ reseed(seed) {
37
+ this.output[1] = seed;
38
+ let s = this.output[1];
39
+ for (let i = 0; i < 4; i++) {
40
+ s = s + 2654435769 >>> 0;
41
+ let z = s;
42
+ z = Math.imul(z ^ z >>> 16, 2246822507), z = Math.imul(z ^ z >>> 13, 3266489909), this.state[i] = (z ^ z >>> 16) >>> 0;
43
+ }
44
+ for (let i = 0; i < 12; i++) this.advance();
45
+ }
46
+ nextUint32() {
47
+ return this.advance(), this.output[0];
48
+ }
49
+ float() {
50
+ return this.advance(), this.output[0] / 4294967296;
51
+ }
52
+ range(min, max) {
53
+ return this.advance(), min + (max - min) * (this.output[0] / 4294967296);
54
+ }
55
+ rangeInto(out, slot, min, max) {
56
+ this.advance(), out[slot] = min + (max - min) * (this.output[0] / 4294967296);
57
+ }
58
+ int(min, maxInclusive) {
59
+ return this.advance(), min + (this.output[0] / 4294967296 * (maxInclusive - min + 1) | 0);
60
+ }
61
+ chance(probability) {
62
+ return this.advance(), this.output[0] / 4294967296 < probability;
63
+ }
64
+ centeredInto(out, slot, halfExtent, fixed, fixedAt) {
65
+ this.advance();
66
+ let s = this.drawn[0] ^ -2147483648, sign = s >>> 31, m = sign === 1 ? ~s : s, al = (m & 65535) + sign, ah = m >>> 16;
67
+ al > 65535 && (al = 0, ah++);
68
+ let lo = halfExtent * al, hi = halfExtent * ah;
69
+ hi += lo >>> 16, lo &= 65535;
70
+ let units = hi >>> 7;
71
+ if (fixed[fixedAt] = (units ^ -sign) + sign, hi === 0 && lo === 0) {
72
+ out[slot] = 0;
73
+ return;
74
+ }
75
+ let top = hi !== 0 ? 47 - Math.clz32(hi) : 31 - Math.clz32(lo), limbs = this.limbs;
76
+ limbs[0] = lo, limbs[1] = hi & 65535, limbs[2] = hi >>> 16, limbs[top >> 4] &= ~(1 << (top & 15)), limbs[3] = 0, limbs[4] = 0, limbs[5] = 0, limbs[6] = 0;
77
+ let shift = 52 - top;
78
+ for (let i = 0; i < 3; i++) {
79
+ let v = limbs[i];
80
+ if (v === 0) continue;
81
+ let at = i * 16 + shift, q = at >> 4, r = at & 15;
82
+ limbs[3 + q] |= (v & 65535 >>> r) << r, r > 0 && q + 1 < 4 && (limbs[3 + q + 1] |= v >>> 16 - r);
83
+ }
84
+ let halves = this.halves, high = sign << 15 | top + 992 << 4 | limbs[6] & 15;
85
+ halves[HALF_INDEX[0]] = limbs[3], halves[HALF_INDEX[1]] = limbs[4], halves[HALF_INDEX[2]] = limbs[5], halves[HALF_INDEX[3]] = high, out.set(this.cell, slot);
86
+ }
87
+ advance() {
88
+ let st = this.words, a = st[0], b = st[1], c = st[2], d = st[3], t = add32(add32(a, b), d);
89
+ st[3] = add32(d, 1), st[0] = b ^ b >>> 9, st[1] = add32(c, c << 3);
90
+ let rotated = c << 21 | c >>> 11;
91
+ st[2] = add32(rotated, t), this.drawn[0] = t;
92
+ }
93
+ saveState(out) {
94
+ out.set(this.state);
95
+ }
96
+ restoreState(source) {
97
+ this.state.set(source);
98
+ }
99
+ };
100
+
101
+ // src/game/kernel/loops.ts
102
+ var LOOP_MAX_REGION_ROWS = 65536, STORAGE = { f32: 0, i32: 1, u32: 2, u8: 3, f64: 4 }, STORAGE_F64_HI = 5, BYTES = { f32: 4, i32: 4, u32: 4, u8: 1, f64: 8 }, WORD = 4, ALIGN = 8, DESCRIPTOR_WORDS = 2, MIN_CAPACITY = 256, MAX_INDEX = 2147483647, TRIAL_RUNS = 4, TRIAL_MS = 2, TRIAL_LIMIT = 48, NS_PER_MS = 1e6, BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", PHASE_TRIAL = 0, PHASE_KERNEL = 1, PHASE_JS = 2, NO_PROGRAM = -1, FAILED = -2, FIELD = /^([ar])(\d+)$/, TABLE_FIELD = /^%tb(\d+)$/, TABLE_ARG = /^tb(\d+)$/, SCALAR_ARG = /^s(\d+)$/, ROW_ARG = "__base", settings = { schedule: "auto", chunkRows: (65536), enabled: true }, engine = null, generation = 0;
103
+ function clock() {
104
+ let perf = globalThis.performance;
105
+ return perf === void 0 ? Date.now() : perf.now();
106
+ }
107
+ function decode(text) {
108
+ let end = text.length;
109
+ for (; end > 0 && text[end - 1] === "="; ) end--;
110
+ let out = new Uint8Array(Math.floor(end * 3 / 4)), bits = 0, value = 0, at = 0;
111
+ for (let k = 0; k < end; k++) {
112
+ let digit = BASE64.indexOf(text[k]);
113
+ if (digit < 0) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "a lowered loop carries invalid base64");
114
+ value = (value << 6 | digit) & 16777215, bits += 6, bits >= 8 && (bits -= 8, out[at++] = value >> bits & 255);
115
+ }
116
+ return out.subarray(0, at);
117
+ }
118
+ function matches(kind, value) {
119
+ switch (kind) {
120
+ case "f32":
121
+ return value instanceof Float32Array;
122
+ case "f64":
123
+ return value instanceof Float64Array;
124
+ case "i32":
125
+ return value instanceof Int32Array;
126
+ case "u32":
127
+ return value instanceof Uint32Array;
128
+ case "u8":
129
+ return value instanceof Uint8Array;
130
+ }
131
+ }
132
+ function view(kind, buffer, at, rows) {
133
+ switch (kind) {
134
+ case "f32":
135
+ return new Float32Array(buffer, at, rows);
136
+ case "f64":
137
+ return new Float64Array(buffer, at, rows);
138
+ case "i32":
139
+ return new Int32Array(buffer, at, rows);
140
+ case "u32":
141
+ return new Uint32Array(buffer, at, rows);
142
+ case "u8":
143
+ return new Uint8Array(buffer, at, rows);
144
+ }
145
+ }
146
+ function setLoopEngine(next) {
147
+ next !== engine && (engine = next, generation++);
148
+ }
149
+ function loopEngineOf(kernels) {
150
+ if (kernels === null) return null;
151
+ let runRegion = kernels.runRegion;
152
+ if (typeof runRegion != "function") return null;
153
+ let exports = kernels.exports;
154
+ return {
155
+ memory: kernels.memory,
156
+ alloc: (bytes, align) => exports.engine_alloc(bytes, align),
157
+ free: (at, bytes, align) => {
158
+ exports.engine_free(at, bytes, align);
159
+ },
160
+ load: (at, bytes) => exports.engine_kernel_load(at, bytes),
161
+ unload: (program) => {
162
+ exports.engine_kernel_unload(program);
163
+ },
164
+ runRegion
165
+ };
166
+ }
167
+ function configureLoops(next) {
168
+ if (next.schedule !== void 0 && (settings.schedule = next.schedule), next.enabled !== void 0 && (settings.enabled = next.enabled), next.chunkRows !== void 0) {
169
+ if (!Number.isInteger(next.chunkRows) || next.chunkRows < 1 || next.chunkRows > (65536)) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `chunkRows must be 1..${(65536)}`);
170
+ settings.chunkRows = next.chunkRows;
171
+ }
172
+ }
173
+ function vmLoopEngine(arenaBytes = 1 << 24) {
174
+ let buffer = new ArrayBuffer(arenaBytes), programs = [], machines = [], capacity = [], top = 64;
175
+ return {
176
+ memory: { buffer },
177
+ alloc: (bytes, align) => {
178
+ if (top = Math.ceil(top / align) * align, top + bytes > arenaBytes) return 0;
179
+ let at = top;
180
+ return top += Math.max(bytes, 1), at;
181
+ },
182
+ free: () => {
183
+ },
184
+ load: (at, bytes) => {
185
+ try {
186
+ programs.push(chunkKZJRSXHK_js.parseProgram(new Uint8Array(buffer, at, bytes).slice()));
187
+ } catch {
188
+ return -4;
189
+ }
190
+ return machines.push(null), capacity.push(0), programs.length - 1;
191
+ },
192
+ runRegion: (program, columns, rows, count, args, argWords) => {
193
+ let parsed = programs[program];
194
+ if (parsed === void 0) return -3;
195
+ let descriptor = new Uint32Array(buffer, columns, parsed.slots.length * (2)), halves = [], views = parsed.slots.map((_, s) => {
196
+ let at = descriptor[s * (2)], storage = descriptor[s * (2) + 1];
197
+ if (storage === STORAGE.f64 || storage === (5)) {
198
+ let words = new Uint32Array(buffer, at, rows * 2), high = storage === (5) ? 1 : 0, column = new Uint32Array(rows);
199
+ for (let r = 0; r < rows; r++) column[r] = words[2 * r + high];
200
+ return halves.push({ words, column, high }), { values: column, storage: STORAGE.u32 };
201
+ }
202
+ let whole = ((parsed.slots[s].word ?? 0) & chunkIR74FJHU_js.ACCESS_ARRAY) !== 0, span = (bytes) => whole ? Math.floor((buffer.byteLength - at) / bytes) : rows;
203
+ return { values: storage === STORAGE.u8 ? new Uint8Array(buffer, at, span(1)) : storage === STORAGE.i32 ? new Int32Array(buffer, at, span((4))) : storage === STORAGE.u32 ? new Uint32Array(buffer, at, span((4))) : new Float32Array(buffer, at, span((4))), storage };
204
+ });
205
+ (machines[program] === null || capacity[program] < rows) && (machines[program] = new chunkKZJRSXHK_js.KernelVm(parsed, rows), capacity[program] = rows), machines[program].run(views, count, null, new Uint32Array(buffer, args, argWords));
206
+ for (let { words, column, high } of halves) for (let r = 0; r < count; r++) words[2 * r + high] = column[r];
207
+ return count;
208
+ }
209
+ };
210
+ }
211
+ var LoweredLoop = class {
212
+ constructor(payload) {
213
+ this.columns = [];
214
+ this.argHalves = new Float64Array(1);
215
+ this.argView = new Uint32Array(this.argHalves.buffer);
216
+ this.program = (-1);
217
+ this.owner = null;
218
+ this.ownerGeneration = -1;
219
+ this.arena = null;
220
+ this.capacity = 0;
221
+ this.descriptorAt = 0;
222
+ this.argsAt = 0;
223
+ this.descriptor = new Uint32Array(0);
224
+ this.argsView = new Uint32Array(0);
225
+ this.stamps = new Uint32Array(0);
226
+ this.stamp = 0;
227
+ this.phase = (0);
228
+ this.pending = false;
229
+ this.pendingAt = 0;
230
+ this.pendingRows = 0;
231
+ this.kernelMs = 0;
232
+ this.kernelRows = 0;
233
+ this.kernelRuns = 0;
234
+ this.jsMs = 0;
235
+ this.jsRows = 0;
236
+ this.jsRuns = 0;
237
+ this.payload = payload, this.a = new Array(payload.bindings).fill(null), this.s = new Float64Array(Math.max(payload.scalars, 1)), this.o = new Float64Array(Math.max(payload.offsets, 1)), this.g = new Array(payload.gathers).fill(null), this.r = new Float64Array(Math.max(payload.folds.length, 1));
238
+ let slots = payload.meta.slots;
239
+ this.slotColumn = new Int32Array(slots.length), this.slotStorage = new Uint32Array(slots.length), this.reductionColumn = new Int32Array(payload.folds.length).fill(-1);
240
+ let byName = /* @__PURE__ */ new Map(), tables = payload.tables ?? [];
241
+ this.slotTable = new Int32Array(slots.length).fill(-1), this.tableAt = new Int32Array(tables.length), this.tableBytes = new Float64Array(tables.length), slots.forEach((slot, k) => {
242
+ let table = TABLE_FIELD.exec(slot.field);
243
+ if (table !== null) {
244
+ let t = Number(table[1]);
245
+ if (t >= tables.length) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `a lowered loop binds unknown table ${slot.field}`);
246
+ this.slotTable[k] = t, this.slotColumn[k] = -1;
247
+ return;
248
+ }
249
+ let m = FIELD.exec(slot.field);
250
+ if (m === null) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `a lowered loop binds unknown column ${slot.field}`);
251
+ let index = Number(m[2]), reduction = m[1] === "r", kind = reduction ? "f64" : payload.fields[index]?.kind ?? "f32";
252
+ if (!reduction && payload.fields[index] === void 0) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `a lowered loop binds unknown column ${slot.field}`);
253
+ let column = byName.get(slot.field);
254
+ column === void 0 && (column = this.columns.length, byName.set(slot.field, column), this.columns.push({ field: reduction ? -1 - index : index, kind, bytes: BYTES[kind] }), reduction && (this.reductionColumn[index] = column)), this.slotColumn[k] = column, this.slotStorage[k] = kind === "f64" ? slot.component === 1 ? (5) : STORAGE.f64 : STORAGE[kind];
255
+ }), this.argWords = new Uint32Array(Math.max(payload.meta.argWords, 1)), this.argScalar = new Int32Array(payload.meta.args.length).fill(-1), this.argTable = new Int32Array(payload.meta.args.length).fill(-1), payload.meta.args.forEach((arg, k) => {
256
+ let m = SCALAR_ARG.exec(arg.name), t = TABLE_ARG.exec(arg.name);
257
+ if (m !== null && arg.kind === "f64") this.argScalar[k] = Number(m[1]);
258
+ else if (t !== null && arg.kind === "u32" && Number(t[1]) < tables.length) this.argTable[k] = Number(t[1]);
259
+ else if (arg.name !== ROW_ARG || arg.kind !== "i32") throw new chunk2V7IL4HC_js.GameError("invalid_argument", `a lowered loop takes an unknown argument ${arg.name}`);
260
+ });
261
+ let n = this.columns.length;
262
+ this.columnAt = new Int32Array(n), this.columnViews = new Array(n).fill(null), this.sources = new Array(n).fill(null), this.sourceArray = new Array(n).fill(null), this.sourceStart = new Float64Array(n), this.sourceRows = new Float64Array(n), this.targets = new Array(n).fill(null), this.targetRows = new Float64Array(n);
263
+ }
264
+ get stats() {
265
+ return {
266
+ kernelRuns: this.kernelRuns,
267
+ jsRuns: this.jsRuns,
268
+ decided: this.phase === (1) ? "kernel" : this.phase === (2) ? "js" : "trial",
269
+ kernelNsPerRow: this.kernelRows === 0 ? 0 : this.kernelMs * (1e6) / this.kernelRows,
270
+ jsNsPerRow: this.jsRows === 0 ? 0 : this.jsMs * (1e6) / this.jsRows
271
+ };
272
+ }
273
+ run(n) {
274
+ if (this.pending = false, !settings.enabled || settings.schedule === "js" || !Number.isInteger(n) || n < 0 || n > (2147483647)) return false;
275
+ let auto = settings.schedule === "auto";
276
+ if (auto && n < this.payload.minRows) return false;
277
+ let target = engine;
278
+ if (target === null || !this.attach(target) || !this.admissible(n)) return false;
279
+ if (auto && this.phase !== (1)) {
280
+ if (this.phase === (2)) return false;
281
+ if ((this.kernelRuns + this.jsRuns) % 2 === 1)
282
+ return this.pending = true, this.pendingRows = n, this.pendingAt = clock(), false;
283
+ }
284
+ let started = auto ? clock() : 0;
285
+ return this.execute(target, n), this.kernelRuns++, auto && this.phase === (0) && (this.kernelMs += clock() - started, this.kernelRows += n, this.decide()), true;
286
+ }
287
+ after() {
288
+ this.pending && (this.pending = false, this.jsMs += clock() - this.pendingAt, this.jsRows += this.pendingRows, this.jsRuns++, this.decide());
289
+ }
290
+ decide() {
291
+ let enough = (runs, ms) => runs >= (4) && ms >= (2);
292
+ if (!(enough(this.kernelRuns, this.kernelMs) && enough(this.jsRuns, this.jsMs) || this.kernelRuns + this.jsRuns >= (48))) return;
293
+ let kernel = this.kernelRows === 0 ? 1 / 0 : this.kernelMs / this.kernelRows, js = this.jsRows === 0 ? 1 / 0 : this.jsMs / this.jsRows;
294
+ this.phase = kernel <= js ? (1) : (2);
295
+ }
296
+ release() {
297
+ this.detach(), this.a.fill(null), this.g.fill(null);
298
+ }
299
+ detach() {
300
+ let owner = this.owner;
301
+ if (owner !== null && this.program >= 0) {
302
+ for (let c = 0; c < this.columns.length && this.capacity > 0; c++) owner.free(this.columnAt[c], this.capacity * this.columns[c].bytes, (8));
303
+ owner.free(this.descriptorAt, Math.max(this.payload.meta.slots.length * (2) * (4), (4)), (8)), owner.free(this.argsAt, Math.max(this.argWords.length * (4), (4)), (8));
304
+ for (let t = 0; t < this.tableBytes.length; t++) this.tableBytes[t] > 0 && owner.free(this.tableAt[t], this.tableBytes[t], (8));
305
+ owner.unload?.(this.program);
306
+ }
307
+ this.owner = null, this.ownerGeneration = -1, this.program = (-1), this.capacity = 0, this.arena = null, this.tableBytes.fill(0);
308
+ }
309
+ attach(target) {
310
+ if (this.owner === target && this.ownerGeneration === generation) return this.program >= 0;
311
+ this.owner !== null && this.program >= 0 && this.detach(), this.owner = target, this.ownerGeneration = generation, this.program = (-2), this.capacity = 0, this.arena = null;
312
+ let bytes = decode(this.payload.program), at = target.alloc(Math.max(bytes.byteLength, (4)), (4));
313
+ if (at === 0) return false;
314
+ new Uint8Array(target.memory.buffer, at, bytes.byteLength).set(bytes);
315
+ let id = -1;
316
+ try {
317
+ id = target.load(at, bytes.byteLength);
318
+ } catch {
319
+ id = -1;
320
+ }
321
+ if (target.free(at, Math.max(bytes.byteLength, (4)), (4)), id < 0) return false;
322
+ let descriptorBytes = Math.max(this.payload.meta.slots.length * (2) * (4), (4));
323
+ return this.descriptorAt = target.alloc(descriptorBytes, (8)), this.argsAt = target.alloc(Math.max(this.argWords.length * (4), (4)), (8)), this.descriptorAt === 0 || this.argsAt === 0 ? false : (this.program = id, true);
324
+ }
325
+ admissible(n) {
326
+ for (let t of this.payload.tables ?? []) if (!matches(t.kind, this.a[t.bind])) return false;
327
+ let fields = this.payload.fields;
328
+ for (let k = 0; k < fields.length; k++) {
329
+ let f = fields[k], array = this.a[f.bind];
330
+ if (!matches(f.kind, array)) return false;
331
+ if (f.gather >= 0) {
332
+ let rows = this.g[f.gather];
333
+ if (!(rows instanceof Int32Array || rows instanceof Uint32Array) || rows.length < n) return false;
334
+ let limit = array.length;
335
+ for (let i = 0; i < n; i++) {
336
+ let r = rows[i];
337
+ if (r < 0 || r >= limit) return false;
338
+ }
339
+ if (f.write && !this.distinct(rows, n, limit)) return false;
340
+ } else {
341
+ let off = f.offset >= 0 ? this.o[f.offset] : 0;
342
+ if (!Number.isInteger(off) || off < 0 || off + n > array.length) return false;
343
+ }
344
+ }
345
+ for (let j = 0; j < fields.length; j++)
346
+ if (fields[j].write) {
347
+ for (let k = 0; k < fields.length; k++)
348
+ if (k !== j && this.overlaps(j, k, n))
349
+ return false;
350
+ }
351
+ return true;
352
+ }
353
+ distinct(rows, n, limit) {
354
+ this.stamps.length < limit && (this.stamps = new Uint32Array(Math.max(limit, this.stamps.length * 2)), this.stamp = 0), this.stamp++, this.stamp === 4294967295 && (this.stamps.fill(0), this.stamp = 1);
355
+ let stamps = this.stamps, mark = this.stamp;
356
+ for (let i = 0; i < n; i++) {
357
+ let r = rows[i];
358
+ if (stamps[r] === mark) return false;
359
+ stamps[r] = mark;
360
+ }
361
+ return true;
362
+ }
363
+ overlaps(j, k, n) {
364
+ let fields = this.payload.fields, x = this.a[fields[j].bind], y = this.a[fields[k].bind];
365
+ return x.buffer !== y.buffer || fields[j].bind === fields[k].bind && fields[j].gather === fields[k].gather && fields[j].offset === fields[k].offset ? false : this.spanStart(j, x) < this.spanEnd(k, y, n) && this.spanStart(k, y) < this.spanEnd(j, x, n);
366
+ }
367
+ spanStart(k, array) {
368
+ let f = this.payload.fields[k];
369
+ return f.gather >= 0 ? array.byteOffset : array.byteOffset + (f.offset >= 0 ? this.o[f.offset] : 0) * array.BYTES_PER_ELEMENT;
370
+ }
371
+ spanEnd(k, array, n) {
372
+ let f = this.payload.fields[k];
373
+ return f.gather >= 0 ? array.byteOffset + array.byteLength : array.byteOffset + ((f.offset >= 0 ? this.o[f.offset] : 0) + n) * array.BYTES_PER_ELEMENT;
374
+ }
375
+ stageTables(target) {
376
+ let tables = this.payload.tables ?? [];
377
+ for (let t = 0; t < tables.length; t++) {
378
+ let array = this.a[tables[t].bind], bytes = Math.max(array.byteLength, (4));
379
+ if (this.tableBytes[t] < bytes) {
380
+ this.tableBytes[t] > 0 && target.free(this.tableAt[t], this.tableBytes[t], (8));
381
+ let at = target.alloc(bytes, (8));
382
+ if (at === 0)
383
+ return this.tableBytes[t] = 0, false;
384
+ this.tableAt[t] = at, this.tableBytes[t] = bytes;
385
+ }
386
+ new Uint8Array(target.memory.buffer, this.tableAt[t], array.byteLength).set(new Uint8Array(array.buffer, array.byteOffset, array.byteLength));
387
+ }
388
+ return true;
389
+ }
390
+ execute(target, n) {
391
+ let chunk = Math.min(settings.chunkRows, (65536));
392
+ if (!this.stageTables(target)) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "the engine has no room for a lowered loop's lookup tables");
393
+ this.reserve(target, Math.min(n, chunk));
394
+ let folds = this.payload.folds, r = this.r;
395
+ for (let base = 0; base < n; base += chunk) {
396
+ let m = Math.min(chunk, n - base);
397
+ this.prepare(target, base, m);
398
+ let code = target.runRegion(this.program, this.descriptorAt, m, m, this.argsAt, this.payload.meta.argWords);
399
+ if (code < 0)
400
+ throw base === 0 ? new chunk2V7IL4HC_js.GameError("invalid_argument", `the engine refused a lowered loop (${code})`) : new chunk2V7IL4HC_js.GameError("invalid_argument", `the engine refused a lowered loop part way (${code})`);
401
+ this.finish(base, m);
402
+ for (let k = 0; k < folds.length; k++) {
403
+ let values = this.columnViews[this.reductionColumn[k]], acc = r[k];
404
+ switch (folds[k]) {
405
+ case "+":
406
+ for (let i = 0; i < m; i++) acc = acc + values[i];
407
+ break;
408
+ case "-":
409
+ for (let i = 0; i < m; i++) acc = acc - values[i];
410
+ break;
411
+ case "*":
412
+ for (let i = 0; i < m; i++) acc = acc * values[i];
413
+ break;
414
+ case "/":
415
+ for (let i = 0; i < m; i++) acc = acc / values[i];
416
+ break;
417
+ case "min":
418
+ for (let i = 0; i < m; i++) acc = Math.min(acc, values[i]);
419
+ break;
420
+ case "max":
421
+ for (let i = 0; i < m; i++) acc = Math.max(acc, values[i]);
422
+ break;
423
+ }
424
+ r[k] = acc;
425
+ }
426
+ }
427
+ }
428
+ inPlace(column, buffer) {
429
+ if (column.field < 0) return null;
430
+ let f = this.payload.fields[column.field];
431
+ if (f.gather >= 0) return null;
432
+ let array = this.a[f.bind];
433
+ return array.buffer === buffer ? array : null;
434
+ }
435
+ reserve(target, rows) {
436
+ let buffer = target.memory.buffer;
437
+ if (rows > this.capacity) {
438
+ let next = Math.max((256), this.capacity);
439
+ for (; next < rows; ) next *= 2;
440
+ next = Math.min(next, (65536));
441
+ for (let c = 0; c < this.columns.length; c++) {
442
+ let bytes = this.columns[c].bytes;
443
+ this.capacity > 0 && target.free(this.columnAt[c], this.capacity * bytes, (8));
444
+ let at = target.alloc(next * bytes, (8));
445
+ if (at === 0) throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", "engine memory cannot hold a lowered loop's columns");
446
+ this.columnAt[c] = at;
447
+ }
448
+ this.capacity = next, this.arena = null;
449
+ }
450
+ if (target.memory.buffer !== this.arena) {
451
+ this.arena = target.memory.buffer;
452
+ for (let c = 0; c < this.columns.length; c++)
453
+ this.columnViews[c] = view(this.columns[c].kind, buffer, this.columnAt[c], this.capacity), this.targets[c] = null, this.sources[c] = null;
454
+ this.descriptor = new Uint32Array(buffer, this.descriptorAt, Math.max(this.payload.meta.slots.length * (2), 1)), this.argsView = new Uint32Array(buffer, this.argsAt, this.argWords.length);
455
+ }
456
+ }
457
+ source(c, array, start, rows) {
458
+ let cached = this.sources[c];
459
+ if (cached !== null && this.sourceArray[c] === array && this.sourceStart[c] === start && this.sourceRows[c] === rows) return cached;
460
+ let made = array.subarray(start, start + rows);
461
+ return this.sources[c] = made, this.sourceArray[c] = array, this.sourceStart[c] = start, this.sourceRows[c] = rows, made;
462
+ }
463
+ target(c, rows) {
464
+ let cached = this.targets[c];
465
+ if (cached !== null && this.targetRows[c] === rows) return cached;
466
+ let made = this.columnViews[c].subarray(0, rows);
467
+ return this.targets[c] = made, this.targetRows[c] = rows, made;
468
+ }
469
+ prepare(target, base, m) {
470
+ let buffer = target.memory.buffer, fields = this.payload.fields, address = this.columnAt;
471
+ for (let c = 0; c < this.columns.length; c++) {
472
+ let column = this.columns[c];
473
+ if (column.field < 0) continue;
474
+ let f = fields[column.field], array = this.a[f.bind];
475
+ if (this.inPlace(column, buffer) !== null) continue;
476
+ let values = this.columnViews[c];
477
+ if (f.gather >= 0) {
478
+ let rows = this.g[f.gather];
479
+ for (let i = 0; i < m; i++) values[i] = array[rows[base + i]];
480
+ } else {
481
+ let off = f.offset >= 0 ? this.o[f.offset] : 0;
482
+ values.set(this.source(c, array, off + base, m));
483
+ }
484
+ }
485
+ let descriptor = this.descriptor;
486
+ for (let s = 0; s < this.slotColumn.length; s++) {
487
+ let table = this.slotTable[s];
488
+ if (table >= 0) {
489
+ descriptor[s * (2)] = this.tableAt[table], descriptor[s * (2) + 1] = STORAGE[this.payload.tables[table].kind];
490
+ continue;
491
+ }
492
+ let c = this.slotColumn[s], column = this.columns[c], own = this.inPlace(column, buffer), at = address[c];
493
+ if (own !== null) {
494
+ let f = fields[column.field], off = f.offset >= 0 ? this.o[f.offset] : 0;
495
+ at = own.byteOffset + (off + base) * column.bytes;
496
+ }
497
+ descriptor[s * (2)] = at, descriptor[s * (2) + 1] = this.slotStorage[s];
498
+ }
499
+ let words = this.argWords, args = this.payload.meta.args, origin = this.payload.origin >= 0 ? this.o[this.payload.origin] : 0, w = 0;
500
+ for (let k = 0; k < args.length; k++) {
501
+ let scalar = this.argScalar[k], table = this.argTable[k];
502
+ if (table >= 0) words[w++] = this.a[this.payload.tables[table].bind].length >>> 0;
503
+ else if (scalar >= 0) {
504
+ this.argHalves[0] = this.s[scalar];
505
+ let nan = Number.isNaN(this.argHalves[0]);
506
+ words[w++] = nan ? 0 : this.argView[0], words[w++] = nan ? 2146959360 : this.argView[1];
507
+ } else
508
+ words[w++] = base + origin | 0;
509
+ }
510
+ this.argsView.set(words);
511
+ }
512
+ finish(base, m) {
513
+ let buffer = this.arena, fields = this.payload.fields;
514
+ for (let c = 0; c < this.columns.length; c++) {
515
+ let column = this.columns[c];
516
+ if (column.field < 0) continue;
517
+ let f = fields[column.field];
518
+ if (!f.write || this.inPlace(column, buffer) !== null) continue;
519
+ let array = this.a[f.bind], values = this.columnViews[c];
520
+ if (f.gather >= 0) {
521
+ let rows = this.g[f.gather];
522
+ for (let i = 0; i < m; i++) array[rows[base + i]] = values[i];
523
+ } else {
524
+ let off = f.offset >= 0 ? this.o[f.offset] : 0;
525
+ array.set(this.target(c, m), off + base);
526
+ }
527
+ }
528
+ }
529
+ }, LOOP_PROBE_GLOBAL = "__cimplify_loop_probe";
530
+ function loopProbe() {
531
+ let probe = globalThis[LOOP_PROBE_GLOBAL];
532
+ return probe === void 0 ? null : probe;
533
+ }
534
+ var loops = /* @__PURE__ */ new Map();
535
+ function lowerLoop(payload) {
536
+ let loop = loops.get(payload);
537
+ return loop === void 0 && (loop = new LoweredLoop(JSON.parse(payload)), loops.set(payload, loop)), loop;
538
+ }
539
+
540
+ // src/game/input/input.ts
541
+ var RECORDED_EVENT_BYTES = 32, RECORDED_TYPE_AT = 0, RECORDED_A_AT = 4, RECORDED_X_AT = 8, RECORDED_Y_AT = 12, RECORDED_Z_AT = 16, RECORDED_TIME_AT = 24;
542
+ function drainSource(events, count) {
543
+ if (count === 0 || events.length < (32)) return "touch";
544
+ let type = events[(0)];
545
+ return type === (10) ? "tilt" : type === (0) || type === (1) || type === (5) || type === (6) || type === (7) ? "key" : "touch";
546
+ }
547
+ var ACTION_BUTTON = 0, ACTION_AXIS = 1, BIND_KEY = 0, BIND_POINTER = 1, BIND_GAMEPAD_BUTTON = 2, BIND_VIRTUAL = 3, BIND_KEYS_AXIS = 4, BIND_GAMEPAD_AXIS = 5, BIND_VIRTUAL_AXIS = 6, EVENT_KEY_DOWN = 0, EVENT_KEY_UP = 1, EVENT_POINTER_DOWN = 2, EVENT_POINTER_MOVE = 3, EVENT_POINTER_UP = 4, EVENT_GAMEPAD_BUTTON = 5, EVENT_GAMEPAD_AXIS = 6, EVENT_VIRTUAL = 7, EVENT_WHEEL = 8, EVENT_MOTION = 9, EVENT_ORIENTATION = 10, EVENT_WHEEL_AT = 11, EVENT_LOOK = 12, EVENT_DEVICE = 13, InputDevice = { none: 0, keyboard: 1, pointer: 2, gamepad: 3 }, GAMEPAD_ACTIVITY = 0.5, STAGE_X = 0, STAGE_Y = 1, STAGE_Z = 2, STAGE_TIME = 3, STAGE_WORDS = 4, NO_POINTER = -1, BUTTON_THRESHOLD = 0.5, TAP_MAX_DISTANCE_FACTOR = 0.5, PRIMARY_BUTTONS = 1, MIN_PINCH_DISTANCE = 1e-6, DEFAULT_LONG_PRESS_MS = 500, LONG_PRESS_SLOP_FACTOR = 0.5, PINCH_POINTERS = 2, SwipeGesture = class {
548
+ constructor() {
549
+ this.ready = false;
550
+ this.startX = 0;
551
+ this.startY = 0;
552
+ this.endX = 0;
553
+ this.endY = 0;
554
+ this.deltaX = 0;
555
+ this.deltaY = 0;
556
+ this.distance = 0;
557
+ this.durationMs = 0;
558
+ this.velocityX = 0;
559
+ this.velocityY = 0;
560
+ this.curl = 0;
561
+ }
562
+ }, TapGesture = class {
563
+ constructor() {
564
+ this.ready = false;
565
+ this.x = 0;
566
+ this.y = 0;
567
+ }
568
+ }, PointerState = class {
569
+ constructor() {
570
+ this.active = false;
571
+ this.down = false;
572
+ this.x = 0;
573
+ this.y = 0;
574
+ this.buttons = 0;
575
+ this.count = 0;
576
+ }
577
+ }, PinchGesture = class {
578
+ constructor() {
579
+ this.active = false;
580
+ this.scale = 1;
581
+ this.totalScale = 1;
582
+ this.centerX = 0;
583
+ this.centerY = 0;
584
+ this.panX = 0;
585
+ this.panY = 0;
586
+ this.rotation = 0;
587
+ this.distance = 0;
588
+ }
589
+ }, WheelState = class {
590
+ constructor() {
591
+ this.deltaX = 0;
592
+ this.deltaY = 0;
593
+ this.deltaZ = 0;
594
+ this.x = 0;
595
+ this.y = 0;
596
+ }
597
+ }, PointerDelta = class {
598
+ constructor() {
599
+ this.x = 0;
600
+ this.y = 0;
601
+ }
602
+ }, FrameInput = class {
603
+ constructor() {
604
+ this.drag = new PointerDelta();
605
+ this.motion = new PointerDelta();
606
+ this.wheel = new WheelState();
607
+ this.pinch = new PinchGesture();
608
+ this.pressed = false;
609
+ this.released = false;
610
+ this.releasedButtons = 0;
611
+ this.pressX = 0;
612
+ this.pressY = 0;
613
+ }
614
+ dragging(pointer) {
615
+ return (pointer.down || this.released) && pointer.count <= 1;
616
+ }
617
+ dragButtons(pointer) {
618
+ return pointer.down ? pointer.buttons : this.releasedButtons;
619
+ }
620
+ begin() {
621
+ this.drag.x = 0, this.drag.y = 0, this.motion.x = 0, this.motion.y = 0, this.wheel.deltaX = 0, this.wheel.deltaY = 0, this.wheel.deltaZ = 0, this.pinch.active = false, this.pinch.scale = 1, this.pinch.panX = 0, this.pinch.panY = 0, this.pinch.rotation = 0, this.pressed = false, this.released = false, this.releasedButtons = 0;
622
+ }
623
+ }, LongPressGesture = class {
624
+ constructor() {
625
+ this.ready = false;
626
+ this.x = 0;
627
+ this.y = 0;
628
+ this.durationMs = 0;
629
+ }
630
+ }, OrientationState = class {
631
+ constructor() {
632
+ this.available = false;
633
+ this.alpha = 0;
634
+ this.beta = 0;
635
+ this.gamma = 0;
636
+ }
637
+ };
638
+ chunkRCQ2MPBV_js.settleDoubleFields(new SwipeGesture(), [
639
+ "startX",
640
+ "startY",
641
+ "endX",
642
+ "endY",
643
+ "deltaX",
644
+ "deltaY",
645
+ "distance",
646
+ "durationMs",
647
+ "velocityX",
648
+ "velocityY",
649
+ "curl"
650
+ ]);
651
+ chunkRCQ2MPBV_js.settleDoubleFields(new TapGesture(), ["x", "y"]);
652
+ chunkRCQ2MPBV_js.settleDoubleFields(new PointerState(), ["x", "y"]);
653
+ chunkRCQ2MPBV_js.settleDoubleFields(new PinchGesture(), ["scale", "totalScale", "centerX", "centerY", "panX", "panY", "rotation", "distance"]);
654
+ chunkRCQ2MPBV_js.settleDoubleFields(new WheelState(), ["deltaX", "deltaY", "deltaZ", "x", "y"]);
655
+ chunkRCQ2MPBV_js.settleDoubleFields(new PointerDelta(), ["x", "y"]);
656
+ chunkRCQ2MPBV_js.settleDoubleFields(new FrameInput(), ["pressX", "pressY"]);
657
+ chunkRCQ2MPBV_js.settleDoubleFields(new LongPressGesture(), ["x", "y", "durationMs"]);
658
+ chunkRCQ2MPBV_js.settleDoubleFields(new OrientationState(), ["alpha", "beta", "gamma"]);
659
+ var InputActions = class {
660
+ constructor(options = {}) {
661
+ this.swipe = new SwipeGesture();
662
+ this.tap = new TapGesture();
663
+ this.pointer = new PointerState();
664
+ this.pinch = new PinchGesture();
665
+ this.wheel = new WheelState();
666
+ this.drag = new PointerDelta();
667
+ this.motion = new PointerDelta();
668
+ this.look = new PointerDelta();
669
+ this.frame = new FrameInput();
670
+ this.longPress = new LongPressGesture();
671
+ this.orientation = new OrientationState();
672
+ this.pendingSwipe = new SwipeGesture();
673
+ this.pendingTap = new TapGesture();
674
+ this.pendingPinch = new PinchGesture();
675
+ this.pendingWheel = new WheelState();
676
+ this.pendingDrag = new PointerDelta();
677
+ this.pendingMotion = new PointerDelta();
678
+ this.pendingLongPress = new LongPressGesture();
679
+ this.pointerX = new Float32Array(10);
680
+ this.pointerY = new Float32Array(10);
681
+ this.pointerButtons = new Int32Array(10);
682
+ this.pointerOrder = new Float64Array(10);
683
+ this.pointerSerial = 0;
684
+ this.pinchA = (-1);
685
+ this.pinchB = (-1);
686
+ this.pinchDistance = 0;
687
+ this.pinchAngle = 0;
688
+ this.pinchCenterX = 0;
689
+ this.pinchCenterY = 0;
690
+ this.multiTouch = false;
691
+ this.longPressFired = false;
692
+ this.longPressMoved = false;
693
+ this.lastEventTime = 0;
694
+ this.lastDevice = InputDevice.none;
695
+ this.lastDeviceTime = 0;
696
+ this.frameNow = 0;
697
+ this.pointerFilter = null;
698
+ this.stage = new Float64Array((4));
699
+ this.pointerStage = new Float64Array((4));
700
+ this.actionNames = /* @__PURE__ */ new Map();
701
+ this.actionCount = 0;
702
+ this.actionKind = new Uint8Array(128);
703
+ this.actionValue = new Float32Array(128);
704
+ this.bindingOut = new Float64Array(1);
705
+ this.actionDown = new Uint8Array(128);
706
+ this.pressedLatch = new Uint8Array(128);
707
+ this.releasedLatch = new Uint8Array(128);
708
+ this.justPressedStep = new Uint8Array(128);
709
+ this.justReleasedStep = new Uint8Array(128);
710
+ this.bindingCount = 0;
711
+ this.bindAction = new Uint16Array(512);
712
+ this.bindKind = new Uint8Array(512);
713
+ this.bindA = new Int32Array(512);
714
+ this.bindB = new Int32Array(512);
715
+ this.bindParam = new Float32Array(512);
716
+ this.bindInvert = new Uint8Array(512);
717
+ this.keySlots = /* @__PURE__ */ new Map();
718
+ this.keyDown = new Uint8Array(256);
719
+ this.virtualSlots = /* @__PURE__ */ new Map();
720
+ this.virtualValue = new Float32Array(256);
721
+ this.virtualButtons = new Uint16Array(256);
722
+ this.gamepadButtons = new Float32Array(32);
723
+ this.gamepadAxes = new Float32Array(16);
724
+ this.pointerIds = new Int32Array(10).fill((-1));
725
+ this.primaryPointer = (-1);
726
+ this.pointerDownCount = 0;
727
+ this.gestureStartX = 0;
728
+ this.gestureStartY = 0;
729
+ this.gestureStartTime = 0;
730
+ this.sampleX = new Float32Array(64);
731
+ this.sampleY = new Float32Array(64);
732
+ this.sampleCount = 0;
733
+ this.eventType = new Uint8Array(512);
734
+ this.eventA = new Int32Array(512);
735
+ this.eventX = new Float32Array(512);
736
+ this.eventY = new Float32Array(512);
737
+ this.eventZ = new Float32Array(512);
738
+ this.eventTime = new Float64Array(512);
739
+ this.eventHead = 0;
740
+ this.eventCount = 0;
741
+ this.droppedEvents = 0;
742
+ this.unlockListener = null;
743
+ this.inputTap = null;
744
+ this.tapBytes = null;
745
+ this.tapView = null;
746
+ this.replayView = null;
747
+ this.swipeMinDistance = options.swipeMinDistance ?? 0.04, this.swipeMaxDurationMs = options.swipeMaxDurationMs ?? 800, this.longPressMs = options.longPressMs ?? (500);
748
+ }
749
+ pointerCount() {
750
+ return this.pointerDownCount;
751
+ }
752
+ pointerAt(index, out, offset = 0) {
753
+ let seen = 0;
754
+ for (let i = 0; i < 10; i++)
755
+ if (this.pointerIds[i] !== (-1)) {
756
+ if (seen === index)
757
+ return out[offset] = this.pointerX[i], out[offset + 1] = this.pointerY[i], true;
758
+ seen++;
759
+ }
760
+ return false;
761
+ }
762
+ get dropped() {
763
+ return this.droppedEvents;
764
+ }
765
+ onFirstGesture(listener) {
766
+ this.unlockListener = listener;
767
+ }
768
+ defineButton(name, bindings) {
769
+ let action = this.defineAction(name, (0));
770
+ for (let binding of bindings)
771
+ switch (binding.device) {
772
+ case "key":
773
+ this.bind(action, (0), this.keySlot(binding.code), 0, 0, false);
774
+ break;
775
+ case "pointer":
776
+ this.bind(action, (1), 0, 0, 0, false);
777
+ break;
778
+ case "gamepad":
779
+ this.bind(
780
+ action,
781
+ (2),
782
+ this.checkIndex(binding.button, 32),
783
+ 0,
784
+ binding.threshold ?? (0.5),
785
+ false
786
+ );
787
+ break;
788
+ case "virtual": {
789
+ let slot = this.virtualSlot(binding.control);
790
+ this.bind(action, (3), slot, 0, (0.5), false), this.virtualButtons[slot]++;
791
+ break;
792
+ }
793
+ }
794
+ return action;
795
+ }
796
+ defineAxis(name, bindings) {
797
+ let action = this.defineAction(name, (1));
798
+ for (let binding of bindings)
799
+ switch (binding.device) {
800
+ case "keys":
801
+ this.bind(
802
+ action,
803
+ (4),
804
+ this.keySlot(binding.negative),
805
+ this.keySlot(binding.positive),
806
+ 0,
807
+ false
808
+ );
809
+ break;
810
+ case "gamepad":
811
+ this.bind(
812
+ action,
813
+ (5),
814
+ this.checkIndex(binding.axis, 16),
815
+ 0,
816
+ binding.deadzone ?? 0.15,
817
+ binding.invert === true
818
+ );
819
+ break;
820
+ case "virtual":
821
+ this.bind(
822
+ action,
823
+ (6),
824
+ this.virtualSlot(binding.control),
825
+ 0,
826
+ 0,
827
+ binding.invert === true
828
+ );
829
+ break;
830
+ }
831
+ return action;
832
+ }
833
+ hasAction(name) {
834
+ return this.actionNames.has(name);
835
+ }
836
+ axisAction(name, negative, positive) {
837
+ let existing = this.actionNames.get(name);
838
+ if (existing !== void 0) return existing;
839
+ let bindings = [], n = Math.min(negative.length, positive.length);
840
+ for (let i = 0; i < n; i++) bindings.push({ device: "keys", negative: negative[i], positive: positive[i] });
841
+ return this.defineAxis(name, bindings);
842
+ }
843
+ action(name) {
844
+ let id = this.actionNames.get(name);
845
+ if (id === void 0) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `unknown action ${name}`);
846
+ return id;
847
+ }
848
+ pressed(action) {
849
+ return this.actionDown[action] === 1;
850
+ }
851
+ justPressed(action) {
852
+ return this.justPressedStep[action] === 1;
853
+ }
854
+ justReleased(action) {
855
+ return this.justReleasedStep[action] === 1;
856
+ }
857
+ value(action) {
858
+ return this.actionValue[action];
859
+ }
860
+ valueInto(action, out, index) {
861
+ out[index] = this.actionValue[action];
862
+ }
863
+ keyEvent(code, down, timeMs) {
864
+ let slot = this.keySlots.get(code);
865
+ slot !== void 0 && this.push(down ? (0) : (1), slot, 0, 0, timeMs);
866
+ }
867
+ pointerStaged(phase, id, buttons = (1)) {
868
+ let stage = this.stage, filter = this.pointerFilter;
869
+ if (filter !== null) {
870
+ let pointer = this.pointerStage;
871
+ if (pointer[(0)] = stage[(0)], pointer[(1)] = stage[(1)], pointer[(3)] = stage[(3)], filter.filterPointer(phase, id, pointer)) {
872
+ if (phase === "down") {
873
+ stage[(3)] = pointer[(3)], this.pushStaged((13), InputDevice.pointer);
874
+ return;
875
+ }
876
+ stage[(0)] = 0, stage[(1)] = 0;
877
+ return;
878
+ }
879
+ }
880
+ stage[(2)] = buttons, this.pushStaged(phase === "down" ? (2) : phase === "move" ? (3) : (4), id);
881
+ }
882
+ setPointerFilter(filter) {
883
+ this.pointerFilter = filter;
884
+ }
885
+ pointerEvent(phase, id, x, y, timeMs, buttons = (1)) {
886
+ let filter = this.pointerFilter;
887
+ if (filter !== null) {
888
+ let pointer = this.pointerStage;
889
+ if (pointer[(0)] = x, pointer[(1)] = y, pointer[(3)] = timeMs, filter.filterPointer(phase, id, pointer)) {
890
+ phase === "down" && this.push((13), InputDevice.pointer, 0, 0, timeMs);
891
+ return;
892
+ }
893
+ }
894
+ let type = phase === "down" ? (2) : phase === "move" ? (3) : (4);
895
+ this.push(type, id, x, y, timeMs, buttons);
896
+ }
897
+ wheelEvent(deltaX, deltaY, deltaZ, x, y, timeMs) {
898
+ this.push((11), 0, x, y, timeMs), this.push((8), 0, deltaX, deltaY, timeMs, deltaZ);
899
+ }
900
+ motionEvent(movementX, movementY, timeMs) {
901
+ this.push((9), 0, movementX, movementY, timeMs);
902
+ }
903
+ orientationEvent(alpha, beta, gamma, timeMs) {
904
+ this.push((10), 0, alpha, beta, timeMs, gamma);
905
+ }
906
+ gamepadButtonEvent(button, value, timeMs) {
907
+ button < 0 || button >= 32 || this.push((5), button, value, 0, timeMs);
908
+ }
909
+ gamepadAxisEvent(axis, value, timeMs) {
910
+ axis < 0 || axis >= 16 || this.push((6), axis, value, 0, timeMs);
911
+ }
912
+ virtualEvent(control, value, timeMs) {
913
+ let slot = this.virtualSlots.get(control);
914
+ slot !== void 0 && this.push((7), slot, value, 0, timeMs);
915
+ }
916
+ virtualControl(control) {
917
+ return this.virtualSlot(control);
918
+ }
919
+ virtualSlotEvent(slot, value, timeMs) {
920
+ let stage = this.stage;
921
+ stage[(0)] = value, stage[(3)] = timeMs, this.virtualStaged(slot);
922
+ }
923
+ virtualStaged(slot) {
924
+ slot < 0 || slot >= 256 || this.pushStaged((7), slot);
925
+ }
926
+ lookEvent(dx, dy, timeMs) {
927
+ let stage = this.stage;
928
+ stage[(0)] = dx, stage[(1)] = dy, stage[(3)] = timeMs, this.lookStaged();
929
+ }
930
+ lookStaged() {
931
+ this.pushStaged((12), 0);
932
+ }
933
+ deviceStaged(device) {
934
+ this.pushStaged((13), device);
935
+ }
936
+ deviceEvent(device, timeMs) {
937
+ this.stage[(3)] = timeMs, this.deviceStaged(device);
938
+ }
939
+ get device() {
940
+ return this.lastDevice;
941
+ }
942
+ get deviceTimeMs() {
943
+ return this.lastDeviceTime;
944
+ }
945
+ processEvents(nowMs = this.lastEventTime) {
946
+ this.frameNow = nowMs, this.drain();
947
+ }
948
+ processEventsFrom(clock2, slot) {
949
+ this.frameNow = clock2[slot], this.drain();
950
+ }
951
+ /** Starts or stops hearing every drain, for recording a play; preallocates the packing buffer once. */
952
+ setTap(tap) {
953
+ this.inputTap = tap, tap !== null && this.tapBytes === null && (this.tapBytes = new Uint8Array(512 * (32)), this.tapView = new DataView(this.tapBytes.buffer));
954
+ }
955
+ /** Applies a recorded drain exactly as it first happened: its events in order, then the drain at its frame time. */
956
+ replay(nowMs, events, count) {
957
+ if (events !== null) {
958
+ (this.replayView === null || this.replayView.buffer !== events.buffer) && (this.replayView = new DataView(events.buffer));
959
+ let view2 = this.replayView;
960
+ for (let i = 0; i < count; i++) {
961
+ let at = events.byteOffset + i * (32);
962
+ this.push(
963
+ view2.getUint32(at + (0), true),
964
+ view2.getInt32(at + (4), true),
965
+ view2.getFloat32(at + (8), true),
966
+ view2.getFloat32(at + (12), true),
967
+ view2.getFloat64(at + (24), true),
968
+ view2.getFloat32(at + (16), true)
969
+ );
970
+ }
971
+ }
972
+ this.frameNow = nowMs, this.drain();
973
+ }
974
+ record() {
975
+ let tap = this.inputTap, view2 = this.tapView, bytes = this.tapBytes;
976
+ if (tap === null || view2 === null || bytes === null) return;
977
+ let index = this.eventHead;
978
+ for (let i = 0; i < this.eventCount; i++) {
979
+ let at = i * (32);
980
+ view2.setUint32(at + (0), this.eventType[index], true), view2.setInt32(at + (4), this.eventA[index], true), view2.setFloat32(at + (8), this.eventX[index], true), view2.setFloat32(at + (12), this.eventY[index], true), view2.setFloat32(at + (16), this.eventZ[index], true), view2.setFloat64(at + (24), this.eventTime[index], true), index = (index + 1) % 512;
981
+ }
982
+ tap.drained(this.frameNow, bytes.subarray(0, this.eventCount * (32)), this.eventCount);
983
+ }
984
+ drain() {
985
+ this.inputTap !== null && this.record(), this.look.x = 0, this.look.y = 0, this.frame.begin();
986
+ let index = this.eventHead;
987
+ for (let i = 0; i < this.eventCount; i++)
988
+ this.apply(index), index = (index + 1) % 512;
989
+ this.eventHead = index, this.eventCount = 0, this.trackPinch(), this.detectLongPress(), this.evaluate();
990
+ }
991
+ beginStep() {
992
+ for (let a = 0; a < this.actionCount; a++)
993
+ this.justPressedStep[a] = this.pressedLatch[a], this.justReleasedStep[a] = this.releasedLatch[a], this.pressedLatch[a] = 0, this.releasedLatch[a] = 0;
994
+ copySwipe(this.swipe, this.pendingSwipe), this.pendingSwipe.ready = false, this.tap.ready = this.pendingTap.ready, this.tap.x = this.pendingTap.x, this.tap.y = this.pendingTap.y, this.pendingTap.ready = false, publishPinch(this.pinch, this.pendingPinch);
995
+ let w = this.pendingWheel;
996
+ this.wheel.deltaX = w.deltaX, this.wheel.deltaY = w.deltaY, this.wheel.deltaZ = w.deltaZ, this.wheel.x = w.x, this.wheel.y = w.y, w.deltaX = 0, w.deltaY = 0, w.deltaZ = 0, this.drag.x = this.pendingDrag.x, this.drag.y = this.pendingDrag.y, this.pendingDrag.x = 0, this.pendingDrag.y = 0, this.motion.x = this.pendingMotion.x, this.motion.y = this.pendingMotion.y, this.pendingMotion.x = 0, this.pendingMotion.y = 0;
997
+ let l = this.pendingLongPress;
998
+ this.longPress.ready = l.ready, this.longPress.x = l.x, this.longPress.y = l.y, this.longPress.durationMs = l.durationMs, l.ready = false;
999
+ }
1000
+ trackPinch() {
1001
+ let a = (-1), b = (-1);
1002
+ for (let i = 0; i < 10; i++)
1003
+ this.pointerIds[i] !== (-1) && (a === (-1) || this.pointerOrder[i] < this.pointerOrder[a] ? (b = a, a = i) : (b === (-1) || this.pointerOrder[i] < this.pointerOrder[b]) && (b = i));
1004
+ let p = this.pendingPinch;
1005
+ if (this.pointerDownCount < (2) || a === (-1) || b === (-1)) {
1006
+ p.active = false, this.pinchA = (-1), this.pinchB = (-1);
1007
+ return;
1008
+ }
1009
+ if (a > b) {
1010
+ let t = a;
1011
+ a = b, b = t;
1012
+ }
1013
+ let dx = this.pointerX[b] - this.pointerX[a], dy = this.pointerY[b] - this.pointerY[a], distance = Math.sqrt(dx * dx + dy * dy), angle = Math.atan2(dy, dx), cx = (this.pointerX[a] + this.pointerX[b]) * 0.5, cy = (this.pointerY[a] + this.pointerY[b]) * 0.5;
1014
+ if (a !== this.pinchA || b !== this.pinchB)
1015
+ this.pinchA = a, this.pinchB = b, p.active || (p.totalScale = 1);
1016
+ else if (this.pinchDistance > (1e-6) && distance > (1e-6)) {
1017
+ let ratio = distance / this.pinchDistance;
1018
+ p.scale *= ratio, p.totalScale *= ratio, p.panX += cx - this.pinchCenterX, p.panY += cy - this.pinchCenterY;
1019
+ let turn = angle - this.pinchAngle;
1020
+ turn > Math.PI ? turn -= Math.PI * 2 : turn < -Math.PI && (turn += Math.PI * 2), p.rotation += turn;
1021
+ let f = this.frame.pinch;
1022
+ f.scale *= ratio, f.panX += cx - this.pinchCenterX, f.panY += cy - this.pinchCenterY, f.rotation += turn;
1023
+ }
1024
+ p.active = true, this.frame.pinch.active = true, this.frame.pinch.totalScale = p.totalScale, this.frame.pinch.centerX = cx, this.frame.pinch.centerY = cy, this.frame.pinch.distance = distance, p.centerX = cx, p.centerY = cy, p.distance = distance, this.pinchDistance = distance, this.pinchAngle = angle, this.pinchCenterX = cx, this.pinchCenterY = cy;
1025
+ }
1026
+ detectLongPress() {
1027
+ if (this.primaryPointer === (-1) || this.longPressFired || this.longPressMoved || this.multiTouch) return;
1028
+ let held = (this.frameNow > this.lastEventTime ? this.frameNow : this.lastEventTime) - this.gestureStartTime;
1029
+ if (held < this.longPressMs) return;
1030
+ this.longPressFired = true;
1031
+ let l = this.pendingLongPress;
1032
+ l.ready = true, l.x = this.gestureStartX, l.y = this.gestureStartY, l.durationMs = held;
1033
+ }
1034
+ defineAction(name, kind) {
1035
+ if (this.actionNames.has(name)) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `action ${name} exists`);
1036
+ if (this.actionCount >= 128)
1037
+ throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `at most ${128} actions`);
1038
+ let id = this.actionCount++;
1039
+ return this.actionKind[id] = kind, this.actionNames.set(name, id), id;
1040
+ }
1041
+ bind(action, kind, a, b, param, invert) {
1042
+ if (this.bindingCount >= 512)
1043
+ throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `at most ${512} bindings`);
1044
+ let i = this.bindingCount++;
1045
+ this.bindAction[i] = action, this.bindKind[i] = kind, this.bindA[i] = a, this.bindB[i] = b, this.bindParam[i] = param, this.bindInvert[i] = invert ? 1 : 0;
1046
+ }
1047
+ keySlot(code) {
1048
+ return slotFor(this.keySlots, code);
1049
+ }
1050
+ virtualSlot(control) {
1051
+ return slotFor(this.virtualSlots, control);
1052
+ }
1053
+ checkIndex(index, limit) {
1054
+ if (index < 0 || index >= limit) throw new chunk2V7IL4HC_js.GameError("invalid_argument", `index ${index} out of range`);
1055
+ return index;
1056
+ }
1057
+ pushStaged(type, a) {
1058
+ if (this.eventCount >= 512) {
1059
+ this.droppedEvents++;
1060
+ return;
1061
+ }
1062
+ let index = (this.eventHead + this.eventCount) % 512, stage = this.stage;
1063
+ this.eventType[index] = type, this.eventA[index] = a, this.eventX[index] = stage[(0)], this.eventY[index] = stage[(1)], this.eventZ[index] = stage[(2)], this.eventTime[index] = stage[(3)], stage[(0)] = 0, stage[(1)] = 0, stage[(2)] = 0, this.eventCount++;
1064
+ }
1065
+ push(type, a, x, y, timeMs, z = 0) {
1066
+ if (this.eventCount >= 512) {
1067
+ this.droppedEvents++;
1068
+ return;
1069
+ }
1070
+ let index = (this.eventHead + this.eventCount) % 512;
1071
+ this.eventType[index] = type, this.eventA[index] = a, this.eventX[index] = x, this.eventY[index] = y, this.eventZ[index] = z, this.eventTime[index] = timeMs, this.eventCount++;
1072
+ }
1073
+ apply(index) {
1074
+ let a = this.eventA[index], x = this.eventX[index], y = this.eventY[index], z = this.eventZ[index], time = this.eventTime[index];
1075
+ time > this.lastEventTime && (this.lastEventTime = time);
1076
+ let device = InputDevice.none;
1077
+ switch (this.eventType[index]) {
1078
+ case (8):
1079
+ this.pendingWheel.deltaX += x, this.pendingWheel.deltaY += y, this.pendingWheel.deltaZ += z, this.frame.wheel.deltaX += x, this.frame.wheel.deltaY += y, this.frame.wheel.deltaZ += z, this.firstGesture();
1080
+ break;
1081
+ case (11):
1082
+ this.pendingWheel.x = x, this.pendingWheel.y = y, this.frame.wheel.x = x, this.frame.wheel.y = y;
1083
+ break;
1084
+ case (9):
1085
+ this.pendingMotion.x += x, this.pendingMotion.y += y, this.frame.motion.x += x, this.frame.motion.y += y;
1086
+ break;
1087
+ case (10):
1088
+ this.orientation.available = true, this.orientation.alpha = x, this.orientation.beta = y, this.orientation.gamma = z;
1089
+ break;
1090
+ case (12):
1091
+ this.look.x += x, this.look.y += y;
1092
+ break;
1093
+ case (13):
1094
+ device = a, this.firstGesture();
1095
+ break;
1096
+ case (0):
1097
+ this.keyDown[a] === 0 && this.latchSlot((0), a, true), this.keyDown[a] = 1, device = InputDevice.keyboard, this.firstGesture();
1098
+ break;
1099
+ case (1):
1100
+ this.keyDown[a] === 1 && this.latchSlot((0), a, false), this.keyDown[a] = 0;
1101
+ break;
1102
+ case (2):
1103
+ this.pointerDown(a, index), device = InputDevice.pointer, this.firstGesture();
1104
+ break;
1105
+ case (3):
1106
+ this.pointerMove(a, index);
1107
+ break;
1108
+ case (4):
1109
+ this.pointerUp(a, index);
1110
+ break;
1111
+ case (5):
1112
+ this.gamepadButtons[a] = x, x >= (0.5) && (device = InputDevice.gamepad), this.firstGesture();
1113
+ break;
1114
+ case (6):
1115
+ this.gamepadAxes[a] = x, (x >= (0.5) || x <= -(0.5)) && (device = InputDevice.gamepad);
1116
+ break;
1117
+ case (7):
1118
+ this.latchVirtual(a, index), this.virtualValue[a] = x, this.firstGesture();
1119
+ break;
1120
+ }
1121
+ device !== InputDevice.none && (this.lastDevice = device, this.lastDeviceTime = time);
1122
+ }
1123
+ latchVirtual(slot, index) {
1124
+ if (this.virtualButtons[slot] === 0) return;
1125
+ let before = this.virtualValue[slot], after = this.eventX[index];
1126
+ for (let i = 0; i < this.bindingCount; i++) {
1127
+ if (this.bindKind[i] !== (3) || this.bindA[i] !== slot) continue;
1128
+ let threshold = this.bindParam[i], action = this.bindAction[i];
1129
+ before < threshold && after >= threshold ? this.pressedLatch[action] = 1 : before >= threshold && after < threshold && (this.releasedLatch[action] = 1);
1130
+ }
1131
+ }
1132
+ firstGesture() {
1133
+ let listener = this.unlockListener;
1134
+ listener && (this.unlockListener = null, listener());
1135
+ }
1136
+ latchSlot(kind, slot, down) {
1137
+ for (let i = 0; i < this.bindingCount; i++) {
1138
+ if (this.bindKind[i] !== kind || this.bindA[i] !== slot) continue;
1139
+ let action = this.bindAction[i];
1140
+ down ? this.pressedLatch[action] = 1 : this.releasedLatch[action] = 1;
1141
+ }
1142
+ }
1143
+ pointerDown(id, index) {
1144
+ let x = this.eventX[index], y = this.eventY[index], buttons = this.eventZ[index], slot = this.pointerSlot(id);
1145
+ if (slot === (-1)) {
1146
+ if (slot = this.pointerSlot((-1)), slot === (-1)) return;
1147
+ this.pointerIds[slot] = id, this.pointerOrder[slot] = this.pointerSerial++, this.pointerDownCount++;
1148
+ }
1149
+ this.pointerX[slot] = x, this.pointerY[slot] = y, this.pointerButtons[slot] = buttons, this.pointer.count = this.pointerDownCount, this.pointerDownCount >= (2) && (this.multiTouch = true), this.primaryPointer === (-1) && (this.primaryPointer = id, this.gestureStartX = x, this.gestureStartY = y, this.gestureStartTime = this.eventTime[index], this.multiTouch = this.pointerDownCount >= (2), this.longPressFired = false, this.longPressMoved = false, this.sampleCount = 0, this.recordSample(index), this.pointer.active = true, this.pointer.down = true, this.pointer.x = x, this.pointer.y = y, this.pointer.buttons = buttons, this.frame.pressed = true, this.frame.pressX = x, this.frame.pressY = y, this.latchSlot((1), 0, true));
1150
+ }
1151
+ pointerMove(id, index) {
1152
+ let x = this.eventX[index], y = this.eventY[index], buttons = this.eventZ[index], slot = this.pointerSlot(id);
1153
+ if (slot !== (-1) && (this.pointerX[slot] = x, this.pointerY[slot] = y, this.pointerButtons[slot] = buttons), id !== this.primaryPointer) {
1154
+ this.primaryPointer === (-1) && (this.pointer.active = true, this.pointer.x = x, this.pointer.y = y);
1155
+ return;
1156
+ }
1157
+ this.pointerDownCount < (2) && this.addDrag(x - this.pointer.x, y - this.pointer.y), this.pointer.x = x, this.pointer.y = y, this.pointer.buttons = buttons;
1158
+ let sx = x - this.gestureStartX, sy = y - this.gestureStartY, slop = this.swipeMinDistance * (0.5);
1159
+ sx * sx + sy * sy > slop * slop && (this.longPressMoved = true), this.recordSample(index);
1160
+ }
1161
+ pointerUp(id, index) {
1162
+ let x = this.eventX[index], y = this.eventY[index], slot = this.pointerSlot(id);
1163
+ slot !== (-1) && (this.pointerIds[slot] = (-1), this.pointerButtons[slot] = 0, this.pointerDownCount--), this.pointer.count = this.pointerDownCount, id === this.primaryPointer && (this.primaryPointer = (-1), this.pointerDownCount < (2) - 1 && this.addDrag(x - this.pointer.x, y - this.pointer.y), this.frame.releasedButtons = this.pointer.buttons, this.pointer.down = false, this.pointer.buttons = 0, this.pointer.x = x, this.pointer.y = y, this.frame.released = true, this.recordSample(index), this.latchSlot((1), 0, false), !this.multiTouch && !this.longPressFired && this.recognize(index));
1164
+ }
1165
+ addDrag(dx, dy) {
1166
+ this.pendingDrag.x += dx, this.pendingDrag.y += dy, this.frame.drag.x += dx, this.frame.drag.y += dy;
1167
+ }
1168
+ pointerSlot(id) {
1169
+ for (let i = 0; i < 10; i++) if (this.pointerIds[i] === id) return i;
1170
+ return (-1);
1171
+ }
1172
+ recordSample(index) {
1173
+ let at = this.sampleCount >= 64 ? 63 : this.sampleCount++;
1174
+ this.sampleX[at] = this.eventX[index], this.sampleY[at] = this.eventY[index];
1175
+ }
1176
+ recognize(index) {
1177
+ let x = this.eventX[index], y = this.eventY[index], dx = x - this.gestureStartX, dy = y - this.gestureStartY, distance = (dx * dx + dy * dy) ** 0.5, scratch = this.bindingOut;
1178
+ scratch[0] = this.eventTime[index] - this.gestureStartTime, scratch[0] < 1 && (scratch[0] = 1);
1179
+ let duration = scratch[0];
1180
+ if (distance >= this.swipeMinDistance && duration <= this.swipeMaxDurationMs) {
1181
+ let s = this.pendingSwipe;
1182
+ s.ready = true, s.startX = this.gestureStartX, s.startY = this.gestureStartY, s.endX = x, s.endY = y, s.deltaX = dx, s.deltaY = dy, s.distance = distance, s.durationMs = duration, s.velocityX = dx / duration, s.velocityY = dy / duration, this.curlInto(s);
1183
+ return;
1184
+ }
1185
+ distance < this.swipeMinDistance * (0.5) && (this.pendingTap.ready = true, this.pendingTap.x = x, this.pendingTap.y = y);
1186
+ }
1187
+ curlInto(s) {
1188
+ let distance = s.distance, extreme = this.bindingOut;
1189
+ extreme[0] = 0;
1190
+ let nx = -s.deltaY / distance, ny = s.deltaX / distance;
1191
+ for (let i = 0; i < this.sampleCount; i++) {
1192
+ let d = (this.sampleX[i] - this.gestureStartX) * nx + (this.sampleY[i] - this.gestureStartY) * ny;
1193
+ Math.abs(d) > Math.abs(extreme[0]) && (extreme[0] = d);
1194
+ }
1195
+ s.curl = extreme[0] / distance;
1196
+ }
1197
+ evaluate() {
1198
+ let values = this.actionValue;
1199
+ for (let a = 0; a < this.actionCount; a++) values[a] = 0;
1200
+ let out = this.bindingOut;
1201
+ for (let i = 0; i < this.bindingCount; i++) {
1202
+ let action = this.bindAction[i];
1203
+ this.bindingValue(i, out);
1204
+ let v = out[0], current = values[action];
1205
+ Math.abs(v) > Math.abs(current) && (values[action] = v);
1206
+ }
1207
+ for (let a = 0; a < this.actionCount; a++) {
1208
+ if (this.actionKind[a] !== (0)) continue;
1209
+ let down = values[a] >= (0.5) ? 1 : 0;
1210
+ down === 1 && this.actionDown[a] === 0 && (this.pressedLatch[a] = 1), down === 0 && this.actionDown[a] === 1 && (this.releasedLatch[a] = 1), this.actionDown[a] = down;
1211
+ }
1212
+ }
1213
+ bindingValue(i, out) {
1214
+ let a = this.bindA[i], v = 0;
1215
+ switch (this.bindKind[i]) {
1216
+ case (0):
1217
+ v = this.keyDown[a];
1218
+ break;
1219
+ case (1):
1220
+ v = this.pointerDownCount > 0 ? 1 : 0;
1221
+ break;
1222
+ case (2):
1223
+ v = this.gamepadButtons[a] >= this.bindParam[i] ? 1 : 0;
1224
+ break;
1225
+ case (3):
1226
+ v = this.virtualValue[a] >= this.bindParam[i] ? 1 : 0;
1227
+ break;
1228
+ case (4):
1229
+ v = this.keyDown[this.bindB[i]] - this.keyDown[a];
1230
+ break;
1231
+ case (5): {
1232
+ let raw = this.gamepadAxes[a], dead = this.bindParam[i];
1233
+ v = (raw < 0 ? -raw : raw) < dead ? 0 : (raw - (raw > 0 ? 1 : raw < 0 ? -1 : raw) * dead) / (1 - dead);
1234
+ break;
1235
+ }
1236
+ case (6):
1237
+ v = this.virtualValue[a];
1238
+ break;
1239
+ }
1240
+ out[0] = this.bindInvert[i] === 1 ? -v : v;
1241
+ }
1242
+ };
1243
+ function slotFor(map, name) {
1244
+ let existing = map.get(name);
1245
+ if (existing !== void 0) return existing;
1246
+ if (map.size >= 256)
1247
+ throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `at most ${256} input slots`);
1248
+ let slot = map.size;
1249
+ return map.set(name, slot), slot;
1250
+ }
1251
+ function publishPinch(out, from) {
1252
+ out.active = from.active, out.scale = from.scale, out.totalScale = from.totalScale, out.centerX = from.centerX, out.centerY = from.centerY, out.panX = from.panX, out.panY = from.panY, out.rotation = from.rotation, out.distance = from.distance, from.scale = 1, from.panX = 0, from.panY = 0, from.rotation = 0;
1253
+ }
1254
+ function copySwipe(out, from) {
1255
+ out.ready = from.ready, out.startX = from.startX, out.startY = from.startY, out.endX = from.endX, out.endY = from.endY, out.deltaX = from.deltaX, out.deltaY = from.deltaY, out.distance = from.distance, out.durationMs = from.durationMs, out.velocityX = from.velocityX, out.velocityY = from.velocityY, out.curl = from.curl;
1256
+ }
1257
+
1258
+ // src/game/softbody/softbody.ts
1259
+ var SOFT_DEFAULTS = {
1260
+ stretch: 1e-6,
1261
+ bend: 1e-4,
1262
+ volume: 0,
1263
+ damping: 0.5,
1264
+ gravity: { x: 0, y: -9.81, z: 0 },
1265
+ substeps: 10,
1266
+ radius: 0.01,
1267
+ friction: 0.3,
1268
+ contraction: 0.3,
1269
+ density: 1e3,
1270
+ ropeMass: 0.02
1271
+ }, MAX_SUBSTEPS = 32;
1272
+ function writeSoftOptions(f, r, options) {
1273
+ let substeps = options.substeps ?? SOFT_DEFAULTS.substeps;
1274
+ if (!Number.isInteger(substeps) || substeps < 1 || substeps > (32))
1275
+ throw new chunk2V7IL4HC_js.GameError("invalid_argument", `soft body substeps must be a whole number from 1 to ${(32)}`);
1276
+ let gravity = options.gravity ?? SOFT_DEFAULTS.gravity;
1277
+ f[chunkX5A5FOWW_js.SOFT_STRETCH] = options.stretch ?? SOFT_DEFAULTS.stretch, f[chunkX5A5FOWW_js.SOFT_BEND] = options.bend ?? SOFT_DEFAULTS.bend, f[chunkX5A5FOWW_js.SOFT_VOLUME] = options.volume ?? SOFT_DEFAULTS.volume, f[chunkX5A5FOWW_js.SOFT_DAMPING] = options.damping ?? SOFT_DEFAULTS.damping, f[chunkX5A5FOWW_js.SOFT_GRAVITY] = gravity.x, f[chunkX5A5FOWW_js.SOFT_GRAVITY + 1] = gravity.y, f[chunkX5A5FOWW_js.SOFT_GRAVITY + 2] = gravity.z, r[chunkX5A5FOWW_js.SOFT_SUBSTEPS] = substeps, f[chunkX5A5FOWW_js.SOFT_RADIUS] = options.radius ?? SOFT_DEFAULTS.radius, f[chunkX5A5FOWW_js.SOFT_FRICTION] = options.friction ?? SOFT_DEFAULTS.friction, f[chunkX5A5FOWW_js.SOFT_CONTRACTION] = options.contraction ?? SOFT_DEFAULTS.contraction, f[chunkX5A5FOWW_js.SOFT_YIELD] = options.plastic?.yieldStrain ?? 0, f[chunkX5A5FOWW_js.SOFT_CREEP] = options.plastic ? options.plastic.creep ?? 1 : 0, f[chunkX5A5FOWW_js.SOFT_LIMIT] = options.plastic ? options.plastic.limit ?? 0.5 : 0, f[chunkX5A5FOWW_js.SOFT_FIBRE] = options.fibre?.x ?? 0, f[chunkX5A5FOWW_js.SOFT_FIBRE + 1] = options.fibre?.y ?? 0, f[chunkX5A5FOWW_js.SOFT_FIBRE + 2] = options.fibre?.z ?? 0;
1278
+ }
1279
+ function packSoftCollider(out, at, collider) {
1280
+ out.fill(0, at, at + chunkX5A5FOWW_js.SOFT_COLLIDER_FLOATS);
1281
+ let put = (k, v) => {
1282
+ out[at + k] = v.x, out[at + k + 1] = v.y, out[at + k + 2] = v.z;
1283
+ };
1284
+ if ("plane" in collider)
1285
+ out[at] = chunkX5A5FOWW_js.SOFT_COLLIDER_PLANE, put(1, collider.plane.normal), out[at + 7] = collider.plane.offset;
1286
+ else if ("sphere" in collider)
1287
+ out[at] = chunkX5A5FOWW_js.SOFT_COLLIDER_SPHERE, put(1, collider.sphere.center), out[at + 7] = collider.sphere.radius;
1288
+ else if ("capsule" in collider)
1289
+ out[at] = chunkX5A5FOWW_js.SOFT_COLLIDER_CAPSULE, put(1, collider.capsule.a), put(4, collider.capsule.b), out[at + 7] = collider.capsule.radius;
1290
+ else {
1291
+ out[at] = chunkX5A5FOWW_js.SOFT_COLLIDER_BOX, put(1, collider.box.center), put(4, collider.box.half);
1292
+ let q = collider.box.rotation ?? { x: 0, y: 0, z: 0, w: 1 };
1293
+ out[at + 8] = q.x, out[at + 9] = q.y, out[at + 10] = q.z, out[at + 11] = q.w;
1294
+ }
1295
+ }
1296
+ function packCrumple(options, low, high) {
1297
+ let d = new Float32Array(chunkX5A5FOWW_js.CRUMPLE_DESC_FLOATS), span = Math.max(high.x - low.x, high.y - low.y, high.z - low.z), cells = options.cells ?? [4, 2, 6];
1298
+ return d.set(cells, 0), d.set([low.x, low.y, low.z, high.x, high.y, high.z], 3), d[9] = options.threshold ?? 3, d[10] = options.crush ?? 0.02, d[11] = options.maxDepth ?? 0.35, d[12] = options.radius ?? span * 0.25, d[13] = options.stiffness ?? 1e-5, d;
1299
+ }
1300
+ var SoftBody = class {
1301
+ constructor(port, info, geometry) {
1302
+ this.port = port;
1303
+ this.info = info;
1304
+ this.disposed = false;
1305
+ this.particles = info.particles, this.skinned = info.skinned, this.tets = info.tets, this.geometry = geometry;
1306
+ }
1307
+ get id() {
1308
+ return this.info.id;
1309
+ }
1310
+ positions() {
1311
+ return this.port.positions(this.info.id, this.particles);
1312
+ }
1313
+ attach(geometry) {
1314
+ if (geometry !== null && this.skinned === 0) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "this soft body has no embedded surface to draw");
1315
+ this.geometry = geometry;
1316
+ }
1317
+ setOptions(options) {
1318
+ writeSoftOptions(this.port.prepare(), this.port.registers, options), this.port.params(this.info.id);
1319
+ }
1320
+ setActivation(activation) {
1321
+ if (!(activation >= 0 && activation <= 1)) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "muscle activation runs from 0 to 1");
1322
+ this.port.activate(this.info.id, activation);
1323
+ }
1324
+ setAnchors(anchors) {
1325
+ this.port.anchors(this.info.id, anchors);
1326
+ }
1327
+ push(offset, velocity) {
1328
+ this.port.move(this.info.id, [offset.x, offset.y, offset.z], [velocity.x, velocity.y, velocity.z]);
1329
+ }
1330
+ present() {
1331
+ return this.disposed || this.geometry === null ? 0 : this.port.present(this.info.id, this.geometry);
1332
+ }
1333
+ dispose() {
1334
+ this.disposed || (this.disposed = true, this.port.remove(this.info.id));
1335
+ }
1336
+ }, SoftBodies = class {
1337
+ constructor(port) {
1338
+ this.port = port;
1339
+ this.bodies = [];
1340
+ this.block = new Float32Array(chunkX5A5FOWW_js.SOFT_COLLIDER_FLOATS * chunkX5A5FOWW_js.SOFT_MAX_COLLIDERS);
1341
+ }
1342
+ create(shape, options = {}) {
1343
+ writeSoftOptions(this.port.prepare(), this.port.registers, options);
1344
+ let info;
1345
+ if ("lattice" in shape) {
1346
+ let l = shape.lattice;
1347
+ info = this.port.lattice(
1348
+ { cells: l.cells, size: [l.size.x, l.size.y, l.size.z], origin: [l.origin.x, l.origin.y, l.origin.z], density: l.density ?? SOFT_DEFAULTS.density },
1349
+ shape.surface ?? null
1350
+ );
1351
+ } else "rope" in shape ? info = this.port.rope(shape.rope.points, shape.rope.mass ?? SOFT_DEFAULTS.ropeMass, shape.rope.pinFirst ?? false) : info = this.port.asset(shape.asset);
1352
+ let body = new SoftBody(this.port, info, options.geometry ?? null);
1353
+ return this.bodies.push(body), body;
1354
+ }
1355
+ remove(body) {
1356
+ let index = this.bodies.indexOf(body);
1357
+ index >= 0 && this.bodies.splice(index, 1), body.dispose();
1358
+ }
1359
+ setColliders(colliders) {
1360
+ if (colliders.length > chunkX5A5FOWW_js.SOFT_MAX_COLLIDERS) throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `soft bodies collide with at most ${chunkX5A5FOWW_js.SOFT_MAX_COLLIDERS} shapes`);
1361
+ for (let i = 0; i < colliders.length; i++) packSoftCollider(this.block, i * chunkX5A5FOWW_js.SOFT_COLLIDER_FLOATS, colliders[i]);
1362
+ this.port.colliders(this.block, colliders.length);
1363
+ }
1364
+ couple(collider) {
1365
+ if (this.port.couple === void 0) throw new chunk2V7IL4HC_js.GameError("unsupported_feature", "soft bodies couple to rigid bodies only on the native engine (feature rigid_coupling_1)");
1366
+ return this.port.couple(collider);
1367
+ }
1368
+ uncouple(slot) {
1369
+ this.port.uncouple?.(slot);
1370
+ }
1371
+ get count() {
1372
+ return this.bodies.length;
1373
+ }
1374
+ step(seconds) {
1375
+ this.bodies.length > 0 && this.port.step(seconds);
1376
+ }
1377
+ present() {
1378
+ for (let i = 0; i < this.bodies.length; i++) this.bodies[i].present();
1379
+ }
1380
+ digest() {
1381
+ return this.port.digest();
1382
+ }
1383
+ dispose() {
1384
+ for (let body of this.bodies) body.dispose();
1385
+ this.bodies.length = 0, this.port.dispose();
1386
+ }
1387
+ };
1388
+ function crumpleDesc(vertices, options) {
1389
+ if (options === void 0) return null;
1390
+ let low = { x: 1 / 0, y: 1 / 0, z: 1 / 0 }, high = { x: -1 / 0, y: -1 / 0, z: -1 / 0 };
1391
+ for (let i = 0; i < vertices.length; i += 3)
1392
+ low.x = Math.min(low.x, vertices[i]), low.y = Math.min(low.y, vertices[i + 1]), low.z = Math.min(low.z, vertices[i + 2]), high.x = Math.max(high.x, vertices[i]), high.y = Math.max(high.y, vertices[i + 1]), high.z = Math.max(high.z, vertices[i + 2]);
1393
+ return packCrumple(options, low, high);
1394
+ }
1395
+
1396
+ // src/game/cloth/cloth.ts
1397
+ var CLOTH_DEFAULTS = {
1398
+ mass: 0.01,
1399
+ stretch: 1e-7,
1400
+ bend: 1e-4,
1401
+ tetherSlack: 0.05,
1402
+ damping: 0.5,
1403
+ gravity: { x: 0, y: -9.81, z: 0 },
1404
+ substeps: 8,
1405
+ thickness: 5e-3,
1406
+ friction: 0.2
1407
+ }, MAX_SUBSTEPS2 = 64, MIN_SIDE = 2, PINNING = { none: chunkX5A5FOWW_js.CLOTH_PIN_NONE, top: chunkX5A5FOWW_js.CLOTH_PIN_TOP_ROW, corners: chunkX5A5FOWW_js.CLOTH_PIN_TOP_CORNERS };
1408
+ function refuse(what) {
1409
+ throw new chunk2V7IL4HC_js.GameError("invalid_argument", `cloth ${what}`);
1410
+ }
1411
+ function nonNegative(value, what) {
1412
+ return Number.isFinite(value) && value >= 0 || refuse(`${what} must be finite and not negative`), value;
1413
+ }
1414
+ function finite(value, what) {
1415
+ return Number.isFinite(value) || refuse(`${what} must be finite`), value;
1416
+ }
1417
+ function writeClothOptions(f, r, options) {
1418
+ let substeps = options.substeps ?? CLOTH_DEFAULTS.substeps;
1419
+ (!Number.isInteger(substeps) || substeps < 1 || substeps > (64)) && refuse(`substeps must be a whole number from 1 to ${(64)}`);
1420
+ let mass = options.mass ?? CLOTH_DEFAULTS.mass;
1421
+ Number.isFinite(mass) && mass > 0 || refuse("mass must be positive");
1422
+ let friction = options.friction ?? CLOTH_DEFAULTS.friction;
1423
+ friction >= 0 && friction <= 1 || refuse("friction runs from 0 to 1");
1424
+ let gravity = options.gravity ?? CLOTH_DEFAULTS.gravity;
1425
+ f[chunkX5A5FOWW_js.CLOTH_MASS] = mass, f[chunkX5A5FOWW_js.CLOTH_STRETCH] = nonNegative(options.stretch ?? CLOTH_DEFAULTS.stretch, "stretch"), f[chunkX5A5FOWW_js.CLOTH_BEND] = nonNegative(options.bend ?? CLOTH_DEFAULTS.bend, "bend"), f[chunkX5A5FOWW_js.CLOTH_TETHER_SLACK] = nonNegative(options.tetherSlack ?? CLOTH_DEFAULTS.tetherSlack, "tetherSlack"), f[chunkX5A5FOWW_js.CLOTH_DAMPING] = nonNegative(options.damping ?? CLOTH_DEFAULTS.damping, "damping"), f[chunkX5A5FOWW_js.CLOTH_GRAVITY] = finite(gravity.x, "gravity"), f[chunkX5A5FOWW_js.CLOTH_GRAVITY + 1] = finite(gravity.y, "gravity"), f[chunkX5A5FOWW_js.CLOTH_GRAVITY + 2] = finite(gravity.z, "gravity"), r[chunkX5A5FOWW_js.CLOTH_SUBSTEPS] = substeps, f[chunkX5A5FOWW_js.CLOTH_THICKNESS] = nonNegative(options.thickness ?? CLOTH_DEFAULTS.thickness, "thickness"), f[chunkX5A5FOWW_js.CLOTH_FRICTION] = friction;
1426
+ }
1427
+ function writeClothGrid(f, r, grid) {
1428
+ let side = (n, what) => ((!Number.isInteger(n) || n < (2)) && refuse(`${what} must be a whole number of at least ${(2)}`), n);
1429
+ r[chunkX5A5FOWW_js.CLOTH_COLUMNS] = side(grid.columns, "columns"), r[chunkX5A5FOWW_js.CLOTH_ROWS] = side(grid.rows, "rows"), Number.isFinite(grid.spacing) && grid.spacing > 0 || refuse("spacing must be positive"), f[chunkX5A5FOWW_js.CLOTH_SPACING] = grid.spacing;
1430
+ let put = (at, v) => {
1431
+ f[at] = v === void 0 ? 0 : finite(v.x, "axes"), f[at + 1] = v === void 0 ? 0 : finite(v.y, "axes"), f[at + 2] = v === void 0 ? 0 : finite(v.z, "axes");
1432
+ };
1433
+ put(chunkX5A5FOWW_js.CLOTH_ORIGIN, grid.origin), put(chunkX5A5FOWW_js.CLOTH_ACROSS, grid.across), put(chunkX5A5FOWW_js.CLOTH_DOWN, grid.down), r[chunkX5A5FOWW_js.CLOTH_PIN] = PINNING[grid.pin ?? "top"];
1434
+ }
1435
+ function packClothCollider(out, at, collider) {
1436
+ out.fill(0, at, at + chunkX5A5FOWW_js.CLOTH_COLLIDER_FLOATS);
1437
+ let put = (k, v) => {
1438
+ out[at + k] = v.x, out[at + k + 1] = v.y, out[at + k + 2] = v.z;
1439
+ };
1440
+ "sphere" in collider ? (out[at] = chunkX5A5FOWW_js.CLOTH_COLLIDER_SPHERE, put(1, collider.sphere.center), out[at + 7] = collider.sphere.radius) : (out[at] = chunkX5A5FOWW_js.CLOTH_COLLIDER_CAPSULE, put(1, collider.capsule.a), put(4, collider.capsule.b), out[at + 7] = collider.capsule.radius);
1441
+ }
1442
+ var ClothSheet = class {
1443
+ constructor(port, info, geometry) {
1444
+ this.port = port;
1445
+ this.info = info;
1446
+ this.disposed = false;
1447
+ this.particles = info.particles, this.triangles = info.triangles, this.pins = info.pins, this.geometry = geometry;
1448
+ }
1449
+ get id() {
1450
+ return this.info.id;
1451
+ }
1452
+ get engineHost() {
1453
+ return this.port.engineHost ?? null;
1454
+ }
1455
+ positions() {
1456
+ return this.port.positions(this.info.id, this.particles);
1457
+ }
1458
+ attach(geometry) {
1459
+ this.geometry = geometry;
1460
+ }
1461
+ setOptions(options) {
1462
+ writeClothOptions(this.port.prepare(), this.port.registers, options), this.port.params(this.info.id);
1463
+ }
1464
+ setAnchors(anchors) {
1465
+ this.port.anchors(this.info.id, anchors);
1466
+ }
1467
+ present() {
1468
+ return this.disposed || this.geometry === null ? 0 : this.port.present(this.info.id, this.geometry);
1469
+ }
1470
+ dispose() {
1471
+ this.disposed || (this.disposed = true, this.port.remove(this.info.id));
1472
+ }
1473
+ }, Cloths = class {
1474
+ constructor(port) {
1475
+ this.port = port;
1476
+ this.sheets = [];
1477
+ this.block = new Float32Array(chunkX5A5FOWW_js.CLOTH_COLLIDER_FLOATS * chunkX5A5FOWW_js.CLOTH_MAX_COLLIDERS);
1478
+ }
1479
+ create(shape, options = {}) {
1480
+ let floats = this.port.prepare();
1481
+ writeClothOptions(floats, this.port.registers, options);
1482
+ let info;
1483
+ if ("grid" in shape) {
1484
+ writeClothGrid(floats, this.port.registers, shape.grid);
1485
+ let pins = shape.grid.pins;
1486
+ info = this.port.grid(pins === void 0 || pins.length === 0 ? null : Uint32Array.from(pins));
1487
+ } else
1488
+ info = this.port.mesh(shape.mesh.positions, shape.mesh.triangles, shape.mesh.pins ?? null);
1489
+ let sheet = new ClothSheet(this.port, info, options.geometry ?? null);
1490
+ return this.sheets.push(sheet), sheet;
1491
+ }
1492
+ remove(sheet) {
1493
+ let index = this.sheets.indexOf(sheet);
1494
+ index >= 0 && this.sheets.splice(index, 1), sheet.dispose();
1495
+ }
1496
+ setColliders(colliders) {
1497
+ if (colliders.length > chunkX5A5FOWW_js.CLOTH_MAX_COLLIDERS) throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `cloth collides with at most ${chunkX5A5FOWW_js.CLOTH_MAX_COLLIDERS} shapes`);
1498
+ for (let i = 0; i < colliders.length; i++) packClothCollider(this.block, i * chunkX5A5FOWW_js.CLOTH_COLLIDER_FLOATS, colliders[i]);
1499
+ this.port.colliders(this.block, colliders.length);
1500
+ }
1501
+ couple(collider) {
1502
+ if (this.port.couple === void 0) throw new chunk2V7IL4HC_js.GameError("unsupported_feature", "cloth couples to rigid bodies only on the native engine (feature rigid_coupling_1)");
1503
+ return this.port.couple(collider);
1504
+ }
1505
+ uncouple(slot) {
1506
+ this.port.uncouple?.(slot);
1507
+ }
1508
+ get count() {
1509
+ return this.sheets.length;
1510
+ }
1511
+ step(seconds) {
1512
+ this.sheets.length > 0 && this.port.step(seconds);
1513
+ }
1514
+ present() {
1515
+ for (let i = 0; i < this.sheets.length; i++) this.sheets[i].present();
1516
+ }
1517
+ digest() {
1518
+ return this.port.digest();
1519
+ }
1520
+ dispose() {
1521
+ for (let sheet of this.sheets) sheet.dispose();
1522
+ this.sheets.length = 0, this.port.dispose();
1523
+ }
1524
+ };
1525
+
1526
+ // src/game/prefetch/predict.ts
1527
+ var DEFAULT_HORIZONS = [1, 3, 8], DEFAULT_MAX_SPEED = 10, DEFAULT_SPREAD = 0.35, DEFAULT_MIN_SPREAD = 1.5, DEFAULT_TURN_PENALTY = 3, DEFAULT_PLAN_INTERVAL = 6, DEFAULT_PREFETCH_BUDGET = 24 * 1024 * 1024, DEFAULT_MAX_PENDING = 8, DEFAULT_MAX_SPECULATIVE = 2, DEFAULT_CANDIDATES = 1024, DEFAULT_TELEPORT = 50, DEFAULT_SMOOTHING = 0.3, IDLE_HORIZON_SCALE = 2, EntryState = { idle: 0, pending: 1, resident: 2, consumed: 3 }, LEVEL_SPAN = 16, TIME_SPAN = 1 << 20, ENTRY_SPAN = 1 << 24, MS = 1e3, EPSILON = 1e-9, NO_SLOT = -1, NO_CELL = -1, SCALE_SLOT = 7, S_PX = 0, S_PY = 1, S_PZ = 2, S_VX = 3, S_VY = 4, S_VZ = 5, S_SIGMA = 6, S_TOP = 7, S_STOP = 8, S_RADIUS = 9, S_LIMIT = 10, S_RELEASE = 11, S_SCALE = 12, S_KEY = 13, S_BYTES = 14, S_DT = 15, S_ELAPSED = 16, S_ARRIVED = 17, S_LAST = 18, S_RATE = 19, S_OWN_PENDING = 20, S_DEMAND = 21, SCRATCH = 22, RATE_SMOOTHING = 0.25, LOADED_SHARE = 0.5, DEFAULT_SATURATION_SECONDS = 2, LinkLoad = { free: 0, loaded: 1, saturated: 2 }, R_X = 0, R_Z = 1, R_VX = 2, R_VZ = 3, R_HORIZON = 4, R_OUT = 5, R_RANGE = 2, T_MAX_SPEED = 0, T_SPREAD = 1, T_MIN_SPREAD = 2, T_TURN = 3, T_RELEASE = 4, T_TELEPORT = 5, T_SMOOTHING = 6, T_SATURATION = 7, StreamPredictor = class {
1528
+ constructor(layer, assets, options = {}) {
1529
+ this.stats = { plans: 0, requested: 0, reprioritised: 0, released: 0, consumed: 0, pendingBytes: 0, pending: 0, tracked: 0 };
1530
+ this.local = new Float64Array(3);
1531
+ this.previous = new Float64Array(3);
1532
+ this.velocity = new Float64Array(3);
1533
+ this.s = new Float64Array((22));
1534
+ this.r = new Float64Array(6);
1535
+ this.trackedCount = 0;
1536
+ this.candidateCount = 0;
1537
+ this.planId = 0;
1538
+ this.frames = 0;
1539
+ this.hasPrevious = false;
1540
+ this.idleMode = false;
1541
+ this.pendingCount = 0;
1542
+ this.pendingBytes = 0;
1543
+ this.inFlight = 0;
1544
+ this.linkLoad = LinkLoad.free;
1545
+ this.prefetchAllowed = true;
1546
+ this.layer = layer, this.assets = assets;
1547
+ let entries = layer.entries;
1548
+ this.state = new Uint8Array(entries), this.priority = new Uint8Array(entries), this.time = new Float64Array(entries).fill(1 / 0), this.stamp = new Uint32Array(entries), this.slot = new Int32Array(entries).fill((-1)), this.tracked = new Int32Array(entries), this.keys = new Float64Array(Math.max(1, options.capacity ?? (1024)));
1549
+ let horizons = options.horizons ?? DEFAULT_HORIZONS;
1550
+ this.horizons = Float64Array.from(horizons.length > 0 ? horizons : DEFAULT_HORIZONS), this.tuning = Float64Array.of(
1551
+ options.maxSpeed ?? (10),
1552
+ options.spread ?? (0.35),
1553
+ Math.max((1e-9), options.minSpread ?? (1.5)),
1554
+ Math.max(1, options.turnPenalty ?? (3)),
1555
+ options.releaseSeconds ?? this.horizons[this.horizons.length - 1] * 2,
1556
+ options.teleport ?? (50),
1557
+ Math.min(1, Math.max((1e-9), options.smoothing ?? (0.3))),
1558
+ Math.max((1e-9), options.saturationSeconds ?? (2))
1559
+ ), this.budget = Math.max(0, Math.floor(options.budgetBytes ?? DEFAULT_PREFETCH_BUDGET)), this.interval = Math.max(1, Math.floor(options.interval ?? (6))), this.maxPending = Math.max(1, options.maxPending ?? (8)), this.maxSpeculative = Math.max(1, options.maxSpeculative ?? (2));
1560
+ let reach = options.reach ?? null;
1561
+ if (this.reach = reach, this.reachCell = new Int32Array(reach === null ? 0 : layer.count), reach !== null) for (let i = 0; i < layer.count; i++) this.reachCell[i] = reach.cellAt(layer.x[i], layer.z[i]);
1562
+ }
1563
+ attach(assets) {
1564
+ assets !== this.assets && (this.releaseAll(), this.assets = assets);
1565
+ }
1566
+ set idle(on) {
1567
+ this.idleMode = on;
1568
+ }
1569
+ get idle() {
1570
+ return this.idleMode;
1571
+ }
1572
+ get stopTime() {
1573
+ return this.s[(8)];
1574
+ }
1575
+ get bytesPending() {
1576
+ return this.pendingBytes;
1577
+ }
1578
+ get speed() {
1579
+ let v = this.velocity;
1580
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
1581
+ }
1582
+ velocityInto(out) {
1583
+ out[0] = this.velocity[0], out[1] = this.velocity[1], out[2] = this.velocity[2];
1584
+ }
1585
+ activeHorizons(depth) {
1586
+ return this.idleMode && depth.horizons > 1 ? this.horizons.length : Math.min(this.horizons.length, Math.max(1, depth.horizons));
1587
+ }
1588
+ horizonLimit(depth) {
1589
+ let limit = this.horizons[this.activeHorizons(depth) - 1];
1590
+ return this.idleMode && depth.horizons > 1 ? limit * (2) : limit;
1591
+ }
1592
+ frame(eye, dtSeconds) {
1593
+ this.s[(15)] = dtSeconds, this.step(eye);
1594
+ }
1595
+ frameAt(eye, clock2, slot) {
1596
+ this.s[(15)] = clock2[slot], this.step(eye);
1597
+ }
1598
+ get load() {
1599
+ return this.linkLoad;
1600
+ }
1601
+ get throughput() {
1602
+ return this.s[(19)];
1603
+ }
1604
+ step(eye) {
1605
+ this.s[(15)] > 0 && (this.s[(16)] += this.s[(15)]), this.layer.toLocal(eye, this.local, 0, true), this.observe();
1606
+ let due = this.frames % this.interval === 0;
1607
+ this.frames++, due && this.assets !== null && this.assets.prefetch !== void 0 && this.plan();
1608
+ }
1609
+ observe() {
1610
+ let dt = this.s[(15)], position = this.local, previous = this.previous, v = this.velocity, first = !this.hasPrevious, dx = position[0] - previous[0], dy = position[1] - previous[1], dz = position[2] - previous[2];
1611
+ previous[0] = position[0], previous[1] = position[1], previous[2] = position[2], this.hasPrevious = true;
1612
+ let limit = this.tuning[(5)] / this.layer.place[(7)];
1613
+ if (first || dx * dx + dy * dy + dz * dz > limit * limit) {
1614
+ v[0] = 0, v[1] = 0, v[2] = 0;
1615
+ return;
1616
+ }
1617
+ if (!(dt > 0)) return;
1618
+ let a = this.tuning[(6)];
1619
+ v[0] += (dx / dt - v[0]) * a, v[1] += (dy / dt - v[1]) * a, v[2] += (dz / dt - v[2]) * a;
1620
+ }
1621
+ plan() {
1622
+ let layer = this.layer, assets = this.assets, s = this.s, tuning = this.tuning;
1623
+ this.planId = this.planId + 1 >>> 0 || 1, this.stats.plans++;
1624
+ let depth = chunkT7LOXGYX_js.prefetchDepth(assets?.networkHint?.() ?? null);
1625
+ this.prefetchAllowed = depth.prefetch;
1626
+ let idle = this.idleMode && depth.horizons > 1, active = idle ? this.horizons.length : Math.min(this.horizons.length, Math.max(1, depth.horizons));
1627
+ s[(10)] = idle ? this.horizons[active - 1] * (2) : this.horizons[active - 1], s[(11)] = Math.max(tuning[(4)], s[(10)] * 2), this.linkLoad = this.measureLoad(), this.linkLoad !== LinkLoad.free && (s[(10)] = this.horizons[0], this.prefetchAllowed = false), s[(12)] = layer.place[(7)], s[(9)] = layer.needRadius() / s[(12)], s[(0)] = this.local[0], s[(1)] = this.local[1], s[(2)] = this.local[2];
1628
+ let v = this.velocity;
1629
+ s[(3)] = v[0], s[(4)] = v[1], s[(5)] = v[2];
1630
+ let speed = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
1631
+ s[(6)] = Math.max(tuning[(2)] / s[(12)], speed * tuning[(1)]), s[(7)] = Math.max(tuning[(0)] / s[(12)], speed), s[(8)] = 1 / 0;
1632
+ let reach = this.reach;
1633
+ if (reach !== null) {
1634
+ let r = this.r;
1635
+ r[(0)] = s[(0)], r[(1)] = s[(2)], r[(2)] = s[(7)] * s[(11)] * tuning[(3)] + s[(9)], reach.updateFrom(r), r[(0)] = s[(0)], r[(1)] = s[(2)], r[(2)] = s[(3)], r[(3)] = s[(5)], r[(4)] = s[(11)], reach.stopTimeInto(r), s[(8)] = r[(5)];
1636
+ }
1637
+ let range = s[(9)] + layer.maxRadius + s[(7)] * s[(11)], cell = layer.cellSize, c0 = Math.max(0, Math.floor((s[(0)] - range - layer.originX) / cell)), c1 = Math.min(layer.cols - 1, Math.floor((s[(0)] + range - layer.originX) / cell)), r0 = Math.max(0, Math.floor((s[(2)] - range - layer.originZ) / cell)), r1 = Math.min(layer.rows - 1, Math.floor((s[(2)] + range - layer.originZ) / cell));
1638
+ this.candidateCount = 0;
1639
+ for (let row = r0; row <= r1; row++)
1640
+ for (let col = c0; col <= c1; col++) {
1641
+ let c = row * layer.cols + col, end = layer.cellStart[c + 1];
1642
+ for (let k = layer.cellStart[c]; k < end; k++) this.consider(layer.cellItems[k]);
1643
+ }
1644
+ this.refresh(), this.issue(), this.stats.pendingBytes = this.pendingBytes, this.stats.pending = this.pendingCount, this.stats.tracked = this.trackedCount;
1645
+ }
1646
+ consider(item) {
1647
+ let layer = this.layer, s = this.s, wx = layer.x[item] - s[(0)], wy = layer.y[item] - s[(1)], wz = layer.z[item] - s[(2)], distance = Math.sqrt(wx * wx + wy * wy + wz * wz), radius = s[(9)], r = layer.radius[item], top = s[(7)], release = s[(11)];
1648
+ if (distance - r - radius > top * release) return;
1649
+ let held = layer.held, route = distance;
1650
+ if (this.reach !== null) {
1651
+ let at = this.reachCell[item], path = at === (-1) ? 1 / 0 : this.reach.distance[at];
1652
+ path > route && (route = path);
1653
+ }
1654
+ let vx = s[(3)], vy = s[(4)], vz = s[(5)], sigma = s[(6)], stop = s[(8)], limit = s[(10)], scale = s[(12)], turnPenalty = this.tuning[(3)], first = this.horizons[0];
1655
+ for (let e = layer.entryStart[item]; e < layer.entryStart[item + 1]; e++) {
1656
+ let within = layer.entryWithin[e] / scale, reachDistance = (within < radius ? within : radius) + r, t = 0;
1657
+ if (distance > reachDistance) {
1658
+ let c = distance * distance - reachDistance * reachDistance, a = vx * vx + vy * vy + vz * vz - sigma * sigma, b = -2 * (wx * vx + wy * vy + wz * vz + reachDistance * sigma), motion = 1 / 0;
1659
+ if (Math.abs(a) < (1e-9))
1660
+ b < 0 && (motion = -c / b);
1661
+ else {
1662
+ let disc = b * b - 4 * a * c;
1663
+ if (disc >= 0) {
1664
+ let root = Math.sqrt(disc), t1 = (-b - root) / (2 * a), t2 = (-b + root) / (2 * a);
1665
+ a > 0 ? motion = t2 < 0 ? 1 / 0 : t1 > 0 ? t1 : 0 : motion = t1 > t2 ? t1 : t2;
1666
+ }
1667
+ }
1668
+ if (motion > stop) {
1669
+ let sx = wx - vx * stop, sy = wy - vy * stop, sz = wz - vz * stop, gap = (Math.sqrt(sx * sx + sy * sy + sz * sz) - reachDistance) / sigma;
1670
+ motion = gap > stop ? gap : stop;
1671
+ }
1672
+ let turn = route === 1 / 0 ? 1 / 0 : (route - reachDistance) / top * turnPenalty, lower = (distance - reachDistance) / top;
1673
+ t = motion < turn ? motion : turn, t < lower && (t = lower);
1674
+ }
1675
+ if (this.stamp[e] = this.planId, this.time[e] = t, t > limit || held !== null && held(e)) continue;
1676
+ let level = layer.entryLevel[e], priority = chunk4ZDR72SG_js.ChunkPriority.prefetch;
1677
+ if (level === 0 && t <= first) priority = chunk4ZDR72SG_js.ChunkPriority.soon;
1678
+ else if (!this.prefetchAllowed) continue;
1679
+ let state = this.state[e];
1680
+ if (state !== EntryState.idle && !(state === EntryState.pending && priority < this.priority[e])) continue;
1681
+ let quantised = t * (1e3) < TIME_SPAN - 1 ? Math.floor(t * (1e3)) : TIME_SPAN - 1;
1682
+ s[(13)] = ((priority * (16) + level) * TIME_SPAN + quantised) * ENTRY_SPAN + e, this.candidate();
1683
+ }
1684
+ }
1685
+ candidate() {
1686
+ let keys = this.keys, key = this.s[(13)];
1687
+ if (this.candidateCount < keys.length) {
1688
+ keys[this.candidateCount++] = key;
1689
+ return;
1690
+ }
1691
+ let worst = 0;
1692
+ for (let i = 1; i < this.candidateCount; i++) keys[i] > keys[worst] && (worst = i);
1693
+ key < keys[worst] && (keys[worst] = key);
1694
+ }
1695
+ measureLoad() {
1696
+ let flow = this.layer.flow;
1697
+ if (flow === null) return LinkLoad.free;
1698
+ let s = this.s, delivered = flow[chunkVVE3Y76O_js.FLOW_DELIVERED] + s[(17)], elapsed = s[(16)];
1699
+ if (elapsed > 0) {
1700
+ if (s[(21)] > 0) {
1701
+ let rate = (delivered - s[(18)]) / elapsed;
1702
+ s[(19)] = s[(19)] > 0 ? s[(19)] + (rate - s[(19)]) * (0.25) : rate;
1703
+ }
1704
+ s[(18)] = delivered, s[(16)] = 0;
1705
+ }
1706
+ let demand = flow[chunkVVE3Y76O_js.FLOW_BACKLOG] + s[(20)];
1707
+ if (s[(21)] = demand, demand <= 0) return LinkLoad.free;
1708
+ let drain = s[(19)] * this.tuning[(7)];
1709
+ return demand > drain ? LinkLoad.saturated : demand > drain * (0.5) ? LinkLoad.loaded : LinkLoad.free;
1710
+ }
1711
+ refresh() {
1712
+ let assets = this.assets, planId = this.planId, release = this.s[(11)];
1713
+ this.inFlight = 0, this.s[(20)] = 0;
1714
+ for (let i = this.trackedCount - 1; i >= 0; i--) {
1715
+ let e = this.tracked[i], path = this.layer.paths[e], state = this.state[e];
1716
+ if (state === EntryState.pending || state === EntryState.resident) {
1717
+ let resident = assets?.resident?.(path) === true, pending = !resident && assets?.pending?.(path) === true;
1718
+ resident ? (state === EntryState.pending && (this.s[(17)] += this.layer.entryBytes[e]), state = EntryState.resident) : pending || (state = EntryState.consumed, this.stats.consumed++, this.untrackBytes(e)), this.state[e] = state;
1719
+ }
1720
+ let keep = this.stamp[e] === planId && this.time[e] <= release;
1721
+ keep && state === EntryState.pending && (this.s[(20)] += this.layer.entryBytes[e], this.priority[e] === chunk4ZDR72SG_js.ChunkPriority.prefetch && this.inFlight++), !keep && ((state === EntryState.pending || state === EntryState.resident) && (assets?.cancelPrefetch?.(path), this.stats.released++, this.untrackBytes(e)), this.state[e] = EntryState.idle, this.untrack(i));
1722
+ }
1723
+ }
1724
+ issue() {
1725
+ let assets = this.assets, keys = this.keys, n = this.candidateCount;
1726
+ if (heapSort(keys, n), assets === null || assets.prefetch === void 0) return;
1727
+ let busy = this.layer.busy !== null && this.layer.busy();
1728
+ for (let i = 0; i < n; i++) {
1729
+ let key = keys[i], entry = key % ENTRY_SPAN | 0, priority = Math.floor(key / ENTRY_SPAN / TIME_SPAN / (16)) | 0, state = this.state[entry], path = this.layer.paths[entry];
1730
+ if (state === EntryState.pending) {
1731
+ assets.prefetch(path, priority) && (this.priority[entry] = priority, this.stats.reprioritised++);
1732
+ continue;
1733
+ }
1734
+ if (this.linkLoad !== LinkLoad.free || this.pendingCount >= this.maxPending || busy && priority === chunk4ZDR72SG_js.ChunkPriority.prefetch || priority === chunk4ZDR72SG_js.ChunkPriority.prefetch && this.inFlight >= this.maxSpeculative) continue;
1735
+ let bytes = this.layer.entryBytes[entry];
1736
+ if (!(this.pendingBytes + bytes > this.budget && (this.s[(13)] = key, this.s[(14)] = bytes, !this.evict()))) {
1737
+ if (!assets.prefetch(path, priority)) {
1738
+ this.state[entry] = EntryState.consumed, this.track(entry);
1739
+ continue;
1740
+ }
1741
+ this.state[entry] = assets.resident?.(path) === true ? EntryState.resident : EntryState.pending, this.priority[entry] = priority, this.track(entry), this.pendingBytes += bytes, this.pendingCount++, priority === chunk4ZDR72SG_js.ChunkPriority.prefetch && this.state[entry] === EntryState.pending && this.inFlight++, this.stats.requested++;
1742
+ }
1743
+ }
1744
+ }
1745
+ evict() {
1746
+ let assets = this.assets, key = this.s[(13)], bytes = this.s[(14)];
1747
+ for (; this.pendingBytes + bytes > this.budget; ) {
1748
+ let worst = (-1), worstKey = key;
1749
+ for (let i = 0; i < this.trackedCount; i++) {
1750
+ let e2 = this.tracked[i], state = this.state[e2];
1751
+ if (state !== EntryState.resident && state !== EntryState.pending) continue;
1752
+ let t = this.time[e2], quantised = t * (1e3) < TIME_SPAN - 1 ? Math.floor(t * (1e3)) : TIME_SPAN - 1, k = ((this.priority[e2] * (16) + this.layer.entryLevel[e2]) * TIME_SPAN + quantised) * ENTRY_SPAN + e2;
1753
+ k > worstKey && (worstKey = k, worst = i);
1754
+ }
1755
+ if (worst === (-1)) return false;
1756
+ let e = this.tracked[worst];
1757
+ assets?.cancelPrefetch?.(this.layer.paths[e]), this.stats.released++, this.untrackBytes(e), this.state[e] = EntryState.idle, this.untrack(worst);
1758
+ }
1759
+ return true;
1760
+ }
1761
+ track(entry) {
1762
+ this.slot[entry] === (-1) && (this.slot[entry] = this.trackedCount, this.tracked[this.trackedCount++] = entry);
1763
+ }
1764
+ untrack(index) {
1765
+ let entry = this.tracked[index], last = this.tracked[--this.trackedCount];
1766
+ this.tracked[index] = last, this.slot[last] = index, this.slot[entry] = (-1);
1767
+ }
1768
+ untrackBytes(entry) {
1769
+ let left = this.pendingBytes - this.layer.entryBytes[entry];
1770
+ this.pendingBytes = left > 0 ? left : 0, this.pendingCount > 0 && this.pendingCount--;
1771
+ }
1772
+ releaseAll() {
1773
+ let assets = this.assets;
1774
+ for (let i = this.trackedCount - 1; i >= 0; i--) {
1775
+ let e = this.tracked[i], state = this.state[e];
1776
+ (state === EntryState.pending || state === EntryState.resident) && (assets?.cancelPrefetch?.(this.layer.paths[e]), this.stats.released++), this.state[e] = EntryState.idle, this.slot[e] = (-1);
1777
+ }
1778
+ this.trackedCount = 0, this.pendingBytes = 0, this.pendingCount = 0;
1779
+ }
1780
+ reset() {
1781
+ this.releaseAll(), this.hasPrevious = false, this.velocity.fill(0), this.frames = 0;
1782
+ }
1783
+ };
1784
+ function cone(wx, wy, wz, vx, vy, vz, reach, sigma) {
1785
+ let c = wx * wx + wy * wy + wz * wz - reach * reach;
1786
+ if (c <= 0) return 0;
1787
+ let a = vx * vx + vy * vy + vz * vz - sigma * sigma, b = -2 * (wx * vx + wy * vy + wz * vz + reach * sigma);
1788
+ if (Math.abs(a) < (1e-9)) return b < 0 ? -c / b : 1 / 0;
1789
+ let disc = b * b - 4 * a * c;
1790
+ if (disc < 0) return 1 / 0;
1791
+ let root = Math.sqrt(disc), t1 = (-b - root) / (2 * a), t2 = (-b + root) / (2 * a);
1792
+ return a > 0 ? t2 < 0 ? 1 / 0 : t1 > 0 ? t1 : 0 : t1 > t2 ? t1 : t2;
1793
+ }
1794
+ function heapSort(keys, n) {
1795
+ for (let start = (n >> 1) - 1; start >= 0; start--) siftDown(keys, start, n);
1796
+ for (let end = n - 1; end > 0; end--) {
1797
+ let top = keys[0];
1798
+ keys[0] = keys[end], keys[end] = top, siftDown(keys, 0, end);
1799
+ }
1800
+ }
1801
+ function siftDown(keys, start, end) {
1802
+ let root = start, value = keys[root];
1803
+ for (; ; ) {
1804
+ let child = 2 * root + 1;
1805
+ if (child >= end || (child + 1 < end && keys[child + 1] > keys[child] && child++, keys[child] <= value)) break;
1806
+ keys[root] = keys[child], root = child;
1807
+ }
1808
+ keys[root] = value;
1809
+ }
1810
+
1811
+ exports.CENTERED_FIXED_UNITS = (256);
1812
+ exports.CENTERED_MAX_EXTENT = (16384);
1813
+ exports.CLOTH_DEFAULTS = CLOTH_DEFAULTS;
1814
+ exports.ClothSheet = ClothSheet;
1815
+ exports.Cloths = Cloths;
1816
+ exports.DEFAULT_CANDIDATES = (1024);
1817
+ exports.DEFAULT_HORIZONS = DEFAULT_HORIZONS;
1818
+ exports.DEFAULT_MAX_PENDING = (8);
1819
+ exports.DEFAULT_MAX_SPECULATIVE = (2);
1820
+ exports.DEFAULT_MAX_SPEED = (10);
1821
+ exports.DEFAULT_MIN_SPREAD = (1.5);
1822
+ exports.DEFAULT_PLAN_INTERVAL = (6);
1823
+ exports.DEFAULT_PREFETCH_BUDGET = DEFAULT_PREFETCH_BUDGET;
1824
+ exports.DEFAULT_SATURATION_SECONDS = (2);
1825
+ exports.DEFAULT_SMOOTHING = (0.3);
1826
+ exports.DEFAULT_SPREAD = (0.35);
1827
+ exports.DEFAULT_TELEPORT = (50);
1828
+ exports.DEFAULT_TURN_PENALTY = (3);
1829
+ exports.EntryState = EntryState;
1830
+ exports.FrameInput = FrameInput;
1831
+ exports.InputActions = InputActions;
1832
+ exports.InputDevice = InputDevice;
1833
+ exports.LOOP_MAX_REGION_ROWS = (65536);
1834
+ exports.LOOP_PROBE_GLOBAL = LOOP_PROBE_GLOBAL;
1835
+ exports.LongPressGesture = LongPressGesture;
1836
+ exports.LoweredLoop = LoweredLoop;
1837
+ exports.OrientationState = OrientationState;
1838
+ exports.PinchGesture = PinchGesture;
1839
+ exports.PointerDelta = PointerDelta;
1840
+ exports.PointerState = PointerState;
1841
+ exports.RECORDED_EVENT_BYTES = (32);
1842
+ exports.SOFT_DEFAULTS = SOFT_DEFAULTS;
1843
+ exports.STAGE_TIME = (3);
1844
+ exports.STAGE_X = (0);
1845
+ exports.STAGE_Y = (1);
1846
+ exports.STAGE_Z = (2);
1847
+ exports.SeededRandom = SeededRandom;
1848
+ exports.SoftBodies = SoftBodies;
1849
+ exports.SoftBody = SoftBody;
1850
+ exports.StreamPredictor = StreamPredictor;
1851
+ exports.SwipeGesture = SwipeGesture;
1852
+ exports.TapGesture = TapGesture;
1853
+ exports.WheelState = WheelState;
1854
+ exports.cone = cone;
1855
+ exports.configureLoops = configureLoops;
1856
+ exports.crumpleDesc = crumpleDesc;
1857
+ exports.drainSource = drainSource;
1858
+ exports.loopEngineOf = loopEngineOf;
1859
+ exports.loopProbe = loopProbe;
1860
+ exports.lowerLoop = lowerLoop;
1861
+ exports.setLoopEngine = setLoopEngine;
1862
+ exports.vmLoopEngine = vmLoopEngine;