castle-web-cli 0.4.254 → 0.4.256

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 (29) hide show
  1. package/kits/hub-game/code/client/chrome.js +94 -27
  2. package/kits/hub-game/code/client/crowdNames.js +3 -2
  3. package/kits/hub-game/code/client/hudTree.js +16 -4
  4. package/kits/hub-game/code/client/nameTagLayout.js +46 -0
  5. package/kits/hub-game/code/client/role.js +4 -2
  6. package/kits/hub-game/code/client/safeLayout.js +1 -0
  7. package/kits/hub-game/code/client/worldLabels.js +54 -8
  8. package/kits/hub-game/code/systems/hub.js +90 -12
  9. package/kits/hub-game/docs/contract.md +10 -2
  10. package/kits/hub-game/scripts/fixtures/hud-surface.json +63 -63
  11. package/kits/hub-game/scripts/fixtures/talk-surface.json +4 -4
  12. package/kits/hub-game/scripts/test-actions-client.mjs +13 -3
  13. package/kits/hub-game/scripts/test-disguise-client.mjs +1 -1
  14. package/kits/hub-game/scripts/test-hud-clear.mjs +16 -10
  15. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +59 -0
  16. package/kits/hub-game/scripts/test-hud-surface.mjs +31 -4
  17. package/kits/hub-game/scripts/test-placement-cache.mjs +87 -0
  18. package/kits/hub-game/scripts/test-prompt-portrait-dom.mjs +128 -0
  19. package/kits/hub-game/scripts/test-quality.mjs +1 -1
  20. package/kits/hub-game/scripts/test-role-client.mjs +82 -6
  21. package/kits/hub-game/scripts/test-talk-surface.mjs +3 -0
  22. package/kits/hub-game/scripts/test-world-labels.mjs +81 -0
  23. package/kits/multiplayer-3d/CLAUDE.md +13 -0
  24. package/kits/multiplayer-3d/castle.json +3 -3
  25. package/kits/multiplayer-3d/code/client/resumeGate.js +70 -8
  26. package/kits/multiplayer-3d/code/systems/multiplayer.js +3 -0
  27. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +133 -1
  28. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +39 -0
  29. package/package.json +1 -1
@@ -5,6 +5,8 @@ import { pathToFileURL } from 'node:url';
5
5
  import { makeNear } from '../code/client/labelsNear.js';
6
6
  import { relevantLabels, worldPlacement, makeWorldLayout, worldLabelFocus, mapWorldPoint, offsetWorldPoint } from '../code/client/worldLabels.js';
7
7
  import { makeLayoutCache } from '../code/client/layoutCache.js';
8
+ import { nameTagShift, projectNameTag } from '../code/client/nameTagLayout.js';
9
+ import { PerspectiveCamera, Sprite, Vector3 } from 'three';
8
10
 
9
11
  assert.equal(worldLabelFocus(true, false, false), false, 'explicit near town unchanged');
10
12
  assert.equal(worldLabelFocus(true, true, true), true, 'host town policy does not exempt games');
@@ -46,6 +48,43 @@ assert.equal(worldLabelFocus(false, false, false), true, 'keyless standalone pla
46
48
  }
47
49
 
48
50
  const box = (left, top, w = 100, h = 26) => ({ left, top, right: left + w, bottom: top + h });
