@wardic/core 1.3.2 → 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 +15 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +218 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +7 -7
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +17 -16
- 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 +5 -4
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +37 -14
- 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 +1 -1
- package/dist/InputFeed.js +2 -2
- 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 +7 -6
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +45 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +7 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +146 -45
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +6 -1
- 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 +1 -1
- package/dist/Recognizer.js +6 -6
- 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 +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +102 -81
- package/dist/internal/frameLoop.js.map +1 -1
- 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 +13 -2
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -1
- 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 +37 -38
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +39 -36
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +5 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +19 -19
- package/dist/unstable/Config.d.ts.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 +53 -51
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +56 -49
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +2 -2
- package/dist/unstable/FrameEffects.js +2 -2
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +29 -9
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +79 -47
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +26 -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 +1 -1
- package/dist/unstable/Report.js +1 -1
- package/dist/unstable/RetargetLegs.d.ts +1 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +9 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +81 -72
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +152 -150
- 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 +7 -7
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +11 -11
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +36 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +33 -33
- 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 +236 -22
- package/src/Clock.ts +18 -17
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +41 -16
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +47 -17
- package/src/Machine.ts +199 -61
- package/src/Playback.ts +5 -1
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +7 -7
- 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 +103 -87
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +20 -2
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +59 -56
- package/src/unstable/AppearHandoff.ts +6 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +19 -19
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +92 -82
- package/src/unstable/FrameEffects.ts +2 -2
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +126 -56
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +29 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +1 -1
- package/src/unstable/RetargetLegs.ts +10 -9
- package/src/unstable/Spine.ts +190 -188
- 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 +13 -13
- package/src/unstable/VariantTree.ts +42 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
import * as Option from "effect/Option";
|
|
18
|
+
/** A 60 Hz frame, in ms: the Frame loop takes one for a gap it hasn't timed. */
|
|
19
|
+
export declare const NOMINAL_FRAME_MS: number;
|
|
20
|
+
/**
|
|
21
|
+
* The frames' interval, in ms, from the last five gaps between their timestamps, `gap` and the four before it,
|
|
22
|
+
* newest first: their median, so neither a late frame's long gap nor a short one after it moves it, and a 30 Hz
|
|
23
|
+
* frame at most.
|
|
24
|
+
*/
|
|
25
|
+
export declare const intervalOf: (gap: number, before1: number, before2: number, before3: number, before4: number) => number;
|
|
26
|
+
/** 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. */
|
|
27
|
+
export declare const lateByLag: (lag: number, line: number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* How late a frame `gap` ms after the one before is by its gap, in ms, on frames `interval` ms apart: what its gap
|
|
30
|
+
* is longer than one interval, once that's more than half of one; else 0.
|
|
31
|
+
*/
|
|
32
|
+
export declare const lateByGap: (gap: number, interval: number) => number;
|
|
33
|
+
/** What a run made now owes: its first step, made in a frame `madeLate` seconds late by its lag, or in one on time. */
|
|
34
|
+
export declare const madeOwing: (madeLate: number) => number;
|
|
35
|
+
/**
|
|
36
|
+
* The dt of a step of a run that owes `owed` (not 0), in a frame `lateByGap` seconds late by its gap, on frames
|
|
37
|
+
* `interval` seconds apart: its second, `dt` less its first frame's lateness by its lag; its first, `dt` less its
|
|
38
|
+
* 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
|
|
39
|
+
* Late window and stepped at a later tick, whichever is more, and one interval at least. That frame's own Late
|
|
40
|
+
* step leaves only `lateByGap` out: its dt doesn't hold the frame's lateness by its lag.
|
|
41
|
+
*/
|
|
42
|
+
export declare const owingDt: (owed: number, dt: number, lateStep: boolean, lateByGap: number, interval: number) => number;
|
|
43
|
+
/** 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. */
|
|
44
|
+
export declare const owedAfter: (owed: number, lateByLag: number) => number;
|
|
45
|
+
/**
|
|
46
|
+
* The Frame loop's ticks as the rule reads them, for a run that keeps it per member: what one made now owes,
|
|
47
|
+
* and the dt of a step of one that owes, in the tick or Late step running now. Stateless: it reads the loop.
|
|
48
|
+
*/
|
|
49
|
+
export interface Reader {
|
|
50
|
+
/** What a member made now owes (`madeOwing`): 0, nothing, where the loop tells no late frame. */
|
|
51
|
+
readonly madeOwing: () => number;
|
|
52
|
+
/**
|
|
53
|
+
* The dt of a step, now, of a member that owes `owed` (not 0): `owingDt`'s. A step in a tick's Late window,
|
|
54
|
+
* after its steps, is a Late step: the loop's own, or one a run takes there itself.
|
|
55
|
+
*/
|
|
56
|
+
readonly owingDt: (owed: number, dt: number) => number;
|
|
57
|
+
/** What a member that owed `owed` owes after its step now: `owedAfter`'s. */
|
|
58
|
+
readonly owedAfter: (owed: number) => number;
|
|
59
|
+
}
|
|
60
|
+
/** A `Reader` under which nothing owes: for a loop that carries none, so its runs step at the tick's dt. */
|
|
61
|
+
export declare const owingNothing: Reader;
|
|
62
|
+
/** `loop`, carrying `reader`. */
|
|
63
|
+
export declare const carrying: <L extends object>(loop: L, reader: Reader) => L;
|
|
64
|
+
/** The `Reader` `loop` carries: `None` for a loop that carries none (one a test makes of its own). */
|
|
65
|
+
export declare const readerOf: (loop: object) => Option.Option<Reader>;
|
|
66
|
+
//# sourceMappingURL=firstSteps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firstSteps.d.ts","sourceRoot":"","sources":["../../src/internal/firstSteps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAQvC,gFAAgF;AAChF,eAAO,MAAM,gBAAgB,QAA0B,CAAA;AAQvD;;;;GAIG;AAGH,eAAO,MAAM,UAAU,QAAS,MAAM,WAAW,MAAM,WAAW,MAAM,WAAW,MAAM,WAAW,MAAM,KAAG,MAI1G,CAAA;AAEH,6HAA6H;AAC7H,eAAO,MAAM,SAAS,QAAS,MAAM,QAAQ,MAAM,KAAG,MAGrD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,YAAY,MAAM,KAAG,MAIzD,CAAA;AAED,uHAAuH;AACvH,eAAO,MAAM,SAAS,aAAc,MAAM,KAAG,MAG5C,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,SAAU,MAAM,MAAM,MAAM,YAAY,OAAO,aAAa,MAAM,YAAY,MAAM,KAAG,MAG1G,CAAA;AAYD,yIAAyI;AACzI,eAAO,MAAM,SAAS,SAAU,MAAM,aAAa,MAAM,KAAG,MAG3D,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,iGAAiG;IACjG,QAAQ,CAAC,SAAS,EAAE,MAAM,MAAM,CAAA;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,CAAA;IACtD,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7C;AAED,4GAA4G;AAC5G,eAAO,MAAM,YAAY,EAAE,MAI1B,CAAA;AAWD,iCAAiC;AACjC,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,UAAU,MAAM,KAAG,CAA6B,CAAA;AAElG,sGAAsG;AACtG,eAAO,MAAM,QAAQ,SAAU,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAmC,CAAA"}
|
|
@@ -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","sourceRoot":"","sources":["../../src/internal/firstSteps.ts"],"names":[],"mappings":"AAAA;;;;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tick, as a binding that renders in a frame callback of its own does (ADR-0071 decision 32).
|
|
64
64
|
* Opens the **Late window** when a burst's last tick was this frame's (`Clock.frameAt`) or no burst runs
|
|
65
65
|
* (no tick is coming this frame), so the runs added after it, in the rest of the callback and its
|
|
66
|
-
* 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
|
|
67
67
|
* tick still to come in the frame, nothing: that tick is their first step. Idle, the Late step's dt is
|
|
68
68
|
* the last tick's, or a nominal frame before any.
|
|
69
69
|
*/
|
|
@@ -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,CAA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,EAAE,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
|
|
@@ -75,6 +75,7 @@ import * as UndefinedOr from "effect/UndefinedOr";
|
|
|
75
75
|
import * as Clock from "../Clock.js";
|
|
76
76
|
import * as Supersede from "../Supersede.js";
|
|
77
77
|
import * as Report from "../unstable/Report.js";
|
|
78
|
+
import * as FirstSteps from "./firstSteps.js";
|
|
78
79
|
import { none, SpansGiven, traced } from "./tracing.js";
|
|
79
80
|
/** How many Late rounds a window runs before the rest wait for the next tick: the Measure pass's cap (#680). */
|
|
80
81
|
const MAX_LATE_ROUNDS = 5;
|
|
@@ -90,8 +91,6 @@ const onFrameTimeline = (options) => {
|
|
|
90
91
|
return false;
|
|
91
92
|
return options.onFrameTimeline === true;
|
|
92
93
|
};
|
|
93
|
-
/** `dt`, less `left` seconds left out of it: a nominal frame at least, and never more than `dt`. */
|
|
94
|
-
const leavingOut = (dt, left) => Math.min(dt, Math.max(dt - left, Clock.NOMINAL_DT));
|
|
95
94
|
/**
|
|
96
95
|
* Where a run's fiber finds the metrics. The loop takes them from the first run that has them: an app
|
|
97
96
|
* gives them beside its Environment, which the loop's own build doesn't see, as `CheckFrames` is read.
|
|
@@ -226,23 +225,39 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
226
225
|
// is held (#81).
|
|
227
226
|
let bursting = false;
|
|
228
227
|
// The Late window (ADR-0027 *Amendment (#680)*): open from a tick's first step until the microtask
|
|
229
|
-
// queued at its end has run. `
|
|
228
|
+
// queued at its end has run. `lateWindowQueued` keeps one microtask per window, however many ticks open
|
|
230
229
|
// it before a checkpoint (a test firing frames back to back).
|
|
231
|
-
let
|
|
232
|
-
let
|
|
230
|
+
let lateWindowOpen = false;
|
|
231
|
+
let lateWindowQueued = false;
|
|
233
232
|
// The dt of the tick that opened the window: a Late step's. A nominal frame before any tick, for a
|
|
234
233
|
// window a hint opens while idle (#791).
|
|
235
|
-
let
|
|
234
|
+
let tickDt = Clock.NOMINAL_DT;
|
|
236
235
|
// The ticks run, for `tickCount` (#991): one add a tick.
|
|
237
236
|
let ticked = 0;
|
|
238
237
|
// A late frame, as the Environment tells one (#1026, `Clock.LateFrames`): the line, in ms, `NaN` for
|
|
239
238
|
// none. Telling one, each tick reads its frame's timestamp and when it ran, on the Clock's `now()`, and
|
|
240
|
-
//
|
|
239
|
+
// how late it is by its lag, in seconds (`tickLateByLag`); a hint's window while the loop idles tells nothing.
|
|
241
240
|
const lateAfter = lateAfterOf(yield* Clock.LateFrames);
|
|
242
241
|
const tellsLate = !Number.isNaN(lateAfter);
|
|
243
|
-
let
|
|
244
|
-
let windowLate = 0;
|
|
242
|
+
let tickLateByLag = 0;
|
|
245
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;
|
|
246
261
|
// The `run` runs added in the window, in add order: their Late step is due. The `runLast` runs added
|
|
247
262
|
// in it take none, and are marked only so the dt-0 step leaves them out: they step at the next tick.
|
|
248
263
|
const lateFirst = [];
|
|
@@ -282,54 +297,59 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
282
297
|
// Per frame (ADR-0025): plain calls only, in the one `Stream.map` call per tick (ADR-0027,
|
|
283
298
|
// decision 8); counted loops, statement `if`s, a `try` per entry (it costs nothing measurable).
|
|
284
299
|
/**
|
|
285
|
-
* The tick's frame, told late or on time (#1026): late once its callback ran past the line after
|
|
286
|
-
* timestamp, a long task
|
|
287
|
-
* an input), which the Clock times by `now()`, is on time.
|
|
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.
|
|
288
306
|
*/
|
|
307
|
+
// A repeated timestamp: Firefox's frame right after an input (#18; ADR-0017, amended by #2).
|
|
289
308
|
const tellLate = () => {
|
|
290
309
|
const stamp = clock.frameAt();
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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;
|
|
295
325
|
lastStamp = stamp;
|
|
296
|
-
|
|
297
|
-
|
|
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),
|
|
298
341
|
};
|
|
299
342
|
/**
|
|
300
343
|
* The dt `entry` steps at (#1026): the tick's, but a run takes none of a long task's time from before it
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* frame was held of its second step; one made in that frame's Late window and first stepped at the next
|
|
304
|
-
* tick, of its first; and one that waited past the line for its first frame (Motion's
|
|
305
|
-
* `MAX_START_DELAY`, however its frame is stamped) begins there, a 60 Hz frame at most. What was
|
|
306
|
-
* running catches up, as before; a run on the frame timeline keeps the ticks' dt. Per frame: a field
|
|
307
|
-
* read, and nothing made.
|
|
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.
|
|
308
346
|
*/
|
|
309
347
|
const dtOf = (entry, dt) => {
|
|
310
348
|
const owed = entry.owed;
|
|
311
349
|
if (owed === 0)
|
|
312
350
|
return dt;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return leavingOut(dt, owed);
|
|
316
|
-
}
|
|
317
|
-
return firstDt(entry, dt, entry.madeLate);
|
|
318
|
-
};
|
|
319
|
-
/** A run's first step (`owed` `NaN`): what of its frame a long task held, owed to its second; `before` left out. */
|
|
320
|
-
const firstDt = (entry, dt, before) => {
|
|
321
|
-
entry.owed = windowLate;
|
|
322
|
-
if (windowRanAt - entry.madeAt > lateAfter)
|
|
323
|
-
return Math.min(dt, Clock.NOMINAL_DT);
|
|
324
|
-
if (before > 0)
|
|
325
|
-
return leavingOut(dt, before);
|
|
326
|
-
return dt;
|
|
327
|
-
};
|
|
328
|
-
/** A Late step's dt: its first step, in the window it was made in, with nothing of the window's left out. */
|
|
329
|
-
const lateDtOf = (entry, dt) => {
|
|
330
|
-
if (entry.owed === 0)
|
|
331
|
-
return dt;
|
|
332
|
-
return firstDt(entry, dt, 0);
|
|
351
|
+
entry.owed = reader.owedAfter(owed);
|
|
352
|
+
return reader.owingDt(owed, dt);
|
|
333
353
|
};
|
|
334
354
|
/**
|
|
335
355
|
* Step the last lane's first `count` entries, in add order, as `tick` steps the others. Per frame,
|
|
@@ -373,8 +393,8 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
373
393
|
// frames in a test): its runs are on the lanes, so this tick steps them.
|
|
374
394
|
if (lateFirst.length + lateLast.length > 0)
|
|
375
395
|
dropLate();
|
|
376
|
-
|
|
377
|
-
|
|
396
|
+
lateWindowOpen = true;
|
|
397
|
+
tickDt = dt;
|
|
378
398
|
if (tellsLate)
|
|
379
399
|
tellLate();
|
|
380
400
|
// The tick's start, read only for the metrics' histogram (#518).
|
|
@@ -385,6 +405,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
385
405
|
// Late step at the window's end, a `runLast` run waits for the next tick (#680).
|
|
386
406
|
const count = entries.length;
|
|
387
407
|
const lastCount = lastEntries.length;
|
|
408
|
+
tickStepping = true;
|
|
388
409
|
for (let i = 0; i < count; i++) {
|
|
389
410
|
const entry = entries[i];
|
|
390
411
|
if (entry.removed)
|
|
@@ -403,6 +424,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
403
424
|
// The last lane, after every other run (ADR-0027, *Amendment (#137)*).
|
|
404
425
|
if (lastCount > 0)
|
|
405
426
|
stepLast(lastCount, dt);
|
|
427
|
+
tickStepping = false;
|
|
406
428
|
// Drop the removed entries in place, keeping order (and those added during the pass).
|
|
407
429
|
let kept = 0;
|
|
408
430
|
for (let i = 0; i < entries.length; i++) {
|
|
@@ -438,8 +460,8 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
438
460
|
}
|
|
439
461
|
}
|
|
440
462
|
// The window stays open to the end of this frame's microtasks, which take the Late steps (#680).
|
|
441
|
-
if (!
|
|
442
|
-
|
|
463
|
+
if (!lateWindowQueued) {
|
|
464
|
+
lateWindowQueued = true;
|
|
443
465
|
queueMicrotask(endLateWindow);
|
|
444
466
|
}
|
|
445
467
|
// The burst ends with no run left, counted after the hooks: one a hook started (the flush
|
|
@@ -464,7 +486,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
464
486
|
};
|
|
465
487
|
/**
|
|
466
488
|
* One step of `entry` at `at`: its Frame to its sink, its settle, or its defect, as a tick's. A Late
|
|
467
|
-
* step's dt is its first's
|
|
489
|
+
* step's dt is its first's; a dt-0 step leaves what it owes as it was.
|
|
468
490
|
*/
|
|
469
491
|
const stepOne = (entry, at) => {
|
|
470
492
|
try {
|
|
@@ -484,7 +506,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
484
506
|
return false;
|
|
485
507
|
if (Predicate.isNotUndefined(entry.span))
|
|
486
508
|
entry.span.attribute("late", true);
|
|
487
|
-
stepOne(entry,
|
|
509
|
+
stepOne(entry, dtOf(entry, tickDt));
|
|
488
510
|
return true;
|
|
489
511
|
};
|
|
490
512
|
/**
|
|
@@ -513,7 +535,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
513
535
|
for (let i = 0; i < again.length; i++) {
|
|
514
536
|
const added = again[i];
|
|
515
537
|
try {
|
|
516
|
-
added.hook(
|
|
538
|
+
added.hook(tickDt);
|
|
517
539
|
if (added.failing)
|
|
518
540
|
added.failing = false;
|
|
519
541
|
}
|
|
@@ -529,8 +551,8 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
529
551
|
* left past the cap steps at the next tick. A hook that throws ends every run, as in a tick (Q15).
|
|
530
552
|
*/
|
|
531
553
|
const endLateWindow = () => {
|
|
532
|
-
|
|
533
|
-
if (!
|
|
554
|
+
lateWindowQueued = false;
|
|
555
|
+
if (!lateWindowOpen)
|
|
534
556
|
return;
|
|
535
557
|
let rounds = 0;
|
|
536
558
|
try {
|
|
@@ -546,7 +568,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
546
568
|
// Past the cap, the first lane's rest step at the next tick; the last lane's were never due.
|
|
547
569
|
if (lateFirst.length + lateLast.length > 0)
|
|
548
570
|
dropLate();
|
|
549
|
-
|
|
571
|
+
lateWindowOpen = false;
|
|
550
572
|
};
|
|
551
573
|
/**
|
|
552
574
|
* A hook threw in a Late round, outside the burst's stream: the burst is interrupted, and its end
|
|
@@ -565,16 +587,19 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
565
587
|
const burstFiber = () => held;
|
|
566
588
|
/** A binding's hint (above): the window opened under the rule, closed by the microtask it queues. */
|
|
567
589
|
const hint = (frameTime) => {
|
|
568
|
-
if (
|
|
590
|
+
if (lateWindowOpen)
|
|
569
591
|
return;
|
|
570
592
|
if (bursting && clock.frameAt() !== frameTime)
|
|
571
593
|
return;
|
|
572
|
-
|
|
573
|
-
//
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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;
|
|
578
603
|
queueMicrotask(endLateWindow);
|
|
579
604
|
}
|
|
580
605
|
};
|
|
@@ -603,7 +628,7 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
603
628
|
// A burst that failed closes the window: no later call is in it (#673, TK3; #680). One that ran out
|
|
604
629
|
// of runs leaves it open, so a run started after its last tick, in its frame, takes its Late step.
|
|
605
630
|
if (failed) {
|
|
606
|
-
|
|
631
|
+
lateWindowOpen = false;
|
|
607
632
|
dropLate();
|
|
608
633
|
}
|
|
609
634
|
Arr.forEach(Arr.appendAll(entries.splice(0), lastEntries.splice(0)), (entry) => {
|
|
@@ -624,6 +649,8 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
624
649
|
onTrue: () => Effect.void,
|
|
625
650
|
onFalse: () => {
|
|
626
651
|
bursting = true;
|
|
652
|
+
// The time since the last burst's last frame is no frame's gap (#1048).
|
|
653
|
+
gapFrom = Number.NaN;
|
|
627
654
|
// Detached and started at once, as `FiberHandle.run` forks: no scheduler hop before the
|
|
628
655
|
// subscription, and no caller's fiber its parent.
|
|
629
656
|
return Effect.map(Effect.forkDetach(ticking, START_NOW), hold);
|
|
@@ -678,17 +705,11 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
678
705
|
let checkedSink = sink;
|
|
679
706
|
if (check)
|
|
680
707
|
checkedSink = checked(sink);
|
|
681
|
-
// What
|
|
682
|
-
// frame timeline:
|
|
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.
|
|
683
710
|
let owed = 0;
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if (tellsLate && !onFrameTimeline(options)) {
|
|
687
|
-
owed = Number.NaN;
|
|
688
|
-
madeAt = clock.now();
|
|
689
|
-
if (windowOpen)
|
|
690
|
-
madeLate = windowLate;
|
|
691
|
-
}
|
|
711
|
+
if (tellsLate && !onFrameTimeline(options))
|
|
712
|
+
owed = reader.madeOwing();
|
|
692
713
|
const entry = {
|
|
693
714
|
name: machine.span.name,
|
|
694
715
|
step: machine.start(),
|
|
@@ -696,11 +717,9 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
696
717
|
settles: machine.settles,
|
|
697
718
|
settled: Deferred.makeUnsafe(),
|
|
698
719
|
removed: false,
|
|
699
|
-
late:
|
|
720
|
+
late: lateWindowOpen,
|
|
700
721
|
span,
|
|
701
722
|
owed,
|
|
702
|
-
madeAt,
|
|
703
|
-
madeLate,
|
|
704
723
|
};
|
|
705
724
|
lane.push(entry);
|
|
706
725
|
if (entry.late)
|
|
@@ -709,7 +728,9 @@ export const make = Effect.fnUntraced(function* () {
|
|
|
709
728
|
joinSupersede(options.supersede, entry);
|
|
710
729
|
return Effect.as(startBurst, entry);
|
|
711
730
|
};
|
|
712
|
-
const inLateWindow = () =>
|
|
713
|
-
|
|
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);
|
|
714
735
|
}, (self) => traced(self, "wardic.frameloop.make"));
|
|
715
736
|
//# sourceMappingURL=frameLoop.js.map
|