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