51
+ {
52
+ const area = { ...box(15, 20, 360, 800), width: 360, height: 800 };
53
+ assert.equal(nameTagShift(box(-10, 200, 80), area), 33);
54
+ assert.equal(nameTagShift(box(330, 200, 80), area), -43);
55
+ assert.equal(nameTagShift(box(50, 200, 80), area), 0);
56
+ assert.equal(nameTagShift(box(-35, 200, 80), area), 58, 'a cut name whose centre is past the left edge slides in');
57
+ assert.equal(nameTagShift(box(370, 200, 80), area), -83, 'and past the right edge');
58
+ assert.equal(nameTagShift(box(-65, 200, 80), area), 0, 'a name wholly left of the view stays out');
59
+ assert.equal(nameTagShift(box(375, 200, 80), area), 0, 'a name wholly right of the view stays out');
60
+ assert.equal(nameTagShift(box(-10, -20, 80), area), 0, 'top anchor off screen');
61
+ assert.equal(nameTagShift(box(-5, 200, 400), area), 0, 'a tag wider than the view cannot fit');
62
+
63
+ const cam = new PerspectiveCamera(55, area.width / area.height, 0.1, 100);
64
+ cam.position.set(1, 4, 10); cam.lookAt(0, 0, 0); cam.updateMatrixWorld();
65
+ const tag = new Sprite();
66
+ tag.scale.set(1, 0.4, 1);
67
+ tag.position.set(-0.98, 0, 0.97).unproject(cam);
68
+ const anchor = tag.position.clone().project(cam);
69
+ const projected = projectNameTag(tag, cam, area, new Vector3(), {});
70
+ const moved = tag.position.clone().project(cam);
71
+ assert(Math.abs(projected.left - (area.left + 8)) < 1e-10);
72
+ assert(moved.x > anchor.x);
73
+ assert(Math.abs(moved.z - anchor.z) < 1e-10, 'clamp preserves camera depth');
74
+ assert(Math.abs(moved.y - anchor.y) < 1e-10, 'clamp moves only along camera right');
75
+ // Centre just past the left edge, part of the name still in view: slides in.
76
+ tag.position.set(-1.02, 0, 0.97).unproject(cam);
77
+ assert(Math.abs(projectNameTag(tag, cam, area, new Vector3(), {}).left - (area.left + 8)) < 1e-9);
78
+ // Wholly outside the view: left where it is.
79
+ tag.position.set(-2, 0, 0.97).unproject(cam);
80
+ const offscreen = tag.position.clone();
81
+ assert(projectNameTag(tag, cam, area, new Vector3(), {}).right < area.left);
82
+ assert(tag.position.equals(offscreen));
83
+ tag.position.set(0, 0, 1).applyMatrix4(cam.matrixWorld);
84
+ const behind = tag.position.clone();
85
+ assert.equal(projectNameTag(tag, cam, area, new Vector3(), {}), null);
86
+ assert(tag.position.equals(behind));
87
+ }
49
88
  for (const view of [{ w: 844, h: 390 }, { w: 1440, h: 900 }]) {
50
89
  const items = Array.from({ length: 20 }, (_, i) => ({ id: `tag${i}`, d: i + 1, box: box(200 + i * 110, 200) }));
51
90
  const state = makeNear();
@@ -83,6 +122,48 @@ assert.equal(label.style.visibility, '', 'label returns when pointer leaves');
83
122
  layout.begin();
84
123
  console.log('world labels: bounded nearest tags, objective precedence, HUD/columns/corners, collision collapse and frame restoration passed');
85
124
 
125
+ {
126
+ const view = { w: 390, h: 844 };
127
+ const names = new Map([['p2', { ...box(110, 240, 100, 24), depth: 0.8 }]]);
128
+ const caption = { ...box(130, 246, 80, 30), depth: 0.9 };
129
+ assert.deepEqual(worldPlacement([], [caption], [], view, [], names).labels, [null]);
130
+ const nearer = { ...caption, depth: 0.7 };
131
+ assert.deepEqual(worldPlacement([], [nearer], [], view, [], names).labels, [nearer]);
132
+ const mark = { ...box(135, 208, 50, 28), tagPlayerId: 'p2' };
133
+ const role = { ...box(128, 268, 64, 28), tagPlayerId: 'p2' };
134
+ for (const chip of [mark, role]) {
135
+ const sign = { ...chip, tagPlayerId: undefined, depth: 0.9 };
136
+ assert.deepEqual(worldPlacement([], [sign, chip], [], view, [], names).labels, [null, chip], 'the anchored chip wins against a farther sign');
137
+ const blocked = worldPlacement([], [sign, chip], [box(135, chip.top - 10, 10, 20)], view, [], names);
138
+ assert.deepEqual(blocked.labels, [null, null], 'controls still have priority');
139
+ }
140
+ // The viewer's own mark under a turned phone's HUD steps down just clear of
141
+ // it, over its own body if need be, rather than vanishing; another
142
+ // player's mark there is still dropped, and no step lands on a control.
143
+ {
144
+ const turned = { w: 844, h: 390 };
145
+ const hud = box(282, 12, 280, 88);
146
+ const body = box(390, 160, 70, 120);
147
+ const own = { ...box(403, 91, 38, 30), drop: true, ignoreObstacle: body, tagPlayerId: 'me' };
148
+ assert.deepEqual(worldPlacement([], [own], [hud, body], turned).labels, [box(403, 104, 38, 30)]);
149
+ assert.deepEqual(worldPlacement([], [{ ...own, drop: undefined }], [hud, body], turned).labels, [null], 'another mark is dropped as before');
150
+ const lower = box(380, 100, 80, 40);
151
+ assert.deepEqual(worldPlacement([], [own], [hud, lower, body], turned).labels, [box(403, 144, 38, 30)], 'steps past each control in turn');
152
+ assert.deepEqual(worldPlacement([], [own], [hud, box(0, 100, 844, 290)], turned).labels, [null], 'nothing clear below');
153
+ assert.deepEqual(worldPlacement([], [{ ...own, top: -40, bottom: -10 }], [], turned).labels, [box(403, 6, 38, 30)], 'above the view it comes down onto it');
154
+ }
155
+ const slidesIntoName = { ...box(-8, 248, 48, 22), depth: 0.9, clamp: true };
156
+ const clipped = node(slidesIntoName);
157
+ const tagAtEdge = new Map([['p2', { ...box(41, 240, 20, 24), depth: 0.8 }]]);
158
+ const pass = makeWorldLayout(() => [{ kind: 'label', node: clipped, depth: slidesIntoName.depth, clamp: true }],
159
+ () => view, undefined, undefined, undefined, () => tagAtEdge);
160
+ pass.flush();
161
+ assert.equal(clipped.style.visibility, 'hidden', 'depth uses the final box after sliding');
162
+ tagAtEdge.clear();
163
+ pass.flush();
164
+ assert.equal(clipped.style.visibility, '', 'a hidden name no longer occludes');
165
+ }
166
+
86
167
  // Caption reflow is a deliberate late measurement. It survives the deferred
87
168
  // reset, and restoring its width invalidates a snapshot taken while narrowed.
88
169
  {
@@ -348,3 +348,16 @@ text (comparing the raw username rebuilt an anonymous player's canvas and textur
348
348
  every frame), and `connection.js`'s `status().you` falls back to the roster entry
349
349
  for the local playerId, so a local player's own tag is not missing while the
350
350
  SDK's `you` is still null.
351
+
352
+ ## Change notes
353
+
354
+ - 2026-11-19 (572b9ab0b): a short away (a frame stall past `STALL_MS`, or an app
355
+ switch under `RESYNC_AWAY_MS` with the socket kept) asks for its resync once the
356
+ page has been shown `RESYNC_QUIET_MS` (250 ms) since it last hid and a drain
357
+ brought nothing current (`ResumeGate.askQuiet`). The session sends nothing on a
358
+ tick where nothing changed, so a still room (Foot Race's start line) used to keep
359
+ the resume cover up until 5 s: black, then "Reconnecting…". A page that hides
360
+ with a resync out asks again on return, and only a WORLD arriving after the latest
361
+ request answers it. Known limit: replies carry no request id, so a late reply to
362
+ an earlier request still counts. No wire change; aways of 5 s or more and dropped
363
+ connections behave as before.
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "castle.physics-3d": {
13
13
  "deckId": "JH0SclbPVP0y",
14
- "version": "2026-11-15T00:45:03.769Z"
14
+ "version": "2026-11-19T11:14:34.739Z"
15
15
  },
16
16
  "castle.physics-2d": {
17
17
  "deckId": "ckRZGFW4iPrx",
@@ -20,13 +20,13 @@
20
20
  },
21
21
  "castle.base": {
22
22
  "deckId": "yRcmH4_aYllE",
23
- "version": "2026-11-15T00:40:25.157Z"
23
+ "version": "2026-11-19T09:37:15.255Z"
24
24
  }
25
25
  },
26
26
  "autoUpdateWhenImported": true,
27
27
  "deckId": "ZwA_P_-VO-Qh",
28
28
  "cardId": "bvRmCzyUpt_a",
29
- "publishedVersion": "2026-11-17T22:31:57.174Z",
29
+ "publishedVersion": "2026-11-19T12:39:24.311Z",
30
30
  "main": "main.jsx",
31
31
  "server": {
32
32
  "main": "code/server/index.js",
@@ -57,6 +57,15 @@ const WORLD = 'w';
57
57
  // ordinary release, as does a session that offers none.
58
58
  export const RESYNC_AWAY_MS = 5000;
59
59
 
60
+ // A session broadcasts nothing on a tick where nothing changed, so a still room
61
+ // (players waiting at a start line) may send no current broadcast at all after
62
+ // a short away: a phone rotation or an arrival hitch past `STALL_MS` then kept
63
+ // the cover up until `RESYNC_AWAY_MS`, black and then 'Reconnecting…'. A shorter
64
+ // away is asked for its resync once the page has been shown this long, without
65
+ // hiding, and a whole drain still brought nothing current (`askQuiet`); a busy
66
+ // room's next broadcast releases it well before.
67
+ export const RESYNC_QUIET_MS = 250;
68
+
60
69
  // A socket can read connected and carry nothing after an away. A resync left
61
70
  // unanswered this long asks the transport to recover instead of waiting for
62
71
  // its keepalive deadline.
@@ -69,9 +78,13 @@ export const RESYNC_REPLY_MS = 3000;
69
78
  // it was seen not connected, `backAt` when it came back after that, and
70
79
  // `asked` whether a resync was asked for (`ask`), `askedAt` the page time then,
71
80
  // `replyExpired` whether its unanswered reply has been reported, and `hiddenAt`
72
- // the page time the page hid with a resync out (`suspendReply`).
81
+ // the page time the page hid with a resync out (`suspendReply`). `visibleAt` is
82
+ // the first frame of the page's current showing (cleared by a hide), `replyAfter`
83
+ // the page time of the latest resync sent, which only a WORLD arriving after
84
+ // answers, and `reask` whether the page hid with a resync out, so its return
85
+ // asks again.
73
86
  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, pausedAt: null };
87
+ 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, visibleAt: null, replyAfter: null, reask: false };
75
88
  }
