castle-web-cli 0.4.240 → 0.4.241

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.
@@ -177,7 +177,10 @@ await test('unreadable resumed pose uses standing spawn', async () => {
177
177
  // -0.14, +1.09), the client snapped there with WORLD, and the arrival row at
178
178
  // the spawn then reached it as a correction under the client's 4 m snap, eased
179
179
  // a quarter of the way a frame: a 1.1 m glide after the cover lifted.
180
- await test('joiners wait on the spawn and the arrival row moves nothing', async () => {
180
+ // v1.218 (Nov 17 Market check): two bodies on exactly one spot wedge, so the
181
+ // second lone joiner starts beside the first, and its WORLD is still the one
182
+ // placement: the arrival row keeps it there.
183
+ await test('joiners wait where WORLD put them, the second beside the first, and the arrival row moves nothing', async () => {
181
184
  const town = { id: 'spawn', components: { ...spawn.components, Transform: { x: 0, y: 1, z: 9 } } };
182
185
  globalThis.__standingActors = [town, door];
183
186
  globalThis.__standingGround = {};
@@ -194,7 +197,14 @@ await test('joiners wait on the spawn and the arrival row moves nothing', async
194
197
  for (const id of ['p1', 'p2']) {
195
198
  wrapped.addPlayer(sim, id);
196
199
  const waiting = { ...sim.players.get(id).at };
197
- assert.deepEqual([waiting.x, waiting.z], [0, 9], `${id} waits on the spawn`);
200
+ if (id === 'p1') {
201
+ assert.deepEqual([waiting.x, waiting.z], [0, 9], 'the first joiner waits on the spawn');
202
+ } else {
203
+ const first = sim.players.get('p1').at;
204
+ const gap = Math.hypot(waiting.x - first.x, waiting.z - first.z);
205
+ assert.ok(gap >= 2 * 0.35, `the second joiner waits off the taken spawn, ${gap} m from the first`);
206
+ assert.deepEqual([first.x, first.z], [0, 9], 'the first stays on the spawn');
207
+ }
198
208
  h.message(session, { playerId: id }, { k: 'hub-hello', avatar: 1 });
199
209
  h.place(sim);
200
210
  assert.ok(sent.some(([to, data]) => to === id && data.k === 'hub-arrived'), `${id} arrived`);
@@ -203,6 +213,129 @@ await test('joiners wait on the spawn and the arrival row moves nothing', async
203
213
  }
204
214
  } finally { sim.world.free(); }
205
215
  });
216
+ // v1.218: the step-off stands on the ground slab, which is finite: a spawn
217
+ // 0.4 m inside a 5 m slab's edge, whose row runs outward first (+x), steps
218
+ // inward, not off the edge.
219
+ await test('a joiner beside a taken spawn near the slab edge steps inward', async () => {
220
+ const edge = { id: 'spawn', components: { ...spawn.components, Transform: { x: 4.6, y: 1, z: 0, rotationY: 0 } } };
221
+ globalThis.__standingActors = [edge, door];
222
+ globalThis.__standingGround = { half: 5 };
223
+ const sim = await World.createSimulation();
224
+ sim.spawn = { x: 4.6, y: 1, z: 0 };
225
+ const h = layer(config, {}, {}, () => true, () => ({ half: 5 }), null, engine);
226
+ const session = { sessionId: 'dev:slab', players: [{ playerId: 'p1' }, { playerId: 'p2' }], send() {}, broadcast() {} };
227
+ h.sceneFor(session);
228
+ h.ready(sim);
229
+ const wrapped = hubPlayers(h);
230
+ try {
231
+ wrapped.addPlayer(sim, 'p1');
232
+ wrapped.addPlayer(sim, 'p2');
233
+ const [a, b] = ['p1', 'p2'].map((id) => sim.players.get(id).at);
234
+ assert.ok(Math.hypot(a.x - b.x, a.z - b.z) >= 0.7, `p2 steps off p1 ${JSON.stringify(b)}`);
235
+ assert.ok(Math.abs(b.x) <= 5 && Math.abs(b.z) <= 5, `p2 stands on the slab ${JSON.stringify(b)}`);
236
+ } finally { sim.world.free(); }
237
+ });
238
+ // v1.218: standing height uses the same finite slab as spotClear: past the
239
+ // edge a body stands on an authored platform below the ground plane, or keeps
240
+ // its given height when nothing holds it, never on the slab's plane.
241
+ await test('standing height past the slab edge stands on the platform there', async () => {
242
+ const platform = { id: 'ledge', components: { Transform: { x: 7, y: -1.5, z: 0, rotationY: 0 },
243
+ Shape: { kind: 'box', width: 2, height: 1, depth: 2, solid: true }, Solid: {} } };
244
+ globalThis.__standingActors = [spawn, door, platform];
245
+ globalThis.__standingGround = { half: 5 };
246
+ const sim = await World.createSimulation();
247
+ sim.spawn = { x: 0, y: 1, z: 0 };
248
+ const h = layer(config, {}, {}, () => true, () => ({ half: 5 }), null, engine);
249
+ const session = { sessionId: 'dev:ledge', players: [{ playerId: 'p1' }], send() {}, broadcast() {} };
250
+ h.sceneFor(session);
251
+ h.ready(sim);
252
+ try {
253
+ const onLedge = h.standingY(sim, { x: 7, y: 1, z: 0 });
254
+ assert.ok(onLedge < -0.1 && onLedge > -0.4, `stands on the ledge top (-1), got ${onLedge}`);
255
+ assert.equal(h.standingY(sim, { x: 7, y: 1, z: 4 }), 1, 'nothing holds a body past the slab: keep the given height');
256
+ assert.ok(Math.abs(h.standingY(sim, { x: 4, y: 1, z: 0 }) - 0.76) < 0.05, 'on the slab: the ground');
257
+ } finally { sim.world.free(); }
258
+ });
259
+ // v1.218: a body on a floor above (or below) does not take the spot.
260
+ await test('a body on another floor does not move a joiner off the spawn', async () => {
261
+ globalThis.__standingActors = [spawn, door];
262
+ globalThis.__standingGround = {};
263
+ const sim = await World.createSimulation();
264
+ sim.spawn = { x: 0, y: 1, z: 0 };
265
+ const h = layer(config, {}, {}, () => true, () => ({}), null, engine);
266
+ const session = { sessionId: 'dev:floors', players: [{ playerId: 'p1' }, { playerId: 'p2' }], send() {}, broadcast() {} };
267
+ h.sceneFor(session);
268
+ h.ready(sim);
269
+ const wrapped = hubPlayers(h);
270
+ try {
271
+ wrapped.addPlayer(sim, 'p1');
272
+ const up = sim.players.get('p1');
273
+ up.at = { ...up.at, y: up.at.y + 4 };
274
+ wrapped.addPlayer(sim, 'p2');
275
+ const b = sim.players.get('p2').at;
276
+ assert.deepEqual([b.x, b.z], [0, 0], `p2 keeps the spawn under a body 4 m up ${JSON.stringify(b)}`);
277
+ up.at = { ...up.at, y: up.at.y - 4 };
278
+ wrapped.addPlayer(sim, 'p3');
279
+ const c = sim.players.get('p3').at;
280
+ assert.ok(Math.hypot(c.x, c.z) >= 0.7, `a third, with two on the spawn at its height, steps off ${JSON.stringify(c)}`);
281
+ } finally { sim.world.free(); }
282
+ });
283
+ // v1.218: real-time admits a joiner before it removes the bodies of players
284
+ // who left the roster that tick (session.js reconcilePlayers). Such a body is
285
+ // going, and takes no spot: the joiner lands on the spawn itself.
286
+ await test('a body whose player left the roster this tick does not move a joiner off the spawn', async () => {
287
+ globalThis.__standingActors = [spawn, door];
288
+ globalThis.__standingGround = {};
289
+ const sim = await World.createSimulation();
290
+ sim.spawn = { x: 0, y: 1, z: 0 };
291
+ const h = layer(config, {}, {}, () => true, () => ({}), null, engine);
292
+ const session = { sessionId: 'dev:leaving', players: [{ playerId: 'p1' }], send() {}, broadcast() {} };
293
+ h.sceneFor(session);
294
+ h.ready(sim);
295
+ const wrapped = hubPlayers(h);
296
+ try {
297
+ wrapped.addPlayer(sim, 'p1');
298
+ // p1 leaves and p2 joins on the same tick: the roster has p2 only, and
299
+ // p1's body is still in the simulation while p2 is admitted.
300
+ session.players = [{ playerId: 'p2' }];
301
+ assert.ok(sim.players.has('p1'), 'the leaver\'s body is still there');
302
+ wrapped.addPlayer(sim, 'p2');
303
+ const b = sim.players.get('p2').at;
304
+ assert.deepEqual([b.x, b.z], [0, 0], `p2 lands exactly on the spawn ${JSON.stringify(b)}`);
305
+ } finally { sim.world.free(); }
306
+ });
307
+ // v1.218: a group row whose arrival marker stands 4 m above flat ground. Its
308
+ // slots are judged where a body stands in them: a member stepping off an
309
+ // occupied slot does not take a later member's slot (at the marker's raw
310
+ // height that slot looked free).
311
+ await test('an elevated arrival row: a stepped-off member leaves later members their own slots', async () => {
312
+ const marker = { id: 'arrival', components: { Transform: { x: 0, y: 5, z: 0 } } };
313
+ globalThis.__standingActors = [spawn, door, marker];
314
+ globalThis.__standingGround = {};
315
+ const sim = await World.createSimulation();
316
+ const rowConfig = { ...config, hub: { ...config.hub, arrival: { actor: 'arrival', spread: 1.5, face: 0 } } };
317
+ const h = layer(rowConfig, {}, {}, () => true, () => ({}), null, engine);
318
+ const session = { sessionId: 'dev:row', players: ['p0', 'p1', 'p2'].map((playerId) => ({ playerId })), send() {}, broadcast() {} };
319
+ h.sceneFor(session);
320
+ h.ready(sim);
321
+ try {
322
+ for (const id of ['p0', 'p1', 'p2']) Players.addPlayer(sim, id);
323
+ // Face 0: the row runs along +x, slots at x -0.75 and +0.75. p0 stands
324
+ // in the first.
325
+ const p0 = sim.players.get('p0');
326
+ p0.at = { x: -0.75, y: h.standingY(sim, { x: -0.75, y: 5, z: 0 }), z: 0 };
327
+ p0.body.setTranslation(p0.at, true);
328
+ assert.ok(p0.at.y < 1, `flat ground under the marker ${p0.at.y}`);
329
+ for (const id of ['p1', 'p2']) h.message(session, { playerId: id }, { k: 'hub-hello', avatar: 1, party: 2 });
330
+ h.place(sim);
331
+ const [a, b] = ['p1', 'p2'].map((id) => sim.players.get(id).at);
332
+ assert.ok(Math.abs(b.x - 0.75) < 1e-6 && Math.abs(b.z) < 1e-6, `the later member keeps its own slot ${JSON.stringify(b)}`);
333
+ assert.ok(a.x < -0.75 - 0.7, `the stepped-off member goes the other way ${JSON.stringify(a)}`);
334
+ for (const [u, v] of [[a, b], [a, p0.at], [b, p0.at]]) {
335
+ assert.ok(Math.hypot(u.x - v.x, u.z - v.z) >= 0.7, `distinct spots ${JSON.stringify([u, v])}`);
336
+ }
337
+ } finally { sim.world.free(); }
338
+ });
206
339
  await test('other Players exports pass through unchanged', () => {
207
340
  const wrapped = hubPlayers({});
208
341
  assert.deepEqual(Object.keys(wrapped).sort(), Object.keys(Players).sort());
@@ -1400,7 +1400,11 @@ test('refused when asked again within 5 s, taken after', () => {
1400
1400
  assert.deepEqual(b.at('p2'), { x: 6, y: 0.76, z: -9 });
1401
1401
  skew += 200;
1402
1402
  b.unstick('p1');
1403
- assert.deepEqual(b.at('p1'), { x: 6, y: 0.76, z: -9 });
1403
+ // v1.218: p2 stands on the arrival now, so p1 steps off it along the row
1404
+ // (two bodies on one spot wedge on the client).
1405
+ const p1 = b.at('p1');
1406
+ assert.equal(p1.x, 6);
1407
+ assert.ok(Math.hypot(p1.x - 6, p1.z + 9) >= 0.7, `p1 is put beside p2, not on it: ${JSON.stringify(p1)}`);
1404
1408
  assert.equal(b.sent.length, 3);
1405
1409
  // It counts as a jump: no door jump within a second of it, and none of it
1406
1410
  // within a second of a door jump.
@@ -26,7 +26,7 @@
26
26
  "autoUpdateWhenImported": true,
27
27
  "deckId": "ZwA_P_-VO-Qh",
28
28
  "cardId": "bvRmCzyUpt_a",
29
- "publishedVersion": "2026-11-15T00:45:38.865Z",
29
+ "publishedVersion": "2026-11-17T22:31:57.174Z",
30
30
  "main": "main.jsx",
31
31
  "server": {
32
32
  "main": "code/server/index.js",
@@ -71,7 +71,7 @@ export const RESYNC_REPLY_MS = 3000;
71
71
  // `replyExpired` whether its unanswered reply has been reported, and `hiddenAt`
72
72
  // the page time the page hid with a resync out (`suspendReply`).
73
73
  export function makeGate() {
74
- return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false, askedAt: null, replyExpired: false, hiddenAt: null };
74
+ return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false, askedAt: null, replyExpired: false, hiddenAt: null, pausedAt: null };
75
75
  }
76
76
 
77
77
  // Arm the gate for an away that began at page time `since`, when the server's
@@ -92,6 +92,7 @@ export function arm(gate, since, serverAt) {
92
92
  gate.askedAt = null;
93
93
  gate.replyExpired = false;
94
94
  gate.hiddenAt = null;
95
+ gate.pausedAt = null;
95
96
  return true;
96
97
  }
97
98
 
@@ -106,6 +107,7 @@ export function clear(gate) {
106
107
  gate.askedAt = null;
107
108
  gate.replyExpired = false;
108
109
  gate.hiddenAt = null;
110
+ gate.pausedAt = null;
109
111
  }
110
112
 
111
113
  // Whether to ask for a resync now, at page time `now`: once per away, an away
@@ -202,6 +204,15 @@ export function current(gate, msg) {
202
204
  return msg.t >= expected - Math.max(LAG_MS, away * LAG_SHARE);
203
205
  }
204
206
 
207
+ // A gate whose visible wait must not count an away (the report wait after a
208
+ // reconnect) is paused at page time `at`, when the page hid or its frames
209
+ // stopped; the next visible `waited` moves its start on by the time away.
210
+ export function pauseWait(gate, at) {
211
+ if (gate.armed && gate.pausedAt === null) {
212
+ gate.pausedAt = at;
213
+ }
214
+ }
215
+
205
216
  // Note one frame while armed. `visible` is whether the page is shown. Returns
206
217
  // true when the gate has waited `RESUME_WAIT_MS` of visible time and should
207
218
  // give up.
@@ -209,6 +220,12 @@ export function waited(gate, now, visible) {
209
220
  if (!gate.armed || !visible) {
210
221
  return false;
211
222
  }
223
+ if (gate.pausedAt !== null) {
224
+ if (gate.shownAt !== null) {
225
+ gate.shownAt += Math.max(0, now - gate.pausedAt);
226
+ }
227
+ gate.pausedAt = null;
228
+ }
212
229
  gate.shownAt ??= now;
213
230
  return now - gate.shownAt > RESUME_WAIT_MS;
214
231
  }
@@ -227,6 +227,9 @@ class MultiplayerSystem {
227
227
  this.resume = ResumeGate.makeGate();
228
228
  // How long to wait for a resync reply before forcing recovery; 0 turns it off.
229
229
  this.resyncReplyMs = ResumeGate.RESYNC_REPLY_MS;
230
+ // A reconnect can retain joined and the old local pose. It must not
231
+ // report that pose as acknowledgement of this connection's placement.
232
+ this.reportPlacement = ResumeGate.makeGate();
230
233
  this.frameAt = 0;
231
234
  this.wasAway = false;
232
235
  this.gaveUp = false;
@@ -293,6 +296,7 @@ class MultiplayerSystem {
293
296
  this.gaveUp = false;
294
297
  } else {
295
298
  this.away(last || now);
299
+ this.waitForPlacement(now);
296
300
  }
297
301
  ResumeGate.noteConnection(this.resume, connected, now);
298
302
  if (gaitModel()) {
@@ -324,6 +328,11 @@ class MultiplayerSystem {
324
328
  this.resumed();
325
329
  this.gaveUp = true;
326
330
  }
331
+ // A WORLD without a self row (including a resync) can release the cover
332
+ // without placing us. Bound the separate report wait by the same timeout.
333
+ if (ResumeGate.waited(this.reportPlacement, now, !pageHidden())) {
334
+ ResumeGate.clear(this.reportPlacement);
335
+ }
327
336
  this.applyGone(scene);
328
337
  this.reportGone(scene);
329
338
 
@@ -343,7 +352,7 @@ class MultiplayerSystem {
343
352
  // Deck code can make a final local adjustment after engine Player behavior
344
353
  // and physics, then optionally replace the kit's standard report.
345
354
  game.beforeReport?.(scene, local, this);
346
- if (!this.joined) {
355
+ if (!this.joined || this.reportPlacement.armed) {
347
356
  // Nothing reported until the session has placed this player.
348
357
  } else if (game.report) {
349
358
  game.report(scene, local, this);
@@ -425,6 +434,7 @@ class MultiplayerSystem {
425
434
  return;
426
435
  }
427
436
  this.net = net;
437
+ if (this.joined) {this.waitForPlacement(performance.now());}
428
438
  this.joinCommitted = true;
429
439
  if (net.status().state === 'connected') { this.joinStage('connected'); }
430
440
  this.joinRetryAt = 0;
@@ -645,6 +655,8 @@ class MultiplayerSystem {
645
655
  // kept behind the cover from now until a current snapshot (`receive`). The
646
656
  // cover goes up at once, because this runs from the page's hidden event.
647
657
  away(since) {
658
+ // The report wait counts visible time only, like the cover's give-up.
659
+ ResumeGate.pauseWait(this.reportPlacement, since);
648
660
  if (!this.net || !this.joined || this.gaveUp || this.net.status().solo || this.joinError) {
649
661
  return;
650
662
  }
@@ -662,11 +674,21 @@ class MultiplayerSystem {
662
674
  reconnected() {
663
675
  const now = performance.now();
664
676
  this.gaveUp = false;
677
+ ResumeGate.clear(this.reportPlacement);
678
+ this.waitForPlacement(now);
665
679
  this.away(this.frameAt || now);
666
680
  ResumeGate.noteConnection(this.resume, false, now);
667
681
  ResumeGate.noteConnection(this.resume, true, now);
668
682
  }
669
683
 
684
+ waitForPlacement(now) {
685
+ if (!this.joined || this.gaveUp || this.net?.status().solo) {return;}
686
+ if (ResumeGate.arm(this.reportPlacement, now, null)) {
687
+ this.placedTo = null;
688
+ this.clampedTo = null;
689
+ }
690
+ }
691
+
670
692
  // A current snapshot arrived after an away. Every displayed pose is
671
693
  // forgotten, so this frame draws each object and player at its current pose
672
694
  // rather than smoothing from the one shown before the away, and each live
@@ -719,6 +741,7 @@ class MultiplayerSystem {
719
741
  // gone, and the join overlay covers the next one.
720
742
  endAway() {
721
743
  ResumeGate.clear(this.resume);
744
+ ResumeGate.clear(this.reportPlacement);
722
745
  this.wasAway = false;
723
746
  this.gaveUp = false;
724
747
  }
@@ -852,7 +875,8 @@ class MultiplayerSystem {
852
875
  for (const [id, x, y, z, facing, clamped] of msg.ps ?? []) {
853
876
  if (id !== selfId) {
854
877
  sample(this.players, msg, id, [x, y, z, facing]);
855
- } else if (msg.k === WORLD && !again) {
878
+ } else if (!again && (msg.k === WORLD || this.reportPlacement.armed) &&
879
+ (!this.reportPlacement.armed || msg.localMs >= this.reportPlacement.since)) {
856
880
  // The WORLD snapshot that starts a session carries where this player
857
881
  // left off. The body is moved there in one step, behind the overlay.
858
882
  this.placedTo = { x, y, z };
@@ -1199,6 +1223,11 @@ class MultiplayerSystem {
1199
1223
  // Without a body yet, the placement waits for one.
1200
1224
  if (this.placedTo && body) {
1201
1225
  body.setTranslation(this.placedTo, true);
1226
+ scene.physics3d.resetInterpolation?.(local);
1227
+ // Physics already synced this frame: reports and hooks must see the
1228
+ // correction too, rather than the Transform from before it.
1229
+ Object.assign(local.components.Transform, this.placedTo);
1230
+ ResumeGate.clear(this.reportPlacement);
1202
1231
  body.setLinvel({ x: 0, y: 0, z: 0 }, true);
1203
1232
  this.placedTo = null;
1204
1233
  this.settleFrames = 1;
@@ -1218,23 +1247,25 @@ class MultiplayerSystem {
1218
1247
  // intermediate positions as valid movement.
1219
1248
  if (Math.hypot(off.x, off.y, off.z) > CLAMP_SNAP) {
1220
1249
  body.setTranslation(to, true);
1250
+ scene.physics3d.resetInterpolation?.(local);
1251
+ Object.assign(local.components.Transform, to);
1221
1252
  body.setLinvel({ x: 0, y: 0, z: 0 }, true);
1222
1253
  return;
1223
1254
  }
1224
1255
 
1225
1256
  // Ease smaller corrections to avoid an abrupt backward change after an
1226
1257
  // ordinary dropped frame or client stall.
1227
- body.setTranslation(
1228
- { x: at.x + off.x * CLAMP_EASE, y: at.y + off.y * CLAMP_EASE, z: at.z + off.z * CLAMP_EASE },
1229
- true,
1230
- );
1258
+ const eased = { x: at.x + off.x * CLAMP_EASE, y: at.y + off.y * CLAMP_EASE, z: at.z + off.z * CLAMP_EASE };
1259
+ body.setTranslation(eased, true);
1260
+ scene.physics3d.resetInterpolation?.(local);
1261
+ Object.assign(local.components.Transform, eased);
1231
1262
  }
1232
1263
 
1233
1264
  // Report the post-physics local Player pose, poses of locally owned objects,
1234
1265
  // and proximity-based ownership requests. Engine Player behavior and local
1235
1266
  // Rapier simulation have already completed for this frame.
1236
1267
  report(scene, local) {
1237
- if (!local) {
1268
+ if (!local || this.reportPlacement.armed) {
1238
1269
  return;
1239
1270
  }
1240
1271
  const now = performance.now();
@@ -1444,6 +1475,9 @@ class MultiplayerSystem {
1444
1475
  // Other players' avatars are the kit's own and are not reported. Nothing is
1445
1476
  // reported before the session has placed this player.
1446
1477
  reportGone(scene) {
1478
+ // Keep the previous set until reporting resumes, so removals during the
1479
+ // wait are reported afterwards rather than lost or sent to an old world.
1480
+ if (this.reportPlacement.armed) {return;}
1447
1481
  const ids = new Set(scene.actors.keys());
1448
1482
  if (this.seen && this.joined) {
1449
1483
  const avatars = new Set(this.avatars.actors.values());
@@ -37,10 +37,22 @@ const stubs = {
37
37
  register(
38
38
  `data:text/javascript,${encodeURIComponent(`
39
39
  import { readFile } from 'node:fs/promises';
40
+ import { existsSync } from 'node:fs';
41
+ import { fileURLToPath } from 'node:url';
40
42
  const stubs = ${JSON.stringify(stubs)};
41
43
  const kits = ${JSON.stringify(kits)};
42
44
  const baseline = ${JSON.stringify(baseline)};
43
45
  export async function resolve(s, c, next) {
46
+ // Exercise the live physics step/writeBack/API with a stationary stand-in
47
+ // Rapier body. Frozen rendering is outside this interpolation regression.
48
+ if (c.parentURL?.endsWith('/physics-3d/systems/physics3d.js')) {
49
+ if (s === '../engine3d/rapier.js') return { url: 'data:text/javascript,' + encodeURIComponent('export const init = async () => {}; export const RigidBodyType = { Dynamic: 0 };'), shortCircuit: true };
50
+ if (s === '../engine3d/frozenphysics.js') return { url: 'data:text/javascript,export class FrozenPhysics {}', shortCircuit: true };
51
+ }
52
+ if (c.parentURL?.endsWith('/real-time/code/client/connection.js')) {
53
+ if (s === 'castle-web-sdk') return { url: 'data:text/javascript,' + encodeURIComponent('export const Multiplayer = { join: async () => globalThis.__rateConnection };'), shortCircuit: true };
54
+ if (s === './joinOverlay.js') return { url: 'data:text/javascript,export const showLoadFailed = () => {};', shortCircuit: true };
55
+ }
44
56
  if (c.parentURL?.endsWith('/systems/multiplayer.js') && stubs[s]) {
45
57
  return { url: 'data:text/javascript,' + encodeURIComponent(stubs[s]), shortCircuit: true };
46
58
  }
@@ -51,6 +63,10 @@ register(
51
63
  if (baseline && c.parentURL === baseline && s.startsWith('../')) {
52
64
  return next(new URL(s, kits + 'multiplayer-3d/code/systems/multiplayer.js').href, c);
53
65
  }
66
+ if (s.startsWith('.') && c.parentURL?.includes('/physics-3d/')) {
67
+ const url = new URL(s, c.parentURL);
68
+ if (existsSync(fileURLToPath(url) + '.js')) return next(url.href + '.js', c);
69
+ }
54
70
  return next(s, c);
55
71
  }
56
72
  export async function load(u, c, next) {
@@ -877,6 +893,216 @@ for (const action of ['close', 'switch']) {
877
893
  frame(room);
878
894
  assert.equal(globalThis.__cover, '(no words)', 'a second return is quiet again');
879
895
  }
896
+ // A resumed transport retains joined, but its old local pose must not count
897
+ // as acknowledgement of a placement this connection has not applied yet.
898
+ const { game: reportHooks } = await import(`data:text/javascript,${encodeURIComponent(stubs['@imports/castle.real-time/code/client/gameHooks.js'])}`);
899
+ for (const event of [true, false]) for (const placement of ['world', 'self row']) {
900
+ const room = await makeRoom({ objects: { crate: [4, 1, 0, 0, 0, 0, 1] } });
901
+ deliver(room, world(room), pageMs);
902
+ run(room, pageMs + 100);
903
+ const local = room.scene.actorWith('Player');
904
+ Object.assign(local.components.Transform, { x: -1, y: 1, z: 12.844 });
905
+ room.scene.physics3d.bodyOf(local).setTranslation(local.components.Transform);
906
+ const reports = [];
907
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
908
+ let delegated = 0;
909
+ // Same delegation as hub-game's hookLayer.report for a player on foot.
910
+ reportHooks.report = (scene, actor, system) => { delegated++; system.report(scene, actor); };
911
+ try {
912
+ frame(room);
913
+ assert.equal(reports.length, 1, 'an already placed connection reports normally');
914
+ reports.length = 0;
915
+ delegated = 0;
916
+ room.socket = false;
917
+ room.state = 'reconnecting';
918
+ frame(room);
919
+ reconnect(room, { event });
920
+ room.actors.delete('crate');
921
+ frame(room);
922
+ assert.equal(room.system.joined, true, 'joined is retained across reconnect');
923
+ assert.equal(reports.length, 0, 'the old body is not reported on the new connection');
924
+ assert.equal(delegated, 0, 'the hub report override waits too');
925
+ room.system.report(room.scene, local);
926
+ assert.equal(reports.length, 0, 'direct calls through the override cannot bypass the gate');
927
+ assert.ok(!room.outbox.some(msg => msg.k === 'g'), 'gone reports wait with moves');
928
+ deliver(room, world(room, { again: 1 }), pageMs);
929
+ frame(room);
930
+ assert.equal(reports.length, 0, 'a resync WORLD does not place this connection');
931
+ const bodyOf = room.scene.physics3d.bodyOf;
932
+ room.scene.physics3d.bodyOf = () => null;
933
+ const ps = [['self', 0, 1, 9, 0]];
934
+ deliver(room, placement === 'world' ? world(room, { ps }) : { k: 's', t: simNow(), ps }, pageMs);
935
+ frame(room);
936
+ assert.equal(reports.length, 0, 'receipt alone is not enough while the body is missing');
937
+ room.scene.physics3d.bodyOf = bodyOf;
938
+ frame(room);
939
+ assert.equal(reports.length, 1, 'the frame applying placement can report');
940
+ assert.deepEqual(reports[0].slice(0, 3), [0, 1, 9], 'the first report carries the applied placement');
941
+ frame(room);
942
+ assert.ok(room.outbox.some(msg => msg.k === 'g'), 'gone reports resume after placement');
943
+ } finally { delete reportHooks.report; }
944
+ }
945
+ for (const release of ['timeout', 'endAway']) {
946
+ const room = await makeRoom({ objects: {} });
947
+ deliver(room, world(room), pageMs);
948
+ run(room, pageMs + 100);
949
+ const reports = [];
950
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
951
+ reconnect(room);
952
+ // The cover can release without a placement, but the report wait still
953
+ // has its own copy of the existing visible-time deadline.
954
+ deliver(room, world(room, { again: 1 }), pageMs);
955
+ frame(room);
956
+ assert.equal(reports.length, 0);
957
+ if (release === 'timeout') run(room, pageMs + 10100);
958
+ else { room.system.endAway(); frame(room); }
959
+ assert.ok(reports.length > 0, `${release}: reporting does not wait forever`);
960
+ }
961
+ // The report wait counts visible time only: an away after the wait started
962
+ // (hidden, or frames stopped) does not spend it, so a return cannot report the
963
+ // retained pose before this connection's placement.
964
+ for (const away of ['hidden', 'stall']) {
965
+ const room = await makeRoom({ objects: {} });
966
+ deliver(room, world(room), pageMs);
967
+ run(room, pageMs + 100);
968
+ const reports = [];
969
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
970
+ reconnect(room);
971
+ deliver(room, world(room, { again: 1 }), pageMs);
972
+ frame(room);
973
+ run(room, pageMs + 2000);
974
+ assert.equal(room.system.reportPlacement.armed, true, `${away}: still waiting for placement`);
975
+ if (away === 'hidden') { hide(room); pageMs += 30000; show(room); }
976
+ else { pageMs += 30000; }
977
+ frame(room);
978
+ assert.equal(room.system.reportPlacement.armed, true, `${away}: time away does not release the report wait`);
979
+ assert.equal(reports.length, 0, `${away}: no report of the retained pose on return`);
980
+ run(room, pageMs + 7000);
981
+ assert.equal(reports.length, 0, `${away}: still held inside the visible wait`);
982
+ run(room, pageMs + 1500);
983
+ assert.ok(reports.length > 0, `${away}: the visible wait still ends`);
984
+ }
985
+ console.log('test-resume-gate: reconnect reports wait for applied placement; WORLD, self row, body delay, hook, timeout, endAway and visible-time wait pass');
986
+
987
+ // Clamp application and reporting share one frame, before physics can sync
988
+ // the Transform again. The hub's report hook delegates to this same report.
989
+ for (const correction of ['placement', 'snap', 'ease', 'placement then ease']) {
990
+ const room = await makeRoom({ objects: {} });
991
+ deliver(room, world(room), pageMs);
992
+ run(room, pageMs + 100);
993
+ const local = room.scene.actorWith('Player');
994
+ const body = room.scene.physics3d.bodyOf(local);
995
+ const before = { x: -1, y: 1, z: 12.656 };
996
+ Object.assign(local.components.Transform, before, { rotationY: 90 });
997
+ body.setTranslation(before, true);
998
+ let expected;
999
+ if (correction === 'placement' || correction === 'placement then ease') {
1000
+ room.system.placedTo = { x: 0, y: 1, z: 9 };
1001
+ expected = { x: 0, y: 1, z: 9 };
1002
+ }
1003
+ if (correction === 'snap') {
1004
+ room.system.clampedTo = { x: 8, y: 2, z: 20 };
1005
+ expected = { x: 8, y: 2, z: 20 };
1006
+ }
1007
+ if (correction === 'ease') {
1008
+ room.system.clampedTo = { x: 0, y: 2, z: 9 };
1009
+ expected = { x: -0.75, y: 1.25, z: 11.742 };
1010
+ }
1011
+ if (correction === 'placement then ease') {
1012
+ room.system.clampedTo = { x: -1, y: 1, z: 12.656 };
1013
+ expected = { x: -0.25, y: 1, z: 9.914 };
1014
+ }
1015
+ const reports = [];
1016
+ room.system.net.sendMove = pose => { reports.push(pose); return true; };
1017
+ frame(room);
1018
+ assert.equal(reports.length, 1, `${correction}: one report in the corrected frame`);
1019
+ assert.deepEqual(reports[0].slice(0, 3), [expected.x, expected.y, expected.z], `${correction}: the report carries the applied pose`);
1020
+ for (const axis of ['x', 'y', 'z']) {
1021
+ assert.ok(Math.abs(local.components.Transform[axis] - expected[axis]) < 1e-9, `${correction}: Transform ${axis} agrees`);
1022
+ assert.ok(Math.abs(body.translation()[axis] - expected[axis]) < 1e-9, `${correction}: body ${axis} agrees`);
1023
+ }
1024
+ assert.equal(local.components.Transform.rotationY, 90, 'corrections preserve facing');
1025
+ assert.equal(reports[0][3], 1.571, 'report retains Transform facing');
1026
+ if (correction.startsWith('placement')) assert.equal(room.system.settleFrames, 1);
1027
+ }
1028
+ console.log('test-resume-gate: same-frame placement, clamp snap and clamp ease reports carry the applied position');
1029
+
1030
+ // A rate-limited correction frame can be followed by several render frames
1031
+ // before physics steps again. Use the LIVE engine's history/writeback and
1032
+ // the real MOVE_HZ transport, rather than making every send succeed.
1033
+ const { Physics3DSystem } = await import('../../physics-3d/systems/physics3d.js');
1034
+ const { connectSession: rateLimitedSession } = await import('../../real-time/code/client/connection.js');
1035
+ const { MOVE_HZ } = await import('../../real-time/code/client/messages.js');
1036
+ const fastFrameMs = 1000 / 240;
1037
+ for (const correction of ['placement', 'snap', 'ease', 'placement then ease']) {
1038
+ const room = await makeRoom({ objects: {} });
1039
+ deliver(room, world(room), pageMs);
1040
+ run(room, pageMs + 100);
1041
+ const local = room.scene.actorWith('Player');
1042
+ const body = room.scene.physics3d.bodyOf(local);
1043
+ const before = { x: 0, y: 1, z: 1 };
1044
+ Object.assign(local.components.Transform, before, { rotationY: 90 });
1045
+ local.components.Body = { lockRotations: true };
1046
+ body.setTranslation(before, true);
1047
+ body.bodyType = () => 0;
1048
+ room.scene.getActors = () => [local];
1049
+ const physics = new Physics3DSystem();
1050
+ physics.attach(room.scene);
1051
+ physics.bodies.set(local.id, { body });
1052
+ let fixedSteps = 0;
1053
+ physics.world = { step: () => fixedSteps++ };
1054
+ physics.eventQueue = { drainCollisionEvents() {} };
1055
+ physics.step(1 / 60);
1056
+ physics.writeBack(room.scene);
1057
+ assert.equal(physics.bodies.get(local.id).prev.z, before.z, 'a fixed step recorded the old pose');
1058
+
1059
+ const packets = [];
1060
+ globalThis.__rateConnection = {
1061
+ playerId: 'self', state: 'connected', isSolo: false,
1062
+ send: packet => packets.push(packet), onMessage() {}, onRoster() {}, onStateChange() {},
1063
+ };
1064
+ const transport = await rateLimitedSession();
1065
+ // The correction narrowly misses a send slot; the next frame gets it,
1066
+ // still before a single new fixed physics step has run.
1067
+ const correctionAt = pageMs;
1068
+ pageMs -= 1000 / MOVE_HZ - fastFrameMs / 2;
1069
+ assert.equal(transport.sendMove([0, 1, 1, 0], [], [], []), true);
1070
+ pageMs = correctionAt;
1071
+ packets.length = 0;
1072
+ room.system.net.sendMove = transport.sendMove;
1073
+ let expected;
1074
+ if (correction === 'placement' || correction === 'placement then ease') {
1075
+ room.system.placedTo = { x: 0, y: 1, z: 0 };
1076
+ expected = [0, 1, 0];
1077
+ }
1078
+ if (correction === 'snap') {
1079
+ room.system.clampedTo = { x: 5, y: 1, z: -5 };
1080
+ expected = [5, 1, -5];
1081
+ }
1082
+ if (correction === 'ease') {
1083
+ room.system.clampedTo = { x: 0, y: 1, z: -2 };
1084
+ expected = [0, 1, 0.25];
1085
+ }
1086
+ if (correction === 'placement then ease') {
1087
+ room.system.clampedTo = { x: 0, y: 1, z: 1 };
1088
+ expected = [0, 1, 0.25];
1089
+ }
1090
+ frame(room);
1091
+ assert.equal(packets.length, 0, `${correction}: the correction frame's report is rate-limited`);
1092
+ for (let i = 1; i <= 16; i++) {
1093
+ pageMs += fastFrameMs;
1094
+ physics.step(fastFrameMs / 1000);
1095
+ physics.writeBack(room.scene);
1096
+ if (i < 4) assert.equal(fixedSteps, 1, 'writeback runs without a new physics step');
1097
+ const t = local.components.Transform;
1098
+ assert.deepEqual([t.x, t.y, t.z], expected, `${correction}: frame ${i} never interpolates from the old pose`);
1099
+ frame(room);
1100
+ if (i === 1) assert.equal(packets.length, 1, 'the next actual send precedes the next physics step');
1101
+ for (const packet of packets) assert.deepEqual(packet.p.slice(0, 3), expected, `${correction}: outgoing reports keep the corrected position`);
1102
+ }
1103
+ assert.ok(packets.length >= 2, 'the rate limiter also sends a later report');
1104
+ }
1105
+ console.log('test-resume-gate: 240 Hz live physics writeback and rate-limited reports keep placement, snap and ease corrections');
880
1106
 
881
1107
  console.table(results);
882
1108
  console.log('test-resume-gate: current snapshots release returns; silent resyncs recover once');
@@ -61,5 +61,5 @@
61
61
  "autoUpdateWhenImported": true,
62
62
  "deckId": "JH0SclbPVP0y",
63
63
  "cardId": "eXfAaUdbSU5A",
64
- "publishedVersion": "2026-11-15T00:45:03.769Z"
64
+ "publishedVersion": "2026-11-18T00:50:50.040Z"
65
65
  }
@@ -6,7 +6,7 @@
6
6
  "restart": "castle-web restart .",
7
7
  "screenshot": "castle-web screenshot .",
8
8
  "test:wall-slide": "node scripts/test-wall-slide.mjs",
9
- "check": "eslint . && jscpd && npm run test:wall-slide && node scripts/test-rapier-gz.mjs && node scripts/test-ground-half.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-sleeping-models.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-template-cache.mjs && node scripts/test-template-cache-minified.mjs && node scripts/test-model-cache.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
9
+ "check": "eslint . && jscpd && npm run test:wall-slide && node scripts/test-coaxial-escape.mjs && node scripts/test-rapier-gz.mjs && node scripts/test-ground-half.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-sleeping-models.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-template-cache.mjs && node scripts/test-template-cache-minified.mjs && node scripts/test-model-cache.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
10
10
  },
11
11
  "jscpd": {
12
12
  "path": [