@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.
- package/LICENSE +21 -0
- package/dist/advanced.d.mts +4 -3
- package/dist/advanced.d.ts +4 -3
- package/dist/advanced.js +24 -24
- package/dist/advanced.mjs +5 -5
- package/dist/animation-4EXBXRVX.js +27 -0
- package/dist/animation-6DICNWUP.mjs +6 -0
- package/dist/audio-DhvyjqdA.d.mts +249 -0
- package/dist/audio-m0w8cnxq.d.ts +249 -0
- package/dist/avatars.d.mts +110 -0
- package/dist/avatars.d.ts +110 -0
- package/dist/avatars.js +82 -0
- package/dist/avatars.mjs +5 -0
- package/dist/backend-gUCzs5Kg.d.mts +3866 -0
- package/dist/backend-gUCzs5Kg.d.ts +3866 -0
- package/dist/{catalogue-B4eLL8Mi.d.ts → catalogue-CPTMyBUz.d.mts} +109 -221
- package/dist/catalogue-DzrTXP3v.d.mts +541 -0
- package/dist/catalogue-DzrTXP3v.d.ts +541 -0
- package/dist/{catalogue-OT89_Ifs.d.mts → catalogue-OTuS5zp-.d.ts} +109 -221
- package/dist/chunk-22BD3RHN.mjs +1809 -0
- package/dist/chunk-25T4JHEA.mjs +21 -0
- package/dist/chunk-2AQ237Y4.js +508 -0
- package/dist/chunk-2IC4H6OV.mjs +48 -0
- package/dist/chunk-2LHLG4OB.mjs +71 -0
- package/dist/chunk-2O2CG465.js +1709 -0
- package/dist/chunk-2Q4DTHXK.js +316 -0
- package/dist/chunk-2QTQ6BUH.mjs +46 -0
- package/dist/chunk-2UN4SFLR.mjs +100 -0
- package/dist/chunk-2V75I7K3.js +454 -0
- package/dist/chunk-2V7IL4HC.js +10 -0
- package/dist/chunk-34XBXUMW.js +296 -0
- package/dist/chunk-3C4C654I.js +71 -0
- package/dist/chunk-3DAD2LDF.mjs +72 -0
- package/dist/chunk-3GXH2NFD.mjs +4 -0
- package/dist/chunk-3O47ZFW3.js +961 -0
- package/dist/chunk-3OY3VYNF.mjs +11 -0
- package/dist/chunk-3S6WPBZL.js +2936 -0
- package/dist/chunk-3TUOUP5T.js +399 -0
- package/dist/chunk-3VEH23I5.mjs +1380 -0
- package/dist/chunk-3ZYSAW2T.mjs +263 -0
- package/dist/chunk-4ANVF274.js +103 -0
- package/dist/chunk-4C7I3ELN.js +388 -0
- package/dist/chunk-4DYKAYFO.mjs +8 -0
- package/dist/chunk-4ZDR72SG.js +329 -0
- package/dist/chunk-52YS45RR.js +1066 -0
- package/dist/chunk-5325XSCH.js +107 -0
- package/dist/chunk-5AD5X6AV.js +13 -0
- package/dist/chunk-5BYDGGWO.mjs +197 -0
- package/dist/chunk-5C3C7VDM.mjs +55 -0
- package/dist/chunk-5HFMY3D7.js +660 -0
- package/dist/chunk-5LH2QN3T.js +1862 -0
- package/dist/chunk-5PJEXSOW.js +44 -0
- package/dist/chunk-5SXDH3Y7.js +90 -0
- package/dist/chunk-5YFBGGCK.mjs +502 -0
- package/dist/chunk-5YWN6H5Q.mjs +133 -0
- package/dist/chunk-66QP3SMN.js +402 -0
- package/dist/chunk-6DAEZKIG.mjs +385 -0
- package/dist/chunk-6DATW7TB.mjs +420 -0
- package/dist/{chunk-JRGK3NXR.mjs → chunk-6ETDAU62.mjs} +72 -212
- package/dist/chunk-6H254EVP.mjs +178 -0
- package/dist/chunk-6PFNJPBJ.mjs +820 -0
- package/dist/chunk-6PJWXIFX.mjs +357 -0
- package/dist/chunk-6SWKWCMS.js +80 -0
- package/dist/chunk-6VVXXX7S.js +808 -0
- package/dist/chunk-6WUBSMTX.js +1403 -0
- package/dist/chunk-73SGZLAQ.mjs +35 -0
- package/dist/chunk-76L2V6KD.mjs +4 -0
- package/dist/chunk-7AAIAVAA.js +1531 -0
- package/dist/chunk-7ARSJPV3.mjs +93 -0
- package/dist/chunk-7BHW5GTC.mjs +1234 -0
- package/dist/chunk-7DQSDKDU.js +6 -0
- package/dist/chunk-7IQQQENP.mjs +401 -0
- package/dist/chunk-7KFTYENS.js +11357 -0
- package/dist/chunk-7SM6XSPZ.js +3171 -0
- package/dist/chunk-7SXOHAIR.mjs +28 -0
- package/dist/chunk-A2MAX6S4.js +90 -0
- package/dist/chunk-A33OORT7.mjs +1530 -0
- package/dist/{chunk-U6ACF76H.mjs → chunk-A36JRXXH.mjs} +1075 -1845
- package/dist/chunk-A7BU3BK4.js +52 -0
- package/dist/chunk-A7MQSN2V.mjs +77 -0
- package/dist/chunk-A7V4L2IT.mjs +416 -0
- package/dist/chunk-AABEK6XU.js +226 -0
- package/dist/chunk-AGV33FWC.mjs +5005 -0
- package/dist/chunk-AHNR3BXI.js +108 -0
- package/dist/chunk-AQ5RLBU2.mjs +286 -0
- package/dist/chunk-AQOE6WCG.js +1270 -0
- package/dist/chunk-ATAWRACV.mjs +62 -0
- package/dist/chunk-ATCURNUV.js +14 -0
- package/dist/chunk-AWPV33OO.js +6 -0
- package/dist/chunk-AYJPHKYV.js +337 -0
- package/dist/chunk-AZ5BGWHB.js +162 -0
- package/dist/chunk-AZAXD44P.js +1373 -0
- package/dist/chunk-BBGKQIJJ.mjs +406 -0
- package/dist/chunk-BP4JLSUA.js +1453 -0
- package/dist/{chunk-SUCE7FWA.mjs → chunk-BTUSVHIE.mjs} +539 -978
- package/dist/chunk-BU6OK542.mjs +818 -0
- package/dist/chunk-CVSRWM6W.js +418 -0
- package/dist/chunk-CYBMFMJD.mjs +247 -0
- package/dist/chunk-DDJLDOUX.mjs +217 -0
- package/dist/{chunk-V32BCG7M.js → chunk-DFZWHNRG.js} +75 -215
- package/dist/chunk-DJ2C7AVG.js +644 -0
- package/dist/chunk-DS2VU4WW.mjs +102 -0
- package/dist/chunk-DSAG7T5P.js +7290 -0
- package/dist/chunk-E2QPPH7I.js +327 -0
- package/dist/chunk-E65WCTIG.mjs +1187 -0
- package/dist/{chunk-33VCYWVL.mjs → chunk-E6QQKDNE.mjs} +30 -42
- package/dist/chunk-ECDK6QBF.mjs +981 -0
- package/dist/chunk-EIB4OWVQ.mjs +620 -0
- package/dist/chunk-EQUZYCGO.js +250 -0
- package/dist/chunk-F3UJ6ZRM.mjs +313 -0
- package/dist/chunk-F63N2ZTQ.js +7023 -0
- package/dist/chunk-F6XRYEM3.mjs +26 -0
- package/dist/chunk-FE6VCE4K.js +5030 -0
- package/dist/chunk-FLWD6GRR.js +1372 -0
- package/dist/chunk-FQBFWJBS.mjs +110 -0
- package/dist/chunk-FXVJ2HFU.js +26 -0
- package/dist/chunk-FZMQMQBW.js +312 -0
- package/dist/chunk-G3EEC44R.js +53 -0
- package/dist/{chunk-KG3WT4PR.mjs → chunk-GCKWKLZF.mjs} +73 -104
- package/dist/chunk-GCX7TY4D.mjs +6826 -0
- package/dist/chunk-GDB6TCSD.js +450 -0
- package/dist/chunk-GDCV4IWO.mjs +21 -0
- package/dist/chunk-GDZT5LZ5.js +170 -0
- package/dist/chunk-GHPUYD4I.mjs +213 -0
- package/dist/chunk-GHS6MIL6.mjs +1432 -0
- package/dist/chunk-GPS2THCL.mjs +11 -0
- package/dist/{chunk-EV2EVOYS.js → chunk-GTJWQAGU.js} +31 -42
- package/dist/chunk-GVTI6UJQ.mjs +130 -0
- package/dist/chunk-GXKI64OT.mjs +1138 -0
- package/dist/chunk-GYDYF2WX.js +275 -0
- package/dist/chunk-GYLP6UG4.mjs +705 -0
- package/dist/chunk-H3OQKK6X.js +1158 -0
- package/dist/chunk-H5DFSCJ6.js +40 -0
- package/dist/chunk-HAGEIC2L.mjs +186 -0
- package/dist/chunk-HAJ4JRFO.js +293 -0
- package/dist/chunk-HDR72GB6.js +188 -0
- package/dist/chunk-HF5HPS4T.mjs +40 -0
- package/dist/chunk-HK6LOFDS.js +218 -0
- package/dist/chunk-HMWYTXCY.mjs +143 -0
- package/dist/chunk-HPCSRCMA.js +89 -0
- package/dist/chunk-HSEO6TPU.js +247 -0
- package/dist/chunk-I5FOHCLH.js +132 -0
- package/dist/chunk-IDLW4NWA.mjs +85 -0
- package/dist/chunk-IIDZ5WUX.js +61 -0
- package/dist/chunk-IR74FJHU.js +2332 -0
- package/dist/chunk-IRVFYAKP.mjs +100 -0
- package/dist/{chunk-XBL3TMPC.mjs → chunk-IZDWAL53.mjs} +1795 -3287
- package/dist/chunk-J2KZXIU3.js +51 -0
- package/dist/chunk-J2U6PJSO.js +91 -0
- package/dist/chunk-J5AJNY2N.js +283 -0
- package/dist/chunk-J6KQZ4FO.mjs +821 -0
- package/dist/{chunk-OWW5GUSB.js → chunk-JGBCIKJV.js} +7 -6
- package/dist/chunk-JKGTBMU7.mjs +25 -0
- package/dist/chunk-JR3TNEQC.js +422 -0
- package/dist/chunk-JURRXY2J.mjs +29 -0
- package/dist/chunk-K3HW5I2A.mjs +317 -0
- package/dist/chunk-K46SMZ66.mjs +103 -0
- package/dist/chunk-K4UDGE3Z.mjs +6 -0
- package/dist/chunk-KDQOR4QQ.mjs +350 -0
- package/dist/chunk-KDTVOLHI.mjs +288 -0
- package/dist/chunk-KGHJH5KJ.mjs +35 -0
- package/dist/chunk-KIZOA5LX.mjs +140 -0
- package/dist/chunk-KK6HYVBI.mjs +242 -0
- package/dist/chunk-KMKWGXMK.js +856 -0
- package/dist/chunk-KPA6K5IB.js +80 -0
- package/dist/chunk-KU7O4IXU.mjs +260 -0
- package/dist/chunk-KVFNRJOR.mjs +11142 -0
- package/dist/chunk-KZJRSXHK.js +2432 -0
- package/dist/chunk-LHWPRUJL.js +79 -0
- package/dist/chunk-LIV3KXJG.mjs +369 -0
- package/dist/chunk-LKV4LACG.js +21 -0
- package/dist/chunk-LUY45X3U.mjs +263 -0
- package/dist/chunk-LYEZZEEF.mjs +17 -0
- package/dist/chunk-M5EXQZYY.mjs +1519 -0
- package/dist/chunk-ME6HGG4I.mjs +1338 -0
- package/dist/chunk-MEXP6DA6.js +31 -0
- package/dist/chunk-MG52AW3H.js +902 -0
- package/dist/chunk-MIPO6F72.js +334 -0
- package/dist/{chunk-5QW7CQBA.js → chunk-MKIJQL5Q.js} +211 -321
- package/dist/chunk-MN3YETVN.mjs +17 -0
- package/dist/chunk-MOBSBXVE.mjs +2391 -0
- package/dist/chunk-MOMOZEUM.mjs +88 -0
- package/dist/chunk-MRFUNRAP.js +62 -0
- package/dist/chunk-MTIHEW2M.js +433 -0
- package/dist/chunk-N4RGGDEL.mjs +73 -0
- package/dist/chunk-NH654HAT.js +10 -0
- package/dist/chunk-NHJUGZUR.mjs +253 -0
- package/dist/chunk-NMQT4HG3.mjs +757 -0
- package/dist/chunk-NPSYB6DC.mjs +906 -0
- package/dist/chunk-NW2GPMSO.js +857 -0
- package/dist/chunk-NXKQOQ6L.js +76 -0
- package/dist/chunk-NXLAZIJZ.js +309 -0
- package/dist/chunk-NYWNA5CF.js +148 -0
- package/dist/chunk-NZTKLY2W.js +1442 -0
- package/dist/chunk-O2ICABUD.js +36 -0
- package/dist/chunk-OIVVQQ22.js +862 -0
- package/dist/chunk-OKC2B4O3.mjs +312 -0
- package/dist/chunk-OLWFPDBK.js +2220 -0
- package/dist/chunk-OMTVH334.js +3779 -0
- package/dist/chunk-OQRVEM56.mjs +362 -0
- package/dist/chunk-OXMIBOD4.js +337 -0
- package/dist/chunk-PBL6YL5L.mjs +288 -0
- package/dist/chunk-PDOELNNQ.js +97 -0
- package/dist/chunk-PDQJY2GZ.js +136 -0
- package/dist/chunk-PKOZXD2Q.js +1274 -0
- package/dist/chunk-PPF2BYFL.mjs +2191 -0
- package/dist/chunk-PQTQKNKD.js +539 -0
- package/dist/chunk-PRSR4FAV.mjs +81 -0
- package/dist/chunk-PTRNO5UD.js +95 -0
- package/dist/chunk-Q2Y3VMKH.js +2000 -0
- package/dist/chunk-QCZOE65N.js +96 -0
- package/dist/chunk-QDYFLATW.mjs +52 -0
- package/dist/chunk-QQABGCMM.js +22 -0
- package/dist/chunk-QS6TRHMR.js +345 -0
- package/dist/chunk-R56P64LB.mjs +208 -0
- package/dist/chunk-RCQ2MPBV.js +428 -0
- package/dist/chunk-RFVRPYR2.mjs +856 -0
- package/dist/chunk-RKBLPGPV.js +11521 -0
- package/dist/chunk-RM2V4IND.mjs +327 -0
- package/dist/chunk-RQXN5A34.mjs +613 -0
- package/dist/chunk-RUVGVNOF.mjs +2687 -0
- package/dist/chunk-SAFJIGYB.mjs +165 -0
- package/dist/chunk-SKQFLBDD.js +263 -0
- package/dist/chunk-SMK6JU2F.mjs +2092 -0
- package/dist/{chunk-UVRPC2P7.js → chunk-SNNEOS5Z.js} +1984 -3476
- package/dist/chunk-SPCRQ6NO.mjs +1246 -0
- package/dist/chunk-SWX4SALA.mjs +19 -0
- package/dist/{chunk-JVODCGFP.mjs → chunk-SYEO2WV4.mjs} +128 -238
- package/dist/chunk-T2QQMX2N.js +10 -0
- package/dist/chunk-T3AFF3L7.mjs +57 -0
- package/dist/chunk-T6Z2EXYL.js +712 -0
- package/dist/chunk-T7LOXGYX.js +118 -0
- package/dist/chunk-TJCAE7RC.mjs +1315 -0
- package/dist/chunk-TJI3K6RP.js +137 -0
- package/dist/chunk-TL2SVO4P.mjs +55 -0
- package/dist/chunk-TM63CYGN.mjs +399 -0
- package/dist/chunk-TU5RYTYU.mjs +13 -0
- package/dist/chunk-TVJZ4GPS.js +1553 -0
- package/dist/chunk-TWM6DLYF.js +371 -0
- package/dist/chunk-U63OC4TQ.js +30 -0
- package/dist/{chunk-L5GKVQVJ.js → chunk-U6BVSJZ6.js} +25 -57
- package/dist/chunk-U6UVWEAK.mjs +792 -0
- package/dist/chunk-UCEPNO6N.mjs +11048 -0
- package/dist/{chunk-ANT574FD.js → chunk-UCR5HRYM.js} +74 -105
- package/dist/chunk-UG5BTOTF.mjs +334 -0
- package/dist/chunk-UGH37BQW.mjs +157 -0
- package/dist/chunk-V7ZRH3PY.mjs +271 -0
- package/dist/chunk-VBGHBL3E.mjs +1394 -0
- package/dist/chunk-VRBDAS5I.js +920 -0
- package/dist/chunk-VVE3Y76O.js +230 -0
- package/dist/chunk-W65JIRI4.mjs +1182 -0
- package/dist/chunk-WHYKAT7G.js +62 -0
- package/dist/{chunk-YOIVZ6OA.mjs → chunk-WIZRUIZB.mjs} +25 -57
- package/dist/chunk-WKWTDZS7.js +385 -0
- package/dist/chunk-WLMINRC4.mjs +78 -0
- package/dist/chunk-WOF3AD3J.js +22 -0
- package/dist/chunk-WWKMOA76.js +1262 -0
- package/dist/chunk-X5A5FOWW.js +615 -0
- package/dist/chunk-X6CN6KQF.mjs +192 -0
- package/dist/chunk-XD2PMH46.mjs +517 -0
- package/dist/chunk-XJA2NGTI.mjs +88 -0
- package/dist/chunk-XJIHN3BY.mjs +8 -0
- package/dist/chunk-XK6UDWJS.js +203 -0
- package/dist/chunk-XPG3N5CF.mjs +415 -0
- package/dist/chunk-XVZ2NKSU.mjs +74 -0
- package/dist/chunk-XYP45OLE.js +117 -0
- package/dist/chunk-XZSDGZX6.mjs +301 -0
- package/dist/chunk-Y2EMGN4T.mjs +120 -0
- package/dist/chunk-Y3XWP5XW.mjs +298 -0
- package/dist/chunk-Y4K22JL6.js +228 -0
- package/dist/chunk-Y65LXQGA.mjs +3164 -0
- package/dist/chunk-Y66WVMO5.mjs +87 -0
- package/dist/chunk-Y7JWLB25.mjs +7280 -0
- package/dist/chunk-YCDXAJKU.js +175 -0
- package/dist/chunk-YRDQCCIS.js +152 -0
- package/dist/chunk-YV52DGSA.js +111 -0
- package/dist/chunk-YXGZQPUD.js +94 -0
- package/dist/chunk-Z3A3AFVU.mjs +102 -0
- package/dist/chunk-ZCY6YKKP.mjs +475 -0
- package/dist/chunk-ZEQHXVU5.js +215 -0
- package/dist/chunk-ZF7JCXCI.js +284 -0
- package/dist/chunk-ZJBRUH6V.js +29 -0
- package/dist/chunk-ZMIL4ZOA.js +365 -0
- package/dist/chunk-ZR5ULMN2.mjs +337 -0
- package/dist/chunk-ZXREOYOW.js +87 -0
- package/dist/{client-BSP9U1O1.d.mts → client-CX_WR0-J.d.mts} +2 -2
- package/dist/client-Dytx_ZTC.d.ts +230 -0
- package/dist/{client-B878xeAP.d.ts → client-dqOhP9Nc.d.ts} +2 -2
- package/dist/client-hTKbCuhG.d.mts +230 -0
- package/dist/clock-B-UAjkKa.d.mts +5 -0
- package/dist/clock-B-UAjkKa.d.ts +5 -0
- package/dist/config-BlXQluJR.d.mts +36 -0
- package/dist/config-BlXQluJR.d.ts +36 -0
- package/dist/courier-Cnn-edJ4.d.ts +95 -0
- package/dist/courier-FmGfkvIN.d.mts +95 -0
- package/dist/crowd-DdHFbqKK.d.ts +186 -0
- package/dist/crowd-hOVSAmA3.d.mts +186 -0
- package/dist/danfo-BEBapFlX.d.mts +146 -0
- package/dist/danfo-UQ_PTIIx.d.ts +146 -0
- package/dist/{elements-Bty6Qs_N.d.mts → elements-DdsRig-2.d.mts} +1548 -257
- package/dist/{elements-Bty6Qs_N.d.ts → elements-DdsRig-2.d.ts} +1548 -257
- package/dist/engines/godot.d.mts +56 -0
- package/dist/engines/godot.d.ts +56 -0
- package/dist/engines/godot.js +28 -0
- package/dist/engines/godot.mjs +3 -0
- package/dist/engines/wasm.d.mts +11 -0
- package/dist/engines/wasm.d.ts +11 -0
- package/dist/engines/wasm.js +178 -0
- package/dist/engines/wasm.mjs +176 -0
- package/dist/fallback-CrG_lTFk.d.mts +270 -0
- package/dist/fallback-CrG_lTFk.d.ts +270 -0
- package/dist/fallback-KDB4Y2CE.mjs +6 -0
- package/dist/fallback-Y26TQENE.js +19 -0
- package/dist/features-CZB4rmcD.d.mts +118 -0
- package/dist/features-CZB4rmcD.d.ts +118 -0
- package/dist/fit-BWiE7rgA.d.mts +44 -0
- package/dist/fit-DK0oT7zO.d.ts +44 -0
- package/dist/five-a-side-Bv1AOUy3.d.mts +115 -0
- package/dist/five-a-side-EC51SJY1.d.ts +115 -0
- package/dist/fluid-ARr0qUIL.d.ts +939 -0
- package/dist/fluid-DLlEj2cs.d.mts +939 -0
- package/dist/game/conformance.d.mts +84 -0
- package/dist/game/conformance.d.ts +84 -0
- package/dist/game/conformance.js +1025 -0
- package/dist/game/conformance.mjs +994 -0
- package/dist/game/heap.d.mts +40 -0
- package/dist/game/heap.d.ts +40 -0
- package/dist/game/heap.js +48 -0
- package/dist/game/heap.mjs +7 -0
- package/dist/game/kit/canvas.d.mts +240 -0
- package/dist/game/kit/canvas.d.ts +240 -0
- package/dist/game/kit/canvas.js +3566 -0
- package/dist/game/kit/canvas.mjs +1039 -0
- package/dist/game/kit/courier.d.mts +17 -0
- package/dist/game/kit/courier.d.ts +17 -0
- package/dist/game/kit/courier.js +66 -0
- package/dist/game/kit/courier.mjs +49 -0
- package/dist/game/kit/danfo.d.mts +11 -0
- package/dist/game/kit/danfo.d.ts +11 -0
- package/dist/game/kit/danfo.js +109 -0
- package/dist/game/kit/danfo.mjs +44 -0
- package/dist/game/kit/engine.d.mts +29 -0
- package/dist/game/kit/engine.d.ts +29 -0
- package/dist/game/kit/engine.js +183 -0
- package/dist/game/kit/engine.mjs +30 -0
- package/dist/game/kit/five-a-side.d.mts +11 -0
- package/dist/game/kit/five-a-side.d.ts +11 -0
- package/dist/game/kit/five-a-side.js +86 -0
- package/dist/game/kit/five-a-side.mjs +41 -0
- package/dist/game/kit/frontier.d.mts +344 -0
- package/dist/game/kit/frontier.d.ts +344 -0
- package/dist/game/kit/frontier.js +435 -0
- package/dist/game/kit/frontier.mjs +14 -0
- package/dist/game/kit/genesis.d.mts +752 -0
- package/dist/game/kit/genesis.d.ts +752 -0
- package/dist/game/kit/genesis.js +380 -0
- package/dist/game/kit/genesis.mjs +15 -0
- package/dist/game/kit/ludo.d.mts +15 -0
- package/dist/game/kit/ludo.d.ts +15 -0
- package/dist/game/kit/ludo.js +87 -0
- package/dist/game/kit/ludo.mjs +42 -0
- package/dist/game/kit/runner.d.mts +12 -0
- package/dist/game/kit/runner.d.ts +12 -0
- package/dist/game/kit/runner.js +83 -0
- package/dist/game/kit/runner.mjs +46 -0
- package/dist/game/kit/shootout.d.mts +13 -0
- package/dist/game/kit/shootout.d.ts +13 -0
- package/dist/game/kit/shootout.js +122 -0
- package/dist/game/kit/shootout.mjs +57 -0
- package/dist/game/kit/slots.d.mts +392 -0
- package/dist/game/kit/slots.d.ts +392 -0
- package/dist/game/kit/slots.js +215 -0
- package/dist/game/kit/slots.mjs +6 -0
- package/dist/game/kit/tycoon.d.mts +16 -0
- package/dist/game/kit/tycoon.d.ts +16 -0
- package/dist/game/kit/tycoon.js +145 -0
- package/dist/game/kit/tycoon.mjs +44 -0
- package/dist/game/kit/word.d.mts +11 -0
- package/dist/game/kit/word.d.ts +11 -0
- package/dist/game/kit/word.js +78 -0
- package/dist/game/kit/word.mjs +41 -0
- package/dist/game/kit/worlds.d.mts +18 -0
- package/dist/game/kit/worlds.d.ts +18 -0
- package/dist/game/kit/worlds.js +74 -0
- package/dist/game/kit/worlds.mjs +49 -0
- package/dist/game/kit.d.mts +53 -0
- package/dist/game/kit.d.ts +53 -0
- package/dist/game/kit.js +2610 -0
- package/dist/game/kit.mjs +101 -0
- package/dist/game/prepared.d.mts +14 -0
- package/dist/game/prepared.d.ts +14 -0
- package/dist/game/prepared.js +81 -0
- package/dist/game/prepared.mjs +32 -0
- package/dist/game-Bx8onkhX.d.mts +1451 -0
- package/dist/game-fgQy2YIm.d.ts +1451 -0
- package/dist/game-theme-CBTw1b_d.d.mts +35 -0
- package/dist/game-theme-Dg-ict5A.d.ts +35 -0
- package/dist/game.d.mts +3546 -0
- package/dist/game.d.ts +3546 -0
- package/dist/game.js +4455 -0
- package/dist/game.mjs +50 -0
- package/dist/graphics-C6YjWYvP.d.ts +5 -0
- package/dist/graphics-Dk2yQnYN.d.mts +5 -0
- package/dist/guest-DrsA00XD.d.mts +732 -0
- package/dist/guest-wIdfoT05.d.ts +732 -0
- package/dist/hit-stop-BKkVwTq7.d.mts +43 -0
- package/dist/hit-stop-D-8pPYnM.d.ts +43 -0
- package/dist/hot-Crn9XpHJ.d.ts +29 -0
- package/dist/hot-DH3nOhQD.d.mts +29 -0
- package/dist/{index-CQStGb3B.d.mts → index-6gkHMGAq.d.mts} +2 -2
- package/dist/index-B8ybCKJI.d.ts +41 -0
- package/dist/{index-DJwXmoaP.d.ts → index-B98Xac8e.d.ts} +2 -2
- package/dist/{index-B7oA_1XI.d.ts → index-B_ByTtIT.d.ts} +2 -2
- package/dist/index-DHjNHb1c.d.mts +41 -0
- package/dist/{index-DhUSTAhT.d.mts → index-DbAN_VQE.d.mts} +2 -2
- package/dist/index.d.mts +134 -24
- package/dist/index.d.ts +134 -24
- package/dist/index.js +407 -248
- package/dist/index.mjs +184 -58
- package/dist/interactives-authoring.d.mts +231 -0
- package/dist/interactives-authoring.d.ts +231 -0
- package/dist/interactives-authoring.js +1743 -0
- package/dist/interactives-authoring.mjs +1704 -0
- package/dist/interactives-canvas.global.js +148 -0
- package/dist/interactives-guest.d.mts +20 -0
- package/dist/interactives-guest.d.ts +20 -0
- package/dist/interactives-guest.js +63 -0
- package/dist/interactives-guest.json +1 -0
- package/dist/interactives-guest.mjs +61 -0
- package/dist/interactives-jsc.global.js +9357 -0
- package/dist/interactives-meters.d.mts +93 -0
- package/dist/interactives-meters.d.ts +93 -0
- package/dist/interactives-meters.js +252 -0
- package/dist/interactives-meters.mjs +68 -0
- package/dist/interactives-production.d.mts +430 -0
- package/dist/interactives-production.d.ts +430 -0
- package/dist/interactives-production.js +1231 -0
- package/dist/interactives-production.mjs +1170 -0
- package/dist/interactives-record.d.mts +112 -0
- package/dist/interactives-record.d.ts +112 -0
- package/dist/interactives-record.js +302 -0
- package/dist/interactives-record.mjs +295 -0
- package/dist/interactives-runtime.d.mts +61 -0
- package/dist/interactives-runtime.d.ts +61 -0
- package/dist/interactives-runtime.js +442 -0
- package/dist/interactives-runtime.mjs +25 -0
- package/dist/interactives-studio-kernel.global.js +1 -0
- package/dist/interactives-studio.d.mts +806 -0
- package/dist/interactives-studio.d.ts +806 -0
- package/dist/interactives-studio.js +5741 -0
- package/dist/interactives-studio.mjs +5651 -0
- package/dist/interactives-tick.d.mts +90 -0
- package/dist/interactives-tick.d.ts +90 -0
- package/dist/interactives-tick.js +203 -0
- package/dist/interactives-tick.mjs +6 -0
- package/dist/interactives-web.d.mts +762 -0
- package/dist/interactives-web.d.ts +762 -0
- package/dist/interactives-web.js +5000 -0
- package/dist/interactives-web.mjs +4628 -0
- package/dist/interactives.d.mts +2430 -0
- package/dist/interactives.d.ts +2430 -0
- package/dist/interactives.js +5723 -0
- package/dist/interactives.mjs +4333 -0
- package/dist/juice-CoHxlpKA.d.ts +42 -0
- package/dist/juice-DQztFS43.d.mts +42 -0
- package/dist/launch-T2f4_Di4.d.mts +151 -0
- package/dist/launch-d6oreMzR.d.ts +151 -0
- package/dist/library-DXYaMFhi.d.mts +69 -0
- package/dist/library-DXYaMFhi.d.ts +69 -0
- package/dist/link-BUTqGmyi.d.mts +38 -0
- package/dist/link-BUTqGmyi.d.ts +38 -0
- package/dist/lint.js +104 -204
- package/dist/lint.mjs +103 -203
- package/dist/local-D8_I6UeL.d.mts +6967 -0
- package/dist/local-VZkqsCzR.d.ts +6967 -0
- package/dist/lockstep-BLf6dglI.d.mts +321 -0
- package/dist/lockstep-D50Ia0JW.d.ts +321 -0
- package/dist/ludo-B8ClkDqr.d.ts +205 -0
- package/dist/ludo-BOuohQ-M.d.mts +205 -0
- package/dist/mock/cli.mjs +200 -56
- package/dist/mock/library.js +200 -56
- package/dist/mock/library.mjs +200 -56
- package/dist/mock/msw.js +200 -56
- package/dist/mock/msw.mjs +200 -56
- package/dist/native-BodxSh03.d.mts +16 -0
- package/dist/native-DUHMT8gA.d.ts +16 -0
- package/dist/network-ZXLD7l1b.d.mts +19 -0
- package/dist/network-ZXLD7l1b.d.ts +19 -0
- package/dist/online-XeymeM9s.d.ts +381 -0
- package/dist/online-d7W_Al9a.d.mts +381 -0
- package/dist/params-DxFb5G_U.d.mts +155 -0
- package/dist/params-DxFb5G_U.d.ts +155 -0
- package/dist/play-BRRlfLhX.d.ts +940 -0
- package/dist/play-ClrMd_e8.d.mts +940 -0
- package/dist/policy-CCw8tXLm.d.mts +3078 -0
- package/dist/policy-CMqOSQIu.d.ts +3078 -0
- package/dist/ports-B_0v_P3A.d.mts +13 -0
- package/dist/ports-CGU_3e_0.d.ts +13 -0
- package/dist/prefetch-BHnicOQj.d.ts +117 -0
- package/dist/prefetch-CBXgYacv.d.mts +117 -0
- package/dist/{price-CSztR02F.d.mts → price-BOzexBww.d.mts} +1 -1
- package/dist/{price-C_vasx9A.d.ts → price-C1h9sPxE.d.ts} +1 -1
- package/dist/protocol-C8qbpUbT.d.mts +242 -0
- package/dist/protocol-C8qbpUbT.d.ts +242 -0
- package/dist/rapier-AZHT4YI7.js +7886 -0
- package/dist/rapier-ODEPCQA6.mjs +7792 -0
- package/dist/react.d.mts +157 -15
- package/dist/react.d.ts +157 -15
- package/dist/react.js +5564 -5904
- package/dist/react.mjs +5451 -5808
- package/dist/runner-CQcLL7By.d.ts +189 -0
- package/dist/runner-D46Yj-wE.d.mts +189 -0
- package/dist/runtime-BRWfkf_q.d.mts +51 -0
- package/dist/runtime-DyuBMkKM.d.ts +51 -0
- package/dist/scheduling-D2ajXpMC.d.ts +224 -0
- package/dist/scheduling-DSRbbaZb.d.mts +224 -0
- package/dist/schema-BrWxzKp6.d.mts +63 -0
- package/dist/schema-BrWxzKp6.d.ts +63 -0
- package/dist/server/evict.js +34 -37
- package/dist/server/evict.mjs +34 -37
- package/dist/server/tanstack.d.mts +49 -3
- package/dist/server/tanstack.d.ts +49 -3
- package/dist/server/tanstack.js +169 -117
- package/dist/server/tanstack.mjs +166 -118
- package/dist/{server-Dckg4Vdr.d.ts → server-D29IIuDV.d.ts} +136 -130
- package/dist/{server-B6dW7-Lj.d.mts → server-DQMWPnc8.d.mts} +136 -130
- package/dist/server.d.mts +45 -5
- package/dist/server.d.ts +45 -5
- package/dist/server.js +171 -227
- package/dist/server.mjs +165 -225
- package/dist/session-grant-CJ27DwrT.d.mts +19 -0
- package/dist/session-grant-CJ27DwrT.d.ts +19 -0
- package/dist/shootout-BJZeX6FG.d.ts +140 -0
- package/dist/shootout-tcZd1Rxt.d.mts +140 -0
- package/dist/state-replica-stMtdkVD.d.mts +42 -0
- package/dist/state-replica-stMtdkVD.d.ts +42 -0
- package/dist/studio-CowqWqez.d.mts +14 -0
- package/dist/studio-CowqWqez.d.ts +14 -0
- package/dist/styles.css +1 -1
- package/dist/template-AhCdB1kW.d.mts +190 -0
- package/dist/template-BkEGVTQj.d.ts +190 -0
- package/dist/terrain-BMxEc6Oc.d.ts +429 -0
- package/dist/terrain-C-XC1Oui.d.mts +429 -0
- package/dist/testing/msw.d.mts +28 -4
- package/dist/testing/msw.d.ts +28 -4
- package/dist/testing/msw.js +15 -21
- package/dist/testing/msw.mjs +15 -21
- package/dist/testing/suite.d.mts +6 -5
- package/dist/testing/suite.d.ts +6 -5
- package/dist/testing/suite.js +89 -124
- package/dist/testing/suite.mjs +81 -116
- package/dist/testing.d.mts +27 -1227
- package/dist/testing.d.ts +27 -1227
- package/dist/testing.js +127 -131
- package/dist/testing.mjs +19 -23
- package/dist/tick-transport-C8QEh8Uw.d.mts +50 -0
- package/dist/tick-transport-UjHY3xK1.d.ts +50 -0
- package/dist/timeline-protocol-hp6e8zFB.d.mts +47 -0
- package/dist/timeline-protocol-hp6e8zFB.d.ts +47 -0
- package/dist/tokens-DhanQRQS.d.mts +21 -0
- package/dist/tokens-K8yxwd6G.d.ts +21 -0
- package/dist/tree-C-Io2Hbx.d.mts +35 -0
- package/dist/tree-CP_qSW4H.d.ts +35 -0
- package/dist/tycoon-B5KHk2Xx.d.mts +255 -0
- package/dist/tycoon-hmHo-3HX.d.ts +255 -0
- package/dist/types-BQkxPwZP.d.mts +219 -0
- package/dist/types-D_f6UUxM.d.ts +219 -0
- package/dist/ui-DwHicuFv.d.mts +563 -0
- package/dist/ui-hi7S2YcH.d.ts +563 -0
- package/dist/{sign-in-DQlIdqsi.d.mts → url-52ndUruG.d.mts} +15 -1
- package/dist/{sign-in-DQlIdqsi.d.ts → url-52ndUruG.d.ts} +15 -1
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +37 -37
- package/dist/utils.mjs +4 -4
- package/dist/vars-Dc_PrhBK.d.mts +511 -0
- package/dist/vars-Dc_PrhBK.d.ts +511 -0
- package/dist/vm-IUARFFAI.mjs +63 -0
- package/dist/vm-N7L6MGGH.js +65 -0
- package/dist/weave-delivery-CW-Kstut.d.mts +360 -0
- package/dist/weave-delivery-CW-Kstut.d.ts +360 -0
- package/dist/web-Dss74a7v.d.ts +883 -0
- package/dist/web-f9ZQPoyw.d.mts +883 -0
- package/dist/web-transport-C7MkBL0a.d.ts +19 -0
- package/dist/web-transport-aYEqXMd9.d.mts +19 -0
- package/dist/weight-CPGjsgjV.d.ts +92 -0
- package/dist/weight-tF1ODR1p.d.mts +92 -0
- package/dist/word-BcX9Jcmv.d.mts +70 -0
- package/dist/word-C7sVPLHm.d.ts +70 -0
- package/dist/world-PvILHDR1.d.ts +2285 -0
- package/dist/world-qekkXjJv.d.mts +2285 -0
- package/dist/worlds-Br2Pb0Cs.d.ts +109 -0
- package/dist/worlds-D5ydYr7d.d.mts +109 -0
- package/engines/c/cimplify.h +108 -0
- package/engines/c/cimplify.lib.js +11 -0
- package/engines/godot/addons/cimplify/cimplify.gd +97 -0
- package/engines/rust/interactives-ctx/Cargo.toml +9 -0
- package/engines/rust/interactives-ctx/src/lib.rs +189 -0
- package/package.json +189 -3
- package/vendor/rapier3d-compat/LICENSE +201 -0
- package/vendor/rapier3d-compat/PATCHES.md +61 -0
- package/dist/chunk-2P4KXFB6.js +0 -274
- package/dist/chunk-3G6RQLXK.mjs +0 -21
- package/dist/chunk-3V4DVXV3.mjs +0 -254
- package/dist/chunk-EDK3LNM6.js +0 -2436
- package/dist/chunk-F7J3HK27.js +0 -4549
- package/dist/chunk-U4MW6PYU.mjs +0 -23
- package/dist/chunk-XREIZ56K.js +0 -26
|
@@ -0,0 +1,1372 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkRCQ2MPBV_js = require('./chunk-RCQ2MPBV.js');
|
|
4
|
+
var chunkMRFUNRAP_js = require('./chunk-MRFUNRAP.js');
|
|
5
|
+
var chunkIIDZ5WUX_js = require('./chunk-IIDZ5WUX.js');
|
|
6
|
+
require('./chunk-T2QQMX2N.js');
|
|
7
|
+
var chunkKZJRSXHK_js = require('./chunk-KZJRSXHK.js');
|
|
8
|
+
var chunkIR74FJHU_js = require('./chunk-IR74FJHU.js');
|
|
9
|
+
var chunk2V7IL4HC_js = require('./chunk-2V7IL4HC.js');
|
|
10
|
+
|
|
11
|
+
// src/game/kernel/train.ts
|
|
12
|
+
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;
|
|
13
|
+
function invalid(message2) {
|
|
14
|
+
throw new chunk2V7IL4HC_js.GameError("invalid_argument", message2);
|
|
15
|
+
}
|
|
16
|
+
function joinMemory(data) {
|
|
17
|
+
let memory = data.memory;
|
|
18
|
+
if (memory === void 0) return data;
|
|
19
|
+
let { samples } = data, width = memory.width;
|
|
20
|
+
(!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`);
|
|
21
|
+
let features = data.inputs.length / samples, actions = data.targets.length / samples, inputs = new Float32Array(samples * (features + width)), targets = new Float32Array(samples * (actions + width));
|
|
22
|
+
for (let s = 0; s < samples; s++) {
|
|
23
|
+
let i = s * (features + width), t = s * (actions + width);
|
|
24
|
+
for (let k = 0; k < features; k++) inputs[i + k] = data.inputs[s * features + k];
|
|
25
|
+
for (let k = 0; k < width; k++) inputs[i + features + k] = memory.previous[s * width + k];
|
|
26
|
+
for (let k = 0; k < actions; k++) targets[t + k] = data.targets[s * actions + k];
|
|
27
|
+
for (let k = 0; k < width; k++) targets[t + actions + k] = memory.next[s * width + k];
|
|
28
|
+
}
|
|
29
|
+
return { samples, inputs, targets };
|
|
30
|
+
}
|
|
31
|
+
function memorySamples(episodes) {
|
|
32
|
+
let first = episodes.find((e) => e.inputs.length > 0);
|
|
33
|
+
first === void 0 && invalid("memory training needs at least one episode with a step");
|
|
34
|
+
let features = first.inputs[0].length, actions = first.targets[0]?.length ?? 0, width = first.memory[0]?.length ?? 0, samples = 0;
|
|
35
|
+
for (let episode of episodes)
|
|
36
|
+
(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;
|
|
37
|
+
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) => {
|
|
38
|
+
values.length !== length && invalid(`every ${what} row has ${length} numbers`), out.set(values, at * length);
|
|
39
|
+
};
|
|
40
|
+
for (let episode of episodes)
|
|
41
|
+
for (let t = 0; t < episode.inputs.length; t++, s++)
|
|
42
|
+
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");
|
|
43
|
+
return { samples, inputs, targets, memory: { width, previous, next } };
|
|
44
|
+
}
|
|
45
|
+
var Random = class {
|
|
46
|
+
constructor(seed) {
|
|
47
|
+
this.state = seed >>> 0 || (2654435769);
|
|
48
|
+
}
|
|
49
|
+
next() {
|
|
50
|
+
let x = this.state;
|
|
51
|
+
return x ^= x << 13, x >>>= 0, x ^= x >>> 17, x ^= x << 5, this.state = x >>> 0, this.state;
|
|
52
|
+
}
|
|
53
|
+
unit() {
|
|
54
|
+
return (this.next() >>> (8)) * UNIT_SCALE;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function roundHalfEven(x) {
|
|
58
|
+
let r = Math.floor(x), d = x - r;
|
|
59
|
+
return d > (0.5) ? r + 1 : d < (0.5) || r % 2 === 0 ? r : r + 1;
|
|
60
|
+
}
|
|
61
|
+
function clamp(x, low, high) {
|
|
62
|
+
return x < low ? low : x > high ? high : x;
|
|
63
|
+
}
|
|
64
|
+
function maxAbs(values) {
|
|
65
|
+
let m = 0;
|
|
66
|
+
for (let k = 0; k < values.length; k++) {
|
|
67
|
+
let a = Math.abs(values[k]);
|
|
68
|
+
a > m && (m = a);
|
|
69
|
+
}
|
|
70
|
+
return m;
|
|
71
|
+
}
|
|
72
|
+
function scaleOf(max) {
|
|
73
|
+
return max > 0 ? fr(max / (127)) : fr(1 / (127));
|
|
74
|
+
}
|
|
75
|
+
function check(data, widths) {
|
|
76
|
+
let fail = (message2) => {
|
|
77
|
+
throw new chunk2V7IL4HC_js.GameError("invalid_argument", message2);
|
|
78
|
+
};
|
|
79
|
+
(widths.length < 2 || widths.length - 1 > chunkKZJRSXHK_js.MLP_MAX_LAYERS) && fail(`a network has 1 to ${chunkKZJRSXHK_js.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 > chunkIR74FJHU_js.MLP_MAX_WIDTH) && fail(`inputs and hidden layers are at most ${chunkIR74FJHU_js.MLP_MAX_WIDTH} wide`), widths[widths.length - 1] > chunkIR74FJHU_js.MLP_MAX_OUTPUTS && fail(`a network has at most ${chunkIR74FJHU_js.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`);
|
|
80
|
+
}
|
|
81
|
+
function layersOf(widths, random) {
|
|
82
|
+
let layers = [];
|
|
83
|
+
for (let l = 0; l + 1 < widths.length; l++) {
|
|
84
|
+
let inputs = widths[l], outputs = widths[l + 1], limit = fr(Math.sqrt(fr((6) / inputs))), w = new Float32Array(inputs * outputs);
|
|
85
|
+
for (let k = 0; k < w.length; k++) w[k] = fr(fr(fr(random.unit() * 2) - 1) * limit);
|
|
86
|
+
let size = inputs * outputs;
|
|
87
|
+
layers.push({
|
|
88
|
+
inputs,
|
|
89
|
+
outputs,
|
|
90
|
+
w,
|
|
91
|
+
b: new Float32Array(outputs),
|
|
92
|
+
vw: new Float32Array(size),
|
|
93
|
+
vb: new Float32Array(outputs),
|
|
94
|
+
gw: new Float32Array(size),
|
|
95
|
+
gb: new Float32Array(outputs),
|
|
96
|
+
wq: new Float32Array(size),
|
|
97
|
+
z: new Float32Array(outputs),
|
|
98
|
+
a: new Float32Array(outputs),
|
|
99
|
+
da: new Float32Array(inputs),
|
|
100
|
+
wScale: 1,
|
|
101
|
+
aScale: 1
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return layers;
|
|
105
|
+
}
|
|
106
|
+
function quantizeWeights(layer) {
|
|
107
|
+
layer.wScale = scaleOf(maxAbs(layer.w));
|
|
108
|
+
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);
|
|
109
|
+
}
|
|
110
|
+
function quantizeInput(x, scale, unit) {
|
|
111
|
+
let raw = fr(fr(x) * scale), t = Number.isNaN(raw) ? 0 : clamp(raw, -(256), (256));
|
|
112
|
+
return fr(clamp(roundHalfEven(t), (-128), (127)) * unit);
|
|
113
|
+
}
|
|
114
|
+
function forward(layers, input, quantizeActs) {
|
|
115
|
+
let prev = input;
|
|
116
|
+
layers.forEach((layer, l) => {
|
|
117
|
+
let last = l + 1 === layers.length;
|
|
118
|
+
for (let j = 0; j < layer.outputs; j++) {
|
|
119
|
+
let acc = layer.b[j], row = j * layer.inputs;
|
|
120
|
+
for (let i = 0; i < layer.inputs; i++) acc = fr(acc + fr(layer.wq[row + i] * prev[i]));
|
|
121
|
+
if (layer.z[j] = acc, last) layer.a[j] = acc;
|
|
122
|
+
else {
|
|
123
|
+
let r = acc > 0 ? acc : 0;
|
|
124
|
+
layer.a[j] = quantizeActs ? fr(clamp(roundHalfEven(fr(r / layer.aScale)), 0, (127)) * layer.aScale) : r;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
prev = layer.a;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function backward(layers, input, error) {
|
|
131
|
+
let delta = error;
|
|
132
|
+
for (let l = layers.length - 1; l >= 0; l--) {
|
|
133
|
+
let layer = layers[l], prev = l === 0 ? input : layers[l - 1].a;
|
|
134
|
+
layer.da.fill(0);
|
|
135
|
+
for (let j = 0; j < layer.outputs; j++) {
|
|
136
|
+
let g = delta[j];
|
|
137
|
+
if (g === 0) continue;
|
|
138
|
+
let row = j * layer.inputs;
|
|
139
|
+
layer.gb[j] = fr(layer.gb[j] + g);
|
|
140
|
+
for (let i = 0; i < layer.inputs; i++)
|
|
141
|
+
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]));
|
|
142
|
+
}
|
|
143
|
+
if (l > 0) {
|
|
144
|
+
let below = layers[l - 1];
|
|
145
|
+
for (let i = 0; i < layer.inputs; i++) below.z[i] > 0 || (layer.da[i] = 0);
|
|
146
|
+
}
|
|
147
|
+
delta = layer.da;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function step(layers, size, momentum) {
|
|
151
|
+
for (let layer of layers) {
|
|
152
|
+
for (let k = 0; k < layer.w.length; k++)
|
|
153
|
+
layer.vw[k] = fr(fr(momentum * layer.vw[k]) - fr(size * layer.gw[k])), layer.w[k] = fr(layer.w[k] + layer.vw[k]);
|
|
154
|
+
for (let j = 0; j < layer.outputs; j++)
|
|
155
|
+
layer.vb[j] = fr(fr(momentum * layer.vb[j]) - fr(size * layer.gb[j])), layer.b[j] = fr(layer.b[j] + layer.vb[j]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function begin(layers) {
|
|
159
|
+
for (let layer of layers)
|
|
160
|
+
quantizeWeights(layer), layer.gw.fill(0), layer.gb.fill(0);
|
|
161
|
+
}
|
|
162
|
+
function calibrate(layers, data, inputScale2, inputUnit, input) {
|
|
163
|
+
let peaks = new Float32Array(layers.length);
|
|
164
|
+
for (let s = 0; s < data.samples; s++) {
|
|
165
|
+
for (let i = 0; i < input.length; i++) input[i] = quantizeInput(data.inputs[s * input.length + i], inputScale2, inputUnit);
|
|
166
|
+
forward(layers, input, false);
|
|
167
|
+
for (let l = 0; l + 1 < layers.length; l++) for (let v of layers[l].a) v > peaks[l] && (peaks[l] = v);
|
|
168
|
+
}
|
|
169
|
+
for (let l = 0; l + 1 < layers.length; l++) layers[l].aScale = scaleOf(peaks[l]);
|
|
170
|
+
}
|
|
171
|
+
function shiftFor(m) {
|
|
172
|
+
for (let shift = chunkKZJRSXHK_js.MLP_MAX_SHIFT; shift >= 0; shift--) {
|
|
173
|
+
let multiplier = Math.floor(m * 2 ** shift + (0.5));
|
|
174
|
+
if (multiplier < chunkKZJRSXHK_js.MLP_MULTIPLIER_LIMIT) return [multiplier, shift];
|
|
175
|
+
}
|
|
176
|
+
return [chunkKZJRSXHK_js.MLP_MULTIPLIER_LIMIT - 1, 0];
|
|
177
|
+
}
|
|
178
|
+
function exportBlob(layers, inputScale2, inputUnit) {
|
|
179
|
+
let specs = [], unit = inputUnit;
|
|
180
|
+
return layers.forEach((layer, l) => {
|
|
181
|
+
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)), -chunkKZJRSXHK_js.MLP_ACC_LIMIT, chunkKZJRSXHK_js.MLP_ACC_LIMIT));
|
|
182
|
+
if (last) {
|
|
183
|
+
specs.push({ outputs: layer.outputs, activation: chunkKZJRSXHK_js.MLP_ACT_LINEAR, multiplier: 0, shift: 0, zero: 0, scale: accScale, bias, weights });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let [multiplier, shift] = shiftFor(accScale / layer.aScale);
|
|
187
|
+
specs.push({ outputs: layer.outputs, activation: chunkKZJRSXHK_js.MLP_ACT_RELU, multiplier, shift, zero: 0, scale: layer.aScale, bias, weights }), unit = layer.aScale;
|
|
188
|
+
}), chunkKZJRSXHK_js.mlpBlob(layers[0].inputs, inputScale2, 0, specs);
|
|
189
|
+
}
|
|
190
|
+
function blobLoss(blob, data, inputs, outputs) {
|
|
191
|
+
let net = chunkKZJRSXHK_js.parseMlp(blob, blob.length, inputs, outputs);
|
|
192
|
+
if (net === null) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "the trained network did not pack into a valid file");
|
|
193
|
+
let bits = new Float32Array(inputs), words = new Uint32Array(bits.buffer), out = new Uint32Array(outputs), view = new Float32Array(out.buffer), total = 0;
|
|
194
|
+
for (let s = 0; s < data.samples; s++) {
|
|
195
|
+
for (let i = 0; i < inputs; i++) bits[i] = data.inputs[s * inputs + i];
|
|
196
|
+
chunkKZJRSXHK_js.evalMlp(net, words, out);
|
|
197
|
+
for (let j = 0; j < outputs; j++) {
|
|
198
|
+
let e = fr(view[j] - fr(data.targets[s * outputs + j]));
|
|
199
|
+
total = fr(total + fr(fr(e * e) * (0.5)));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return fr(total / data.samples);
|
|
203
|
+
}
|
|
204
|
+
function trainMlp(source, options) {
|
|
205
|
+
let data = joinMemory(source), widths = options.widths;
|
|
206
|
+
check(data, widths);
|
|
207
|
+
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;
|
|
208
|
+
for (let k = 0; k < data.inputs.length; k++) {
|
|
209
|
+
let a = Math.abs(fr(data.inputs[k]));
|
|
210
|
+
a > peak && (peak = a);
|
|
211
|
+
}
|
|
212
|
+
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);
|
|
213
|
+
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
214
|
+
for (let layer of layers) quantizeWeights(layer);
|
|
215
|
+
calibrate(layers, data, inputScale2, inputUnit, input);
|
|
216
|
+
for (let k = data.samples - 1; k > 0; k--) {
|
|
217
|
+
let j = random.next() % (k + 1), t = order[k];
|
|
218
|
+
order[k] = order[j], order[j] = t;
|
|
219
|
+
}
|
|
220
|
+
let total = 0;
|
|
221
|
+
for (let start = 0; start < data.samples; start += batch) {
|
|
222
|
+
let end = Math.min(start + batch, data.samples);
|
|
223
|
+
begin(layers);
|
|
224
|
+
for (let k = start; k < end; k++) {
|
|
225
|
+
let s = order[k];
|
|
226
|
+
for (let i = 0; i < inputs; i++) input[i] = quantizeInput(data.inputs[s * inputs + i], inputScale2, inputUnit);
|
|
227
|
+
forward(layers, input, true);
|
|
228
|
+
let top = layers[layers.length - 1];
|
|
229
|
+
for (let j = 0; j < outputs; j++) {
|
|
230
|
+
let e = fr(top.a[j] - fr(data.targets[s * outputs + j]));
|
|
231
|
+
error[j] = e, total = fr(total + fr(fr(e * e) * (0.5)));
|
|
232
|
+
}
|
|
233
|
+
backward(layers, input, error);
|
|
234
|
+
}
|
|
235
|
+
step(layers, fr(rate / (end - start)), momentum);
|
|
236
|
+
}
|
|
237
|
+
loss[epoch] = fr(total / data.samples);
|
|
238
|
+
}
|
|
239
|
+
for (let layer of layers) quantizeWeights(layer);
|
|
240
|
+
calibrate(layers, data, inputScale2, inputUnit, input);
|
|
241
|
+
let blob = exportBlob(layers, inputScale2, inputUnit);
|
|
242
|
+
return { blob, loss, blobLoss: blobLoss(blob, data, inputs, outputs) };
|
|
243
|
+
}
|
|
244
|
+
var MOE_DEFAULT_BALANCE = 0.5;
|
|
245
|
+
function halfSquared(y, data, at) {
|
|
246
|
+
let total = 0;
|
|
247
|
+
for (let j = 0; j < y.length; j++) {
|
|
248
|
+
let e = fr(y[j] - fr(data.targets[at + j]));
|
|
249
|
+
total = fr(total + fr(fr(e * e) * (0.5)));
|
|
250
|
+
}
|
|
251
|
+
return total;
|
|
252
|
+
}
|
|
253
|
+
function topOf(values) {
|
|
254
|
+
let best = 0;
|
|
255
|
+
for (let j = 1; j < values.length; j++) values[j] > values[best] && (best = j);
|
|
256
|
+
return best;
|
|
257
|
+
}
|
|
258
|
+
function assign(errors, counts, len, balance) {
|
|
259
|
+
let experts = errors.length, best = 0, low = Number.POSITIVE_INFINITY;
|
|
260
|
+
for (let e = 0; e < experts; e++) {
|
|
261
|
+
let load = fr(fr(counts[e] * experts) / len), score = fr(errors[e] * fr(1 + fr(balance * load)));
|
|
262
|
+
score < low && (low = score, best = e);
|
|
263
|
+
}
|
|
264
|
+
return best;
|
|
265
|
+
}
|
|
266
|
+
function lastOf(layers) {
|
|
267
|
+
return layers[layers.length - 1];
|
|
268
|
+
}
|
|
269
|
+
function trainMoe(source, options) {
|
|
270
|
+
let data = joinMemory(source), count = options.experts;
|
|
271
|
+
(!Number.isInteger(count) || count < chunkKZJRSXHK_js.MOE_MIN_EXPERTS || count > chunkKZJRSXHK_js.MOE_MAX_EXPERTS) && invalid(`a mixture has ${chunkKZJRSXHK_js.MOE_MIN_EXPERTS} to ${chunkKZJRSXHK_js.MOE_MAX_EXPERTS} experts`), (!Number.isInteger(data.samples) || data.samples < 1) && invalid("training needs at least one sample");
|
|
272
|
+
let inputs = data.inputs.length / data.samples, outputs = data.targets.length / data.samples, routerWidths = [inputs, ...options.router ?? [], count], expertWidths = [inputs, ...options.expert ?? [], outputs];
|
|
273
|
+
check(data, expertWidths), check({ samples: data.samples, inputs: data.inputs, targets: new Float32Array(data.samples * count) }, routerWidths);
|
|
274
|
+
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;
|
|
275
|
+
for (let k = 0; k < data.inputs.length; k++) {
|
|
276
|
+
let a = Math.abs(fr(data.inputs[k]));
|
|
277
|
+
a > peak && (peak = a);
|
|
278
|
+
}
|
|
279
|
+
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];
|
|
280
|
+
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
281
|
+
for (let layers of all) for (let layer of layers) quantizeWeights(layer);
|
|
282
|
+
for (let layers of all) calibrate(layers, data, inputScale2, inputUnit, input);
|
|
283
|
+
for (let k = data.samples - 1; k > 0; k--) {
|
|
284
|
+
let j = random.next() % (k + 1), t = order[k];
|
|
285
|
+
order[k] = order[j], order[j] = t;
|
|
286
|
+
}
|
|
287
|
+
let total = 0;
|
|
288
|
+
for (let start = 0; start < data.samples; start += batch) {
|
|
289
|
+
let end = Math.min(start + batch, data.samples), len = end - start;
|
|
290
|
+
for (let layers of all) begin(layers);
|
|
291
|
+
counts.fill(0);
|
|
292
|
+
for (let k = start; k < end; k++) {
|
|
293
|
+
let s = order[k];
|
|
294
|
+
for (let i = 0; i < inputs; i++) input[i] = quantizeInput(data.inputs[s * inputs + i], inputScale2, inputUnit);
|
|
295
|
+
for (let e = 0; e < count; e++)
|
|
296
|
+
forward(experts[e], input, true), errors[e] = halfSquared(lastOf(experts[e]).a, data, s * outputs);
|
|
297
|
+
forward(router, input, true), total = fr(total + errors[topOf(lastOf(router).a)]);
|
|
298
|
+
let best = assign(errors, counts, len, balance);
|
|
299
|
+
counts[best]++;
|
|
300
|
+
let top = lastOf(experts[best]).a;
|
|
301
|
+
for (let j = 0; j < outputs; j++) error[j] = fr(top[j] - fr(data.targets[s * outputs + j]));
|
|
302
|
+
backward(experts[best], input, error);
|
|
303
|
+
let z = lastOf(router).a;
|
|
304
|
+
for (let j = 0; j < count; j++) routeError[j] = fr(z[j] - (j === best ? 1 : 0));
|
|
305
|
+
backward(router, input, routeError);
|
|
306
|
+
}
|
|
307
|
+
step(router, fr(rate / len), momentum);
|
|
308
|
+
for (let e = 0; e < count; e++) step(experts[e], fr(rate / Math.max(counts[e], 1)), momentum);
|
|
309
|
+
}
|
|
310
|
+
loss[epoch] = fr(total / data.samples);
|
|
311
|
+
}
|
|
312
|
+
for (let layers of all) for (let layer of layers) quantizeWeights(layer);
|
|
313
|
+
for (let layers of all) calibrate(layers, data, inputScale2, inputUnit, input);
|
|
314
|
+
let blob = chunkKZJRSXHK_js.moeBlob(inputs, outputs, exportBlob(router, inputScale2, inputUnit), experts.map((e) => exportBlob(e, inputScale2, inputUnit))), net = chunkKZJRSXHK_js.parseMoe(blob, blob.length, inputs, outputs);
|
|
315
|
+
if (net === null) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "the trained mixture did not pack into a valid file");
|
|
316
|
+
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;
|
|
317
|
+
for (let s = 0; s < data.samples; s++) {
|
|
318
|
+
for (let i = 0; i < inputs; i++) bits[i] = data.inputs[s * inputs + i];
|
|
319
|
+
usage[chunkKZJRSXHK_js.evalMoeLane(net, words, 0, 1, out)]++;
|
|
320
|
+
for (let j = 0; j < outputs; j++) {
|
|
321
|
+
let e = fr(view[j] - fr(data.targets[s * outputs + j]));
|
|
322
|
+
shipped = fr(shipped + fr(fr(e * e) * (0.5)));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return { blob, loss, blobLoss: fr(shipped / data.samples), usage };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/game/kernel/import.ts
|
|
329
|
+
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 chunk2V7IL4HC_js.GameError {
|
|
330
|
+
constructor(message2) {
|
|
331
|
+
super("invalid_argument", message2), this.name = "ImportError";
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
function malformed(what) {
|
|
335
|
+
throw new ImportError(`the model file is malformed: ${what}`);
|
|
336
|
+
}
|
|
337
|
+
function unsupported(what) {
|
|
338
|
+
throw new ImportError(`${what}; the importer reads ${IMPORT_SUPPORTED_OPS}`);
|
|
339
|
+
}
|
|
340
|
+
function shape(what) {
|
|
341
|
+
throw new ImportError(what);
|
|
342
|
+
}
|
|
343
|
+
function varint(bytes, at) {
|
|
344
|
+
let value = 0, scale = 1;
|
|
345
|
+
for (let n = 0; n < (10); n++) {
|
|
346
|
+
at.k >= bytes.length && malformed("a number runs past the end");
|
|
347
|
+
let byte = bytes[at.k++];
|
|
348
|
+
if (value += (byte & (127)) * scale, (byte & (128)) === 0) return value;
|
|
349
|
+
scale *= (128);
|
|
350
|
+
}
|
|
351
|
+
malformed("a number is too long");
|
|
352
|
+
}
|
|
353
|
+
function take(bytes, at, len) {
|
|
354
|
+
(len < 0 || at.k + len > bytes.length) && malformed("a field runs past the end");
|
|
355
|
+
let out = bytes.subarray(at.k, at.k + len);
|
|
356
|
+
return at.k += len, out;
|
|
357
|
+
}
|
|
358
|
+
function fields(bytes) {
|
|
359
|
+
let out = [], at = { k: 0 };
|
|
360
|
+
for (; at.k < bytes.length; ) {
|
|
361
|
+
let key = varint(bytes, at), number = Math.floor(key / (8));
|
|
362
|
+
switch (key % (8) & (7)) {
|
|
363
|
+
case (0):
|
|
364
|
+
out.push({ number, wire: { t: "varint", v: varint(bytes, at) } });
|
|
365
|
+
break;
|
|
366
|
+
case (1):
|
|
367
|
+
take(bytes, at, (8)), out.push({ number, wire: { t: "fixed64" } });
|
|
368
|
+
break;
|
|
369
|
+
case (2):
|
|
370
|
+
out.push({ number, wire: { t: "bytes", b: take(bytes, at, varint(bytes, at)) } });
|
|
371
|
+
break;
|
|
372
|
+
case (5): {
|
|
373
|
+
let b = take(bytes, at, (4));
|
|
374
|
+
out.push({ number, wire: { t: "fixed32", w: new DataView(b.buffer, b.byteOffset, (4)).getUint32(0, true) } });
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
default:
|
|
378
|
+
malformed("a field has an unknown wire type");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
function text(field) {
|
|
384
|
+
field.wire.t !== "bytes" && malformed("a name is not a string");
|
|
385
|
+
try {
|
|
386
|
+
return decoder.decode(field.wire.b);
|
|
387
|
+
} catch {
|
|
388
|
+
malformed("a name is not UTF-8");
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function message(field) {
|
|
392
|
+
return field.wire.t !== "bytes" && malformed("a message field is not length-delimited"), field.wire.b;
|
|
393
|
+
}
|
|
394
|
+
function floatBits(word) {
|
|
395
|
+
return new Float32Array(Uint32Array.of(word).buffer)[0];
|
|
396
|
+
}
|
|
397
|
+
function floats(b) {
|
|
398
|
+
let view = new DataView(b.buffer, b.byteOffset, b.byteLength), out = [];
|
|
399
|
+
for (let k = 0; k + (4) <= b.byteLength; k += (4)) out.push(view.getFloat32(k, true));
|
|
400
|
+
return out;
|
|
401
|
+
}
|
|
402
|
+
function tensor(bytes) {
|
|
403
|
+
let name = "", dims = [], values = [], kind = (1), raw = null;
|
|
404
|
+
for (let f of fields(bytes))
|
|
405
|
+
if (f.number === (1) && f.wire.t === "varint") dims.push(f.wire.v);
|
|
406
|
+
else if (f.number === (1) && f.wire.t === "bytes") {
|
|
407
|
+
let at = { k: 0 };
|
|
408
|
+
for (; at.k < f.wire.b.length; ) dims.push(varint(f.wire.b, at));
|
|
409
|
+
} 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);
|
|
410
|
+
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) }];
|
|
411
|
+
}
|
|
412
|
+
function node(bytes) {
|
|
413
|
+
let n = { inputs: [], outputs: [], op: "", floats: /* @__PURE__ */ new Map(), ints: /* @__PURE__ */ new Map() };
|
|
414
|
+
for (let f of fields(bytes))
|
|
415
|
+
if (f.number === (1)) n.inputs.push(text(f));
|
|
416
|
+
else if (f.number === (2)) n.outputs.push(text(f));
|
|
417
|
+
else if (f.number === (4)) n.op = text(f);
|
|
418
|
+
else if (f.number === (5)) {
|
|
419
|
+
let name = "", float = null, int = null;
|
|
420
|
+
for (let a of fields(message(f)))
|
|
421
|
+
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);
|
|
422
|
+
float !== null && n.floats.set(name, float), int !== null && n.ints.set(name, int);
|
|
423
|
+
}
|
|
424
|
+
return n;
|
|
425
|
+
}
|
|
426
|
+
function clipActivation(low, high) {
|
|
427
|
+
if (low === 0 && high === Number.POSITIVE_INFINITY) return { kind: "relu" };
|
|
428
|
+
if (Number.isFinite(high) && high > 0 && (low === 0 || low === -high)) return { kind: "clip", low, high };
|
|
429
|
+
unsupported(`Clip(${low}, ${high}) has no int8 form; clip at 0 and a positive bound, or at -b and b`);
|
|
430
|
+
}
|
|
431
|
+
function readOnnx(bytes) {
|
|
432
|
+
let graphField = fields(bytes).find((f) => f.number === (7)) ?? malformed("no graph"), nodes = [], initializers = /* @__PURE__ */ new Map(), inputs = [], outputs = [];
|
|
433
|
+
for (let f of fields(message(graphField)))
|
|
434
|
+
if (f.number === (1)) nodes.push(node(message(f)));
|
|
435
|
+
else if (f.number === (5)) {
|
|
436
|
+
let [name, t] = tensor(message(f));
|
|
437
|
+
initializers.set(name, t);
|
|
438
|
+
} else if (f.number === (11) || f.number === (12)) {
|
|
439
|
+
let nameField = fields(message(f)).find((v) => v.number === (1)), name = nameField === void 0 ? "" : text(nameField);
|
|
440
|
+
(f.number === (11) ? inputs : outputs).push(name);
|
|
441
|
+
}
|
|
442
|
+
let sources = inputs.filter((n) => !initializers.has(n));
|
|
443
|
+
(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)`);
|
|
444
|
+
let matrix = (name) => {
|
|
445
|
+
name === void 0 && malformed("a layer has no weights");
|
|
446
|
+
let t = initializers.get(name) ?? unsupported(`weights ${name} are computed, not constant`);
|
|
447
|
+
return t.dims.length !== (2) && shape(`weights ${name} have dimensions [${t.dims.join(", ")}], not a matrix`), t;
|
|
448
|
+
}, scalar = (name) => {
|
|
449
|
+
if (name === void 0 || name === "") return null;
|
|
450
|
+
let t = initializers.get(name);
|
|
451
|
+
return (t === void 0 || t.values.length !== 1) && unsupported(`Clip bound ${name} is not a constant scalar`), t.values[0];
|
|
452
|
+
}, layers = [], current = sources[0], awaitingBias = false, activated = false;
|
|
453
|
+
for (let n of nodes) {
|
|
454
|
+
let reads = () => {
|
|
455
|
+
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`);
|
|
456
|
+
}, output = () => n.outputs[0] ?? malformed("a node has no output");
|
|
457
|
+
if (n.op === "Gemm" || n.op === "MatMul") {
|
|
458
|
+
reads();
|
|
459
|
+
let gemm = n.op === "Gemm";
|
|
460
|
+
gemm && (n.ints.get("transA") ?? 0) !== 0 && unsupported("Gemm with transA");
|
|
461
|
+
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];
|
|
462
|
+
prev !== void 0 && prev.outputs !== ins && shape(`a layer takes ${ins} inputs after one with ${prev.outputs} outputs`);
|
|
463
|
+
let alpha = gemm ? fr2(n.floats.get("alpha") ?? 1) : 1, weights = new Float32Array(ins * outs);
|
|
464
|
+
for (let j = 0; j < outs; j++)
|
|
465
|
+
for (let i = 0; i < ins; i++) {
|
|
466
|
+
let v = transposed ? w.values[j * ins + i] : w.values[i * outs + j];
|
|
467
|
+
weights[j * ins + i] = alpha === 1 ? v : fr2(v * alpha);
|
|
468
|
+
}
|
|
469
|
+
let bias = new Float32Array(outs), c = gemm ? n.inputs[2] : void 0;
|
|
470
|
+
if (c !== void 0 && c !== "") {
|
|
471
|
+
let t = initializers.get(c) ?? unsupported(`bias ${c} is computed, not constant`);
|
|
472
|
+
t.values.length !== outs && shape(`bias ${c} holds ${t.values.length} values for ${outs} outputs`);
|
|
473
|
+
let beta = fr2(n.floats.get("beta") ?? 1);
|
|
474
|
+
for (let j = 0; j < outs; j++) bias[j] = beta === 1 ? t.values[j] : fr2(t.values[j] * beta);
|
|
475
|
+
}
|
|
476
|
+
layers.push({ inputs: ins, outputs: outs, weights, bias, activation: { kind: "linear" } }), awaitingBias = !gemm, activated = false, current = output();
|
|
477
|
+
} else if (n.op === "Add") {
|
|
478
|
+
let layer = awaitingBias ? layers[layers.length - 1] : void 0;
|
|
479
|
+
layer === void 0 && unsupported("Add that is not the bias of a MatMul");
|
|
480
|
+
let other = n.inputs.find((i) => i !== current) ?? unsupported("Add without a constant bias");
|
|
481
|
+
n.inputs.includes(current) || unsupported("Add that is off the layer chain");
|
|
482
|
+
let t = initializers.get(other) ?? unsupported(`bias ${other} is computed, not constant`);
|
|
483
|
+
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();
|
|
484
|
+
} else if (n.op === "Relu" || n.op === "Tanh" || n.op === "Clip") {
|
|
485
|
+
reads();
|
|
486
|
+
let layer = activated ? void 0 : layers[layers.length - 1];
|
|
487
|
+
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();
|
|
488
|
+
} else unsupported(`operator ${n.op} is not supported`);
|
|
489
|
+
}
|
|
490
|
+
current !== outputs[0] && unsupported(`the graph output ${outputs[0]} is not the end of the layer chain ${current}`);
|
|
491
|
+
let net = { layers };
|
|
492
|
+
return checkNet(net), net;
|
|
493
|
+
}
|
|
494
|
+
var inputsOf = (net) => net.layers[0]?.inputs ?? 0, outputsOf = (net) => net.layers[net.layers.length - 1]?.outputs ?? 0;
|
|
495
|
+
function checkNet(net) {
|
|
496
|
+
let count = net.layers.length;
|
|
497
|
+
(count === 0 || count > chunkKZJRSXHK_js.MLP_MAX_LAYERS) && shape(`a network has 1 to ${chunkKZJRSXHK_js.MLP_MAX_LAYERS} layers, this one ${count}`), net.layers.forEach((layer, l) => {
|
|
498
|
+
let last = l + 1 === count;
|
|
499
|
+
(layer.inputs === 0 || layer.inputs > chunkIR74FJHU_js.MLP_MAX_WIDTH || layer.outputs === 0 || layer.outputs > (last ? chunkIR74FJHU_js.MLP_MAX_OUTPUTS : chunkIR74FJHU_js.MLP_MAX_WIDTH)) && shape(`layer ${l} is ${layer.inputs}x${layer.outputs}; inputs and hidden layers are at most ${chunkIR74FJHU_js.MLP_MAX_WIDTH} wide and outputs at most ${chunkIR74FJHU_js.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`);
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
function generatedSamples(inputs, count = (256), range = (1), seed = (1)) {
|
|
503
|
+
let random = new Random(seed), out = new Float32Array(inputs * count), r = fr2(range);
|
|
504
|
+
for (let k = 0; k < out.length; k++) out[k] = fr2(fr2(fr2(random.unit() * 2) - 1) * r);
|
|
505
|
+
return out;
|
|
506
|
+
}
|
|
507
|
+
function tanh(x) {
|
|
508
|
+
let c = clamp(x, -(9), (9)), e = chunkIR74FJHU_js.exp(fr2(2 * c));
|
|
509
|
+
return fr2(fr2(e - 1) / fr2(e + 1));
|
|
510
|
+
}
|
|
511
|
+
function deployed(y, a) {
|
|
512
|
+
switch (a.kind) {
|
|
513
|
+
case "linear":
|
|
514
|
+
return y;
|
|
515
|
+
case "relu":
|
|
516
|
+
return y > 0 ? y : 0;
|
|
517
|
+
case "clip":
|
|
518
|
+
return clamp(y, a.low, a.high);
|
|
519
|
+
case "tanh":
|
|
520
|
+
return clamp(y, -(1), (1));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function floatActivation(y, a) {
|
|
524
|
+
return a.kind === "tanh" ? tanh(y) : deployed(y, a);
|
|
525
|
+
}
|
|
526
|
+
function layerForward(layer, weights, input, out, activate) {
|
|
527
|
+
for (let j = 0; j < layer.outputs; j++) {
|
|
528
|
+
let acc = layer.bias[j], row = j * layer.inputs;
|
|
529
|
+
for (let i = 0; i < layer.inputs; i++) acc = fr2(acc + fr2(weights[row + i] * input[i]));
|
|
530
|
+
out[j] = activate(acc);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function floatEval(net, input, out) {
|
|
534
|
+
let a = new Float32Array(chunkIR74FJHU_js.MLP_MAX_WIDTH), b = new Float32Array(chunkIR74FJHU_js.MLP_MAX_WIDTH);
|
|
535
|
+
for (let i = 0; i < input.length; i++) a[i] = input[i];
|
|
536
|
+
for (let layer of net.layers) {
|
|
537
|
+
layerForward(layer, layer.weights, a, b, (y) => floatActivation(y, layer.activation));
|
|
538
|
+
let t = a;
|
|
539
|
+
a = b, b = t;
|
|
540
|
+
}
|
|
541
|
+
out.set(a.subarray(0, outputsOf(net)));
|
|
542
|
+
}
|
|
543
|
+
function fixedScale(a) {
|
|
544
|
+
return a.kind === "clip" ? fr2(a.high / (127)) : a.kind === "tanh" ? fr2((1) / (127)) : null;
|
|
545
|
+
}
|
|
546
|
+
function intActivation(a) {
|
|
547
|
+
return a.kind === "relu" || a.kind === "clip" && a.low === 0 ? chunkKZJRSXHK_js.MLP_ACT_RELU : chunkKZJRSXHK_js.MLP_ACT_LINEAR;
|
|
548
|
+
}
|
|
549
|
+
function quantizeNet(net, index, samples, scale, reports) {
|
|
550
|
+
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(chunkIR74FJHU_js.MLP_MAX_WIDTH), b = new Float32Array(chunkIR74FJHU_js.MLP_MAX_WIDTH);
|
|
551
|
+
for (let r = 0; r < rows; r++) {
|
|
552
|
+
for (let i = 0; i < inputs; i++) a[i] = quantizeInput(samples[r * inputs + i], scale, unit0);
|
|
553
|
+
net.layers.forEach((layer, l) => {
|
|
554
|
+
layerForward(layer, wq[l], a, b, (y) => deployed(y, layer.activation));
|
|
555
|
+
let peak = peaks[l];
|
|
556
|
+
for (let j = 0; j < layer.outputs; j++) {
|
|
557
|
+
let m = layer.activation.kind === "relu" ? b[j] : Math.abs(b[j]);
|
|
558
|
+
m > peak && (peak = m);
|
|
559
|
+
}
|
|
560
|
+
peaks[l] = peak;
|
|
561
|
+
let t = a;
|
|
562
|
+
a = b, b = t;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
let count = net.layers.length, specs = [], unit = unit0;
|
|
566
|
+
return net.layers.forEach((layer, l) => {
|
|
567
|
+
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)), -chunkKZJRSXHK_js.MLP_ACC_LIMIT, chunkKZJRSXHK_js.MLP_ACC_LIMIT)), activation = intActivation(layer.activation), spec, aScale;
|
|
568
|
+
if (last)
|
|
569
|
+
spec = { outputs: layer.outputs, activation, multiplier: 0, shift: 0, zero: 0, scale: accScale, bias, weights }, aScale = accScale;
|
|
570
|
+
else {
|
|
571
|
+
aScale = fixedScale(layer.activation) ?? scaleOf(peaks[l]);
|
|
572
|
+
let [multiplier, shift] = shiftFor(accScale / aScale);
|
|
573
|
+
spec = { outputs: layer.outputs, activation, multiplier, shift, zero: 0, scale: aScale, bias, weights };
|
|
574
|
+
}
|
|
575
|
+
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;
|
|
576
|
+
}), chunkKZJRSXHK_js.mlpBlob(inputs, scale, 0, specs);
|
|
577
|
+
}
|
|
578
|
+
function inputScale(samples) {
|
|
579
|
+
let peak = maxAbs(samples);
|
|
580
|
+
return peak > 0 ? fr2((127) / peak) : 1;
|
|
581
|
+
}
|
|
582
|
+
function drift(rows, outputs, bound, row) {
|
|
583
|
+
let float = new Float32Array(outputs), int = new Uint32Array(outputs), view = new Float32Array(int.buffer), maxError = 0, peak = 0;
|
|
584
|
+
for (let r = 0; r < rows; r++) {
|
|
585
|
+
row(r, float, int);
|
|
586
|
+
for (let j = 0; j < outputs; j++) {
|
|
587
|
+
let e = Math.abs(fr2(view[j] - float[j]));
|
|
588
|
+
maxError = Number.isNaN(e) ? Number.POSITIVE_INFINITY : e > maxError ? e : maxError;
|
|
589
|
+
let m = Math.abs(float[j]);
|
|
590
|
+
m > peak && (peak = m);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
let relative = peak > 0 ? fr2(maxError / peak) : maxError;
|
|
594
|
+
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`);
|
|
595
|
+
return { samples: rows, maxError, peak, relative, bound };
|
|
596
|
+
}
|
|
597
|
+
function rowsOf(samples, inputs) {
|
|
598
|
+
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;
|
|
599
|
+
}
|
|
600
|
+
function memoryFits(memory, inputs, outputs) {
|
|
601
|
+
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)`);
|
|
602
|
+
}
|
|
603
|
+
function samplesFor(inputs, options) {
|
|
604
|
+
return options.samples ?? generatedSamples(inputs);
|
|
605
|
+
}
|
|
606
|
+
function importMlp(net, options = {}) {
|
|
607
|
+
checkNet(net);
|
|
608
|
+
let inputs = inputsOf(net), outputs = outputsOf(net), memory = options.memory ?? 0;
|
|
609
|
+
memoryFits(memory, inputs, outputs);
|
|
610
|
+
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 = chunkKZJRSXHK_js.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) => {
|
|
611
|
+
let row = samples.subarray(r * inputs, (r + 1) * inputs);
|
|
612
|
+
floatEval(net, row, float), bits.set(row), chunkKZJRSXHK_js.evalMlp(parsed, words, int);
|
|
613
|
+
});
|
|
614
|
+
return { blob, inputScale: scale, layers, drift: report, memory };
|
|
615
|
+
}
|
|
616
|
+
function importMoe(router, experts, options = {}) {
|
|
617
|
+
checkNet(router), (experts.length < chunkKZJRSXHK_js.MOE_MIN_EXPERTS || experts.length > chunkKZJRSXHK_js.MOE_MAX_EXPERTS || outputsOf(router) !== experts.length) && shape(`a mixture has ${chunkKZJRSXHK_js.MOE_MIN_EXPERTS} to ${chunkKZJRSXHK_js.MOE_MAX_EXPERTS} experts and a router with one output each; this one has ${experts.length} experts and ${outputsOf(router)} router outputs`);
|
|
618
|
+
let inputs = inputsOf(router), outputs = outputsOf(experts[0]);
|
|
619
|
+
experts.forEach((expert, e) => {
|
|
620
|
+
checkNet(expert), (inputsOf(expert) !== inputs || outputsOf(expert) !== outputs) && shape(`expert ${e} is ${inputsOf(expert)}->${outputsOf(expert)}, the mixture ${inputs}->${outputs}`);
|
|
621
|
+
});
|
|
622
|
+
let memory = options.memory ?? 0;
|
|
623
|
+
memoryFits(memory, inputs, outputs);
|
|
624
|
+
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 = chunkKZJRSXHK_js.moeBlob(inputs, outputs, routerWords, parts), parsed = chunkKZJRSXHK_js.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) => {
|
|
625
|
+
let row = samples.subarray(r * inputs, (r + 1) * inputs);
|
|
626
|
+
floatEval(router, row, route);
|
|
627
|
+
let best = 0;
|
|
628
|
+
for (let j = 1; j < route.length; j++) route[j] > route[best] && (best = j);
|
|
629
|
+
floatEval(experts[best], row, float), bits.set(row), chunkKZJRSXHK_js.evalMoeLane(parsed, words, 0, 1, int);
|
|
630
|
+
});
|
|
631
|
+
return { blob, inputScale: scale, layers, drift: report, memory };
|
|
632
|
+
}
|
|
633
|
+
function plainNet(layers) {
|
|
634
|
+
let net = { layers: layers.map((layer, l) => {
|
|
635
|
+
let outputs = layer.weights.length, inputs = layer.weights[0]?.length ?? 0;
|
|
636
|
+
layer.weights.some((row) => row.length !== inputs) && shape(`layer ${l} has rows of different lengths`);
|
|
637
|
+
let activation = layer.activation;
|
|
638
|
+
return {
|
|
639
|
+
inputs,
|
|
640
|
+
outputs,
|
|
641
|
+
weights: Float32Array.from(layer.weights.flat()),
|
|
642
|
+
bias: Float32Array.from(layer.bias ?? new Array(outputs).fill(0)),
|
|
643
|
+
activation: activation === void 0 || activation === "linear" ? { kind: "linear" } : activation === "relu" ? { kind: "relu" } : activation === "tanh" ? { kind: "tanh" } : clipActivation(activation.clip[0], activation.clip[1])
|
|
644
|
+
};
|
|
645
|
+
}) };
|
|
646
|
+
return checkNet(net), net;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/game/render/helpers.ts
|
|
650
|
+
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;
|
|
651
|
+
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]);
|
|
652
|
+
function srgbToLinear(channel) {
|
|
653
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
654
|
+
}
|
|
655
|
+
var LineWriter = class {
|
|
656
|
+
constructor(capacity) {
|
|
657
|
+
this.count = 0;
|
|
658
|
+
this.dropped = 0;
|
|
659
|
+
this.hex = -1;
|
|
660
|
+
this.r = 1;
|
|
661
|
+
this.g = 1;
|
|
662
|
+
this.b = 1;
|
|
663
|
+
this.a = 1;
|
|
664
|
+
this.corners = new Float64Array((8) * 3);
|
|
665
|
+
this.basis = new Float64Array(6);
|
|
666
|
+
this.matrix = new Float64Array((16));
|
|
667
|
+
this.transformed = false;
|
|
668
|
+
this.capacity = capacity, this.positions = new Float32Array(capacity * 2 * 3), this.colors = new Float32Array(capacity * 2 * 4);
|
|
669
|
+
}
|
|
670
|
+
get vertexCount() {
|
|
671
|
+
return this.count * 2;
|
|
672
|
+
}
|
|
673
|
+
clear() {
|
|
674
|
+
this.count = 0, this.dropped = 0;
|
|
675
|
+
}
|
|
676
|
+
color(hex, alpha = 1) {
|
|
677
|
+
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);
|
|
678
|
+
}
|
|
679
|
+
setMatrix(m, mo = 0) {
|
|
680
|
+
if (m === null)
|
|
681
|
+
return this.transformed = false, this;
|
|
682
|
+
for (let i = 0; i < (16); i++) this.matrix[i] = m[mo + i];
|
|
683
|
+
return this.transformed = true, this;
|
|
684
|
+
}
|
|
685
|
+
segment(ax, ay, az, bx, by, bz) {
|
|
686
|
+
if (this.count >= this.capacity)
|
|
687
|
+
return this.dropped++, false;
|
|
688
|
+
if (this.transformed) {
|
|
689
|
+
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];
|
|
690
|
+
ax = tax, ay = tay, az = taz, bx = tbx, by = tby, bz = tbz;
|
|
691
|
+
}
|
|
692
|
+
let v = this.count * 2, p = this.positions, o = v * 3;
|
|
693
|
+
p[o] = ax, p[o + 1] = ay, p[o + 2] = az, p[o + 3] = bx, p[o + 4] = by, p[o + 5] = bz;
|
|
694
|
+
let c = this.colors, q = v * 4;
|
|
695
|
+
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;
|
|
696
|
+
}
|
|
697
|
+
axes(m, mo, size) {
|
|
698
|
+
let ox = m ? m[mo + 12] : 0, oy = m ? m[mo + 13] : 0, oz = m ? m[mo + 14] : 0;
|
|
699
|
+
for (let axis = 0; axis < (3); axis++) {
|
|
700
|
+
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;
|
|
701
|
+
this.color(axis === 0 ? (16726832) : axis === 1 ? (3458905) : (689407)), this.segment(ox, oy, oz, ox + dx * size, oy + dy * size, oz + dz * size);
|
|
702
|
+
}
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
705
|
+
axesAt(px, py, pz, qx, qy, qz, qw, size) {
|
|
706
|
+
for (let axis = 0; axis < (3); axis++) {
|
|
707
|
+
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;
|
|
708
|
+
this.color(axis === 0 ? (16726832) : axis === 1 ? (3458905) : (689407)), this.segment(px, py, pz, px + rx * size, py + ry * size, pz + rz * size);
|
|
709
|
+
}
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
box(minX, minY, minZ, maxX, maxY, maxZ, m = null, mo = 0) {
|
|
713
|
+
let k = this.corners;
|
|
714
|
+
for (let i = 0; i < (8); i++) {
|
|
715
|
+
let x = i & 1 ? maxX : minX, y = i & 2 ? maxY : minY, z = i & 4 ? maxZ : minZ, o = i * 3;
|
|
716
|
+
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);
|
|
717
|
+
}
|
|
718
|
+
return this.cornerEdges();
|
|
719
|
+
}
|
|
720
|
+
frustum(inverseViewProjection, io, apex = null) {
|
|
721
|
+
let k = this.corners, m = inverseViewProjection;
|
|
722
|
+
for (let i = 0; i < (8); i++) {
|
|
723
|
+
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;
|
|
724
|
+
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;
|
|
725
|
+
}
|
|
726
|
+
if (this.cornerEdges(), apex)
|
|
727
|
+
for (let i = 0; i < (4); i++) {
|
|
728
|
+
let o = i * 3;
|
|
729
|
+
this.segment(apex[0], apex[1], apex[2], k[o], k[o + 1], k[o + 2]);
|
|
730
|
+
}
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
circle(cx, cy, cz, radius, nx, ny, nz, segments = (32)) {
|
|
734
|
+
let b = this.basisFor(nx, ny, nz), px = cx + b[0] * radius, py = cy + b[1] * radius, pz = cz + b[2] * radius;
|
|
735
|
+
for (let s = 1; s <= segments; s++) {
|
|
736
|
+
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;
|
|
737
|
+
this.segment(px, py, pz, x, y, z), px = x, py = y, pz = z;
|
|
738
|
+
}
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
sphere(cx, cy, cz, radius, segments = (32)) {
|
|
742
|
+
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);
|
|
743
|
+
}
|
|
744
|
+
cross(x, y, z, size) {
|
|
745
|
+
let h = size * 0.5;
|
|
746
|
+
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;
|
|
747
|
+
}
|
|
748
|
+
arrow(ox, oy, oz, dx, dy, dz, length, headLength = length * (0.2), headWidth = length * (0.1)) {
|
|
749
|
+
let len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
750
|
+
if (len === 0) return this;
|
|
751
|
+
let ux = dx / len, uy = dy / len, uz = dz / len, tx = ox + ux * length, ty = oy + uy * length, tz = oz + uz * length;
|
|
752
|
+
this.segment(ox, oy, oz, tx, ty, tz);
|
|
753
|
+
let b = this.basisFor(ux, uy, uz), bx = tx - ux * headLength, by = ty - uy * headLength, bz = tz - uz * headLength, r = headWidth * 0.5;
|
|
754
|
+
for (let s = 0; s < (4); s++) {
|
|
755
|
+
let t = s / (4) * TAU, c = Math.cos(t) * r, sn = Math.sin(t) * r;
|
|
756
|
+
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);
|
|
757
|
+
}
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
grid(size, divisions, centerColor = (4473924), gridColor = (8947848), y = 0) {
|
|
761
|
+
let step2 = size / divisions, half = size / 2, center = divisions / 2;
|
|
762
|
+
for (let i = 0; i <= divisions; i++) {
|
|
763
|
+
let k = -half + i * step2;
|
|
764
|
+
this.color(i === center ? centerColor : gridColor), this.segment(-half, y, k, half, y, k), this.segment(k, y, -half, k, y, half);
|
|
765
|
+
}
|
|
766
|
+
return this;
|
|
767
|
+
}
|
|
768
|
+
polarGrid(radius, sectors, rings, divisions, sectorColor = (4473924), ringColor = (8947848), y = 0) {
|
|
769
|
+
this.color(sectorColor);
|
|
770
|
+
for (let i = 0; i < sectors; i++) {
|
|
771
|
+
let t = i / sectors * TAU;
|
|
772
|
+
this.segment(0, y, 0, Math.sin(t) * radius, y, Math.cos(t) * radius);
|
|
773
|
+
}
|
|
774
|
+
this.color(ringColor);
|
|
775
|
+
for (let i = 1; i <= rings; i++) this.circle(0, y, 0, radius * i / rings, 0, 1, 0, divisions);
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
plane(nx, ny, nz, constant, size) {
|
|
779
|
+
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;
|
|
780
|
+
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;
|
|
781
|
+
}
|
|
782
|
+
path(points, count, closed = false, stride = 3) {
|
|
783
|
+
for (let i = 1; i < count; i++) {
|
|
784
|
+
let a = (i - 1) * stride, b = i * stride;
|
|
785
|
+
this.segment(points[a], points[a + 1], points[a + 2], points[b], points[b + 1], points[b + 2]);
|
|
786
|
+
}
|
|
787
|
+
if (closed && count > 2) {
|
|
788
|
+
let b = (count - 1) * stride;
|
|
789
|
+
this.segment(points[b], points[b + 1], points[b + 2], points[0], points[1], points[2]);
|
|
790
|
+
}
|
|
791
|
+
return this;
|
|
792
|
+
}
|
|
793
|
+
skeleton(parents, worlds, count, offset = 0) {
|
|
794
|
+
for (let i = 0; i < count; i++) {
|
|
795
|
+
let parent = parents[i];
|
|
796
|
+
if (parent < 0 || parent >= count) continue;
|
|
797
|
+
let c = offset + i * 16, p = offset + parent * 16;
|
|
798
|
+
this.segment(worlds[p + 12], worlds[p + 13], worlds[p + 14], worlds[c + 12], worlds[c + 13], worlds[c + 14]);
|
|
799
|
+
}
|
|
800
|
+
return this;
|
|
801
|
+
}
|
|
802
|
+
normals(positions, normals, vertices, size) {
|
|
803
|
+
for (let i = 0; i < vertices; i++) {
|
|
804
|
+
let o = i * 3, x = positions[o], y = positions[o + 1], z = positions[o + 2];
|
|
805
|
+
this.segment(x, y, z, x + normals[o] * size, y + normals[o + 1] * size, z + normals[o + 2] * size);
|
|
806
|
+
}
|
|
807
|
+
return this;
|
|
808
|
+
}
|
|
809
|
+
directionalLight(size, length) {
|
|
810
|
+
let h = size * 0.5;
|
|
811
|
+
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;
|
|
812
|
+
}
|
|
813
|
+
spotLight(angle, distance, segments = (32)) {
|
|
814
|
+
let radius = Math.tan(angle) * distance;
|
|
815
|
+
this.segment(0, 0, 0, 0, 0, -distance);
|
|
816
|
+
for (let s = 0; s < (5) - 1; s++) {
|
|
817
|
+
let t = s / ((5) - 1) * TAU;
|
|
818
|
+
this.segment(0, 0, 0, Math.cos(t) * radius, Math.sin(t) * radius, -distance);
|
|
819
|
+
}
|
|
820
|
+
return this.circle(0, 0, -distance, radius, 0, 0, 1, segments);
|
|
821
|
+
}
|
|
822
|
+
hemisphere(size, skyColor, groundColor) {
|
|
823
|
+
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);
|
|
824
|
+
}
|
|
825
|
+
audioCone(innerAngle, outerAngle, range, innerColor = (16776960), outerColor = (16755200)) {
|
|
826
|
+
return this.color(innerColor), this.cone(innerAngle * 0.5, range), this.color(outerColor), this.cone(outerAngle * 0.5, range);
|
|
827
|
+
}
|
|
828
|
+
cone(halfAngle, range) {
|
|
829
|
+
let clamped = Math.min(halfAngle, Math.PI), radius = Math.sin(clamped) * range, depth = Math.cos(clamped) * range;
|
|
830
|
+
for (let s = 0; s < (8); s++) {
|
|
831
|
+
let t = s / (8) * TAU;
|
|
832
|
+
this.segment(0, 0, 0, Math.cos(t) * radius, Math.sin(t) * radius, depth);
|
|
833
|
+
}
|
|
834
|
+
return this.circle(0, 0, depth, radius, 0, 0, 1, (32));
|
|
835
|
+
}
|
|
836
|
+
halfCircle(size, sign) {
|
|
837
|
+
let px = size, py = 0;
|
|
838
|
+
for (let s = 1; s <= (16) / 2; s++) {
|
|
839
|
+
let t = s / (16) * TAU, x = Math.cos(t) * size, y = Math.sin(t) * size * sign;
|
|
840
|
+
this.segment(px, py, 0, x, y, 0), px = x, py = y;
|
|
841
|
+
}
|
|
842
|
+
return this;
|
|
843
|
+
}
|
|
844
|
+
cornerEdges() {
|
|
845
|
+
let k = this.corners;
|
|
846
|
+
for (let e = 0; e < (12); e++) {
|
|
847
|
+
let a = BOX_EDGE_CORNERS[e * 2] * 3, b = BOX_EDGE_CORNERS[e * 2 + 1] * 3;
|
|
848
|
+
this.segment(k[a], k[a + 1], k[a + 2], k[b], k[b + 1], k[b + 2]);
|
|
849
|
+
}
|
|
850
|
+
return this;
|
|
851
|
+
}
|
|
852
|
+
basisFor(nx, ny, nz) {
|
|
853
|
+
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;
|
|
854
|
+
Math.abs(y) > (0.99) && (rx = 1, ry = 0);
|
|
855
|
+
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;
|
|
856
|
+
ax /= al, ay /= al, az /= al;
|
|
857
|
+
let b = this.basis;
|
|
858
|
+
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;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
function lineGeometry(writer, dynamic = false) {
|
|
862
|
+
return {
|
|
863
|
+
attributes: {
|
|
864
|
+
position: { data: writer.positions, itemSize: 3, dynamic },
|
|
865
|
+
color: { data: writer.colors, itemSize: 4, dynamic }
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function build(segments, write) {
|
|
870
|
+
let writer = new LineWriter(segments);
|
|
871
|
+
return writer.color((16776960)), write(writer), lineGeometry(writer);
|
|
872
|
+
}
|
|
873
|
+
function axesHelper(size = 1) {
|
|
874
|
+
return build((3), (w) => w.axes(null, 0, size));
|
|
875
|
+
}
|
|
876
|
+
function gridHelper(size = 10, divisions = 10, centerColor = (4473924), gridColor = (8947848)) {
|
|
877
|
+
return build((divisions + 1) * 2, (w) => w.grid(size, divisions, centerColor, gridColor));
|
|
878
|
+
}
|
|
879
|
+
function polarGridHelper(radius = 10, sectors = 16, rings = 8, divisions = 64, sectorColor = (4473924), ringColor = (8947848)) {
|
|
880
|
+
return build(sectors + rings * divisions, (w) => w.polarGrid(radius, sectors, rings, divisions, sectorColor, ringColor));
|
|
881
|
+
}
|
|
882
|
+
function arrowHelper(direction, length = 1, color = (16776960), headLength, headWidth) {
|
|
883
|
+
return build((5), (w) => w.color(color).arrow(0, 0, 0, direction[0], direction[1], direction[2], length, headLength, headWidth));
|
|
884
|
+
}
|
|
885
|
+
function boxHelper(min, max, color = (16776960)) {
|
|
886
|
+
return build((12), (w) => w.color(color).box(min[0], min[1], min[2], max[0], max[1], max[2]));
|
|
887
|
+
}
|
|
888
|
+
function cameraHelper(projectionInverse, color = (16755200)) {
|
|
889
|
+
let apex = new Float64Array(3);
|
|
890
|
+
return build((12) + (4), (w) => w.color(color).frustum(projectionInverse, 0, apex));
|
|
891
|
+
}
|
|
892
|
+
function directionalLightHelper(size = 1, length = size * 2, color = (16776960)) {
|
|
893
|
+
return build((5), (w) => w.color(color).directionalLight(size, length));
|
|
894
|
+
}
|
|
895
|
+
function spotLightHelper(angle, distance = 5, color = (16776960), segments = (32)) {
|
|
896
|
+
return build((5) + segments, (w) => w.color(color).spotLight(angle, distance, segments));
|
|
897
|
+
}
|
|
898
|
+
function pointLightHelper(radius = 0.5, color = (16776960), segments = (32)) {
|
|
899
|
+
return build((3) * segments, (w) => w.color(color).sphere(0, 0, 0, radius, segments));
|
|
900
|
+
}
|
|
901
|
+
function hemisphereLightHelper(size = 1, skyColor = 8900331, groundColor = 9132587) {
|
|
902
|
+
return build((16) * 2, (w) => w.hemisphere(size, skyColor, groundColor));
|
|
903
|
+
}
|
|
904
|
+
function planeHelper(normal, constant = 0, size = 1, color = (16776960)) {
|
|
905
|
+
return build((6), (w) => w.color(color).plane(normal[0], normal[1], normal[2], constant, size));
|
|
906
|
+
}
|
|
907
|
+
function skeletonHelper(parents, worlds, color = (65535)) {
|
|
908
|
+
let bones = parents.length;
|
|
909
|
+
return build(Math.max(1, bones), (w) => w.color(color).skeleton(parents, worlds, bones));
|
|
910
|
+
}
|
|
911
|
+
function vertexNormalsHelper(positions, normals, size = 0.1, color = (16711935)) {
|
|
912
|
+
let vertices = Math.floor(positions.length / 3);
|
|
913
|
+
return build(Math.max(1, vertices), (w) => w.color(color).normals(positions, normals, vertices, size));
|
|
914
|
+
}
|
|
915
|
+
function positionalAudioHelper(innerAngle, outerAngle, range = 1, innerColor = (16776960), outerColor = (16755200)) {
|
|
916
|
+
return build(((8) + (32)) * 2, (w) => w.audioCone(innerAngle, outerAngle, range, innerColor, outerColor));
|
|
917
|
+
}
|
|
918
|
+
function helperSegments(desc) {
|
|
919
|
+
return desc.attributes.position.data.length / 6;
|
|
920
|
+
}
|
|
921
|
+
var DEFAULT_DEBUG_CIRCLE_SEGMENTS = (32);
|
|
922
|
+
|
|
923
|
+
// src/game/render/debug.ts
|
|
924
|
+
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 {
|
|
925
|
+
constructor(graphics, options = {}) {
|
|
926
|
+
this.flushed = 0;
|
|
927
|
+
this.visible = true;
|
|
928
|
+
this.a = new chunkRCQ2MPBV_js.Vec3();
|
|
929
|
+
this.b = new chunkRCQ2MPBV_js.Vec3();
|
|
930
|
+
this.graphics = graphics, this.writer = new LineWriter(options.capacity ?? (8192)), this.geometry = graphics.createGeometry(lineGeometry(this.writer, true)), this.material = graphics.createMaterial({
|
|
931
|
+
kind: "lines",
|
|
932
|
+
vertexColors: true,
|
|
933
|
+
transparent: false,
|
|
934
|
+
depthTest: options.depthTest ?? true,
|
|
935
|
+
depthWrite: false
|
|
936
|
+
}), 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);
|
|
937
|
+
}
|
|
938
|
+
get segments() {
|
|
939
|
+
return this.writer.count;
|
|
940
|
+
}
|
|
941
|
+
get dropped() {
|
|
942
|
+
return this.writer.dropped;
|
|
943
|
+
}
|
|
944
|
+
get capacity() {
|
|
945
|
+
return this.writer.capacity;
|
|
946
|
+
}
|
|
947
|
+
setLayers(mask) {
|
|
948
|
+
this.graphics.setLayers(this.node, mask);
|
|
949
|
+
}
|
|
950
|
+
setVisible(visible) {
|
|
951
|
+
visible !== this.visible && (this.visible = visible, this.graphics.setVisible(this.node, visible));
|
|
952
|
+
}
|
|
953
|
+
clear() {
|
|
954
|
+
this.writer.clear(), this.writer.setMatrix(null);
|
|
955
|
+
}
|
|
956
|
+
color(hex, alpha = 1) {
|
|
957
|
+
return this.writer.color(hex, alpha), this;
|
|
958
|
+
}
|
|
959
|
+
transform(matrix, offset = 0) {
|
|
960
|
+
return this.writer.setMatrix(matrix, offset), this;
|
|
961
|
+
}
|
|
962
|
+
line(ax, ay, az, bx, by, bz, color = (16776960)) {
|
|
963
|
+
return this.writer.color(color).segment(ax, ay, az, bx, by, bz), this;
|
|
964
|
+
}
|
|
965
|
+
ray(ox, oy, oz, dx, dy, dz, length, color = (16776960)) {
|
|
966
|
+
return this.writer.color(color).segment(ox, oy, oz, ox + dx * length, oy + dy * length, oz + dz * length), this;
|
|
967
|
+
}
|
|
968
|
+
arrow(ox, oy, oz, dx, dy, dz, length, color = (16776960)) {
|
|
969
|
+
return this.writer.color(color).arrow(ox, oy, oz, dx, dy, dz, length), this;
|
|
970
|
+
}
|
|
971
|
+
box(minX, minY, minZ, maxX, maxY, maxZ, color = (16776960)) {
|
|
972
|
+
return this.writer.color(color).box(minX, minY, minZ, maxX, maxY, maxZ), this;
|
|
973
|
+
}
|
|
974
|
+
boxTransformed(minX, minY, minZ, maxX, maxY, maxZ, matrix, offset = 0, color = (16776960)) {
|
|
975
|
+
return this.writer.color(color).box(minX, minY, minZ, maxX, maxY, maxZ, matrix, offset), this;
|
|
976
|
+
}
|
|
977
|
+
sphere(x, y, z, radius, color = (16776960), segments = DEFAULT_DEBUG_CIRCLE_SEGMENTS) {
|
|
978
|
+
return this.writer.color(color).sphere(x, y, z, radius, segments), this;
|
|
979
|
+
}
|
|
980
|
+
circle(x, y, z, radius, nx, ny, nz, color = (16776960), segments = DEFAULT_DEBUG_CIRCLE_SEGMENTS) {
|
|
981
|
+
return this.writer.color(color).circle(x, y, z, radius, nx, ny, nz, segments), this;
|
|
982
|
+
}
|
|
983
|
+
axes(matrix, offset = 0, size = (1)) {
|
|
984
|
+
return this.writer.axes(matrix, offset, size), this;
|
|
985
|
+
}
|
|
986
|
+
axesAt(px, py, pz, qx, qy, qz, qw, size = (1)) {
|
|
987
|
+
return this.writer.axesAt(px, py, pz, qx, qy, qz, qw, size), this;
|
|
988
|
+
}
|
|
989
|
+
grid(size = (10), divisions = (10), y = 0) {
|
|
990
|
+
return this.writer.grid(size, divisions, void 0, void 0, y), this;
|
|
991
|
+
}
|
|
992
|
+
polarGrid(radius, sectors, rings, divisions = DEFAULT_DEBUG_CIRCLE_SEGMENTS, y = 0) {
|
|
993
|
+
return this.writer.polarGrid(radius, sectors, rings, divisions, void 0, void 0, y), this;
|
|
994
|
+
}
|
|
995
|
+
frustum(projection, color = (16776960)) {
|
|
996
|
+
return this.writer.color(color).frustum(projection.viewProjectionInverse, 0, null), this;
|
|
997
|
+
}
|
|
998
|
+
frustumMatrix(inverseViewProjection, offset = 0, color = (16776960)) {
|
|
999
|
+
return this.writer.color(color).frustum(inverseViewProjection, offset, null), this;
|
|
1000
|
+
}
|
|
1001
|
+
plane(nx, ny, nz, constant, size, color = (16776960)) {
|
|
1002
|
+
return this.writer.color(color).plane(nx, ny, nz, constant, size), this;
|
|
1003
|
+
}
|
|
1004
|
+
point(x, y, z, size, color = (16776960)) {
|
|
1005
|
+
return this.writer.color(color).cross(x, y, z, size), this;
|
|
1006
|
+
}
|
|
1007
|
+
skeleton(parents, worlds, count = parents.length, color = (16776960)) {
|
|
1008
|
+
return this.writer.color(color).skeleton(parents, worlds, count), this;
|
|
1009
|
+
}
|
|
1010
|
+
path(points, count, color = (16776960), closed = false) {
|
|
1011
|
+
return this.writer.color(color).path(points, count, closed), this;
|
|
1012
|
+
}
|
|
1013
|
+
navPath(path, color = (3199320), marker = (0.1)) {
|
|
1014
|
+
this.writer.color(color).path(path.points, path.count);
|
|
1015
|
+
let p = path.points;
|
|
1016
|
+
for (let i = 0; i < path.count; i++) this.writer.cross(p[i * 3], p[i * 3 + 1], p[i * 3 + 2], marker);
|
|
1017
|
+
return this;
|
|
1018
|
+
}
|
|
1019
|
+
contacts(source, positions, color = (16723285), startedColor = (16776960)) {
|
|
1020
|
+
let n = source.contactCount();
|
|
1021
|
+
for (let i = 0; i < n; i++) {
|
|
1022
|
+
positions.position(source.contactEntityA(i), this.a), positions.position(source.contactEntityB(i), this.b);
|
|
1023
|
+
let a = this.a, b = this.b;
|
|
1024
|
+
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));
|
|
1025
|
+
}
|
|
1026
|
+
return this;
|
|
1027
|
+
}
|
|
1028
|
+
shape(shape2, matrix, offset = 0, color = (6607615)) {
|
|
1029
|
+
let w = this.writer.color(color).setMatrix(matrix, offset);
|
|
1030
|
+
switch (shape2.kind) {
|
|
1031
|
+
case "ball":
|
|
1032
|
+
w.sphere(0, 0, 0, shape2.radius);
|
|
1033
|
+
break;
|
|
1034
|
+
case "cuboid": {
|
|
1035
|
+
let h = shape2.halfExtents;
|
|
1036
|
+
w.box(-h[0], -h[1], -h[2], h[0], h[1], h[2]);
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
case "capsule":
|
|
1040
|
+
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);
|
|
1041
|
+
break;
|
|
1042
|
+
case "cylinder":
|
|
1043
|
+
this.tube(shape2.radius, shape2.radius, shape2.halfHeight);
|
|
1044
|
+
break;
|
|
1045
|
+
case "cone":
|
|
1046
|
+
this.tube(0, shape2.radius, shape2.halfHeight);
|
|
1047
|
+
break;
|
|
1048
|
+
case "round_cuboid": {
|
|
1049
|
+
let h = shape2.halfExtents, b = shape2.border;
|
|
1050
|
+
w.box(-h[0] - b, -h[1] - b, -h[2] - b, h[0] + b, h[1] + b, h[2] + b);
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
case "round_cylinder":
|
|
1054
|
+
this.tube(shape2.radius + shape2.border, shape2.radius + shape2.border, shape2.halfHeight + shape2.border);
|
|
1055
|
+
break;
|
|
1056
|
+
case "round_cone":
|
|
1057
|
+
this.tube(shape2.border, shape2.radius + shape2.border, shape2.halfHeight + shape2.border);
|
|
1058
|
+
break;
|
|
1059
|
+
case "round_convex_hull": {
|
|
1060
|
+
let p = shape2.points;
|
|
1061
|
+
for (let i = 0; i + 2 < p.length; i += 3) w.cross(p[i], p[i + 1], p[i + 2], (0.1) + shape2.border);
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
case "compound":
|
|
1065
|
+
for (let part of shape2.parts) {
|
|
1066
|
+
let at = part.offset ?? COMPOUND_ORIGIN;
|
|
1067
|
+
w.cross(at[0], at[1], at[2], (0.1));
|
|
1068
|
+
}
|
|
1069
|
+
break;
|
|
1070
|
+
case "trimesh": {
|
|
1071
|
+
let v = shape2.vertices, idx = shape2.indices;
|
|
1072
|
+
for (let t = 0; t + 2 < idx.length; t += (3))
|
|
1073
|
+
for (let e = 0; e < (3); e++) {
|
|
1074
|
+
let i0 = idx[t + e] * 3, i1 = idx[t + (e + 1) % (3)] * 3;
|
|
1075
|
+
w.segment(v[i0], v[i0 + 1], v[i0 + 2], v[i1], v[i1 + 1], v[i1 + 2]);
|
|
1076
|
+
}
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
case "convex_hull": {
|
|
1080
|
+
let p = shape2.points;
|
|
1081
|
+
for (let i = 0; i + 2 < p.length; i += 3) w.cross(p[i], p[i + 1], p[i + 2], (0.1));
|
|
1082
|
+
break;
|
|
1083
|
+
}
|
|
1084
|
+
case "heightfield": {
|
|
1085
|
+
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;
|
|
1086
|
+
for (let r = 0; r < rows; r++)
|
|
1087
|
+
for (let c = 0; c < columns; c++) {
|
|
1088
|
+
let y = heights[r * columns + c] * scale[1];
|
|
1089
|
+
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);
|
|
1090
|
+
}
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return w.setMatrix(null), this;
|
|
1095
|
+
}
|
|
1096
|
+
flush() {
|
|
1097
|
+
let vertices = this.writer.count * (2);
|
|
1098
|
+
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);
|
|
1099
|
+
}
|
|
1100
|
+
tube(radiusTop, radiusBottom, halfHeight) {
|
|
1101
|
+
let w = this.writer;
|
|
1102
|
+
radiusTop > 0 && w.circle(0, halfHeight, 0, radiusTop, 0, 1, 0), radiusBottom > 0 && w.circle(0, -halfHeight, 0, radiusBottom, 0, 1, 0);
|
|
1103
|
+
for (let i = 0; i < (4); i++) {
|
|
1104
|
+
let t = i / (4) * Math.PI * 2, c = Math.cos(t), s = Math.sin(t);
|
|
1105
|
+
w.segment(c * radiusTop, halfHeight, s * radiusTop, c * radiusBottom, -halfHeight, s * radiusBottom);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// src/game/ui/labels.ts
|
|
1111
|
+
var DEFAULT_LABEL_CAPACITY = 64, VEC3 = 3, OCCLUSION_EPSILON = 1e-3, OPACITY_STEPS = 32, NO_SLOT = -1, VISIBLE = 1, HIDDEN = 0, ScreenLabels = class {
|
|
1112
|
+
constructor(options = {}) {
|
|
1113
|
+
this.count = 0;
|
|
1114
|
+
this.world = new chunkRCQ2MPBV_js.Vec3();
|
|
1115
|
+
this.ndc = new chunkRCQ2MPBV_js.Vec3();
|
|
1116
|
+
this.hit = chunkIIDZ5WUX_js.createPickHit();
|
|
1117
|
+
this.origin = new Float32Array((3));
|
|
1118
|
+
this.direction = new Float32Array((3));
|
|
1119
|
+
let n = options.capacity ?? (64);
|
|
1120
|
+
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(chunkMRFUNRAP_js.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(chunkMRFUNRAP_js.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;
|
|
1121
|
+
}
|
|
1122
|
+
get size() {
|
|
1123
|
+
return this.count;
|
|
1124
|
+
}
|
|
1125
|
+
add(desc) {
|
|
1126
|
+
let label = -1;
|
|
1127
|
+
for (let i = 0; i < this.capacity; i++)
|
|
1128
|
+
if (this.live[i] === 0) {
|
|
1129
|
+
label = i;
|
|
1130
|
+
break;
|
|
1131
|
+
}
|
|
1132
|
+
if (label < 0) throw new chunk2V7IL4HC_js.GameError("capacity_exceeded", `at most ${this.capacity} screen labels`);
|
|
1133
|
+
if (desc.entity === void 0 && desc.point === void 0) throw new chunk2V7IL4HC_js.GameError("invalid_argument", "a label needs an entity or a point");
|
|
1134
|
+
this.live[label] = 1, this.count++, this.entities[label] = desc.entity ?? chunkMRFUNRAP_js.NO_ENTITY;
|
|
1135
|
+
let p = label * (3);
|
|
1136
|
+
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);
|
|
1137
|
+
let name = desc.name ?? `label${label}`;
|
|
1138
|
+
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));
|
|
1139
|
+
let engine = this.engine;
|
|
1140
|
+
if (engine && desc.text !== void 0) {
|
|
1141
|
+
let style = { ...desc.style, opacity: desc.style?.opacity ?? 1 };
|
|
1142
|
+
this.styles[label] = style;
|
|
1143
|
+
let entity = engine.spawner.spawn();
|
|
1144
|
+
engine.add?.(entity), this.nodes[label] = engine.text.create(entity, { ...style, kind: "text2d", text: desc.text }), this.labelEntity[label] = entity;
|
|
1145
|
+
}
|
|
1146
|
+
return label;
|
|
1147
|
+
}
|
|
1148
|
+
textEntity(label) {
|
|
1149
|
+
return this.labelEntity[label];
|
|
1150
|
+
}
|
|
1151
|
+
node(label) {
|
|
1152
|
+
return this.nodes[label];
|
|
1153
|
+
}
|
|
1154
|
+
setPoint(label, x, y, z) {
|
|
1155
|
+
let p = label * (3);
|
|
1156
|
+
this.points[p] = x, this.points[p + 1] = y, this.points[p + 2] = z;
|
|
1157
|
+
}
|
|
1158
|
+
setText(label, text2) {
|
|
1159
|
+
this.engine && this.styles[label] !== null && this.engine.text.setText(this.nodes[label], text2);
|
|
1160
|
+
}
|
|
1161
|
+
remove(label) {
|
|
1162
|
+
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] = chunkMRFUNRAP_js.NO_ENTITY);
|
|
1163
|
+
}
|
|
1164
|
+
update(projection) {
|
|
1165
|
+
let width = projection.width, height = projection.height, fade = this.fadeFar > this.fadeNear;
|
|
1166
|
+
for (let i = 0; i < this.capacity; i++) {
|
|
1167
|
+
if (this.live[i] === 0) continue;
|
|
1168
|
+
this.anchor(i);
|
|
1169
|
+
let distance = projection.position.distanceTo(this.world);
|
|
1170
|
+
this.distance[i] = distance;
|
|
1171
|
+
let inside = projection.worldToNdc(this.world, this.ndc), front = projection.w > 0, nx = this.ndc.x, ny = this.ndc.y, show = inside, off = 0;
|
|
1172
|
+
if (!inside && this.clampToEdge) {
|
|
1173
|
+
front || (nx = -nx, ny = -ny);
|
|
1174
|
+
let extent = Math.max(Math.abs(nx), Math.abs(ny));
|
|
1175
|
+
if (extent > 1 || !front) {
|
|
1176
|
+
let s = extent > 0 ? 1 / extent : 1;
|
|
1177
|
+
nx *= s, ny *= s;
|
|
1178
|
+
}
|
|
1179
|
+
show = true, off = 1;
|
|
1180
|
+
}
|
|
1181
|
+
let px = (nx + 1) * 0.5 * width, py = (1 - ny) * 0.5 * height;
|
|
1182
|
+
off === 1 && (px = Math.min(width - this.margin, Math.max(this.margin, px)), py = Math.min(height - this.margin, Math.max(this.margin, py)));
|
|
1183
|
+
let occluded = 0;
|
|
1184
|
+
show && off === 0 && this.occluder && this.occludes[i] === 1 && distance > (1e-3) && (occluded = this.occludedBy(projection, distance) ? 1 : 0, occluded === 1 && (show = false));
|
|
1185
|
+
let alpha = show ? 1 : 0;
|
|
1186
|
+
if (show && fade) {
|
|
1187
|
+
let t = Math.min(1, Math.max(0, (distance - this.fadeNear) / (this.fadeFar - this.fadeNear)));
|
|
1188
|
+
alpha = 1 - t * t * (3 - 2 * t), alpha <= 0 && (show = false);
|
|
1189
|
+
}
|
|
1190
|
+
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);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
anchor(i) {
|
|
1194
|
+
let p = i * (3), entity = this.entities[i];
|
|
1195
|
+
entity !== chunkMRFUNRAP_js.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]);
|
|
1196
|
+
}
|
|
1197
|
+
occludedBy(projection, distance) {
|
|
1198
|
+
let occluder = this.occluder, o = projection.position, inv = 1 / distance;
|
|
1199
|
+
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;
|
|
1200
|
+
}
|
|
1201
|
+
publish(i, show, px, py, alpha) {
|
|
1202
|
+
let ui = this.ui;
|
|
1203
|
+
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)));
|
|
1204
|
+
let engine = this.engine, style = this.styles[i];
|
|
1205
|
+
if (!engine || style === null) return;
|
|
1206
|
+
let node2 = this.nodes[i], shown = show ? (1) : (0);
|
|
1207
|
+
if (shown !== this.shown[i] && (this.shown[i] = shown, engine.text.setVisible(node2, show)), !show) return;
|
|
1208
|
+
engine.placement.setPosition(this.labelEntity[i], px, py, 0);
|
|
1209
|
+
let stepped = Math.round(alpha * (32)) / (32);
|
|
1210
|
+
stepped !== this.shownOpacity[i] && (this.shownOpacity[i] = stepped, style.opacity = stepped, engine.text.setTextStyle(node2, style));
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
function engineLabelText(graphics, transforms, world) {
|
|
1214
|
+
return {
|
|
1215
|
+
text: graphics,
|
|
1216
|
+
placement: transforms,
|
|
1217
|
+
spawner: world,
|
|
1218
|
+
add: (entity) => {
|
|
1219
|
+
transforms.add(entity);
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// src/game/kernel/std/intrinsics.ts
|
|
1225
|
+
var fround = Math.fround, TWO_32 = 2 ** 32, LOW_16 = 65535, TWO_16 = 65536;
|
|
1226
|
+
function fsin(x) {
|
|
1227
|
+
return chunkIR74FJHU_js.sin(fround(x));
|
|
1228
|
+
}
|
|
1229
|
+
function fcos(x) {
|
|
1230
|
+
return chunkIR74FJHU_js.cos(fround(x));
|
|
1231
|
+
}
|
|
1232
|
+
function ftan(x) {
|
|
1233
|
+
return chunkIR74FJHU_js.tan(fround(x));
|
|
1234
|
+
}
|
|
1235
|
+
function fasin(x) {
|
|
1236
|
+
return chunkIR74FJHU_js.asin(fround(x));
|
|
1237
|
+
}
|
|
1238
|
+
function facos(x) {
|
|
1239
|
+
return chunkIR74FJHU_js.acos(fround(x));
|
|
1240
|
+
}
|
|
1241
|
+
function fatan(x) {
|
|
1242
|
+
return chunkIR74FJHU_js.atan(fround(x));
|
|
1243
|
+
}
|
|
1244
|
+
function fatan2(y, x) {
|
|
1245
|
+
return chunkIR74FJHU_js.atan2(fround(y), fround(x));
|
|
1246
|
+
}
|
|
1247
|
+
function fexp(x) {
|
|
1248
|
+
return chunkIR74FJHU_js.exp(fround(x));
|
|
1249
|
+
}
|
|
1250
|
+
function flog(x) {
|
|
1251
|
+
return chunkIR74FJHU_js.log(fround(x));
|
|
1252
|
+
}
|
|
1253
|
+
function flog2(x) {
|
|
1254
|
+
return chunkIR74FJHU_js.log2(fround(x));
|
|
1255
|
+
}
|
|
1256
|
+
function fpow(x, y) {
|
|
1257
|
+
return chunkIR74FJHU_js.pow(fround(x), fround(y));
|
|
1258
|
+
}
|
|
1259
|
+
function umulhi(a, b) {
|
|
1260
|
+
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));
|
|
1261
|
+
return xh * yh + (lh >>> 16) + (hl >>> 16) + Math.floor(mid / (65536)) >>> 0;
|
|
1262
|
+
}
|
|
1263
|
+
function uaddCarry(a, b, carry) {
|
|
1264
|
+
return (a >>> 0) + (b >>> 0) + (carry & 1) >= TWO_32 ? 1 : 0;
|
|
1265
|
+
}
|
|
1266
|
+
function usubBorrow(a, b, borrow) {
|
|
1267
|
+
return a >>> 0 < (b >>> 0) + (borrow & 1) ? 1 : 0;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/game/scenes/catalogue.ts
|
|
1271
|
+
var SCENE_CATALOGUE_VERSION = 1, STARTER_CATALOGUE = {
|
|
1272
|
+
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] } },
|
|
1273
|
+
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] } },
|
|
1274
|
+
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] } },
|
|
1275
|
+
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] } },
|
|
1276
|
+
bollard: { footprint: [0.25, 0.25], height: 1, size: "tiny", tags: ["street", "barrier"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1, 0] } },
|
|
1277
|
+
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] } },
|
|
1278
|
+
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] } },
|
|
1279
|
+
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] } },
|
|
1280
|
+
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] } },
|
|
1281
|
+
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] } },
|
|
1282
|
+
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] } },
|
|
1283
|
+
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] } },
|
|
1284
|
+
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] } },
|
|
1285
|
+
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] } },
|
|
1286
|
+
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] } },
|
|
1287
|
+
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] } },
|
|
1288
|
+
barrel: { footprint: [0.7, 0.7], height: 1, size: "small", tags: ["market", "storage"], up: "+y", forward: "+z", solid: true, anchors: { top: [0, 1, 0] } },
|
|
1289
|
+
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] } },
|
|
1290
|
+
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] } },
|
|
1291
|
+
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] } },
|
|
1292
|
+
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] } },
|
|
1293
|
+
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] } },
|
|
1294
|
+
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] } },
|
|
1295
|
+
scoreboard: { footprint: [4, 0.6], height: 5, size: "large", tags: ["sports", "display"], up: "+y", forward: "+z", solid: true, anchors: { front: [0, 0, 1] } },
|
|
1296
|
+
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] } },
|
|
1297
|
+
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] } },
|
|
1298
|
+
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] } },
|
|
1299
|
+
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] } },
|
|
1300
|
+
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] } },
|
|
1301
|
+
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] } },
|
|
1302
|
+
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] } },
|
|
1303
|
+
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] } },
|
|
1304
|
+
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] } },
|
|
1305
|
+
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] } },
|
|
1306
|
+
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] } },
|
|
1307
|
+
tree: { footprint: [1, 1], height: 7, size: "small", tags: ["nature", "plant", "shade"], up: "+y", forward: "+z", solid: true, anchors: { edge: [0.5, 0, 0] } },
|
|
1308
|
+
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] } },
|
|
1309
|
+
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] } },
|
|
1310
|
+
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] } },
|
|
1311
|
+
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] } }
|
|
1312
|
+
};
|
|
1313
|
+
function extendCatalogue(extra, base = STARTER_CATALOGUE) {
|
|
1314
|
+
return Object.freeze({ ...base, ...extra });
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
exports.DEFAULT_DEBUG_SEGMENTS = (8192);
|
|
1318
|
+
exports.DEFAULT_LABEL_CAPACITY = (64);
|
|
1319
|
+
exports.DebugDraw = DebugDraw;
|
|
1320
|
+
exports.IMPORT_DEFAULT_MAX_DRIFT = (0.05);
|
|
1321
|
+
exports.IMPORT_DEFAULT_SAMPLES = (256);
|
|
1322
|
+
exports.ImportError = ImportError;
|
|
1323
|
+
exports.LineWriter = LineWriter;
|
|
1324
|
+
exports.MLP_MEMORY_MAX = (4);
|
|
1325
|
+
exports.MLP_MEMORY_MIN = (2);
|
|
1326
|
+
exports.MOE_DEFAULT_BALANCE = (0.5);
|
|
1327
|
+
exports.SCENE_CATALOGUE_VERSION = (1);
|
|
1328
|
+
exports.STARTER_CATALOGUE = STARTER_CATALOGUE;
|
|
1329
|
+
exports.ScreenLabels = ScreenLabels;
|
|
1330
|
+
exports.arrowHelper = arrowHelper;
|
|
1331
|
+
exports.axesHelper = axesHelper;
|
|
1332
|
+
exports.boxHelper = boxHelper;
|
|
1333
|
+
exports.cameraHelper = cameraHelper;
|
|
1334
|
+
exports.checkNet = checkNet;
|
|
1335
|
+
exports.directionalLightHelper = directionalLightHelper;
|
|
1336
|
+
exports.engineLabelText = engineLabelText;
|
|
1337
|
+
exports.extendCatalogue = extendCatalogue;
|
|
1338
|
+
exports.facos = facos;
|
|
1339
|
+
exports.fasin = fasin;
|
|
1340
|
+
exports.fatan = fatan;
|
|
1341
|
+
exports.fatan2 = fatan2;
|
|
1342
|
+
exports.fcos = fcos;
|
|
1343
|
+
exports.fexp = fexp;
|
|
1344
|
+
exports.floatEval = floatEval;
|
|
1345
|
+
exports.flog = flog;
|
|
1346
|
+
exports.flog2 = flog2;
|
|
1347
|
+
exports.fpow = fpow;
|
|
1348
|
+
exports.fsin = fsin;
|
|
1349
|
+
exports.ftan = ftan;
|
|
1350
|
+
exports.generatedSamples = generatedSamples;
|
|
1351
|
+
exports.gridHelper = gridHelper;
|
|
1352
|
+
exports.helperSegments = helperSegments;
|
|
1353
|
+
exports.hemisphereLightHelper = hemisphereLightHelper;
|
|
1354
|
+
exports.importMlp = importMlp;
|
|
1355
|
+
exports.importMoe = importMoe;
|
|
1356
|
+
exports.joinMemory = joinMemory;
|
|
1357
|
+
exports.lineGeometry = lineGeometry;
|
|
1358
|
+
exports.memorySamples = memorySamples;
|
|
1359
|
+
exports.plainNet = plainNet;
|
|
1360
|
+
exports.planeHelper = planeHelper;
|
|
1361
|
+
exports.pointLightHelper = pointLightHelper;
|
|
1362
|
+
exports.polarGridHelper = polarGridHelper;
|
|
1363
|
+
exports.positionalAudioHelper = positionalAudioHelper;
|
|
1364
|
+
exports.readOnnx = readOnnx;
|
|
1365
|
+
exports.skeletonHelper = skeletonHelper;
|
|
1366
|
+
exports.spotLightHelper = spotLightHelper;
|
|
1367
|
+
exports.trainMlp = trainMlp;
|
|
1368
|
+
exports.trainMoe = trainMoe;
|
|
1369
|
+
exports.uaddCarry = uaddCarry;
|
|
1370
|
+
exports.umulhi = umulhi;
|
|
1371
|
+
exports.usubBorrow = usubBorrow;
|
|
1372
|
+
exports.vertexNormalsHelper = vertexNormalsHelper;
|