ugly-game 0.7.5 → 0.7.6
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.
- package/dist/loop/simCore.js +18 -10
- package/dist/loop/simHost.js +1 -1
- package/package.json +1 -1
package/dist/loop/simCore.js
CHANGED
|
@@ -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 =
|
|
13
|
-
|
|
14
|
-
a
|
|
15
|
-
opts.ctl.
|
|
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,17 @@ 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).
|
|
57
63
|
let budget = opts.ctl.takeStepBudget();
|
|
58
64
|
while (budget-- > 0 && stepped < maxCatch)
|
|
59
65
|
stepOnce();
|
|
60
|
-
// Then chase the target.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
// Then chase the target — but only while PLAYING. Pausing freezes the sim without touching the queue or budget.
|
|
67
|
+
if (opts.ctl.playing) {
|
|
68
|
+
const target = opts.ctl.targetTick;
|
|
69
|
+
while (opts.tickOf(opts.state) < target && stepped < maxCatch)
|
|
70
|
+
stepOnce();
|
|
71
|
+
}
|
|
64
72
|
return stepped;
|
|
65
73
|
}
|
|
66
74
|
export function fixedStepBatch(opts, acc) {
|
package/dist/loop/simHost.js
CHANGED
|
@@ -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) => {
|