@wardic/core 1.3.1 → 1.4.0
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/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +12 -6
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +374 -30
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +22 -8
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +14 -8
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +93 -34
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +11 -8
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +18 -37
- package/dist/InputFeed.js.map +1 -1
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +16 -9
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +204 -27
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +21 -8
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +184 -60
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +16 -9
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +2 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +15 -10
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +11 -3
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +190 -39
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +21 -4
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +21 -5
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +45 -39
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +59 -35
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +11 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +21 -17
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +54 -50
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +201 -77
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +6 -3
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +14 -3
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +42 -13
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +279 -88
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +30 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +8 -1
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +18 -2
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +7 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +24 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +123 -68
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +319 -167
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +32 -10
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +73 -20
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +68 -34
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +83 -36
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +391 -27
- package/src/Clock.ts +29 -8
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +118 -41
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +39 -42
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +186 -30
- package/src/Machine.ts +252 -81
- package/src/Playback.ts +15 -9
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +16 -10
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +203 -41
- package/src/internal/guarded.ts +69 -0
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +33 -6
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +88 -57
- package/src/unstable/AppearHandoff.ts +13 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +23 -17
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +250 -108
- package/src/unstable/FrameEffects.ts +17 -4
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +342 -101
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +33 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +20 -2
- package/src/unstable/RetargetLegs.ts +24 -9
- package/src/unstable/Spine.ts +399 -202
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +102 -23
- package/src/unstable/VariantTree.ts +123 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The late-frame rule for a run's first steps, on plain numbers: a run takes none of a long task's time from
|
|
3
|
+
* before it began. A long task delays a frame, a **Late frame**. Stamped when it was due, the frame is told late
|
|
4
|
+
* by its lag (its callback ran past the line after its timestamp), and the next frame's dt holds the task's time:
|
|
5
|
+
* a run made in the task leaves the frame's lateness out of its second step, and one made in its Late window and
|
|
6
|
+
* first stepped at a later tick, out of its first. Stamped near when it ran, the frame's own gap from the one
|
|
7
|
+
* before holds the task's time, as the gap after a frame told late does: a frame whose gap is more than one and a
|
|
8
|
+
* half of the frames' interval is late by the rest (`lateByGap`), and a run's first step there leaves its
|
|
9
|
+
* lateness out, one interval.
|
|
10
|
+
*
|
|
11
|
+
* A run keeps one number, what it owes (`owed`): `NaN` until its first step, or less than 0 for one made in the
|
|
12
|
+
* Late window of a frame told late by its lag, by the frame's lateness (`madeOwing`); then its first frame's
|
|
13
|
+
* lateness, which its second step leaves out; then 0. A run that owes 0 steps at the tick's dt.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
// #1028 (ADR-0027 *Amendment (#1028)*): #1026's rule, out of the Frame loop's entries, so a Batch's members,
|
|
18
|
+
// on one run, keep it per member. The Frame loop carries a `Reader` of its ticks for them (`internal/carried.ts`).
|
|
19
|
+
// Per frame, for a run or a member that owes: plain math. #1050 (ADR-0027 *Amendment (#1050)*): a frame told late by
|
|
20
|
+
// its gap, in place of #1048's line a run waited past, which missed a run made late in the task: WebKit and Gecko
|
|
21
|
+
// stamp a late frame near when it ran, so its lag never tells it. #1053: "late", where #1050 said "held", which is
|
|
22
|
+
// Foldkit's **Held frame** (CONTEXT.md).
|
|
23
|
+
import * as Option from "effect/Option";
|
|
24
|
+
import * as Predicate from "effect/Predicate";
|
|
25
|
+
import * as Clock from "../Clock.js";
|
|
26
|
+
import { carriedOf, carry } from "./carried.js";
|
|
27
|
+
/** `dt`, less `left` seconds left out of it: `floor` at least, and never more than `dt`. */
|
|
28
|
+
const leavingOut = (dt, left, floor) => Math.min(dt, Math.max(dt - left, floor));
|
|
29
|
+
/** A 60 Hz frame, in ms: the Frame loop takes one for a gap it hasn't timed. */
|
|
30
|
+
export const NOMINAL_FRAME_MS = Clock.NOMINAL_DT * 1000;
|
|
31
|
+
/** A 30 Hz frame, in ms: the longest interval `intervalOf` gives, so late frames one after another don't lift it. */
|
|
32
|
+
const SLOWEST_FRAME_MS = 1000 / 30;
|
|
33
|
+
/** The median of `a`, `b` and `c`. */
|
|
34
|
+
const medianOf3 = (a, b, c) => Math.max(Math.min(a, b), Math.min(Math.max(a, b), c));
|
|
35
|
+
/**
|
|
36
|
+
* The frames' interval, in ms, from the last five gaps between their timestamps, `gap` and the four before it,
|
|
37
|
+
* newest first: their median, so neither a late frame's long gap nor a short one after it moves it, and a 30 Hz
|
|
38
|
+
* frame at most.
|
|
39
|
+
*/
|
|
40
|
+
// The median of five: of the four before, the least and the most can't be it, so it's the median of the two
|
|
41
|
+
// between them and `gap`.
|
|
42
|
+
export const intervalOf = (gap, before1, before2, before3, before4) => Math.min(medianOf3(Math.max(Math.min(before1, before2), Math.min(before3, before4)), Math.min(Math.max(before1, before2), Math.max(before3, before4)), gap), SLOWEST_FRAME_MS);
|
|
43
|
+
/** How late a frame whose callback ran `lag` ms after its timestamp is by its lag, in ms: all of it, past `line`; else 0. */
|
|
44
|
+
export const lateByLag = (lag, line) => {
|
|
45
|
+
if (lag > line)
|
|
46
|
+
return lag;
|
|
47
|
+
return 0;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* How late a frame `gap` ms after the one before is by its gap, in ms, on frames `interval` ms apart: what its gap
|
|
51
|
+
* is longer than one interval, once that's more than half of one; else 0.
|
|
52
|
+
*/
|
|
53
|
+
export const lateByGap = (gap, interval) => {
|
|
54
|
+
const longer = gap - interval;
|
|
55
|
+
if (longer > interval / 2)
|
|
56
|
+
return longer;
|
|
57
|
+
return 0;
|
|
58
|
+
};
|
|
59
|
+
/** What a run made now owes: its first step, made in a frame `madeLate` seconds late by its lag, or in one on time. */
|
|
60
|
+
export const madeOwing = (madeLate) => {
|
|
61
|
+
if (madeLate > 0)
|
|
62
|
+
return -madeLate;
|
|
63
|
+
return Number.NaN;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The dt of a step of a run that owes `owed` (not 0), in a frame `lateByGap` seconds late by its gap, on frames
|
|
67
|
+
* `interval` seconds apart: its second, `dt` less its first frame's lateness by its lag; its first, `dt` less its
|
|
68
|
+
* frame's lateness by its gap, or less what it owes of a frame told late by its lag, for one made in that frame's
|
|
69
|
+
* Late window and stepped at a later tick, whichever is more, and one interval at least. That frame's own Late
|
|
70
|
+
* step leaves only `lateByGap` out: its dt doesn't hold the frame's lateness by its lag.
|
|
71
|
+
*/
|
|
72
|
+
export const owingDt = (owed, dt, lateStep, lateByGap, interval) => {
|
|
73
|
+
if (owed > 0)
|
|
74
|
+
return leavingOut(dt, owed, Clock.NOMINAL_DT);
|
|
75
|
+
return leavingOut(dt, Math.max(lateByGap, owedLateByLag(owed, lateStep)), interval);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* What a run's first step owes of a frame told late by its lag, in seconds: what a run made in its Late window
|
|
79
|
+
* owes, at a later tick; nothing at that frame's own Late step, whose dt doesn't hold it, or for a run that owes
|
|
80
|
+
* `NaN`.
|
|
81
|
+
*/
|
|
82
|
+
const owedLateByLag = (owed, lateStep) => {
|
|
83
|
+
if (owed < 0 && !lateStep)
|
|
84
|
+
return -owed;
|
|
85
|
+
return 0;
|
|
86
|
+
};
|
|
87
|
+
/** What a run that owed `owed` owes after a step in a frame `lateByLag` seconds late by its lag: that, after its first; else nothing. */
|
|
88
|
+
export const owedAfter = (owed, lateByLag) => {
|
|
89
|
+
if (owed > 0)
|
|
90
|
+
return 0;
|
|
91
|
+
return lateByLag;
|
|
92
|
+
};
|
|
93
|
+
/** A `Reader` under which nothing owes: for a loop that carries none, so its runs step at the tick's dt. */
|
|
94
|
+
export const owingNothing = {
|
|
95
|
+
madeOwing: () => 0,
|
|
96
|
+
owingDt: (_owed, dt) => dt,
|
|
97
|
+
owedAfter: () => 0,
|
|
98
|
+
};
|
|
99
|
+
/** Where the Frame loop carries its `Reader`, under a key no other module can name. */
|
|
100
|
+
const KEY = Symbol("@wardic/core/internal/firstSteps");
|
|
101
|
+
/** Whether a value is what `carrying` carries. Only `carrying` writes `KEY`, so its fields are read as they are. */
|
|
102
|
+
const isReader = Predicate.and(Predicate.hasProperty("madeOwing"), Predicate.and(Predicate.hasProperty("owingDt"), Predicate.hasProperty("owedAfter")));
|
|
103
|
+
/** `loop`, carrying `reader`. */
|
|
104
|
+
export const carrying = (loop, reader) => carry(loop, KEY, reader);
|
|
105
|
+
/** The `Reader` `loop` carries: `None` for a loop that carries none (one a test makes of its own). */
|
|
106
|
+
export const readerOf = (loop) => carriedOf(loop, KEY, isReader);
|
|
107
|
+
//# sourceMappingURL=firstSteps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firstSteps.js","sourceR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
|
|
@@ -9,10 +9,12 @@ import type * as Frame from "../Frame.ts";
|
|
|
9
9
|
import * as Supersede from "../Supersede.ts";
|
|
10
10
|
import type * as FrameLoop from "../FrameLoop.ts";
|
|
11
11
|
import type * as Machine from "../Machine.ts";
|
|
12
|
-
/** A run's options: the token it joins, so its caller can end it with others. */
|
|
12
|
+
/** A run's options: the token it joins, so its caller can end it with others, and its timeline. */
|
|
13
13
|
export interface RunOptions {
|
|
14
14
|
/** The token: `Supersede.end` on it ends every run that joined it. */
|
|
15
|
-
readonly supersede
|
|
15
|
+
readonly supersede?: Supersede.Supersede | undefined;
|
|
16
|
+
/** Its start read from the frame timeline: it steps at the ticks' dt from its first frame ({@link dtOf}). */
|
|
17
|
+
readonly onFrameTimeline?: boolean | undefined;
|
|
16
18
|
}
|
|
17
19
|
/** `run`'s and `runLast`'s shape: a run given a token can also end `Superseded`. */
|
|
18
20
|
export interface Run {
|
|
@@ -51,12 +53,17 @@ export interface Shape {
|
|
|
51
53
|
* its end has run. What's written then is drawn in that tick's Refresh frame, after the tick.
|
|
52
54
|
*/
|
|
53
55
|
readonly inLateWindow: () => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* How many ticks the loop has run: 0 before any. Neither a Late round nor a binding's hint window is a
|
|
58
|
+
* tick, so a run's Late step reads the count it was started at, and any step at a later tick a greater one.
|
|
59
|
+
*/
|
|
60
|
+
readonly tickCount: () => number;
|
|
54
61
|
/**
|
|
55
62
|
* A binding's hint: its code runs inside the Refresh frame whose time is `frameTime`, after the
|
|
56
63
|
* frame's tick, as a binding that renders in a frame callback of its own does (ADR-0071 decision 32).
|
|
57
64
|
* Opens the **Late window** when a burst's last tick was this frame's (`Clock.frameAt`) or no burst runs
|
|
58
65
|
* (no tick is coming this frame), so the runs added after it, in the rest of the callback and its
|
|
59
|
-
* microtasks, take their Late step and
|
|
66
|
+
* microtasks, take their Late step and are drawn in this frame, and a queued Measure pass runs as an after-tick one. With a
|
|
60
67
|
* tick still to come in the frame, nothing: that tick is their first step. Idle, the Late step's dt is
|
|
61
68
|
* the last tick's, or a nominal frame before any.
|
|
62
69
|
*/
|
|
@@ -109,6 +116,7 @@ export declare const make: () => Effect.Effect<{
|
|
|
109
116
|
runLast: Run;
|
|
110
117
|
afterTick: (hook: (dt: number) => undefined) => Effect.Effect<void, never, Scope.Scope>;
|
|
111
118
|
inLateWindow: () => boolean;
|
|
119
|
+
tickCount: () => number;
|
|
112
120
|
hint: (frameTime: number) => void;
|
|
113
121
|
}, never, Clock.Clock | Scope.Scope>;
|
|
114
122
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frameLoop.d.ts","sourceRoot":"","sources":["../../src/internal/frameLoop.ts"],"names":[],"mappings":"AA4DA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAKvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"frameLoop.d.ts","sourceRoot":"","sources":["../../src/internal/frameLoop.ts"],"names":[],"mappings":"AA4DA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAKvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;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AAE,EAAE,MAAM,KAAK,SAAS,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;wBA0JnE,OAAO;qBA5JV,MAAM;sBAhBH,MAAM,KAAG,IAAI;oCAmLzC,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The **Frame loop**'s implementation (ADR-0027), behind the `FrameLoop` module's service and
|
|
3
3
|
* `layer` (ADR-0028, decision 11): one fiber per burst that steps every running
|
|
4
4
|
* Primitive's machine once per tick, in one pass, and hands each its Frame. Each animation used
|
|
5
|
-
* to be a fiber running its own `Stream`; at 1,000
|
|
5
|
+
* to be a fiber running its own `Stream`; at 1,000 Subjects that machinery was about 90% of a
|
|
6
6
|
* Primitive's per-frame cost.
|
|
7
7
|
*
|
|
8
8
|
* - **A run** is `run(machine, sink)`: an entry added, its Frames handed to `sink` from the loop's
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
* starts while the ending burst resumes its runs (#81).
|
|
25
25
|
* - **The end of a tick** calls each `afterTick` hook, with the tick's dt, after every step and sink
|
|
26
26
|
* and the continuations of the runs that settled in it, the tick that ends a burst included. The flush
|
|
27
|
-
* gate flushes there, so a value
|
|
27
|
+
* gate flushes there, so a value is drawn in the Refresh frame that computed it (ADR-0033). A run
|
|
28
28
|
* a hook starts keeps the burst: whether it ends is counted after the hooks (#209).
|
|
29
29
|
* - **The Late window** runs from a tick's first step until a microtask the tick queues at its end
|
|
30
30
|
* (ADR-0027 *Amendment (#680)*): what starts in it is drawn in that tick's Refresh frame, after the
|
|
31
31
|
* tick. A run `run` added in it, during the tick or in a microtask the tick's own code queued (Solid
|
|
32
32
|
* 2's effects, a promise it resolved), takes its **Late step** in that microtask: one step at the
|
|
33
|
-
* tick's dt, and the hooks again, so the frame
|
|
33
|
+
* tick's dt, and the hooks again, so the frame draws it, not its origin. A round whose steps or hooks
|
|
34
34
|
* add more runs is followed by another, at most `MAX_LATE_ROUNDS`; the rest step at the next tick. A
|
|
35
35
|
* `runLast` run takes none: the projection's coordinator, its one caller, would step again the nodes
|
|
36
36
|
* an after-tick Measure pass already stepped. One the tick stepped steps again at dt 0 after a round
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
* run gets at its start when the check is on, so the tick is the same either way.
|
|
55
55
|
*
|
|
56
56
|
* Internal (ADR-0028, decision 11): the service's shape (`run`, `runLast`, `afterTick`,
|
|
57
|
-
* `inLateWindow`) and `make`, behind `FrameLoop.layer`.
|
|
57
|
+
* `inLateWindow`, `tickCount`, `hint`) and `make`, behind `FrameLoop.layer`.
|
|
58
58
|
*/
|
|
59
59
|
import * as Arr from "effect/Array";
|
|
60
60
|
import * as Bool from "effect/Boolean";
|
|
@@ -74,9 +74,23 @@ import * as Stream from "effect/Stream";
|
|
|
74
74
|
import * as UndefinedOr from "effect/UndefinedOr";
|
|
75
75
|
import * as Clock from "../Clock.js";
|
|
76
76
|
import * as Supersede from "../Supersede.js";
|
|
77
|
+
import * as Report from "../unstable/Report.js";
|
|
78
|
+
import * as FirstSteps from "./firstSteps.js";
|
|
77
79
|
import { none, SpansGiven, traced } from "./tracing.js";
|
|
78
80
|
/** How many Late rounds a window runs before the rest wait for the next tick: the Measure pass's cap (#680). */
|
|
79
81
|
const MAX_LATE_ROUNDS = 5;
|
|
82
|
+
/** The line past which a Refresh frame ran late, in ms (`Clock.LateFrames`): `NaN` where none is told. */
|
|
83
|
+
const lateAfterOf = (timing) => {
|
|
84
|
+
if (timing === "timestamp")
|
|
85
|
+
return Number.NaN;
|
|
86
|
+
return timing.ranAfter;
|
|
87
|
+
};
|
|
88
|
+
/** Whether a run keeps the frame timeline's time (`RunOptions.onFrameTimeline`). */
|
|
89
|
+
const onFrameTimeline = (options) => {
|
|
90
|
+
if (Predicate.isUndefined(options))
|
|
91
|
+
return false;
|
|
92
|
+
return options.onFrameTimeline === true;
|
|
93
|
+
};
|
|
80
94
|
/**
|
|
81
95
|
* Where a run's fiber finds the metrics. The loop takes them from the first run that has them: an app
|
|
82
96
|
* gives them beside its Environment, which the loop's own build doesn't see, as `CheckFrames` is read.
|
|
@@ -172,6 +186,10 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
172
186
|
const clock = yield* Clock.Clock;
|
|
173
187
|
// The burst runs here, under the Layer's build context, never in a caller's.
|
|
174
188
|
const buildContext = yield* Effect.context();
|
|
189
|
+
/** A hook's throw, reported on what the loop was built with: its failure path. */
|
|
190
|
+
const hookFailed = (defect) => {
|
|
191
|
+
Effect.runForkWith(buildContext)(Report.failure("wardic.frameLoop: an afterTick hook failed", Cause.die(defect)));
|
|
192
|
+
};
|
|
175
193
|
// The burst's fiber (#746: what a `FiberHandle` held, in a field, so an app ships no FiberHandle): a
|
|
176
194
|
// new burst's replaces it, interrupting it, and the loop's Scope interrupts it and lets it go. Once
|
|
177
195
|
// that Scope has closed, the loop takes no run (`entered`), as the handle's closed state had it.
|
|
@@ -207,13 +225,39 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
207
225
|
// is held (#81).
|
|
208
226
|
let bursting = false;
|
|
209
227
|
// The Late window (ADR-0027 *Amendment (#680)*): open from a tick's first step until the microtask
|
|
210
|
-
// queued at its end has run. `
|
|
228
|
+
// queued at its end has run. `lateWindowQueued` keeps one microtask per window, however many ticks open
|
|
211
229
|
// it before a checkpoint (a test firing frames back to back).
|
|
212
|
-
let
|
|
213
|
-
let
|
|
230
|
+
let lateWindowOpen = false;
|
|
231
|
+
let lateWindowQueued = false;
|
|
214
232
|
// The dt of the tick that opened the window: a Late step's. A nominal frame before any tick, for a
|
|
215
233
|
// window a hint opens while idle (#791).
|
|
216
|
-
let
|
|
234
|
+
let tickDt = Clock.NOMINAL_DT;
|
|
235
|
+
// The ticks run, for `tickCount` (#991): one add a tick.
|
|
236
|
+
let ticked = 0;
|
|
237
|
+
// A late frame, as the Environment tells one (#1026, `Clock.LateFrames`): the line, in ms, `NaN` for
|
|
238
|
+
// none. Telling one, each tick reads its frame's timestamp and when it ran, on the Clock's `now()`, and
|
|
239
|
+
// how late it is by its lag, in seconds (`tickLateByLag`); a hint's window while the loop idles tells nothing.
|
|
240
|
+
const lateAfter = lateAfterOf(yield* Clock.LateFrames);
|
|
241
|
+
const tellsLate = !Number.isNaN(lateAfter);
|
|
242
|
+
let tickLateByLag = 0;
|
|
243
|
+
let lastStamp = Number.NaN;
|
|
244
|
+
// The frames' interval (`frameInterval`), once a tick, from the last five gaps between their timestamps, and
|
|
245
|
+
// how late the tick's frame is by its gap (`tickLateByGap`), in seconds (`FirstSteps.intervalOf`, `lateByGap`;
|
|
246
|
+
// #1048, #1050). The time between
|
|
247
|
+
// bursts is no frame's gap: a burst's first tick times none (`gapFrom` is `NaN` from its start), nor does a
|
|
248
|
+
// frame that repeats the one before's timestamp. A gap the loop hasn't timed is a 60 Hz frame's.
|
|
249
|
+
let gapFrom = Number.NaN;
|
|
250
|
+
// The four gaps before the tick's, newest first.
|
|
251
|
+
let gapBefore1 = FirstSteps.NOMINAL_FRAME_MS;
|
|
252
|
+
let gapBefore2 = FirstSteps.NOMINAL_FRAME_MS;
|
|
253
|
+
let gapBefore3 = FirstSteps.NOMINAL_FRAME_MS;
|
|
254
|
+
let gapBefore4 = FirstSteps.NOMINAL_FRAME_MS;
|
|
255
|
+
let frameInterval = Clock.NOMINAL_DT;
|
|
256
|
+
let tickLateByGap = 0;
|
|
257
|
+
// Whether the tick is stepping its runs now (#1028): a step in its window after them is a Late step, the
|
|
258
|
+
// loop's own or one a run takes there itself (the projection's after-tick step), and a member made in the
|
|
259
|
+
// window owes it none of the window's frame, whose dt it takes.
|
|
260
|
+
let tickStepping = false;
|
|
217
261
|
// The `run` runs added in the window, in add order: their Late step is due. The `runLast` runs added
|
|
218
262
|
// in it take none, and are marked only so the dt-0 step leaves them out: they step at the next tick.
|
|
219
263
|
const lateFirst = [];
|
|
@@ -249,9 +293,64 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
249
293
|
};
|
|
250
294
|
// The loop's own hook, the first: the counts reach the counters at the end of every tick, and
|
|
251
295
|
// `tick`, the per-frame path, is as it was (#542).
|
|
252
|
-
hooks = [{ hook: countEnds }];
|
|
296
|
+
hooks = [{ hook: countEnds, failing: false }];
|
|
253
297
|
// Per frame (ADR-0025): plain calls only, in the one `Stream.map` call per tick (ADR-0027,
|
|
254
298
|
// decision 8); counted loops, statement `if`s, a `try` per entry (it costs nothing measurable).
|
|
299
|
+
/**
|
|
300
|
+
* The tick's frame, told late or on time (#1026): late by its lag once its callback ran past the line after
|
|
301
|
+
* its timestamp, a long task delaying it (`FirstSteps.lateByLag`). A frame that repeats the one before's
|
|
302
|
+
* timestamp (a runtime's second frame after an input), which the Clock times by `now()`, is on time. Its gap
|
|
303
|
+
* from the frame before, in a burst, times the frames' interval, and tells whether a long task delayed it,
|
|
304
|
+
* however it's stamped (`FirstSteps.lateByGap`). Once a tick, where late frames are told: the rule's numbers come from
|
|
305
|
+
* `FirstSteps`, and this keeps them.
|
|
306
|
+
*/
|
|
307
|
+
// A repeated timestamp: Firefox's frame right after an input (#18; ADR-0017, amended by #2).
|
|
308
|
+
const tellLate = () => {
|
|
309
|
+
const stamp = clock.frameAt();
|
|
310
|
+
tickLateByLag = 0;
|
|
311
|
+
if (stamp !== lastStamp)
|
|
312
|
+
tickLateByLag = FirstSteps.lateByLag(clock.now() - stamp, lateAfter) / 1000;
|
|
313
|
+
tickLateByGap = 0;
|
|
314
|
+
const gap = stamp - gapFrom;
|
|
315
|
+
if (gap > 0) {
|
|
316
|
+
const interval = FirstSteps.intervalOf(gap, gapBefore1, gapBefore2, gapBefore3, gapBefore4);
|
|
317
|
+
tickLateByGap = FirstSteps.lateByGap(gap, interval) / 1000;
|
|
318
|
+
frameInterval = interval / 1000;
|
|
319
|
+
gapBefore4 = gapBefore3;
|
|
320
|
+
gapBefore3 = gapBefore2;
|
|
321
|
+
gapBefore2 = gapBefore1;
|
|
322
|
+
gapBefore1 = gap;
|
|
323
|
+
}
|
|
324
|
+
gapFrom = stamp;
|
|
325
|
+
lastStamp = stamp;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* The loop's ticks as the rule reads them (`FirstSteps`): its own entries' dt, and a run's that keeps the
|
|
329
|
+
* rule per member, a Batch's, carried on the service (#1028). Its reads are the loop's own fields.
|
|
330
|
+
*/
|
|
331
|
+
const reader = {
|
|
332
|
+
madeOwing: () => {
|
|
333
|
+
if (!tellsLate)
|
|
334
|
+
return 0;
|
|
335
|
+
if (lateWindowOpen)
|
|
336
|
+
return FirstSteps.madeOwing(tickLateByLag);
|
|
337
|
+
return FirstSteps.madeOwing(0);
|
|
338
|
+
},
|
|
339
|
+
owingDt: (owed, dt) => FirstSteps.owingDt(owed, dt, lateWindowOpen && !tickStepping, tickLateByGap, frameInterval),
|
|
340
|
+
owedAfter: (owed) => FirstSteps.owedAfter(owed, tickLateByLag),
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* The dt `entry` steps at (#1026): the tick's, but a run takes none of a long task's time from before it
|
|
344
|
+
* began (`FirstSteps`). What was running catches up, as before; a run on the frame timeline keeps the
|
|
345
|
+
* ticks' dt. Per frame: a field read, and nothing made.
|
|
346
|
+
*/
|
|
347
|
+
const dtOf = (entry, dt) => {
|
|
348
|
+
const owed = entry.owed;
|
|
349
|
+
if (owed === 0)
|
|
350
|
+
return dt;
|
|
351
|
+
entry.owed = reader.owedAfter(owed);
|
|
352
|
+
return reader.owingDt(owed, dt);
|
|
353
|
+
};
|
|
255
354
|
/**
|
|
256
355
|
* Step the last lane's first `count` entries, in add order, as `tick` steps the others. Per frame,
|
|
257
356
|
* and only while it holds a run.
|
|
@@ -262,8 +361,9 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
262
361
|
if (entry.removed)
|
|
263
362
|
continue;
|
|
264
363
|
try {
|
|
265
|
-
const
|
|
266
|
-
entry.
|
|
364
|
+
const at = dtOf(entry, dt);
|
|
365
|
+
const frame = entry.step(at);
|
|
366
|
+
entry.sink(frame, at);
|
|
267
367
|
if (entry.settles && frame.done)
|
|
268
368
|
end(entry, Exit.succeed(frame));
|
|
269
369
|
}
|
|
@@ -288,12 +388,15 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
288
388
|
// The first lane's loops stay inline in `tick`: moved into a function shared with the last lane,
|
|
289
389
|
// Node's `chase/loop` ran 55% slower (`bench:core`, ADR-0027 *Amendment (#137)*).
|
|
290
390
|
const tick = (dt) => {
|
|
391
|
+
ticked++;
|
|
291
392
|
// A window this tick finds open is the last frame's, its checkpoint not yet run (back-to-back
|
|
292
393
|
// frames in a test): its runs are on the lanes, so this tick steps them.
|
|
293
394
|
if (lateFirst.length + lateLast.length > 0)
|
|
294
395
|
dropLate();
|
|
295
|
-
|
|
296
|
-
|
|
396
|
+
lateWindowOpen = true;
|
|
397
|
+
tickDt = dt;
|
|
398
|
+
if (tellsLate)
|
|
399
|
+
tellLate();
|
|
297
400
|
// The tick's start, read only for the metrics' histogram (#518).
|
|
298
401
|
let t0 = 0;
|
|
299
402
|
if (Predicate.isNotUndefined(metrics))
|
|
@@ -302,13 +405,15 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
302
405
|
// Late step at the window's end, a `runLast` run waits for the next tick (#680).
|
|
303
406
|
const count = entries.length;
|
|
304
407
|
const lastCount = lastEntries.length;
|
|
408
|
+
tickStepping = true;
|
|
305
409
|
for (let i = 0; i < count; i++) {
|
|
306
410
|
const entry = entries[i];
|
|
307
411
|
if (entry.removed)
|
|
308
412
|
continue;
|
|
309
413
|
try {
|
|
310
|
-
const
|
|
311
|
-
entry.
|
|
414
|
+
const at = dtOf(entry, dt);
|
|
415
|
+
const frame = entry.step(at);
|
|
416
|
+
entry.sink(frame, at);
|
|
312
417
|
if (entry.settles && frame.done)
|
|
313
418
|
end(entry, Exit.succeed(frame));
|
|
314
419
|
}
|
|
@@ -319,6 +424,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
319
424
|
// The last lane, after every other run (ADR-0027, *Amendment (#137)*).
|
|
320
425
|
if (lastCount > 0)
|
|
321
426
|
stepLast(lastCount, dt);
|
|
427
|
+
tickStepping = false;
|
|
322
428
|
// Drop the removed entries in place, keeping order (and those added during the pass).
|
|
323
429
|
let kept = 0;
|
|
324
430
|
for (let i = 0; i < entries.length; i++) {
|
|
@@ -337,12 +443,25 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
337
443
|
}
|
|
338
444
|
// The end of the tick: everything for this Refresh frame is written (ADR-0033). After
|
|
339
445
|
// `tickMs`, which stays the cost of the steps alone.
|
|
446
|
+
// Each hook's own (#979, ADR-0074): one that throws is reported once until a call returns, and the
|
|
447
|
+
// others run. A try per hook, around its direct call, its flag cleared only when it's set.
|
|
340
448
|
const ended = hooks;
|
|
341
|
-
for (let i = 0; i < ended.length; i++)
|
|
342
|
-
ended[i]
|
|
449
|
+
for (let i = 0; i < ended.length; i++) {
|
|
450
|
+
const added = ended[i];
|
|
451
|
+
try {
|
|
452
|
+
added.hook(dt);
|
|
453
|
+
if (added.failing)
|
|
454
|
+
added.failing = false;
|
|
455
|
+
}
|
|
456
|
+
catch (defect) {
|
|
457
|
+
if (!added.failing)
|
|
458
|
+
hookFailed(defect);
|
|
459
|
+
added.failing = true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
343
462
|
// The window stays open to the end of this frame's microtasks, which take the Late steps (#680).
|
|
344
|
-
if (!
|
|
345
|
-
|
|
463
|
+
if (!lateWindowQueued) {
|
|
464
|
+
lateWindowQueued = true;
|
|
346
465
|
queueMicrotask(endLateWindow);
|
|
347
466
|
}
|
|
348
467
|
// The burst ends with no run left, counted after the hooks: one a hook started (the flush
|
|
@@ -365,11 +484,14 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
365
484
|
list[i] = list[i + count];
|
|
366
485
|
list.length = left;
|
|
367
486
|
};
|
|
368
|
-
/**
|
|
369
|
-
|
|
487
|
+
/**
|
|
488
|
+
* One step of `entry` at `at`: its Frame to its sink, its settle, or its defect, as a tick's. A Late
|
|
489
|
+
* step's dt is its first's; a dt-0 step leaves what it owes as it was.
|
|
490
|
+
*/
|
|
491
|
+
const stepOne = (entry, at) => {
|
|
370
492
|
try {
|
|
371
|
-
const frame = entry.step(
|
|
372
|
-
entry.sink(frame,
|
|
493
|
+
const frame = entry.step(at);
|
|
494
|
+
entry.sink(frame, at);
|
|
373
495
|
if (entry.settles && frame.done)
|
|
374
496
|
end(entry, Exit.succeed(frame));
|
|
375
497
|
}
|
|
@@ -384,7 +506,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
384
506
|
return false;
|
|
385
507
|
if (Predicate.isNotUndefined(entry.span))
|
|
386
508
|
entry.span.attribute("late", true);
|
|
387
|
-
stepOne(entry,
|
|
509
|
+
stepOne(entry, dtOf(entry, tickDt));
|
|
388
510
|
return true;
|
|
389
511
|
};
|
|
390
512
|
/**
|
|
@@ -409,16 +531,28 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
409
531
|
}
|
|
410
532
|
dropFirst(lateFirst, firstCount);
|
|
411
533
|
const again = hooks;
|
|
412
|
-
|
|
413
|
-
|
|
534
|
+
// As the tick's (#979).
|
|
535
|
+
for (let i = 0; i < again.length; i++) {
|
|
536
|
+
const added = again[i];
|
|
537
|
+
try {
|
|
538
|
+
added.hook(tickDt);
|
|
539
|
+
if (added.failing)
|
|
540
|
+
added.failing = false;
|
|
541
|
+
}
|
|
542
|
+
catch (defect) {
|
|
543
|
+
if (!added.failing)
|
|
544
|
+
hookFailed(defect);
|
|
545
|
+
added.failing = true;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
414
548
|
};
|
|
415
549
|
/**
|
|
416
550
|
* The Late window's end, the microtask its tick queued: the Late rounds, then the window closes. A run
|
|
417
551
|
* left past the cap steps at the next tick. A hook that throws ends every run, as in a tick (Q15).
|
|
418
552
|
*/
|
|
419
553
|
const endLateWindow = () => {
|
|
420
|
-
|
|
421
|
-
if (!
|
|
554
|
+
lateWindowQueued = false;
|
|
555
|
+
if (!lateWindowOpen)
|
|
422
556
|
return;
|
|
423
557
|
let rounds = 0;
|
|
424
558
|
try {
|
|
@@ -434,7 +568,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
434
568
|
// Past the cap, the first lane's rest step at the next tick; the last lane's were never due.
|
|
435
569
|
if (lateFirst.length + lateLast.length > 0)
|
|
436
570
|
dropLate();
|
|
437
|
-
|
|
571
|
+
lateWindowOpen = false;
|
|
438
572
|
};
|
|
439
573
|
/**
|
|
440
574
|
* A hook threw in a Late round, outside the burst's stream: the burst is interrupted, and its end
|
|
@@ -453,18 +587,25 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
453
587
|
const burstFiber = () => held;
|
|
454
588
|
/** A binding's hint (above): the window opened under the rule, closed by the microtask it queues. */
|
|
455
589
|
const hint = (frameTime) => {
|
|
456
|
-
if (
|
|
590
|
+
if (lateWindowOpen)
|
|
457
591
|
return;
|
|
458
592
|
if (bursting && clock.frameAt() !== frameTime)
|
|
459
593
|
return;
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
594
|
+
lateWindowOpen = true;
|
|
595
|
+
// Idle, no tick told its frame (#1026): a run made in it is told nothing late. While a burst runs, it's
|
|
596
|
+
// the frame the last tick told, which still stands (#1050).
|
|
597
|
+
if (!bursting) {
|
|
598
|
+
tickLateByLag = 0;
|
|
599
|
+
tickLateByGap = 0;
|
|
600
|
+
}
|
|
601
|
+
if (!lateWindowQueued) {
|
|
602
|
+
lateWindowQueued = true;
|
|
463
603
|
queueMicrotask(endLateWindow);
|
|
464
604
|
}
|
|
465
605
|
};
|
|
606
|
+
const tickCount = () => ticked;
|
|
466
607
|
const afterTick = (hook) => {
|
|
467
|
-
const added = { hook };
|
|
608
|
+
const added = { hook, failing: false };
|
|
468
609
|
return Effect.acquireRelease(Effect.sync(() => {
|
|
469
610
|
hooks = Arr.append(hooks, added);
|
|
470
611
|
}), () => Effect.sync(() => {
|
|
@@ -487,7 +628,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
487
628
|
// A burst that failed closes the window: no later call is in it (#673, TK3; #680). One that ran out
|
|
488
629
|
// of runs leaves it open, so a run started after its last tick, in its frame, takes its Late step.
|
|
489
630
|
if (failed) {
|
|
490
|
-
|
|
631
|
+
lateWindowOpen = false;
|
|
491
632
|
dropLate();
|
|
492
633
|
}
|
|
493
634
|
Arr.forEach(Arr.appendAll(entries.splice(0), lastEntries.splice(0)), (entry) => {
|
|
@@ -508,6 +649,8 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
508
649
|
onTrue: () => Effect.void,
|
|
509
650
|
onFalse: () => {
|
|
510
651
|
bursting = true;
|
|
652
|
+
// The time since the last burst's last frame is no frame's gap (#1048).
|
|
653
|
+
gapFrom = Number.NaN;
|
|
511
654
|
// Detached and started at once, as `FiberHandle.run` forks: no scheduler hop before the
|
|
512
655
|
// subscription, and no caller's fiber its parent.
|
|
513
656
|
return Effect.map(Effect.forkDetach(ticking, START_NOW), hold);
|
|
@@ -562,6 +705,11 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
562
705
|
let checkedSink = sink;
|
|
563
706
|
if (check)
|
|
564
707
|
checkedSink = checked(sink);
|
|
708
|
+
// What it owes of its first frames' lateness (#1026), where late frames are told and it isn't on the
|
|
709
|
+
// frame timeline: its first step owed, made in a window or not.
|
|
710
|
+
let owed = 0;
|
|
711
|
+
if (tellsLate && !onFrameTimeline(options))
|
|
712
|
+
owed = reader.madeOwing();
|
|
565
713
|
const entry = {
|
|
566
714
|
name: machine.span.name,
|
|
567
715
|
step: machine.start(),
|
|
@@ -569,17 +717,20 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
569
717
|
settles: machine.settles,
|
|
570
718
|
settled: Deferred.makeUnsafe(),
|
|
571
719
|
removed: false,
|
|
572
|
-
late:
|
|
720
|
+
late: lateWindowOpen,
|
|
573
721
|
span,
|
|
722
|
+
owed,
|
|
574
723
|
};
|
|
575
724
|
lane.push(entry);
|
|
576
725
|
if (entry.late)
|
|
577
726
|
late.push(entry);
|
|
578
|
-
if (Predicate.isNotUndefined(options))
|
|
727
|
+
if (Predicate.isNotUndefined(options) && Predicate.isNotUndefined(options.supersede))
|
|
579
728
|
joinSupersede(options.supersede, entry);
|
|
580
729
|
return Effect.as(startBurst, entry);
|
|
581
730
|
};
|
|
582
|
-
const inLateWindow = () =>
|
|
583
|
-
|
|
731
|
+
const inLateWindow = () => lateWindowOpen;
|
|
732
|
+
const shape = { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, tickCount, hint };
|
|
733
|
+
// Its `Reader`, carried beside the stable shape (#1028): a Batch keeps the rule per member by it.
|
|
734
|
+
return FirstSteps.carrying(shape, reader);
|
|
584
735
|
}, (self) => traced(self, "wardic.frameloop.make"));
|
|
585
736
|
//# sourceMappingURL=frameLoop.js.map
|