@cimplify/sdk 0.108.0 → 0.110.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/LICENSE +21 -0
  2. package/dist/advanced.d.mts +4 -3
  3. package/dist/advanced.d.ts +4 -3
  4. package/dist/advanced.js +24 -24
  5. package/dist/advanced.mjs +5 -5
  6. package/dist/animation-4EXBXRVX.js +27 -0
  7. package/dist/animation-6DICNWUP.mjs +6 -0
  8. package/dist/audio-DhvyjqdA.d.mts +249 -0
  9. package/dist/audio-m0w8cnxq.d.ts +249 -0
  10. package/dist/avatars.d.mts +110 -0
  11. package/dist/avatars.d.ts +110 -0
  12. package/dist/avatars.js +82 -0
  13. package/dist/avatars.mjs +5 -0
  14. package/dist/backend-gUCzs5Kg.d.mts +3866 -0
  15. package/dist/backend-gUCzs5Kg.d.ts +3866 -0
  16. package/dist/{catalogue-B4eLL8Mi.d.ts → catalogue-CPTMyBUz.d.mts} +109 -221
  17. package/dist/catalogue-DzrTXP3v.d.mts +541 -0
  18. package/dist/catalogue-DzrTXP3v.d.ts +541 -0
  19. package/dist/{catalogue-OT89_Ifs.d.mts → catalogue-OTuS5zp-.d.ts} +109 -221
  20. package/dist/chunk-22BD3RHN.mjs +1809 -0
  21. package/dist/chunk-25T4JHEA.mjs +21 -0
  22. package/dist/chunk-2AQ237Y4.js +508 -0
  23. package/dist/chunk-2IC4H6OV.mjs +48 -0
  24. package/dist/chunk-2LHLG4OB.mjs +71 -0
  25. package/dist/chunk-2O2CG465.js +1709 -0
  26. package/dist/chunk-2Q4DTHXK.js +316 -0
  27. package/dist/chunk-2QTQ6BUH.mjs +46 -0
  28. package/dist/chunk-2UN4SFLR.mjs +100 -0
  29. package/dist/chunk-2V75I7K3.js +454 -0
  30. package/dist/chunk-2V7IL4HC.js +10 -0
  31. package/dist/chunk-34XBXUMW.js +296 -0
  32. package/dist/chunk-3C4C654I.js +71 -0
  33. package/dist/chunk-3DAD2LDF.mjs +72 -0
  34. package/dist/chunk-3GXH2NFD.mjs +4 -0
  35. package/dist/chunk-3O47ZFW3.js +961 -0
  36. package/dist/chunk-3OY3VYNF.mjs +11 -0
  37. package/dist/chunk-3S6WPBZL.js +2936 -0
  38. package/dist/chunk-3TUOUP5T.js +399 -0
  39. package/dist/chunk-3VEH23I5.mjs +1380 -0
  40. package/dist/chunk-3ZYSAW2T.mjs +263 -0
  41. package/dist/chunk-4ANVF274.js +103 -0
  42. package/dist/chunk-4C7I3ELN.js +388 -0
  43. package/dist/chunk-4DYKAYFO.mjs +8 -0
  44. package/dist/chunk-4ZDR72SG.js +329 -0
  45. package/dist/chunk-52YS45RR.js +1066 -0
  46. package/dist/chunk-5325XSCH.js +107 -0
  47. package/dist/chunk-5AD5X6AV.js +13 -0
  48. package/dist/chunk-5BYDGGWO.mjs +197 -0
  49. package/dist/chunk-5C3C7VDM.mjs +55 -0
  50. package/dist/chunk-5HFMY3D7.js +660 -0
  51. package/dist/chunk-5LH2QN3T.js +1862 -0
  52. package/dist/chunk-5PJEXSOW.js +44 -0
  53. package/dist/chunk-5SXDH3Y7.js +90 -0
  54. package/dist/chunk-5YFBGGCK.mjs +502 -0
  55. package/dist/chunk-5YWN6H5Q.mjs +133 -0
  56. package/dist/chunk-66QP3SMN.js +402 -0
  57. package/dist/chunk-6DAEZKIG.mjs +385 -0
  58. package/dist/chunk-6DATW7TB.mjs +420 -0
  59. package/dist/{chunk-JRGK3NXR.mjs → chunk-6ETDAU62.mjs} +72 -212
  60. package/dist/chunk-6H254EVP.mjs +178 -0
  61. package/dist/chunk-6PFNJPBJ.mjs +820 -0
  62. package/dist/chunk-6PJWXIFX.mjs +357 -0
  63. package/dist/chunk-6SWKWCMS.js +80 -0
  64. package/dist/chunk-6VVXXX7S.js +808 -0
  65. package/dist/chunk-6WUBSMTX.js +1403 -0
  66. package/dist/chunk-73SGZLAQ.mjs +35 -0
  67. package/dist/chunk-76L2V6KD.mjs +4 -0
  68. package/dist/chunk-7AAIAVAA.js +1531 -0
  69. package/dist/chunk-7ARSJPV3.mjs +93 -0
  70. package/dist/chunk-7BHW5GTC.mjs +1234 -0
  71. package/dist/chunk-7DQSDKDU.js +6 -0
  72. package/dist/chunk-7IQQQENP.mjs +401 -0
  73. package/dist/chunk-7KFTYENS.js +11357 -0
  74. package/dist/chunk-7SM6XSPZ.js +3171 -0
  75. package/dist/chunk-7SXOHAIR.mjs +28 -0
  76. package/dist/chunk-A2MAX6S4.js +90 -0
  77. package/dist/chunk-A33OORT7.mjs +1530 -0
  78. package/dist/{chunk-U6ACF76H.mjs → chunk-A36JRXXH.mjs} +1075 -1845
  79. package/dist/chunk-A7BU3BK4.js +52 -0
  80. package/dist/chunk-A7MQSN2V.mjs +77 -0
  81. package/dist/chunk-A7V4L2IT.mjs +416 -0
  82. package/dist/chunk-AABEK6XU.js +226 -0
  83. package/dist/chunk-AGV33FWC.mjs +5005 -0
  84. package/dist/chunk-AHNR3BXI.js +108 -0
  85. package/dist/chunk-AQ5RLBU2.mjs +286 -0
  86. package/dist/chunk-AQOE6WCG.js +1270 -0
  87. package/dist/chunk-ATAWRACV.mjs +62 -0
  88. package/dist/chunk-ATCURNUV.js +14 -0
  89. package/dist/chunk-AWPV33OO.js +6 -0
  90. package/dist/chunk-AYJPHKYV.js +337 -0
  91. package/dist/chunk-AZ5BGWHB.js +162 -0
  92. package/dist/chunk-AZAXD44P.js +1373 -0
  93. package/dist/chunk-BBGKQIJJ.mjs +406 -0
  94. package/dist/chunk-BP4JLSUA.js +1453 -0
  95. package/dist/{chunk-SUCE7FWA.mjs → chunk-BTUSVHIE.mjs} +539 -978
  96. package/dist/chunk-BU6OK542.mjs +818 -0
  97. package/dist/chunk-CVSRWM6W.js +418 -0
  98. package/dist/chunk-CYBMFMJD.mjs +247 -0
  99. package/dist/chunk-DDJLDOUX.mjs +217 -0
  100. package/dist/{chunk-V32BCG7M.js → chunk-DFZWHNRG.js} +75 -215
  101. package/dist/chunk-DJ2C7AVG.js +644 -0
  102. package/dist/chunk-DS2VU4WW.mjs +102 -0
  103. package/dist/chunk-DSAG7T5P.js +7290 -0
  104. package/dist/chunk-E2QPPH7I.js +327 -0
  105. package/dist/chunk-E65WCTIG.mjs +1187 -0
  106. package/dist/{chunk-33VCYWVL.mjs → chunk-E6QQKDNE.mjs} +30 -42
  107. package/dist/chunk-ECDK6QBF.mjs +981 -0
  108. package/dist/chunk-EIB4OWVQ.mjs +620 -0
  109. package/dist/chunk-EQUZYCGO.js +250 -0
  110. package/dist/chunk-F3UJ6ZRM.mjs +313 -0
  111. package/dist/chunk-F63N2ZTQ.js +7023 -0
  112. package/dist/chunk-F6XRYEM3.mjs +26 -0
  113. package/dist/chunk-FE6VCE4K.js +5030 -0
  114. package/dist/chunk-FLWD6GRR.js +1372 -0
  115. package/dist/chunk-FQBFWJBS.mjs +110 -0
  116. package/dist/chunk-FXVJ2HFU.js +26 -0
  117. package/dist/chunk-FZMQMQBW.js +312 -0
  118. package/dist/chunk-G3EEC44R.js +53 -0
  119. package/dist/{chunk-KG3WT4PR.mjs → chunk-GCKWKLZF.mjs} +73 -104
  120. package/dist/chunk-GCX7TY4D.mjs +6826 -0
  121. package/dist/chunk-GDB6TCSD.js +450 -0
  122. package/dist/chunk-GDCV4IWO.mjs +21 -0
  123. package/dist/chunk-GDZT5LZ5.js +170 -0
  124. package/dist/chunk-GHPUYD4I.mjs +213 -0
  125. package/dist/chunk-GHS6MIL6.mjs +1432 -0
  126. package/dist/chunk-GPS2THCL.mjs +11 -0
  127. package/dist/{chunk-EV2EVOYS.js → chunk-GTJWQAGU.js} +31 -42
  128. package/dist/chunk-GVTI6UJQ.mjs +130 -0
  129. package/dist/chunk-GXKI64OT.mjs +1138 -0
  130. package/dist/chunk-GYDYF2WX.js +275 -0
  131. package/dist/chunk-GYLP6UG4.mjs +705 -0
  132. package/dist/chunk-H3OQKK6X.js +1158 -0
  133. package/dist/chunk-H5DFSCJ6.js +40 -0
  134. package/dist/chunk-HAGEIC2L.mjs +186 -0
  135. package/dist/chunk-HAJ4JRFO.js +293 -0
  136. package/dist/chunk-HDR72GB6.js +188 -0
  137. package/dist/chunk-HF5HPS4T.mjs +40 -0
  138. package/dist/chunk-HK6LOFDS.js +218 -0
  139. package/dist/chunk-HMWYTXCY.mjs +143 -0
  140. package/dist/chunk-HPCSRCMA.js +89 -0
  141. package/dist/chunk-HSEO6TPU.js +247 -0
  142. package/dist/chunk-I5FOHCLH.js +132 -0
  143. package/dist/chunk-IDLW4NWA.mjs +85 -0
  144. package/dist/chunk-IIDZ5WUX.js +61 -0
  145. package/dist/chunk-IR74FJHU.js +2332 -0
  146. package/dist/chunk-IRVFYAKP.mjs +100 -0
  147. package/dist/{chunk-XBL3TMPC.mjs → chunk-IZDWAL53.mjs} +1795 -3287
  148. package/dist/chunk-J2KZXIU3.js +51 -0
  149. package/dist/chunk-J2U6PJSO.js +91 -0
  150. package/dist/chunk-J5AJNY2N.js +283 -0
  151. package/dist/chunk-J6KQZ4FO.mjs +821 -0
  152. package/dist/{chunk-OWW5GUSB.js → chunk-JGBCIKJV.js} +7 -6
  153. package/dist/chunk-JKGTBMU7.mjs +25 -0
  154. package/dist/chunk-JR3TNEQC.js +422 -0
  155. package/dist/chunk-JURRXY2J.mjs +29 -0
  156. package/dist/chunk-K3HW5I2A.mjs +317 -0
  157. package/dist/chunk-K46SMZ66.mjs +103 -0
  158. package/dist/chunk-K4UDGE3Z.mjs +6 -0
  159. package/dist/chunk-KDQOR4QQ.mjs +350 -0
  160. package/dist/chunk-KDTVOLHI.mjs +288 -0
  161. package/dist/chunk-KGHJH5KJ.mjs +35 -0
  162. package/dist/chunk-KIZOA5LX.mjs +140 -0
  163. package/dist/chunk-KK6HYVBI.mjs +242 -0
  164. package/dist/chunk-KMKWGXMK.js +856 -0
  165. package/dist/chunk-KPA6K5IB.js +80 -0
  166. package/dist/chunk-KU7O4IXU.mjs +260 -0
  167. package/dist/chunk-KVFNRJOR.mjs +11142 -0
  168. package/dist/chunk-KZJRSXHK.js +2432 -0
  169. package/dist/chunk-LHWPRUJL.js +79 -0
  170. package/dist/chunk-LIV3KXJG.mjs +369 -0
  171. package/dist/chunk-LKV4LACG.js +21 -0
  172. package/dist/chunk-LUY45X3U.mjs +263 -0
  173. package/dist/chunk-LYEZZEEF.mjs +17 -0
  174. package/dist/chunk-M5EXQZYY.mjs +1519 -0
  175. package/dist/chunk-ME6HGG4I.mjs +1338 -0
  176. package/dist/chunk-MEXP6DA6.js +31 -0
  177. package/dist/chunk-MG52AW3H.js +902 -0
  178. package/dist/chunk-MIPO6F72.js +334 -0
  179. package/dist/{chunk-5QW7CQBA.js → chunk-MKIJQL5Q.js} +211 -321
  180. package/dist/chunk-MN3YETVN.mjs +17 -0
  181. package/dist/chunk-MOBSBXVE.mjs +2391 -0
  182. package/dist/chunk-MOMOZEUM.mjs +88 -0
  183. package/dist/chunk-MRFUNRAP.js +62 -0
  184. package/dist/chunk-MTIHEW2M.js +433 -0
  185. package/dist/chunk-N4RGGDEL.mjs +73 -0
  186. package/dist/chunk-NH654HAT.js +10 -0
  187. package/dist/chunk-NHJUGZUR.mjs +253 -0
  188. package/dist/chunk-NMQT4HG3.mjs +757 -0
  189. package/dist/chunk-NPSYB6DC.mjs +906 -0
  190. package/dist/chunk-NW2GPMSO.js +857 -0
  191. package/dist/chunk-NXKQOQ6L.js +76 -0
  192. package/dist/chunk-NXLAZIJZ.js +309 -0
  193. package/dist/chunk-NYWNA5CF.js +148 -0
  194. package/dist/chunk-NZTKLY2W.js +1442 -0
  195. package/dist/chunk-O2ICABUD.js +36 -0
  196. package/dist/chunk-OIVVQQ22.js +862 -0
  197. package/dist/chunk-OKC2B4O3.mjs +312 -0
  198. package/dist/chunk-OLWFPDBK.js +2220 -0
  199. package/dist/chunk-OMTVH334.js +3779 -0
  200. package/dist/chunk-OQRVEM56.mjs +362 -0
  201. package/dist/chunk-OXMIBOD4.js +337 -0
  202. package/dist/chunk-PBL6YL5L.mjs +288 -0
  203. package/dist/chunk-PDOELNNQ.js +97 -0
  204. package/dist/chunk-PDQJY2GZ.js +136 -0
  205. package/dist/chunk-PKOZXD2Q.js +1274 -0
  206. package/dist/chunk-PPF2BYFL.mjs +2191 -0
  207. package/dist/chunk-PQTQKNKD.js +539 -0
  208. package/dist/chunk-PRSR4FAV.mjs +81 -0
  209. package/dist/chunk-PTRNO5UD.js +95 -0
  210. package/dist/chunk-Q2Y3VMKH.js +2000 -0
  211. package/dist/chunk-QCZOE65N.js +96 -0
  212. package/dist/chunk-QDYFLATW.mjs +52 -0
  213. package/dist/chunk-QQABGCMM.js +22 -0
  214. package/dist/chunk-QS6TRHMR.js +345 -0
  215. package/dist/chunk-R56P64LB.mjs +208 -0
  216. package/dist/chunk-RCQ2MPBV.js +428 -0
  217. package/dist/chunk-RFVRPYR2.mjs +856 -0
  218. package/dist/chunk-RKBLPGPV.js +11521 -0
  219. package/dist/chunk-RM2V4IND.mjs +327 -0
  220. package/dist/chunk-RQXN5A34.mjs +613 -0
  221. package/dist/chunk-RUVGVNOF.mjs +2687 -0
  222. package/dist/chunk-SAFJIGYB.mjs +165 -0
  223. package/dist/chunk-SKQFLBDD.js +263 -0
  224. package/dist/chunk-SMK6JU2F.mjs +2092 -0
  225. package/dist/{chunk-UVRPC2P7.js → chunk-SNNEOS5Z.js} +1984 -3476
  226. package/dist/chunk-SPCRQ6NO.mjs +1246 -0
  227. package/dist/chunk-SWX4SALA.mjs +19 -0
  228. package/dist/{chunk-JVODCGFP.mjs → chunk-SYEO2WV4.mjs} +128 -238
  229. package/dist/chunk-T2QQMX2N.js +10 -0
  230. package/dist/chunk-T3AFF3L7.mjs +57 -0
  231. package/dist/chunk-T6Z2EXYL.js +712 -0
  232. package/dist/chunk-T7LOXGYX.js +118 -0
  233. package/dist/chunk-TJCAE7RC.mjs +1315 -0
  234. package/dist/chunk-TJI3K6RP.js +137 -0
  235. package/dist/chunk-TL2SVO4P.mjs +55 -0
  236. package/dist/chunk-TM63CYGN.mjs +399 -0
  237. package/dist/chunk-TU5RYTYU.mjs +13 -0
  238. package/dist/chunk-TVJZ4GPS.js +1553 -0
  239. package/dist/chunk-TWM6DLYF.js +371 -0
  240. package/dist/chunk-U63OC4TQ.js +30 -0
  241. package/dist/{chunk-L5GKVQVJ.js → chunk-U6BVSJZ6.js} +25 -57
  242. package/dist/chunk-U6UVWEAK.mjs +792 -0
  243. package/dist/chunk-UCEPNO6N.mjs +11048 -0
  244. package/dist/{chunk-ANT574FD.js → chunk-UCR5HRYM.js} +74 -105
  245. package/dist/chunk-UG5BTOTF.mjs +334 -0
  246. package/dist/chunk-UGH37BQW.mjs +157 -0
  247. package/dist/chunk-V7ZRH3PY.mjs +271 -0
  248. package/dist/chunk-VBGHBL3E.mjs +1394 -0
  249. package/dist/chunk-VRBDAS5I.js +920 -0
  250. package/dist/chunk-VVE3Y76O.js +230 -0
  251. package/dist/chunk-W65JIRI4.mjs +1182 -0
  252. package/dist/chunk-WHYKAT7G.js +62 -0
  253. package/dist/{chunk-YOIVZ6OA.mjs → chunk-WIZRUIZB.mjs} +25 -57
  254. package/dist/chunk-WKWTDZS7.js +385 -0
  255. package/dist/chunk-WLMINRC4.mjs +78 -0
  256. package/dist/chunk-WOF3AD3J.js +22 -0
  257. package/dist/chunk-WWKMOA76.js +1262 -0
  258. package/dist/chunk-X5A5FOWW.js +615 -0
  259. package/dist/chunk-X6CN6KQF.mjs +192 -0
  260. package/dist/chunk-XD2PMH46.mjs +517 -0
  261. package/dist/chunk-XJA2NGTI.mjs +88 -0
  262. package/dist/chunk-XJIHN3BY.mjs +8 -0
  263. package/dist/chunk-XK6UDWJS.js +203 -0
  264. package/dist/chunk-XPG3N5CF.mjs +415 -0
  265. package/dist/chunk-XVZ2NKSU.mjs +74 -0
  266. package/dist/chunk-XYP45OLE.js +117 -0
  267. package/dist/chunk-XZSDGZX6.mjs +301 -0
  268. package/dist/chunk-Y2EMGN4T.mjs +120 -0
  269. package/dist/chunk-Y3XWP5XW.mjs +298 -0
  270. package/dist/chunk-Y4K22JL6.js +228 -0
  271. package/dist/chunk-Y65LXQGA.mjs +3164 -0
  272. package/dist/chunk-Y66WVMO5.mjs +87 -0
  273. package/dist/chunk-Y7JWLB25.mjs +7280 -0
  274. package/dist/chunk-YCDXAJKU.js +175 -0
  275. package/dist/chunk-YRDQCCIS.js +152 -0
  276. package/dist/chunk-YV52DGSA.js +111 -0
  277. package/dist/chunk-YXGZQPUD.js +94 -0
  278. package/dist/chunk-Z3A3AFVU.mjs +102 -0
  279. package/dist/chunk-ZCY6YKKP.mjs +475 -0
  280. package/dist/chunk-ZEQHXVU5.js +215 -0
  281. package/dist/chunk-ZF7JCXCI.js +284 -0
  282. package/dist/chunk-ZJBRUH6V.js +29 -0
  283. package/dist/chunk-ZMIL4ZOA.js +365 -0
  284. package/dist/chunk-ZR5ULMN2.mjs +337 -0
  285. package/dist/chunk-ZXREOYOW.js +87 -0
  286. package/dist/{client-BSP9U1O1.d.mts → client-CX_WR0-J.d.mts} +2 -2
  287. package/dist/client-Dytx_ZTC.d.ts +230 -0
  288. package/dist/{client-B878xeAP.d.ts → client-dqOhP9Nc.d.ts} +2 -2
  289. package/dist/client-hTKbCuhG.d.mts +230 -0
  290. package/dist/clock-B-UAjkKa.d.mts +5 -0
  291. package/dist/clock-B-UAjkKa.d.ts +5 -0
  292. package/dist/config-BlXQluJR.d.mts +36 -0
  293. package/dist/config-BlXQluJR.d.ts +36 -0
  294. package/dist/courier-Cnn-edJ4.d.ts +95 -0
  295. package/dist/courier-FmGfkvIN.d.mts +95 -0
  296. package/dist/crowd-DdHFbqKK.d.ts +186 -0
  297. package/dist/crowd-hOVSAmA3.d.mts +186 -0
  298. package/dist/danfo-BEBapFlX.d.mts +146 -0
  299. package/dist/danfo-UQ_PTIIx.d.ts +146 -0
  300. package/dist/{elements-Bty6Qs_N.d.mts → elements-DdsRig-2.d.mts} +1548 -257
  301. package/dist/{elements-Bty6Qs_N.d.ts → elements-DdsRig-2.d.ts} +1548 -257
  302. package/dist/engines/godot.d.mts +56 -0
  303. package/dist/engines/godot.d.ts +56 -0
  304. package/dist/engines/godot.js +28 -0
  305. package/dist/engines/godot.mjs +3 -0
  306. package/dist/engines/wasm.d.mts +11 -0
  307. package/dist/engines/wasm.d.ts +11 -0
  308. package/dist/engines/wasm.js +178 -0
  309. package/dist/engines/wasm.mjs +176 -0
  310. package/dist/fallback-CrG_lTFk.d.mts +270 -0
  311. package/dist/fallback-CrG_lTFk.d.ts +270 -0
  312. package/dist/fallback-KDB4Y2CE.mjs +6 -0
  313. package/dist/fallback-Y26TQENE.js +19 -0
  314. package/dist/features-CZB4rmcD.d.mts +118 -0
  315. package/dist/features-CZB4rmcD.d.ts +118 -0
  316. package/dist/fit-BWiE7rgA.d.mts +44 -0
  317. package/dist/fit-DK0oT7zO.d.ts +44 -0
  318. package/dist/five-a-side-Bv1AOUy3.d.mts +115 -0
  319. package/dist/five-a-side-EC51SJY1.d.ts +115 -0
  320. package/dist/fluid-ARr0qUIL.d.ts +939 -0
  321. package/dist/fluid-DLlEj2cs.d.mts +939 -0
  322. package/dist/game/conformance.d.mts +84 -0
  323. package/dist/game/conformance.d.ts +84 -0
  324. package/dist/game/conformance.js +1025 -0
  325. package/dist/game/conformance.mjs +994 -0
  326. package/dist/game/heap.d.mts +40 -0
  327. package/dist/game/heap.d.ts +40 -0
  328. package/dist/game/heap.js +48 -0
  329. package/dist/game/heap.mjs +7 -0
  330. package/dist/game/kit/canvas.d.mts +240 -0
  331. package/dist/game/kit/canvas.d.ts +240 -0
  332. package/dist/game/kit/canvas.js +3566 -0
  333. package/dist/game/kit/canvas.mjs +1039 -0
  334. package/dist/game/kit/courier.d.mts +17 -0
  335. package/dist/game/kit/courier.d.ts +17 -0
  336. package/dist/game/kit/courier.js +66 -0
  337. package/dist/game/kit/courier.mjs +49 -0
  338. package/dist/game/kit/danfo.d.mts +11 -0
  339. package/dist/game/kit/danfo.d.ts +11 -0
  340. package/dist/game/kit/danfo.js +109 -0
  341. package/dist/game/kit/danfo.mjs +44 -0
  342. package/dist/game/kit/engine.d.mts +29 -0
  343. package/dist/game/kit/engine.d.ts +29 -0
  344. package/dist/game/kit/engine.js +183 -0
  345. package/dist/game/kit/engine.mjs +30 -0
  346. package/dist/game/kit/five-a-side.d.mts +11 -0
  347. package/dist/game/kit/five-a-side.d.ts +11 -0
  348. package/dist/game/kit/five-a-side.js +86 -0
  349. package/dist/game/kit/five-a-side.mjs +41 -0
  350. package/dist/game/kit/frontier.d.mts +344 -0
  351. package/dist/game/kit/frontier.d.ts +344 -0
  352. package/dist/game/kit/frontier.js +435 -0
  353. package/dist/game/kit/frontier.mjs +14 -0
  354. package/dist/game/kit/genesis.d.mts +752 -0
  355. package/dist/game/kit/genesis.d.ts +752 -0
  356. package/dist/game/kit/genesis.js +380 -0
  357. package/dist/game/kit/genesis.mjs +15 -0
  358. package/dist/game/kit/ludo.d.mts +15 -0
  359. package/dist/game/kit/ludo.d.ts +15 -0
  360. package/dist/game/kit/ludo.js +87 -0
  361. package/dist/game/kit/ludo.mjs +42 -0
  362. package/dist/game/kit/runner.d.mts +12 -0
  363. package/dist/game/kit/runner.d.ts +12 -0
  364. package/dist/game/kit/runner.js +83 -0
  365. package/dist/game/kit/runner.mjs +46 -0
  366. package/dist/game/kit/shootout.d.mts +13 -0
  367. package/dist/game/kit/shootout.d.ts +13 -0
  368. package/dist/game/kit/shootout.js +122 -0
  369. package/dist/game/kit/shootout.mjs +57 -0
  370. package/dist/game/kit/slots.d.mts +392 -0
  371. package/dist/game/kit/slots.d.ts +392 -0
  372. package/dist/game/kit/slots.js +215 -0
  373. package/dist/game/kit/slots.mjs +6 -0
  374. package/dist/game/kit/tycoon.d.mts +16 -0
  375. package/dist/game/kit/tycoon.d.ts +16 -0
  376. package/dist/game/kit/tycoon.js +145 -0
  377. package/dist/game/kit/tycoon.mjs +44 -0
  378. package/dist/game/kit/word.d.mts +11 -0
  379. package/dist/game/kit/word.d.ts +11 -0
  380. package/dist/game/kit/word.js +78 -0
  381. package/dist/game/kit/word.mjs +41 -0
  382. package/dist/game/kit/worlds.d.mts +18 -0
  383. package/dist/game/kit/worlds.d.ts +18 -0
  384. package/dist/game/kit/worlds.js +74 -0
  385. package/dist/game/kit/worlds.mjs +49 -0
  386. package/dist/game/kit.d.mts +53 -0
  387. package/dist/game/kit.d.ts +53 -0
  388. package/dist/game/kit.js +2610 -0
  389. package/dist/game/kit.mjs +101 -0
  390. package/dist/game/prepared.d.mts +14 -0
  391. package/dist/game/prepared.d.ts +14 -0
  392. package/dist/game/prepared.js +81 -0
  393. package/dist/game/prepared.mjs +32 -0
  394. package/dist/game-Bx8onkhX.d.mts +1451 -0
  395. package/dist/game-fgQy2YIm.d.ts +1451 -0
  396. package/dist/game-theme-CBTw1b_d.d.mts +35 -0
  397. package/dist/game-theme-Dg-ict5A.d.ts +35 -0
  398. package/dist/game.d.mts +3546 -0
  399. package/dist/game.d.ts +3546 -0
  400. package/dist/game.js +4455 -0
  401. package/dist/game.mjs +50 -0
  402. package/dist/graphics-C6YjWYvP.d.ts +5 -0
  403. package/dist/graphics-Dk2yQnYN.d.mts +5 -0
  404. package/dist/guest-DrsA00XD.d.mts +732 -0
  405. package/dist/guest-wIdfoT05.d.ts +732 -0
  406. package/dist/hit-stop-BKkVwTq7.d.mts +43 -0
  407. package/dist/hit-stop-D-8pPYnM.d.ts +43 -0
  408. package/dist/hot-Crn9XpHJ.d.ts +29 -0
  409. package/dist/hot-DH3nOhQD.d.mts +29 -0
  410. package/dist/{index-CQStGb3B.d.mts → index-6gkHMGAq.d.mts} +2 -2
  411. package/dist/index-B8ybCKJI.d.ts +41 -0
  412. package/dist/{index-DJwXmoaP.d.ts → index-B98Xac8e.d.ts} +2 -2
  413. package/dist/{index-B7oA_1XI.d.ts → index-B_ByTtIT.d.ts} +2 -2
  414. package/dist/index-DHjNHb1c.d.mts +41 -0
  415. package/dist/{index-DhUSTAhT.d.mts → index-DbAN_VQE.d.mts} +2 -2
  416. package/dist/index.d.mts +134 -24
  417. package/dist/index.d.ts +134 -24
  418. package/dist/index.js +407 -248
  419. package/dist/index.mjs +184 -58
  420. package/dist/interactives-authoring.d.mts +231 -0
  421. package/dist/interactives-authoring.d.ts +231 -0
  422. package/dist/interactives-authoring.js +1743 -0
  423. package/dist/interactives-authoring.mjs +1704 -0
  424. package/dist/interactives-canvas.global.js +148 -0
  425. package/dist/interactives-guest.d.mts +20 -0
  426. package/dist/interactives-guest.d.ts +20 -0
  427. package/dist/interactives-guest.js +63 -0
  428. package/dist/interactives-guest.json +1 -0
  429. package/dist/interactives-guest.mjs +61 -0
  430. package/dist/interactives-jsc.global.js +9357 -0
  431. package/dist/interactives-meters.d.mts +93 -0
  432. package/dist/interactives-meters.d.ts +93 -0
  433. package/dist/interactives-meters.js +252 -0
  434. package/dist/interactives-meters.mjs +68 -0
  435. package/dist/interactives-production.d.mts +430 -0
  436. package/dist/interactives-production.d.ts +430 -0
  437. package/dist/interactives-production.js +1231 -0
  438. package/dist/interactives-production.mjs +1170 -0
  439. package/dist/interactives-record.d.mts +112 -0
  440. package/dist/interactives-record.d.ts +112 -0
  441. package/dist/interactives-record.js +302 -0
  442. package/dist/interactives-record.mjs +295 -0
  443. package/dist/interactives-runtime.d.mts +61 -0
  444. package/dist/interactives-runtime.d.ts +61 -0
  445. package/dist/interactives-runtime.js +442 -0
  446. package/dist/interactives-runtime.mjs +25 -0
  447. package/dist/interactives-studio-kernel.global.js +1 -0
  448. package/dist/interactives-studio.d.mts +806 -0
  449. package/dist/interactives-studio.d.ts +806 -0
  450. package/dist/interactives-studio.js +5741 -0
  451. package/dist/interactives-studio.mjs +5651 -0
  452. package/dist/interactives-tick.d.mts +90 -0
  453. package/dist/interactives-tick.d.ts +90 -0
  454. package/dist/interactives-tick.js +203 -0
  455. package/dist/interactives-tick.mjs +6 -0
  456. package/dist/interactives-web.d.mts +762 -0
  457. package/dist/interactives-web.d.ts +762 -0
  458. package/dist/interactives-web.js +5000 -0
  459. package/dist/interactives-web.mjs +4628 -0
  460. package/dist/interactives.d.mts +2430 -0
  461. package/dist/interactives.d.ts +2430 -0
  462. package/dist/interactives.js +5723 -0
  463. package/dist/interactives.mjs +4333 -0
  464. package/dist/juice-CoHxlpKA.d.ts +42 -0
  465. package/dist/juice-DQztFS43.d.mts +42 -0
  466. package/dist/launch-T2f4_Di4.d.mts +151 -0
  467. package/dist/launch-d6oreMzR.d.ts +151 -0
  468. package/dist/library-DXYaMFhi.d.mts +69 -0
  469. package/dist/library-DXYaMFhi.d.ts +69 -0
  470. package/dist/link-BUTqGmyi.d.mts +38 -0
  471. package/dist/link-BUTqGmyi.d.ts +38 -0
  472. package/dist/lint.js +104 -204
  473. package/dist/lint.mjs +103 -203
  474. package/dist/local-D8_I6UeL.d.mts +6967 -0
  475. package/dist/local-VZkqsCzR.d.ts +6967 -0
  476. package/dist/lockstep-BLf6dglI.d.mts +321 -0
  477. package/dist/lockstep-D50Ia0JW.d.ts +321 -0
  478. package/dist/ludo-B8ClkDqr.d.ts +205 -0
  479. package/dist/ludo-BOuohQ-M.d.mts +205 -0
  480. package/dist/mock/cli.mjs +200 -56
  481. package/dist/mock/library.js +200 -56
  482. package/dist/mock/library.mjs +200 -56
  483. package/dist/mock/msw.js +200 -56
  484. package/dist/mock/msw.mjs +200 -56
  485. package/dist/native-BodxSh03.d.mts +16 -0
  486. package/dist/native-DUHMT8gA.d.ts +16 -0
  487. package/dist/network-ZXLD7l1b.d.mts +19 -0
  488. package/dist/network-ZXLD7l1b.d.ts +19 -0
  489. package/dist/online-XeymeM9s.d.ts +381 -0
  490. package/dist/online-d7W_Al9a.d.mts +381 -0
  491. package/dist/params-DxFb5G_U.d.mts +155 -0
  492. package/dist/params-DxFb5G_U.d.ts +155 -0
  493. package/dist/play-BRRlfLhX.d.ts +940 -0
  494. package/dist/play-ClrMd_e8.d.mts +940 -0
  495. package/dist/policy-CCw8tXLm.d.mts +3078 -0
  496. package/dist/policy-CMqOSQIu.d.ts +3078 -0
  497. package/dist/ports-B_0v_P3A.d.mts +13 -0
  498. package/dist/ports-CGU_3e_0.d.ts +13 -0
  499. package/dist/prefetch-BHnicOQj.d.ts +117 -0
  500. package/dist/prefetch-CBXgYacv.d.mts +117 -0
  501. package/dist/{price-CSztR02F.d.mts → price-BOzexBww.d.mts} +1 -1
  502. package/dist/{price-C_vasx9A.d.ts → price-C1h9sPxE.d.ts} +1 -1
  503. package/dist/protocol-C8qbpUbT.d.mts +242 -0
  504. package/dist/protocol-C8qbpUbT.d.ts +242 -0
  505. package/dist/rapier-AZHT4YI7.js +7886 -0
  506. package/dist/rapier-ODEPCQA6.mjs +7792 -0
  507. package/dist/react.d.mts +157 -15
  508. package/dist/react.d.ts +157 -15
  509. package/dist/react.js +5564 -5904
  510. package/dist/react.mjs +5451 -5808
  511. package/dist/runner-CQcLL7By.d.ts +189 -0
  512. package/dist/runner-D46Yj-wE.d.mts +189 -0
  513. package/dist/runtime-BRWfkf_q.d.mts +51 -0
  514. package/dist/runtime-DyuBMkKM.d.ts +51 -0
  515. package/dist/scheduling-D2ajXpMC.d.ts +224 -0
  516. package/dist/scheduling-DSRbbaZb.d.mts +224 -0
  517. package/dist/schema-BrWxzKp6.d.mts +63 -0
  518. package/dist/schema-BrWxzKp6.d.ts +63 -0
  519. package/dist/server/evict.js +34 -37
  520. package/dist/server/evict.mjs +34 -37
  521. package/dist/server/tanstack.d.mts +49 -3
  522. package/dist/server/tanstack.d.ts +49 -3
  523. package/dist/server/tanstack.js +169 -117
  524. package/dist/server/tanstack.mjs +166 -118
  525. package/dist/{server-Dckg4Vdr.d.ts → server-D29IIuDV.d.ts} +136 -130
  526. package/dist/{server-B6dW7-Lj.d.mts → server-DQMWPnc8.d.mts} +136 -130
  527. package/dist/server.d.mts +45 -5
  528. package/dist/server.d.ts +45 -5
  529. package/dist/server.js +171 -227
  530. package/dist/server.mjs +165 -225
  531. package/dist/session-grant-CJ27DwrT.d.mts +19 -0
  532. package/dist/session-grant-CJ27DwrT.d.ts +19 -0
  533. package/dist/shootout-BJZeX6FG.d.ts +140 -0
  534. package/dist/shootout-tcZd1Rxt.d.mts +140 -0
  535. package/dist/state-replica-stMtdkVD.d.mts +42 -0
  536. package/dist/state-replica-stMtdkVD.d.ts +42 -0
  537. package/dist/studio-CowqWqez.d.mts +14 -0
  538. package/dist/studio-CowqWqez.d.ts +14 -0
  539. package/dist/styles.css +1 -1
  540. package/dist/template-AhCdB1kW.d.mts +190 -0
  541. package/dist/template-BkEGVTQj.d.ts +190 -0
  542. package/dist/terrain-BMxEc6Oc.d.ts +429 -0
  543. package/dist/terrain-C-XC1Oui.d.mts +429 -0
  544. package/dist/testing/msw.d.mts +28 -4
  545. package/dist/testing/msw.d.ts +28 -4
  546. package/dist/testing/msw.js +15 -21
  547. package/dist/testing/msw.mjs +15 -21
  548. package/dist/testing/suite.d.mts +6 -5
  549. package/dist/testing/suite.d.ts +6 -5
  550. package/dist/testing/suite.js +89 -124
  551. package/dist/testing/suite.mjs +81 -116
  552. package/dist/testing.d.mts +27 -1227
  553. package/dist/testing.d.ts +27 -1227
  554. package/dist/testing.js +127 -131
  555. package/dist/testing.mjs +19 -23
  556. package/dist/tick-transport-C8QEh8Uw.d.mts +50 -0
  557. package/dist/tick-transport-UjHY3xK1.d.ts +50 -0
  558. package/dist/timeline-protocol-hp6e8zFB.d.mts +47 -0
  559. package/dist/timeline-protocol-hp6e8zFB.d.ts +47 -0
  560. package/dist/tokens-DhanQRQS.d.mts +21 -0
  561. package/dist/tokens-K8yxwd6G.d.ts +21 -0
  562. package/dist/tree-C-Io2Hbx.d.mts +35 -0
  563. package/dist/tree-CP_qSW4H.d.ts +35 -0
  564. package/dist/tycoon-B5KHk2Xx.d.mts +255 -0
  565. package/dist/tycoon-hmHo-3HX.d.ts +255 -0
  566. package/dist/types-BQkxPwZP.d.mts +219 -0
  567. package/dist/types-D_f6UUxM.d.ts +219 -0
  568. package/dist/ui-DwHicuFv.d.mts +563 -0
  569. package/dist/ui-hi7S2YcH.d.ts +563 -0
  570. package/dist/{sign-in-DQlIdqsi.d.mts → url-52ndUruG.d.mts} +15 -1
  571. package/dist/{sign-in-DQlIdqsi.d.ts → url-52ndUruG.d.ts} +15 -1
  572. package/dist/utils.d.mts +3 -3
  573. package/dist/utils.d.ts +3 -3
  574. package/dist/utils.js +37 -37
  575. package/dist/utils.mjs +4 -4
  576. package/dist/vars-Dc_PrhBK.d.mts +511 -0
  577. package/dist/vars-Dc_PrhBK.d.ts +511 -0
  578. package/dist/vm-IUARFFAI.mjs +63 -0
  579. package/dist/vm-N7L6MGGH.js +65 -0
  580. package/dist/weave-delivery-CW-Kstut.d.mts +360 -0
  581. package/dist/weave-delivery-CW-Kstut.d.ts +360 -0
  582. package/dist/web-Dss74a7v.d.ts +883 -0
  583. package/dist/web-f9ZQPoyw.d.mts +883 -0
  584. package/dist/web-transport-C7MkBL0a.d.ts +19 -0
  585. package/dist/web-transport-aYEqXMd9.d.mts +19 -0
  586. package/dist/weight-CPGjsgjV.d.ts +92 -0
  587. package/dist/weight-tF1ODR1p.d.mts +92 -0
  588. package/dist/word-BcX9Jcmv.d.mts +70 -0
  589. package/dist/word-C7sVPLHm.d.ts +70 -0
  590. package/dist/world-PvILHDR1.d.ts +2285 -0
  591. package/dist/world-qekkXjJv.d.mts +2285 -0
  592. package/dist/worlds-Br2Pb0Cs.d.ts +109 -0
  593. package/dist/worlds-D5ydYr7d.d.mts +109 -0
  594. package/engines/c/cimplify.h +108 -0
  595. package/engines/c/cimplify.lib.js +11 -0
  596. package/engines/godot/addons/cimplify/cimplify.gd +97 -0
  597. package/engines/rust/interactives-ctx/Cargo.toml +9 -0
  598. package/engines/rust/interactives-ctx/src/lib.rs +189 -0
  599. package/package.json +189 -3
  600. package/vendor/rapier3d-compat/LICENSE +201 -0
  601. package/vendor/rapier3d-compat/PATCHES.md +61 -0
  602. package/dist/chunk-2P4KXFB6.js +0 -274
  603. package/dist/chunk-3G6RQLXK.mjs +0 -21
  604. package/dist/chunk-3V4DVXV3.mjs +0 -254
  605. package/dist/chunk-EDK3LNM6.js +0 -2436
  606. package/dist/chunk-F7J3HK27.js +0 -4549
  607. package/dist/chunk-U4MW6PYU.mjs +0 -23
  608. package/dist/chunk-XREIZ56K.js +0 -26
