ugly-game 0.7.5 → 0.7.7

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.
@@ -8,11 +8,16 @@ export function soloStepBatch(opts, acc) {
8
8
  const maxCatch = opts.maxCatchUpFrames ?? 6;
9
9
  const now = opts.clock.now();
10
10
  const elapsed = Math.max(0, (now - opts.lastRef.t) / 1000);
11
- opts.lastRef.t = now;
12
- let a = Math.min(acc + elapsed, maxCatch * T);
13
- const frames = Math.floor(a / T);
14
- a -= frames * T;
15
- opts.ctl.targetTick = opts.tickOf(opts.state) + frames;
11
+ opts.lastRef.t = now; // keep the clock base current even while paused, so resuming doesn't spend a huge catch-up
12
+ let a = acc;
13
+ // Only derive a wall-clock target while PLAYING; paused leaves targetTick where it was (coopStepBatch won't chase
14
+ // past it) so a paused solo world holds still. STEP_BUDGET still drains inside coopStepBatch.
15
+ if (opts.ctl.playing) {
16
+ a = Math.min(acc + elapsed, maxCatch * T);
17
+ const frames = Math.floor(a / T);
18
+ a -= frames * T;
19
+ opts.ctl.targetTick = opts.tickOf(opts.state) + frames;
20
+ }
16
21
  const stepped = coopStepBatch({
17
22
  sim: opts.sim,
18
23
  state: opts.state,
@@ -53,14 +58,18 @@ export function coopStepBatch(opts) {
53
58
  opts.sim.tick(opts.state, due.map((d) => d.c));
54
59
  stepped++;
55
60
  };
56
- // STEP_BUDGET burst first (forced, deterministic — independent of the target).
61
+ // STEP_BUDGET burst first (forced, deterministic — independent of the target AND of play/pause, so a harness can
62
+ // advance a paused world). The FULL budget runs (not maxCatch-bounded): it's a caller-chosen finite count, so a
63
+ // replay/harness step(N) advances exactly N — dropping the remainder would make deterministic advance lossy.
57
64
  let budget = opts.ctl.takeStepBudget();
58
- while (budget-- > 0 && stepped < maxCatch)
59
- stepOnce();
60
- // Then chase the target.
61
- const target = opts.ctl.targetTick;
62
- while (opts.tickOf(opts.state) < target && stepped < maxCatch)
65
+ while (budget-- > 0)
63
66
  stepOnce();
67
+ // Then chase the target — but only while PLAYING. Pausing freezes the sim without touching the queue or budget.
68
+ if (opts.ctl.playing) {
69
+ const target = opts.ctl.targetTick;
70
+ while (opts.tickOf(opts.state) < target && stepped < maxCatch)
71
+ stepOnce();
72
+ }
64
73
  return stepped;
65
74
  }
66
75
  export function fixedStepBatch(opts, acc) {
@@ -23,6 +23,7 @@ export function createSimHost(opts) {
23
23
  const probe = () => opts.sim.probeHash ? opts.sim.probeHash(state) : opts.sim.hash(state);
24
24
  const sampled = new Map(); // our probe hash per grid tick (for divergence compare)
25
25
  let lastHash = opts.sim.hash(state);
26
+ ctl.playing = true; // games start playing; the sim honors ctl.playing (pause freezes stepping, STEP_BUDGET aside)
26
27
  // ── Worker path ──────────────────────────────────────────────
27
28
  // request()/reply round-trip: the game's worker `onMessage` answers a diagnostics request by posting a reply that
28
29
  // echoes `rid`; we resolve the matching pending Promise here. Keyed on `rid` alone, so it's oblivious to payload.
@@ -56,7 +57,6 @@ export function createSimHost(opts) {
56
57
  coop: !!opts.coop,
57
58
  ...opts.initParams,
58
59
  });
59
- ctl.playing = true;
60
60
  }
61
61
  // ── Lockstep driver (co-op) — lives on the main thread; feeds commands to the queue (fallback) or worker. ──
62
62
  const enqueue = (s) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {