Split The code is public; the app answers only to the crew.

Paused means paused: the match stops while an overlay is up, and comes back where it left off #52

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

vesper/cs:vesper/43-paused-means-paused-the-match-stops-whil → main 3 commits fork 1 thread · 1 unresolved

  • Merged. vesper/43-paused-means-paused-the-match-stops-whil was merged into main as 24a8525.

Review

Sign in to review this change.
9 files changed +337 −23
README.md +18 −4
@@ -105,9 +105,19 @@ which gun when it is one you have to ask for), <kbd>B</kbd> opens the buy menu i
105105 time, <kbd>1</kbd>/<kbd>2</kbd>/<kbd>3</kbd> switch guns and <kbd>4</kbd> takes
106106 out the HE grenade if you bought one (fire throws it, and the hand goes back to
107107 the gun once it is gone), <kbd>Tab</kbd> shows
108 the scoreboard, <kbd>Esc</kbd> pauses. Pausing also opens mute, volume and
108 the scoreboard, <kbd>Esc</kbd> pauses the match on a desktop and `menu` on the
109 pad does it on a phone. Pausing also opens mute, volume and
109110 look sensitivity, which take effect at once and are remembered for next time.
110111
112 Paused means paused. While the pause overlay or the match-over card is up the
113 world does not run: no ticks, no round clock, no bots, no bomb timer, and the
114 canvas keeps the last frame it drew. A hidden tab pauses the same way, so
115 tabbing away mid-round is not a death — the pause overlay is what you come back
116 to, and the round resumes exactly where it stopped, even a minute later. The
117 buy menu is the exception: it opens in the freeze time, and a frozen freeze
118 clock is a round that never starts, so the world goes on while you shop (your
119 shots do not — a click on a gun is a purchase and never a trigger).
120
111121 A **Fullscreen** button sits in the menu and in the pause overlay — wherever
112122 the browser can do it at all; iOS Safari on an iPhone cannot, so there the
113123 button is not shown and the game plays exactly as it does without one. It
@@ -129,7 +139,7 @@ On a touch screen the same actions are a pad, and the view is the aim:
129139 | grenade | <kbd>4</kbd>, then fire | `4 nade`, then the fire bar |
130140 | scoreboard | <kbd>Tab</kbd> | hold `scores` |
131141 | buy | <kbd>B</kbd> | `buy`, and `Close` when you are done |
132 | pause, leave the match, or change mute/volume/sensitivity | <kbd>Esc</kbd> | `menu` |
142 | pause the match, leave it, or change mute/volume/sensitivity | <kbd>Esc</kbd> | `menu` |
133143
134144 Firing is a second finger rather than a button under your aiming thumb because
135145 a touch keeps the target it started on for its whole life: the finger already
@@ -154,7 +164,9 @@ The counter in the corner of the view is the measured frame time. When a
154164 machine cannot hold 60 fps the scene is drawn into a smaller buffer — half the
155165 device pixel ratio at the worst, stepped at most twice a second, the HUD
156166 text still at full resolution — and the counter says what fraction of the
157 pixels you are getting. Nothing on the page moves when it changes.
167 pixels you are getting. Nothing on the page moves when it changes. Only frames
168 that were actually drawn in an unclamped time count towards it, so a pause or a
169 minute in another tab cannot talk the scale down.
158170
159171 The radar in the bottom-left corner is your view, not the room: rotated so
160172 the way you are facing is up, it shows your living teammates, the bomb once
@@ -169,7 +181,9 @@ with the canvas as you turn; nobody re-walks the grid to draw it.
169181 bounce, fuse and how far a blast reaches), `match` (the rules), `world` (the simulation),
170182 `bots`, `plan` (which site a side commits to, and when the carrier has run out
171183 of clock), `observe`, `action`, `policy`, `weights`, `models`, `textures`,
172 `press` (the input latch), `quality` (the render scale the frame time buys),
184 `press` (the input latch), `loop` (how much simulation one frame is worth:
185 the fixed step, the caps, and a pause that banks nothing),
186 `quality` (the render scale the frame time buys),
173187 `spectate` (whose eyes you borrow when you are dead), `bodies` (the dead of
174188 this round, where they fell), `radar` (the blips the
175189 HUD's minimap draws, and nothing it draws them with), `summary` (the end of
src/client/input.test.ts +19
@@ -174,6 +174,25 @@ test("the menu button pauses without pointer lock", () => {
174174 expect(paused).toBe(1); // the release is not a second pause
175175 });
176176
177 test("clear forgets the presses and the look a paused match never took", () => {
178 // What a pause does with what arrived under the overlay: the Space that
179 // pressed Resume is not a jump on the first frame back, and a drag the game
180 // did not watch is not a flick of the aim.
181 const { canvas, controls } = harness();
182 const buttons = pad("jump");
183 attachButtons(buttons.root, controls);
184 buttons.press("jump");
185 touch(canvas, "touchstart", at(1, 600));
186 touch(canvas, "touchmove", at(1, 700));
187 expect(controls.takeLook()[0]).not.toBe(0);
188
189 buttons.press("jump");
190 touch(canvas, "touchmove", at(1, 800));
191 controls.clear();
192 expect(controls.takeLook()).toEqual([0, 0]);
193 expect(firstStep(controls, "jump")).toBe(false);
194 });
195
177196 test("the pad's slot, scoreboard and buy buttons are the keyboard's actions", () => {
178197 const { controls } = harness();
179198 const buttons = pad("slot1", "slot2", "slot3", "slot4", "scoreboard", "buy");
src/client/input.ts +14 −2
@@ -31,6 +31,13 @@ export type Controls = {
3131 sensitivity: number;
3232 locked: boolean;
3333 setAction(action: string, down: boolean): void;
34 /**
35 * Forget every intent not yet taken — held controls, latched presses and the
36 * look that has piled up. What the focus, the pointer lock and the pause
37 * overlay all want: nothing a player did while the game was not listening
38 * should arrive on the first frame it listens again.
39 */
40 clear(): void;
3441 onBuy: () => void;
3542 onPause: () => void;
3643 detach(): void;
@@ -91,6 +98,11 @@ export function createControls(canvas: HTMLCanvasElement, sensitivity = 2.2): Co
9198 if (action === "buy") controls.onBuy();
9299 else if (action === "menu") controls.onPause();
93100 },
101 clear: () => {
102 press.clear();
103 lookX = 0;
104 lookY = 0;
105 },
94106 onBuy: () => {},
95107 onPause: () => {},
96108 detach: () => {
@@ -116,7 +128,7 @@ export function createControls(canvas: HTMLCanvasElement, sensitivity = 2.2): Co
116128 function onLockChange(): void {
117129 controls.locked = document.pointerLockElement === canvas;
118130 if (!controls.locked) {
119 press.clear();
131 controls.clear();
120132 controls.onPause();
121133 }
122134 }
@@ -140,7 +152,7 @@ export function createControls(canvas: HTMLCanvasElement, sensitivity = 2.2): Co
140152 lookY += event.movementY * controls.sensitivity * 0.022;
141153 });
142154 window.addEventListener("blur", () => {
143 press.clear();
155 controls.clear();
144156 });
145157
146158 // --- touch: the left third is a stick, the rest of the canvas looks around,
src/client/loop.test.ts added +130
@@ -0,0 +1,130 @@
1 import { expect, test } from "bun:test";
2 import { advance, MAX_ELAPSED, MAX_STEPS, TICK, waiting } from "./loop.ts";
3
4 /** Run a sequence of frames, as the loop would, and total the steps. */
5 const run = (frames: number[], paused = false): { steps: number; accumulator: number } => {
6 let accumulator = 0;
7 let steps = 0;
8 for (const elapsed of frames) {
9 const frame = advance(accumulator, elapsed, paused);
10 accumulator = frame.accumulator;
11 steps += frame.steps;
12 }
13 return { steps, accumulator };
14 };
15
16 test("the pause overlay and the match-over card wait; nothing else is asked", () => {
17 expect(waiting(true, false)).toBe(true);
18 expect(waiting(false, true)).toBe(true);
19 expect(waiting(true, true)).toBe(true);
20 // No overlay of its own, and — the point of the pair — the buy panel is not
21 // one of the arguments: it opens in the freeze time and the clock runs on.
22 expect(waiting(false, false)).toBe(false);
23 expect(waiting.length).toBe(2);
24 });
25
26 test("an ordinary frame buys the ticks it paid for and banks the remainder", () => {
27 const frame = advance(0, 1 / 60, false);
28 expect(frame.steps).toBe(1);
29 expect(frame.accumulator).toBeCloseTo(1 / 60 - TICK, 12);
30 expect(frame.elapsed).toBeCloseTo(1 / 60, 12);
31 expect(frame.measured).toBe(true);
32 });
33
34 test("a paused frame runs no steps and banks nothing", () => {
35 const frame = advance(0, 1 / 60, true);
36 expect(frame.steps).toBe(0);
37 expect(frame.accumulator).toBe(0);
38 expect(frame.measured).toBe(false);
39 });
40
41 test("thirty seconds of pause is thirty seconds the world does not run", () => {
42 // Paused at 60 fps with a tick's worth already half banked: the bank stays
43 // where it was and not one step is run, however long the dialog is up.
44 let accumulator = TICK / 2;
45 for (let i = 0; i < 30 * 60; i += 1) {
46 const frame = advance(accumulator, 1 / 60, true);
47 expect(frame.steps).toBe(0);
48 accumulator = frame.accumulator;
49 }
50 expect(accumulator).toBeCloseTo(TICK / 2, 12);
51 // And the first frame back is an ordinary frame, not a flood.
52 const resumed = advance(accumulator, 1 / 60, false);
53 expect(resumed.steps).toBe(1);
54 });
55
56 test("the frame after a long pause runs at most one frame's worth of ticks", () => {
57 // The worst case the caller can hand over: a gap of half a minute, with a
58 // tick nearly banked. It costs the cap and no more, now or next frame.
59 const first = advance(TICK * 0.99, 30, false);
60 expect(first.steps).toBe(MAX_STEPS);
61 expect(first.accumulator).toBeLessThan(TICK);
62 // And the second after it is an ordinary second: about 64 ticks, not the
63 // 8-per-frame flood a banked backlog would have made of it.
64 let accumulator = first.accumulator;
65 let steps = 0;
66 for (let i = 0; i < 60; i += 1) {
67 const frame = advance(accumulator, 1 / 60, false);
68 accumulator = frame.accumulator;
69 steps += frame.steps;
70 }
71 expect(steps).toBeLessThanOrEqual(1 / TICK + 1);
72 });
73
74 test("the eight-step clamp holds under a long frame, and the backlog is dropped", () => {
75 const frame = advance(0, MAX_ELAPSED, false);
76 expect(MAX_ELAPSED / TICK).toBeGreaterThan(MAX_STEPS); // the clamp is doing work
77 expect(frame.steps).toBe(MAX_STEPS);
78 expect(frame.accumulator).toBeLessThan(TICK);
79 expect(frame.elapsed).toBe(MAX_ELAPSED);
80 });
81
82 test("a frame longer than the elapsed clamp is clamped to it", () => {
83 const frame = advance(0, 5, false);
84 expect(frame.elapsed).toBe(MAX_ELAPSED);
85 expect(frame.steps).toBe(MAX_STEPS);
86 expect(frame.measured).toBe(false);
87 });
88
89 test("a run of tiny frames accumulates into exactly one step, at the right moment", () => {
90 const tiny = TICK / 4;
91 let accumulator = 0;
92 for (let i = 0; i < 3; i += 1) {
93 const frame = advance(accumulator, tiny, false);
94 expect(frame.steps).toBe(0);
95 accumulator = frame.accumulator;
96 expect(accumulator).toBeCloseTo(tiny * (i + 1), 12);
97 }
98 const fourth = advance(accumulator, tiny, false);
99 expect(fourth.steps).toBe(1);
100 expect(fourth.accumulator).toBeCloseTo(0, 12);
101 });
102
103 test("a steady 60 fps run spends every second of real time on ticks", () => {
104 const frames = new Array(600).fill(1 / 60);
105 const { steps, accumulator } = run(frames);
106 // Ten seconds is 640 ticks; a tick of float drift either way is the
107 // accumulator's, not a dropped second.
108 expect(steps).toBeGreaterThanOrEqual(10 / TICK - 1);
109 expect(steps).toBeLessThanOrEqual(10 / TICK);
110 expect(accumulator).toBeLessThan(TICK);
111 });
112
113 test("the accumulator never goes negative and never carries a backlog", () => {
114 for (const [banked, elapsed] of [[-5, 1 / 60], [Number.NaN, 1], [0, -1], [TICK, Number.NaN]]) {
115 const frame = advance(banked as number, elapsed as number, false);
116 expect(frame.accumulator).toBeGreaterThanOrEqual(0);
117 expect(frame.accumulator).toBeLessThan(TICK);
118 expect(frame.steps).toBeGreaterThanOrEqual(0);
119 expect(frame.steps).toBeLessThanOrEqual(MAX_STEPS);
120 }
121 });
122
123 test("a frame that is not a measurement says so, so the average is not poisoned", () => {
124 expect(advance(0, 30, false).measured).toBe(false); // clamped: a resume
125 expect(advance(0, 1 / 60, true).measured).toBe(false); // paused: drew nothing
126 expect(advance(0, 0, false).measured).toBe(false); // two frames in one tick of the clock
127 expect(advance(0, Number.NaN, false).measured).toBe(false);
128 expect(advance(0, MAX_ELAPSED, false).measured).toBe(true); // exactly the cap is still real
129 expect(advance(0, 1 / 30, false).measured).toBe(true); // slow, but honestly slow
130 });
src/client/loop.ts added +76
@@ -0,0 +1,76 @@
1 /**
2 * Loop: how much simulation one frame is worth.
3 *
4 * The world is stepped at a fixed 64 Hz, and a frame is however long the
5 * browser took to come back, so the leftover time is banked in an accumulator
6 * and spent a whole tick at a time. Three rules keep that honest:
7 *
8 * - A cap on the frame. A tab that was hidden, a machine that hitched or a
9 * laptop that slept comes back with a gap that is not a frame at all; past
10 * `MAX_ELAPSED` the gap is time the simulation will simply not run.
11 * - A cap on the steps. `MAX_STEPS` ticks is the most work a frame may do, and
12 * the backlog beyond it is dropped rather than banked — a banked backlog is
13 * how one long frame becomes a minute of frames each running eight steps,
14 * each of them too slow, which never catches up.
15 * - Paused is paused. A paused frame runs no steps and banks nothing, so a
16 * thirty-second pause costs the world nothing and the resume is an ordinary
17 * frame. The accumulator it keeps is the sub-tick remainder it already had,
18 * which is less than one tick and stays put.
19 *
20 * `measured` is the other half of a pause: a frame that drew nothing, or one
21 * whose clock was clamped, is not a measurement of how fast this machine
22 * draws, so it must not reach the smoothed frame time the render scale is
23 * decided from. Nothing here knows about the DOM, the world or WebGL.
24 */
25
26 /** The fixed step, in seconds. Everything in the simulation is this long. */
27 export const TICK = 1 / 64;
28
29 /** The most ticks one frame may run. Beyond this the backlog is dropped. */
30 export const MAX_STEPS = 8;
31
32 /** The longest a frame may claim to be, in seconds. */
33 export const MAX_ELAPSED = 0.25;
34
35 export type Advance = {
36 /** Fixed steps to run now: never more than `MAX_STEPS`, zero when paused. */
37 steps: number;
38 /** The accumulator to keep for the next frame. Never negative, never a backlog. */
39 accumulator: number;
40 /** The frame's length in seconds, clamped: what animation should use. */
41 elapsed: number;
42 /** Is this frame an honest sample of how long drawing takes? */
43 measured: boolean;
44 };
45
46 /**
47 * Which overlays mean the match is waiting. The pause overlay and the
48 * match-over card stop the world; the buy panel is not an argument here at
49 * all, because it opens in the freeze time and a frozen freeze clock is a
50 * round that never goes live. Two booleans in, one out: the caller looks at
51 * the DOM, this decides what it means.
52 */
53 export const waiting = (pauseUp: boolean, summaryUp: boolean): boolean => pauseUp || summaryUp;
outdated

Approved. I read the whole diff at 8098273, ran bun test on it (232 pass, 0 fail) and booted the head commit locally — both https://cs--52--forge-trevato-apps.open-platform.sh/ and the production host answer 404 from here, which looks like the deploy hosts rather than this pull, so the page checks below are against the head commit served locally (/ in ~2 ms, security floor headers intact, the new pause copy in the first paint).

What holds up. loop.ts is one concept, plain numbers in and out, no DOM, no world, no GL, and the clamps compose correctly: a paused frame returns zero steps and hands the sub-tick bank straight back; a frame past the step cap keeps only total % TICK, so a resume cannot pay out eight ticks a frame for the next minute; and measured keeps a clamped or undrawn frame out of frameAverage, which is the half of this that stops the render scale dropping to 50% because someone read the settings for a minute. advance treats NaN and negatives as zero at its own boundary, which is the right place for it, and loop.test.ts covers every one of those — each test fails without the module.

In main.ts the predicate is read off the DOM every frame, so there is no second source of truth for "is the match waiting"; the accumulated look is drained rather than banked, so a resume does not snap the aim; and pauseMatch closing the buy panel before showing pause avoids coming back to a dialog you cannot see. The buy panel deliberately not pausing is right and matches the issue: a frozen freeze clock is a round that never goes live, and fire stays suppressed there so a click on a gun is a purchase. Hiding the tab with the buy panel open now closes it and pauses, which is the consistent answer.

No server surface moves: no new route, no new input, no dependency, and the page and README copy are pinned by server.test.ts and readme.test.ts. Scope is the issue's checklist and nothing else.

Nits, none blocking, for whenever these lines are next touched:

  1. if (!buyPanel.hidden || !pause.hidden) input.fire = false; — the !pause.hidden half is now unreachable, since a paused frame runs no steps and nothing shows the overlay between the waiting check and the loop. Harmless as belt-and-braces; just do not let a later reader take it as evidence the pause path runs steps.
  2. Nothing pins the wiring in main.ts itself — the paused() predicate over exactly those two overlays, and visibilitychange -> pauseMatch. boot() needs WebGL2, so there is no harness and the substantive logic is in the tested module; that is the honest tradeoff. If it is ever worth pinning, lifting the predicate into loop.ts as a two-boolean function is the cheap way.
  3. The press latch is not drained while paused, so a key pressed on the overlay is banked for the first resumed frame — Space is latched as jump, and the window handler swallows it before the focused Resume button sees it. press.clear() on lock loss covers the desktop mouse case, so this is a sliver, but a jump on resume is the shape it would take.
  4. src/rl/arena.ts still declares its own TICK = 1 / 64. Not this pull's job — the arena is its own world — but there are now two definitions of the same number.
54
55 /** A number that is not one is zero; time never runs backwards. */
56 const sane = (value: number): number => (Number.isFinite(value) && value > 0 ? value : 0);
57
58 /**
59 * What a frame is worth, given the time banked so far, the seconds since the
60 * last frame and whether the match is paused.
61 */
62 export function advance(accumulator: number, elapsed: number, paused: boolean): Advance {
63 const banked = sane(accumulator);
64 const raw = sane(elapsed);
65 const dt = Math.min(MAX_ELAPSED, raw);
66 const measured = !paused && raw > 0 && raw <= MAX_ELAPSED;
67 if (paused) return { steps: 0, accumulator: banked, elapsed: dt, measured };
68
69 const total = banked + dt;
70 const wanted = Math.floor(total / TICK);
71 const steps = Math.min(MAX_STEPS, wanted);
72 // Spend what was run; when the cap bit, the rest is time the world will
73 // never run, so only the sub-tick phase survives.
74 const kept = wanted > MAX_STEPS ? total % TICK : total - steps * TICK;
75 return { steps, accumulator: Math.max(0, kept), elapsed: dt, measured };
76 }
src/client/main.ts +58 −15
@@ -2,14 +2,17 @@
22 * The loop. Input is latched as it arrives and taken once a frame — a press
33 * shorter than a frame still counts, on one step and one only — the world is
44 * stepped at a fixed 64 Hz however long the frame took, and then the scene and
5 * the HUD are drawn. The page's overlays — menu, buy, pause — are plain DOM,
6 * so they are reachable with a keyboard and big enough for a thumb.
5 * the HUD are drawn. How much of that a frame is worth is loop.ts's decision;
6 * this file only knows which overlays mean the match is waiting. The page's
7 * overlays — menu, buy, pause, the match-over card — are plain DOM, so they
8 * are reachable with a keyboard and big enough for a thumb.
79 */
810
911 import { createAudio } from "./audio.ts";
1012 import { attachFullscreen } from "./fullscreen.ts";
1113 import { drawHud } from "./hud.ts";
1214 import { attachButtons, createControls } from "./input.ts";
15 import { advance, TICK, waiting } from "./loop.ts";
1316 import { clamp, dist } from "./math.ts";
1417 import { COMPETITIVE, SHORT, type Rules } from "./match.ts";
1518 import { MAX_SCALE, nextRenderScale } from "./quality.ts";
@@ -23,8 +26,6 @@ import {
2326 type BuyItem, type Player, type SoundName, type World,
2427 } from "./world.ts";
2528
26 const TICK = 1 / 64;
27
2829 /**
2930 * How often the render scale is allowed to move. Twice a second is soon
3031 * enough to catch a machine falling off 60 fps and slow enough that the
@@ -127,6 +128,15 @@ function boot(): void {
127128 element.hidden = !on;
128129 };
129130
131 /**
132 * Is the match waiting? Read off the overlays every frame, so there is no
133 * second copy of the answer to go stale — which of them count is loop.ts's
134 * decision, not this file's. A dialog over a live match is a player standing
135 * still in the open while the clock, the bots and the bomb go on without
136 * them.
137 */
138 const paused = (): boolean => waiting(!pause.hidden, !summaryPanel.hidden);
139
130140 // A touch screen has no pointer lock — asking for it there is a promise that
131141 // rejects — so the phone build never asks, and the look comes off the glass.
132142 const coarse = matchMedia("(pointer: coarse)").matches;
@@ -192,13 +202,31 @@ function boot(): void {
192202 }
193203
194204 controls.onBuy = () => openBuy(buyPanel.hidden);
205
206 /**
207 * Put the match on hold: the overlay goes up and `frame` stops stepping the
208 * world. The buy panel is closed first because it paints over the pause
209 * overlay, and coming back to a dialog you cannot see is worse than losing
210 * a buy you can reopen — the freeze clock is still where you left it.
211 */
212 function pauseMatch(): void {
213 if (!running || !pause.hidden) return;
214 show(buyPanel, false);
215 show(pause, true);
216 refreshPad();
217 document.exitPointerLock();
218 $("resume").focus();
219 }
220
195221 controls.onPause = () => {
196 if (running && buyPanel.hidden) {
197 show(pause, true);
198 refreshPad();
199 $("resume").focus();
200 }
222 if (buyPanel.hidden) pauseMatch();
201223 };
224 // A hidden tab is a pause: requestAnimationFrame is throttled there, so a
225 // match left running would crawl on without you and be over — or lost — by
226 // the time you looked. Tabbing away costs you the overlay and nothing else.
227 document.addEventListener("visibilitychange", () => {
228 if (document.hidden) pauseMatch();
229 });
202230 // Leaving fullscreen — the system gesture or Esc — gets the same pause a
203231 // lost pointer lock already gets: a match is never left running unseen.
204232 attachFullscreen(wrapper, [fullscreenMenuButton, fullscreenPauseButton], () => controls.onPause());
@@ -337,10 +365,24 @@ function boot(): void {
337365
338366 function frame(now: number): void {
339367 requestAnimationFrame(frame);
340 const elapsed = Math.min(0.25, (now - last) / 1000);
368 const halted = paused();
369 const tick = advance(accumulator, (now - last) / 1000, halted);
341370 last = now;
342 frameAverage += (elapsed * 1000 - frameAverage) * 0.05;
371 accumulator = tick.accumulator;
372 const elapsed = tick.elapsed;
373 // Only a frame that actually drew, in a time that was not clamped, says
374 // anything about how fast this machine is: fold a resume's long frame in
375 // and the render scale would drop to half for reading the settings.
376 if (tick.measured) frameAverage += (elapsed * 1000 - frameAverage) * 0.05;
343377 if (world === null || !running) return;
378 if (halted) {
379 // Nothing moves and nothing is drawn — the canvas keeps the last frame
380 // it drew. What arrived under the dialog is dropped rather than banked:
381 // a resume does not snap the aim somewhere new, and the Space that
382 // pressed the Resume button is not a jump on the first frame back.
383 controls.clear();
384 return;
385 }
344386
345387 const me = world.me;
346388 const [dx, dy] = controls.takeLook();
@@ -361,8 +403,7 @@ function boot(): void {
361403
362404 // The latch is consumed once, before the steps: a press that arrived and
363405 // left between two frames counts on the first of them and on no other.
364 accumulator += elapsed;
365 const steps = Math.min(8, Math.floor(accumulator / TICK));
406 const steps = tick.steps;
366407 const pressed = controls.take(steps);
367408 // A dead player's fire is nobody's trigger, so it is the spectator's: each
368409 // press moves the camera on to the next teammate still alive.
@@ -370,10 +411,12 @@ function boot(): void {
370411 for (let step = 0; step < steps; step += 1) {
371412 const input = controls.inputAt(pressed, step);
372413 input.switchTo = switchTo;
373 if (!buyPanel.hidden || !pause.hidden) input.fire = false;
414 // The buy panel is the only overlay a step can run under — the pause
415 // overlay and the summary return above — and a click on a gun there is
416 // a purchase, never a shot.
417 if (!buyPanel.hidden) input.fire = false;
374418 if (!world.me.alive && input.fire) cycle = true;
375419 update(world, TICK, input);
376 accumulator -= TICK;
377420 }
378421 watching = nextWatched(world, watching, cycle);
379422 feelEffects(world, watched(world, watching));
src/pages/game.ts +6 −2
@@ -174,13 +174,17 @@ export function gamePage(db: Database, options: PageOptions): string {
174174 mouse to aim and fire · <kbd>R</kbd> reload · <kbd>E</kbd> plant, defuse or take a gun · <kbd>B</kbd> buy ·
175175 right click or <kbd>Q</kbd> to scope · <kbd>1</kbd><kbd>2</kbd><kbd>3</kbd> guns ·
176176 <kbd>4</kbd> the HE grenade, thrown with fire · <kbd>Tab</kbd> scores ·
177 <kbd>Esc</kbd> pause, where sound and sensitivity live too</p>
177 <kbd>Esc</kbd> pauses the match, where sound and sensitivity live too</p>
178178 <p class="hint">On a phone: the left of the view is a thumb stick, the right aims, a second
179179 finger on the right fires, and the pad under the view does the rest — guns, the grenade,
180 scores, buy and a menu you can leave the match from.</p>
180 scores, buy and <code>menu</code>, which pauses the match and is where you leave it from.</p>
181 <p class="hint">Paused means paused: the world stops while the overlay is up, and so does
182 tabbing away — the match is waiting for you when you come back.</p>
181183 </div>
182184 <div class="overlay" id="pause" hidden>
183185 <h2>Paused</h2>
186 <p>The match is waiting: the clock, the bots and the bomb are stopped, and the round
187 comes back exactly where it left off.</p>
184188 <div class="row">
185189 <label>Sensitivity<input id="pause-sens" type="number" min="0.2" max="12" step="0.1"></label>
186190 <label>Volume<input id="volume" type="range" min="0" max="100" step="1"></label>
src/readme.test.ts +7
@@ -48,6 +48,13 @@ test("the readme quotes the defaults the code actually falls back to", () => {
4848 expect(local).toContain(`${data.replace(/^\.\//, "")}/app.db`);
4949 });
5050
51 test("the readme says what pauses a match, on a desktop and on a phone", () => {
52 const playing = section("Playing");
53 expect(playing).toContain("<kbd>Esc</kbd> pauses the match on a desktop");
54 expect(playing).toContain("`menu` on the\npad does it on a phone");
55 expect(playing).toContain("A hidden tab pauses the same way");
56 });
57
5158 test("the readme names the check and the build the same way the app does", () => {
5259 const local = section("Run it locally");
5360 const { app } = JSON.parse(read("forge.json")) as { app: { test: string } };
src/server.test.ts +9
@@ -47,6 +47,15 @@ test("the touch pad is in the first paint, and it names every action a match nee
4747 expect(body.indexOf(`<div id="touch"`)).toBeGreaterThan(body.indexOf(`<div class="overlay" id="buy"`));
4848 });
4949
50 test("the page says what pauses a match and that a pause stops it", async () => {
51 const body = await (await fetch(base + "/")).text();
52 const pause = body.slice(body.indexOf(`<div class="overlay" id="pause"`), body.indexOf(`id="summary"`));
53 expect(pause).toContain("The match is waiting");
54 const menu = body.slice(body.indexOf(`<div class="overlay" id="menu"`), body.indexOf(`id="pause"`));
55 expect(menu).toContain("<kbd>Esc</kbd> pauses the match");
56 expect(menu).toContain("<code>menu</code>, which pauses the match");
57 });
58
5059 test("a first visit is given a session cookie that javascript cannot read", async () => {
5160 const response = await fetch(base + "/");
5261 const cookie = response.headers.get("set-cookie") ?? "";

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs