castle-web-cli 0.4.237 → 0.4.239

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 (239) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +133 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +21 -0
  14. package/dist/init.js +2 -1
  15. package/dist/multiplayerDoc.d.ts +1 -1
  16. package/dist/multiplayerDoc.js +9 -0
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.d.ts +1 -0
  19. package/dist/playPagePolicy.js +8 -3
  20. package/dist/roomLogs.d.ts +39 -0
  21. package/dist/roomLogs.js +166 -0
  22. package/dist/save-deck.js +4 -0
  23. package/kits/base/CLAUDE.md +1 -0
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +113 -2
  26. package/kits/base/sdk/castle.d.ts +6 -2
  27. package/kits/base/sdk/castle.js +2 -0
  28. package/kits/base/sdk/commands.d.ts +56 -1
  29. package/kits/base/sdk/commands.js +29 -1
  30. package/kits/base/sdk/hub.d.ts +17 -0
  31. package/kits/base/sdk/hub.js +33 -9
  32. package/kits/base/sdk/localCache.d.ts +27 -0
  33. package/kits/base/sdk/localCache.js +115 -0
  34. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  35. package/kits/base/sdk/localCacheStore.js +358 -0
  36. package/kits/base/sdk/multiplayer.js +30 -0
  37. package/kits/base/sdk/rooms.d.ts +11 -0
  38. package/kits/base/sdk/rooms.js +22 -0
  39. package/kits/base/sdk/store.d.ts +8 -2
  40. package/kits/base/sdk/store.js +5 -1
  41. package/kits/base/sdk/transport.d.ts +1 -0
  42. package/kits/base/sdk/transport.js +4 -5
  43. package/kits/hub-game/CLAUDE.md +22 -2
  44. package/kits/hub-game/castle.json +8 -5
  45. package/kits/hub-game/code/client/act.js +66 -91
  46. package/kits/hub-game/code/client/actCore.js +134 -0
  47. package/kits/hub-game/code/client/car.js +35 -0
  48. package/kits/hub-game/code/client/chrome.js +208 -381
  49. package/kits/hub-game/code/client/crowdNames.js +2 -2
  50. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  51. package/kits/hub-game/code/client/hats.js +2 -0
  52. package/kits/hub-game/code/client/hookLayer.js +99 -48
  53. package/kits/hub-game/code/client/hostGo.js +77 -0
  54. package/kits/hub-game/code/client/hubControls.js +125 -0
  55. package/kits/hub-game/code/client/hubEntry.js +187 -0
  56. package/kits/hub-game/code/client/hudSurface.js +148 -0
  57. package/kits/hub-game/code/client/hudTree.js +96 -0
  58. package/kits/hub-game/code/client/idle.js +59 -13
  59. package/kits/hub-game/code/client/invites.js +13 -4
  60. package/kits/hub-game/code/client/menuIcons.js +8 -0
  61. package/kits/hub-game/code/client/menuRows.js +8 -2
  62. package/kits/hub-game/code/client/noTrips.js +38 -0
  63. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  64. package/kits/hub-game/code/client/rehello.js +3 -1
  65. package/kits/hub-game/code/client/riders.js +26 -0
  66. package/kits/hub-game/code/client/role.js +79 -0
  67. package/kits/hub-game/code/client/safeLayout.js +32 -3
  68. package/kits/hub-game/code/client/sound.js +10 -3
  69. package/kits/hub-game/code/client/soundscape.js +2 -2
  70. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  71. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  72. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  73. package/kits/hub-game/code/client/state.js +19 -0
  74. package/kits/hub-game/code/client/stuck.js +2 -1
  75. package/kits/hub-game/code/client/talkSurface.js +178 -0
  76. package/kits/hub-game/code/client/talkTree.js +238 -0
  77. package/kits/hub-game/code/client/tiers.js +8 -5
  78. package/kits/hub-game/code/client/uiDom.js +600 -0
  79. package/kits/hub-game/code/client/uiTree.js +359 -0
  80. package/kits/hub-game/code/client/vehicle.js +156 -0
  81. package/kits/hub-game/code/client/wear.js +27 -5
  82. package/kits/hub-game/code/client/worldLabels.js +13 -3
  83. package/kits/hub-game/code/client/yours.js +10 -3
  84. package/kits/hub-game/code/server/actors.js +4 -3
  85. package/kits/hub-game/code/server/analytics.js +61 -18
  86. package/kits/hub-game/code/server/decor.js +56 -16
  87. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  88. package/kits/hub-game/code/server/hub.js +261 -46
  89. package/kits/hub-game/code/server/idle.js +118 -5
  90. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  91. package/kits/hub-game/code/server/manifest.js +46 -4
  92. package/kits/hub-game/code/server/npcs.js +4 -2
  93. package/kits/hub-game/code/server/players.js +3 -0
  94. package/kits/hub-game/code/server/role.js +142 -0
  95. package/kits/hub-game/code/server/standing.js +6 -4
  96. package/kits/hub-game/code/server/trackQueue.js +29 -0
  97. package/kits/hub-game/code/server/vehicle.js +126 -0
  98. package/kits/hub-game/code/shared/car.js +52 -0
  99. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  100. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  101. package/kits/hub-game/code/shared/expression.js +9 -0
  102. package/kits/hub-game/code/systems/hub.js +281 -86
  103. package/kits/hub-game/docs/analytics.md +15 -3
  104. package/kits/hub-game/docs/contract.md +352 -14
  105. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  106. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  107. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  108. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  109. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  110. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  111. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  112. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  113. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  114. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  115. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  116. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  117. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  118. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  119. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  120. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  121. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  122. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  123. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  124. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  125. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  126. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  127. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  128. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  129. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  130. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  131. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  132. package/kits/hub-game/package-lock.json +1 -1
  133. package/kits/hub-game/package.json +1 -1
  134. package/kits/hub-game/scripts/check.mjs +7 -4
  135. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  136. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  137. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  138. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  139. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  140. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  141. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  142. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  143. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  144. package/kits/hub-game/scripts/test-analytics.mjs +100 -6
  145. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  146. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  147. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  148. package/kits/hub-game/scripts/test-car.mjs +43 -0
  149. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  150. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  151. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  152. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  153. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  154. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  155. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  156. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  157. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  158. package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
  159. package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
  160. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  161. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  162. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  163. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  164. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  165. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  166. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  167. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  168. package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
  169. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  170. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  171. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  172. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  173. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  174. package/kits/hub-game/scripts/test-resync.mjs +196 -0
  175. package/kits/hub-game/scripts/test-role-client.mjs +427 -0
  176. package/kits/hub-game/scripts/test-role.mjs +350 -0
  177. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  178. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  179. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  180. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  181. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  182. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  183. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  184. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  185. package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
  186. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  187. package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
  188. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  189. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  190. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  191. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  192. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  193. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
  194. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  195. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  196. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  197. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  198. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
  199. package/kits/multiplayer-3d/castle.json +4 -4
  200. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  201. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  202. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  203. package/kits/multiplayer-3d/package-lock.json +1 -1
  204. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  205. package/kits/physics-3d/CLAUDE.md +1 -1
  206. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  207. package/kits/physics-3d/castle.json +2 -2
  208. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  209. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  210. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  211. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  212. package/kits/physics-3d/engine3d/world3d.js +6 -3
  213. package/kits/physics-3d/package.json +1 -1
  214. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  215. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  216. package/kits/physics-3d/systems/physics3d.js +5 -2
  217. package/kits/real-time/castle.json +2 -2
  218. package/kits/real-time/code/client/messages.js +5 -0
  219. package/kits/real-time/code/server/session.js +28 -1
  220. package/kits/real-time/package-lock.json +1 -1
  221. package/package.json +5 -4
  222. package/vendor/three/LICENSE +21 -0
  223. package/vendor/three/build/three.core.js +58773 -0
  224. package/vendor/three/build/three.module.js +18251 -0
  225. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  226. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  227. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  228. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  229. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  230. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  231. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  232. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  233. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  234. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  235. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  236. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  237. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  238. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  239. package/vendor/three/package.json +134 -0
