@moku-labs/game 0.15.148 → 0.15.150
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/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-DCBhp5aM.d.mts → commands-DXSaq2AP.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-BUk0oFzZ.d.mts → define-DoJN_Ctu.d.mts} +2 -2
- package/dist/{headless-ABpROLSJ.d.mts → headless-CO19o31k.d.mts} +1 -1
- package/dist/{index-sltlACR5.d.mts → index-Dgwheaoi.d.mts} +3 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-D97-7253.d.mts → runtime-CX1RTfCg.d.mts} +1 -1
- package/dist/{src-BcZrBZKH.mjs → src-DQdOkAKn.mjs} +613 -106
- package/dist/testing.d.mts +10 -9
- package/dist/testing.mjs +48 -12
- package/dist/{types-CbbpjAo1.d.mts → types-BaarAgv8.d.mts} +1 -1
- package/dist/{types-BZuWxDNn.d.mts → types-BpmdVJso.d.mts} +2 -2
- package/dist/{types-Bxecqli6.d.mts → types-C2-KGQGt.d.mts} +4 -4
- package/dist/{types-D9J6jJ6g.d.mts → types-CbSTnp8T.d.mts} +2 -2
- package/dist/{types-C9L-dSRf.d.mts → types-VJcIdmHU.d.mts} +107 -24
- package/dist/{visual-BmR3GBMY.d.mts → visual-Dw4QXpgC.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/llms.txt +6 -4
- package/package.json +1 -1
|
@@ -3063,6 +3063,41 @@ function createFeaturesApi(ctx) {
|
|
|
3063
3063
|
};
|
|
3064
3064
|
}
|
|
3065
3065
|
//#endregion
|
|
3066
|
+
//#region src/plugins/flow/signal.ts
|
|
3067
|
+
/**
|
|
3068
|
+
* @file flow plugin — the child abort signal that the effects gateway and the `fx` of a node
|
|
3069
|
+
* context both derive. A plugin-root helper: the `fx` and `runner` modules may not import each
|
|
3070
|
+
* other's run-time code, and both need this one.
|
|
3071
|
+
*/
|
|
3072
|
+
/**
|
|
3073
|
+
* Derives a signal that ends with its parent or earlier on its own: a child of the node's signal
|
|
3074
|
+
* that the gateway, or the `fx` of a node context, can end by itself. The parent's abort reaches
|
|
3075
|
+
* the child with its reason; what the child does never reaches the parent. The forwarding
|
|
3076
|
+
* listener is dropped with the child, so a node that shows many popups leaves nothing behind on
|
|
3077
|
+
* its signal once they ended.
|
|
3078
|
+
*
|
|
3079
|
+
* @param signal - The parent signal, the node's or one derived from it.
|
|
3080
|
+
* @returns The controller of the child signal.
|
|
3081
|
+
* @example
|
|
3082
|
+
* ```ts
|
|
3083
|
+
* childOf(AbortSignal.abort("restore")).signal.reason; // "restore": born aborted, like its parent
|
|
3084
|
+
* ```
|
|
3085
|
+
*/
|
|
3086
|
+
function childOf$1(signal) {
|
|
3087
|
+
const child = new AbortController();
|
|
3088
|
+
if (signal.aborted) {
|
|
3089
|
+
child.abort(signal.reason);
|
|
3090
|
+
return child;
|
|
3091
|
+
}
|
|
3092
|
+
signal.addEventListener("abort", () => {
|
|
3093
|
+
child.abort(signal.reason);
|
|
3094
|
+
}, {
|
|
3095
|
+
once: true,
|
|
3096
|
+
signal: child.signal
|
|
3097
|
+
});
|
|
3098
|
+
return child;
|
|
3099
|
+
}
|
|
3100
|
+
//#endregion
|
|
3066
3101
|
//#region src/plugins/flow/fx/api.ts
|
|
3067
3102
|
/**
|
|
3068
3103
|
* Turns whatever an effect handler or a hint listener failed with into an error the log takes.
|
|
@@ -3282,29 +3317,6 @@ function enqueue$2(state, work) {
|
|
|
3282
3317
|
});
|
|
3283
3318
|
}
|
|
3284
3319
|
/**
|
|
3285
|
-
* Derives the signal one handler gets: a child of the node's signal that the gateway can end on
|
|
3286
|
-
* its own. The node's abort reaches the child with its reason; what the child does never reaches
|
|
3287
|
-
* the node. The forwarding listener is dropped with the child, so a node that shows many popups
|
|
3288
|
-
* leaves nothing behind on its signal.
|
|
3289
|
-
*
|
|
3290
|
-
* @param signal - The node's abort signal.
|
|
3291
|
-
* @returns The controller of the child signal.
|
|
3292
|
-
*/
|
|
3293
|
-
function childOf$1(signal) {
|
|
3294
|
-
const child = new AbortController();
|
|
3295
|
-
if (signal.aborted) {
|
|
3296
|
-
child.abort(signal.reason);
|
|
3297
|
-
return child;
|
|
3298
|
-
}
|
|
3299
|
-
signal.addEventListener("abort", () => {
|
|
3300
|
-
child.abort(signal.reason);
|
|
3301
|
-
}, {
|
|
3302
|
-
once: true,
|
|
3303
|
-
signal: child.signal
|
|
3304
|
-
});
|
|
3305
|
-
return child;
|
|
3306
|
-
}
|
|
3307
|
-
/**
|
|
3308
3320
|
* Starts the signal of a `guide` handler and records it, so the runner can end every guide where
|
|
3309
3321
|
* it lifts the narrow. A guide the node's abort already ended takes itself off the list.
|
|
3310
3322
|
*
|
|
@@ -5609,19 +5621,96 @@ function refuseStart(descriptor, path) {
|
|
|
5609
5621
|
throw new Error(`[game] fx.start() got the effect "${descriptor.kind}" in the node "${path}", and its answer has to be awaited.\n Write await fx(...) for a descriptor with answers and for a guide.`);
|
|
5610
5622
|
}
|
|
5611
5623
|
/**
|
|
5624
|
+
* Takes one effect off the open list of its run.
|
|
5625
|
+
*
|
|
5626
|
+
* @param open - The open effects of the run.
|
|
5627
|
+
* @param entry - The effect that settled or was closed.
|
|
5628
|
+
*/
|
|
5629
|
+
function forget(open, entry) {
|
|
5630
|
+
const index = open.indexOf(entry);
|
|
5631
|
+
if (index !== -1) open.splice(index, 1);
|
|
5632
|
+
}
|
|
5633
|
+
/**
|
|
5634
|
+
* Ends one open effect of a node run and takes it off the list: its handler's signal is aborted (a
|
|
5635
|
+
* popup unmounts), the gate closes for a descriptor with `answers`, and the promise the body got
|
|
5636
|
+
* resolves `undefined`. Only an effect found on the list is handed here, so nothing is closed twice.
|
|
5637
|
+
*
|
|
5638
|
+
* @param modules - Injected sibling APIs.
|
|
5639
|
+
* @param open - The open effects of the run.
|
|
5640
|
+
* @param entry - The effect to end, on the list.
|
|
5641
|
+
*/
|
|
5642
|
+
function closeOne(modules, open, entry) {
|
|
5643
|
+
forget(open, entry);
|
|
5644
|
+
entry.controller.abort();
|
|
5645
|
+
if (entry.descriptor.answers !== void 0) modules.gate.close();
|
|
5646
|
+
entry.end();
|
|
5647
|
+
}
|
|
5648
|
+
/**
|
|
5649
|
+
* Closes the popups a body or a `recover` left open, in the order they were started, when it
|
|
5650
|
+
* settled with a result or a failure. Other awaited effects run on. Nothing is closed after the
|
|
5651
|
+
* abort of the node: the abort already reached every effect, the runner shut the gate, and a body
|
|
5652
|
+
* that settles late must not close the gate of the node the loop entered after it.
|
|
5653
|
+
*
|
|
5654
|
+
* @param modules - Injected sibling APIs.
|
|
5655
|
+
* @param signal - The abort signal of the run.
|
|
5656
|
+
* @param open - The open effects of the run.
|
|
5657
|
+
*/
|
|
5658
|
+
function closePopups(modules, signal, open) {
|
|
5659
|
+
if (signal.aborted) return;
|
|
5660
|
+
const popups = open.filter((entry) => entry.descriptor.answers !== void 0);
|
|
5661
|
+
for (const entry of popups) closeOne(modules, open, entry);
|
|
5662
|
+
}
|
|
5663
|
+
/**
|
|
5664
|
+
* Runs one awaited effect with a signal of its own, a child of the run's, and keeps it on the open
|
|
5665
|
+
* list until it settles, so `fx.cancel` and the body's return can end it early.
|
|
5666
|
+
*
|
|
5667
|
+
* @param modules - Injected sibling APIs.
|
|
5668
|
+
* @param step - The run in progress: its abort signal.
|
|
5669
|
+
* @param open - The open effects of the run.
|
|
5670
|
+
* @param descriptor - The descriptor the body awaits.
|
|
5671
|
+
* @returns The promise the body gets: the effect's value, or `undefined` once it was ended early.
|
|
5672
|
+
*/
|
|
5673
|
+
function track(modules, step, open, descriptor) {
|
|
5674
|
+
const controller = childOf$1(step.signal);
|
|
5675
|
+
const value = modules.fx.run(descriptor, controller.signal);
|
|
5676
|
+
const entry = {
|
|
5677
|
+
effect: value,
|
|
5678
|
+
descriptor,
|
|
5679
|
+
controller,
|
|
5680
|
+
end: noop
|
|
5681
|
+
};
|
|
5682
|
+
entry.effect = new Promise((resolve, reject) => {
|
|
5683
|
+
entry.end = () => {
|
|
5684
|
+
resolve(void 0);
|
|
5685
|
+
};
|
|
5686
|
+
value.then((result) => {
|
|
5687
|
+
forget(open, entry);
|
|
5688
|
+
resolve(result);
|
|
5689
|
+
}, (error) => {
|
|
5690
|
+
forget(open, entry);
|
|
5691
|
+
reject(error);
|
|
5692
|
+
});
|
|
5693
|
+
});
|
|
5694
|
+
open.push(entry);
|
|
5695
|
+
return entry.effect;
|
|
5696
|
+
}
|
|
5697
|
+
/**
|
|
5612
5698
|
* Builds the `fx` of a node context: awaited effects by call, effects the body does not wait for
|
|
5613
|
-
* by `start`, cosmetic hints by `emit
|
|
5614
|
-
*
|
|
5615
|
-
*
|
|
5616
|
-
*
|
|
5617
|
-
*
|
|
5699
|
+
* by `start`, cosmetic hints by `emit`, an awaited effect ended early by `cancel`. Each awaited
|
|
5700
|
+
* effect but a `guide` gets a child of the run's signal and stays on `open` until it settles; the
|
|
5701
|
+
* caller closes the popups left there with `closePopups` when the body settles. A `guide` narrows
|
|
5702
|
+
* the gate while it runs; the runner lifts the narrow when the node is left. A body that was
|
|
5703
|
+
* aborted keeps running, since the loop only stops waiting for it, so its `fx` starts and ends
|
|
5704
|
+
* nothing any more: the gate and the narrow belong to the node the loop entered after it. The
|
|
5705
|
+
* `recover` of a rest node gets the same `fx`, bound to the signal of its recovery.
|
|
5618
5706
|
*
|
|
5619
5707
|
* @param modules - Injected sibling APIs.
|
|
5620
5708
|
* @param step - The run in progress: its abort signal, how it tells a walk that a gate opened, and
|
|
5621
5709
|
* the path and the log a failed `start` is reported with.
|
|
5710
|
+
* @param open - The open effects of the run, filled and emptied by this `fx`.
|
|
5622
5711
|
* @returns The effects gateway of one node run.
|
|
5623
5712
|
*/
|
|
5624
|
-
function nodeFx(modules, step) {
|
|
5713
|
+
function nodeFx(modules, step, open = []) {
|
|
5625
5714
|
/**
|
|
5626
5715
|
* Awaits one effect. After the abort of the node it rejects with the abort reason instead.
|
|
5627
5716
|
*
|
|
@@ -5634,11 +5723,24 @@ function nodeFx(modules, step) {
|
|
|
5634
5723
|
const allow = guideAnswer(descriptor.payload, "allow");
|
|
5635
5724
|
if (allow !== void 0) modules.gate.narrow(allow, guideAnswer(descriptor.payload, "blocked"));
|
|
5636
5725
|
}
|
|
5637
|
-
const value = modules.fx.run(descriptor, step.signal);
|
|
5726
|
+
const value = descriptor.kind === "guide" ? modules.fx.run(descriptor, step.signal) : track(modules, step, open, descriptor);
|
|
5638
5727
|
if (descriptor.answers !== void 0) step.gateOpened();
|
|
5639
5728
|
return value;
|
|
5640
5729
|
};
|
|
5641
5730
|
/**
|
|
5731
|
+
* Ends one open effect of this run early. After the abort of the node nothing is ended.
|
|
5732
|
+
*
|
|
5733
|
+
* @param effect - A promise `run` returned.
|
|
5734
|
+
* @returns True when the effect was open and is ended now.
|
|
5735
|
+
*/
|
|
5736
|
+
const cancel = (effect) => {
|
|
5737
|
+
if (step.signal.aborted) return false;
|
|
5738
|
+
const entry = open.find((item) => item.effect === effect);
|
|
5739
|
+
if (entry === void 0) return false;
|
|
5740
|
+
closeOne(modules, open, entry);
|
|
5741
|
+
return true;
|
|
5742
|
+
};
|
|
5743
|
+
/**
|
|
5642
5744
|
* Starts one effect and does not wait for it. It takes the path of an awaited effect, so the
|
|
5643
5745
|
* mode and the node's signal apply; only its end is nobody's wait. A failure is the handler's:
|
|
5644
5746
|
* it goes to the log and never to the node. A `cosmetic` descriptor does not get that far: the
|
|
@@ -5670,7 +5772,8 @@ function nodeFx(modules, step) {
|
|
|
5670
5772
|
emit: (item) => {
|
|
5671
5773
|
modules.fx.buffer(item);
|
|
5672
5774
|
},
|
|
5673
|
-
start
|
|
5775
|
+
start,
|
|
5776
|
+
cancel
|
|
5674
5777
|
});
|
|
5675
5778
|
}
|
|
5676
5779
|
/**
|
|
@@ -5678,15 +5781,16 @@ function nodeFx(modules, step) {
|
|
|
5678
5781
|
*
|
|
5679
5782
|
* @param modules - Injected sibling APIs.
|
|
5680
5783
|
* @param step - The node run in progress.
|
|
5784
|
+
* @param open - The open effects of the run, for its `fx`.
|
|
5681
5785
|
* @returns The node context.
|
|
5682
5786
|
*/
|
|
5683
|
-
function nodeContext(modules, step) {
|
|
5787
|
+
function nodeContext(modules, step, open) {
|
|
5684
5788
|
return {
|
|
5685
5789
|
input: step.input,
|
|
5686
5790
|
player: step.transaction.player,
|
|
5687
5791
|
session: step.transaction.session,
|
|
5688
5792
|
rng: step.transaction.rng,
|
|
5689
|
-
fx: nodeFx(modules, step),
|
|
5793
|
+
fx: nodeFx(modules, step, open),
|
|
5690
5794
|
out: createOut(step.node.outcomes),
|
|
5691
5795
|
signal: step.signal,
|
|
5692
5796
|
now: step.now
|
|
@@ -5814,14 +5918,16 @@ function abortOutcome(signal) {
|
|
|
5814
5918
|
}
|
|
5815
5919
|
/**
|
|
5816
5920
|
* Calls the body of a node and turns what it does into an outcome. Nothing is thrown out of here.
|
|
5921
|
+
* A body that settles closes the popups it left open before the loop moves on.
|
|
5817
5922
|
*
|
|
5818
5923
|
* @param modules - Injected sibling APIs.
|
|
5819
5924
|
* @param step - The node run in progress.
|
|
5820
5925
|
* @returns The result, the abort or the failure.
|
|
5821
5926
|
*/
|
|
5822
5927
|
async function callBody(modules, step) {
|
|
5928
|
+
const open = [];
|
|
5823
5929
|
try {
|
|
5824
|
-
const result = await step.node.run?.(nodeContext(modules, step));
|
|
5930
|
+
const result = await step.node.run?.(nodeContext(modules, step, open));
|
|
5825
5931
|
if (step.signal.aborted) return {
|
|
5826
5932
|
kind: "aborted",
|
|
5827
5933
|
reason: abortReason(step.signal)
|
|
@@ -5843,6 +5949,8 @@ async function callBody(modules, step) {
|
|
|
5843
5949
|
kind: "failed",
|
|
5844
5950
|
error
|
|
5845
5951
|
};
|
|
5952
|
+
} finally {
|
|
5953
|
+
closePopups(modules, step.signal, open);
|
|
5846
5954
|
}
|
|
5847
5955
|
}
|
|
5848
5956
|
/**
|
|
@@ -6166,29 +6274,31 @@ function takeRecovery(safe, node) {
|
|
|
6166
6274
|
*
|
|
6167
6275
|
* @param modules - Injected sibling APIs.
|
|
6168
6276
|
* @param recovery - The recovery in progress.
|
|
6277
|
+
* @param open - The open effects of the recovery, for its `fx`.
|
|
6169
6278
|
* @returns The recovery context.
|
|
6170
6279
|
*/
|
|
6171
|
-
function recoverContext(modules, recovery) {
|
|
6280
|
+
function recoverContext(modules, recovery, open) {
|
|
6172
6281
|
return {
|
|
6173
6282
|
player: recovery.transaction.player,
|
|
6174
6283
|
session: recovery.transaction.session,
|
|
6175
6284
|
rng: recovery.transaction.rng,
|
|
6176
|
-
fx: nodeFx(modules, recovery),
|
|
6285
|
+
fx: nodeFx(modules, recovery, open),
|
|
6177
6286
|
signal: recovery.signal,
|
|
6178
6287
|
now: recovery.now
|
|
6179
6288
|
};
|
|
6180
6289
|
}
|
|
6181
6290
|
/**
|
|
6182
6291
|
* Calls the `recover` of a node and turns what it does into an outcome. Nothing is thrown out of
|
|
6183
|
-
* here.
|
|
6292
|
+
* here. A `recover` that settles closes the popups it left open, so the gate of its node opens.
|
|
6184
6293
|
*
|
|
6185
6294
|
* @param modules - Injected sibling APIs.
|
|
6186
6295
|
* @param recovery - The recovery in progress.
|
|
6187
6296
|
* @returns That it returned, the abort or the failure.
|
|
6188
6297
|
*/
|
|
6189
6298
|
async function callRecover(modules, recovery) {
|
|
6299
|
+
const open = [];
|
|
6190
6300
|
try {
|
|
6191
|
-
await recovery.node.recover?.(recoverContext(modules, recovery));
|
|
6301
|
+
await recovery.node.recover?.(recoverContext(modules, recovery, open));
|
|
6192
6302
|
if (recovery.signal.aborted) return {
|
|
6193
6303
|
kind: "aborted",
|
|
6194
6304
|
reason: abortReason(recovery.signal)
|
|
@@ -6203,6 +6313,8 @@ async function callRecover(modules, recovery) {
|
|
|
6203
6313
|
kind: "failed",
|
|
6204
6314
|
error
|
|
6205
6315
|
};
|
|
6316
|
+
} finally {
|
|
6317
|
+
closePopups(modules, recovery.signal, open);
|
|
6206
6318
|
}
|
|
6207
6319
|
}
|
|
6208
6320
|
/**
|
|
@@ -11689,8 +11801,8 @@ function dropDeadRest(_pose, entity, rests) {
|
|
|
11689
11801
|
if (sweeping.pctx?.deps.ecs.ownerOf(entity) === void 0) rests.delete(entity);
|
|
11690
11802
|
}
|
|
11691
11803
|
/**
|
|
11692
|
-
* Drops the key of an element whose entity is gone, and its side of the key table
|
|
11693
|
-
* still names that entity.
|
|
11804
|
+
* Drops the key of an element whose entity is gone, and its side of the key table, or of the keys
|
|
11805
|
+
* held elements wait with, when the key still names that entity.
|
|
11694
11806
|
*
|
|
11695
11807
|
* @param place - The projection and key of the element.
|
|
11696
11808
|
* @param entity - Its entity.
|
|
@@ -11700,8 +11812,11 @@ function dropDeadKey(place, entity, keysByEntity) {
|
|
|
11700
11812
|
const pctx = sweeping.pctx;
|
|
11701
11813
|
if (pctx === void 0 || pctx.deps.ecs.ownerOf(entity) !== void 0) return;
|
|
11702
11814
|
keysByEntity.delete(entity);
|
|
11703
|
-
const
|
|
11815
|
+
const state = pctx.ctx.state.projection;
|
|
11816
|
+
const byKey = state.keys.get(place.projection);
|
|
11704
11817
|
if (byKey?.get(place.key) === entity) byKey.delete(place.key);
|
|
11818
|
+
const waiting = state.heldKeys.size > 0 ? state.heldKeys.get(place.projection) : void 0;
|
|
11819
|
+
if (waiting?.get(place.key) === entity) waiting.delete(place.key);
|
|
11705
11820
|
}
|
|
11706
11821
|
/**
|
|
11707
11822
|
* Drops what the projection keeps about an element whose entity is gone: the rest pose `setRest`
|
|
@@ -12305,7 +12420,9 @@ function ensureWarm(state, spec) {
|
|
|
12305
12420
|
const record = {
|
|
12306
12421
|
name: spec.name,
|
|
12307
12422
|
entities: /* @__PURE__ */ new Set(),
|
|
12308
|
-
phase: "cold"
|
|
12423
|
+
phase: "cold",
|
|
12424
|
+
next: false,
|
|
12425
|
+
waiting: false
|
|
12309
12426
|
};
|
|
12310
12427
|
state.warm.set(spec.name, record);
|
|
12311
12428
|
state.warmList.push(record);
|
|
@@ -12329,8 +12446,9 @@ function heldFor(state, name, key) {
|
|
|
12329
12446
|
}
|
|
12330
12447
|
/**
|
|
12331
12448
|
* Despawns what a record holds: its view, with the cause `"discard"` and no motion, then every entity `adopt` marked
|
|
12332
|
-
* for it that is still there. The removal hooks still see them held.
|
|
12333
|
-
* alone. The record keeps its phase; the
|
|
12449
|
+
* for it that is still there. The removal hooks still see them held. The keys its elements wait with are forgotten:
|
|
12450
|
+
* the live elements keep theirs. A shown view belongs to `mounted` and is left alone. The record keeps its phase; the
|
|
12451
|
+
* caller sets it.
|
|
12334
12452
|
*
|
|
12335
12453
|
* @param pctx - Domain context of the projection module.
|
|
12336
12454
|
* @param record - The record.
|
|
@@ -12339,6 +12457,7 @@ function dropHeld(pctx, record) {
|
|
|
12339
12457
|
const state = pctx.ctx.state.projection;
|
|
12340
12458
|
const ecs = pctx.deps.ecs;
|
|
12341
12459
|
const view = record.view;
|
|
12460
|
+
if (state.heldKeys.size > 0) state.heldKeys.delete(record.name);
|
|
12342
12461
|
if (view !== void 0 && record.phase !== "shown") {
|
|
12343
12462
|
cancelTracks(pctx, view.entity);
|
|
12344
12463
|
state.byEntity.delete(view.entity);
|
|
@@ -12354,13 +12473,17 @@ function dropHeld(pctx, record) {
|
|
|
12354
12473
|
record.entities.clear();
|
|
12355
12474
|
}
|
|
12356
12475
|
/**
|
|
12357
|
-
* Leaves a record cold: nothing held, no longer in work, and the warm step looks at it
|
|
12476
|
+
* Leaves a record cold: nothing held, no longer in work, no next view, no read waiting, and the warm step looks at it
|
|
12477
|
+
* again.
|
|
12358
12478
|
*
|
|
12359
12479
|
* @param state - The projection branch of the plugin state.
|
|
12360
12480
|
* @param record - The record.
|
|
12361
12481
|
*/
|
|
12362
12482
|
function coolRecord(state, record) {
|
|
12363
12483
|
record.phase = "cold";
|
|
12484
|
+
record.next = false;
|
|
12485
|
+
record.waiting = false;
|
|
12486
|
+
delete record.pending;
|
|
12364
12487
|
delete record.key;
|
|
12365
12488
|
delete record.item;
|
|
12366
12489
|
delete record.view;
|
|
@@ -12424,6 +12547,8 @@ function clearWarm(pctx) {
|
|
|
12424
12547
|
state.warm.clear();
|
|
12425
12548
|
state.warmList.length = 0;
|
|
12426
12549
|
state.warmHeld.clear();
|
|
12550
|
+
state.heldKeys.clear();
|
|
12551
|
+
state.warmLoose = -1;
|
|
12427
12552
|
state.held.clear();
|
|
12428
12553
|
state.showing.length = 0;
|
|
12429
12554
|
state.fed.clear();
|
|
@@ -12433,35 +12558,122 @@ function clearWarm(pctx) {
|
|
|
12433
12558
|
}
|
|
12434
12559
|
/**
|
|
12435
12560
|
* Marks an entity another plugin spawned for the record in work, so `isBuilding` answers for it and a discard
|
|
12436
|
-
* despawns it with the view.
|
|
12561
|
+
* despawns it with the view. While no record is in work it only remembers the entity: ui adopts an element of a root
|
|
12562
|
+
* held warm right after its spawn, then registers its key, and `holdRegistered` reads it there.
|
|
12437
12563
|
*
|
|
12438
12564
|
* @param state - The projection branch of the plugin state.
|
|
12439
12565
|
* @param entity - The entity.
|
|
12440
12566
|
*/
|
|
12441
12567
|
function adoptWarm(state, entity) {
|
|
12442
12568
|
const active = state.warmActive;
|
|
12443
|
-
if (active === void 0)
|
|
12569
|
+
if (active === void 0) {
|
|
12570
|
+
state.warmLoose = entity;
|
|
12571
|
+
return;
|
|
12572
|
+
}
|
|
12444
12573
|
active.entities.add(entity);
|
|
12445
12574
|
state.warmHeld.add(entity);
|
|
12446
12575
|
}
|
|
12447
12576
|
/**
|
|
12448
|
-
*
|
|
12449
|
-
*
|
|
12450
|
-
*
|
|
12451
|
-
*
|
|
12452
|
-
*
|
|
12577
|
+
* Tells whether an element whose key a plugin registers under a projection belongs to a held root, and holds it with
|
|
12578
|
+
* the record when it does. An element `adopt` marked for the record in work is held already. One made after the record
|
|
12579
|
+
* was ready (a row a windowed list ranges in after the solve) is held when the projection's record holds a view not
|
|
12580
|
+
* shown and either `adopt` was handed the element since its spawn (ui adopts every element of a root held warm), or
|
|
12581
|
+
* the projection shows no live view, so it can only be one of the held root's. It joins the record as an adopted one:
|
|
12582
|
+
* `isBuilding` answers true, `entityOf` nothing, until the open; a discard despawns it with the view. An element of a
|
|
12583
|
+
* live view of the projection (the dim of a gated window) is live.
|
|
12453
12584
|
*
|
|
12454
12585
|
* @param state - The projection branch of the plugin state.
|
|
12455
12586
|
* @param projection - The projection the key is registered under.
|
|
12456
12587
|
* @param entity - The element.
|
|
12588
|
+
* @returns True when the element is held.
|
|
12457
12589
|
*/
|
|
12458
12590
|
function holdRegistered(state, projection, entity) {
|
|
12459
|
-
|
|
12591
|
+
const loose = state.warmLoose === entity;
|
|
12592
|
+
if (loose) state.warmLoose = -1;
|
|
12593
|
+
if (state.warm.size === 0) return false;
|
|
12594
|
+
if (state.warmHeld.has(entity)) return true;
|
|
12460
12595
|
const record = state.warm.get(projection);
|
|
12461
|
-
if (record?.view === void 0 || record.phase === "shown") return;
|
|
12462
|
-
if (state.mounted.get(projection)?.live.size !== 0) return;
|
|
12596
|
+
if (record?.view === void 0 || record.phase === "shown") return false;
|
|
12597
|
+
if (!loose && state.mounted.get(projection)?.live.size !== 0) return false;
|
|
12463
12598
|
record.entities.add(entity);
|
|
12464
12599
|
state.warmHeld.add(entity);
|
|
12600
|
+
return true;
|
|
12601
|
+
}
|
|
12602
|
+
/**
|
|
12603
|
+
* Creates the table of waiting keys of one projection with its first key. Its own function, because lint rule L5
|
|
12604
|
+
* refuses a collection built inside an exported declaration.
|
|
12605
|
+
*
|
|
12606
|
+
* @param key - The first key.
|
|
12607
|
+
* @param entity - The element that waits with it.
|
|
12608
|
+
* @returns The table.
|
|
12609
|
+
*/
|
|
12610
|
+
function keyTable(key, entity) {
|
|
12611
|
+
return /* @__PURE__ */ new Map([[key, entity]]);
|
|
12612
|
+
}
|
|
12613
|
+
/**
|
|
12614
|
+
* Lets the key of a held element wait while a live element of its projection holds the same key: the live one keeps
|
|
12615
|
+
* it in `keys`, so `entityOf` answers the element on the screen until the show of the record.
|
|
12616
|
+
*
|
|
12617
|
+
* @param state - The projection branch of the plugin state.
|
|
12618
|
+
* @param projection - The projection the key is registered under.
|
|
12619
|
+
* @param key - The key.
|
|
12620
|
+
* @param entity - The held element.
|
|
12621
|
+
* @returns True when the key waits; false when the key is free, and the element takes it as before.
|
|
12622
|
+
*/
|
|
12623
|
+
function waitHeldKey(state, projection, key, entity) {
|
|
12624
|
+
const holder = state.keys.get(projection)?.get(key);
|
|
12625
|
+
if (holder === void 0 || holder === entity || state.warmHeld.has(holder)) return false;
|
|
12626
|
+
const waiting = state.heldKeys.get(projection);
|
|
12627
|
+
if (waiting === void 0) state.heldKeys.set(projection, keyTable(key, entity));
|
|
12628
|
+
else waiting.set(key, entity);
|
|
12629
|
+
return true;
|
|
12630
|
+
}
|
|
12631
|
+
/**
|
|
12632
|
+
* Lets a held element that holds a key wait with it when a live element of its projection registers the same key
|
|
12633
|
+
* (the dim's elements registered after the open view's): the live one takes the key, the held one gets it back at
|
|
12634
|
+
* the show. With nothing held it reads one size.
|
|
12635
|
+
*
|
|
12636
|
+
* @param state - The projection branch of the plugin state.
|
|
12637
|
+
* @param projection - The projection the key is registered under.
|
|
12638
|
+
* @param key - The key the live element registers.
|
|
12639
|
+
*/
|
|
12640
|
+
function yieldHeldKey(state, projection, key) {
|
|
12641
|
+
if (state.warmHeld.size === 0) return;
|
|
12642
|
+
const holder = state.keys.get(projection)?.get(key);
|
|
12643
|
+
if (holder === void 0 || !state.warmHeld.has(holder)) return;
|
|
12644
|
+
const waiting = state.heldKeys.get(projection);
|
|
12645
|
+
if (waiting === void 0) state.heldKeys.set(projection, keyTable(key, holder));
|
|
12646
|
+
else waiting.set(key, holder);
|
|
12647
|
+
}
|
|
12648
|
+
/**
|
|
12649
|
+
* Forgets the waiting key of a held element: its remover was called.
|
|
12650
|
+
*
|
|
12651
|
+
* @param state - The projection branch of the plugin state.
|
|
12652
|
+
* @param projection - The projection the key was registered under.
|
|
12653
|
+
* @param key - The key.
|
|
12654
|
+
* @param entity - The element.
|
|
12655
|
+
*/
|
|
12656
|
+
function dropHeldKey(state, projection, key, entity) {
|
|
12657
|
+
const waiting = state.heldKeys.get(projection);
|
|
12658
|
+
if (waiting?.get(key) === entity) waiting.delete(key);
|
|
12659
|
+
}
|
|
12660
|
+
/**
|
|
12661
|
+
* Gives the waiting keys of a projection's held view their place at its show: each replaces the entry of the live
|
|
12662
|
+
* element that held it, which leaves with the live view it belonged to.
|
|
12663
|
+
*
|
|
12664
|
+
* @param state - The projection branch of the plugin state.
|
|
12665
|
+
* @param name - The projection.
|
|
12666
|
+
*/
|
|
12667
|
+
function releaseHeldKeys(state, name) {
|
|
12668
|
+
const waiting = state.heldKeys.get(name);
|
|
12669
|
+
if (waiting === void 0) return;
|
|
12670
|
+
state.heldKeys.delete(name);
|
|
12671
|
+
const byKey = state.keys.get(name);
|
|
12672
|
+
if (byKey === void 0) {
|
|
12673
|
+
state.keys.set(name, waiting);
|
|
12674
|
+
return;
|
|
12675
|
+
}
|
|
12676
|
+
for (const [key, entity] of waiting) byKey.set(key, entity);
|
|
12465
12677
|
}
|
|
12466
12678
|
/** What the prune's callback reads: set before the walk, so the callback is module-level and a walk makes no closure. */
|
|
12467
12679
|
const pruning = { pctx: void 0 };
|
|
@@ -12506,8 +12718,8 @@ function frameBudget(state) {
|
|
|
12506
12718
|
}
|
|
12507
12719
|
/**
|
|
12508
12720
|
* Shows the held view of a record: it and every entity marked for it stop being held, the view joins the live views
|
|
12509
|
-
* of its projection with the cause of the reconcile,
|
|
12510
|
-
* ui builds the rest of its root in one block.
|
|
12721
|
+
* of its projection with the cause of the reconcile, the keys its elements waited with take their place, and the
|
|
12722
|
+
* record is shown. A record still in work leaves the work: ui builds the rest of its root in one block.
|
|
12511
12723
|
*
|
|
12512
12724
|
* @param pctx - Domain context of the projection module.
|
|
12513
12725
|
* @param mounted - The mounted projection.
|
|
@@ -12520,7 +12732,9 @@ function showHeld$1(pctx, mounted, record, cause) {
|
|
|
12520
12732
|
for (const entity of record.entities) state.warmHeld.delete(entity);
|
|
12521
12733
|
record.entities.clear();
|
|
12522
12734
|
if (state.warmActive === record) delete state.warmActive;
|
|
12735
|
+
if (state.heldKeys.size > 0) releaseHeldKeys(state, record.name);
|
|
12523
12736
|
record.phase = "shown";
|
|
12737
|
+
record.next = false;
|
|
12524
12738
|
view.cause = cause;
|
|
12525
12739
|
mounted.live.set(view.key, view);
|
|
12526
12740
|
state.membershipVersion += 1;
|
|
@@ -12747,52 +12961,136 @@ function refreshWarm(pctx, spec, record, warm) {
|
|
|
12747
12961
|
return true;
|
|
12748
12962
|
}
|
|
12749
12963
|
/**
|
|
12964
|
+
* How the key of a warm item stands in its projection: `from` does not show it (`"closed"`), shows it with the same
|
|
12965
|
+
* content (`"open"`: the window is open, it is not built twice), or shows it with another content (`"next"`: the dim
|
|
12966
|
+
* of a gated window, whose open view is built aside, F202). A map lookup and, for a shown key, one `sameItem`.
|
|
12967
|
+
*
|
|
12968
|
+
* @param state - The projection branch of the plugin state.
|
|
12969
|
+
* @param name - The projection.
|
|
12970
|
+
* @param warm - The warm item and its key.
|
|
12971
|
+
* @returns How the key stands.
|
|
12972
|
+
*/
|
|
12973
|
+
function standing(state, name, warm) {
|
|
12974
|
+
const mounted = state.mounted.get(name);
|
|
12975
|
+
if (mounted?.items.has(warm.key) !== true) return "closed";
|
|
12976
|
+
const live = mounted.live.get(warm.key);
|
|
12977
|
+
return live === void 0 || sameItem(live.item, warm.item) ? "open" : "next";
|
|
12978
|
+
}
|
|
12979
|
+
/** The turn of a warm step, filled in place by `stepNext`, so a frame under a motion makes no object. */
|
|
12980
|
+
const stepTurn = {
|
|
12981
|
+
snapshot: Object.freeze({
|
|
12982
|
+
player: {},
|
|
12983
|
+
session: {},
|
|
12984
|
+
rng: {
|
|
12985
|
+
seed: 0,
|
|
12986
|
+
streams: {}
|
|
12987
|
+
}
|
|
12988
|
+
}),
|
|
12989
|
+
moving: false
|
|
12990
|
+
};
|
|
12991
|
+
/** What `readTurn` answers for a record that has no turn: read against this state, and not waiting to be stepped. */
|
|
12992
|
+
const NO_TURN = Object.freeze({
|
|
12993
|
+
item: void 0,
|
|
12994
|
+
key: ""
|
|
12995
|
+
});
|
|
12996
|
+
/**
|
|
12997
|
+
* The read a record's turn works from: the one it waited with, when the state did not change since and no owned
|
|
12998
|
+
* motion runs any more; `NO_TURN` while it still waits or was stepped against this state; else a new read of its item,
|
|
12999
|
+
* once per state (a throw is logged once per commit, not on every frame).
|
|
13000
|
+
*
|
|
13001
|
+
* @param pctx - Domain context of the projection module.
|
|
13002
|
+
* @param spec - The projection spec.
|
|
13003
|
+
* @param record - The record.
|
|
13004
|
+
* @param turn - The state now and whether an owned motion runs.
|
|
13005
|
+
* @returns The read, `undefined` for no item, or `NO_TURN`.
|
|
13006
|
+
*/
|
|
13007
|
+
function readTurn(pctx, spec, record, turn) {
|
|
13008
|
+
if (isSeen(record.seen, turn.snapshot)) {
|
|
13009
|
+
if (!record.waiting || turn.moving) return NO_TURN;
|
|
13010
|
+
const pending = record.pending;
|
|
13011
|
+
record.waiting = false;
|
|
13012
|
+
delete record.pending;
|
|
13013
|
+
return pending;
|
|
13014
|
+
}
|
|
13015
|
+
record.waiting = false;
|
|
13016
|
+
delete record.pending;
|
|
13017
|
+
record.seen = turn.snapshot;
|
|
13018
|
+
return readWarm(pctx, spec, turn.snapshot);
|
|
13019
|
+
}
|
|
13020
|
+
/**
|
|
12750
13021
|
* One record's turn in the warm step: a record shown, in work, or read against this state is passed over. Otherwise
|
|
12751
|
-
* its item is read (`warm`, or `from`'s first while held): with no item, or with a key `from` shows
|
|
12752
|
-
* dropped; a cold record spawns its held view, a ready one is brought up to date.
|
|
13022
|
+
* its item is read (`warm`, or `from`'s first while held): with no item, or with a key `from` shows with that content,
|
|
13023
|
+
* what is held is dropped; a cold record spawns its held view, a ready one is brought up to date. While a motion that
|
|
13024
|
+
* owns its fields runs, only a record whose key `from` shows with another content (the dim of a gated window, F202)
|
|
13025
|
+
* does its work; any other one with work waits with its read, and does it once no such motion runs.
|
|
12753
13026
|
*
|
|
12754
13027
|
* @param pctx - Domain context of the projection module.
|
|
12755
13028
|
* @param record - The record.
|
|
12756
|
-
* @param
|
|
13029
|
+
* @param turn - The state now and whether an owned motion runs.
|
|
12757
13030
|
* @returns True when the step did work, so the frame takes no more.
|
|
12758
13031
|
*/
|
|
12759
|
-
function stepRecord$1(pctx, record,
|
|
13032
|
+
function stepRecord$1(pctx, record, turn) {
|
|
12760
13033
|
if (record.phase === "shown" || record.phase === "building") return false;
|
|
12761
|
-
if (isSeen(record.seen, snapshot)) return false;
|
|
12762
13034
|
const state = pctx.ctx.state.projection;
|
|
12763
13035
|
const spec = state.specs.get(record.name);
|
|
12764
13036
|
if (spec === void 0) return false;
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
13037
|
+
const read = readTurn(pctx, spec, record, turn);
|
|
13038
|
+
if (read === NO_TURN) return false;
|
|
13039
|
+
const stands = read === void 0 ? "open" : standing(state, record.name, read);
|
|
13040
|
+
if (stands === "open" && record.view === void 0) return false;
|
|
13041
|
+
if (turn.moving && stands !== "next") {
|
|
13042
|
+
record.waiting = true;
|
|
13043
|
+
record.next = false;
|
|
13044
|
+
if (read !== void 0) record.pending = read;
|
|
13045
|
+
return false;
|
|
13046
|
+
}
|
|
13047
|
+
if (read === void 0 || stands === "open") {
|
|
12769
13048
|
dropHeld(pctx, record);
|
|
12770
13049
|
coolRecord(state, record);
|
|
12771
13050
|
return true;
|
|
12772
13051
|
}
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
13052
|
+
let worked;
|
|
13053
|
+
if (record.phase === "ready") worked = refreshWarm(pctx, spec, record, read);
|
|
13054
|
+
else {
|
|
13055
|
+
spawnWarm(pctx, spec, record, read);
|
|
13056
|
+
worked = record.view !== void 0;
|
|
13057
|
+
}
|
|
13058
|
+
record.next = stands === "next" && record.view !== void 0;
|
|
13059
|
+
return worked;
|
|
12776
13060
|
}
|
|
12777
13061
|
/**
|
|
12778
13062
|
* Takes the next record that has work, in mounted order, and does its one step. A walk that finds none leaves the
|
|
12779
|
-
* world at rest until a commit or a close
|
|
13063
|
+
* world at rest until a commit or a close; one that passed a record over under an owned motion stays stale, so the
|
|
13064
|
+
* record is stepped once the motion ends. Index loop: under a motion this walk runs every frame.
|
|
12780
13065
|
*
|
|
12781
13066
|
* @param pctx - Domain context of the projection module.
|
|
13067
|
+
* @param moving - Whether a motion that owns its fields runs.
|
|
12782
13068
|
*/
|
|
12783
|
-
function stepNext(pctx) {
|
|
13069
|
+
function stepNext(pctx, moving) {
|
|
12784
13070
|
const state = pctx.ctx.state.projection;
|
|
12785
|
-
const
|
|
12786
|
-
|
|
12787
|
-
|
|
13071
|
+
const list = state.warmList;
|
|
13072
|
+
const count = list.length;
|
|
13073
|
+
const turn = stepTurn;
|
|
13074
|
+
let waits = false;
|
|
13075
|
+
turn.snapshot = pctx.ctx.deps.model.store.snapshot();
|
|
13076
|
+
turn.moving = moving;
|
|
13077
|
+
for (let index = 0; index < count; index += 1) {
|
|
13078
|
+
const record = list[index];
|
|
13079
|
+
if (record === void 0) continue;
|
|
13080
|
+
if (stepRecord$1(pctx, record, turn)) return;
|
|
13081
|
+
if (record.waiting) waits = true;
|
|
13082
|
+
}
|
|
13083
|
+
state.warmStale = waits;
|
|
12788
13084
|
}
|
|
12789
13085
|
/**
|
|
12790
13086
|
* One step of the warm windows, run in world's `input` callback after the reconcile. At rest it reads two fields and
|
|
12791
|
-
* returns. It runs only in a live world with no scene build
|
|
12792
|
-
*
|
|
12793
|
-
*
|
|
12794
|
-
*
|
|
12795
|
-
*
|
|
13087
|
+
* returns. It runs only in a live world with no scene build and a drawing plugin. Where it may not run, the record in
|
|
13088
|
+
* work is dropped: a paused or fast world builds no part of it, and `left()` would stay finite for good; it is built
|
|
13089
|
+
* again once the step runs. While a record is in work its checks are polled; otherwise the next record with work
|
|
13090
|
+
* spawns, patches or drops its held view. One step a frame. The frames of a motion that owns its fields and ends get
|
|
13091
|
+
* no work of an ordinary record (no spawn, no patch, no poll), but a record that holds the next view of a key `from`
|
|
13092
|
+
* shows live is stepped and polled through it: the tapped button's press tween runs through the whole dim of a gated
|
|
13093
|
+
* window (F202, the album).
|
|
12796
13094
|
*
|
|
12797
13095
|
* @param pctx - Domain context of the projection module.
|
|
12798
13096
|
*/
|
|
@@ -12804,9 +13102,9 @@ function stepWarm(pctx) {
|
|
|
12804
13102
|
if (active !== void 0) discardWarm(pctx, active);
|
|
12805
13103
|
return;
|
|
12806
13104
|
}
|
|
12807
|
-
|
|
12808
|
-
if (active === void 0) stepNext(pctx);
|
|
12809
|
-
else pollActive(state, active);
|
|
13105
|
+
const moving = ownedMotionRuns(state.tracks);
|
|
13106
|
+
if (active === void 0) stepNext(pctx, moving);
|
|
13107
|
+
else if (!moving || active.next) pollActive(state, active);
|
|
12810
13108
|
}
|
|
12811
13109
|
//#endregion
|
|
12812
13110
|
//#region src/plugins/world/projection/reconcile.ts
|
|
@@ -12964,8 +13262,40 @@ function enterEntry(pctx, spec, mounted, entry) {
|
|
|
12964
13262
|
* @param entry.used - The hints that reached an entry.
|
|
12965
13263
|
*/
|
|
12966
13264
|
function adoptEntry(pctx, spec, mounted, record, entry) {
|
|
13265
|
+
showWithItem(pctx, spec, mounted, record, entry, heldDifference(pctx, spec, record, entry.item));
|
|
13266
|
+
}
|
|
13267
|
+
/**
|
|
13268
|
+
* The output of `view` a held view needs to show an item: none for an item with the content of the held one, else
|
|
13269
|
+
* `view(item)`. A `view` that throws throws here, before anything is shown.
|
|
13270
|
+
*
|
|
13271
|
+
* @param pctx - Domain context of the projection module.
|
|
13272
|
+
* @param spec - The projection spec.
|
|
13273
|
+
* @param record - The warm record that holds the view.
|
|
13274
|
+
* @param item - The item the view is shown with.
|
|
13275
|
+
* @returns The component values, or `undefined` when nothing is to be written.
|
|
13276
|
+
*/
|
|
13277
|
+
function heldDifference(pctx, spec, record, item) {
|
|
13278
|
+
return sameItem(record.item, item) ? void 0 : collectView(pctx, spec, item);
|
|
13279
|
+
}
|
|
13280
|
+
/**
|
|
13281
|
+
* Shows the held view of a record with an item: the record is shown, then the item is stored (no `view` ran) or the
|
|
13282
|
+
* difference `next` is written directly, with no `change` hook, and the view comes as a spawned view does
|
|
13283
|
+
* (`playEnter`).
|
|
13284
|
+
*
|
|
13285
|
+
* @param pctx - Domain context of the projection module.
|
|
13286
|
+
* @param spec - The projection spec.
|
|
13287
|
+
* @param mounted - The mounted projection.
|
|
13288
|
+
* @param record - The warm record that holds the view.
|
|
13289
|
+
* @param entry - The key, its item, the peers, the mode and the used hints.
|
|
13290
|
+
* @param entry.key - The model key.
|
|
13291
|
+
* @param entry.item - The model item.
|
|
13292
|
+
* @param entry.peers - The new and the old items.
|
|
13293
|
+
* @param entry.direct - Whether the reconcile writes without motions.
|
|
13294
|
+
* @param entry.used - The hints that reached an entry.
|
|
13295
|
+
* @param next - The output of `view(item)`, or `undefined` for an item with the held one's content.
|
|
13296
|
+
*/
|
|
13297
|
+
function showWithItem(pctx, spec, mounted, record, entry, next) {
|
|
12967
13298
|
const view = record.view;
|
|
12968
|
-
const next = sameItem(record.item, entry.item) ? void 0 : collectView(pctx, spec, entry.item);
|
|
12969
13299
|
showHeld$1(pctx, mounted, record, entry.direct ? "mount" : "change");
|
|
12970
13300
|
if (next === void 0) {
|
|
12971
13301
|
view.item = entry.item;
|
|
@@ -12974,6 +13304,55 @@ function adoptEntry(pctx, spec, mounted, record, entry) {
|
|
|
12974
13304
|
playEnter$1(pctx, spec, view, entry);
|
|
12975
13305
|
}
|
|
12976
13306
|
/**
|
|
13307
|
+
* The record whose held view takes the place of a live view: a warm record holds a view of the live key, not shown
|
|
13308
|
+
* (the open view of a gated window, built under its dim, F202), and the new item differs in content from the live
|
|
13309
|
+
* one. `heldFor` is asked first: with nothing warm it reads one size. The gate's own dim → dim commit (a new object,
|
|
13310
|
+
* the same content) swaps nothing.
|
|
13311
|
+
*
|
|
13312
|
+
* @param pctx - Domain context of the projection module.
|
|
13313
|
+
* @param spec - The projection spec.
|
|
13314
|
+
* @param live - The live view of the key.
|
|
13315
|
+
* @param item - The new item, another object than the live one's.
|
|
13316
|
+
* @returns The record, or `undefined` when the live view changes as before.
|
|
13317
|
+
*/
|
|
13318
|
+
function swapFor(pctx, spec, live, item) {
|
|
13319
|
+
const held = heldFor(pctx.ctx.state.projection, spec.name, live.key);
|
|
13320
|
+
return held === void 0 || sameItem(live.item, item) ? void 0 : held;
|
|
13321
|
+
}
|
|
13322
|
+
/**
|
|
13323
|
+
* Swaps the held view of a record in for the live view of its key: the new item's `view` runs first, then the live
|
|
13324
|
+
* view leaves at once (out of `live`, the cause `"discard"`, despawned with no exit hook) and the held view is shown
|
|
13325
|
+
* with the item (`showWithItem`: the difference written if any, its enter played). A `view` that throws is logged as
|
|
13326
|
+
* a projection that failed and changes nothing: the key keeps its live view and the record its held one until the
|
|
13327
|
+
* next commit.
|
|
13328
|
+
*
|
|
13329
|
+
* @param pctx - Domain context of the projection module.
|
|
13330
|
+
* @param spec - The projection spec.
|
|
13331
|
+
* @param mounted - The mounted projection.
|
|
13332
|
+
* @param live - The live view of the key.
|
|
13333
|
+
* @param record - The record that holds the next view of the key.
|
|
13334
|
+
* @param entry - The key, its item, the peers, the mode and the used hints.
|
|
13335
|
+
* @param entry.key - The model key.
|
|
13336
|
+
* @param entry.item - The model item.
|
|
13337
|
+
* @param entry.peers - The new and the old items.
|
|
13338
|
+
* @param entry.direct - Whether the reconcile writes without motions.
|
|
13339
|
+
* @param entry.used - The hints that reached an entry.
|
|
13340
|
+
* @returns True when the held view was swapped in.
|
|
13341
|
+
*/
|
|
13342
|
+
function swapEntry(pctx, spec, mounted, live, record, entry) {
|
|
13343
|
+
let next;
|
|
13344
|
+
try {
|
|
13345
|
+
next = heldDifference(pctx, spec, record, entry.item);
|
|
13346
|
+
} catch (error) {
|
|
13347
|
+
pctx.ctx.log.error("world:projection-failed", { projection: spec.name }, asError$2(error));
|
|
13348
|
+
return false;
|
|
13349
|
+
}
|
|
13350
|
+
live.cause = "discard";
|
|
13351
|
+
despawnView(pctx, mounted, live);
|
|
13352
|
+
showWithItem(pctx, spec, mounted, record, entry, next);
|
|
13353
|
+
return true;
|
|
13354
|
+
}
|
|
13355
|
+
/**
|
|
12977
13356
|
* A key whose item is another object than before: structural changes are written, a changed
|
|
12978
13357
|
* component with a hook is handed to it and one without is written directly, then the retarget
|
|
12979
13358
|
* settles what is loose. A view no motion moves after that gets its pending `lift(false)`.
|
|
@@ -13132,8 +13511,39 @@ function settleUnchanged(pctx, spec, view, entry) {
|
|
|
13132
13511
|
dropIfStill(pctx, view);
|
|
13133
13512
|
}
|
|
13134
13513
|
/**
|
|
13135
|
-
*
|
|
13136
|
-
*
|
|
13514
|
+
* The entry of a key that has a live view. The same object, or in play mode the same content: nothing to project. A
|
|
13515
|
+
* restore and a load still write its rest pose, once for every live view, in `convergeMounted`; a rollback settles it
|
|
13516
|
+
* when it stands off it. A warm record that holds the next view of the key (a gated window's open view, built under
|
|
13517
|
+
* its dim) has it swapped in, or nothing happens when its `view` throws. Otherwise the view changes.
|
|
13518
|
+
*
|
|
13519
|
+
* @param pctx - Domain context of the projection module.
|
|
13520
|
+
* @param spec - The projection spec.
|
|
13521
|
+
* @param mounted - The mounted projection.
|
|
13522
|
+
* @param live - The live view of the key.
|
|
13523
|
+
* @param entry - The key, its item, the peers, the mode, the flags and the used hints.
|
|
13524
|
+
* @param entry.key - The model key.
|
|
13525
|
+
* @param entry.item - The model item.
|
|
13526
|
+
* @param entry.peers - The new and the old items.
|
|
13527
|
+
* @param entry.direct - Whether the reconcile writes without motions.
|
|
13528
|
+
* @param entry.force - Whether an unchanged item is projected again.
|
|
13529
|
+
* @param entry.settle - Whether an unchanged view that stands off its rest pose is settled.
|
|
13530
|
+
* @param entry.used - The hints that reached an entry.
|
|
13531
|
+
* @param entry.unchanged - The unchanged views of a direct reconcile that settles.
|
|
13532
|
+
* @param entry.rewritten - The views a direct reconcile wrote, written again after its flush.
|
|
13533
|
+
* @param counts - The counters of this reconcile.
|
|
13534
|
+
*/
|
|
13535
|
+
function applyLive(pctx, spec, mounted, live, entry, counts) {
|
|
13536
|
+
const same = !entry.force && live.item === entry.item;
|
|
13537
|
+
const swap = same ? void 0 : swapFor(pctx, spec, live, entry.item);
|
|
13538
|
+
if (swap !== void 0) {
|
|
13539
|
+
if (swapEntry(pctx, spec, mounted, live, swap, entry)) counts.entered += 1;
|
|
13540
|
+
} else if (!same && changeEntry(pctx, spec, live, entry)) counts.changed += 1;
|
|
13541
|
+
else if (entry.settle) settleUnchanged(pctx, spec, live, entry);
|
|
13542
|
+
}
|
|
13543
|
+
/**
|
|
13544
|
+
* Routes one key of the new state to the entry it belongs to: a live view changes, or gives its place to the next
|
|
13545
|
+
* view a warm record holds of its key, a queued view revives, a key a warm window holds is shown, an unknown key
|
|
13546
|
+
* enters.
|
|
13137
13547
|
*
|
|
13138
13548
|
* @param pctx - Domain context of the projection module.
|
|
13139
13549
|
* @param spec - The projection spec.
|
|
@@ -13153,8 +13563,7 @@ function settleUnchanged(pctx, spec, view, entry) {
|
|
|
13153
13563
|
function applyEntry(pctx, spec, mounted, entry, counts) {
|
|
13154
13564
|
const live = mounted.live.get(entry.key);
|
|
13155
13565
|
if (live !== void 0) {
|
|
13156
|
-
|
|
13157
|
-
else if (entry.settle) settleUnchanged(pctx, spec, live, entry);
|
|
13566
|
+
applyLive(pctx, spec, mounted, live, entry, counts);
|
|
13158
13567
|
return;
|
|
13159
13568
|
}
|
|
13160
13569
|
const queued = mounted.queue.find((view) => view.key === entry.key);
|
|
@@ -14134,16 +14543,18 @@ function createProjectionApi(ctx, deps) {
|
|
|
14134
14543
|
registerKey: (projection, key, entity) => {
|
|
14135
14544
|
if (state.mounted.get(projection)?.live.has(key) === true) throw new Error(`[game] Key "${key}" of projection "${projection}" is already a live view.\n Register the element under another key.`);
|
|
14136
14545
|
const byKey = state.keys.get(projection) ?? emptyKeys$2();
|
|
14137
|
-
|
|
14546
|
+
const held = holdRegistered(state, projection, entity);
|
|
14547
|
+
if (!held) yieldHeldKey(state, projection, key);
|
|
14548
|
+
if (!held || !waitHeldKey(state, projection, key, entity)) byKey.set(key, entity);
|
|
14138
14549
|
state.keys.set(projection, byKey);
|
|
14139
14550
|
state.keysByEntity.set(entity, {
|
|
14140
14551
|
projection,
|
|
14141
14552
|
key
|
|
14142
14553
|
});
|
|
14143
14554
|
state.sweptDespawns = -1;
|
|
14144
|
-
holdRegistered(state, projection, entity);
|
|
14145
14555
|
return () => {
|
|
14146
14556
|
if (byKey.get(key) === entity) byKey.delete(key);
|
|
14557
|
+
if (state.heldKeys.size > 0) dropHeldKey(state, projection, key, entity);
|
|
14147
14558
|
if (state.keysByEntity.get(entity)?.key === key) state.keysByEntity.delete(entity);
|
|
14148
14559
|
state.rests.delete(entity);
|
|
14149
14560
|
};
|
|
@@ -14539,7 +14950,7 @@ function emptySet$8() {
|
|
|
14539
14950
|
* running track and no driver, so every motion is instant until `anim` installs one. No build
|
|
14540
14951
|
* runs: `building` is absent. No warm window is held, and none is being built: `warmActive` is
|
|
14541
14952
|
* absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate. No
|
|
14542
|
-
* projection is held, no `show` is owed, and nothing was
|
|
14953
|
+
* projection is held, no `show` is owed, nothing was fed, no held key waits and nothing was adopted.
|
|
14543
14954
|
*
|
|
14544
14955
|
* @returns The projection branch of the plugin state.
|
|
14545
14956
|
*/
|
|
@@ -14573,6 +14984,8 @@ function createProjectionState() {
|
|
|
14573
14984
|
warm: emptyMap$9(),
|
|
14574
14985
|
warmList: [],
|
|
14575
14986
|
warmHeld: emptySet$8(),
|
|
14987
|
+
heldKeys: emptyMap$9(),
|
|
14988
|
+
warmLoose: -1,
|
|
14576
14989
|
warmStale: false,
|
|
14577
14990
|
warmBudgetMs: FALLBACK_WARM_MS,
|
|
14578
14991
|
held: emptySet$8(),
|
|
@@ -44764,31 +45177,114 @@ function ageReadyWaiting(state) {
|
|
|
44764
45177
|
else state.readyWaiting.set(name, rests + 1);
|
|
44765
45178
|
}
|
|
44766
45179
|
/**
|
|
45180
|
+
* Tells whether a warm view is in work for a `ready` to wait on: `world.projection.left()` is finite (a warm record
|
|
45181
|
+
* builds, or a scene build runs), and no capped post waived the wait.
|
|
45182
|
+
*
|
|
45183
|
+
* @param ctx - Domain context of the plugin.
|
|
45184
|
+
* @returns True while the `ready` waits for the build too.
|
|
45185
|
+
*/
|
|
45186
|
+
function warmInWork(ctx) {
|
|
45187
|
+
return ctx.state.readyWait !== "waived" && ctx.deps.world.projection.left() !== Number.POSITIVE_INFINITY;
|
|
45188
|
+
}
|
|
45189
|
+
/**
|
|
45190
|
+
* Lets the post of `ready` wait for the warm view in work: the system `assets.ready` posts it once `left()` turns
|
|
45191
|
+
* infinite, or at the cap. A wait already running keeps its start.
|
|
45192
|
+
*
|
|
45193
|
+
* @param state - The plugin state.
|
|
45194
|
+
* @param ask - The number `beginAsk` gave the ask whose post waits.
|
|
45195
|
+
*/
|
|
45196
|
+
function waitForWarm(state, ask) {
|
|
45197
|
+
state.readyWarmAsk = ask;
|
|
45198
|
+
if (state.readyWait === "warm") return;
|
|
45199
|
+
state.readyWait = "warm";
|
|
45200
|
+
state.readySince = -1;
|
|
45201
|
+
}
|
|
45202
|
+
/**
|
|
45203
|
+
* Posts the `ready` of the latest waiting ask, through `settleAsk` (F204): only to the rest that ask leads to.
|
|
45204
|
+
*
|
|
45205
|
+
* @param ctx - Domain context of the plugin.
|
|
45206
|
+
*/
|
|
45207
|
+
function postReady(ctx) {
|
|
45208
|
+
settleAsk(ctx, ctx.state.readyWarmAsk);
|
|
45209
|
+
}
|
|
45210
|
+
/**
|
|
45211
|
+
* The bundles a `ready` answered `false` for settled: it posts at once, or, in a live game with a warm view in work,
|
|
45212
|
+
* leaves the post to the system `assets.ready`.
|
|
45213
|
+
*
|
|
45214
|
+
* @param ctx - Domain context of the plugin.
|
|
45215
|
+
* @param live - Whether the effect ran in live mode.
|
|
45216
|
+
* @param ask - The number `beginAsk` gave the ask.
|
|
45217
|
+
*/
|
|
45218
|
+
function bundlesSettled(ctx, live, ask) {
|
|
45219
|
+
if (live && warmInWork(ctx)) waitForWarm(ctx.state, ask);
|
|
45220
|
+
else settleAsk(ctx, ask);
|
|
45221
|
+
}
|
|
45222
|
+
/**
|
|
45223
|
+
* One frame of the system `assets.ready` (phase `sync`): with no wait it reads one field. A `ready` waiting for the
|
|
45224
|
+
* warm view in work posts once `left()` turns infinite (the record became ready, or was discarded, paused or dropped by
|
|
45225
|
+
* a scene build or a restore: every end of it counts), or `READY_WARM_CAP_MS` after its first frame, which waives the
|
|
45226
|
+
* wait until the build ends, so the re-ask goes on and nothing posts again. A waived wait ends when `left()` turns
|
|
45227
|
+
* infinite.
|
|
45228
|
+
*
|
|
45229
|
+
* @param ctx - Domain context of the plugin.
|
|
45230
|
+
* @param frame - What the system run gets: the frame's `Time`.
|
|
45231
|
+
* @param frame.time - The frame's `Time`, its game clock read only while a wait runs.
|
|
45232
|
+
* @param frame.time.elapsed - The game clock, in scaled ms.
|
|
45233
|
+
*/
|
|
45234
|
+
function stepReady(ctx, frame) {
|
|
45235
|
+
const state = ctx.state;
|
|
45236
|
+
const wait = state.readyWait;
|
|
45237
|
+
if (wait === "none") return;
|
|
45238
|
+
const rests = ctx.deps.world.projection.left() === Number.POSITIVE_INFINITY;
|
|
45239
|
+
if (wait === "waived") {
|
|
45240
|
+
if (rests) state.readyWait = "none";
|
|
45241
|
+
return;
|
|
45242
|
+
}
|
|
45243
|
+
if (rests) {
|
|
45244
|
+
state.readyWait = "none";
|
|
45245
|
+
postReady(ctx);
|
|
45246
|
+
return;
|
|
45247
|
+
}
|
|
45248
|
+
const now = frame.time.elapsed;
|
|
45249
|
+
if (state.readySince < 0) state.readySince = now;
|
|
45250
|
+
else if (now - state.readySince >= 400) {
|
|
45251
|
+
state.readyWait = "waived";
|
|
45252
|
+
postReady(ctx);
|
|
45253
|
+
}
|
|
45254
|
+
}
|
|
45255
|
+
/**
|
|
44767
45256
|
* The handler of the `ready` effect (F52). Headless it answers `true` before any name check, as the
|
|
44768
|
-
* `load` effect does. Every bundle there: `true`, and nothing is posted.
|
|
44769
|
-
* warm of each bundle that is not there, answers `false`, and posts
|
|
44770
|
-
* `flow.inbox` once all of them settled,
|
|
44771
|
-
*
|
|
44772
|
-
*
|
|
44773
|
-
*
|
|
45257
|
+
* `load` effect does. Every bundle there and no warm view in work: `true`, and nothing is posted.
|
|
45258
|
+
* Otherwise it starts the warm of each bundle that is not there, answers `false`, and posts
|
|
45259
|
+
* `{ type: "ready" }` into `flow.inbox` once all of them settled and, in live mode, the warm view in
|
|
45260
|
+
* work is built (F202: the open view of a gated window, built under its dim; at most
|
|
45261
|
+
* `READY_WARM_CAP_MS` later, see `stepReady`), for the rest this ask leads to only (F204,
|
|
45262
|
+
* `settleAsk`): a `ready` nobody rests on would end the next wait at once. The posting does not
|
|
45263
|
+
* wait on the node's signal: the warm is shared work. A bundle it answers `false` for
|
|
45264
|
+
* is rested on (`readyWaiting`) until a `ready` finds it there: neither the budget nor the `"leave"`
|
|
44774
45265
|
* release of the rest in between takes it, else the node that asks again finds it gone and the two
|
|
44775
45266
|
* nodes cycle forever (F190). `ageReadyWaiting` ends the hold of one nobody asks for again.
|
|
44776
45267
|
*
|
|
44777
45268
|
* @param ctx - Domain context of the plugin.
|
|
44778
45269
|
* @param bundles - The bundle names of the descriptor.
|
|
45270
|
+
* @param live - Whether the effect runs in live mode: a fast walk builds no warm view and waits for none.
|
|
44779
45271
|
* @returns True when the node may go on, false when it should rest until the inbox event `ready`.
|
|
44780
45272
|
* @throws {Error} When the manifest has no such bundle.
|
|
44781
45273
|
*/
|
|
44782
|
-
function answerReady(ctx, bundles) {
|
|
45274
|
+
function answerReady(ctx, bundles, live = true) {
|
|
44783
45275
|
const state = ctx.state;
|
|
44784
45276
|
if (state.io === void 0) return true;
|
|
44785
45277
|
for (const name of bundles) if (state.manifest.bundles[name] === void 0) throw unknownBundle(name);
|
|
44786
45278
|
const missing = bundles.filter((name) => !isThere(state, name));
|
|
44787
45279
|
for (const name of bundles) if (missing.includes(name)) state.readyWaiting.set(name, 0);
|
|
44788
45280
|
else state.readyWaiting.delete(name);
|
|
44789
|
-
if (missing.length === 0)
|
|
45281
|
+
if (missing.length === 0) {
|
|
45282
|
+
if (!live || !warmInWork(ctx)) return true;
|
|
45283
|
+
waitForWarm(state, beginAsk(ctx));
|
|
45284
|
+
return false;
|
|
45285
|
+
}
|
|
44790
45286
|
const ask = beginAsk(ctx);
|
|
44791
|
-
Promise.all(missing.map((name) => warmForReady(ctx, name))).then(() =>
|
|
45287
|
+
Promise.all(missing.map((name) => warmForReady(ctx, name))).then(() => bundlesSettled(ctx, live, ask));
|
|
44792
45288
|
return false;
|
|
44793
45289
|
}
|
|
44794
45290
|
/**
|
|
@@ -44868,7 +45364,7 @@ function passReadyNode(ctx, node) {
|
|
|
44868
45364
|
//#endregion
|
|
44869
45365
|
//#region src/plugins/assets/lifecycle.ts
|
|
44870
45366
|
/**
|
|
44871
|
-
* @file assets plugin — lifecycle: the
|
|
45367
|
+
* @file assets plugin — lifecycle: the eight registrations of `onInit`, the boot of `onStart`
|
|
44872
45368
|
* and the teardown that frees every texture and cancels every fetch.
|
|
44873
45369
|
*/
|
|
44874
45370
|
/**
|
|
@@ -45011,15 +45507,16 @@ async function enterNode(ctx, node, run) {
|
|
|
45011
45507
|
/**
|
|
45012
45508
|
* Connects the plugin in `onInit`: the `load` stage of `onEnter`, the handlers of the `load` and
|
|
45013
45509
|
* the `ready` effects (F52), both run in fast mode too, the texture provider of `renderer`, the
|
|
45014
|
-
* start and the end of an exit in `world`, counted,
|
|
45015
|
-
* which lets a leaving scene's bundles go once its elements played their exit (F51)
|
|
45016
|
-
*
|
|
45510
|
+
* start and the end of an exit in `world`, counted, the system `assets.leave` of phase `sync`,
|
|
45511
|
+
* which lets a leaving scene's bundles go once its elements played their exit (F51), and the system
|
|
45512
|
+
* `assets.ready` of the same phase, which posts a `ready` that waits for a warm view once its build
|
|
45513
|
+
* ended (F202). The eight removers go to the state, because `onStop` has nothing but the state.
|
|
45017
45514
|
*
|
|
45018
45515
|
* @param ctx - Kernel context of the assets plugin.
|
|
45019
45516
|
*/
|
|
45020
45517
|
function connectAssets(ctx) {
|
|
45021
45518
|
const assets = withDeps$6(ctx);
|
|
45022
|
-
assets.state.removers.push(assets.deps.flow.onEnter("load", (node, run) => enterNode(assets, node, run)), assets.deps.flow.fx.handle("load", (descriptor, run) => runLoadEffect(assets, descriptor, run), { runInFast: true }), assets.deps.flow.fx.handle("ready", (descriptor) => answerReady(assets, bundlesOfDescriptor(descriptor)), { runInFast: true }), assets.deps.renderer.sync.textures.provide((key) => lookupTexture(assets, key)), assets.deps.world.ecs.onAdded(Exiting, () => {
|
|
45519
|
+
assets.state.removers.push(assets.deps.flow.onEnter("load", (node, run) => enterNode(assets, node, run)), assets.deps.flow.fx.handle("load", (descriptor, run) => runLoadEffect(assets, descriptor, run), { runInFast: true }), assets.deps.flow.fx.handle("ready", (descriptor, run) => answerReady(assets, bundlesOfDescriptor(descriptor), run.mode === "live"), { runInFast: true }), assets.deps.renderer.sync.textures.provide((key) => lookupTexture(assets, key)), assets.deps.world.ecs.onAdded(Exiting, () => {
|
|
45023
45520
|
assets.state.exiting += 1;
|
|
45024
45521
|
}), assets.deps.world.ecs.onRemoved(Exiting, () => {
|
|
45025
45522
|
assets.state.exiting -= 1;
|
|
@@ -45028,6 +45525,11 @@ function connectAssets(ctx) {
|
|
|
45028
45525
|
phase: "sync",
|
|
45029
45526
|
query: [],
|
|
45030
45527
|
run: () => releaseSceneLeft(assets)
|
|
45528
|
+
})), assets.deps.world.ecs.system(system({
|
|
45529
|
+
name: "assets.ready",
|
|
45530
|
+
phase: "sync",
|
|
45531
|
+
query: [],
|
|
45532
|
+
run: (_rows, frame) => stepReady(assets, frame)
|
|
45031
45533
|
})));
|
|
45032
45534
|
}
|
|
45033
45535
|
/**
|
|
@@ -45099,7 +45601,7 @@ async function startAssets(ctx) {
|
|
|
45099
45601
|
}
|
|
45100
45602
|
/**
|
|
45101
45603
|
* Frees everything in `onStop`: the preload and every running load are aborted, every texture is
|
|
45102
|
-
* destroyed, the
|
|
45604
|
+
* destroyed, the eight registrations are removed and the registries are emptied, the companions
|
|
45103
45605
|
* too. A teardown context carries the state and nothing else, so no other plugin is called here:
|
|
45104
45606
|
* no companion's `unload` either, its plugin stopped before this one.
|
|
45105
45607
|
*
|
|
@@ -45138,6 +45640,8 @@ function releaseAll(state) {
|
|
|
45138
45640
|
state.exiting = 0;
|
|
45139
45641
|
state.restPending = false;
|
|
45140
45642
|
state.restedLive = false;
|
|
45643
|
+
state.readyWait = "none";
|
|
45644
|
+
state.readySince = -1;
|
|
45141
45645
|
state.stamps = void 0;
|
|
45142
45646
|
state.swapping = void 0;
|
|
45143
45647
|
state.io = void 0;
|
|
@@ -46010,7 +46514,10 @@ function createAssetsState() {
|
|
|
46010
46514
|
restPending: false,
|
|
46011
46515
|
restedLive: false,
|
|
46012
46516
|
readyFailed: emptySet$2(),
|
|
46013
|
-
warmed: emptyMap$3()
|
|
46517
|
+
warmed: emptyMap$3(),
|
|
46518
|
+
readyWait: "none",
|
|
46519
|
+
readySince: -1,
|
|
46520
|
+
readyWarmAsk: 0
|
|
46014
46521
|
};
|
|
46015
46522
|
}
|
|
46016
46523
|
/**
|