ugly-game 0.7.4 → 0.7.5
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/simHost.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface CoopOpts {
|
|
|
19
19
|
onNeedSnap?: (from: string) => void;
|
|
20
20
|
onSnapReady?: (from: string) => void;
|
|
21
21
|
onLate?: (n: number) => void;
|
|
22
|
+
/** Whether co-op is active from construction (default true). Pass false for OPT-IN co-op (no ambient socket): the
|
|
23
|
+
* lockstep driver + transport are wired but `ctl.coop` stays false — the game flips it on join/leave, and until
|
|
24
|
+
* then the sim free-runs solo. */
|
|
25
|
+
autoStart?: boolean;
|
|
22
26
|
}
|
|
23
27
|
export interface SimHostOpts<State, Input> {
|
|
24
28
|
layout: Layout<State>;
|
package/dist/loop/simHost.js
CHANGED
|
@@ -80,7 +80,7 @@ export function createSimHost(opts) {
|
|
|
80
80
|
onSnapReady: opts.coop.onSnapReady ?? (() => undefined),
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
|
-
ctl.coop = true;
|
|
83
|
+
ctl.coop = opts.coop.autoStart ?? true; // opt-in co-op leaves this false until the game joins a session
|
|
84
84
|
}
|
|
85
85
|
// ── Per-frame driver ─────────────────────────────────────────
|
|
86
86
|
// Co-op bookkeeping runs on the MAIN thread from the shared state, so the local sample and the value sent to
|
|
@@ -91,7 +91,7 @@ export function createSimHost(opts) {
|
|
|
91
91
|
let acc = 0;
|
|
92
92
|
const hashEvery = opts.coop?.hashEvery ?? 600;
|
|
93
93
|
const drive = (nowMs, doStep) => {
|
|
94
|
-
if (lockstep) {
|
|
94
|
+
if (lockstep && ctl.coop) {
|
|
95
95
|
const tk = worker ? ctl.tick : opts.tickOf(state);
|
|
96
96
|
if (tk % hashEvery === 0 && !sampled.has(tk))
|
|
97
97
|
sampled.set(tk, probe());
|
|
@@ -142,8 +142,8 @@ export function createSimHost(opts) {
|
|
|
142
142
|
},
|
|
143
143
|
available: useWorker,
|
|
144
144
|
send(input) {
|
|
145
|
-
if (lockstep)
|
|
146
|
-
lockstep.send(input); // stamped + forwarded; comes back via onCommand
|
|
145
|
+
if (lockstep && ctl.coop)
|
|
146
|
+
lockstep.send(input); // co-op: stamped + forwarded; comes back via onCommand
|
|
147
147
|
else
|
|
148
148
|
enqueue({ c: input, at: opts.tickOf(state) + 1 }); // solo: apply next tick
|
|
149
149
|
},
|
|
@@ -10,7 +10,6 @@ export function runSimWorker(cfg) {
|
|
|
10
10
|
let state = null;
|
|
11
11
|
let ctl = null;
|
|
12
12
|
let acc = 0;
|
|
13
|
-
let coop = false;
|
|
14
13
|
const clock = { now: () => performance.now() };
|
|
15
14
|
const lastRef = { t: 0 };
|
|
16
15
|
let fps = 60;
|
|
@@ -23,7 +22,9 @@ export function runSimWorker(cfg) {
|
|
|
23
22
|
const onLate = (n) => {
|
|
24
23
|
c.addLate(n);
|
|
25
24
|
};
|
|
26
|
-
|
|
25
|
+
// Co-op mode is read from the control block EVERY loop (not fixed at init): a game can join/leave a session
|
|
26
|
+
// at runtime (co-op is opt-in — no ambient socket), toggling ctl.coop from the main thread.
|
|
27
|
+
if (ctl.coop) {
|
|
27
28
|
coopStepBatch({
|
|
28
29
|
sim: cfg.sim,
|
|
29
30
|
state,
|
|
@@ -84,7 +85,8 @@ export function runSimWorker(cfg) {
|
|
|
84
85
|
state = layout.attach(init.dataBuf);
|
|
85
86
|
ctl = createControlView(init.ctlBuf, init.scalars ?? []);
|
|
86
87
|
fps = init.simFps ?? 60;
|
|
87
|
-
coop
|
|
88
|
+
// ctl.coop is set by the main thread (createSimHost) before init and read live each loop — the worker doesn't
|
|
89
|
+
// latch it here (co-op can start/stop mid-session).
|
|
88
90
|
ctl.running = true;
|
|
89
91
|
lastRef.t = clock.now();
|
|
90
92
|
loop();
|