76
89
 
77
90
  // Arm the gate for an away that began at page time `since`, when the server's
@@ -93,6 +106,9 @@ export function arm(gate, since, serverAt) {
93
106
  gate.replyExpired = false;
94
107
  gate.hiddenAt = null;
95
108
  gate.pausedAt = null;
109
+ gate.visibleAt = null;
110
+ gate.replyAfter = null;
111
+ gate.reask = false;
96
112
  return true;
97
113
  }
98
114
 
@@ -108,17 +124,49 @@ export function clear(gate) {
108
124
  gate.replyExpired = false;
109
125
  gate.hiddenAt = null;
110
126
  gate.pausedAt = null;
127
+ gate.visibleAt = null;
128
+ gate.replyAfter = null;
129
+ gate.reask = false;
111
130
  }
112
131
 
113
- // Whether to ask for a resync now, at page time `now`: once per away, an away
114
- // of at least `RESYNC_AWAY_MS` over a connection that never dropped (one that
115
- // dropped is sent a WORLD anyway). Marks the gate asked when it says yes.
132
+ // Whether to ask for a resync now, at page time `now`, before a drain: once per
133
+ // away of at least `RESYNC_AWAY_MS` over a connection that never dropped (one
134
+ // that dropped is sent a WORLD anyway), and again after the page hid with one
135
+ // out, since a reply that came while hidden may be followed by dropped frames.
136
+ // Marks the gate asked when it says yes.
116
137
  export function ask(gate, now) {
117
- if (!gate.armed || gate.dropped || gate.asked || now - gate.since < RESYNC_AWAY_MS) {
138
+ if (!gate.armed || gate.dropped) {
139
+ return false;
140
+ }
141
+ if (gate.asked) {
142
+ if (!gate.reask) {
143
+ return false;
144
+ }
145
+ gate.reask = false;
146
+ gate.replyAfter = now;
147
+ return true;
148
+ }
149
+ if (now - gate.since < RESYNC_AWAY_MS) {
118
150
  return false;
119
151
  }
152
+ return asking(gate, now);
153
+ }
154
+
155
+ // Whether to ask for a resync now, at page time `now`, after a drain that left
156
+ // the gate armed: a shorter away over a connection that never dropped, whose
157
+ // page has been shown for `RESYNC_QUIET_MS` since it last hid. A still room
158
+ // sends no broadcast to release it.
159
+ export function askQuiet(gate, now) {
160
+ if (!gate.armed || gate.dropped || gate.asked || gate.visibleAt === null || now - gate.visibleAt < RESYNC_QUIET_MS) {
161
+ return false;
162
+ }
163
+ return asking(gate, now);
164
+ }
165
+
166
+ function asking(gate, now) {
120
167
  gate.asked = true;
121
168
  gate.askedAt = now;
169
+ gate.replyAfter = now;
122
170
  return true;
123
171
  }
124
172
 
@@ -137,8 +185,17 @@ export function unanswered(gate, now, limit) {
137
185
  // be drained while hidden, so the reply wait and the give-up both count visible
138
186
  // time only: `resumeReply` moves them on by the time away. Neither restarts, so
139
187
  // a page that keeps hiding still reaches both.
188
+ // The page hiding also ends its current showing (`askQuiet` counts from the
189
+ // next), and a resync out is asked again on the return (`ask`).
140
190
  export function suspendReply(gate, now) {
141
- if (gate.armed && gate.asked && gate.hiddenAt === null) {
191
+ if (!gate.armed) {
192
+ return;
193
+ }
194
+ gate.visibleAt = null;
195
+ if (gate.asked) {
196
+ gate.reask = true;
197
+ }
198
+ if (gate.asked && gate.hiddenAt === null) {
142
199
  gate.hiddenAt = now;
143
200
  }
144
201
  }
@@ -189,8 +246,12 @@ export function current(gate, msg) {
189
246
  if (gate.dropped) {
190
247
  return msg.k === WORLD && gate.backAt !== null && msg.localMs >= gate.backAt;
191
248
  }
249
+ // Asked for a resync, only a WORLD after the latest request answers it.
250
+ // Known limit: a reply carries no request id, so a reply to an earlier
251
+ // request that is delivered late (after a hide's re-ask) still counts. Closing
252
+ // that needs the session to echo a request id: a wire change.
192
253
  if (msg.k === WORLD) {
193
- return true;
254
+ return !gate.asked || msg.localMs >= gate.replyAfter;
194
255
  }
195
256
  // A resync was asked for: no broadcast can say what the dropped ones did.
196
257
  if (gate.asked) {
@@ -227,5 +288,6 @@ export function waited(gate, now, visible) {
227
288
  gate.pausedAt = null;
228
289
  }
229
290
  gate.shownAt ??= now;
291
+ gate.visibleAt ??= now;
230
292
  return now - gate.shownAt > RESUME_WAIT_MS;
231
293
  }
@@ -918,6 +918,9 @@ class MultiplayerSystem {
918
918
  }
919
919
  if (fresh) {
920
920
  this.resumed();
921
+ } else if (resuming && this.resyncs && ResumeGate.askQuiet(this.resume, performance.now())) {
922
+ // After the drain, so a current broadcast already queued releases first.
923
+ this.net.send({ k: RESYNC });
921
924
  }
922
925
  this.placeGrants(scene);
923
926
  }
@@ -246,7 +246,9 @@ function run(room, until) {
246
246
  if (pageMs >= room.nextTick) {
247
247
  room.nextTick += TICK_MS;
248
248
  const msg = broadcast(room);
249
- if (room.socket) {
249
+ // A real session sends nothing on a tick where nothing changed (`still`).
250
+ const empty = !msg.os.length && !msg.ps.length;
251
+ if (room.socket && !(room.still && empty)) {
250
252
  deliver(room, msg);
251
253
  }
252
254
  }
@@ -572,6 +574,136 @@ if (baseline) {
572
574
  check('1.1 s frame stall', room, { uncoverBy: 200 });
573
575
  }
574
576
 
577
+ // A frame stall in a still room (Foot Race's start line: nobody moves, so the
578
+ // session sends nothing at all) has no broadcast to release it. The gate asks
579
+ // for its resync once the page has been shown RESYNC_QUIET_MS, and the reply
580
+ // releases it well before RESYNC_AWAY_MS and before the cover finds words:
581
+ // it was black, then 'Reconnecting…', for 5 s on every phone rotation.
582
+ {
583
+ const room = await makeRoom({ objects: { crate: [3, 0.5, 3, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0] } });
584
+ room.still = true;
585
+ deliver(room, world(room, { rs: 1 }), pageMs);
586
+ run(room, pageMs + 2000);
587
+ room.lastFrame = pageMs - FRAME_MS;
588
+ frame(room);
589
+ pageMs += 1500;
590
+ room.nextTick = pageMs;
591
+ room.shownAt = pageMs;
592
+ const asks = () => room.outbox.filter((m) => m.k === 'r').length;
593
+ run(room, pageMs + FRAME_MS * 2);
594
+ assert.equal(room.system.resume.armed, true, 'the stall arms the gate');
595
+ assert.equal(asks(), 0, 'no resync before the quiet wait');
596
+ run(room, room.shownAt + 350);
597
+ assert.equal(asks(), 1, 'a still room is asked for its resync once');
598
+ deliver(room, world(room, { rs: 1, again: 1 }));
599
+ run(room, pageMs + 300);
600
+ assert.equal(room.system.resume.armed, false, 'the resync releases it');
601
+ assert.equal(asks(), 1);
602
+ check('1.5 s frame stall in a still room', room, { uncoverBy: 700 });
603
+ assert.ok(room.frames.every((f) => f.cover !== 'Reconnecting…'), 'the cover never says Reconnecting');
604
+ }
605
+
606
+ // A stall in a still room whose page hides again with the quiet resync out:
607
+ // the reply that came while hidden can be followed by dropped frames (here the
608
+ // crate moved), so the return asks again and only that reply releases it.
609
+ {
610
+ const room = await makeRoom({ objects: { crate: [3, 0.5, 3, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0] } });
611
+ room.still = true;
612
+ deliver(room, world(room, { rs: 1 }), pageMs);
613
+ run(room, pageMs + 2000);
614
+ room.lastFrame = pageMs - FRAME_MS;
615
+ frame(room);
616
+ pageMs += 1500;
617
+ room.nextTick = pageMs;
618
+ const asks = () => room.outbox.filter((m) => m.k === 'r').length;
619
+ run(room, pageMs + 350);
620
+ assert.equal(asks(), 1, 'the quiet ask went out');
621
+ hide(room);
622
+ deliver(room, world(room, { rs: 1, again: 1 }));
623
+ run(room, pageMs + 100);
624
+ room.socket = false;
625
+ room.objects.crate = [5, 0.5, 1, 0, 0, 0, 1];
626
+ run(room, pageMs + 300);
627
+ room.socket = true;
628
+ run(room, pageMs + 500);
629
+ show(room);
630
+ run(room, pageMs + 300);
631
+ assert.equal(room.system.resume.armed, true, 'the reply from while hidden does not release it');
632
+ assert.equal(asks(), 2, 'the return asks again');
633
+ deliver(room, world(room, { rs: 1, again: 1 }));
634
+ run(room, pageMs + 300);
635
+ assert.equal(room.system.resume.armed, false, 'the new reply releases it');
636
+ check('quiet resync out, hidden again', room, { uncoverBy: 700 });
637
+ }
638
+
639
+ // A current broadcast already queued when the quiet wait runs out releases the
640
+ // cover itself: the quiet ask comes only after a drain that brought nothing.
641
+ {
642
+ const room = await makeRoom({ objects: { crate: [3, 0.5, 3, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0] } });
643
+ room.still = true;
644
+ deliver(room, world(room, { rs: 1 }), pageMs);
645
+ run(room, pageMs + 2000);
646
+ room.lastFrame = pageMs - FRAME_MS;
647
+ frame(room);
648
+ pageMs += 1500;
649
+ room.nextTick = pageMs;
650
+ room.shownAt = pageMs;
651
+ run(room, room.shownAt + 240);
652
+ assert.equal(room.system.resume.armed, true);
653
+ room.players.partner = [1.3, 0, 1.1, 0.2];
654
+ deliver(room, broadcast(room), pageMs);
655
+ pageMs = room.shownAt + 260;
656
+ room.nextTick = pageMs + TICK_MS;
657
+ frame(room);
658
+ assert.equal(room.system.resume.armed, false, 'the queued broadcast released it');
659
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, 0, 'with no resync asked');
660
+ }
661
+
662
+ // A genuine drop in the same still room is not hidden by the quiet ask: the
663
+ // cover stays up and says Reconnecting, no resync is asked over the dead
664
+ // connection, and the WORLD the session sends the connection that comes back
665
+ // releases it.
666
+ {
667
+ const room = await makeRoom({ objects: { crate: [3, 0.5, 3, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0] } });
668
+ room.still = true;
669
+ deliver(room, world(room, { rs: 1 }), pageMs);
670
+ run(room, pageMs + 2000);
671
+ room.shownAt = pageMs;
672
+ room.socket = false;
673
+ room.state = 'reconnecting';
674
+ run(room, pageMs + 3500);
675
+ assert.equal(room.system.resume.armed, true, 'a drop arms the gate');
676
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, 0, 'no resync over a dropped connection');
677
+ assert.equal(globalThis.__cover, 'Reconnecting…', 'a drop past the quiet start says Reconnecting');
678
+ reconnect(room);
679
+ run(room, pageMs + 1000);
680
+ assert.equal(room.system.resume.armed, true, 'the connection back is not enough');
681
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, 0, 'nor is it asked for a resync');
682
+ deliver(room, world(room, { rs: 1 }));
683
+ run(room, pageMs + 300);
684
+ assert.equal(room.system.resume.armed, false, 'the WORLD after the drop releases it');
685
+ check('3.5 s drop in a still room', room, { uncoverBy: 3500 + 1000 + 300 });
686
+ }
687
+
688
+ // The same stall in a room that moves releases on its next broadcast, with no
689
+ // resync asked for.
690
+ {
691
+ const room = await makeRoom({ objects: { crate: [3, 0.5, 3, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0] } });
692
+ room.still = true;
693
+ deliver(room, world(room, { rs: 1 }), pageMs);
694
+ run(room, pageMs + 2000);
695
+ room.lastFrame = pageMs - FRAME_MS;
696
+ frame(room);
697
+ pageMs += 1500;
698
+ room.nextTick = pageMs;
699
+ room.shownAt = pageMs;
700
+ room.players.partner = [1.4, 0, 1.2, 0.3];
701
+ run(room, pageMs + 600);
702
+ assert.equal(room.system.resume.armed, false);
703
+ assert.equal(room.outbox.filter((m) => m.k === 'r').length, 0, 'a moving room needs no resync');
704
+ check('1.5 s frame stall in a moving room', room, { uncoverBy: 200 });
705
+ }
706
+
575
707
  // A dropped connection that comes back with ordinary broadcasts and no WORLD
576
708
  // (a session from before the kept-body WORLD) is never uncovered on them, since
577
709
  // they say nothing of what moved while it was gone; the wait gives up instead.
@@ -36,6 +36,45 @@ assert.equal(Gate.unanswered(gate, 30000, limit), false, 'a natural drop needs n
36
36
  Gate.noteConnection(gate, true, 30000);
37
37
  assert.equal(Gate.unanswered(gate, 31000, limit), false, 'nor does that drop returning');
38
38
 
39
+ // A short away whose page has been shown RESYNC_QUIET_MS since it last hid,
40
+ // with nothing current (a still room sends no broadcast), is asked for its
41
+ // resync then; one not shown yet is not, nor one whose connection dropped (a
42
+ // WORLD comes anyway). Hidden time does not count toward the quiet wait.
43
+ {
44
+ const quiet = Gate.makeGate();
45
+ Gate.arm(quiet, 1000, 0);
46
+ assert.equal(Gate.askQuiet(quiet, 2000), false, 'not before the page is shown');
47
+ assert.equal(Gate.waited(quiet, 2500, true), false);
48
+ assert.equal(quiet.visibleAt, 2500);
49
+ Gate.suspendReply(quiet, 2590);
50
+ assert.equal(quiet.visibleAt, null, 'a hide ends the showing');
51
+ assert.equal(Gate.askQuiet(quiet, 3100), false, 'hidden time does not count');
52
+ Gate.waited(quiet, 3100, true);
53
+ assert.equal(Gate.askQuiet(quiet, 3100 + Gate.RESYNC_QUIET_MS - 1), false);
54
+ assert.equal(Gate.ask(quiet, 3100 + Gate.RESYNC_QUIET_MS), false, 'the pre-drain ask leaves a short away alone');
55
+ assert.equal(Gate.askQuiet(quiet, 3100 + Gate.RESYNC_QUIET_MS), true, 'a quiet return asks early');
56
+ assert.equal(quiet.replyAfter, 3100 + Gate.RESYNC_QUIET_MS);
57
+ assert.equal(Gate.askQuiet(quiet, 9000), false, 'once per showing');
58
+ assert.equal(Gate.ask(quiet, 9000), false, 'and not again before the drain');
59
+ // Only a WORLD after the latest request answers it.
60
+ assert.equal(Gate.current(quiet, { k: 'w', localMs: 3300 }), false, 'a WORLD from before the request');
61
+ assert.equal(Gate.current(quiet, { k: 'w', localMs: 3400 }), true);
62
+ assert.equal(Gate.current(quiet, { k: 's', t: 1e9, localMs: 3400 }), false, 'no broadcast once asked');
63
+ // Hidden with the request out: the return asks again, and only that reply counts.
64
+ Gate.suspendReply(quiet, 3500);
65
+ assert.equal(quiet.reask, true);
66
+ assert.equal(Gate.ask(quiet, 4000), true, 'the return asks again');
67
+ assert.equal(Gate.ask(quiet, 4100), false, 'once');
68
+ assert.equal(Gate.current(quiet, { k: 'w', localMs: 3600 }), false, 'a reply that came while hidden');
69
+ assert.equal(Gate.current(quiet, { k: 'w', localMs: 4050 }), true, 'the new reply');
70
+ const dropped = Gate.makeGate();
71
+ Gate.arm(dropped, 1000, 0);
72
+ Gate.waited(dropped, 1500, true);
73
+ Gate.noteConnection(dropped, false, 1600);
74
+ assert.equal(Gate.askQuiet(dropped, 9000), false, 'a dropped connection is never asked');
75
+ assert.equal(Gate.ask(dropped, 9000), false);
76
+ }
77
+
39
78
  // The real transport wrapper, with only SDK acquisition replaced. Calling a
40
79
  // method on the connection must preserve its receiver; old SDKs have no method.
41
80
  register(`data:text/javascript,${encodeURIComponent(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.254",
3
+ "version": "0.4.256",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"