ugly-game 0.7.3 → 0.7.4
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.
|
@@ -20,5 +20,6 @@ export interface SimWorkerConfig<S, I> {
|
|
|
20
20
|
mirror?: (s: S, ctl: ControlView<string>) => void;
|
|
21
21
|
beforeTick?: (due: Stamped<I>[], state: S) => void;
|
|
22
22
|
onMessage?: (m: Record<string, unknown>, ctx: SimWorkerContext<S>) => void;
|
|
23
|
+
onReinit?: (ctx: SimWorkerContext<S>) => void;
|
|
23
24
|
}
|
|
24
25
|
export declare function runSimWorker<S, I>(cfg: SimWorkerConfig<S, I>): void;
|
|
@@ -3,6 +3,9 @@ import { soloStepBatch, coopStepBatch, } from './simCore';
|
|
|
3
3
|
import { CommandQueue } from './commandQueue';
|
|
4
4
|
export function runSimWorker(cfg) {
|
|
5
5
|
const ctx = globalThis;
|
|
6
|
+
const post = (msg) => {
|
|
7
|
+
ctx.postMessage(msg);
|
|
8
|
+
};
|
|
6
9
|
const queue = new CommandQueue();
|
|
7
10
|
let state = null;
|
|
8
11
|
let ctl = null;
|
|
@@ -98,6 +101,8 @@ export function runSimWorker(cfg) {
|
|
|
98
101
|
queue.clear();
|
|
99
102
|
lastRef.t = clock.now();
|
|
100
103
|
acc = 0;
|
|
104
|
+
if (ctl)
|
|
105
|
+
cfg.onReinit?.({ state, ctl, post });
|
|
101
106
|
}
|
|
102
107
|
else if (m.t === 'cmd') {
|
|
103
108
|
queue.push(m.s);
|
|
@@ -108,13 +113,7 @@ export function runSimWorker(cfg) {
|
|
|
108
113
|
}
|
|
109
114
|
else if (state && ctl) {
|
|
110
115
|
// A message this runner doesn't own — hand it to the game (diagnostics requests, etc.).
|
|
111
|
-
cfg.onMessage?.(m, {
|
|
112
|
-
state,
|
|
113
|
-
ctl,
|
|
114
|
-
post: (msg) => {
|
|
115
|
-
ctx.postMessage(msg);
|
|
116
|
-
},
|
|
117
|
-
});
|
|
116
|
+
cfg.onMessage?.(m, { state, ctl, post });
|
|
118
117
|
}
|
|
119
118
|
};
|
|
120
119
|
}
|