@@ -20,6 +20,8 @@
20
20
 
21
21
  import { warnOnce, isActor } from './actors.js';
22
22
  import { danceFloors } from '../shared/danceIdle.js';
23
+ import { EXPRESSION_EMOTES } from '../shared/expression.js';
24
+ import { bodySize, solids, footprintHas } from './standing.js';
23
25
 
24
26
  const DEG = Math.PI / 180;
25
27
 
@@ -88,9 +90,46 @@ function ask(h, name, ...args) {
88
90
 
89
91
  // --- emotes ---------------------------------------------------------------
90
92
 
93
+ function roleEmote(h, id) {
94
+ return idleOf(h)?.expression?.roleEmotes.find((role) => role.id === id);
95
+ }
96
+
97
+ function duration(h, id) {
98
+ if (typeof id !== 'string') { return null; }
99
+ if (Object.hasOwn(EMOTES, id)) { return EMOTES[id]; }
100
+ if (!idleOf(h)?.expression) { return null; }
101
+ return (Object.hasOwn(EXPRESSION_EMOTES, id) ? EXPRESSION_EMOTES[id].ms : roleEmote(h, id)?.ms) ?? null;
102
+ }
103
+
104
+ // Private visit grants never ride the shared snapshot.
105
+ export function emotesFor(h, playerId, ids) {
106
+ if (!idleOf(h)?.expression || !present(h, playerId) || (ids !== null && !Array.isArray(ids))) { return false; }
107
+ const clean = [];
108
+ for (const id of ids ?? []) {
109
+ if (!roleEmote(h, id)) {
110
+ warnOnce(h, `emotesFor:${String(id)}`, 'hub.emotesFor: unknown role emote');
111
+ } else if (!clean.includes(id)) { clean.push(id); }
112
+ }
113
+ const grants = h.roleEmotes ??= new Map();
114
+ const previous = grants.get(playerId) ?? [];
115
+ if (previous.length === clean.length && previous.every((id) => clean.includes(id))) { return true; }
116
+ grants.set(playerId, clean);
117
+ h.session.send(playerId, { k: 'hub-emotes-for', ids: [...clean] });
118
+ return true;
119
+ }
120
+
121
+ // A fresh client holds no grants: replay a non-empty list on its hello, and
122
+ // any list ever sent on a resume hello (it may have missed a clear).
123
+ export function joinedAfresh(h, playerId, held = false) {
124
+ const ids = h.roleEmotes?.get(playerId);
125
+ if (idleOf(h)?.expression && ids && (held || ids.length)) {
126
+ h.session.send(playerId, { k: 'hub-emotes-for', ids: [...ids] });
127
+ }
128
+ }
129
+
91
130
  function startEmote(h, playerId, id) {
92
131
  const now = h.sim.timeMs;
93
- h.emotes.set(playerId, { id, at: now, until: now + EMOTES[id] });
132
+ h.emotes.set(playerId, { id, at: now, until: now + duration(h, id) });
94
133
  h.emoteAt.set(playerId, now);
95
134
  // v1.47: only a player's emote can start nearby bodies reacting.
96
135
  if (present(h, playerId)) {
@@ -103,7 +142,7 @@ function startEmote(h, playerId, id) {
103
142
  // `emote` hook. Anything else is dropped.
104
143
  export function emoteMessage(h, playerId, data) {
105
144
  const id = data?.id;
106
- if (!idleOf(h)?.emotes || !h.sim || typeof id !== 'string' || !Object.hasOwn(EMOTES, id)) {
145
+ if (!idleOf(h)?.emotes || !h.sim || typeof id !== 'string' || !duration(h, id) || (roleEmote(h, id) && !h.roleEmotes?.get(playerId)?.includes(id))) {
107
146
  return;
108
147
  }
109
148
  if (!present(h, playerId)) {
@@ -130,7 +169,7 @@ export function emote(h, playerId, id) {
130
169
  warnOnce(h, 'emote:off', 'hub.emote: this place does not turn on idle.emotes');
131
170
  return false;
132
171
  }
133
- if (typeof id !== 'string' || !Object.hasOwn(EMOTES, id)) {
172
+ if (!duration(h, id)) {
134
173
  warnOnce(h, `emote:${id}`, `hub.emote: "${id}" is not an emote (${Object.keys(EMOTES).join(', ')})`);
135
174
  return false;
136
175
  }
@@ -247,6 +286,7 @@ export function sitMessage(h, placeAt, playerId, data) {
247
286
  if (!idleOf(h)?.seats || !h.sim || !spendSit(h, playerId)) {
248
287
  return;
249
288
  }
289
+ if (h.ctx?.vehicle?.(playerId)) {return;}
250
290
  const seat = seatOf(h, data?.seat);
251
291
  const body = h.sim.players.get(playerId);
252
292
  if (!seat || !body || !present(h, playerId)) {
@@ -281,12 +321,76 @@ export function sitMessage(h, placeAt, playerId, data) {
281
321
  }
282
322
  h.held.set(playerId, { at: { ...seat.at }, facing: seat.facing, seat: seat.id });
283
323
  h.seated.set(playerId, seat.id);
324
+ h.expressionStill?.delete(playerId);
284
325
  placeAt(h, playerId, seat.at, seat.facing);
285
326
  }
286
327
 
328
+ // Ground support uses the same fixed floor shapes as standing placement: the
329
+ // top a body's feet rest on (within -0.15..0.12 m of them), or null.
330
+ function floorUnder(h, at) {
331
+ const size = bodySize(h);
332
+ if (!size) { return null; }
333
+ const feet = at.y - size.halfHeight;
334
+ let top = null;
335
+ if (h.noGround !== true && Math.abs(at.x) <= 100 && Math.abs(at.z) <= 100 && feet >= -0.15 && feet <= 0.12) { top = 0; }
336
+ for (const { shape, pose, moving } of solids(h)) {
337
+ if (moving || !pose.upright || !['box', 'cylinder'].includes(shape.kind) || !footprintHas(shape, pose, at, 0)) { continue; }
338
+ const surface = pose.y + (shape.height ?? 1) / 2;
339
+ const gap = feet - surface;
340
+ if (gap >= -0.15 && gap <= 0.12 && (top === null || surface > top)) { top = surface; }
341
+ }
342
+ return top;
343
+ }
344
+
345
+ // Keep the anchor until a meaningful displacement, so small pose jitter
346
+ // does not restart the stillness timer; the last step must also be still
347
+ // across, so a walk's first step never sits. Requests also sample between ticks.
348
+ function stillSample(h, playerId, at) {
349
+ const samples = h.expressionStill ??= new Map();
350
+ let sample = samples.get(playerId);
351
+ if (!sample || Math.hypot(at.x - sample.pose.x, at.z - sample.pose.z) > 0.05 || Math.abs(at.y - sample.pose.y) > 0.08) {
352
+ sample = { pose: { ...at }, since: h.sim.timeMs, prev: { ...at }, last: { ...at }, lastAt: h.sim.timeMs, step: 0 };
353
+ samples.set(playerId, sample);
354
+ }
355
+ // The step is measured from the previous tick's pose. Later reports in
356
+ // the same tick only make it larger, so a request after a mid-tick move
357
+ // sees that move, and repeated checks never measure a pose against itself.
358
+ if (sample.lastAt !== h.sim.timeMs) {
359
+ sample.prev = sample.last ?? sample.pose;
360
+ sample.step = 0;
361
+ sample.lastAt = h.sim.timeMs;
362
+ }
363
+ const prev = sample.prev ?? sample.pose;
364
+ sample.step = Math.max(sample.step ?? 0, Math.hypot(at.x - prev.x, at.z - prev.z));
365
+ sample.last = { ...at };
366
+ return sample;
367
+ }
368
+
369
+ // The floor top a still player would sit on, or null.
370
+ function stillFloor(h, playerId) {
371
+ const body = h.sim.players.get(playerId);
372
+ if (!body) { return null; }
373
+ const sample = stillSample(h, playerId, body.at);
374
+ return h.sim.timeMs - sample.since >= 250 && sample.step <= 0.015 ? floorUnder(h, body.at) : null;
375
+ }
376
+
377
+ export function sitHereMessage(h, placeAt, playerId) {
378
+ if (!idleOf(h)?.expression || !h.sim || !spendSit(h, playerId)) { return; }
379
+ const can = () => present(h, playerId) && !h.held.has(playerId) && !sitting(h, playerId) && !h.grabs?.has(playerId) && stillFloor(h, playerId) !== null;
380
+ if (!can() || !ask(h, 'sit', playerId, null) || !can()) { return; }
381
+ const body = h.sim.players.get(playerId);
382
+ // Held no higher than standing on the floor found: a body caught rising is
383
+ // lowered onto it, never frozen in the air.
384
+ const at = { ...body.at, y: Math.min(body.at.y, stillFloor(h, playerId) + bodySize(h).halfHeight + 0.06) };
385
+ h.held.set(playerId, { at, facing: body.facing, seat: 'ground', ground: true });
386
+ h.seated.set(playerId, 'ground');
387
+ h.expressionStill.delete(playerId);
388
+ placeAt(h, playerId, at, body.facing);
389
+ }
390
+
287
391
  // `{ k: 'hub-stand' }` from a client: a sitter gets up where they are.
288
392
  export function standMessage(h, playerId) {
289
- if (!idleOf(h)?.seats || !h.sim || !spendSit(h, playerId)) {
393
+ if (!(idleOf(h)?.seats || idleOf(h)?.expression) || !h.sim || !spendSit(h, playerId)) {
290
394
  return;
291
395
  }
292
396
  stand(h, playerId);
@@ -299,6 +403,7 @@ export function stand(h, playerId) {
299
403
  }
300
404
  h.held.delete(playerId);
301
405
  h.seated.delete(playerId);
406
+ h.expressionStill?.delete(playerId);
302
407
  return true;
303
408
  }
304
409
 
@@ -400,9 +505,15 @@ function loopsNow(h) {
400
505
  // A seat ends when its hold does: the place released the player, held them
401
506
  // itself, ended their visit, or they left; or the place hid the seat.
402
507
  export function tick(h) {
508
+ if (idleOf(h)?.expression) {
509
+ for (const [id, body] of h.sim.players) { stillSample(h, id, body.at); }
510
+ }
403
511
  for (const [playerId, seatId] of [...h.seated]) {
404
512
  if (!h.sim.players.has(playerId) || h.held.get(playerId)?.seat !== seatId) {
405
513
  h.seated.delete(playerId);
514
+ h.expressionStill?.delete(playerId);
515
+ } else if (h.held.get(playerId)?.ground) {
516
+ continue;
406
517
  } else if (h.hidden.has(seatId)) {
407
518
  stand(h, playerId);
408
519
  } else if (h.place?.decor) {
@@ -425,7 +536,7 @@ export function fields(h) {
425
536
  ...(h.danceIdleUsed ? { hubDanceIdle: danceIdleNow(h) } : {}),
426
537
  ...(idle.emotes ? { hubEmotes: emotesNow(h) } : {}),
427
538
  ...(idle.emotes ? h.npcs?.emoteFields() : {}),
428
- ...(idle.seats ? { hubSeated: seatedNow(h) } : {}),
539
+ ...(idle.seats || idle.expression ? { hubSeated: seatedNow(h) } : {}),
429
540
  ...(idle.sounds.length ? { hubSounds: loopsNow(h) } : {}),
430
541
  };
431
542
  }
@@ -453,6 +564,8 @@ function danceIdleNow(h) {
453
564
  }
454
565
 
455
566
  export function forget(h, playerId) {
567
+ h.roleEmotes?.delete(playerId);
568
+ h.expressionStill?.delete(playerId);
456
569
  h.emotes.delete(playerId);
457
570
  h.emoteAt.delete(playerId);
458
571
  h.seated.delete(playerId);
@@ -8,6 +8,7 @@
8
8
  // arrived, LOAD_ABANDON_TIMEOUT_MS after it joined). A timeout suppresses the
9
9
  // later close; an arrival suppresses both.
10
10
  import { LOAD_STAGES, CLIENT_LOAD_STAGES, LOAD_REASONS } from '../shared/loadStages.js';
11
+ import { send } from './trackQueue.js';
11
12
  export { LOAD_STAGES, CLIENT_LOAD_STAGES, LOAD_REASONS };
12
13
 
13
14
  export const LOAD_ABANDONED_KIND = 27;
@@ -29,11 +30,7 @@ function loads(h) {
29
30
  function emit(h, playerId, load, result, now) {
30
31
  load.done = true;
31
32
  const value = Math.max(0, Math.min(LOAD_ABANDON_MAX_MS, Math.round(now - load.at)));
32
- try {
33
- const pending = h.session?.hub?.track?.(playerId, { kind: LOAD_ABANDONED_KIND, subject: load.stage, value, result, flags: 0 });
34
- pending?.catch?.(() => {});
35
- return pending !== undefined && pending !== false;
36
- } catch {return false;}
33
+ return send(h.session, playerId, { kind: LOAD_ABANDONED_KIND, subject: load.stage, value, result, flags: 0 });
37
34
  }
38
35
 
39
36
  // The furthest stage the server can see now; never lowers a recorded one.
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { readUnlocks } from './earned.js';
11
11
  import { readQuality } from '../shared/quality.js';
12
+ import { EMOTE_MOTIONS } from '../shared/expression.js';
12
13
  import { readDecor } from './decor.js';
13
14
 
14
15
  // Manifest/wire major stays 1; latest optional contract additions are v1.128.
@@ -46,7 +47,7 @@ export const GRAB_REACH_LIMITS = [1.6, 3, 'metres'];
46
47
  const GRAB_KEYS = [...Object.keys(GRAB_DEFAULTS), 'reach', 'steady', 'keepHeld'];
47
48
  // Idle play (v1.6, §6): emotes, seats and the place's own sounds. Sounds are
48
49
  // files of the deck, listed so the server can refuse any other name.
49
- export const IDLE_KEYS = ['emotes', 'seats', 'sounds'];
50
+ export const IDLE_KEYS = ['emotes', 'seats', 'sounds', 'expression'];
50
51
  export const SOUND_EXTS = ['.mp3', '.wav', '.m4a'];
51
52
  export const MAX_SOUND_FILES = 16;
52
53
  const SOUND_PATH = /^[A-Za-z0-9_@-][A-Za-z0-9_./@-]{0,199}$/;
@@ -130,7 +131,7 @@ export const SOUNDSCAPE_SURFACES = ['grass', 'street', 'wood', 'stone', 'sand',
130
131
  // `unlocks` is the deck's (v1.53): the earned items its places may give
131
132
  // (`earned.js`). The manifest carries it only when declared, so a deck
132
133
  // without it reads as before.
133
- const TOP_KEYS = ['firstVisit', 'act', 'bringFriend', 'frameBatch', 'defaultEnvironment', 'weakestTier', 'highOnly', 'weakestLookBake', 'pongTimeoutMs', 'contract', 'places', 'interest', 'tiers', 'quality', 'companionIdle', 'lowActorBudget', 'lowActorDistance', 'mergeFarAvatars', 'playOnlyEntry', 'loadTimings', 'loadingCover', 'cues', 'playCards', 'stuck', 'yourGames', 'avatarColors', 'labels', 'safeInsets', 'soundscape', 'unlocks', 'house', 'weeklyCup', ...PLACE_KEYS];
134
+ const TOP_KEYS = ['firstVisit', 'act', 'bringFriend', 'frameBatch', 'defaultEnvironment', 'weakestTier', 'highOnly', 'weakestLookBake', 'pongTimeoutMs', 'contract', 'places', 'interest', 'tiers', 'quality', 'companionIdle', 'lowActorBudget', 'lowActorDistance', 'mergeFarAvatars', 'playOnlyEntry', 'loadTimings', 'loadingCover', 'cues', 'playCards', 'stuck', 'yourGames', 'avatarColors', 'labels', 'safeInsets', 'soundscape', 'unlocks', 'house', 'weeklyCup', 'spawnCap', ...PLACE_KEYS];
134
135
 
135
136
  const DEFAULT_SCENE = 'scenes/main.scene';
136
137
 
@@ -202,6 +203,10 @@ export function readManifest(castleJson, sceneExists = () => true) {
202
203
  if (hub.playCards !== undefined && typeof hub.playCards !== 'boolean') {
203
204
  errors.push('hub.playCards must be true or false.');
204
205
  }
206
+ // v1.161: a deck may raise hub.spawn's cap on copies alive from 96.
207
+ if (hub.spawnCap !== undefined && (!Number.isInteger(hub.spawnCap) || hub.spawnCap < 96 || hub.spawnCap > 192)) {
208
+ errors.push('hub.spawnCap must be an integer 96..192.');
209
+ }
205
210
  if (hub.yourGames !== undefined && typeof hub.yourGames !== 'boolean') {
206
211
  errors.push('hub.yourGames must be true or false.');
207
212
  }
@@ -274,7 +279,7 @@ export function readManifest(castleJson, sceneExists = () => true) {
274
279
  place.idle = { emotes: false, sounds: [], ...place.idle, seats: true };
275
280
  }
276
281
  }
277
- return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, ...(quality ? { quality } : {}), ...(hub.act === true ? { act: true } : {}), cues: hub.cues === true, ...(hub.yourGames === true ? { yourGames: true } : {}), ...(hub.avatarColors === true ? { avatarColors: true } : {}), ...(hub.stuck === true ? { stuck: true } : {}), ...(hub.weeklyCup === true ? { weeklyCup: true } : {}), ...(soundscape ? { soundscape } : {}), ...(unlocks ? { unlocks } : {}), ...(house ? { house } : {}), ...(ballot ? { ballot: true } : {}), places } };
282
+ return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, ...(quality ? { quality } : {}), ...(hub.act === true ? { act: true } : {}), cues: hub.cues === true, ...(hub.yourGames === true ? { yourGames: true } : {}), ...(hub.avatarColors === true ? { avatarColors: true } : {}), ...(hub.stuck === true ? { stuck: true } : {}), ...(hub.weeklyCup === true ? { weeklyCup: true } : {}), ...(soundscape ? { soundscape } : {}), ...(unlocks ? { unlocks } : {}), ...(house ? { house } : {}), ...(ballot ? { ballot: true } : {}), ...(hub.spawnCap !== undefined ? { spawnCap: hub.spawnCap } : {}), places } };
278
283
  }
279
284
 
280
285
  // `hub.soundscape`: its parts where it is on, null where it is left out or
@@ -819,6 +824,43 @@ function readIdle(value, where, errors) {
819
824
  idle[key] = value[key] === true;
820
825
  }
821
826
  }
827
+ if (value.expression !== undefined) {
828
+ const expression = value.expression;
829
+ if (!idle.emotes) { errors.push(`${where}.expression requires idle.emotes: true.`); }
830
+ if (expression !== true && !isObject(expression)) {
831
+ errors.push(`${where}.expression must be true or an object.`);
832
+ } else {
833
+ if (expression !== true) { unknownKeys(expression, ['roleEmotes'], `${where}.expression`, errors); }
834
+ const roles = expression === true ? [] : (Object.hasOwn(expression, 'roleEmotes') ? expression.roleEmotes : []);
835
+ const ids = new Set(EMOTE_MOTIONS);
836
+ const checked = [];
837
+ if (!Array.isArray(roles) || roles.length > 12) {
838
+ errors.push(`${where}.expression.roleEmotes must be a list of at most 12 emotes.`);
839
+ } else {
840
+ for (const [i, role] of roles.entries()) {
841
+ const at = `${where}.expression.roleEmotes[${i}]`;
842
+ if (!isObject(role)) { errors.push(`${at} must be an object.`); continue; }
843
+ unknownKeys(role, ['id', 'emoji', 'label', 'motion', 'ms'], at, errors);
844
+ if (typeof role.id !== 'string' || !/^[a-z][a-z0-9-]{0,23}$/.test(role.id) || ids.has(role.id)) {
845
+ errors.push(`${at}.id must be a unique short id, distinct from kit emotes.`);
846
+ }
847
+ ids.add(role.id);
848
+ if (typeof role.emoji !== 'string' || role.emoji.length > 8 || !/^(?:\p{Regional_Indicator}{2}|[#*0-9]\uFE0F?\u20E3|\p{Extended_Pictographic}\uFE0F?\p{Emoji_Modifier}?(?:\u200D\p{Extended_Pictographic}\uFE0F?\p{Emoji_Modifier}?)*)$/u.test(role.emoji)) {
849
+ errors.push(`${at}.emoji must be one emoji of at most 8 UTF-16 units.`);
850
+ }
851
+ if (typeof role.label !== 'string' || !role.label.trim() || [...role.label].length > 16) {
852
+ errors.push(`${at}.label must be 1..16 characters.`);
853
+ }
854
+ if (!EMOTE_MOTIONS.includes(role.motion)) { errors.push(`${at}.motion must be a kit motion.`); }
855
+ if (typeof role.ms !== 'number' || !Number.isFinite(role.ms) || role.ms < 1000 || role.ms > 6000) {
856
+ errors.push(`${at}.ms must be 1000..6000.`);
857
+ }
858
+ checked.push({ id: role.id, emoji: role.emoji, label: role.label, motion: role.motion, ms: role.ms });
859
+ }
860
+ }
861
+ idle.expression = { roleEmotes: checked };
862
+ }
863
+ }
822
864
  if (value.sounds !== undefined) {
823
865
  const ok =
824
866
  Array.isArray(value.sounds) &&
@@ -1133,7 +1175,7 @@ export function publicPlace(id, place) {
1133
1175
  // without it is sent exactly what it was.
1134
1176
  ...(place.grab ? { grab: { ...place.grab } } : {}),
1135
1177
  // v1.6: likewise idle play.
1136
- ...(place.idle ? { idle: { emotes: place.idle.emotes, seats: place.idle.seats, sounds: [...place.idle.sounds] } } : {}),
1178
+ ...(place.idle ? { idle: { emotes: place.idle.emotes, seats: place.idle.seats, sounds: [...place.idle.sounds], ...(place.idle.expression ? { expression: { roleEmotes: place.idle.expression.roleEmotes.map((role) => ({ ...role })) } } : {}) } } : {}),
1137
1179
  // v1.26: likewise the HUD's layout.
1138
1180
  ...(place.hud ? { hud: { ...place.hud } } : {}),
1139
1181
  ...(place.decor ? { decor: place.decor } : {}),
@@ -497,10 +497,12 @@ function say(h, npc, text, { to, ttlMs = SPEECH_MS, about } = {}) {
497
497
  }
498
498
 
499
499
  function react(h, n, playerId, emote) {
500
+ const aliases = { sleep: 'wave', eat: 'wave', cry: 'wave', laugh: 'cheer', point: 'wave' };
501
+ const reaction = Object.hasOwn(REACTIONS, emote) ? emote : h.place?.idle?.expression && Object.hasOwn(aliases, emote) ? aliases[emote] : null;
500
502
  const player = h.sim?.players.get(playerId);
501
503
  const entry = h.players?.get(playerId);
502
504
  const now = h.sim?.timeMs ?? 0;
503
- if (!player || (h.players && (!entry?.arrived || entry.ended)) || !Object.hasOwn(REACTIONS, emote) || !n.bodies.size || now - (n.reactAt.get(playerId) ?? -Infinity) < REACT_PLAYER_MS) {
505
+ if (!player || (h.players && (!entry?.arrived || entry.ended)) || !reaction || !n.bodies.size || now - (n.reactAt.get(playerId) ?? -Infinity) < REACT_PLAYER_MS) {
504
506
  return;
505
507
  }
506
508
  n.reactAt.set(playerId, now);
@@ -521,7 +523,7 @@ function react(h, n, playerId, emote) {
521
523
  if (override === false) {
522
524
  continue;
523
525
  }
524
- const defaults = REACTIONS[emote];
526
+ const defaults = REACTIONS[reaction];
525
527
  const props = npc.props.reactions?.[emote];
526
528
  let id = reactionEmote(props?.emote, defaults.emote);
527
529
  const lines = Array.isArray(props?.lines) ? props.lines.filter((line) => typeof line === 'string').slice(0, 6).map((line) => cleanLine(line, 80)).filter(Boolean) : defaults.lines;
@@ -16,6 +16,9 @@ import { readPoint } from '@imports/castle.multiplayer-3d/code/server/limits.js'
16
16
  export function hubPlayers(hub) {
17
17
  return {
18
18
  ...Players,
19
+ setPose(sim, playerId, message) {
20
+ if (hub.allowPlayerPose?.(playerId) !== false) {Players.setPose(sim, playerId, message);}
21
+ },
19
22
  addPlayer(sim, playerId, pose) {
20
23
  const result = Players.addPlayer(sim, playerId, pose);
21
24
  if (!pose || !readPoint(pose)) {
@@ -0,0 +1,142 @@
1
+ // Visit-only roles (contract §11, v1.157). No host calls; shared and private
2
+ // whole blocks follow hub.tryOn, including fresh-client RESEND clears.
3
+ import { warnOnce } from './actors.js';
4
+ import { HATS } from '../client/hats.js';
5
+ import { ROLE_TOPS, ROLE_TOOLS } from '../client/role.js';
6
+
7
+ const ID = /^[a-z][a-z0-9-]{0,23}$/;
8
+ const COLOR = /^#[0-9a-f]{6}$/i;
9
+ const KEYS = ['id', 'label', 'color', 'hat', 'top', 'tool'];
10
+ const RESEND = 'resend';
11
+
12
+ export function newRoleState() {
13
+ return { roles: new Map(), roleOwners: new Map(), sentRoleMe: new Map(), roleAloneUsed: false };
14
+ }
15
+
16
+ export function cleanRole(spec) {
17
+ if (spec === null || spec === undefined) { return null; }
18
+ if (typeof spec !== 'object' || Array.isArray(spec) || Object.keys(spec).some((key) => !KEYS.includes(key))) { return undefined; }
19
+ if (typeof spec.id !== 'string' || !ID.test(spec.id) || typeof spec.label !== 'string' ||
20
+ /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(spec.label) ||
21
+ typeof spec.color !== 'string' || !COLOR.test(spec.color)) { return undefined; }
22
+ const label = spec.label.trim();
23
+ if (!label || [...label].length > 16) { return undefined; }
24
+ const out = { id: spec.id, label, color: spec.color.toLowerCase() };
25
+ for (const [key, list] of [['hat', HATS], ['top', ROLE_TOPS], ['tool', ROLE_TOOLS]]) {
26
+ if (Object.hasOwn(spec, key)) {
27
+ if (!list.includes(spec[key])) { return undefined; }
28
+ out[key] = spec[key];
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+
34
+ const present = (h, id) => h.sim?.players.has(id) && h.session?.players.some((p) => p.playerId === id);
35
+ const owner = (h, id) => h.session?.players.find((p) => p.playerId === id)?.userId ?? null;
36
+
37
+ export function role(h, playerId, spec) {
38
+ if (typeof playerId !== 'string' || !(h.players.has(playerId) || h.sim?.players.has(playerId))) {
39
+ warnOnce(h, `role:${playerId}`, `hub.role: "${playerId}" is not a player here`);
40
+ return false;
41
+ }
42
+ const clean = cleanRole(spec);
43
+ if (clean === undefined) {
44
+ warnOnce(h, 'role:spec', 'hub.role: expected { id, label, color: "#rrggbb", hat?, top?, tool? } or null');
45
+ return false;
46
+ }
47
+ if (clean) {
48
+ h.roles.set(playerId, clean);
49
+ // Absent through a short drop, the visit's record names the account: a
50
+ // role given then belongs to it, and is kept when that account returns.
51
+ if (h.session?.players.some((p) => p.playerId === playerId)) {
52
+ h.roleOwners.set(playerId, owner(h, playerId));
53
+ } else if (!h.roleOwners.has(playerId)) {
54
+ h.roleOwners.set(playerId, h.players.get(playerId)?.userId ?? null);
55
+ }
56
+ } else {
57
+ h.roles.delete(playerId);
58
+ h.roleOwners.delete(playerId);
59
+ }
60
+ return true;
61
+ }
62
+
63
+ export function roleOf(h, playerId) {
64
+ if (!(h.players.has(playerId) || h.sim?.players.has(playerId))) { return null; }
65
+ if (h.roleOwners.has(playerId) && h.session?.players.some((p) => p.playerId === playerId) && h.roleOwners.get(playerId) !== owner(h, playerId)) {
66
+ h.roles.delete(playerId);
67
+ h.roleOwners.delete(playerId);
68
+ }
69
+ const spec = h.roles.get(playerId);
70
+ return spec ? { ...spec } : null;
71
+ }
72
+
73
+ // Retained records survive a short absence; an account change never inherits
74
+ // the old role, including a roster change without a new hello.
75
+ export function prune(h) {
76
+ for (const id of h.roles.keys()) {
77
+ const present = h.session?.players.some((p) => p.playerId === id);
78
+ if ((!h.players.has(id) && !h.sim?.players.has(id)) ||
79
+ (present && h.roleOwners.get(id) !== owner(h, id))) {
80
+ h.roles.delete(id);
81
+ h.roleOwners.delete(id);
82
+ }
83
+ }
84
+ for (const id of h.sentRoleMe.keys()) {
85
+ if (!h.players.has(id) && !h.sim?.players.has(id)) { h.sentRoleMe.delete(id); }
86
+ }
87
+ }
88
+
89
+ export function rolesOf(h, hidden) {
90
+ prune(h);
91
+ const out = {};
92
+ for (const [id, spec] of h.roles) {
93
+ if (h.players.get(id)?.hello && present(h, id) && !hidden?.has(id)) { out[id] = spec; }
94
+ }
95
+ return out;
96
+ }
97
+
98
+ export function sendOverrides(h, hidden) {
99
+ // Absent retained players are kept server-side, but not shown on the wire.
100
+ const shown = new Map([...h.roles].filter(([id]) => present(h, id)));
101
+ sendAlone(h, hidden, shown, h.sentRoleMe, (out) => {
102
+ h.roleAloneUsed = true;
103
+ return { k: 'hub-role', hubRole: out };
104
+ });
105
+ }
106
+
107
+ export function joinedAfresh(h, playerId) {
108
+ prune(h);
109
+ if (h.roleAloneUsed) { h.sentRoleMe.set(playerId, RESEND); }
110
+ }
111
+
112
+ export function used(h) { return h.roles.size > 0 || h.sentRoleMe.size > 0; }
113
+
114
+ export function forget(h, playerId) {
115
+ h.roles.delete(playerId);
116
+ h.roleOwners.delete(playerId);
117
+ h.sentRoleMe.delete(playerId);
118
+ }
119
+
120
+ export function end(h) {
121
+ h.roles.clear();
122
+ h.roleOwners.clear();
123
+ h.sentRoleMe.clear();
124
+ }
125
+
126
+ function sendAlone(h, hidden, worn, sent, message) {
127
+ for (const playerId of h.sim.players.keys()) {
128
+ const out = {};
129
+ for (const shrouded of hidden?.keys() ?? []) {
130
+ const wearable = worn.get(shrouded);
131
+ if (wearable && h.players.get(shrouded)?.hello && !hidden.get(playerId)?.has(shrouded)) {
132
+ out[shrouded] = wearable;
133
+ }
134
+ }
135
+ const json = JSON.stringify(out);
136
+ if ((sent.get(playerId) ?? '{}') !== json) {
137
+ sent.set(playerId, json);
138
+ h.session?.send(playerId, message(out));
139
+ }
140
+ }
141
+ }
142
+
@@ -66,7 +66,9 @@ export function bodySize(h) {
66
66
  // Spawned copies live outside h.actors. Hide/show changes h.hidden at once.
67
67
  // hub.move keeps interpolation in h.moves/h.poses and queues a kinematic
68
68
  // target; translation/rotation on the body are the pose physics is at now.
69
- function* solids(h) {
69
+ // Every solid the place has now: scene actors and the copies a game spawned
70
+ // (a House's placed furniture), each at its body's live pose when it has one.
71
+ export function* solids(h) {
70
72
  const actors = [...h.actors, ...[...(h.spawned?.values() ?? [])].map((entry) => entry.actor)];
71
73
  for (const actor of actors) {
72
74
  const c = actor.components;
@@ -74,7 +76,7 @@ function* solids(h) {
74
76
  if (c.Player || h.hidden?.has(actor.id) || !(c.Solid || c.Shape?.solid === true) || !c.Shape) {
75
77
  continue;
76
78
  }
77
- const body = h.sim.bodies?.get(actor.id);
79
+ const body = h.sim?.bodies?.get(actor.id);
78
80
  let pose;
79
81
  if (body) {
80
82
  const p = body.translation();
@@ -94,7 +96,7 @@ function* solids(h) {
94
96
  }
95
97
  }
96
98
 
97
- function footprintHas(shape, pose, at, pad) {
99
+ export function footprintHas(shape, pose, at, pad) {
98
100
  const dx = at.x - pose.x;
99
101
  const dz = at.z - pose.z;
100
102
  if (shape.kind === 'box') {
@@ -105,7 +107,7 @@ function footprintHas(shape, pose, at, pad) {
105
107
  return Math.hypot(dx, dz) <= (shape.radius ?? 0.5) + pad;
106
108
  }
107
109
 
108
- function boundingRadius(shape) {
110
+ export function boundingRadius(shape) {
109
111
  if (shape.kind === 'sphere') {
110
112
  return shape.radius ?? 0.5;
111
113
  }
@@ -0,0 +1,29 @@
1
+ // The cauldron host refuses a hubTrack while two are in flight per session, and
2
+ // a refused row is lost. Every server row goes through here: two in flight per
3
+ // session, the rest wait in order, and past the bound a row is refused at once
4
+ // so a runaway deck cannot grow memory.
5
+ export const TRACK_IN_FLIGHT = 2;
6
+ export const TRACK_QUEUE_MAX = 256;
7
+ const queues = new WeakMap();
8
+ // Whether the row was sent or queued; false when the host has no track.
9
+ export function send(session, playerId, event) {
10
+ if (typeof session?.hub?.track !== 'function') {return false;}
11
+ let q = queues.get(session);
12
+ if (!q) {queues.set(session, q = { inFlight: 0, waiting: [] });}
13
+ if (q.inFlight < TRACK_IN_FLIGHT) {return start(session, q, playerId, event);}
14
+ if (q.waiting.length >= TRACK_QUEUE_MAX) {return false;}
15
+ q.waiting.push([playerId, event]);
16
+ return true;
17
+ }
18
+ function start(session, q, playerId, event) {
19
+ let pending;
20
+ try { pending = session.hub.track(playerId, event); } catch { return false; }
21
+ if (typeof pending?.then !== 'function') {return pending !== undefined && pending !== false;}
22
+ q.inFlight += 1;
23
+ const done = () => {
24
+ q.inFlight -= 1;
25
+ while (q.inFlight < TRACK_IN_FLIGHT && q.waiting.length > 0) {start(session, q, ...q.waiting.shift());}
26
+ };
27
+ pending.then(done, done);
28
+ return true;
29
+ }