@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,1315 @@
1
+ import { Vec3 } from './chunk-XPG3N5CF.mjs';
2
+ import { NO_ENTITY } from './chunk-T3AFF3L7.mjs';
3
+ import { createPickHit } from './chunk-TL2SVO4P.mjs';
4
+ import './chunk-K4UDGE3Z.mjs';
5
+ import { MOE_MIN_EXPERTS, MOE_MAX_EXPERTS, moeBlob, parseMoe, evalMoeLane, MLP_MAX_LAYERS, parseMlp, MLP_ACT_LINEAR, MLP_ACT_RELU, mlpBlob, evalMlp, MLP_ACC_LIMIT, MLP_MULTIPLIER_LIMIT, MLP_MAX_SHIFT } from './chunk-MOBSBXVE.mjs';
6
+ import { MLP_MAX_WIDTH, MLP_MAX_OUTPUTS, sin, cos, tan, asin, acos, atan, atan2, exp, log, log2, pow } from './chunk-SMK6JU2F.mjs';
7
+ import { GameError } from './chunk-XJIHN3BY.mjs';
8
+
9
+ // src/game/kernel/train.ts
10
+ var fr = Math.fround, Q_MAX = 127, Q_MIN = -128, INPUT_SPAN = 256, HALF = 0.5, HE_GAIN = 6, SEED_FALLBACK = 2654435769, UNIT_SHIFT = 8, UNIT_SCALE = 2 ** -24, DEFAULT_EPOCHS = 20, DEFAULT_BATCH = 32, DEFAULT_RATE = 0.02, DEFAULT_MOMENTUM = 0.9, DEFAULT_SEED = 1, MLP_MEMORY_MIN = 2, MLP_MEMORY_MAX = 4;
11
+ function invalid(message2) {
12
+ throw new GameError("invalid_argument", message2);
13
+ }
14
+ function joinMemory(data) {
15
+ let memory = data.memory;
16
+ if (memory === void 0) return data;
17
+ let { samples } = data, width = memory.width;
18
+ (!Number.isInteger(samples) || samples < 1) && invalid("training needs at least one sample"), (!Number.isInteger(width) || width < (2) || width > (4)) && invalid(`memory carries ${(2)} to ${(4)} values`), (memory.previous.length !== samples * width || memory.next.length !== samples * width) && invalid(`memory needs ${width} previous and ${width} next values for each of the ${samples} samples`), data.inputs.length % samples !== 0 && invalid(`inputs need the same count of numbers for each of the ${samples} samples`), data.targets.length % samples !== 0 && invalid(`targets need the same count of numbers for each of the ${samples} samples`);
19
+ let features = data.inputs.length / samples, actions = data.targets.length / samples, inputs = new Float32Array(samples * (features + width)), targets = new Float32Array(samples * (actions + width));
20
+ for (let s = 0; s < samples; s++) {
21
+ let i = s * (features + width), t = s * (actions + width);
22
+ for (let k = 0; k < features; k++) inputs[i + k] = data.inputs[s * features + k];
23
+ for (let k = 0; k < width; k++) inputs[i + features + k] = memory.previous[s * width + k];
24
+ for (let k = 0; k < actions; k++) targets[t + k] = data.targets[s * actions + k];
25
+ for (let k = 0; k < width; k++) targets[t + actions + k] = memory.next[s * width + k];
26
+ }
27
+ return { samples, inputs, targets };
28
+ }
29
+ function memorySamples(episodes) {
30
+ let first = episodes.find((e) => e.inputs.length > 0);
31
+ first === void 0 && invalid("memory training needs at least one episode with a step");
32
+ let features = first.inputs[0].length, actions = first.targets[0]?.length ?? 0, width = first.memory[0]?.length ?? 0, samples = 0;
33
+ for (let episode of episodes)
34
+ (episode.targets.length !== episode.inputs.length || episode.memory.length !== episode.inputs.length + 1) && invalid("each episode has one target row per input row and one more memory row than steps, the first being the starting memory"), samples += episode.inputs.length;
35
+ let inputs = new Float32Array(samples * features), targets = new Float32Array(samples * actions), previous = new Float32Array(samples * width), next = new Float32Array(samples * width), s = 0, row = (out, values, length, at, what) => {
36
+ values.length !== length && invalid(`every ${what} row has ${length} numbers`), out.set(values, at * length);
37
+ };
38
+ for (let episode of episodes)
39
+ for (let t = 0; t < episode.inputs.length; t++, s++)
40
+ row(inputs, episode.inputs[t], features, s, "input"), row(targets, episode.targets[t], actions, s, "target"), row(previous, episode.memory[t], width, s, "memory"), row(next, episode.memory[t + 1], width, s, "memory");
41
+ return { samples, inputs, targets, memory: { width, previous, next } };
42
+ }
43
+ var Random = class {
44
+ constructor(seed) {
45
+ this.state = seed >>> 0 || (2654435769);
46
+ }
47
+ next() {
48
+ let x = this.state;
49
+ return x ^= x << 13, x >>>= 0, x ^= x >>> 17, x ^= x << 5, this.state = x >>> 0, this.state;
50
+ }
51
+ unit() {
52
+ return (this.next() >>> (8)) * UNIT_SCALE;
53
+ }
54
+ };
55
+ function roundHalfEven(x) {
56
+ let r = Math.floor(x), d = x - r;
57
+ return d > (0.5) ? r + 1 : d < (0.5) || r % 2 === 0 ? r : r + 1;
58
+ }
59
+ function clamp(x, low, high) {
60
+ return x < low ? low : x > high ? high : x;
61
+ }
62
+ function maxAbs(values) {
63
+ let m = 0;
64
+ for (let k = 0; k < values.length; k++) {
65
+ let a = Math.abs(values[k]);
66
+ a > m && (m = a);
67
+ }
68
+ return m;
69
+ }
70
+ function scaleOf(max) {
71
+ return max > 0 ? fr(max / (127)) : fr(1 / (127));
72
+ }
73
+ function check(data, widths) {
74
+ let fail = (message2) => {
75
+ throw new GameError("invalid_argument", message2);
76
+ };
77
+ (widths.length < 2 || widths.length - 1 > MLP_MAX_LAYERS) && fail(`a network has 1 to ${MLP_MAX_LAYERS} layers`), widths.some((w) => !Number.isInteger(w) || w < 1) && fail("every layer width is a whole number of at least 1"), widths.slice(0, -1).some((w) => w > MLP_MAX_WIDTH) && fail(`inputs and hidden layers are at most ${MLP_MAX_WIDTH} wide`), widths[widths.length - 1] > MLP_MAX_OUTPUTS && fail(`a network has at most ${MLP_MAX_OUTPUTS} outputs`), (!Number.isInteger(data.samples) || data.samples < 1) && fail("training needs at least one sample"), data.inputs.length !== data.samples * widths[0] && fail(`inputs need ${widths[0]} numbers for each of the ${data.samples} samples`), data.targets.length !== data.samples * widths[widths.length - 1] && fail(`targets need ${widths[widths.length - 1]} numbers for each of the ${data.samples} samples`);
78
+ }
79
+ function layersOf(widths, random) {
80
+ let layers = [];
81
+ for (let l = 0; l + 1 < widths.length; l++) {
82
+ let inputs = widths[l], outputs = widths[l + 1], limit = fr(Math.sqrt(fr((6) / inputs))), w = new Float32Array(inputs * outputs);
83
+ for (let k = 0; k < w.length; k++) w[k] = fr(fr(fr(random.unit() * 2) - 1) * limit);
84
+ let size = inputs * outputs;
85
+ layers.push({
86
+ inputs,
87
+ outputs,
88
+ w,
89
+ b: new Float32Array(outputs),
90
+ vw: new Float32Array(size),
91
+ vb: new Float32Array(outputs),
92
+ gw: new Float32Array(size),
93
+ gb: new Float32Array(outputs),
94
+ wq: new Float32Array(size),
95
+ z: new Float32Array(outputs),
96
+ a: new Float32Array(outputs),
97
+ da: new Float32Array(inputs),
98
+ wScale: 1,
99
+ aScale: 1
100
+ });
101
+ }
102
+ return layers;
103
+ }
104
+ function quantizeWeights(layer) {
105
+ layer.wScale = scaleOf(maxAbs(layer.w));
106
+ for (let k = 0; k < layer.w.length; k++) layer.wq[k] = fr(clamp(roundHalfEven(fr(layer.w[k] / layer.wScale)), -(127), (127)) * layer.wScale);
107
+ }
108
+ function quantizeInput(x, scale, unit) {
109
+ let raw = fr(fr(x) * scale), t = Number.isNaN(raw) ? 0 : clamp(raw, -(256), (256));
110
+ return fr(clamp(roundHalfEven(t), (-128), (127)) * unit);
111
+ }
112
+ function forward(layers, input, quantizeActs) {
113
+ let prev = input;
114
+ layers.forEach((layer, l) => {
115
+ let last = l + 1 === layers.length;
116
+ for (let j = 0; j < layer.outputs; j++) {
117
+ let acc = layer.b[j], row = j * layer.inputs;
118
+ for (let i = 0; i < layer.inputs; i++) acc = fr(acc + fr(layer.wq[row + i] * prev[i]));
119
+ if (layer.z[j] = acc, last) layer.a[j] = acc;
120
+ else {
121
+ let r = acc > 0 ? acc : 0;
122
+ layer.a[j] = quantizeActs ? fr(clamp(roundHalfEven(fr(r / layer.aScale)), 0, (127)) * layer.aScale) : r;
123
+ }
124
+ }
125
+ prev = layer.a;
126
+ });
127
+ }
128
+ function backward(layers, input, error) {
129
+ let delta = error;
130
+ for (let l = layers.length - 1; l >= 0; l--) {
131
+ let layer = layers[l], prev = l === 0 ? input : layers[l - 1].a;
132
+ layer.da.fill(0);
133
+ for (let j = 0; j < layer.outputs; j++) {
134
+ let g = delta[j];
135
+ if (g === 0) continue;
136
+ let row = j * layer.inputs;
137
+ layer.gb[j] = fr(layer.gb[j] + g);
138
+ for (let i = 0; i < layer.inputs; i++)
139
+ layer.gw[row + i] = fr(layer.gw[row + i] + fr(g * prev[i])), layer.da[i] = fr(layer.da[i] + fr(g * layer.wq[row + i]));
140
+ }
141
+ if (l > 0) {
142
+ let below = layers[l - 1];
143
+ for (let i = 0; i < layer.inputs; i++) below.z[i] > 0 || (layer.da[i] = 0);
144
+ }
145
+ delta = layer.da;
146
+ }
147
+ }
148
+ function step(layers, size, momentum) {
149
+ for (let layer of layers) {
150
+ for (let k = 0; k < layer.w.length; k++)
151
+ layer.vw[k] = fr(fr(momentum * layer.vw[k]) - fr(size * layer.gw[k])), layer.w[k] = fr(layer.w[k] + layer.vw[k]);
152
+ for (let j = 0; j < layer.outputs; j++)
153
+ layer.vb[j] = fr(fr(momentum * layer.vb[j]) - fr(size * layer.gb[j])), layer.b[j] = fr(layer.b[j] + layer.vb[j]);
154
+ }
155
+ }
156
+ function begin(layers) {
157
+ for (let layer of layers)
158
+ quantizeWeights(layer), layer.gw.fill(0), layer.gb.fill(0);
159
+ }
160
+ function calibrate(layers, data, inputScale2, inputUnit, input) {
161
+ let peaks = new Float32Array(layers.length);
162
+ for (let s = 0; s < data.samples; s++) {
163
+ for (let i = 0; i < input.length; i++) input[i] = quantizeInput(data.inputs[s * input.length + i], inputScale2, inputUnit);
164
+ forward(layers, input, false);
165
+ for (let l = 0; l + 1 < layers.length; l++) for (let v of layers[l].a) v > peaks[l] && (peaks[l] = v);
166
+ }
167
+ for (let l = 0; l + 1 < layers.length; l++) layers[l].aScale = scaleOf(peaks[l]);
168
+ }
169
+ function shiftFor(m) {
170
+ for (let shift = MLP_MAX_SHIFT; shift >= 0; shift--) {
171
+ let multiplier = Math.floor(m * 2 ** shift + (0.5));
172
+ if (multiplier < MLP_MULTIPLIER_LIMIT) return [multiplier, shift];
173
+ }
174
+ return [MLP_MULTIPLIER_LIMIT - 1, 0];
175
+ }
176
+ function exportBlob(layers, inputScale2, inputUnit) {
177
+ let specs = [], unit = inputUnit;
178
+ return layers.forEach((layer, l) => {
179
+ let last = l + 1 === layers.length, accScale = fr(unit * layer.wScale), weights = Array.from(layer.w, (v) => clamp(roundHalfEven(fr(v / layer.wScale)), -(127), (127))), bias = Array.from(layer.b, (v) => clamp(roundHalfEven(fr(v / accScale)), -MLP_ACC_LIMIT, MLP_ACC_LIMIT));
180
+ if (last) {
181
+ specs.push({ outputs: layer.outputs, activation: MLP_ACT_LINEAR, multiplier: 0, shift: 0, zero: 0, scale: accScale, bias, weights });
182
+ return;
183
+ }
184
+ let [multiplier, shift] = shiftFor(accScale / layer.aScale);
185
+ specs.push({ outputs: layer.outputs, activation: MLP_ACT_RELU, multiplier, shift, zero: 0, scale: layer.aScale, bias, weights }), unit = layer.aScale;
186
+ }), mlpBlob(layers[0].inputs, inputScale2, 0, specs);
187
+ }
188
+ function blobLoss(blob, data, inputs, outputs) {
189
+ let net = parseMlp(blob, blob.length, inputs, outputs);
190
+ if (net === null) throw new GameError("invalid_argument", "the trained network did not pack into a valid file");
191
+ let bits = new Float32Array(inputs), words = new Uint32Array(bits.buffer), out = new Uint32Array(outputs), view = new Float32Array(out.buffer), total = 0;
192
+ for (let s = 0; s < data.samples; s++) {
193
+ for (let i = 0; i < inputs; i++) bits[i] = data.inputs[s * inputs + i];
194
+ evalMlp(net, words, out);
195
+ for (let j = 0; j < outputs; j++) {
196
+ let e = fr(view[j] - fr(data.targets[s * outputs + j]));
197
+ total = fr(total + fr(fr(e * e) * (0.5)));
198
+ }
199
+ }
200
+ return fr(total / data.samples);
201
+ }
202
+ function trainMlp(source, options) {
203
+ let data = joinMemory(source), widths = options.widths;
204
+ check(data, widths);
205
+ let epochs = options.epochs ?? (20), batch = Math.max(1, Math.floor(options.batch ?? (32))), rate = fr(options.learningRate ?? (0.02)), momentum = fr(options.momentum ?? (0.9)), random = new Random(options.seed ?? (1)), inputs = widths[0], outputs = widths[widths.length - 1], layers = layersOf(widths, random), peak = 0;
206
+ for (let k = 0; k < data.inputs.length; k++) {
207
+ let a = Math.abs(fr(data.inputs[k]));
208
+ a > peak && (peak = a);
209
+ }
210
+ let inputScale2 = peak > 0 ? fr((127) / peak) : 1, inputUnit = fr(1 / inputScale2), input = new Float32Array(inputs), error = new Float32Array(outputs), order = Uint32Array.from({ length: data.samples }, (_, k) => k), loss = new Float32Array(epochs);
211
+ for (let epoch = 0; epoch < epochs; epoch++) {
212
+ for (let layer of layers) quantizeWeights(layer);
213
+ calibrate(layers, data, inputScale2, inputUnit, input);
214
+ for (let k = data.samples - 1; k > 0; k--) {
215
+ let j = random.next() % (k + 1), t = order[k];
216
+ order[k] = order[j], order[j] = t;
217
+ }
218
+ let total = 0;
219
+ for (let start = 0; start < data.samples; start += batch) {
220
+ let end = Math.min(start + batch, data.samples);
221
+ begin(layers);
222
+ for (let k = start; k < end; k++) {
223
+ let s = order[k];
224
+ for (let i = 0; i < inputs; i++) input[i] = quantizeInput(data.inputs[s * inputs + i], inputScale2, inputUnit);
225
+ forward(layers, input, true);
226
+ let top = layers[layers.length - 1];
227
+ for (let j = 0; j < outputs; j++) {
228
+ let e = fr(top.a[j] - fr(data.targets[s * outputs + j]));
229
+ error[j] = e, total = fr(total + fr(fr(e * e) * (0.5)));
230
+ }
231
+ backward(layers, input, error);
232
+ }
233
+ step(layers, fr(rate / (end - start)), momentum);
234
+ }
235
+ loss[epoch] = fr(total / data.samples);
236
+ }
237
+ for (let layer of layers) quantizeWeights(layer);
238
+ calibrate(layers, data, inputScale2, inputUnit, input);
239
+ let blob = exportBlob(layers, inputScale2, inputUnit);
240
+ return { blob, loss, blobLoss: blobLoss(blob, data, inputs, outputs) };
241
+ }
242
+ var MOE_DEFAULT_BALANCE = 0.5;
243
+ function halfSquared(y, data, at) {
244
+ let total = 0;
245
+ for (let j = 0; j < y.length; j++) {
246
+ let e = fr(y[j] - fr(data.targets[at + j]));
247
+ total = fr(total + fr(fr(e * e) * (0.5)));
248
+ }
249
+ return total;
250
+ }
251
+ function topOf(values) {
252
+ let best = 0;
253
+ for (let j = 1; j < values.length; j++) values[j] > values[best] && (best = j);
254
+ return best;
255
+ }
256
+ function assign(errors, counts, len, balance) {
257
+ let experts = errors.length, best = 0, low = Number.POSITIVE_INFINITY;
258
+ for (let e = 0; e < experts; e++) {
259
+ let load = fr(fr(counts[e] * experts) / len), score = fr(errors[e] * fr(1 + fr(balance * load)));
260
+ score < low && (low = score, best = e);
261
+ }
262
+ return best;
263
+ }
264
+ function lastOf(layers) {
265
+ return layers[layers.length - 1];
266
+ }
267
+ function trainMoe(source, options) {
268
+ let data = joinMemory(source), count = options.experts;
269
+ (!Number.isInteger(count) || count < MOE_MIN_EXPERTS || count > MOE_MAX_EXPERTS) && invalid(`a mixture has ${MOE_MIN_EXPERTS} to ${MOE_MAX_EXPERTS} experts`), (!Number.isInteger(data.samples) || data.samples < 1) && invalid("training needs at least one sample");
270
+ let inputs = data.inputs.length / data.samples, outputs = data.targets.length / data.samples, routerWidths = [inputs, ...options.router ?? [], count], expertWidths = [inputs, ...options.expert ?? [], outputs];
271
+ check(data, expertWidths), check({ samples: data.samples, inputs: data.inputs, targets: new Float32Array(data.samples * count) }, routerWidths);
272
+ let epochs = options.epochs ?? (20), batch = Math.max(1, Math.floor(options.batch ?? (32))), rate = fr(options.learningRate ?? (0.02)), momentum = fr(options.momentum ?? (0.9)), balance = fr(options.balance ?? (0.5)), random = new Random(options.seed ?? (1)), router = layersOf(routerWidths, random), experts = Array.from({ length: count }, () => layersOf(expertWidths, random)), peak = 0;
273
+ for (let k = 0; k < data.inputs.length; k++) {
274
+ let a = Math.abs(fr(data.inputs[k]));
275
+ a > peak && (peak = a);
276
+ }
277
+ let inputScale2 = peak > 0 ? fr((127) / peak) : 1, inputUnit = fr(1 / inputScale2), input = new Float32Array(inputs), error = new Float32Array(outputs), routeError = new Float32Array(count), errors = new Float32Array(count), counts = new Uint32Array(count), order = Uint32Array.from({ length: data.samples }, (_, k) => k), loss = new Float32Array(epochs), all = [router, ...experts];
278
+ for (let epoch = 0; epoch < epochs; epoch++) {
279
+ for (let layers of all) for (let layer of layers) quantizeWeights(layer);
280
+ for (let layers of all) calibrate(layers, data, inputScale2, inputUnit, input);
281
+ for (let k = data.samples - 1; k > 0; k--) {
282
+ let j = random.next() % (k + 1), t = order[k];
283
+ order[k] = order[j], order[j] = t;
284
+ }
285
+ let total = 0;
286
+ for (let start = 0; start < data.samples; start += batch) {
287
+ let end = Math.min(start + batch, data.samples), len = end - start;
288
+ for (let layers of all) begin(layers);
289
+ counts.fill(0);
290
+ for (let k = start; k < end; k++) {
291
+ let s = order[k];
292
+ for (let i = 0; i < inputs; i++) input[i] = quantizeInput(data.inputs[s * inputs + i], inputScale2, inputUnit);
293
+ for (let e = 0; e < count; e++)
294
+ forward(experts[e], input, true), errors[e] = halfSquared(lastOf(experts[e]).a, data, s * outputs);
295
+ forward(router, input, true), total = fr(total + errors[topOf(lastOf(router).a)]);
296
+ let best = assign(errors, counts, len, balance);
297
+ counts[best]++;
298
+ let top = lastOf(experts[best]).a;
299
+ for (let j = 0; j < outputs; j++) error[j] = fr(top[j] - fr(data.targets[s * outputs + j]));
300
+ backward(experts[best], input, error);
301
+ let z = lastOf(router).a;
302
+ for (let j = 0; j < count; j++) routeError[j] = fr(z[j] - (j === best ? 1 : 0));
303
+ backward(router, input, routeError);
304
+ }
305
+ step(router, fr(rate / len), momentum);
306
+ for (let e = 0; e < count; e++) step(experts[e], fr(rate / Math.max(counts[e], 1)), momentum);
307
+ }
308
+ loss[epoch] = fr(total / data.samples);
309
+ }
310
+ for (let layers of all) for (let layer of layers) quantizeWeights(layer);
311
+ for (let layers of all) calibrate(layers, data, inputScale2, inputUnit, input);
312
+ let blob = moeBlob(inputs, outputs, exportBlob(router, inputScale2, inputUnit), experts.map((e) => exportBlob(e, inputScale2, inputUnit))), net = parseMoe(blob, blob.length, inputs, outputs);
313
+ if (net === null) throw new GameError("invalid_argument", "the trained mixture did not pack into a valid file");
314
+ let usage = new Uint32Array(count), bits = new Float32Array(inputs), words = new Uint32Array(bits.buffer), out = new Uint32Array(outputs), view = new Float32Array(out.buffer), shipped = 0;
315
+ for (let s = 0; s < data.samples; s++) {
316
+ for (let i = 0; i < inputs; i++) bits[i] = data.inputs[s * inputs + i];
317
+ usage[evalMoeLane(net, words, 0, 1, out)]++;
318
+ for (let j = 0; j < outputs; j++) {
319
+ let e = fr(view[j] - fr(data.targets[s * outputs + j]));
320
+ shipped = fr(shipped + fr(fr(e * e) * (0.5)));
321
+ }
322
+ }
323
+ return { blob, loss, blobLoss: fr(shipped / data.samples), usage };
324
+ }
325
+
326
+ // src/game/kernel/import.ts
327
+ var fr2 = Math.fround, Q_MAX2 = 127, IMPORT_DEFAULT_SAMPLES = 256, IMPORT_DEFAULT_RANGE = 1, IMPORT_DEFAULT_SEED = 1, IMPORT_DEFAULT_MAX_DRIFT = 0.05, IMPORT_SUPPORTED_OPS = "Gemm, MatMul, Add, Relu, Tanh and Clip", WIRE_VARINT = 0, WIRE_FIXED64 = 1, WIRE_BYTES = 2, WIRE_FIXED32 = 5, WIRE_MASK = 7, WIRE_SHIFT = 8, VARINT_PAYLOAD = 127, VARINT_CONTINUE = 128, VARINT_STEP = 128, VARINT_MAX_BYTES = 10, F32_BYTES = 4, FIXED64_BYTES = 8, MODEL_GRAPH = 7, GRAPH_NODE = 1, GRAPH_INITIALIZER = 5, GRAPH_INPUT = 11, GRAPH_OUTPUT = 12, NODE_INPUT = 1, NODE_OUTPUT = 2, NODE_OP = 4, NODE_ATTRIBUTE = 5, ATTRIBUTE_NAME = 1, ATTRIBUTE_FLOAT = 2, ATTRIBUTE_INT = 3, TENSOR_DIMS = 1, TENSOR_TYPE = 2, TENSOR_FLOATS = 4, TENSOR_NAME = 8, TENSOR_RAW = 9, VALUE_NAME = 1, ONNX_FLOAT = 1, MATRIX_DIMS = 2, TANH_LIMIT = 9, TANH_RANGE = 1, decoder = new TextDecoder("utf-8", { fatal: true }), ImportError = class extends GameError {
328
+ constructor(message2) {
329
+ super("invalid_argument", message2), this.name = "ImportError";
330
+ }
331
+ };
332
+ function malformed(what) {
333
+ throw new ImportError(`the model file is malformed: ${what}`);
334
+ }
335
+ function unsupported(what) {
336
+ throw new ImportError(`${what}; the importer reads ${IMPORT_SUPPORTED_OPS}`);
337
+ }
338
+ function shape(what) {
339
+ throw new ImportError(what);
340
+ }
341
+ function varint(bytes, at) {
342
+ let value = 0, scale = 1;
343
+ for (let n = 0; n < (10); n++) {
344
+ at.k >= bytes.length && malformed("a number runs past the end");
345
+ let byte = bytes[at.k++];
346
+ if (value += (byte & (127)) * scale, (byte & (128)) === 0) return value;
347
+ scale *= (128);
348
+ }
349
+ malformed("a number is too long");
350
+ }
351
+ function take(bytes, at, len) {
352
+ (len < 0 || at.k + len > bytes.length) && malformed("a field runs past the end");
353
+ let out = bytes.subarray(at.k, at.k + len);
354
+ return at.k += len, out;
355
+ }
356
+ function fields(bytes) {
357
+ let out = [], at = { k: 0 };
358
+ for (; at.k < bytes.length; ) {
359
+ let key = varint(bytes, at), number = Math.floor(key / (8));
360
+ switch (key % (8) & (7)) {
361
+ case (0):
362
+ out.push({ number, wire: { t: "varint", v: varint(bytes, at) } });
363
+ break;
364
+ case (1):
365
+ take(bytes, at, (8)), out.push({ number, wire: { t: "fixed64" } });
366
+ break;
367
+ case (2):
368
+ out.push({ number, wire: { t: "bytes", b: take(bytes, at, varint(bytes, at)) } });
369
+ break;
370
+ case (5): {
371
+ let b = take(bytes, at, (4));
372
+ out.push({ number, wire: { t: "fixed32", w: new DataView(b.buffer, b.byteOffset, (4)).getUint32(0, true) } });
373
+ break;
374
+ }
375
+ default:
376
+ malformed("a field has an unknown wire type");
377
+ }
378
+ }
379
+ return out;
380
+ }
381
+ function text(field) {
382
+ field.wire.t !== "bytes" && malformed("a name is not a string");
383
+ try {
384
+ return decoder.decode(field.wire.b);
385
+ } catch {
386
+ malformed("a name is not UTF-8");
387
+ }
388
+ }
389
+ function message(field) {
390
+ return field.wire.t !== "bytes" && malformed("a message field is not length-delimited"), field.wire.b;
391
+ }
392
+ function floatBits(word) {
393
+ return new Float32Array(Uint32Array.of(word).buffer)[0];
394
+ }
395
+ function floats(b) {
396
+ let view = new DataView(b.buffer, b.byteOffset, b.byteLength), out = [];
397
+ for (let k = 0; k + (4) <= b.byteLength; k += (4)) out.push(view.getFloat32(k, true));
398
+ return out;
399
+ }
400
+ function tensor(bytes) {
401
+ let name = "", dims = [], values = [], kind = (1), raw = null;
402
+ for (let f of fields(bytes))
403
+ if (f.number === (1) && f.wire.t === "varint") dims.push(f.wire.v);
404
+ else if (f.number === (1) && f.wire.t === "bytes") {
405
+ let at = { k: 0 };
406
+ for (; at.k < f.wire.b.length; ) dims.push(varint(f.wire.b, at));
407
+ } else f.number === (2) && f.wire.t === "varint" ? kind = f.wire.v : f.number === (4) && f.wire.t === "fixed32" ? values.push(floatBits(f.wire.w)) : f.number === (4) && f.wire.t === "bytes" ? values.push(...floats(f.wire.b)) : f.number === (8) ? name = text(f) : f.number === (9) && f.wire.t === "bytes" && (raw = f.wire.b);
408
+ return kind !== (1) && unsupported(`tensor ${name} is not float32`), raw !== null && (raw.byteLength % (4) !== 0 && malformed("raw tensor data is not whole float32 values"), values = floats(raw)), dims.reduce((a, b) => a * b, 1) !== values.length && shape(`tensor ${name} holds ${values.length} values for dimensions [${dims.join(", ")}]`), [name, { dims, values: Float32Array.from(values) }];
409
+ }
410
+ function node(bytes) {
411
+ let n = { inputs: [], outputs: [], op: "", floats: /* @__PURE__ */ new Map(), ints: /* @__PURE__ */ new Map() };
412
+ for (let f of fields(bytes))
413
+ if (f.number === (1)) n.inputs.push(text(f));
414
+ else if (f.number === (2)) n.outputs.push(text(f));
415
+ else if (f.number === (4)) n.op = text(f);
416
+ else if (f.number === (5)) {
417
+ let name = "", float = null, int = null;
418
+ for (let a of fields(message(f)))
419
+ a.number === (1) ? name = text(a) : a.number === (2) && a.wire.t === "fixed32" ? float = floatBits(a.wire.w) : a.number === (3) && a.wire.t === "varint" && (int = a.wire.v);
420
+ float !== null && n.floats.set(name, float), int !== null && n.ints.set(name, int);
421
+ }
422
+ return n;
423
+ }
424
+ function clipActivation(low, high) {
425
+ if (low === 0 && high === Number.POSITIVE_INFINITY) return { kind: "relu" };
426
+ if (Number.isFinite(high) && high > 0 && (low === 0 || low === -high)) return { kind: "clip", low, high };
427
+ unsupported(`Clip(${low}, ${high}) has no int8 form; clip at 0 and a positive bound, or at -b and b`);
428
+ }
429
+ function readOnnx(bytes) {
430
+ let graphField = fields(bytes).find((f) => f.number === (7)) ?? malformed("no graph"), nodes = [], initializers = /* @__PURE__ */ new Map(), inputs = [], outputs = [];
431
+ for (let f of fields(message(graphField)))
432
+ if (f.number === (1)) nodes.push(node(message(f)));
433
+ else if (f.number === (5)) {
434
+ let [name, t] = tensor(message(f));
435
+ initializers.set(name, t);
436
+ } else if (f.number === (11) || f.number === (12)) {
437
+ let nameField = fields(message(f)).find((v) => v.number === (1)), name = nameField === void 0 ? "" : text(nameField);
438
+ (f.number === (11) ? inputs : outputs).push(name);
439
+ }
440
+ let sources = inputs.filter((n) => !initializers.has(n));
441
+ (sources.length !== 1 || outputs.length !== 1) && unsupported(`the graph has ${sources.length} inputs and ${outputs.length} outputs; one of each is supported (put memory columns at the end of both)`);
442
+ let matrix = (name) => {
443
+ name === void 0 && malformed("a layer has no weights");
444
+ let t = initializers.get(name) ?? unsupported(`weights ${name} are computed, not constant`);
445
+ return t.dims.length !== (2) && shape(`weights ${name} have dimensions [${t.dims.join(", ")}], not a matrix`), t;
446
+ }, scalar = (name) => {
447
+ if (name === void 0 || name === "") return null;
448
+ let t = initializers.get(name);
449
+ return (t === void 0 || t.values.length !== 1) && unsupported(`Clip bound ${name} is not a constant scalar`), t.values[0];
450
+ }, layers = [], current = sources[0], awaitingBias = false, activated = false;
451
+ for (let n of nodes) {
452
+ let reads = () => {
453
+ n.inputs[0] !== current && unsupported(`${n.op} reads ${n.inputs[0]}, not the running layer chain ${current}; only a single chain of layers is supported`);
454
+ }, output = () => n.outputs[0] ?? malformed("a node has no output");
455
+ if (n.op === "Gemm" || n.op === "MatMul") {
456
+ reads();
457
+ let gemm = n.op === "Gemm";
458
+ gemm && (n.ints.get("transA") ?? 0) !== 0 && unsupported("Gemm with transA");
459
+ let transposed = gemm && (n.ints.get("transB") ?? 0) !== 0, w = matrix(n.inputs[1]), [ins, outs] = transposed ? [w.dims[1], w.dims[0]] : [w.dims[0], w.dims[1]], prev = layers[layers.length - 1];
460
+ prev !== void 0 && prev.outputs !== ins && shape(`a layer takes ${ins} inputs after one with ${prev.outputs} outputs`);
461
+ let alpha = gemm ? fr2(n.floats.get("alpha") ?? 1) : 1, weights = new Float32Array(ins * outs);
462
+ for (let j = 0; j < outs; j++)
463
+ for (let i = 0; i < ins; i++) {
464
+ let v = transposed ? w.values[j * ins + i] : w.values[i * outs + j];
465
+ weights[j * ins + i] = alpha === 1 ? v : fr2(v * alpha);
466
+ }
467
+ let bias = new Float32Array(outs), c = gemm ? n.inputs[2] : void 0;
468
+ if (c !== void 0 && c !== "") {
469
+ let t = initializers.get(c) ?? unsupported(`bias ${c} is computed, not constant`);
470
+ t.values.length !== outs && shape(`bias ${c} holds ${t.values.length} values for ${outs} outputs`);
471
+ let beta = fr2(n.floats.get("beta") ?? 1);
472
+ for (let j = 0; j < outs; j++) bias[j] = beta === 1 ? t.values[j] : fr2(t.values[j] * beta);
473
+ }
474
+ layers.push({ inputs: ins, outputs: outs, weights, bias, activation: { kind: "linear" } }), awaitingBias = !gemm, activated = false, current = output();
475
+ } else if (n.op === "Add") {
476
+ let layer = awaitingBias ? layers[layers.length - 1] : void 0;
477
+ layer === void 0 && unsupported("Add that is not the bias of a MatMul");
478
+ let other = n.inputs.find((i) => i !== current) ?? unsupported("Add without a constant bias");
479
+ n.inputs.includes(current) || unsupported("Add that is off the layer chain");
480
+ let t = initializers.get(other) ?? unsupported(`bias ${other} is computed, not constant`);
481
+ t.values.length !== layer.outputs && shape(`bias ${other} holds ${t.values.length} values for ${layer.outputs} outputs`), layer.bias.set(t.values), awaitingBias = false, current = output();
482
+ } else if (n.op === "Relu" || n.op === "Tanh" || n.op === "Clip") {
483
+ reads();
484
+ let layer = activated ? void 0 : layers[layers.length - 1];
485
+ layer === void 0 && unsupported(`${n.op} that does not follow a layer`), n.op === "Relu" ? layer.activation = { kind: "relu" } : n.op === "Tanh" ? layer.activation = { kind: "tanh" } : layer.activation = clipActivation(scalar(n.inputs[1]) ?? n.floats.get("min") ?? Number.NEGATIVE_INFINITY, scalar(n.inputs[2]) ?? n.floats.get("max") ?? Number.POSITIVE_INFINITY), activated = true, awaitingBias = false, current = output();
486
+ } else unsupported(`operator ${n.op} is not supported`);
487
+ }
488
+ current !== outputs[0] && unsupported(`the graph output ${outputs[0]} is not the end of the layer chain ${current}`);
489
+ let net = { layers };
490
+ return checkNet(net), net;
491
+ }
492
+ var inputsOf = (net) => net.layers[0]?.inputs ?? 0, outputsOf = (net) => net.layers[net.layers.length - 1]?.outputs ?? 0;
493
+ function checkNet(net) {
494
+ let count = net.layers.length;
495
+ (count === 0 || count > MLP_MAX_LAYERS) && shape(`a network has 1 to ${MLP_MAX_LAYERS} layers, this one ${count}`), net.layers.forEach((layer, l) => {
496
+ let last = l + 1 === count;
497
+ (layer.inputs === 0 || layer.inputs > MLP_MAX_WIDTH || layer.outputs === 0 || layer.outputs > (last ? MLP_MAX_OUTPUTS : MLP_MAX_WIDTH)) && shape(`layer ${l} is ${layer.inputs}x${layer.outputs}; inputs and hidden layers are at most ${MLP_MAX_WIDTH} wide and outputs at most ${MLP_MAX_OUTPUTS}`), (layer.weights.length !== layer.inputs * layer.outputs || layer.bias.length !== layer.outputs) && shape(`layer ${l} has ${layer.weights.length} weights and ${layer.bias.length} biases for ${layer.inputs}x${layer.outputs}`), l > 0 && net.layers[l - 1].outputs !== layer.inputs && shape(`layer ${l} takes ${layer.inputs} inputs after ${net.layers[l - 1].outputs} outputs`), last && layer.activation.kind !== "linear" && layer.activation.kind !== "relu" && unsupported("a Clip or Tanh on the last layer has no int8 form; clamp in the kernel after mlp()"), [...layer.weights, ...layer.bias].some((v) => !Number.isFinite(v)) && shape(`layer ${l} holds a weight that is not finite`);
498
+ });
499
+ }
500
+ function generatedSamples(inputs, count = (256), range = (1), seed = (1)) {
501
+ let random = new Random(seed), out = new Float32Array(inputs * count), r = fr2(range);
502
+ for (let k = 0; k < out.length; k++) out[k] = fr2(fr2(fr2(random.unit() * 2) - 1) * r);
503
+ return out;
504
+ }
505
+ function tanh(x) {
506
+ let c = clamp(x, -(9), (9)), e = exp(fr2(2 * c));
507
+ return fr2(fr2(e - 1) / fr2(e + 1));
508
+ }
509
+ function deployed(y, a) {
510
+ switch (a.kind) {
511
+ case "linear":
512
+ return y;
513
+ case "relu":
514
+ return y > 0 ? y : 0;
515
+ case "clip":
516
+ return clamp(y, a.low, a.high);
517
+ case "tanh":
518
+ return clamp(y, -(1), (1));
519
+ }
520
+ }
521
+ function floatActivation(y, a) {
522
+ return a.kind === "tanh" ? tanh(y) : deployed(y, a);
523
+ }
524
+ function layerForward(layer, weights, input, out, activate) {
525
+ for (let j = 0; j < layer.outputs; j++) {
526
+ let acc = layer.bias[j], row = j * layer.inputs;
527
+ for (let i = 0; i < layer.inputs; i++) acc = fr2(acc + fr2(weights[row + i] * input[i]));
528
+ out[j] = activate(acc);
529
+ }
530
+ }
531
+ function floatEval(net, input, out) {
532
+ let a = new Float32Array(MLP_MAX_WIDTH), b = new Float32Array(MLP_MAX_WIDTH);
533
+ for (let i = 0; i < input.length; i++) a[i] = input[i];
534
+ for (let layer of net.layers) {
535
+ layerForward(layer, layer.weights, a, b, (y) => floatActivation(y, layer.activation));
536
+ let t = a;
537
+ a = b, b = t;
538
+ }
539
+ out.set(a.subarray(0, outputsOf(net)));
540
+ }
541
+ function fixedScale(a) {
542
+ return a.kind === "clip" ? fr2(a.high / (127)) : a.kind === "tanh" ? fr2((1) / (127)) : null;
543
+ }
544
+ function intActivation(a) {
545
+ return a.kind === "relu" || a.kind === "clip" && a.low === 0 ? MLP_ACT_RELU : MLP_ACT_LINEAR;
546
+ }
547
+ function quantizeNet(net, index, samples, scale, reports) {
548
+ let unit0 = fr2(1 / scale), inputs = inputsOf(net), rows = samples.length / inputs, wScales = net.layers.map((l) => scaleOf(maxAbs(l.weights))), wq = net.layers.map((l, k) => Float32Array.from(l.weights, (w) => fr2(clamp(roundHalfEven(fr2(w / wScales[k])), -(127), (127)) * wScales[k]))), peaks = new Float32Array(net.layers.length), a = new Float32Array(MLP_MAX_WIDTH), b = new Float32Array(MLP_MAX_WIDTH);
549
+ for (let r = 0; r < rows; r++) {
550
+ for (let i = 0; i < inputs; i++) a[i] = quantizeInput(samples[r * inputs + i], scale, unit0);
551
+ net.layers.forEach((layer, l) => {
552
+ layerForward(layer, wq[l], a, b, (y) => deployed(y, layer.activation));
553
+ let peak = peaks[l];
554
+ for (let j = 0; j < layer.outputs; j++) {
555
+ let m = layer.activation.kind === "relu" ? b[j] : Math.abs(b[j]);
556
+ m > peak && (peak = m);
557
+ }
558
+ peaks[l] = peak;
559
+ let t = a;
560
+ a = b, b = t;
561
+ });
562
+ }
563
+ let count = net.layers.length, specs = [], unit = unit0;
564
+ return net.layers.forEach((layer, l) => {
565
+ let last = l + 1 === count, accScale = fr2(unit * wScales[l]), weights = Array.from(layer.weights, (v) => clamp(roundHalfEven(fr2(v / wScales[l])), -(127), (127))), bias = Array.from(layer.bias, (v) => clamp(roundHalfEven(fr2(v / accScale)), -MLP_ACC_LIMIT, MLP_ACC_LIMIT)), activation = intActivation(layer.activation), spec, aScale;
566
+ if (last)
567
+ spec = { outputs: layer.outputs, activation, multiplier: 0, shift: 0, zero: 0, scale: accScale, bias, weights }, aScale = accScale;
568
+ else {
569
+ aScale = fixedScale(layer.activation) ?? scaleOf(peaks[l]);
570
+ let [multiplier, shift] = shiftFor(accScale / aScale);
571
+ spec = { outputs: layer.outputs, activation, multiplier, shift, zero: 0, scale: aScale, bias, weights };
572
+ }
573
+ reports.push({ net: index, layer: l, inputs: layer.inputs, outputs: layer.outputs, activation, weightScale: wScales[l], activationScale: aScale, multiplier: spec.multiplier, shift: spec.shift }), specs.push(spec), unit = aScale;
574
+ }), mlpBlob(inputs, scale, 0, specs);
575
+ }
576
+ function inputScale(samples) {
577
+ let peak = maxAbs(samples);
578
+ return peak > 0 ? fr2((127) / peak) : 1;
579
+ }
580
+ function drift(rows, outputs, bound, row) {
581
+ let float = new Float32Array(outputs), int = new Uint32Array(outputs), view = new Float32Array(int.buffer), maxError = 0, peak = 0;
582
+ for (let r = 0; r < rows; r++) {
583
+ row(r, float, int);
584
+ for (let j = 0; j < outputs; j++) {
585
+ let e = Math.abs(fr2(view[j] - float[j]));
586
+ maxError = Number.isNaN(e) ? Number.POSITIVE_INFINITY : e > maxError ? e : maxError;
587
+ let m = Math.abs(float[j]);
588
+ m > peak && (peak = m);
589
+ }
590
+ }
591
+ let relative = peak > 0 ? fr2(maxError / peak) : maxError;
592
+ if (Number.isNaN(relative) || relative > bound) throw new ImportError(`the int8 network drifts ${relative} from the float model (largest error over the largest output), over the ${bound} bound`);
593
+ return { samples: rows, maxError, peak, relative, bound };
594
+ }
595
+ function rowsOf(samples, inputs) {
596
+ return (inputs === 0 || samples.length === 0 || samples.length % inputs !== 0) && shape(`samples hold ${samples.length} numbers, not whole rows of ${inputs} inputs`), samples.length / inputs;
597
+ }
598
+ function memoryFits(memory, inputs, outputs) {
599
+ memory > 0 && (memory > inputs || memory > outputs || memory < (2) || memory > (4)) && shape(`${memory} memory columns do not fit ${inputs} inputs and ${outputs} outputs (memory is ${(2)} to ${(4)} columns at the end of both)`);
600
+ }
601
+ function samplesFor(inputs, options) {
602
+ return options.samples ?? generatedSamples(inputs);
603
+ }
604
+ function importMlp(net, options = {}) {
605
+ checkNet(net);
606
+ let inputs = inputsOf(net), outputs = outputsOf(net), memory = options.memory ?? 0;
607
+ memoryFits(memory, inputs, outputs);
608
+ let samples = samplesFor(inputs, options), rows = rowsOf(samples, inputs), bound = fr2(options.maxDrift ?? (0.05)), scale = inputScale(samples), layers = [], blob = quantizeNet(net, 0, samples, scale, layers), parsed = parseMlp(blob, blob.length, inputs, outputs) ?? shape("the quantized network did not pack"), bits = new Float32Array(inputs), words = new Uint32Array(bits.buffer), report = drift(rows, outputs, bound, (r, float, int) => {
609
+ let row = samples.subarray(r * inputs, (r + 1) * inputs);
610
+ floatEval(net, row, float), bits.set(row), evalMlp(parsed, words, int);
611
+ });
612
+ return { blob, inputScale: scale, layers, drift: report, memory };
613
+ }
614
+ function importMoe(router, experts, options = {}) {
615
+ checkNet(router), (experts.length < MOE_MIN_EXPERTS || experts.length > MOE_MAX_EXPERTS || outputsOf(router) !== experts.length) && shape(`a mixture has ${MOE_MIN_EXPERTS} to ${MOE_MAX_EXPERTS} experts and a router with one output each; this one has ${experts.length} experts and ${outputsOf(router)} router outputs`);
616
+ let inputs = inputsOf(router), outputs = outputsOf(experts[0]);
617
+ experts.forEach((expert, e) => {
618
+ checkNet(expert), (inputsOf(expert) !== inputs || outputsOf(expert) !== outputs) && shape(`expert ${e} is ${inputsOf(expert)}->${outputsOf(expert)}, the mixture ${inputs}->${outputs}`);
619
+ });
620
+ let memory = options.memory ?? 0;
621
+ memoryFits(memory, inputs, outputs);
622
+ let samples = samplesFor(inputs, options), rows = rowsOf(samples, inputs), bound = fr2(options.maxDrift ?? (0.05)), scale = inputScale(samples), layers = [], routerWords = quantizeNet(router, 0, samples, scale, layers), parts = experts.map((x, e) => quantizeNet(x, e + 1, samples, scale, layers)), blob = moeBlob(inputs, outputs, routerWords, parts), parsed = parseMoe(blob, blob.length, inputs, outputs) ?? shape("the quantized mixture did not pack"), bits = new Float32Array(inputs), words = new Uint32Array(bits.buffer), route = new Float32Array(experts.length), report = drift(rows, outputs, bound, (r, float, int) => {
623
+ let row = samples.subarray(r * inputs, (r + 1) * inputs);
624
+ floatEval(router, row, route);
625
+ let best = 0;
626
+ for (let j = 1; j < route.length; j++) route[j] > route[best] && (best = j);
627
+ floatEval(experts[best], row, float), bits.set(row), evalMoeLane(parsed, words, 0, 1, int);
628
+ });
629
+ return { blob, inputScale: scale, layers, drift: report, memory };
630
+ }
631
+ function plainNet(layers) {
632
+ let net = { layers: layers.map((layer, l) => {
633
+ let outputs = layer.weights.length, inputs = layer.weights[0]?.length ?? 0;
634
+ layer.weights.some((row) => row.length !== inputs) && shape(`layer ${l} has rows of different lengths`);
635
+ let activation = layer.activation;
636
+ return {
637
+ inputs,
638
+ outputs,
639
+ weights: Float32Array.from(layer.weights.flat()),
640
+ bias: Float32Array.from(layer.bias ?? new Array(outputs).fill(0)),
641
+ activation: activation === void 0 || activation === "linear" ? { kind: "linear" } : activation === "relu" ? { kind: "relu" } : activation === "tanh" ? { kind: "tanh" } : clipActivation(activation.clip[0], activation.clip[1])
642
+ };
643
+ }) };
644
+ return checkNet(net), net;
645
+ }
646
+
647
+ // src/game/render/helpers.ts
648
+ var TAU = Math.PI * 2, BOX_EDGES = 12, BOX_CORNERS = 8, AXES_SEGMENTS = 3, ARROW_SEGMENTS = 5, ARROW_HEAD_SPOKES = 4, DEFAULT_HEAD_LENGTH = 0.2, DEFAULT_HEAD_WIDTH = 0.1, DEFAULT_CIRCLE_SEGMENTS = 32, SPHERE_CIRCLES = 3;
649
+ var FRUSTUM_EDGES = 12, FRUSTUM_CONE = 4, PLANE_SEGMENTS = 6, DIRECTIONAL_SEGMENTS = 5, SPOT_SPOKES = 5, HEMISPHERE_SEGMENTS = 16, AUDIO_CONE_SPOKES = 8, NEAR_FAR_NDC = 1, PARALLEL_LIMIT = 0.99, MATRIX_FLOATS = 16, AXIS_X_COLOR = 16726832, AXIS_Y_COLOR = 3458905, AXIS_Z_COLOR = 689407, GRID_CENTER_COLOR = 4473924, GRID_COLOR = 8947848, HELPER_COLOR = 16776960, FRUSTUM_COLOR = 16755200, SKELETON_COLOR = 65535, NORMAL_COLOR = 16711935, BOX_EDGE_CORNERS = new Uint8Array([0, 1, 1, 3, 3, 2, 2, 0, 4, 5, 5, 7, 7, 6, 6, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
650
+ function srgbToLinear(channel) {
651
+ return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
652
+ }
653
+ var LineWriter = class {
654
+ constructor(capacity) {
655
+ this.count = 0;
656
+ this.dropped = 0;
657
+ this.hex = -1;
658
+ this.r = 1;
659
+ this.g = 1;
660
+ this.b = 1;
661
+ this.a = 1;
662
+ this.corners = new Float64Array((8) * 3);
663
+ this.basis = new Float64Array(6);
664
+ this.matrix = new Float64Array((16));
665
+ this.transformed = false;
666
+ this.capacity = capacity, this.positions = new Float32Array(capacity * 2 * 3), this.colors = new Float32Array(capacity * 2 * 4);
667
+ }
668
+ get vertexCount() {
669
+ return this.count * 2;
670
+ }
671
+ clear() {
672
+ this.count = 0, this.dropped = 0;
673
+ }
674
+ color(hex, alpha = 1) {
675
+ return this.a = alpha, hex === this.hex ? this : (this.hex = hex, this.r = srgbToLinear((hex >> 16 & 255) / 255), this.g = srgbToLinear((hex >> 8 & 255) / 255), this.b = srgbToLinear((hex & 255) / 255), this);
676
+ }
677
+ setMatrix(m, mo = 0) {
678
+ if (m === null)
679
+ return this.transformed = false, this;
680
+ for (let i = 0; i < (16); i++) this.matrix[i] = m[mo + i];
681
+ return this.transformed = true, this;
682
+ }
683
+ segment(ax, ay, az, bx, by, bz) {
684
+ if (this.count >= this.capacity)
685
+ return this.dropped++, false;
686
+ if (this.transformed) {
687
+ let m = this.matrix, tax = m[0] * ax + m[4] * ay + m[8] * az + m[12], tay = m[1] * ax + m[5] * ay + m[9] * az + m[13], taz = m[2] * ax + m[6] * ay + m[10] * az + m[14], tbx = m[0] * bx + m[4] * by + m[8] * bz + m[12], tby = m[1] * bx + m[5] * by + m[9] * bz + m[13], tbz = m[2] * bx + m[6] * by + m[10] * bz + m[14];
688
+ ax = tax, ay = tay, az = taz, bx = tbx, by = tby, bz = tbz;
689
+ }
690
+ let v = this.count * 2, p = this.positions, o = v * 3;
691
+ p[o] = ax, p[o + 1] = ay, p[o + 2] = az, p[o + 3] = bx, p[o + 4] = by, p[o + 5] = bz;
692
+ let c = this.colors, q = v * 4;
693
+ return c[q] = this.r, c[q + 1] = this.g, c[q + 2] = this.b, c[q + 3] = this.a, c[q + 4] = this.r, c[q + 5] = this.g, c[q + 6] = this.b, c[q + 7] = this.a, this.count++, true;
694
+ }
695
+ axes(m, mo, size) {
696
+ let ox = m ? m[mo + 12] : 0, oy = m ? m[mo + 13] : 0, oz = m ? m[mo + 14] : 0;
697
+ for (let axis = 0; axis < (3); axis++) {
698
+ let c = mo + axis * 4, dx = m ? m[c] : axis === 0 ? 1 : 0, dy = m ? m[c + 1] : axis === 1 ? 1 : 0, dz = m ? m[c + 2] : axis === 2 ? 1 : 0;
699
+ this.color(axis === 0 ? (16726832) : axis === 1 ? (3458905) : (689407)), this.segment(ox, oy, oz, ox + dx * size, oy + dy * size, oz + dz * size);
700
+ }
701
+ return this;
702
+ }
703
+ axesAt(px, py, pz, qx, qy, qz, qw, size) {
704
+ for (let axis = 0; axis < (3); axis++) {
705
+ let vx = axis === 0 ? 1 : 0, vy = axis === 1 ? 1 : 0, vz = axis === 2 ? 1 : 0, ix = qw * vx + qy * vz - qz * vy, iy = qw * vy + qz * vx - qx * vz, iz = qw * vz + qx * vy - qy * vx, iw = -qx * vx - qy * vy - qz * vz, rx = ix * qw + iw * -qx + iy * -qz - iz * -qy, ry = iy * qw + iw * -qy + iz * -qx - ix * -qz, rz = iz * qw + iw * -qz + ix * -qy - iy * -qx;
706
+ this.color(axis === 0 ? (16726832) : axis === 1 ? (3458905) : (689407)), this.segment(px, py, pz, px + rx * size, py + ry * size, pz + rz * size);
707
+ }
708
+ return this;
709
+ }
710
+ box(minX, minY, minZ, maxX, maxY, maxZ, m = null, mo = 0) {
711
+ let k = this.corners;
712
+ for (let i = 0; i < (8); i++) {
713
+ let x = i & 1 ? maxX : minX, y = i & 2 ? maxY : minY, z = i & 4 ? maxZ : minZ, o = i * 3;
714
+ m ? (k[o] = m[mo] * x + m[mo + 4] * y + m[mo + 8] * z + m[mo + 12], k[o + 1] = m[mo + 1] * x + m[mo + 5] * y + m[mo + 9] * z + m[mo + 13], k[o + 2] = m[mo + 2] * x + m[mo + 6] * y + m[mo + 10] * z + m[mo + 14]) : (k[o] = x, k[o + 1] = y, k[o + 2] = z);
715
+ }
716
+ return this.cornerEdges();
717
+ }
718
+ frustum(inverseViewProjection, io, apex = null) {
719
+ let k = this.corners, m = inverseViewProjection;
720
+ for (let i = 0; i < (8); i++) {
721
+ let x = i & 1 ? (1) : -(1), y = i & 2 ? (1) : -(1), z = i & 4 ? (1) : -(1), w = m[io + 3] * x + m[io + 7] * y + m[io + 11] * z + m[io + 15], inv = w !== 0 ? 1 / w : 1, o = i * 3;
722
+ k[o] = (m[io] * x + m[io + 4] * y + m[io + 8] * z + m[io + 12]) * inv, k[o + 1] = (m[io + 1] * x + m[io + 5] * y + m[io + 9] * z + m[io + 13]) * inv, k[o + 2] = (m[io + 2] * x + m[io + 6] * y + m[io + 10] * z + m[io + 14]) * inv;
723
+ }
724
+ if (this.cornerEdges(), apex)
725
+ for (let i = 0; i < (4); i++) {
726
+ let o = i * 3;
727
+ this.segment(apex[0], apex[1], apex[2], k[o], k[o + 1], k[o + 2]);
728
+ }
729
+ return this;
730
+ }
731
+ circle(cx, cy, cz, radius, nx, ny, nz, segments = (32)) {
732
+ let b = this.basisFor(nx, ny, nz), px = cx + b[0] * radius, py = cy + b[1] * radius, pz = cz + b[2] * radius;
733
+ for (let s = 1; s <= segments; s++) {
734
+ let t = s / segments * TAU, c = Math.cos(t) * radius, sn = Math.sin(t) * radius, x = cx + b[0] * c + b[3] * sn, y = cy + b[1] * c + b[4] * sn, z = cz + b[2] * c + b[5] * sn;
735
+ this.segment(px, py, pz, x, y, z), px = x, py = y, pz = z;
736
+ }
737
+ return this;
738
+ }
739
+ sphere(cx, cy, cz, radius, segments = (32)) {
740
+ return this.circle(cx, cy, cz, radius, 1, 0, 0, segments), this.circle(cx, cy, cz, radius, 0, 1, 0, segments), this.circle(cx, cy, cz, radius, 0, 0, 1, segments);
741
+ }
742
+ cross(x, y, z, size) {
743
+ let h = size * 0.5;
744
+ return this.segment(x - h, y, z, x + h, y, z), this.segment(x, y - h, z, x, y + h, z), this.segment(x, y, z - h, x, y, z + h), this;
745
+ }
746
+ arrow(ox, oy, oz, dx, dy, dz, length, headLength = length * (0.2), headWidth = length * (0.1)) {
747
+ let len = Math.sqrt(dx * dx + dy * dy + dz * dz);
748
+ if (len === 0) return this;
749
+ let ux = dx / len, uy = dy / len, uz = dz / len, tx = ox + ux * length, ty = oy + uy * length, tz = oz + uz * length;
750
+ this.segment(ox, oy, oz, tx, ty, tz);
751
+ let b = this.basisFor(ux, uy, uz), bx = tx - ux * headLength, by = ty - uy * headLength, bz = tz - uz * headLength, r = headWidth * 0.5;
752
+ for (let s = 0; s < (4); s++) {
753
+ let t = s / (4) * TAU, c = Math.cos(t) * r, sn = Math.sin(t) * r;
754
+ this.segment(tx, ty, tz, bx + b[0] * c + b[3] * sn, by + b[1] * c + b[4] * sn, bz + b[2] * c + b[5] * sn);
755
+ }
756
+ return this;
757
+ }
758
+ grid(size, divisions, centerColor = (4473924), gridColor = (8947848), y = 0) {
759
+ let step2 = size / divisions, half = size / 2, center = divisions / 2;
760
+ for (let i = 0; i <= divisions; i++) {
761
+ let k = -half + i * step2;
762
+ this.color(i === center ? centerColor : gridColor), this.segment(-half, y, k, half, y, k), this.segment(k, y, -half, k, y, half);
763
+ }
764
+ return this;
765
+ }
766
+ polarGrid(radius, sectors, rings, divisions, sectorColor = (4473924), ringColor = (8947848), y = 0) {
767
+ this.color(sectorColor);
768
+ for (let i = 0; i < sectors; i++) {
769
+ let t = i / sectors * TAU;
770
+ this.segment(0, y, 0, Math.sin(t) * radius, y, Math.cos(t) * radius);
771
+ }
772
+ this.color(ringColor);
773
+ for (let i = 1; i <= rings; i++) this.circle(0, y, 0, radius * i / rings, 0, 1, 0, divisions);
774
+ return this;
775
+ }
776
+ plane(nx, ny, nz, constant, size) {
777
+ let len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1, ux = nx / len, uy = ny / len, uz = nz / len, cx = -ux * constant, cy = -uy * constant, cz = -uz * constant, b = this.basisFor(ux, uy, uz), h = size * 0.5, ax = b[0] * h, ay = b[1] * h, az = b[2] * h, vx = b[3] * h, vy = b[4] * h, vz = b[5] * h;
778
+ return this.segment(cx - ax - vx, cy - ay - vy, cz - az - vz, cx + ax - vx, cy + ay - vy, cz + az - vz), this.segment(cx + ax - vx, cy + ay - vy, cz + az - vz, cx + ax + vx, cy + ay + vy, cz + az + vz), this.segment(cx + ax + vx, cy + ay + vy, cz + az + vz, cx - ax + vx, cy - ay + vy, cz - az + vz), this.segment(cx - ax + vx, cy - ay + vy, cz - az + vz, cx - ax - vx, cy - ay - vy, cz - az - vz), this.segment(cx - ax - vx, cy - ay - vy, cz - az - vz, cx + ax + vx, cy + ay + vy, cz + az + vz), this.segment(cx, cy, cz, cx + ux * h, cy + uy * h, cz + uz * h), this;
779
+ }
780
+ path(points, count, closed = false, stride = 3) {
781
+ for (let i = 1; i < count; i++) {
782
+ let a = (i - 1) * stride, b = i * stride;
783
+ this.segment(points[a], points[a + 1], points[a + 2], points[b], points[b + 1], points[b + 2]);
784
+ }
785
+ if (closed && count > 2) {
786
+ let b = (count - 1) * stride;
787
+ this.segment(points[b], points[b + 1], points[b + 2], points[0], points[1], points[2]);
788
+ }
789
+ return this;
790
+ }
791
+ skeleton(parents, worlds, count, offset = 0) {
792
+ for (let i = 0; i < count; i++) {
793
+ let parent = parents[i];
794
+ if (parent < 0 || parent >= count) continue;
795
+ let c = offset + i * 16, p = offset + parent * 16;
796
+ this.segment(worlds[p + 12], worlds[p + 13], worlds[p + 14], worlds[c + 12], worlds[c + 13], worlds[c + 14]);
797
+ }
798
+ return this;
799
+ }
800
+ normals(positions, normals, vertices, size) {
801
+ for (let i = 0; i < vertices; i++) {
802
+ let o = i * 3, x = positions[o], y = positions[o + 1], z = positions[o + 2];
803
+ this.segment(x, y, z, x + normals[o] * size, y + normals[o + 1] * size, z + normals[o + 2] * size);
804
+ }
805
+ return this;
806
+ }
807
+ directionalLight(size, length) {
808
+ let h = size * 0.5;
809
+ return this.segment(-h, h, 0, h, h, 0), this.segment(h, h, 0, h, -h, 0), this.segment(h, -h, 0, -h, -h, 0), this.segment(-h, -h, 0, -h, h, 0), this.segment(0, 0, 0, 0, 0, -length), this;
810
+ }
811
+ spotLight(angle, distance, segments = (32)) {
812
+ let radius = Math.tan(angle) * distance;
813
+ this.segment(0, 0, 0, 0, 0, -distance);
814
+ for (let s = 0; s < (5) - 1; s++) {
815
+ let t = s / ((5) - 1) * TAU;
816
+ this.segment(0, 0, 0, Math.cos(t) * radius, Math.sin(t) * radius, -distance);
817
+ }
818
+ return this.circle(0, 0, -distance, radius, 0, 0, 1, segments);
819
+ }
820
+ hemisphere(size, skyColor, groundColor) {
821
+ return this.color(skyColor), this.circle(0, 0, 0, size, 0, 1, 0, (16)), this.halfCircle(size, 1), this.color(groundColor), this.halfCircle(size, -1);
822
+ }
823
+ audioCone(innerAngle, outerAngle, range, innerColor = (16776960), outerColor = (16755200)) {
824
+ return this.color(innerColor), this.cone(innerAngle * 0.5, range), this.color(outerColor), this.cone(outerAngle * 0.5, range);
825
+ }
826
+ cone(halfAngle, range) {
827
+ let clamped = Math.min(halfAngle, Math.PI), radius = Math.sin(clamped) * range, depth = Math.cos(clamped) * range;
828
+ for (let s = 0; s < (8); s++) {
829
+ let t = s / (8) * TAU;
830
+ this.segment(0, 0, 0, Math.cos(t) * radius, Math.sin(t) * radius, depth);
831
+ }
832
+ return this.circle(0, 0, depth, radius, 0, 0, 1, (32));
833
+ }
834
+ halfCircle(size, sign) {
835
+ let px = size, py = 0;
836
+ for (let s = 1; s <= (16) / 2; s++) {
837
+ let t = s / (16) * TAU, x = Math.cos(t) * size, y = Math.sin(t) * size * sign;
838
+ this.segment(px, py, 0, x, y, 0), px = x, py = y;
839
+ }
840
+ return this;
841
+ }
842
+ cornerEdges() {
843
+ let k = this.corners;
844
+ for (let e = 0; e < (12); e++) {
845
+ let a = BOX_EDGE_CORNERS[e * 2] * 3, b = BOX_EDGE_CORNERS[e * 2 + 1] * 3;
846
+ this.segment(k[a], k[a + 1], k[a + 2], k[b], k[b + 1], k[b + 2]);
847
+ }
848
+ return this;
849
+ }
850
+ basisFor(nx, ny, nz) {
851
+ let len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1, x = nx / len, y = ny / len, z = nz / len, rx = 0, ry = 1, rz = 0;
852
+ Math.abs(y) > (0.99) && (rx = 1, ry = 0);
853
+ let ax = ry * z - rz * y, ay = rz * x - rx * z, az = rx * y - ry * x, al = Math.sqrt(ax * ax + ay * ay + az * az) || 1;
854
+ ax /= al, ay /= al, az /= al;
855
+ let b = this.basis;
856
+ return b[0] = ax, b[1] = ay, b[2] = az, b[3] = y * az - z * ay, b[4] = z * ax - x * az, b[5] = x * ay - y * ax, b;
857
+ }
858
+ };
859
+ function lineGeometry(writer, dynamic = false) {
860
+ return {
861
+ attributes: {
862
+ position: { data: writer.positions, itemSize: 3, dynamic },
863
+ color: { data: writer.colors, itemSize: 4, dynamic }
864
+ }
865
+ };
866
+ }
867
+ function build(segments, write) {
868
+ let writer = new LineWriter(segments);
869
+ return writer.color((16776960)), write(writer), lineGeometry(writer);
870
+ }
871
+ function axesHelper(size = 1) {
872
+ return build((3), (w) => w.axes(null, 0, size));
873
+ }
874
+ function gridHelper(size = 10, divisions = 10, centerColor = (4473924), gridColor = (8947848)) {
875
+ return build((divisions + 1) * 2, (w) => w.grid(size, divisions, centerColor, gridColor));
876
+ }
877
+ function polarGridHelper(radius = 10, sectors = 16, rings = 8, divisions = 64, sectorColor = (4473924), ringColor = (8947848)) {
878
+ return build(sectors + rings * divisions, (w) => w.polarGrid(radius, sectors, rings, divisions, sectorColor, ringColor));
879
+ }
880
+ function arrowHelper(direction, length = 1, color = (16776960), headLength, headWidth) {
881
+ return build((5), (w) => w.color(color).arrow(0, 0, 0, direction[0], direction[1], direction[2], length, headLength, headWidth));
882
+ }
883
+ function boxHelper(min, max, color = (16776960)) {
884
+ return build((12), (w) => w.color(color).box(min[0], min[1], min[2], max[0], max[1], max[2]));
885
+ }
886
+ function cameraHelper(projectionInverse, color = (16755200)) {
887
+ let apex = new Float64Array(3);
888
+ return build((12) + (4), (w) => w.color(color).frustum(projectionInverse, 0, apex));
889
+ }
890
+ function directionalLightHelper(size = 1, length = size * 2, color = (16776960)) {
891
+ return build((5), (w) => w.color(color).directionalLight(size, length));
892
+ }
893
+ function spotLightHelper(angle, distance = 5, color = (16776960), segments = (32)) {
894
+ return build((5) + segments, (w) => w.color(color).spotLight(angle, distance, segments));
895
+ }
896
+ function pointLightHelper(radius = 0.5, color = (16776960), segments = (32)) {
897
+ return build((3) * segments, (w) => w.color(color).sphere(0, 0, 0, radius, segments));
898
+ }
899
+ function hemisphereLightHelper(size = 1, skyColor = 8900331, groundColor = 9132587) {
900
+ return build((16) * 2, (w) => w.hemisphere(size, skyColor, groundColor));
901
+ }
902
+ function planeHelper(normal, constant = 0, size = 1, color = (16776960)) {
903
+ return build((6), (w) => w.color(color).plane(normal[0], normal[1], normal[2], constant, size));
904
+ }
905
+ function skeletonHelper(parents, worlds, color = (65535)) {
906
+ let bones = parents.length;
907
+ return build(Math.max(1, bones), (w) => w.color(color).skeleton(parents, worlds, bones));
908
+ }
909
+ function vertexNormalsHelper(positions, normals, size = 0.1, color = (16711935)) {
910
+ let vertices = Math.floor(positions.length / 3);
911
+ return build(Math.max(1, vertices), (w) => w.color(color).normals(positions, normals, vertices, size));
912
+ }
913
+ function positionalAudioHelper(innerAngle, outerAngle, range = 1, innerColor = (16776960), outerColor = (16755200)) {
914
+ return build(((8) + (32)) * 2, (w) => w.audioCone(innerAngle, outerAngle, range, innerColor, outerColor));
915
+ }
916
+ function helperSegments(desc) {
917
+ return desc.attributes.position.data.length / 6;
918
+ }
919
+ var DEFAULT_DEBUG_CIRCLE_SEGMENTS = (32);
920
+
921
+ // src/game/render/debug.ts
922
+ var DEFAULT_DEBUG_SEGMENTS = 8192, SEGMENT_VERTICES = 2, CONTACT_CROSS = 0.1, COMPOUND_ORIGIN = [0, 0, 0], SHAPE_RIBS = 4, TRIANGLE_EDGES = 3, DEFAULT_GRID_SIZE = 10, DEFAULT_GRID_DIVISIONS = 10, DEFAULT_AXES = 1, CONTACT_COLOR = 16723285, NAV_COLOR = 3199320, SHAPE_COLOR = 6607615, DebugDraw = class {
923
+ constructor(graphics, options = {}) {
924
+ this.flushed = 0;
925
+ this.visible = true;
926
+ this.a = new Vec3();
927
+ this.b = new Vec3();
928
+ this.graphics = graphics, this.writer = new LineWriter(options.capacity ?? (8192)), this.geometry = graphics.createGeometry(lineGeometry(this.writer, true)), this.material = graphics.createMaterial({
929
+ kind: "lines",
930
+ vertexColors: true,
931
+ transparent: false,
932
+ depthTest: options.depthTest ?? true,
933
+ depthWrite: false
934
+ }), this.node = graphics.createDetached({ kind: "lines", geometry: this.geometry, material: this.material, segments: true, renderOrder: options.renderOrder ?? 0 }), graphics.setLayers(this.node, options.layers ?? 2147483647), graphics.setDrawRange(this.geometry, 0, 0);
935
+ }
936
+ get segments() {
937
+ return this.writer.count;
938
+ }
939
+ get dropped() {
940
+ return this.writer.dropped;
941
+ }
942
+ get capacity() {
943
+ return this.writer.capacity;
944
+ }
945
+ setLayers(mask) {
946
+ this.graphics.setLayers(this.node, mask);
947
+ }
948
+ setVisible(visible) {
949
+ visible !== this.visible && (this.visible = visible, this.graphics.setVisible(this.node, visible));
950
+ }
951
+ clear() {
952
+ this.writer.clear(), this.writer.setMatrix(null);
953
+ }
954
+ color(hex, alpha = 1) {
955
+ return this.writer.color(hex, alpha), this;
956
+ }
957
+ transform(matrix, offset = 0) {
958
+ return this.writer.setMatrix(matrix, offset), this;
959
+ }
960
+ line(ax, ay, az, bx, by, bz, color = (16776960)) {
961
+ return this.writer.color(color).segment(ax, ay, az, bx, by, bz), this;
962
+ }
963
+ ray(ox, oy, oz, dx, dy, dz, length, color = (16776960)) {
964
+ return this.writer.color(color).segment(ox, oy, oz, ox + dx * length, oy + dy * length, oz + dz * length), this;
965
+ }
966
+ arrow(ox, oy, oz, dx, dy, dz, length, color = (16776960)) {
967
+ return this.writer.color(color).arrow(ox, oy, oz, dx, dy, dz, length), this;
968
+ }
969
+ box(minX, minY, minZ, maxX, maxY, maxZ, color = (16776960)) {
970
+ return this.writer.color(color).box(minX, minY, minZ, maxX, maxY, maxZ), this;
971
+ }
972
+ boxTransformed(minX, minY, minZ, maxX, maxY, maxZ, matrix, offset = 0, color = (16776960)) {
973
+ return this.writer.color(color).box(minX, minY, minZ, maxX, maxY, maxZ, matrix, offset), this;
974
+ }
975
+ sphere(x, y, z, radius, color = (16776960), segments = DEFAULT_DEBUG_CIRCLE_SEGMENTS) {
976
+ return this.writer.color(color).sphere(x, y, z, radius, segments), this;
977
+ }
978
+ circle(x, y, z, radius, nx, ny, nz, color = (16776960), segments = DEFAULT_DEBUG_CIRCLE_SEGMENTS) {
979
+ return this.writer.color(color).circle(x, y, z, radius, nx, ny, nz, segments), this;
980
+ }
981
+ axes(matrix, offset = 0, size = (1)) {
982
+ return this.writer.axes(matrix, offset, size), this;
983
+ }
984
+ axesAt(px, py, pz, qx, qy, qz, qw, size = (1)) {
985
+ return this.writer.axesAt(px, py, pz, qx, qy, qz, qw, size), this;
986
+ }
987
+ grid(size = (10), divisions = (10), y = 0) {
988
+ return this.writer.grid(size, divisions, void 0, void 0, y), this;
989
+ }
990
+ polarGrid(radius, sectors, rings, divisions = DEFAULT_DEBUG_CIRCLE_SEGMENTS, y = 0) {
991
+ return this.writer.polarGrid(radius, sectors, rings, divisions, void 0, void 0, y), this;
992
+ }
993
+ frustum(projection, color = (16776960)) {
994
+ return this.writer.color(color).frustum(projection.viewProjectionInverse, 0, null), this;
995
+ }
996
+ frustumMatrix(inverseViewProjection, offset = 0, color = (16776960)) {
997
+ return this.writer.color(color).frustum(inverseViewProjection, offset, null), this;
998
+ }
999
+ plane(nx, ny, nz, constant, size, color = (16776960)) {
1000
+ return this.writer.color(color).plane(nx, ny, nz, constant, size), this;
1001
+ }
1002
+ point(x, y, z, size, color = (16776960)) {
1003
+ return this.writer.color(color).cross(x, y, z, size), this;
1004
+ }
1005
+ skeleton(parents, worlds, count = parents.length, color = (16776960)) {
1006
+ return this.writer.color(color).skeleton(parents, worlds, count), this;
1007
+ }
1008
+ path(points, count, color = (16776960), closed = false) {
1009
+ return this.writer.color(color).path(points, count, closed), this;
1010
+ }
1011
+ navPath(path, color = (3199320), marker = (0.1)) {
1012
+ this.writer.color(color).path(path.points, path.count);
1013
+ let p = path.points;
1014
+ for (let i = 0; i < path.count; i++) this.writer.cross(p[i * 3], p[i * 3 + 1], p[i * 3 + 2], marker);
1015
+ return this;
1016
+ }
1017
+ contacts(source, positions, color = (16723285), startedColor = (16776960)) {
1018
+ let n = source.contactCount();
1019
+ for (let i = 0; i < n; i++) {
1020
+ positions.position(source.contactEntityA(i), this.a), positions.position(source.contactEntityB(i), this.b);
1021
+ let a = this.a, b = this.b;
1022
+ this.writer.color(source.contactStarted(i) ? startedColor : color), this.writer.segment(a.x, a.y, a.z, b.x, b.y, b.z), this.writer.cross((a.x + b.x) * 0.5, (a.y + b.y) * 0.5, (a.z + b.z) * 0.5, (0.1));
1023
+ }
1024
+ return this;
1025
+ }
1026
+ shape(shape2, matrix, offset = 0, color = (6607615)) {
1027
+ let w = this.writer.color(color).setMatrix(matrix, offset);
1028
+ switch (shape2.kind) {
1029
+ case "ball":
1030
+ w.sphere(0, 0, 0, shape2.radius);
1031
+ break;
1032
+ case "cuboid": {
1033
+ let h = shape2.halfExtents;
1034
+ w.box(-h[0], -h[1], -h[2], h[0], h[1], h[2]);
1035
+ break;
1036
+ }
1037
+ case "capsule":
1038
+ this.tube(shape2.radius, shape2.radius, shape2.halfHeight), w.circle(0, shape2.halfHeight, 0, shape2.radius, 1, 0, 0), w.circle(0, shape2.halfHeight, 0, shape2.radius, 0, 0, 1), w.circle(0, -shape2.halfHeight, 0, shape2.radius, 1, 0, 0), w.circle(0, -shape2.halfHeight, 0, shape2.radius, 0, 0, 1);
1039
+ break;
1040
+ case "cylinder":
1041
+ this.tube(shape2.radius, shape2.radius, shape2.halfHeight);
1042
+ break;
1043
+ case "cone":
1044
+ this.tube(0, shape2.radius, shape2.halfHeight);
1045
+ break;
1046
+ case "round_cuboid": {
1047
+ let h = shape2.halfExtents, b = shape2.border;
1048
+ w.box(-h[0] - b, -h[1] - b, -h[2] - b, h[0] + b, h[1] + b, h[2] + b);
1049
+ break;
1050
+ }
1051
+ case "round_cylinder":
1052
+ this.tube(shape2.radius + shape2.border, shape2.radius + shape2.border, shape2.halfHeight + shape2.border);
1053
+ break;
1054
+ case "round_cone":
1055
+ this.tube(shape2.border, shape2.radius + shape2.border, shape2.halfHeight + shape2.border);
1056
+ break;
1057
+ case "round_convex_hull": {
1058
+ let p = shape2.points;
1059
+ for (let i = 0; i + 2 < p.length; i += 3) w.cross(p[i], p[i + 1], p[i + 2], (0.1) + shape2.border);
1060
+ break;
1061
+ }
1062
+ case "compound":
1063
+ for (let part of shape2.parts) {
1064
+ let at = part.offset ?? COMPOUND_ORIGIN;
1065
+ w.cross(at[0], at[1], at[2], (0.1));
1066
+ }
1067
+ break;
1068
+ case "trimesh": {
1069
+ let v = shape2.vertices, idx = shape2.indices;
1070
+ for (let t = 0; t + 2 < idx.length; t += (3))
1071
+ for (let e = 0; e < (3); e++) {
1072
+ let i0 = idx[t + e] * 3, i1 = idx[t + (e + 1) % (3)] * 3;
1073
+ w.segment(v[i0], v[i0 + 1], v[i0 + 2], v[i1], v[i1 + 1], v[i1 + 2]);
1074
+ }
1075
+ break;
1076
+ }
1077
+ case "convex_hull": {
1078
+ let p = shape2.points;
1079
+ for (let i = 0; i + 2 < p.length; i += 3) w.cross(p[i], p[i + 1], p[i + 2], (0.1));
1080
+ break;
1081
+ }
1082
+ case "heightfield": {
1083
+ let { rows, columns, heights, scale } = shape2, sx = scale[0] / Math.max(1, columns - 1), sz = scale[2] / Math.max(1, rows - 1), ox = -scale[0] * 0.5, oz = -scale[2] * 0.5;
1084
+ for (let r = 0; r < rows; r++)
1085
+ for (let c = 0; c < columns; c++) {
1086
+ let y = heights[r * columns + c] * scale[1];
1087
+ c + 1 < columns && w.segment(ox + c * sx, y, oz + r * sz, ox + (c + 1) * sx, heights[r * columns + c + 1] * scale[1], oz + r * sz), r + 1 < rows && w.segment(ox + c * sx, y, oz + r * sz, ox + c * sx, heights[(r + 1) * columns + c] * scale[1], oz + (r + 1) * sz);
1088
+ }
1089
+ break;
1090
+ }
1091
+ }
1092
+ return w.setMatrix(null), this;
1093
+ }
1094
+ flush() {
1095
+ let vertices = this.writer.count * (2);
1096
+ vertices > 0 && (this.graphics.markGeometryDirty(this.geometry, "position", 0, vertices * 3), this.graphics.markGeometryDirty(this.geometry, "color", 0, vertices * 4)), vertices !== this.flushed && (this.graphics.setDrawRange(this.geometry, 0, vertices), this.flushed = vertices);
1097
+ }
1098
+ tube(radiusTop, radiusBottom, halfHeight) {
1099
+ let w = this.writer;
1100
+ radiusTop > 0 && w.circle(0, halfHeight, 0, radiusTop, 0, 1, 0), radiusBottom > 0 && w.circle(0, -halfHeight, 0, radiusBottom, 0, 1, 0);
1101
+ for (let i = 0; i < (4); i++) {
1102
+ let t = i / (4) * Math.PI * 2, c = Math.cos(t), s = Math.sin(t);
1103
+ w.segment(c * radiusTop, halfHeight, s * radiusTop, c * radiusBottom, -halfHeight, s * radiusBottom);
1104
+ }
1105
+ }
1106
+ };
1107
+
1108
+ // src/game/ui/labels.ts
1109
+ var DEFAULT_LABEL_CAPACITY = 64, VEC3 = 3, OCCLUSION_EPSILON = 1e-3, OPACITY_STEPS = 32, NO_SLOT = -1, VISIBLE = 1, HIDDEN = 0, ScreenLabels = class {
1110
+ constructor(options = {}) {
1111
+ this.count = 0;
1112
+ this.world = new Vec3();
1113
+ this.ndc = new Vec3();
1114
+ this.hit = createPickHit();
1115
+ this.origin = new Float32Array((3));
1116
+ this.direction = new Float32Array((3));
1117
+ let n = options.capacity ?? (64);
1118
+ this.capacity = n, this.x = new Float32Array(n), this.y = new Float32Array(n), this.depth = new Float32Array(n), this.distance = new Float32Array(n), this.opacity = new Float32Array(n), this.visible = new Uint8Array(n), this.offscreen = new Uint8Array(n), this.occluded = new Uint8Array(n), this.live = new Uint8Array(n), this.entities = new Uint32Array(n).fill(NO_ENTITY), this.points = new Float32Array(n * (3)), this.offsets = new Float32Array(n * (3)), this.occludes = new Uint8Array(n), this.nodes = new Uint32Array(n), this.labelEntity = new Uint32Array(n).fill(NO_ENTITY), this.shownOpacity = new Float32Array(n).fill(-1), this.shown = new Uint8Array(n).fill((1)), this.hudX = new Int32Array(n).fill((-1)), this.hudY = new Int32Array(n).fill((-1)), this.hudVisible = new Int32Array(n).fill((-1)), this.hudOpacity = new Int32Array(n).fill((-1)), this.styles = new Array(n).fill(null), this.anchors = options.anchors ?? null, this.ui = options.ui ?? null, this.engine = options.engineText ?? null, this.occluder = options.occluder ?? null, this.occlusionLayers = options.occlusionLayers ?? 4294967295, this.fadeNear = options.fadeNear ?? 0, this.fadeFar = options.fadeFar ?? 0, this.clampToEdge = options.clampToEdge ?? false, this.margin = options.margin ?? 0;
1119
+ }
1120
+ get size() {
1121
+ return this.count;
1122
+ }
1123
+ add(desc) {
1124
+ let label = -1;
1125
+ for (let i = 0; i < this.capacity; i++)
1126
+ if (this.live[i] === 0) {
1127
+ label = i;
1128
+ break;
1129
+ }
1130
+ if (label < 0) throw new GameError("capacity_exceeded", `at most ${this.capacity} screen labels`);
1131
+ if (desc.entity === void 0 && desc.point === void 0) throw new GameError("invalid_argument", "a label needs an entity or a point");
1132
+ this.live[label] = 1, this.count++, this.entities[label] = desc.entity ?? NO_ENTITY;
1133
+ let p = label * (3);
1134
+ this.points[p] = desc.point?.[0] ?? 0, this.points[p + 1] = desc.point?.[1] ?? 0, this.points[p + 2] = desc.point?.[2] ?? 0, this.offsets[p] = desc.offset?.[0] ?? 0, this.offsets[p + 1] = desc.offset?.[1] ?? 0, this.offsets[p + 2] = desc.offset?.[2] ?? 0, this.occludes[label] = desc.occlude === false ? 0 : 1, this.shownOpacity[label] = -1, this.shown[label] = (1);
1135
+ let name = desc.name ?? `label${label}`;
1136
+ desc.hud && this.ui && (this.hudX[label] = this.ui.hudNumber(`${name}.x`), this.hudY[label] = this.ui.hudNumber(`${name}.y`), this.hudVisible[label] = this.ui.hudNumber(`${name}.visible`), this.hudOpacity[label] = this.ui.hudNumber(`${name}.opacity`, 1));
1137
+ let engine = this.engine;
1138
+ if (engine && desc.text !== void 0) {
1139
+ let style = { ...desc.style, opacity: desc.style?.opacity ?? 1 };
1140
+ this.styles[label] = style;
1141
+ let entity = engine.spawner.spawn();
1142
+ engine.add?.(entity), this.nodes[label] = engine.text.create(entity, { ...style, kind: "text2d", text: desc.text }), this.labelEntity[label] = entity;
1143
+ }
1144
+ return label;
1145
+ }
1146
+ textEntity(label) {
1147
+ return this.labelEntity[label];
1148
+ }
1149
+ node(label) {
1150
+ return this.nodes[label];
1151
+ }
1152
+ setPoint(label, x, y, z) {
1153
+ let p = label * (3);
1154
+ this.points[p] = x, this.points[p + 1] = y, this.points[p + 2] = z;
1155
+ }
1156
+ setText(label, text2) {
1157
+ this.engine && this.styles[label] !== null && this.engine.text.setText(this.nodes[label], text2);
1158
+ }
1159
+ remove(label) {
1160
+ this.live[label] !== 0 && (this.live[label] = 0, this.count--, this.visible[label] = (0), this.engine && this.styles[label] !== null && this.engine.text.setVisible(this.nodes[label], false), this.styles[label] = null, this.entities[label] = NO_ENTITY);
1161
+ }
1162
+ update(projection) {
1163
+ let width = projection.width, height = projection.height, fade = this.fadeFar > this.fadeNear;
1164
+ for (let i = 0; i < this.capacity; i++) {
1165
+ if (this.live[i] === 0) continue;
1166
+ this.anchor(i);
1167
+ let distance = projection.position.distanceTo(this.world);
1168
+ this.distance[i] = distance;
1169
+ let inside = projection.worldToNdc(this.world, this.ndc), front = projection.w > 0, nx = this.ndc.x, ny = this.ndc.y, show = inside, off = 0;
1170
+ if (!inside && this.clampToEdge) {
1171
+ front || (nx = -nx, ny = -ny);
1172
+ let extent = Math.max(Math.abs(nx), Math.abs(ny));
1173
+ if (extent > 1 || !front) {
1174
+ let s = extent > 0 ? 1 / extent : 1;
1175
+ nx *= s, ny *= s;
1176
+ }
1177
+ show = true, off = 1;
1178
+ }
1179
+ let px = (nx + 1) * 0.5 * width, py = (1 - ny) * 0.5 * height;
1180
+ off === 1 && (px = Math.min(width - this.margin, Math.max(this.margin, px)), py = Math.min(height - this.margin, Math.max(this.margin, py)));
1181
+ let occluded = 0;
1182
+ show && off === 0 && this.occluder && this.occludes[i] === 1 && distance > (1e-3) && (occluded = this.occludedBy(projection, distance) ? 1 : 0, occluded === 1 && (show = false));
1183
+ let alpha = show ? 1 : 0;
1184
+ if (show && fade) {
1185
+ let t = Math.min(1, Math.max(0, (distance - this.fadeNear) / (this.fadeFar - this.fadeNear)));
1186
+ alpha = 1 - t * t * (3 - 2 * t), alpha <= 0 && (show = false);
1187
+ }
1188
+ this.x[i] = px, this.y[i] = py, this.depth[i] = this.ndc.z, this.opacity[i] = alpha, this.visible[i] = show ? (1) : (0), this.offscreen[i] = off, this.occluded[i] = occluded, this.publish(i, show, px, py, alpha);
1189
+ }
1190
+ }
1191
+ anchor(i) {
1192
+ let p = i * (3), entity = this.entities[i];
1193
+ entity !== NO_ENTITY && this.anchors ? this.anchors.renderPosition(entity, this.world) : this.world.set(this.points[p], this.points[p + 1], this.points[p + 2]), this.world.set(this.world.x + this.offsets[p], this.world.y + this.offsets[p + 1], this.world.z + this.offsets[p + 2]);
1194
+ }
1195
+ occludedBy(projection, distance) {
1196
+ let occluder = this.occluder, o = projection.position, inv = 1 / distance;
1197
+ return this.origin[0] = o.x, this.origin[1] = o.y, this.origin[2] = o.z, this.direction[0] = (this.world.x - o.x) * inv, this.direction[1] = (this.world.y - o.y) * inv, this.direction[2] = (this.world.z - o.z) * inv, occluder.raycast(this.origin, this.direction, this.hit, distance, this.occlusionLayers) ? this.hit.distance < distance - (1e-3) : false;
1198
+ }
1199
+ publish(i, show, px, py, alpha) {
1200
+ let ui = this.ui;
1201
+ ui && this.hudX[i] !== (-1) && (ui.setNumber(this.hudX[i], px), ui.setNumber(this.hudY[i], py), ui.setNumber(this.hudVisible[i], show ? (1) : (0)), ui.setNumber(this.hudOpacity[i], Math.round(alpha * (32)) / (32)));
1202
+ let engine = this.engine, style = this.styles[i];
1203
+ if (!engine || style === null) return;
1204
+ let node2 = this.nodes[i], shown = show ? (1) : (0);
1205
+ if (shown !== this.shown[i] && (this.shown[i] = shown, engine.text.setVisible(node2, show)), !show) return;
1206
+ engine.placement.setPosition(this.labelEntity[i], px, py, 0);
1207
+ let stepped = Math.round(alpha * (32)) / (32);
1208
+ stepped !== this.shownOpacity[i] && (this.shownOpacity[i] = stepped, style.opacity = stepped, engine.text.setTextStyle(node2, style));
1209
+ }
1210
+ };
1211
+ function engineLabelText(graphics, transforms, world) {
1212
+ return {
1213
+ text: graphics,
1214
+ placement: transforms,
1215
+ spawner: world,
1216
+ add: (entity) => {
1217
+ transforms.add(entity);
1218
+ }
1219
+ };
1220
+ }
1221
+
1222
+ // src/game/kernel/std/intrinsics.ts
1223
+ var fround = Math.fround, TWO_32 = 2 ** 32, LOW_16 = 65535, TWO_16 = 65536;
1224
+ function fsin(x) {
1225
+ return sin(fround(x));
1226
+ }
1227
+ function fcos(x) {
1228
+ return cos(fround(x));
1229
+ }
1230
+ function ftan(x) {
1231
+ return tan(fround(x));
1232
+ }
1233
+ function fasin(x) {
1234
+ return asin(fround(x));
1235
+ }
1236
+ function facos(x) {
1237
+ return acos(fround(x));
1238
+ }
1239
+ function fatan(x) {
1240
+ return atan(fround(x));
1241
+ }
1242
+ function fatan2(y, x) {
1243
+ return atan2(fround(y), fround(x));
1244
+ }
1245
+ function fexp(x) {
1246
+ return exp(fround(x));
1247
+ }
1248
+ function flog(x) {
1249
+ return log(fround(x));
1250
+ }
1251
+ function flog2(x) {
1252
+ return log2(fround(x));
1253
+ }
1254
+ function fpow(x, y) {
1255
+ return pow(fround(x), fround(y));
1256
+ }
1257
+ function umulhi(a, b) {
1258
+ let x = a >>> 0, y = b >>> 0, xl = x & (65535), xh = x >>> 16, yl = y & (65535), yh = y >>> 16, lh = xl * yh, hl = xh * yl, mid = (xl * yl >>> 16) + (lh & (65535)) + (hl & (65535));
1259
+ return xh * yh + (lh >>> 16) + (hl >>> 16) + Math.floor(mid / (65536)) >>> 0;
1260
+ }
1261
+ function uaddCarry(a, b, carry) {
1262
+ return (a >>> 0) + (b >>> 0) + (carry & 1) >= TWO_32 ? 1 : 0;
1263
+ }
1264
+ function usubBorrow(a, b, borrow) {
1265
+ return a >>> 0 < (b >>> 0) + (borrow & 1) ? 1 : 0;
1266
+ }
1267
+
1268
+ // src/game/scenes/catalogue.ts
1269
+ var SCENE_CATALOGUE_VERSION = 1, STARTER_CATALOGUE = {
1270
+ bench: { footprint: [1.6, 0.6], height: 0.9, size: "medium", tags: ["street", "seat", "rest"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 0.45, 0.05], front: [0, 0, 0.6], edge: [0.8, 0.45, 0] } },
1271
+ street_lamp: { footprint: [0.4, 0.4], height: 4.5, size: "tiny", tags: ["street", "light"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 4.5, 0], front: [0, 0, 0.5] } },
1272
+ bus_stop: { footprint: [3.5, 1.5], height: 2.6, size: "medium", tags: ["street", "transit", "shelter"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 0.45, -0.3], front: [0, 0, 1.2], top: [0, 2.6, 0] } },
1273
+ trash_bin: { footprint: [0.5, 0.5], height: 1, size: "small", tags: ["street", "utility"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 0.5], top: [0, 1, 0] } },
1274
+ bollard: { footprint: [0.25, 0.25], height: 1, size: "tiny", tags: ["street", "barrier"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1, 0] } },
1275
+ fire_hydrant: { footprint: [0.4, 0.4], height: 0.8, size: "tiny", tags: ["street", "utility"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 0.5] } },
1276
+ mailbox: { footprint: [0.5, 0.5], height: 1.2, size: "small", tags: ["street", "utility"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 0.6], top: [0, 1.2, 0] } },
1277
+ bike_rack: { footprint: [2, 0.6], height: 0.9, size: "medium", tags: ["street", "transit"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1], edge: [1, 0.5, 0] } },
1278
+ planter: { footprint: [1.2, 1.2], height: 0.8, size: "small", tags: ["street", "plant"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.8, 0], edge: [0.6, 0.5, 0] } },
1279
+ fountain: { footprint: [4, 4], height: 2.2, size: "large", tags: ["street", "landmark", "water"], up: "+y", forward: "+z", solid: true, anchors: { edge: [2, 0.5, 0], front: [0, 0, 2.4] } },
1280
+ kiosk: { footprint: [2.5, 2.5], height: 3, size: "medium", tags: ["street", "shop"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1.6], door: [0, 0, 1.25], top: [0, 3, 0] } },
1281
+ parked_car: { footprint: [1.9, 4.5], height: 1.5, size: "large", tags: ["street", "vehicle"], up: "+y", forward: "+z", solid: true, anchors: { door: [1, 0, 0.3], front: [0, 0, 2.6], back: [0, 0, -2.6] } },
1282
+ spawn_point: { footprint: [0.8, 0.8], height: 0, size: "small", tags: ["street", "marker", "gameplay"], up: "+y", forward: "+z", solid: false, anchors: { front: [0, 0, 0] } },
1283
+ waypoint: { footprint: [0.5, 0.5], height: 0, size: "small", tags: ["street", "marker", "gameplay"], up: "+y", forward: "+z", solid: false, anchors: { front: [0, 0, 0] } },
1284
+ market_stall: { footprint: [3, 2], height: 2.6, size: "medium", tags: ["market", "shop", "shelter"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1.3], edge: [0, 0.9, 0.9], top: [0, 0.9, 0.2], back: [0, 0, -1.2] } },
1285
+ crate_stack: { footprint: [1.2, 1.2], height: 1.4, size: "small", tags: ["market", "storage"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1.4, 0] } },
1286
+ barrel: { footprint: [0.7, 0.7], height: 1, size: "small", tags: ["market", "storage"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1, 0] } },
1287
+ produce_table: { footprint: [2, 1], height: 0.9, size: "medium", tags: ["market", "shop", "table"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.9, 0], front: [0, 0, 0.8], edge: [0, 0.9, 0.5] } },
1288
+ parasol: { footprint: [2.4, 2.4], height: 2.5, size: "medium", tags: ["market", "shade"], up: "+y", forward: "+z", solid: false, anchors: { top: [0, 2.5, 0] } },
1289
+ cart: { footprint: [1.2, 2.2], height: 1.3, size: "medium", tags: ["market", "vehicle", "shop"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.9, 0], front: [0, 0, 1.4] } },
1290
+ goal: { footprint: [7.3, 2], height: 2.44, size: "large", tags: ["sports", "football"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1.5], edge: [3.65, 1.2, 0] } },
1291
+ basketball_hoop: { footprint: [1.8, 2], height: 3.95, size: "medium", tags: ["sports", "basketball"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 2.2], top: [0, 3.05, 1.2] } },
1292
+ bleacher: { footprint: [8, 3], height: 2.4, size: "large", tags: ["sports", "seat", "crowd"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 1.2, 0], front: [0, 0, 1.8] } },
1293
+ scoreboard: { footprint: [4, 0.6], height: 5, size: "large", tags: ["sports", "display"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1] } },
1294
+ corner_flag: { footprint: [0.2, 0.2], height: 1.5, size: "tiny", tags: ["sports", "football", "marker"], up: "+y", forward: "+z", solid: false, anchors: { top: [0, 1.5, 0] } },
1295
+ ball_rack: { footprint: [1.5, 0.6], height: 1.1, size: "medium", tags: ["sports", "storage"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 0.7], top: [0, 1.1, 0] } },
1296
+ table: { footprint: [1.6, 0.9], height: 0.75, size: "medium", tags: ["interior", "table"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.75, 0], edge: [0, 0.75, 0.45], front: [0, 0, 0.9] } },
1297
+ chair: { footprint: [0.5, 0.5], height: 0.9, size: "small", tags: ["interior", "seat"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 0.45, 0], front: [0, 0, 0.5] } },
1298
+ sofa: { footprint: [2.2, 0.9], height: 0.85, size: "medium", tags: ["interior", "seat", "rest"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 0.45, 0.1], front: [0, 0, 0.9] } },
1299
+ bed: { footprint: [1.6, 2.1], height: 0.6, size: "medium", tags: ["interior", "rest"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.6, 0], edge: [0.8, 0.5, 0], front: [0.95, 0, 0] } },
1300
+ shelf: { footprint: [1.2, 0.4], height: 2, size: "small", tags: ["interior", "storage"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 2, 0], front: [0, 0, 0.6] } },
1301
+ counter: { footprint: [3, 0.8], height: 1.05, size: "medium", tags: ["interior", "shop", "table"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1.05, 0], front: [0, 0, 0.9], back: [0, 0, -0.9] } },
1302
+ door: { footprint: [1, 0.2], height: 2.1, size: "small", tags: ["interior", "passage"], up: "+y", forward: "+z", solid: false, anchors: { door: [0, 0, 0], front: [0, 0, 0.6], back: [0, 0, -0.6] } },
1303
+ rug: { footprint: [2, 3], height: 0.02, size: "medium", tags: ["interior", "decor", "flat"], up: "+y", forward: "+z", solid: false, anchors: { top: [0, 0.02, 0] } },
1304
+ lamp: { footprint: [0.3, 0.3], height: 0.5, size: "tiny", tags: ["interior", "light"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.5, 0] } },
1305
+ tree: { footprint: [1, 1], height: 7, size: "small", tags: ["nature", "plant", "shade"], up: "+y", forward: "+z", solid: true, anchors: { edge: [0.5, 0, 0] } },
1306
+ bush: { footprint: [1.4, 1.4], height: 1.2, size: "small", tags: ["nature", "plant"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1.2, 0] } },
1307
+ rock: { footprint: [1.6, 1.2], height: 0.9, size: "medium", tags: ["nature", "stone"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 0.9, 0], seat: [0, 0.6, 0.3] } },
1308
+ log: { footprint: [2.5, 0.5], height: 0.5, size: "medium", tags: ["nature", "seat", "wood"], up: "+y", forward: "+z", solid: true, anchors: { seat: [0, 0.5, 0], front: [0, 0, 0.6] } },
1309
+ flower_bed: { footprint: [2, 1], height: 0.4, size: "medium", tags: ["nature", "plant", "flat"], up: "+y", forward: "+z", solid: false, anchors: { edge: [1, 0.2, 0] } }
1310
+ };
1311
+ function extendCatalogue(extra, base = STARTER_CATALOGUE) {
1312
+ return Object.freeze({ ...base, ...extra });
1313
+ }
1314
+
1315
+ export { DEFAULT_DEBUG_SEGMENTS, DEFAULT_LABEL_CAPACITY, DebugDraw, IMPORT_DEFAULT_MAX_DRIFT, IMPORT_DEFAULT_SAMPLES, ImportError, LineWriter, MLP_MEMORY_MAX, MLP_MEMORY_MIN, MOE_DEFAULT_BALANCE, SCENE_CATALOGUE_VERSION, STARTER_CATALOGUE, ScreenLabels, arrowHelper, axesHelper, boxHelper, cameraHelper, checkNet, directionalLightHelper, engineLabelText, extendCatalogue, facos, fasin, fatan, fatan2, fcos, fexp, floatEval, flog, flog2, fpow, fsin, ftan, generatedSamples, gridHelper, helperSegments, hemisphereLightHelper, importMlp, importMoe, joinMemory, lineGeometry, memorySamples, plainNet, planeHelper, pointLightHelper, polarGridHelper, positionalAudioHelper, readOnnx, skeletonHelper, spotLightHelper, trainMlp, trainMoe, uaddCarry, umulhi, usubBorrow, vertexNormalsHelper };