ugly-game 0.7.0 → 0.7.1
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
|
@@ -30,6 +30,9 @@ export interface SimHostOpts<State, Input> {
|
|
|
30
30
|
maxCatchUpFrames?: number;
|
|
31
31
|
net?: NetAdapter;
|
|
32
32
|
coop?: CoopOpts;
|
|
33
|
+
/** Extra params forwarded verbatim in the worker `init` message — e.g. a map size a worker rebuilds its Layout
|
|
34
|
+
* from. Must be structured-cloneable. */
|
|
35
|
+
initParams?: Record<string, unknown>;
|
|
33
36
|
}
|
|
34
37
|
export interface SimHost<State, Input> {
|
|
35
38
|
readonly state: State;
|
package/dist/loop/simHost.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Layout } from './layout';
|
|
2
|
+
import { type ControlView } from './controlBlock';
|
|
2
3
|
import { type SimHostSim } from './simCore';
|
|
3
4
|
export interface SimWorkerConfig<S, I> {
|
|
4
5
|
sim: SimHostSim<S, I>;
|
|
5
|
-
layout: Layout<S
|
|
6
|
+
layout: Layout<S> | ((init: Record<string, unknown>) => Layout<S>);
|
|
6
7
|
tickOf: (s: S) => number;
|
|
8
|
+
mirror?: (s: S, ctl: ControlView<string>) => void;
|
|
7
9
|
}
|
|
8
10
|
export declare function runSimWorker<S, I>(cfg: SimWorkerConfig<S, I>): void;
|
|
@@ -53,6 +53,7 @@ export function runSimWorker(cfg) {
|
|
|
53
53
|
}
|
|
54
54
|
if (stepped > 0) {
|
|
55
55
|
ctl.tick = cfg.tickOf(state);
|
|
56
|
+
cfg.mirror?.(state, ctl); // publish worker-owned scalars for the main thread
|
|
56
57
|
ctx.postMessage({
|
|
57
58
|
t: 'hash',
|
|
58
59
|
hash: cfg.sim.hash(state),
|
|
@@ -65,7 +66,8 @@ export function runSimWorker(cfg) {
|
|
|
65
66
|
ctx.onmessage = (e) => {
|
|
66
67
|
const m = e.data;
|
|
67
68
|
if (m.t === 'init') {
|
|
68
|
-
|
|
69
|
+
const layout = typeof cfg.layout === 'function' ? cfg.layout(m) : cfg.layout;
|
|
70
|
+
state = layout.attach(m.dataBuf);
|
|
69
71
|
ctl = createControlView(m.ctlBuf, m.scalars ?? []);
|
|
70
72
|
fps = m.simFps ?? 60;
|
|
71
73
|
coop = !!m.coop;
|