@@ -0,0 +1,1519 @@
1
+ import { JOIN_VERSION_DELTA, FALLBACK_AFTER_MS, CONNECT_TIMEOUT_MS, RESUME_TOKEN_BYTES, JOIN_REPLY_BYTES, JOIN_VERSION, U32_RANGE, AXIS_LIMIT, NANOS_PER_SECOND, SPAWN_ORIGIN_UNITS, SPAWN_ROW, SPAWN_SPACING_UNITS, WALK_UNITS_PER_SECOND, SPRINT_UNITS_PER_SECOND, BUTTON_SPRINT, VELOCITY_FRACTION, NETWORK_MEMORY_PREFIX, DEFAULT_NETWORK, OUTBOUND_POOL_SLOTS, PACKET_BYTES, APPLIED_RING, ENTITY_CAPACITY, WATCHER_SLOT, SPECTATOR_ACK_EVERY, SHORT_TICK_MASK, Lane, EXTRAPOLATION_CAP_MS, RETRY_AFTER_MS, RESUME_GRACE_MS, DEFAULT_SUBSTEPS, COMMAND_DURABLE_SLOT, MOVE_DURABLE_SLOT, MOVE_APPLIED_SLOT, INPUT_BUFFER_TARGET, CAMERA_RESEND_MS, SNAPSHOT_STREAM_SLOT, CAMERA_ACTION, CAMERA_PAYLOAD_BYTES, ACK_HISTORY_BITS, HIGH_LATENCY_ENTER_MS, HIGH_LATENCY_LEAVE_MS, LANE_LENGTH_BYTES, TIMING_BUFFERED_MASK, TIMING_TICK_SHIFT, JOIN_HEADER_BYTES, MAX_JOIN_BYTES, CELL_MAX_UNITS, NETWORK_MEMORY_TTL_MS, INBOUND_POOL_SLOTS, OFFSET_WINDOW, RTT_WINDOW, MS_PER_SECOND, INTERPOLATION_SEND_INTERVALS, JITTER_SMOOTHING, JITTER_MULTIPLIER, MAX_INTERPOLATION_DELAY_MS, DELAY_SMOOTHING, RTT_SMOOTHING, Pace, PACE_FASTER_SCALE, PACE_SLOWER_SCALE, MAX_CATCH_UP_TICKS, MAX_SUBTICK, MAX_SEND_STRIDE, SEND_RECOVER_MS, INPUT_LOG_CAPACITY, ROOM_LAYER, MAX_INPUTS_PER_PACKET, U16_RANGE, SNAPSHOT_RING, SEEN_TICKS, KEYFRAME_FLAG, REMOTE_HISTORY, SETTLED_OFFSET_UNITS, TIMING_PACE_SHIFT, STREAM_BUFFER_BYTES, SUBTICKS_PER_TICK, YAW_UNITS_PER_TURN, SMOOTHING_TIME_CONSTANT_MS, JOIN_TICKET, JOIN_RESUME, HALF_YAW_UNITS } from './chunk-TU5RYTYU.mjs';
2
+ import { dequantiseCellOffset, quantiseAxis, quantiseYaw, quantiseCellOffset, writeRoomInputHeader, writeChannelHeader, dequantiseHeight, dequantiseYaw, frameLength, peekFrameCode, FrameCode, decodeAck, decodeChannelFrame, encodeAck, FrameBufferPool, encodeMoveInput, decodePresenceDelta, decodePresenceTick, readPresenceEntry, readPresenceDeltaEntry } from './chunk-OQRVEM56.mjs';
3
+ import { FRAME_FLAGS, FRAME_LIMITS, FRAME_LAYOUT } from './chunk-SPCRQ6NO.mjs';
4
+
5
+ // src/interactives/rooms/connect.ts
6
+ var Connecting = {
7
+ Idle: 0,
8
+ Pending: 1,
9
+ Won: 2,
10
+ Failed: 3
11
+ }, Settled = {
12
+ Waiting: 0,
13
+ Dialed: 1,
14
+ Failed: 2
15
+ }, Attempt = class {
16
+ constructor(dialer, race) {
17
+ this.settled = Settled.Waiting;
18
+ this.dialed = null;
19
+ this.done = (dialed) => {
20
+ this.dialed = dialed, this.settled = dialed ? Settled.Dialed : Settled.Failed, this.race.settled(this);
21
+ };
22
+ this.failed = () => {
23
+ this.done(null);
24
+ };
25
+ this.dialer = dialer, this.race = race;
26
+ }
27
+ start(request) {
28
+ this.dialer.dial(request, this).then(this.done, this.failed);
29
+ }
30
+ frame(lane, bytes) {
31
+ this.race.forward(this, lane, bytes);
32
+ }
33
+ closed() {
34
+ this.race.lost(this);
35
+ }
36
+ backpressure(failures, status) {
37
+ this.race.backpressure(this, failures, status);
38
+ }
39
+ }, Connector = class {
40
+ constructor(primary, fallback, memory, network) {
41
+ this.sink = null;
42
+ this.request = null;
43
+ this.first = null;
44
+ this.second = null;
45
+ this.won = null;
46
+ this.networkKey = "";
47
+ this.startedAt = 0;
48
+ this.lastNow = 0;
49
+ this.state = Connecting.Idle;
50
+ this.primary = primary, this.fallback = fallback, this.memory = memory, this.network = network;
51
+ }
52
+ get winner() {
53
+ return this.won?.dialed ?? null;
54
+ }
55
+ begin(request, sink, nowMs) {
56
+ this.cancel(), this.sink = sink, this.request = request, this.startedAt = nowMs, this.lastNow = nowMs, this.state = Connecting.Pending, this.networkKey = this.network();
57
+ let remembered = this.memory.recall(this.networkKey, nowMs), opener = this.fallback !== null && remembered === this.fallback.transport || !this.primary ? this.fallback : this.primary;
58
+ if (!opener) {
59
+ this.state = Connecting.Failed;
60
+ return;
61
+ }
62
+ this.first = new Attempt(opener, this), opener === this.fallback && (this.second = this.first), this.first.start(request);
63
+ }
64
+ poll(nowMs) {
65
+ if (this.lastNow = nowMs, this.state !== Connecting.Pending) return this.state;
66
+ let elapsed = nowMs - this.startedAt;
67
+ return !this.second && this.fallback && (elapsed >= FALLBACK_AFTER_MS || this.first?.settled === Settled.Failed) && this.launchFallback(), this.state === Connecting.Pending && (elapsed >= CONNECT_TIMEOUT_MS || this.exhausted()) && this.fail(), this.state;
68
+ }
69
+ cancel() {
70
+ for (let attempt of [this.first, this.second]) attempt?.dialed?.link.close();
71
+ this.first = null, this.second = null, this.won = null, this.sink = null, this.state = Connecting.Idle;
72
+ }
73
+ release() {
74
+ let dialed = this.winner;
75
+ return this.first = null, this.second = null, this.state = Connecting.Idle, dialed;
76
+ }
77
+ forward(attempt, lane, bytes) {
78
+ attempt === this.won && this.sink?.frame(lane, bytes);
79
+ }
80
+ lost(attempt) {
81
+ attempt === this.won && this.sink?.closed();
82
+ }
83
+ backpressure(attempt, failures, status) {
84
+ attempt === this.won && this.sink?.backpressure?.(failures, status);
85
+ }
86
+ settled(attempt) {
87
+ if (attempt !== this.first && attempt !== this.second) {
88
+ attempt.dialed?.link.close();
89
+ return;
90
+ }
91
+ if (attempt.settled !== Settled.Dialed) return;
92
+ if (this.won) {
93
+ attempt !== this.won && attempt.dialed?.link.close();
94
+ return;
95
+ }
96
+ this.won = attempt, this.state = Connecting.Won;
97
+ let loser = attempt === this.first ? this.second : this.first;
98
+ loser && loser !== attempt && loser.dialed?.link.close(), this.primary && this.fallback && this.memory.remember(this.networkKey, attempt.dialer.transport, this.lastNow);
99
+ }
100
+ launchFallback() {
101
+ !this.fallback || !this.request || (this.second = new Attempt(this.fallback, this), this.second.start(this.request));
102
+ }
103
+ exhausted() {
104
+ let firstDone = !this.first || this.first.settled === Settled.Failed, secondDone = this.second ? this.second.settled === Settled.Failed : !this.fallback;
105
+ return firstDone && secondDone;
106
+ }
107
+ fail() {
108
+ let sink = this.sink;
109
+ this.cancel(), this.sink = sink, this.state = Connecting.Failed;
110
+ }
111
+ };
112
+
113
+ // src/interactives/rooms/join.ts
114
+ var JoinStatus = {
115
+ Admitted: 0,
116
+ Malformed: 1,
117
+ Forged: 2,
118
+ Expired: 3,
119
+ UnknownResume: 4,
120
+ Full: 5,
121
+ Overloaded: 6,
122
+ Unavailable: 7,
123
+ Prewarmed: 8,
124
+ Denied: 9
125
+ }, LAST_STATUS = JoinStatus.Denied, LITTLE_ENDIAN = true;
126
+ function blankReply() {
127
+ return {
128
+ status: JoinStatus.Unavailable,
129
+ slot: 0,
130
+ route: 0,
131
+ resume: new Uint8Array(RESUME_TOKEN_BYTES),
132
+ simulationHz: 0,
133
+ sendHz: 0,
134
+ tick: 0
135
+ };
136
+ }
137
+ function joinRequest(kind, body, version) {
138
+ if (JOIN_HEADER_BYTES + body.length > MAX_JOIN_BYTES) throw new RangeError("the join request is too large");
139
+ let out = new Uint8Array(JOIN_HEADER_BYTES + body.length), view = new DataView(out.buffer);
140
+ return view.setUint8(0, version), view.setUint8(1, kind), view.setUint16(2, body.length, (true)), out.set(body, JOIN_HEADER_BYTES), out;
141
+ }
142
+ function ticketRequest(ticket, version = JOIN_VERSION_DELTA) {
143
+ return joinRequest(JOIN_TICKET, ticket, version);
144
+ }
145
+ function resumeRequest(token, version = JOIN_VERSION_DELTA) {
146
+ return joinRequest(JOIN_RESUME, token, version);
147
+ }
148
+ function withoutDeltaPresence(request) {
149
+ return request.length === 0 || request[0] !== JOIN_VERSION_DELTA ? false : (request[0] = JOIN_VERSION, true);
150
+ }
151
+ function decodeJoinReply(bytes, out) {
152
+ if (bytes.length !== JOIN_REPLY_BYTES) return false;
153
+ let view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
154
+ if (view.getUint8(0) !== JOIN_VERSION) return false;
155
+ let status = view.getUint8(1);
156
+ return status > LAST_STATUS ? false : (out.status = status, out.slot = view.getUint16(2, (true)), out.route = view.getUint32(4, (true)), out.resume.set(bytes.subarray(8, 8 + RESUME_TOKEN_BYTES)), out.simulationHz = view.getUint16(24, (true)), out.sendHz = view.getUint16(26, (true)), out.tick = view.getUint32(32, (true)) * U32_RANGE + view.getUint32(28, (true)), true);
157
+ }
158
+
159
+ // src/interactives/rooms/locomotion.ts
160
+ var FRACTION_BITS = BigInt(24), LIMIT_SQUARED = AXIS_LIMIT * AXIS_LIMIT;
161
+ function perAxisUnit(unitsPerSecond, stepNs) {
162
+ let scaled = BigInt(unitsPerSecond) * BigInt(stepNs) << FRACTION_BITS, divisor = BigInt(AXIS_LIMIT) * BigInt(NANOS_PER_SECOND);
163
+ return Number(scaled / divisor);
164
+ }
165
+ function isqrt(value) {
166
+ let root = Math.floor(Math.sqrt(value));
167
+ for (; root * root > value; ) root -= 1;
168
+ for (; (root + 1) * (root + 1) <= value; ) root += 1;
169
+ return root;
170
+ }
171
+ function spawn(body, slot) {
172
+ body.x = SPAWN_ORIGIN_UNITS + slot % SPAWN_ROW * SPAWN_SPACING_UNITS, body.z = SPAWN_ORIGIN_UNITS + Math.floor(slot / SPAWN_ROW) * SPAWN_SPACING_UNITS, body.axisX = 0, body.axisZ = 0, body.buttons = 0;
173
+ }
174
+ function steer(body, axisX, axisZ, buttons) {
175
+ let x = Math.max(axisX, -AXIS_LIMIT), z = Math.max(axisZ, -AXIS_LIMIT), magnitudeSquared = x * x + z * z;
176
+ if (magnitudeSquared <= LIMIT_SQUARED)
177
+ body.axisX = x, body.axisZ = z;
178
+ else {
179
+ let magnitude = isqrt(magnitudeSquared);
180
+ body.axisX = Math.trunc(x * AXIS_LIMIT / magnitude), body.axisZ = Math.trunc(z * AXIS_LIMIT / magnitude);
181
+ }
182
+ body.buttons = buttons;
183
+ }
184
+ function clampUnits(value) {
185
+ return value < 0 ? 0 : value > CELL_MAX_UNITS ? CELL_MAX_UNITS : value;
186
+ }
187
+ var Locomotion = class {
188
+ constructor(simulationHz, physicsHz) {
189
+ this.substeps = Math.ceil(physicsHz / simulationHz), this.stepNs = Math.floor(NANOS_PER_SECOND / (simulationHz * this.substeps)), this.walk = perAxisUnit(WALK_UNITS_PER_SECOND, this.stepNs), this.sprint = perAxisUnit(SPRINT_UNITS_PER_SECOND, this.stepNs);
190
+ }
191
+ step(body) {
192
+ let scale = (body.buttons & BUTTON_SPRINT) !== 0 ? this.sprint : this.walk, stepX = Math.floor(body.axisX * scale / VELOCITY_FRACTION), stepZ = Math.floor(body.axisZ * scale / VELOCITY_FRACTION);
193
+ body.x = clampUnits(body.x + stepX * this.substeps), body.z = clampUnits(body.z + stepZ * this.substeps);
194
+ }
195
+ };
196
+
197
+ // src/interactives/rooms/motion.ts
198
+ var EXACT = 0, LocomotionMotion = class {
199
+ constructor(simulationHz, physicsHz) {
200
+ this.toleranceUnits = (0);
201
+ this.body = { x: 0, z: 0, axisX: 0, axisZ: 0, buttons: 0 };
202
+ this.locomotion = new Locomotion(simulationHz, physicsHz);
203
+ }
204
+ get x() {
205
+ return this.body.x;
206
+ }
207
+ get y() {
208
+ return 0;
209
+ }
210
+ get z() {
211
+ return this.body.z;
212
+ }
213
+ spawn(slot) {
214
+ spawn(this.body, slot);
215
+ }
216
+ steer(axisX, axisZ, buttons) {
217
+ steer(this.body, axisX, axisZ, buttons);
218
+ }
219
+ step() {
220
+ this.locomotion.step(this.body);
221
+ }
222
+ place(x, _y, z) {
223
+ this.body.x = x, this.body.z = z;
224
+ }
225
+ }, locomotionMotion = (simulationHz, physicsHz) => new LocomotionMotion(simulationHz, physicsHz);
226
+
227
+ // src/interactives/rooms/link.ts
228
+ var Transport = {
229
+ WebTransport: "web_transport",
230
+ WebSocket: "web_socket"
231
+ };
232
+
233
+ // src/interactives/rooms/network-memory.ts
234
+ function known(value) {
235
+ return value === Transport.WebTransport || value === Transport.WebSocket;
236
+ }
237
+ function fresh(remembered, nowMs) {
238
+ return !remembered || nowMs - remembered.at > NETWORK_MEMORY_TTL_MS ? null : remembered.transport;
239
+ }
240
+ var InMemoryNetworkMemory = class {
241
+ constructor() {
242
+ this.entries = /* @__PURE__ */ new Map();
243
+ }
244
+ recall(network, nowMs) {
245
+ return fresh(this.entries.get(network), nowMs);
246
+ }
247
+ remember(network, transport, nowMs) {
248
+ this.entries.set(network, { transport, at: nowMs });
249
+ }
250
+ }, StorageNetworkMemory = class {
251
+ constructor() {
252
+ this.fallback = new InMemoryNetworkMemory();
253
+ }
254
+ recall(network, nowMs) {
255
+ try {
256
+ let raw = globalThis.localStorage?.getItem(NETWORK_MEMORY_PREFIX + network);
257
+ if (!raw) return this.fallback.recall(network, nowMs);
258
+ let parsed = JSON.parse(raw);
259
+ if (typeof parsed != "object" || parsed === null) return null;
260
+ let entry = parsed;
261
+ return !known(entry.transport) || typeof entry.at != "number" ? null : fresh({ transport: entry.transport, at: entry.at }, nowMs);
262
+ } catch {
263
+ return this.fallback.recall(network, nowMs);
264
+ }
265
+ }
266
+ remember(network, transport, nowMs) {
267
+ this.fallback.remember(network, transport, nowMs);
268
+ try {
269
+ globalThis.localStorage?.setItem(NETWORK_MEMORY_PREFIX + network, JSON.stringify({ transport, at: nowMs }));
270
+ } catch {
271
+ return;
272
+ }
273
+ }
274
+ };
275
+ function currentNetwork() {
276
+ let connection = globalThis.navigator?.connection;
277
+ return connection?.type ?? connection?.effectiveType ?? DEFAULT_NETWORK;
278
+ }
279
+
280
+ // src/interactives/rooms/clock-sync.ts
281
+ var ClockSync = class {
282
+ constructor() {
283
+ this.tickMs = 0;
284
+ this.sendIntervalMs = 0;
285
+ this.offsets = new Float64Array(OFFSET_WINDOW);
286
+ this.rtts = new Float64Array(RTT_WINDOW);
287
+ this.offsetCount = 0;
288
+ this.offsetNext = 0;
289
+ this.rttCount = 0;
290
+ this.rttNext = 0;
291
+ this.offsetMs = 0;
292
+ this.jitter = 0;
293
+ this.smoothedRtt = 0;
294
+ this.delay = 0;
295
+ }
296
+ configure(simulationHz, sendHz, handshakeRttMs) {
297
+ this.tickMs = MS_PER_SECOND / simulationHz, this.sendIntervalMs = MS_PER_SECOND / sendHz, this.offsetCount = 0, this.offsetNext = 0, this.rttCount = 0, this.rttNext = 0, this.jitter = 0, this.offsetMs = 0, this.smoothedRtt = handshakeRttMs, this.delay = INTERPOLATION_SEND_INTERVALS * this.sendIntervalMs;
298
+ }
299
+ get tickIntervalMs() {
300
+ return this.tickMs;
301
+ }
302
+ get rttMs() {
303
+ return this.smoothedRtt;
304
+ }
305
+ get jitterMs() {
306
+ return this.jitter;
307
+ }
308
+ get interpolationDelayMs() {
309
+ return this.delay;
310
+ }
311
+ get synchronised() {
312
+ return this.offsetCount > 0;
313
+ }
314
+ snapshot(serverTick, nowMs) {
315
+ let sample = serverTick * this.tickMs - nowMs;
316
+ this.offsets[this.offsetNext] = sample, this.offsetNext = (this.offsetNext + 1) % OFFSET_WINDOW, this.offsetCount < OFFSET_WINDOW && (this.offsetCount += 1);
317
+ let best = sample;
318
+ for (let index = 0; index < this.offsetCount; index++) this.offsets[index] > best && (best = this.offsets[index]);
319
+ this.offsetMs = best, this.jitter += (best - sample - this.jitter) * JITTER_SMOOTHING;
320
+ let target = Math.min(
321
+ INTERPOLATION_SEND_INTERVALS * this.sendIntervalMs + JITTER_MULTIPLIER * this.jitter,
322
+ MAX_INTERPOLATION_DELAY_MS
323
+ );
324
+ this.delay += (target - this.delay) * DELAY_SMOOTHING;
325
+ }
326
+ roundTrip(sampleMs) {
327
+ if (!(sampleMs >= 0)) return;
328
+ this.rtts[this.rttNext] = sampleMs, this.rttNext = (this.rttNext + 1) % RTT_WINDOW, this.rttCount < RTT_WINDOW && (this.rttCount += 1);
329
+ let lowest = sampleMs;
330
+ for (let index = 0; index < this.rttCount; index++) this.rtts[index] < lowest && (lowest = this.rtts[index]);
331
+ this.smoothedRtt += (lowest - this.smoothedRtt) * RTT_SMOOTHING;
332
+ }
333
+ serverTick(nowMs) {
334
+ return (nowMs + this.offsetMs) / this.tickMs;
335
+ }
336
+ renderTick(nowMs) {
337
+ return (nowMs + this.offsetMs - this.delay) / this.tickMs;
338
+ }
339
+ leadTicks() {
340
+ return this.smoothedRtt / 2 / this.tickMs;
341
+ }
342
+ };
343
+
344
+ // src/interactives/rooms/inbound.ts
345
+ var InboundQueue = class {
346
+ constructor() {
347
+ this.pool = new FrameBufferPool(INBOUND_POOL_SLOTS, PACKET_BYTES);
348
+ this.slots = new Int32Array(INBOUND_POOL_SLOTS);
349
+ this.lanes = new Uint8Array(INBOUND_POOL_SLOTS);
350
+ this.lengths = new Int32Array(INBOUND_POOL_SLOTS);
351
+ this.head = 0;
352
+ this.count = 0;
353
+ this.current = -1;
354
+ this.dropped = 0;
355
+ this.sendFailures = 0;
356
+ this.lastSendStatus = 0;
357
+ this.lost = false;
358
+ }
359
+ clear() {
360
+ for (this.release(); this.count > 0; )
361
+ this.pool.release(this.slots[this.head]), this.head = (this.head + 1) % INBOUND_POOL_SLOTS, this.count -= 1;
362
+ this.lost = false;
363
+ }
364
+ frame(lane, bytes) {
365
+ if (bytes.length > PACKET_BYTES || this.count === INBOUND_POOL_SLOTS) {
366
+ this.dropped += 1;
367
+ return;
368
+ }
369
+ let slot = this.pool.acquire();
370
+ if (slot < 0) {
371
+ this.dropped += 1;
372
+ return;
373
+ }
374
+ this.pool.bytes(slot).set(bytes);
375
+ let at = (this.head + this.count) % INBOUND_POOL_SLOTS;
376
+ this.slots[at] = slot, this.lanes[at] = lane, this.lengths[at] = bytes.length, this.count += 1;
377
+ }
378
+ closed() {
379
+ this.lost = true;
380
+ }
381
+ backpressure(failures, status) {
382
+ this.sendFailures += failures, this.lastSendStatus = status;
383
+ }
384
+ next() {
385
+ return this.release(), this.count === 0 ? false : (this.current = this.head, this.head = (this.head + 1) % INBOUND_POOL_SLOTS, this.count -= 1, true);
386
+ }
387
+ get view() {
388
+ return this.pool.view(this.slots[this.current]);
389
+ }
390
+ get length() {
391
+ return this.lengths[this.current];
392
+ }
393
+ get lane() {
394
+ return this.lanes[this.current];
395
+ }
396
+ release() {
397
+ this.current < 0 || (this.pool.release(this.slots[this.current]), this.current = -1);
398
+ }
399
+ };
400
+
401
+ // src/interactives/rooms/input-log.ts
402
+ var InputLog = class {
403
+ constructor() {
404
+ this.buttons = new Uint8Array(INPUT_LOG_CAPACITY);
405
+ this.axisX = new Int16Array(INPUT_LOG_CAPACITY);
406
+ this.axisZ = new Int16Array(INPUT_LOG_CAPACITY);
407
+ this.yaw = new Uint16Array(INPUT_LOG_CAPACITY);
408
+ this.clientTick = new Float64Array(INPUT_LOG_CAPACITY);
409
+ this.subtick = new Uint8Array(INPUT_LOG_CAPACITY);
410
+ this.sentAt = new Float64Array(INPUT_LOG_CAPACITY);
411
+ this.frame = {
412
+ buttons: 0,
413
+ sequence: 0,
414
+ client_tick: 0,
415
+ axis_x: 0,
416
+ axis_z: 0,
417
+ yaw: 0,
418
+ layer: ROOM_LAYER,
419
+ subtick: 0
420
+ };
421
+ this.latestSequence = 0;
422
+ this.appliedSequence = 0;
423
+ this.durableSequence = 0;
424
+ }
425
+ get latest() {
426
+ return this.latestSequence;
427
+ }
428
+ get applied() {
429
+ return this.appliedSequence;
430
+ }
431
+ get durable() {
432
+ return this.durableSequence;
433
+ }
434
+ get pending() {
435
+ return this.latestSequence - this.appliedSequence;
436
+ }
437
+ rebase(applied) {
438
+ this.appliedSequence = applied, this.durableSequence > applied && (this.durableSequence = applied), (this.latestSequence < applied || this.latestSequence - this.durableSequence >= INPUT_LOG_CAPACITY) && (this.latestSequence = applied, this.durableSequence = applied);
439
+ }
440
+ reset(applied) {
441
+ this.latestSequence = applied, this.appliedSequence = applied, this.durableSequence = applied;
442
+ }
443
+ acknowledge(applied) {
444
+ return applied <= this.appliedSequence || applied > this.latestSequence ? false : (this.appliedSequence = applied, true);
445
+ }
446
+ persist(durable) {
447
+ durable > this.durableSequence && (this.durableSequence = Math.min(durable, this.latestSequence));
448
+ }
449
+ holds(sequence) {
450
+ return sequence > this.durableSequence && sequence <= this.latestSequence;
451
+ }
452
+ push(axisX, axisZ, yaw, buttons, clientTick, subtick) {
453
+ this.latestSequence - this.durableSequence >= INPUT_LOG_CAPACITY && (this.durableSequence += 1);
454
+ let sequence = this.latestSequence + 1, at = sequence % INPUT_LOG_CAPACITY;
455
+ return this.axisX[at] = axisX, this.axisZ[at] = axisZ, this.yaw[at] = yaw, this.buttons[at] = buttons, this.clientTick[at] = clientTick, this.subtick[at] = subtick, this.sentAt[at] = Number.NaN, this.latestSequence = sequence, sequence;
456
+ }
457
+ axisXOf(sequence) {
458
+ return this.axisX[sequence % INPUT_LOG_CAPACITY];
459
+ }
460
+ axisZOf(sequence) {
461
+ return this.axisZ[sequence % INPUT_LOG_CAPACITY];
462
+ }
463
+ buttonsOf(sequence) {
464
+ return this.buttons[sequence % INPUT_LOG_CAPACITY];
465
+ }
466
+ yawOf(sequence) {
467
+ return this.yaw[sequence % INPUT_LOG_CAPACITY];
468
+ }
469
+ sentAtOf(sequence) {
470
+ return this.holds(sequence) ? this.sentAt[sequence % INPUT_LOG_CAPACITY] : Number.NaN;
471
+ }
472
+ write(view, offset, nowMs) {
473
+ let first = Math.max(this.appliedSequence, this.durableSequence) + 1, last = Math.min(this.latestSequence, first + MAX_INPUTS_PER_PACKET - 1), at = offset, frame = this.frame;
474
+ for (let sequence = first; sequence <= last; sequence++) {
475
+ let slot = sequence % INPUT_LOG_CAPACITY;
476
+ frame.buttons = this.buttons[slot], frame.sequence = sequence % U16_RANGE, frame.client_tick = this.clientTick[slot] >>> 0, frame.axis_x = this.axisX[slot], frame.axis_z = this.axisZ[slot], frame.yaw = this.yaw[slot], frame.subtick = this.subtick[slot];
477
+ let written = encodeMoveInput(view, at, frame);
478
+ if (written < 0) break;
479
+ at += written, Number.isNaN(this.sentAt[slot]) && (this.sentAt[slot] = nowMs);
480
+ }
481
+ return at - offset;
482
+ }
483
+ };
484
+
485
+ // src/interactives/rooms/interpolation.ts
486
+ var Sampled = {
487
+ None: 0,
488
+ Interpolated: 1,
489
+ Extrapolated: 2
490
+ }, SAMPLES = ENTITY_CAPACITY * REMOTE_HISTORY;
491
+ function yawBetween(from, to, alpha) {
492
+ let delta = to - from;
493
+ return delta > HALF_YAW_UNITS ? delta -= YAW_UNITS_PER_TURN : delta < -HALF_YAW_UNITS && (delta += YAW_UNITS_PER_TURN), ((from + delta * alpha) % YAW_UNITS_PER_TURN + YAW_UNITS_PER_TURN) % YAW_UNITS_PER_TURN;
494
+ }
495
+ var RemoteTracks = class {
496
+ constructor() {
497
+ this.ticks = new Float64Array(SAMPLES);
498
+ this.xs = new Int32Array(SAMPLES);
499
+ this.ys = new Int32Array(SAMPLES);
500
+ this.zs = new Int32Array(SAMPLES);
501
+ this.yaws = new Uint16Array(SAMPLES);
502
+ this.animations = new Uint8Array(SAMPLES);
503
+ this.heads = new Int32Array(ENTITY_CAPACITY);
504
+ this.counts = new Int32Array(ENTITY_CAPACITY);
505
+ }
506
+ reset() {
507
+ this.counts.fill(0), this.heads.fill(0);
508
+ }
509
+ newestTick(slot) {
510
+ return this.counts[slot] === 0 ? -1 : this.ticks[slot * REMOTE_HISTORY + this.heads[slot]];
511
+ }
512
+ push(slot, tick, x, y, z, yaw, animation) {
513
+ if (this.counts[slot] > 0 && tick <= this.newestTick(slot)) return;
514
+ let head = this.counts[slot] === 0 ? 0 : (this.heads[slot] + 1) % REMOTE_HISTORY, at = slot * REMOTE_HISTORY + head;
515
+ this.ticks[at] = tick, this.xs[at] = x, this.ys[at] = y, this.zs[at] = z, this.yaws[at] = yaw, this.animations[at] = animation, this.heads[slot] = head, this.counts[slot] < REMOTE_HISTORY && (this.counts[slot] += 1);
516
+ }
517
+ sample(slot, renderTick, capTicks, out) {
518
+ let count = this.counts[slot];
519
+ if (count === 0) return Sampled.None;
520
+ let base = slot * REMOTE_HISTORY, newest = base + this.heads[slot];
521
+ if (renderTick >= this.ticks[newest]) {
522
+ if (count === 1)
523
+ return this.copy(newest, out), Sampled.Extrapolated;
524
+ let previous = base + (this.heads[slot] + REMOTE_HISTORY - 1) % REMOTE_HISTORY, span = this.ticks[newest] - this.ticks[previous], ahead = Math.min(renderTick - this.ticks[newest], capTicks);
525
+ return this.blend(previous, newest, span > 0 ? 1 + ahead / span : 1, out), Sampled.Extrapolated;
526
+ }
527
+ let later = newest;
528
+ for (let back = 1; back < count; back++) {
529
+ let earlier = base + (this.heads[slot] + REMOTE_HISTORY - back) % REMOTE_HISTORY;
530
+ if (this.ticks[earlier] <= renderTick) {
531
+ let span = this.ticks[later] - this.ticks[earlier];
532
+ return this.blend(earlier, later, span > 0 ? (renderTick - this.ticks[earlier]) / span : 0, out), Sampled.Interpolated;
533
+ }
534
+ later = earlier;
535
+ }
536
+ return this.copy(later, out), Sampled.Interpolated;
537
+ }
538
+ copy(at, out) {
539
+ out.x = this.xs[at], out.y = this.ys[at], out.z = this.zs[at], out.yaw = this.yaws[at], out.animation = this.animations[at];
540
+ }
541
+ blend(from, to, alpha, out) {
542
+ out.x = this.xs[from] + (this.xs[to] - this.xs[from]) * alpha, out.y = this.ys[from] + (this.ys[to] - this.ys[from]) * alpha, out.z = this.zs[from] + (this.zs[to] - this.zs[from]) * alpha, out.yaw = yawBetween(this.yaws[from], this.yaws[to], alpha), out.animation = this.animations[to];
543
+ }
544
+ };
545
+
546
+ // src/interactives/rooms/pacing.ts
547
+ function paceOf(code) {
548
+ return code === Pace.Faster ? Pace.Faster : code === Pace.Slower ? Pace.Slower : Pace.Steady;
549
+ }
550
+ var ClientTicker = class {
551
+ constructor() {
552
+ this.nominalMs = 0;
553
+ this.intervalMs = 0;
554
+ this.nextAt = 0;
555
+ this.lastAt = 0;
556
+ this.current = Pace.Steady;
557
+ this.tick = 0;
558
+ this.changes = 0;
559
+ }
560
+ start(simulationHz, firstTick, nowMs) {
561
+ this.nominalMs = MS_PER_SECOND / simulationHz, this.intervalMs = this.nominalMs, this.current = Pace.Steady, this.tick = firstTick, this.lastAt = nowMs, this.nextAt = nowMs + this.intervalMs;
562
+ }
563
+ get pace() {
564
+ return this.current;
565
+ }
566
+ get interval() {
567
+ return this.intervalMs;
568
+ }
569
+ steer(pace) {
570
+ pace !== this.current && (this.current = pace, this.changes += 1, this.intervalMs = pace === Pace.Faster ? this.nominalMs * PACE_FASTER_SCALE : pace === Pace.Slower ? this.nominalMs * PACE_SLOWER_SCALE : this.nominalMs);
571
+ }
572
+ due(nowMs) {
573
+ if (nowMs < this.nextAt) return 0;
574
+ let count = 0;
575
+ for (; nowMs >= this.nextAt && count < MAX_CATCH_UP_TICKS; )
576
+ this.lastAt = this.nextAt, this.nextAt += this.intervalMs, count += 1;
577
+ return nowMs >= this.nextAt && (this.lastAt = nowMs, this.nextAt = nowMs + this.intervalMs), count;
578
+ }
579
+ subtick(sampledAtMs) {
580
+ let fraction = (sampledAtMs - this.lastAt) / this.intervalMs, units = Math.floor(fraction * SUBTICKS_PER_TICK);
581
+ return units < 0 ? 0 : units > MAX_SUBTICK ? MAX_SUBTICK : units;
582
+ }
583
+ };
584
+
585
+ // src/interactives/rooms/prediction.ts
586
+ var Predictor = class {
587
+ constructor(motion) {
588
+ this.xs = new Int32Array(INPUT_LOG_CAPACITY);
589
+ this.zs = new Int32Array(INPUT_LOG_CAPACITY);
590
+ this.predicted = new Float64Array(INPUT_LOG_CAPACITY).fill(-1);
591
+ this.settled = false;
592
+ this.offsetX = 0;
593
+ this.offsetZ = 0;
594
+ this.stats = { corrections: 0, maxUnits: 0, totalUnits: 0 };
595
+ this.motion = motion;
596
+ }
597
+ get x() {
598
+ return this.motion.x;
599
+ }
600
+ get z() {
601
+ return this.motion.z;
602
+ }
603
+ get renderX() {
604
+ return this.motion.x + this.offsetX;
605
+ }
606
+ get renderZ() {
607
+ return this.motion.z + this.offsetZ;
608
+ }
609
+ begin(slot, applied) {
610
+ this.motion.spawn(slot), this.predicted.fill(-1), this.remember(applied), this.settled = false, this.offsetX = 0, this.offsetZ = 0;
611
+ }
612
+ predict(sequence, log) {
613
+ this.apply(sequence, log), this.remember(sequence);
614
+ }
615
+ reconcile(applied, x, y, z, log) {
616
+ let at = applied % INPUT_LOG_CAPACITY;
617
+ if (this.predicted[at] !== applied) return false;
618
+ let errorX = x - this.xs[at], errorZ = z - this.zs[at], tolerance = this.motion.toleranceUnits;
619
+ if (Math.abs(errorX) <= tolerance && Math.abs(errorZ) <= tolerance)
620
+ return this.settled = true, true;
621
+ let motion = this.motion, beforeX = motion.x + this.offsetX, beforeZ = motion.z + this.offsetZ;
622
+ motion.place(x, y, z), this.remember(applied);
623
+ for (let sequence = applied + 1; sequence <= log.latest; sequence++) this.predict(sequence, log);
624
+ if (this.settled) {
625
+ let units = Math.hypot(errorX, errorZ);
626
+ this.stats.corrections += 1, this.stats.totalUnits += units, units > this.stats.maxUnits && (this.stats.maxUnits = units), this.offsetX = beforeX - motion.x, this.offsetZ = beforeZ - motion.z;
627
+ }
628
+ return this.settled = true, true;
629
+ }
630
+ decay(elapsedMs) {
631
+ if (this.offsetX === 0 && this.offsetZ === 0) return;
632
+ let keep = Math.exp(-elapsedMs / SMOOTHING_TIME_CONSTANT_MS);
633
+ this.offsetX *= keep, this.offsetZ *= keep, Math.abs(this.offsetX) < SETTLED_OFFSET_UNITS && Math.abs(this.offsetZ) < SETTLED_OFFSET_UNITS && (this.offsetX = 0, this.offsetZ = 0);
634
+ }
635
+ apply(sequence, log) {
636
+ let motion = this.motion;
637
+ motion.steer(log.axisXOf(sequence), log.axisZOf(sequence), log.buttonsOf(sequence)), motion.step();
638
+ }
639
+ remember(sequence) {
640
+ let at = sequence % INPUT_LOG_CAPACITY;
641
+ this.xs[at] = this.motion.x, this.zs[at] = this.motion.z, this.predicted[at] = sequence;
642
+ }
643
+ };
644
+
645
+ // src/interactives/rooms/send-governor.ts
646
+ var SendGovernor = class {
647
+ constructor() {
648
+ this.stride = 1;
649
+ this.shed = 0;
650
+ this.skipped = 0;
651
+ this.calmSince = 0;
652
+ }
653
+ get pressured() {
654
+ return this.stride > 1;
655
+ }
656
+ pressure(nowMs) {
657
+ this.stride = Math.min(this.stride * 2, MAX_SEND_STRIDE), this.calmSince = nowMs;
658
+ }
659
+ recover(nowMs) {
660
+ this.stride === 1 || nowMs - this.calmSince < SEND_RECOVER_MS || (this.stride >>= 1, this.calmSince = nowMs, this.stride === 1 && (this.skipped = 0));
661
+ }
662
+ admit() {
663
+ return this.stride === 1 ? true : (this.skipped += 1, this.skipped < this.stride ? (this.shed += 1, false) : (this.skipped = 0, true));
664
+ }
665
+ force() {
666
+ return this.skipped = 0, true;
667
+ }
668
+ reset() {
669
+ this.stride = 1, this.skipped = 0, this.calmSince = 0;
670
+ }
671
+ };
672
+
673
+ // src/interactives/rooms/sized-views.ts
674
+ var SizedViews = class {
675
+ constructor(buffer) {
676
+ this.buffer = buffer, this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength), this.views = Array.from({ length: buffer.length + 1 });
677
+ }
678
+ of(length) {
679
+ let cached = this.views[length];
680
+ if (cached) return cached;
681
+ let view = this.buffer.subarray(0, length);
682
+ return this.views[length] = view, view;
683
+ }
684
+ };
685
+
686
+ // src/interactives/rooms/snapshots.ts
687
+ var Decoded = {
688
+ Stored: 0,
689
+ Duplicate: 1,
690
+ MissingBaseline: 2,
691
+ Malformed: 3
692
+ }, DELTA_FULL = FRAME_FLAGS.presence_delta.entry_full, DELTA_ANIMATION = FRAME_FLAGS.presence_delta.entry_animation, DELTA_FLAGS = FRAME_FLAGS.presence_delta.entry_flags, NO_TICK = -1, NO_ROW = -1, CELLS = SNAPSHOT_RING * ENTITY_CAPACITY;
693
+ function newerTick(candidate, than) {
694
+ let ahead = (candidate - than + U32_RANGE) % U32_RANGE;
695
+ return ahead !== 0 && ahead < U32_RANGE / 2;
696
+ }
697
+ var SnapshotStore = class {
698
+ constructor() {
699
+ this.present = new Uint8Array(CELLS);
700
+ this.x = new Uint16Array(CELLS);
701
+ this.y = new Int16Array(CELLS);
702
+ this.z = new Uint16Array(CELLS);
703
+ this.yaw = new Uint16Array(CELLS);
704
+ this.animation = new Uint8Array(CELLS);
705
+ this.flags = new Uint8Array(CELLS);
706
+ this.ticks = new Float64Array(SNAPSHOT_RING).fill((-1));
707
+ this.seen = new Float64Array(SEEN_TICKS).fill((-1));
708
+ this.header = {
709
+ flags: 0,
710
+ server_tick: 0,
711
+ cell_index: 0,
712
+ acked_input: 0,
713
+ layer: 0,
714
+ baseline_age: 0,
715
+ count: 0,
716
+ entries_offset: 0,
717
+ end: 0
718
+ };
719
+ this.entry = { slot: 0, x: 0, y: 0, z: 0, yaw: 0, animation: 0, flags: 0 };
720
+ this.delta = { slot: 0, mask: 0, x: 0, y: 0, z: 0, yaw: 0, animation: 0, flags: 0 };
721
+ this.next = 0;
722
+ this.latestRow = (-1);
723
+ this.lastKeyframe = false;
724
+ }
725
+ reset() {
726
+ this.ticks.fill((-1)), this.seen.fill((-1)), this.present.fill(0), this.next = 0, this.latestRow = (-1);
727
+ }
728
+ get hasLatest() {
729
+ return this.latestRow !== (-1);
730
+ }
731
+ get latestTick() {
732
+ return this.latestRow === (-1) ? (-1) : this.ticks[this.latestRow];
733
+ }
734
+ get latest() {
735
+ return this.latestRow;
736
+ }
737
+ tickOf(row) {
738
+ return this.ticks[row];
739
+ }
740
+ row(tick) {
741
+ for (let row = 0; row < SNAPSHOT_RING; row++) if (this.ticks[row] === tick) return row;
742
+ return (-1);
743
+ }
744
+ rowByShortTick(short) {
745
+ let found = (-1);
746
+ for (let row = 0; row < SNAPSHOT_RING; row++) {
747
+ let tick = this.ticks[row];
748
+ tick === (-1) || (tick & SHORT_TICK_MASK) !== short || (found === (-1) || newerTick(tick, this.ticks[found])) && (found = row);
749
+ }
750
+ return found;
751
+ }
752
+ received(tick) {
753
+ return this.seen[tick % SEEN_TICKS] === tick;
754
+ }
755
+ decode(view, offset, end) {
756
+ let header = this.header, compact = peekFrameCode(view, offset, end) === FrameCode.presence_delta;
757
+ if ((compact ? decodePresenceDelta(view, offset, end, header) : decodePresenceTick(view, offset, end, header)) < 0) return Decoded.Malformed;
758
+ let tick = header.server_tick;
759
+ if (this.row(tick) !== (-1)) return Decoded.Duplicate;
760
+ let keyframe = (header.flags & KEYFRAME_FLAG) !== 0, row = this.next, start = row * ENTITY_CAPACITY;
761
+ if (keyframe)
762
+ this.present.fill(0, start, start + ENTITY_CAPACITY);
763
+ else {
764
+ let base = this.row((tick - header.baseline_age + U32_RANGE) % U32_RANGE);
765
+ if (base === (-1)) return Decoded.MissingBaseline;
766
+ base !== row && this.copyRow(base * ENTITY_CAPACITY, start);
767
+ }
768
+ return compact ? this.applyDelta(view, start) : this.applyFull(view, start), this.ticks[row] = tick, this.seen[tick % SEEN_TICKS] = tick, this.next = (row + 1) % SNAPSHOT_RING, this.lastKeyframe = keyframe, this.latestRow = this.newestRow(), Decoded.Stored;
769
+ }
770
+ applyFull(view, start) {
771
+ let header = this.header, entry = this.entry;
772
+ for (let index = 0; index < header.count; index++) {
773
+ if (readPresenceEntry(view, header, index, entry), entry.slot >= ENTITY_CAPACITY) continue;
774
+ let cell = start + entry.slot;
775
+ this.present[cell] = 1, this.x[cell] = entry.x, this.y[cell] = entry.y, this.z[cell] = entry.z, this.yaw[cell] = entry.yaw, this.animation[cell] = entry.animation, this.flags[cell] = entry.flags;
776
+ }
777
+ }
778
+ applyDelta(view, start) {
779
+ let header = this.header, entry = this.delta, cursor = header.entries_offset;
780
+ for (let index = 0; index < header.count; index++) {
781
+ if (cursor = readPresenceDeltaEntry(view, cursor, header.end, entry), cursor < 0) return;
782
+ if (entry.slot >= ENTITY_CAPACITY) continue;
783
+ let cell = start + entry.slot;
784
+ if (this.present[cell] = 1, (entry.mask & DELTA_FULL) !== 0) {
785
+ this.x[cell] = entry.x, this.y[cell] = entry.y, this.z[cell] = entry.z, this.yaw[cell] = entry.yaw, this.animation[cell] = entry.animation, this.flags[cell] = entry.flags;
786
+ continue;
787
+ }
788
+ this.x[cell] += entry.x, this.y[cell] += entry.y, this.z[cell] += entry.z, this.yaw[cell] += entry.yaw, (entry.mask & DELTA_ANIMATION) !== 0 && (this.animation[cell] = entry.animation), (entry.mask & DELTA_FLAGS) !== 0 && (this.flags[cell] = entry.flags);
789
+ }
790
+ }
791
+ newestRow() {
792
+ let newest = (-1);
793
+ for (let row = 0; row < SNAPSHOT_RING; row++)
794
+ this.ticks[row] !== (-1) && (newest === (-1) || newerTick(this.ticks[row], this.ticks[newest])) && (newest = row);
795
+ return newest;
796
+ }
797
+ get decodedRow() {
798
+ return (this.next + SNAPSHOT_RING - 1) % SNAPSHOT_RING;
799
+ }
800
+ copyRow(from, to) {
801
+ let until = from + ENTITY_CAPACITY;
802
+ this.present.copyWithin(to, from, until), this.x.copyWithin(to, from, until), this.y.copyWithin(to, from, until), this.z.copyWithin(to, from, until), this.yaw.copyWithin(to, from, until), this.animation.copyWithin(to, from, until), this.flags.copyWithin(to, from, until);
803
+ }
804
+ };
805
+
806
+ // src/interactives/rooms/client.ts
807
+ var RoomPhase = {
808
+ Idle: 0,
809
+ Ticketing: 1,
810
+ Connecting: 2,
811
+ Joined: 3,
812
+ Waiting: 4,
813
+ Refused: 5,
814
+ Closed: 6
815
+ }, GAME_CHANNEL_SLOTS = FRAME_LIMITS.game_channel_slots, GAME_CHANNEL_RELIABLE_BASE = FRAME_LIMITS.game_channel_reliable_base, NO_TICK2 = -1, RATE_KEY_SCALE = 65536, ROOM_INPUT_COMMAND = FRAME_FLAGS.room_input.command, ROOM_INPUT_HEADER = FRAME_LAYOUT.room_input.header_bytes, CHANNEL_HEADER = FRAME_LAYOUT.channel.header_bytes, LITTLE_ENDIAN2 = true, RETRYABLE = [JoinStatus.Full, JoinStatus.Overloaded, JoinStatus.Unavailable], RoomClient = class {
816
+ constructor(options) {
817
+ this.queue = new InboundQueue();
818
+ this.outbound = Array.from({ length: OUTBOUND_POOL_SLOTS }, () => new SizedViews(new Uint8Array(PACKET_BYTES)));
819
+ this.reply = blankReply();
820
+ this.ack = { slot: 0, sequence: 0, received_mask: 0 };
821
+ this.streamAcks = [];
822
+ this.clock = new ClockSync();
823
+ this.ticker = new ClientTicker();
824
+ this.governor = new SendGovernor();
825
+ this.seenSendFailures = 0;
826
+ this.leadBoost = 0;
827
+ this.log = new InputLog();
828
+ this.store = new SnapshotStore();
829
+ this.tracks = new RemoteTracks();
830
+ this.units = { x: 0, y: 0, z: 0, yaw: 0, animation: 0 };
831
+ this.appliedShort = new Int32Array(APPLIED_RING).fill((-1));
832
+ this.appliedSequence = new Float64Array(APPLIED_RING);
833
+ this.remoteSlots = new Uint16Array(ENTITY_CAPACITY);
834
+ this.roomInput = { flags: ROOM_INPUT_COMMAND, action: 0, sequence: 0, client_tick: 0, sender: 0 };
835
+ this.channelHeader = { flags: 0, slot: 0, sequence: 0, sender: 0 };
836
+ this.channelMessage = { flags: 0, slot: 0, sequence: 0, sender: 0, payload_offset: 0, payload_length: 0 };
837
+ this.channelSequence = 0;
838
+ this.statistics = {
839
+ slot: WATCHER_SLOT,
840
+ transport: null,
841
+ corrections: 0,
842
+ maxCorrectionM: 0,
843
+ meanCorrectionM: 0,
844
+ inputsSent: 0,
845
+ snapshots: 0,
846
+ deltas: 0,
847
+ keyframes: 0,
848
+ missingBaselines: 0,
849
+ rttMs: 0,
850
+ interpolationDelayMs: 0,
851
+ extrapolatingFrames: 0,
852
+ paceChanges: 0,
853
+ reconnects: 0,
854
+ dropped: 0,
855
+ sendFailures: 0,
856
+ sendStride: 1,
857
+ statesShed: 0
858
+ };
859
+ this.predictor = null;
860
+ this.predictorRates = 0;
861
+ this.link = null;
862
+ this.stateValue = RoomPhase.Idle;
863
+ this.pendingTicket = null;
864
+ this.ticketFailed = false;
865
+ this.resumeToken = null;
866
+ this.joinVersion = JOIN_VERSION_DELTA;
867
+ this.request = null;
868
+ this.admittedAt = 0;
869
+ this.dialStartedAt = 0;
870
+ this.retryAt = 0;
871
+ this.lastUpdate = 0;
872
+ this.outboundNext = 0;
873
+ this.appliedNext = 0;
874
+ this.remoteCountValue = 0;
875
+ this.joins = 0;
876
+ this.slotValue = WATCHER_SLOT;
877
+ this.watcher = true;
878
+ this.started = false;
879
+ this.freshSnapshot = false;
880
+ this.lastReconciled = (-1);
881
+ this.extrapolating = false;
882
+ this.ownTick = (-1);
883
+ this.ownX = 0;
884
+ this.ownY = 0;
885
+ this.ownZ = 0;
886
+ this.ownVelocityX = 0;
887
+ this.ownVelocityZ = 0;
888
+ this.inputAxisX = 0;
889
+ this.inputAxisZ = 0;
890
+ this.inputYaw = 0;
891
+ this.inputButtons = 0;
892
+ this.inputSubtick = 0;
893
+ this.commandSequence = 0;
894
+ this.cameraSequence = 0;
895
+ this.cameraX = 0;
896
+ this.cameraZ = 0;
897
+ this.cameraRadius = 0;
898
+ this.cameraDirty = false;
899
+ this.cameraSentAt = Number.NEGATIVE_INFINITY;
900
+ this.unackedSnapshots = 0;
901
+ this.ticketArrived = (ticket) => {
902
+ this.pendingTicket = ticket;
903
+ };
904
+ this.ticketRefused = () => {
905
+ this.ticketFailed = true;
906
+ };
907
+ this.tickets = options.tickets, this.spectatorAckEvery = Math.max(1, Math.floor(options.spectatorAckEvery ?? SPECTATOR_ACK_EVERY)), this.physicsHz = options.physicsHz ?? 0, this.channelSink = options.channels ?? null, this.motionFactory = options.motion ?? locomotionMotion, this.connector = new Connector(
908
+ options.primary ?? null,
909
+ options.fallback ?? null,
910
+ options.memory ?? new StorageNetworkMemory(),
911
+ options.network ?? currentNetwork
912
+ );
913
+ }
914
+ get state() {
915
+ return this.stateValue;
916
+ }
917
+ get slot() {
918
+ return this.slotValue;
919
+ }
920
+ ackStream(slot, sequence) {
921
+ this.streamAcks.push({ slot, sequence });
922
+ }
923
+ get watching() {
924
+ return this.watcher;
925
+ }
926
+ get extrapolatingLocal() {
927
+ return this.extrapolating;
928
+ }
929
+ get serverTick() {
930
+ return this.store.latestTick;
931
+ }
932
+ get remoteCount() {
933
+ return this.remoteCountValue;
934
+ }
935
+ remoteSlot(index) {
936
+ return this.remoteSlots[index];
937
+ }
938
+ get stats() {
939
+ let stats = this.statistics, corrections = this.predictor?.stats;
940
+ return stats.slot = this.slotValue, stats.transport = this.link?.transport ?? null, stats.corrections = corrections?.corrections ?? 0, stats.maxCorrectionM = dequantiseCellOffset(corrections?.maxUnits ?? 0), stats.meanCorrectionM = corrections && corrections.corrections > 0 ? dequantiseCellOffset(corrections.totalUnits / corrections.corrections) : 0, stats.rttMs = this.clock.rttMs, stats.interpolationDelayMs = this.clock.interpolationDelayMs, stats.paceChanges = this.ticker.changes, stats.dropped = this.queue.dropped, stats.sendFailures = this.queue.sendFailures, stats.sendStride = this.governor.stride, stats.statesShed = this.governor.shed, stats;
941
+ }
942
+ start(nowMs) {
943
+ this.stateValue === RoomPhase.Idle && (this.lastUpdate = nowMs, this.fetchTicket());
944
+ }
945
+ close() {
946
+ this.connector.cancel(), this.link?.close(), this.link = null, this.stateValue = RoomPhase.Closed;
947
+ }
948
+ setInput(axisX, axisZ, yawRadians, buttons, nowMs) {
949
+ this.inputAxisX = quantiseAxis(axisX), this.inputAxisZ = quantiseAxis(axisZ), this.inputYaw = quantiseYaw(yawRadians), this.inputButtons = buttons, this.inputSubtick = this.ticker.subtick(nowMs);
950
+ }
951
+ setCamera(xMetres, zMetres, radiusMetres) {
952
+ this.cameraX = quantiseCellOffset(xMetres), this.cameraZ = quantiseCellOffset(zMetres), this.cameraRadius = Math.max(0, Math.min(Math.round(radiusMetres), SHORT_TICK_MASK)), this.cameraSequence += 1, this.cameraDirty = true;
953
+ }
954
+ sendCommand(action, payload, length) {
955
+ let link = this.link;
956
+ if (!link || this.watcher || this.stateValue !== RoomPhase.Joined) return -1;
957
+ let packet = this.packet(), input = this.roomInput;
958
+ input.flags = ROOM_INPUT_COMMAND, input.action = action, input.sequence = (this.commandSequence + 1) % U32_RANGE, input.client_tick = this.ticker.tick >>> 0;
959
+ let total = writeRoomInputHeader(packet.view, 0, input, length);
960
+ if (total < 0) return total;
961
+ let buffer = packet.buffer;
962
+ for (let index = 0; index < length; index++) buffer[ROOM_INPUT_HEADER + index] = payload[index];
963
+ return this.commandSequence = input.sequence, link.send(Lane.Reliable, packet.of(total)), input.sequence;
964
+ }
965
+ sendChannel(slot, payload, length) {
966
+ let link = this.link;
967
+ if (!link || this.watcher || this.stateValue !== RoomPhase.Joined || slot < 0 || slot >= GAME_CHANNEL_SLOTS) return -1;
968
+ let packet = this.packet(), header = this.channelHeader;
969
+ header.slot = slot, header.sequence = (this.channelSequence + 1) % U32_RANGE;
970
+ let total = writeChannelHeader(packet.view, 0, header, length);
971
+ if (total < 0) return total;
972
+ let buffer = packet.buffer;
973
+ for (let index = 0; index < length; index++) buffer[CHANNEL_HEADER + index] = payload[index];
974
+ return this.channelSequence = header.sequence, link.send(slot < GAME_CHANNEL_RELIABLE_BASE ? Lane.Datagram : Lane.Reliable, packet.of(total)), header.sequence;
975
+ }
976
+ update(nowMs) {
977
+ let elapsed = nowMs - this.lastUpdate;
978
+ switch (this.lastUpdate = nowMs, this.stateValue) {
979
+ case RoomPhase.Ticketing:
980
+ this.dial(nowMs);
981
+ break;
982
+ case RoomPhase.Connecting:
983
+ this.connecting(nowMs);
984
+ break;
985
+ case RoomPhase.Waiting:
986
+ nowMs >= this.retryAt && this.fetchTicket();
987
+ break;
988
+ }
989
+ if (this.stateValue === RoomPhase.Joined) {
990
+ if (this.drain(nowMs), this.queue.lost) {
991
+ this.reconnect(nowMs);
992
+ return;
993
+ }
994
+ this.govern(nowMs), this.play(nowMs), this.predictor?.decay(elapsed), this.watchLatency();
995
+ }
996
+ }
997
+ localPose(out, nowMs) {
998
+ let predictor = this.predictor;
999
+ if (!predictor || !this.started) return false;
1000
+ let x = predictor.renderX, z = predictor.renderZ;
1001
+ if (this.extrapolating && this.ownTick !== (-1)) {
1002
+ let projected = this.clock.serverTick(nowMs) + this.clock.leadTicks(), ahead = Math.max(0, Math.min(projected - this.ownTick, this.capTicks()));
1003
+ x = this.ownX + this.ownVelocityX * ahead, z = this.ownZ + this.ownVelocityZ * ahead;
1004
+ }
1005
+ return out.x = dequantiseCellOffset(x), out.y = dequantiseHeight(this.ownY), out.z = dequantiseCellOffset(z), out.yaw = dequantiseYaw(this.inputYaw), out.animation = 0, true;
1006
+ }
1007
+ presence(slot, out) {
1008
+ let store = this.store, row = store.latest;
1009
+ if (slot < 0 || slot >= ENTITY_CAPACITY || !store.hasLatest) return false;
1010
+ let cell = row * ENTITY_CAPACITY + slot;
1011
+ return store.present[cell] === 0 ? false : (out.tick = store.tickOf(row), out.x = store.x[cell], out.y = store.y[cell], out.z = store.z[cell], out.yaw = store.yaw[cell], out.animation = store.animation[cell], out.flags = store.flags[cell], true);
1012
+ }
1013
+ remotePose(slot, out, nowMs) {
1014
+ if (slot >= ENTITY_CAPACITY) return false;
1015
+ let units = this.units;
1016
+ return this.tracks.sample(slot, this.clock.renderTick(nowMs), this.capTicks(), units) === Sampled.None ? false : (out.x = dequantiseCellOffset(units.x), out.y = dequantiseHeight(units.y), out.z = dequantiseCellOffset(units.z), out.yaw = dequantiseYaw(units.yaw), out.animation = units.animation, true);
1017
+ }
1018
+ capTicks() {
1019
+ return EXTRAPOLATION_CAP_MS / this.clock.tickIntervalMs;
1020
+ }
1021
+ fetchTicket() {
1022
+ this.stateValue = RoomPhase.Ticketing, this.pendingTicket = null, this.ticketFailed = false, this.tickets().then(this.ticketArrived, this.ticketRefused);
1023
+ }
1024
+ dial(nowMs) {
1025
+ if (this.ticketFailed) {
1026
+ this.waitAndRetry(nowMs);
1027
+ return;
1028
+ }
1029
+ let ticket = this.pendingTicket;
1030
+ ticket && (this.pendingTicket = null, this.begin(ticketRequest(ticket, this.joinVersion), nowMs));
1031
+ }
1032
+ begin(request, nowMs) {
1033
+ this.request = request, this.queue.clear(), this.dialStartedAt = nowMs, this.stateValue = RoomPhase.Connecting, this.connector.begin(request, this.queue, nowMs);
1034
+ }
1035
+ connecting(nowMs) {
1036
+ let state = this.connector.poll(nowMs);
1037
+ if (state === Connecting.Failed) {
1038
+ this.waitAndRetry(nowMs);
1039
+ return;
1040
+ }
1041
+ if (state !== Connecting.Won) return;
1042
+ let dialed = this.connector.release();
1043
+ if (!dialed || !decodeJoinReply(dialed.reply, this.reply)) {
1044
+ dialed?.link.close(), this.waitAndRetry(nowMs);
1045
+ return;
1046
+ }
1047
+ let status = this.reply.status;
1048
+ if (status === JoinStatus.Admitted) {
1049
+ this.joined(dialed.link, nowMs);
1050
+ return;
1051
+ }
1052
+ dialed.link.close();
1053
+ let request = this.request;
1054
+ if (status === JoinStatus.Malformed && request !== null && withoutDeltaPresence(request)) {
1055
+ this.joinVersion = JOIN_VERSION, this.begin(request, nowMs);
1056
+ return;
1057
+ }
1058
+ status === JoinStatus.UnknownResume || status === JoinStatus.Expired ? (this.resumeToken = null, this.fetchTicket()) : RETRYABLE.indexOf(status) >= 0 ? this.waitAndRetry(nowMs) : this.stateValue = RoomPhase.Refused;
1059
+ }
1060
+ waitAndRetry(nowMs) {
1061
+ this.stateValue = RoomPhase.Waiting, this.retryAt = nowMs + RETRY_AFTER_MS;
1062
+ }
1063
+ reconnect(nowMs) {
1064
+ this.link?.close(), this.link = null;
1065
+ let token = this.resumeToken;
1066
+ if (token && nowMs - this.admittedAt < RESUME_GRACE_MS) {
1067
+ this.resumeToken = null, this.begin(resumeRequest(token, this.joinVersion), nowMs);
1068
+ return;
1069
+ }
1070
+ this.resumeToken = null, this.fetchTicket();
1071
+ }
1072
+ joined(link, nowMs) {
1073
+ let reply = this.reply;
1074
+ this.link = link, this.stateValue = RoomPhase.Joined, this.admittedAt = nowMs, this.resumeToken = reply.resume.slice(), this.slotValue = reply.slot, this.watcher = reply.slot === WATCHER_SLOT, this.joins > 0 && (this.statistics.reconnects += 1), this.joins += 1, this.clock.configure(reply.simulationHz, reply.sendHz, nowMs - this.dialStartedAt);
1075
+ let physicsHz = this.physicsHz > 0 ? this.physicsHz : reply.simulationHz * DEFAULT_SUBSTEPS, rates = reply.simulationHz * (65536) + physicsHz;
1076
+ (!this.predictor || this.predictorRates !== rates) && (this.predictor = new Predictor(this.motionFactory(reply.simulationHz, physicsHz)), this.predictorRates = rates), this.store.reset(), this.tracks.reset(), this.appliedShort.fill((-1)), this.remoteCountValue = 0, this.lastReconciled = (-1), this.ownTick = (-1), this.started = false, this.freshSnapshot = false, this.extrapolating = false, this.cameraDirty = this.cameraSequence > 0, this.governor.reset(), this.seenSendFailures = this.queue.sendFailures, this.leadBoost = 0;
1077
+ }
1078
+ govern(nowMs) {
1079
+ let failures = this.queue.sendFailures;
1080
+ if (failures === this.seenSendFailures) {
1081
+ this.governor.recover(nowMs);
1082
+ return;
1083
+ }
1084
+ this.seenSendFailures = failures, this.governor.pressure(nowMs);
1085
+ }
1086
+ drain(nowMs) {
1087
+ let queue = this.queue;
1088
+ for (; queue.next(); ) {
1089
+ let view = queue.view, end = queue.length, offset = 0;
1090
+ for (; offset < end; ) {
1091
+ let length = frameLength(view, offset, end);
1092
+ if (length <= 0) break;
1093
+ let code = peekFrameCode(view, offset, end);
1094
+ code === FrameCode.presence_tick || code === FrameCode.presence_delta ? this.snapshot(view, offset, offset + length, nowMs) : code === FrameCode.ack && decodeAck(view, offset, offset + length, this.ack) > 0 ? this.acknowledged(nowMs) : code === FrameCode.channel && this.channel(view, offset, offset + length), offset += length;
1095
+ }
1096
+ }
1097
+ }
1098
+ channel(view, offset, end) {
1099
+ let sink = this.channelSink;
1100
+ if (sink === null) return;
1101
+ let message = this.channelMessage;
1102
+ decodeChannelFrame(view, offset, end, message) < 0 || sink.deliver(message.slot, message.sender, view, message.payload_offset, message.payload_length);
1103
+ }
1104
+ snapshot(view, offset, end, nowMs) {
1105
+ let store = this.store, decoded = store.decode(view, offset, end);
1106
+ if (decoded === Decoded.MissingBaseline) {
1107
+ this.statistics.missingBaselines += 1;
1108
+ return;
1109
+ }
1110
+ if (decoded !== Decoded.Stored) return;
1111
+ let stats = this.statistics;
1112
+ stats.snapshots += 1, store.lastKeyframe ? stats.keyframes += 1 : stats.deltas += 1;
1113
+ let row = store.decodedRow, tick = store.tickOf(row);
1114
+ this.clock.snapshot(tick, nowMs), this.freshSnapshot = true;
1115
+ let fresh2 = row === store.latest, start = row * ENTITY_CAPACITY;
1116
+ fresh2 && (this.remoteCountValue = 0);
1117
+ for (let slot = 0; slot < ENTITY_CAPACITY; slot++) {
1118
+ let cell = start + slot;
1119
+ if (store.present[cell] !== 0) {
1120
+ if (slot === this.slotValue) {
1121
+ this.observeOwn(tick, store.x[cell], store.y[cell], store.z[cell]);
1122
+ continue;
1123
+ }
1124
+ this.tracks.push(slot, tick, store.x[cell], store.y[cell], store.z[cell], store.yaw[cell], store.animation[cell]), fresh2 && (this.remoteSlots[this.remoteCountValue++] = slot);
1125
+ }
1126
+ }
1127
+ let short = tick & SHORT_TICK_MASK;
1128
+ for (let index = 0; index < APPLIED_RING; index++)
1129
+ this.appliedShort[index] === short && this.reconcile(this.appliedSequence[index], row);
1130
+ }
1131
+ observeOwn(tick, x, y, z) {
1132
+ if (!(this.ownTick !== (-1) && !newerTick(tick, this.ownTick))) {
1133
+ if (this.ownTick !== (-1)) {
1134
+ let span = tick - this.ownTick;
1135
+ this.ownVelocityX = (x - this.ownX) / span, this.ownVelocityZ = (z - this.ownZ) / span;
1136
+ }
1137
+ this.ownTick = tick, this.ownX = x, this.ownY = y, this.ownZ = z;
1138
+ }
1139
+ }
1140
+ acknowledged(nowMs) {
1141
+ let ack = this.ack;
1142
+ switch (ack.slot) {
1143
+ case MOVE_APPLIED_SLOT:
1144
+ this.applied(ack.sequence, ack.received_mask, nowMs);
1145
+ return;
1146
+ case MOVE_DURABLE_SLOT:
1147
+ this.log.persist(ack.sequence);
1148
+ return;
1149
+ case COMMAND_DURABLE_SLOT:
1150
+ ack.sequence > this.commandSequence && (this.commandSequence = ack.sequence);
1151
+ return;
1152
+ default:
1153
+ return;
1154
+ }
1155
+ }
1156
+ applied(applied, mask, nowMs) {
1157
+ let buffered = mask & TIMING_BUFFERED_MASK, pace = paceOf(mask >>> TIMING_PACE_SHIFT & TIMING_BUFFERED_MASK), short = mask >>> TIMING_TICK_SHIFT;
1158
+ if (this.watcher) return;
1159
+ this.started ? this.log.acknowledge(applied) && this.clock.roundTrip(nowMs - this.log.sentAtOf(applied) - buffered * this.clock.tickIntervalMs) : this.beginSession(applied, nowMs), this.ticker.steer(pace), this.appliedShort[this.appliedNext] = short, this.appliedSequence[this.appliedNext] = applied, this.appliedNext = (this.appliedNext + 1) % APPLIED_RING;
1160
+ let row = this.store.rowByShortTick(short);
1161
+ row >= 0 && this.reconcile(applied, row);
1162
+ }
1163
+ beginSession(applied, nowMs) {
1164
+ let log = this.log;
1165
+ log.latest > applied && log.holds(applied + 1) ? log.rebase(applied) : (log.reset(applied), this.predictor?.begin(this.slotValue, applied));
1166
+ let lead = Math.ceil(this.clock.leadTicks()) + INPUT_BUFFER_TARGET;
1167
+ this.ticker.start(this.reply.simulationHz, this.reply.tick + lead, nowMs), this.started = true;
1168
+ }
1169
+ reconcile(applied, row) {
1170
+ let predictor = this.predictor;
1171
+ if (!predictor || !this.started) return;
1172
+ let store = this.store, tick = store.tickOf(row);
1173
+ if (this.lastReconciled !== (-1) && !newerTick(tick, this.lastReconciled)) return;
1174
+ let cell = row * ENTITY_CAPACITY + this.slotValue;
1175
+ store.present[cell] !== 0 && predictor.reconcile(applied, store.x[cell], store.y[cell], store.z[cell], this.log) && (this.lastReconciled = tick);
1176
+ }
1177
+ play(nowMs) {
1178
+ if (this.watcher) {
1179
+ this.freshSnapshot && (this.unackedSnapshots += 1), (this.unackedSnapshots >= this.spectatorAckEvery || this.cameraDue(nowMs)) && (this.unackedSnapshots = 0, this.governor.admit() && this.send(nowMs)), this.freshSnapshot = false;
1180
+ return;
1181
+ }
1182
+ if (!this.started) return;
1183
+ let predictor = this.predictor;
1184
+ if (!predictor) return;
1185
+ let boost = this.leadDebt(), due = this.ticker.due(nowMs) + boost, coalesce = this.governor.pressured;
1186
+ for (let index = 0; index < due; index++) {
1187
+ let sequence = this.log.push(
1188
+ this.inputAxisX,
1189
+ this.inputAxisZ,
1190
+ this.inputYaw,
1191
+ this.inputButtons,
1192
+ this.ticker.tick,
1193
+ this.inputSubtick
1194
+ );
1195
+ this.ticker.tick += 1, this.inputSubtick = 0, predictor.predict(sequence, this.log), this.statistics.inputsSent += 1, coalesce || this.send(nowMs);
1196
+ }
1197
+ coalesce && due > 0 && (boost > 0 ? this.governor.force() : this.governor.admit()) && this.send(nowMs), this.freshSnapshot = false;
1198
+ }
1199
+ leadDebt() {
1200
+ let want = this.governor.stride - 1;
1201
+ if (want <= this.leadBoost)
1202
+ return this.leadBoost = want, 0;
1203
+ let extra = want - this.leadBoost;
1204
+ return this.leadBoost = want, extra;
1205
+ }
1206
+ cameraDue(nowMs) {
1207
+ return this.cameraSequence > 0 && (this.cameraDirty || nowMs - this.cameraSentAt >= CAMERA_RESEND_MS);
1208
+ }
1209
+ packet() {
1210
+ let packet = this.outbound[this.outboundNext];
1211
+ return this.outboundNext = (this.outboundNext + 1) % OUTBOUND_POOL_SLOTS, packet;
1212
+ }
1213
+ send(nowMs) {
1214
+ let link = this.link;
1215
+ if (!link) return;
1216
+ let packet = this.packet(), view = packet.view, offset = this.watcher ? 0 : this.log.write(view, 0, nowMs);
1217
+ if (this.watcher && this.cameraDue(nowMs) && (offset += this.writeCamera(view, offset, nowMs)), this.store.hasLatest) {
1218
+ let ack = this.ack;
1219
+ ack.slot = SNAPSHOT_STREAM_SLOT, ack.sequence = this.store.latestTick, ack.received_mask = this.receivedMask(ack.sequence);
1220
+ let written = encodeAck(view, offset, ack);
1221
+ written > 0 && (offset += written);
1222
+ }
1223
+ for (let i = 0; i < this.streamAcks.length; i++) {
1224
+ let stream = this.streamAcks[i], sequence = stream.sequence();
1225
+ if (sequence < 0) continue;
1226
+ let ack = this.ack;
1227
+ ack.slot = stream.slot, ack.sequence = sequence >>> 0, ack.received_mask = 0;
1228
+ let written = encodeAck(view, offset, ack);
1229
+ written > 0 && (offset += written);
1230
+ }
1231
+ offset > 0 && link.send(Lane.Datagram, packet.of(offset));
1232
+ }
1233
+ writeCamera(view, offset, nowMs) {
1234
+ let input = this.roomInput;
1235
+ input.flags = 0, input.action = CAMERA_ACTION, input.sequence = this.cameraSequence, input.client_tick = 0;
1236
+ let total = writeRoomInputHeader(view, offset, input, CAMERA_PAYLOAD_BYTES);
1237
+ if (total < 0) return 0;
1238
+ let at = offset + ROOM_INPUT_HEADER;
1239
+ return view.setUint16(at, this.cameraX, (true)), view.setUint16(at + 2, this.cameraZ, (true)), view.setUint16(at + 4, this.cameraRadius, (true)), this.cameraDirty = false, this.cameraSentAt = nowMs, total;
1240
+ }
1241
+ receivedMask(latest) {
1242
+ let simulation = this.reply.simulationHz, sends = this.reply.sendHz, mask = 0, tick = latest;
1243
+ for (let bit = 0; bit < ACK_HISTORY_BITS && (tick = previousSend(tick, simulation, sends), !(tick < 0)); bit++)
1244
+ this.store.received(tick) && (mask = (mask | 1 << bit) >>> 0);
1245
+ return mask;
1246
+ }
1247
+ watchLatency() {
1248
+ let rtt = this.clock.rttMs;
1249
+ !this.extrapolating && rtt > HIGH_LATENCY_ENTER_MS ? this.extrapolating = true : this.extrapolating && rtt < HIGH_LATENCY_LEAVE_MS && (this.extrapolating = false), this.extrapolating && (this.statistics.extrapolatingFrames += 1);
1250
+ }
1251
+ };
1252
+ function sendsOn(tick, simulationHz, sendHz) {
1253
+ return Math.floor(tick * sendHz / simulationHz) !== Math.floor((tick - 1) * sendHz / simulationHz);
1254
+ }
1255
+ function previousSend(tick, simulationHz, sendHz) {
1256
+ for (let candidate = tick - 1; candidate > 0; candidate--)
1257
+ if (sendsOn(candidate, simulationHz, sendHz)) return candidate;
1258
+ return -1;
1259
+ }
1260
+
1261
+ // src/interactives/rooms/state-replica.ts
1262
+ var ROOM_STATE_SLOT = 65520;
1263
+ var STATE_CHUNK_BYTES = 16, STATE_FRAME_VERSION = 1, STATE_HEADER_BYTES = 20;
1264
+ var MAX_STATE_FRAGMENTS = 255;
1265
+ var TickStateReplica = class {
1266
+ constructor() {
1267
+ this.confirmed = new Uint8Array(0);
1268
+ this.confirmedView = new DataView(this.confirmed.buffer);
1269
+ this.pending = new Uint8Array(0);
1270
+ this.predictedBytes = new Uint8Array(0);
1271
+ this.predictedView = new DataView(this.predictedBytes.buffer);
1272
+ this.received = new Uint8Array(Math.ceil(256 / 8));
1273
+ this.confirmedTickValue = -1;
1274
+ this.pendingTick = -1;
1275
+ this.pendingCount = 0;
1276
+ this.pendingFragments = 0;
1277
+ this.listeners = [];
1278
+ this.predictor = null;
1279
+ this.stats = { fragments: 0, completed: 0, keyframes: 0, stale: 0, malformed: 0 };
1280
+ }
1281
+ get tick() {
1282
+ return this.confirmedTickValue;
1283
+ }
1284
+ get bytes() {
1285
+ return this.confirmed.length;
1286
+ }
1287
+ get state() {
1288
+ return this.confirmedView;
1289
+ }
1290
+ get stateBytes() {
1291
+ return this.confirmed;
1292
+ }
1293
+ onState(listener) {
1294
+ return this.listeners.push(listener), () => {
1295
+ let at = this.listeners.indexOf(listener);
1296
+ at >= 0 && this.listeners.splice(at, 1);
1297
+ };
1298
+ }
1299
+ predict(predictor) {
1300
+ this.predictor = predictor;
1301
+ }
1302
+ predicted(toTick) {
1303
+ let predictor = this.predictor;
1304
+ return predictor === null || this.confirmedTickValue === -1 || toTick <= this.confirmedTickValue ? this.confirmedView : (this.predictedBytes.set(this.confirmed), predictor(this.confirmedView, this.predictedView, this.confirmedTickValue, toTick), this.predictedView);
1305
+ }
1306
+ ingest(view, offset, length) {
1307
+ if (length < 20 || view.getUint8(offset + 0) !== 1)
1308
+ return this.stats.malformed++, false;
1309
+ this.stats.fragments++;
1310
+ let keyframe = (view.getUint8(offset + 1) & 1) !== 0, fragment = view.getUint8(offset + 2), fragments = view.getUint8(offset + 3), tick = view.getUint32(offset + 4, true), base = view.getUint32(offset + 8, true), firstChunk = view.getUint16(offset + 12, true), chunkCount = view.getUint16(offset + 14, true), stateBytes = view.getUint32(offset + 16, true);
1311
+ if (fragment >= fragments)
1312
+ return this.stats.malformed++, false;
1313
+ if (this.confirmedTickValue !== -1 && tick <= this.confirmedTickValue)
1314
+ return this.stats.stale++, false;
1315
+ if (!keyframe && (this.confirmedTickValue === -1 || base !== this.confirmedTickValue || stateBytes !== this.confirmed.length))
1316
+ return this.stats.stale++, false;
1317
+ if (tick !== this.pendingTick) {
1318
+ if (this.pendingTick !== -1 && tick < this.pendingTick)
1319
+ return this.stats.stale++, false;
1320
+ this.begin(tick, stateBytes, fragments, keyframe);
1321
+ }
1322
+ let bit = 1 << fragment % 8, byte = fragment >> 3;
1323
+ return (this.received[byte] & bit) !== 0 ? false : this.apply(view, offset + 20, offset + length, firstChunk, chunkCount) ? (this.received[byte] |= bit, this.pendingCount++, this.pendingCount < this.pendingFragments ? false : (this.complete(keyframe), true)) : (this.stats.malformed++, this.pendingTick = -1, false);
1324
+ }
1325
+ begin(tick, stateBytes, fragments, keyframe) {
1326
+ this.confirmed.length !== stateBytes && (this.confirmed = new Uint8Array(stateBytes), this.confirmedView = new DataView(this.confirmed.buffer), this.pending = new Uint8Array(stateBytes), this.predictedBytes = new Uint8Array(stateBytes), this.predictedView = new DataView(this.predictedBytes.buffer), keyframe || (this.confirmedTickValue = -1)), this.pending.set(this.confirmed), this.received.fill(0), this.pendingTick = tick, this.pendingCount = 0, this.pendingFragments = fragments;
1327
+ }
1328
+ apply(view, at, end, firstChunk, chunkCount) {
1329
+ let maskBytes = Math.ceil(chunkCount / 8), read = at + maskBytes;
1330
+ if (read > end) return false;
1331
+ let state = this.pending;
1332
+ for (let index = 0; index < chunkCount; index++) {
1333
+ if ((view.getUint8(at + (index >> 3)) & 1 << index % 8) === 0) continue;
1334
+ let from = (firstChunk + index) * 16, to = Math.min(from + 16, state.length);
1335
+ if (from >= to || read + (to - from) > end) return false;
1336
+ for (let i = from; i < to; i++) state[i] = view.getUint8(read++);
1337
+ }
1338
+ return true;
1339
+ }
1340
+ complete(keyframe) {
1341
+ this.confirmed.set(this.pending), this.confirmedTickValue = this.pendingTick, this.pendingTick = -1, this.stats.completed++, keyframe && this.stats.keyframes++;
1342
+ for (let i = 0; i < this.listeners.length; i++) this.listeners[i](this.confirmedTickValue, this.confirmedView);
1343
+ }
1344
+ };
1345
+
1346
+ // src/interactives/rooms/links/web-socket.ts
1347
+ var BINARY = "arraybuffer", OPEN = 1, WebSocketLink = class {
1348
+ constructor(socket) {
1349
+ this.transport = Transport.WebSocket;
1350
+ this.socket = socket;
1351
+ }
1352
+ send(_lane, bytes) {
1353
+ this.socket.readyState === (1) && this.socket.send(bytes);
1354
+ }
1355
+ close() {
1356
+ this.socket.close();
1357
+ }
1358
+ }, Session = class {
1359
+ constructor(socket, request, handler, settle) {
1360
+ this.admitted = false;
1361
+ this.finished = false;
1362
+ this.opened = () => {
1363
+ this.socket.send(this.request);
1364
+ };
1365
+ this.message = (event) => {
1366
+ let data = event.data;
1367
+ if (typeof data == "string") return;
1368
+ let bytes = new Uint8Array(data);
1369
+ if (this.admitted) {
1370
+ this.handler.frame(Lane.Datagram, bytes);
1371
+ return;
1372
+ }
1373
+ this.admitted = true, this.settle({ link: new WebSocketLink(this.socket), reply: bytes });
1374
+ };
1375
+ this.ended = () => {
1376
+ this.finished || (this.finished = true, this.admitted ? this.handler.closed() : this.settle(null));
1377
+ };
1378
+ this.socket = socket, this.request = request, this.handler = handler, this.settle = settle;
1379
+ }
1380
+ attach() {
1381
+ let socket = this.socket;
1382
+ socket.binaryType = BINARY, socket.onopen = this.opened, socket.onmessage = this.message, socket.onerror = this.ended, socket.onclose = this.ended;
1383
+ }
1384
+ }, WebSocketDialer = class {
1385
+ constructor(url) {
1386
+ this.transport = Transport.WebSocket;
1387
+ this.url = url;
1388
+ }
1389
+ dial(request, handler) {
1390
+ return typeof globalThis.WebSocket != "function" ? Promise.resolve(null) : new Promise((settle) => {
1391
+ try {
1392
+ new Session(new WebSocket(this.url), request, handler, settle).attach();
1393
+ } catch {
1394
+ settle(null);
1395
+ }
1396
+ });
1397
+ }
1398
+ };
1399
+
1400
+ // src/interactives/rooms/links/stream-framer.ts
1401
+ var StreamFramer = class {
1402
+ constructor() {
1403
+ this.buffer = new Uint8Array(STREAM_BUFFER_BYTES);
1404
+ this.view = new DataView(this.buffer.buffer);
1405
+ this.start = 0;
1406
+ this.end = 0;
1407
+ }
1408
+ push(chunk) {
1409
+ return this.end + chunk.length > this.buffer.length && (this.buffer.copyWithin(0, this.start, this.end), this.end -= this.start, this.start = 0), this.end + chunk.length > this.buffer.length ? false : (this.buffer.set(chunk, this.end), this.end += chunk.length, true);
1410
+ }
1411
+ next() {
1412
+ if (this.end - this.start < LANE_LENGTH_BYTES) return null;
1413
+ let length = this.view.getUint16(this.start, true), from = this.start + LANE_LENGTH_BYTES;
1414
+ return this.end - from < length ? null : (this.start = from + length, this.buffer.subarray(from, from + length));
1415
+ }
1416
+ };
1417
+ function lengthPrefixed(bytes, out) {
1418
+ let total = LANE_LENGTH_BYTES + bytes.length;
1419
+ return total > out.length ? -1 : (out[0] = bytes.length & 255, out[1] = bytes.length >>> 8, out.set(bytes, LANE_LENGTH_BYTES), total);
1420
+ }
1421
+
1422
+ // src/interactives/rooms/links/web-transport.ts
1423
+ var RELIABLE_SCRATCH = 8;
1424
+ function ignore() {
1425
+ }
1426
+ function shut(session) {
1427
+ try {
1428
+ session?.close();
1429
+ } catch {
1430
+ return;
1431
+ }
1432
+ }
1433
+ var WebTransportLink = class {
1434
+ constructor(session, stream, datagrams) {
1435
+ this.transport = Transport.WebTransport;
1436
+ this.next = 0;
1437
+ this.open = true;
1438
+ this.session = session, this.stream = stream, this.datagrams = datagrams, this.scratch = Array.from({ length: (8) }, () => new SizedViews(new Uint8Array(PACKET_BYTES + LANE_LENGTH_BYTES)));
1439
+ }
1440
+ send(lane, bytes) {
1441
+ if (!this.open) return;
1442
+ if (lane === Lane.Datagram) {
1443
+ this.datagrams.write(bytes).catch(ignore);
1444
+ return;
1445
+ }
1446
+ let scratch = this.scratch[this.next];
1447
+ this.next = (this.next + 1) % (8);
1448
+ let length = lengthPrefixed(bytes, scratch.buffer);
1449
+ length < 0 || this.stream.write(scratch.of(length)).catch(ignore);
1450
+ }
1451
+ close() {
1452
+ this.open && (this.open = false, shut(this.session));
1453
+ }
1454
+ }, Watch = class {
1455
+ constructor(handler) {
1456
+ this.done = false;
1457
+ this.end = () => {
1458
+ this.done || (this.done = true, this.handler.closed());
1459
+ };
1460
+ this.handler = handler;
1461
+ }
1462
+ };
1463
+ async function pumpDatagrams(reader, handler, watch) {
1464
+ try {
1465
+ for (; ; ) {
1466
+ let read = await reader.read();
1467
+ if (read.done) break;
1468
+ handler.frame(Lane.Datagram, read.value);
1469
+ }
1470
+ } catch {
1471
+ watch.end();
1472
+ return;
1473
+ }
1474
+ watch.end();
1475
+ }
1476
+ async function pumpStream(reader, framer, handler, watch) {
1477
+ try {
1478
+ for (; ; ) {
1479
+ for (let frame = framer.next(); frame; frame = framer.next()) handler.frame(Lane.Reliable, frame);
1480
+ let read = await reader.read();
1481
+ if (read.done || !framer.push(read.value)) break;
1482
+ }
1483
+ } catch {
1484
+ watch.end();
1485
+ return;
1486
+ }
1487
+ watch.end();
1488
+ }
1489
+ var WebTransportDialer = class _WebTransportDialer {
1490
+ constructor(url, options = {}) {
1491
+ this.transport = Transport.WebTransport;
1492
+ this.url = url, this.options = options;
1493
+ }
1494
+ static available() {
1495
+ return typeof globalThis.WebTransport == "function";
1496
+ }
1497
+ async dial(request, handler) {
1498
+ if (!_WebTransportDialer.available()) return null;
1499
+ let session = null;
1500
+ try {
1501
+ session = new WebTransport(this.url, this.options), await session.ready;
1502
+ let stream = await session.createBidirectionalStream(), writer = stream.writable.getWriter(), prefixed = new Uint8Array(LANE_LENGTH_BYTES + request.length);
1503
+ lengthPrefixed(request, prefixed), await writer.write(prefixed);
1504
+ let reader = stream.readable.getReader(), framer = new StreamFramer(), reply = framer.next();
1505
+ for (; !reply; ) {
1506
+ let read = await reader.read();
1507
+ if (read.done || !framer.push(read.value))
1508
+ return shut(session), null;
1509
+ reply = framer.next();
1510
+ }
1511
+ let copied = reply.slice(), watch = new Watch(handler), datagrams = session.datagrams.writable.getWriter(), link = new WebTransportLink(session, writer, datagrams);
1512
+ return pumpDatagrams(session.datagrams.readable.getReader(), handler, watch), pumpStream(reader, framer, handler, watch), session.closed.then(watch.end, watch.end), { link, reply: copied };
1513
+ } catch {
1514
+ return shut(session), null;
1515
+ }
1516
+ }
1517
+ };
1518
+
1519
+ export { Connecting, Connector, GAME_CHANNEL_RELIABLE_BASE, GAME_CHANNEL_SLOTS, InMemoryNetworkMemory, JoinStatus, Locomotion, LocomotionMotion, MAX_STATE_FRAGMENTS, ROOM_STATE_SLOT, RoomClient, RoomPhase, STATE_CHUNK_BYTES, STATE_FRAME_VERSION, STATE_HEADER_BYTES, SizedViews, StorageNetworkMemory, TickStateReplica, Transport, WebSocketDialer, WebTransportDialer, blankReply, currentNetwork, decodeJoinReply, isqrt, locomotionMotion, perAxisUnit, previousSend, resumeRequest, sendsOn, spawn, steer, ticketRequest };