@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
package/src/Batch.ts
CHANGED
|
@@ -18,24 +18,28 @@
|
|
|
18
18
|
// a member's keys at `slot * stride + k` (#663's shape); stepped by `Spring.matrixFor`'s exact step
|
|
19
19
|
// (#370), the probe's loop (`.tmp/564-canvas/perf/group.ts` on `probe/564-canvas`).
|
|
20
20
|
import * as Arr from "effect/Array"
|
|
21
|
+
import * as Cause from "effect/Cause"
|
|
22
|
+
import * as Context from "effect/Context"
|
|
21
23
|
import * as Effect from "effect/Effect"
|
|
22
24
|
import { identity } from "effect/Function"
|
|
23
25
|
import * as Inspectable from "effect/Inspectable"
|
|
24
|
-
import * as Iter from "effect/Iterable"
|
|
25
26
|
import * as Match from "effect/Match"
|
|
27
|
+
import * as Option from "effect/Option"
|
|
26
28
|
import { type Pipeable, pipeArguments } from "effect/Pipeable"
|
|
27
29
|
import * as Predicate from "effect/Predicate"
|
|
28
30
|
import type { Invariant } from "effect/Types"
|
|
29
31
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
30
32
|
import type * as Easing from "./Easing.ts"
|
|
31
33
|
import type * as Frame from "./Frame.ts"
|
|
32
|
-
import
|
|
34
|
+
import * as FrameLoop from "./FrameLoop.ts"
|
|
33
35
|
import * as Machine from "./Machine.ts"
|
|
34
36
|
import type * as Playback from "./Playback.ts"
|
|
35
37
|
import * as Scalar from "./Scalar.ts"
|
|
36
38
|
import * as Spring from "./Spring.ts"
|
|
37
39
|
import * as UnitScale from "./UnitScale.ts"
|
|
40
|
+
import * as Report from "./unstable/Report.ts"
|
|
38
41
|
import { dual } from "./internal/dual.ts"
|
|
42
|
+
import * as FirstSteps from "./internal/firstSteps.ts"
|
|
39
43
|
import { tickOf, writableOf } from "./internal/playhead.ts"
|
|
40
44
|
import { resolveKeyframes } from "./internal/keyframes.ts"
|
|
41
45
|
import { checked, fn, literals, nonNegative, positive, union } from "./internal/options.ts"
|
|
@@ -178,7 +182,7 @@ const COUNTED = 8
|
|
|
178
182
|
* `elapsed` `NaN` until then. It's in `startList`, which each step's start pass reads before the loops.
|
|
179
183
|
*/
|
|
180
184
|
const STARTS = 16
|
|
181
|
-
/** The start pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
|
|
185
|
+
/** The start pass or the owing pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
|
|
182
186
|
const STARTED = 32
|
|
183
187
|
/**
|
|
184
188
|
* Its values changed outside a step (it entered, took a new Subject, a change started it from a given value,
|
|
@@ -226,6 +230,22 @@ interface State<S> {
|
|
|
226
230
|
flags: Uint8Array
|
|
227
231
|
/** The slots a `leave` freed, the next `enter`'s. */
|
|
228
232
|
readonly free: Array<number>
|
|
233
|
+
/**
|
|
234
|
+
* What each member owes of a long task's time (`FirstSteps`): its first step (`NaN`, or less than 0 for one
|
|
235
|
+
* set off in the Late window of a frame told late by its lag), then its first frame's lateness, which its second
|
|
236
|
+
* leaves out, then 0. 0 for a member that started partway (`startAt`), which keeps the frame timeline's time, and where
|
|
237
|
+
* the Frame loop tells no late frame.
|
|
238
|
+
*/
|
|
239
|
+
owed: Float64Array
|
|
240
|
+
/** How many members owe: while none does, every member steps at the tick's dt. */
|
|
241
|
+
owing: number
|
|
242
|
+
/**
|
|
243
|
+
* What the members a run starts with owe, all alike, until its first step (`FirstSteps`), 0 after: told at
|
|
244
|
+
* that step, they owe each, or, on time, nothing.
|
|
245
|
+
*/
|
|
246
|
+
startOwing: number
|
|
247
|
+
/** The Frame loop's ticks as the late-frame rule reads them, from the Batch's first run on. */
|
|
248
|
+
ticks: FirstSteps.Reader | undefined
|
|
229
249
|
/** Each `STARTS` member's `startAt`, by slot, read once at its first step. */
|
|
230
250
|
readonly startAts: Array<((slot: number) => number) | undefined>
|
|
231
251
|
/** The `STARTS` members, in the order their changes came: the next step's start pass. */
|
|
@@ -267,10 +287,26 @@ interface State<S> {
|
|
|
267
287
|
readonly onFrame: () => void
|
|
268
288
|
/** How many steps it has taken: a driven change works its tick out once in each. */
|
|
269
289
|
frame: number
|
|
290
|
+
/** The step's dt, unclamped: a driven change that owes works its tick out of it. */
|
|
291
|
+
frameDt: number
|
|
270
292
|
/** The run stepping it now, by its number, or 0 for none. */
|
|
271
293
|
running: number
|
|
272
294
|
/** How many runs it has had: the next one's number. */
|
|
273
295
|
runs: number
|
|
296
|
+
/** What its failures are reported on: its last run's services, an empty Context before its first. */
|
|
297
|
+
services: Context.Context<never>
|
|
298
|
+
/** Whether a member's write threw in this step. */
|
|
299
|
+
writeThrewInStep: boolean
|
|
300
|
+
/** Whether a member's write throw is reported, with no step since that wrote every member clean. */
|
|
301
|
+
writeReported: boolean
|
|
302
|
+
/** Whether a member's start partway threw in this step. */
|
|
303
|
+
startThrewInStep: boolean
|
|
304
|
+
/** Whether a member's start throw is reported, with no step since that started every member clean. */
|
|
305
|
+
startReported: boolean
|
|
306
|
+
/** Whether its writer's `flush` throw is reported, with no `flush` since that returned. */
|
|
307
|
+
flushReported: boolean
|
|
308
|
+
/** Whether its `onFrame` throw is reported, with no `onFrame` since that returned. */
|
|
309
|
+
onFrameReported: boolean
|
|
274
310
|
}
|
|
275
311
|
|
|
276
312
|
const Proto = {
|
|
@@ -450,6 +486,10 @@ export const make = <S>(options: Options<S>): Batch<S> => {
|
|
|
450
486
|
movers: new Int32Array(capacity),
|
|
451
487
|
flags: new Uint8Array(capacity),
|
|
452
488
|
free: [],
|
|
489
|
+
owed: new Float64Array(capacity),
|
|
490
|
+
owing: 0,
|
|
491
|
+
startOwing: 0,
|
|
492
|
+
ticks: undefined,
|
|
453
493
|
startAts: [],
|
|
454
494
|
startList: [],
|
|
455
495
|
plainList: new Int32Array(capacity),
|
|
@@ -472,8 +512,16 @@ export const make = <S>(options: Options<S>): Batch<S> => {
|
|
|
472
512
|
flush: UndefinedOr.match(options.writer.flush, { onUndefined: () => noop, onDefined: identity }),
|
|
473
513
|
onFrame: UndefinedOr.match(options.onFrame, { onUndefined: () => noop, onDefined: identity }),
|
|
474
514
|
frame: 0,
|
|
515
|
+
frameDt: 0,
|
|
475
516
|
running: 0,
|
|
476
517
|
runs: 0,
|
|
518
|
+
services: Context.empty(),
|
|
519
|
+
writeThrewInStep: false,
|
|
520
|
+
writeReported: false,
|
|
521
|
+
startThrewInStep: false,
|
|
522
|
+
startReported: false,
|
|
523
|
+
flushReported: false,
|
|
524
|
+
onFrameReported: false,
|
|
477
525
|
}
|
|
478
526
|
// The Batch's own transitions, pinned: the first entries, rule 0 the first key's.
|
|
479
527
|
state.ownRules = rulesOf(state, options.transition, unnamedKey(state))
|
|
@@ -536,7 +584,11 @@ export const enter: {
|
|
|
536
584
|
state.subjects[slot] = subject
|
|
537
585
|
// A start a member that left never took isn't this one's.
|
|
538
586
|
// Drawn at its first step, at its start, though a delay holds it there.
|
|
539
|
-
|
|
587
|
+
const flag = (state.flags[slot] & ~(STARTS | STARTED)) | LIVE | DUE
|
|
588
|
+
state.flags[slot] = flag
|
|
589
|
+
// A slot the member before left while it moved is still in its list, stepped as a moving member's: the new
|
|
590
|
+
// one owes its first steps from now while the run goes on (#1028), as one set off is; a run's start counts it.
|
|
591
|
+
if ((flag & (IN_PLAIN | IN_RULED)) !== 0 && state.running !== 0) owes(state, slot, owingNow(state))
|
|
540
592
|
const base = slot * state.stride
|
|
541
593
|
Arr.forEach(state.keys, (key, k) => {
|
|
542
594
|
const given = start[key]
|
|
@@ -573,15 +625,16 @@ export const leave: {
|
|
|
573
625
|
if ((state.flags[slot] & LIVE) === 0) return
|
|
574
626
|
state.flags[slot] = state.flags[slot] & ~LIVE
|
|
575
627
|
state.subjects[slot] = undefined
|
|
628
|
+
owesNothing(state, slot)
|
|
576
629
|
state.free.push(slot)
|
|
577
630
|
})
|
|
578
631
|
|
|
579
632
|
/**
|
|
580
633
|
* The member at `slot` is drawn on `subject` from now on: its values, speed, targets and delays carry
|
|
581
|
-
* on as they were. For
|
|
634
|
+
* on as they were. For a Subject its framework made again for the same member.
|
|
582
635
|
*
|
|
583
636
|
* @example
|
|
584
|
-
* Batch.replace(grid, slot,
|
|
637
|
+
* Batch.replace(grid, slot, subject)
|
|
585
638
|
*/
|
|
586
639
|
export const replace: {
|
|
587
640
|
<S>(slot: number, subject: S): (self: Batch<S>) => void
|
|
@@ -628,6 +681,7 @@ const grow = <S>(state: State<S>, capacity: number): void => {
|
|
|
628
681
|
state.pending = grown(state.pending, size)
|
|
629
682
|
state.movers = grown(state.movers, capacity)
|
|
630
683
|
state.flags = grown(state.flags, capacity)
|
|
684
|
+
state.owed = grown(state.owed, capacity)
|
|
631
685
|
state.plainList = grown(state.plainList, capacity)
|
|
632
686
|
state.ruledList = grown(state.ruledList, capacity)
|
|
633
687
|
}
|
|
@@ -734,6 +788,9 @@ export const retarget: {
|
|
|
734
788
|
const driven = state.animations.size > 0
|
|
735
789
|
// Started partway (#706): each key it turns waits, `elapsed` `NaN`, for its member's first step to read where.
|
|
736
790
|
const startAt = UndefinedOr.map(options, (bag) => bag.startAt)
|
|
791
|
+
// While its run goes on, a member it sets off from rest owes its first steps (#1028), read once.
|
|
792
|
+
let owing = 0
|
|
793
|
+
if (state.running !== 0) owing = owingNow(state)
|
|
737
794
|
let fresh = 0
|
|
738
795
|
if (Predicate.isNotUndefined(startAt)) fresh = Number.NaN
|
|
739
796
|
let setOff = 0
|
|
@@ -780,7 +837,12 @@ export const retarget: {
|
|
|
780
837
|
state.startAts[slot] = startAt
|
|
781
838
|
}
|
|
782
839
|
flags[slot] = flag
|
|
783
|
-
if ((flag & (IN_PLAIN | IN_RULED)) === 0)
|
|
840
|
+
if ((flag & (IN_PLAIN | IN_RULED)) === 0) {
|
|
841
|
+
setOff++
|
|
842
|
+
// Set off from rest while its run goes on: it owes its first steps (#1028), unless its first step
|
|
843
|
+
// takes an Appear animation over (`startedPartway`). A run that starts owes its members' at its start.
|
|
844
|
+
owes(state, slot, owing)
|
|
845
|
+
}
|
|
784
846
|
// Into the ruled list, out of the plain one (which drops it at its next step); else into the plain
|
|
785
847
|
// list, if it's in neither.
|
|
786
848
|
if (ruled && (flag & IN_RULED) === 0) {
|
|
@@ -798,6 +860,139 @@ export const retarget: {
|
|
|
798
860
|
return setOff
|
|
799
861
|
})
|
|
800
862
|
|
|
863
|
+
// --- A member's first steps (#1028) ------------------------------------------------
|
|
864
|
+
//
|
|
865
|
+
// A Batch is one run on the Frame loop, on the frame timeline, so the late-frame rule a run of its own keeps
|
|
866
|
+
// (`FirstSteps`, #1026) is kept here per member: a member set off from rest takes none of a long task's time
|
|
867
|
+
// from before it moved. Per member at a change and at a run's start; per frame, only while one owes.
|
|
868
|
+
|
|
869
|
+
/** What a member or a Playhead set off now owes (`FirstSteps.madeOwing`): 0, nothing, before the Batch's first run. */
|
|
870
|
+
const owingNow = <S>(state: State<S>): number => {
|
|
871
|
+
const ticks = state.ticks
|
|
872
|
+
if (Predicate.isUndefined(ticks)) return 0
|
|
873
|
+
return ticks.madeOwing()
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** The member at `slot` owes `owing` (0, nothing). */
|
|
877
|
+
// Per member at a change, what they owe read once for all of them.
|
|
878
|
+
const owes = <S>(state: State<S>, slot: number, owing: number): void => {
|
|
879
|
+
if (owing === 0) return
|
|
880
|
+
if (state.owed[slot] === 0) state.owing = state.owing + 1
|
|
881
|
+
state.owed[slot] = owing
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** The member at `slot` owes nothing: it rests, left, or keeps the frame timeline's time. */
|
|
885
|
+
const owesNothing = <S>(state: State<S>, slot: number): void => {
|
|
886
|
+
if (state.owed[slot] === 0) return
|
|
887
|
+
state.owed[slot] = 0
|
|
888
|
+
state.owing = state.owing - 1
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** The dt now of a member or a Playhead that owes `owed`: the step's, what it owes left out, clamped. */
|
|
892
|
+
// Per member or Playhead that owes, in a step: twice a play or a set-off at most.
|
|
893
|
+
const owingDt = <S>(state: State<S>, owed: number): number => {
|
|
894
|
+
const ticks = state.ticks
|
|
895
|
+
let dt = state.frameDt
|
|
896
|
+
if (Predicate.isNotUndefined(ticks)) dt = ticks.owingDt(owed, dt)
|
|
897
|
+
return Math.min(dt, Machine.MAX_DT)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** What a member or a Playhead that owed `owed` owes after its step now. */
|
|
901
|
+
const owedAfter = <S>(state: State<S>, owed: number): number => {
|
|
902
|
+
const ticks = state.ticks
|
|
903
|
+
if (Predicate.isUndefined(ticks)) return 0
|
|
904
|
+
return ticks.owedAfter(owed)
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* A run's start: the members it starts with owe their first steps from now, all alike, kept once for the
|
|
909
|
+
* Batch (`startOwing`) until its first step tells whether they owe each. What one owed of a run before is
|
|
910
|
+
* forgotten.
|
|
911
|
+
*/
|
|
912
|
+
// Once a run: nothing per member, so a run that starts on time costs what it did.
|
|
913
|
+
const runStarts = <S>(state: State<S>): void => {
|
|
914
|
+
if (state.owing > 0) {
|
|
915
|
+
state.owed.fill(0)
|
|
916
|
+
state.owing = 0
|
|
917
|
+
}
|
|
918
|
+
state.startOwing = owingNow(state)
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* The run's first step: whether the members it started with take the tick's dt. Where they don't, each one
|
|
923
|
+
* moving owes its first steps as they did, and each change a Playhead drives its first ticks: one taking an
|
|
924
|
+
* Appear animation over (the start pass drew it) and one set off or played since, owing its own, aside.
|
|
925
|
+
*/
|
|
926
|
+
// Once a run, at its first step; per member only where that step's frame came late.
|
|
927
|
+
const startOwes = <S>(state: State<S>): void => {
|
|
928
|
+
const owing = state.startOwing
|
|
929
|
+
state.startOwing = 0
|
|
930
|
+
if (owingDt(state, owing) === Math.min(state.frameDt, Machine.MAX_DT) && owedAfter(state, owing) === 0) return
|
|
931
|
+
owesFromNow(state, state.plainList, state.plainCount, IN_PLAIN, owing)
|
|
932
|
+
owesFromNow(state, state.ruledList, state.ruledCount, IN_RULED, owing)
|
|
933
|
+
// And each change a Playhead drives that it started with, played before it, but one played since.
|
|
934
|
+
for (const animation of state.animations) {
|
|
935
|
+
if (animation.owed !== 0) continue
|
|
936
|
+
animation.owed = owing
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** Each live member of `list`'s first `count` still in it (`inList`), not drawn this step nor owing, owes as `owing`. */
|
|
941
|
+
const owesFromNow = <S>(state: State<S>, list: Int32Array, count: number, inList: number, owing: number): void => {
|
|
942
|
+
const { flags, owed } = state
|
|
943
|
+
let added = 0
|
|
944
|
+
for (let a = 0; a < count; a++) {
|
|
945
|
+
const slot = list[a]
|
|
946
|
+
if ((flags[slot] & (LIVE | inList | STARTED)) !== (LIVE | inList)) continue
|
|
947
|
+
if (owed[slot] !== 0) continue
|
|
948
|
+
owed[slot] = owing
|
|
949
|
+
added++
|
|
950
|
+
}
|
|
951
|
+
state.owing = state.owing + added
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* `defect`, a failure on the Batch's path named by `message`, logged and handed to the ErrorReporters of
|
|
956
|
+
* what it runs on, annotated with its member's slot where it's one member's.
|
|
957
|
+
*/
|
|
958
|
+
// #977 (ADR-0074): one member's failure is its own. Its failure path, off the per-frame one.
|
|
959
|
+
const report = <S>(state: State<S>, message: string, defect: unknown, slot?: number): void => {
|
|
960
|
+
const failure = Report.failure(message, Cause.die(defect))
|
|
961
|
+
if (Predicate.isUndefined(slot)) {
|
|
962
|
+
Effect.runForkWith(state.services)(failure)
|
|
963
|
+
return
|
|
964
|
+
}
|
|
965
|
+
Effect.runForkWith(state.services)(Effect.annotateLogs(failure, { member: slot }))
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/** A member's write that threw: reported once, until a step writes every member clean. */
|
|
969
|
+
const writeFailed = <S>(state: State<S>, slot: number, defect: unknown): void => {
|
|
970
|
+
state.writeThrewInStep = true
|
|
971
|
+
if (state.writeReported) return
|
|
972
|
+
state.writeReported = true
|
|
973
|
+
report(state, "wardic.batch: a member's write failed", defect, slot)
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** A member's start partway that threw: reported once, until a step starts every member clean. */
|
|
977
|
+
const startFailed = <S>(state: State<S>, slot: number, defect: unknown): void => {
|
|
978
|
+
state.startThrewInStep = true
|
|
979
|
+
if (state.startReported) return
|
|
980
|
+
state.startReported = true
|
|
981
|
+
report(state, "wardic.batch: a member's start failed", defect, slot)
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** The writer's `flush`, a step's or a draw's: a throw reported once, until one returns. */
|
|
985
|
+
const flushed = <S>(state: State<S>): void => {
|
|
986
|
+
try {
|
|
987
|
+
state.flush()
|
|
988
|
+
if (state.flushReported) state.flushReported = false
|
|
989
|
+
} catch (defect) {
|
|
990
|
+
if (state.flushReported) return
|
|
991
|
+
state.flushReported = true
|
|
992
|
+
report(state, "wardic.batch: its writer's flush failed", defect)
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
801
996
|
/** Whether any member moves: one `step` would move. */
|
|
802
997
|
export const isMoving = <S>(self: Batch<S>): boolean => {
|
|
803
998
|
const state = stateOf(self)
|
|
@@ -809,6 +1004,11 @@ export const isMoving = <S>(self: Batch<S>): boolean => {
|
|
|
809
1004
|
* outside a step set (an `enter`, a `replace`, a start from a given value, a play, seek, stop or cancel):
|
|
810
1005
|
* whether nothing moves now. One a delay or a paused Playhead holds still isn't written. The run on the
|
|
811
1006
|
* Frame loop calls it each tick.
|
|
1007
|
+
*
|
|
1008
|
+
* One member's failure is its own: a write or a start partway that throws is reported once, until a step
|
|
1009
|
+
* runs every member's clean, and its member steps on with the others. A landing's callback that throws is
|
|
1010
|
+
* reported each time, the other members told and the other changes landed; the writer's `flush` and
|
|
1011
|
+
* `onFrame` once until they return. Each is reported on what the Batch last ran on.
|
|
812
1012
|
*/
|
|
813
1013
|
// Per frame (ADR-0025, ADR-0030 decisions 10 and 11): `dt` clamped once (#78), then the two moving
|
|
814
1014
|
// lists. Each steps a key by `springValues`' exact step, or `Machine.tween`'s, its spring's matrix
|
|
@@ -817,12 +1017,39 @@ export const step = <S>(self: Batch<S>, dt: number): boolean => {
|
|
|
817
1017
|
const state = stateOf(self)
|
|
818
1018
|
const clamped = Math.min(dt, Machine.MAX_DT)
|
|
819
1019
|
state.frame = state.frame + 1
|
|
1020
|
+
state.frameDt = dt
|
|
1021
|
+
// Whether a member's write or start throws in this step: a `draw`'s between steps isn't one (#977).
|
|
1022
|
+
state.writeThrewInStep = false
|
|
1023
|
+
state.startThrewInStep = false
|
|
820
1024
|
if (state.startList.length > 0) startPass(state, clamped)
|
|
1025
|
+
// A member that owes its first steps steps by its own dt, out of the loops (#1028).
|
|
1026
|
+
if (state.startOwing !== 0) startOwes(state)
|
|
1027
|
+
if (state.owing > 0) owingPass(state, clamped)
|
|
821
1028
|
if (state.plainCount > 0) stepPlain(state, clamped)
|
|
822
1029
|
if (state.ruledCount > 0) stepRuled(state, clamped)
|
|
823
|
-
|
|
824
|
-
state.
|
|
825
|
-
|
|
1030
|
+
// Each change's landing its own: a callback that throws leaves the others to land (#977).
|
|
1031
|
+
if (state.animations.size > 0) {
|
|
1032
|
+
for (const animation of state.animations) {
|
|
1033
|
+
try {
|
|
1034
|
+
checkLanding(animation)
|
|
1035
|
+
} catch (defect) {
|
|
1036
|
+
report(state, "wardic.batch: a change's landing failed", defect)
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
flushed(state)
|
|
1041
|
+
try {
|
|
1042
|
+
state.onFrame()
|
|
1043
|
+
if (state.onFrameReported) state.onFrameReported = false
|
|
1044
|
+
} catch (defect) {
|
|
1045
|
+
if (!state.onFrameReported) {
|
|
1046
|
+
state.onFrameReported = true
|
|
1047
|
+
report(state, "wardic.batch: an onFrame failed", defect)
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
// A path that stepped clean is reported again at its next throw (#977).
|
|
1051
|
+
if (!state.writeThrewInStep) state.writeReported = false
|
|
1052
|
+
if (!state.startThrewInStep) state.startReported = false
|
|
826
1053
|
// Counted after `onFrame`: a change it makes keeps the run going.
|
|
827
1054
|
if (state.plainCount + state.ruledCount > 0) return false
|
|
828
1055
|
// A driven change playing, paused at rest, still holds its entries.
|
|
@@ -832,7 +1059,7 @@ export const step = <S>(self: Batch<S>, dt: number): boolean => {
|
|
|
832
1059
|
|
|
833
1060
|
/**
|
|
834
1061
|
* Writes every member where it is now, with no step, then flushes the writer: a change that started its
|
|
835
|
-
* members from their targets (`retarget`'s `from`),
|
|
1062
|
+
* members from their targets (`retarget`'s `from`), committed now, before the frame is drawn, where the run would
|
|
836
1063
|
* draw it at its next tick.
|
|
837
1064
|
*/
|
|
838
1065
|
// #712: a Batch Reorder group's first read of its element places its items at once. Once a change, over
|
|
@@ -843,9 +1070,13 @@ export const draw = <S>(self: Batch<S>): void => {
|
|
|
843
1070
|
for (let slot = 0; slot < state.used; slot++) {
|
|
844
1071
|
if ((flags[slot] & LIVE) === 0) continue
|
|
845
1072
|
flags[slot] = flags[slot] & ~DUE
|
|
846
|
-
|
|
1073
|
+
try {
|
|
1074
|
+
write(subjects[slot] as S, positions, slot * stride)
|
|
1075
|
+
} catch (defect) {
|
|
1076
|
+
writeFailed(state, slot, defect)
|
|
1077
|
+
}
|
|
847
1078
|
}
|
|
848
|
-
state
|
|
1079
|
+
flushed(state)
|
|
849
1080
|
}
|
|
850
1081
|
|
|
851
1082
|
/**
|
|
@@ -936,7 +1167,13 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
936
1167
|
elapsed[at] = time
|
|
937
1168
|
}
|
|
938
1169
|
// One a delay holds still isn't written: an unchanged write is a style write all the same.
|
|
939
|
-
if (moved)
|
|
1170
|
+
if (moved) {
|
|
1171
|
+
try {
|
|
1172
|
+
write(subjects[slot] as S, positions, base)
|
|
1173
|
+
} catch (defect) {
|
|
1174
|
+
writeFailed(state, slot, defect)
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
940
1177
|
// At rest: still its member's, in neither list.
|
|
941
1178
|
if (still) {
|
|
942
1179
|
flags[slot] = LIVE
|
|
@@ -1066,7 +1303,13 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
1066
1303
|
positions[at] = position
|
|
1067
1304
|
velocities[at] = speed
|
|
1068
1305
|
}
|
|
1069
|
-
if (moved)
|
|
1306
|
+
if (moved) {
|
|
1307
|
+
try {
|
|
1308
|
+
write(subjects[slot] as S, positions, base)
|
|
1309
|
+
} catch (defect) {
|
|
1310
|
+
writeFailed(state, slot, defect)
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1070
1313
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1071
1314
|
if (still) {
|
|
1072
1315
|
flags[slot] = LIVE
|
|
@@ -1167,7 +1410,13 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1167
1410
|
positions[at] = position
|
|
1168
1411
|
velocities[at] = speed
|
|
1169
1412
|
}
|
|
1170
|
-
if (moved)
|
|
1413
|
+
if (moved) {
|
|
1414
|
+
try {
|
|
1415
|
+
write(subjects[slot] as S, positions, base)
|
|
1416
|
+
} catch (defect) {
|
|
1417
|
+
writeFailed(state, slot, defect)
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1171
1420
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1172
1421
|
if (still) {
|
|
1173
1422
|
flags[slot] = LIVE
|
|
@@ -1273,6 +1522,11 @@ interface AnimationState<S> {
|
|
|
1273
1522
|
dt: number
|
|
1274
1523
|
/** Played from partway through: its first step lands where it was played from, as a driven machine's (`Playback.drive`). */
|
|
1275
1524
|
landing: boolean
|
|
1525
|
+
/**
|
|
1526
|
+
* What its Playhead owes of a long task's time (`FirstSteps`), as a member does: from its play while the
|
|
1527
|
+
* run goes on, or from the run's start, its first ticks leave it out.
|
|
1528
|
+
*/
|
|
1529
|
+
owed: number
|
|
1276
1530
|
/** Each member it moves, by rank, its first key's index in `ats`, and one past the last's; whether each has been told it landed. */
|
|
1277
1531
|
firsts: Int32Array
|
|
1278
1532
|
told: Uint8Array
|
|
@@ -1318,18 +1572,25 @@ const drivenStep = <S>(animation: AnimationState<S>, clamped: number, frame: num
|
|
|
1318
1572
|
if (animation.frame === frame) return animation.dt
|
|
1319
1573
|
animation.frame = frame
|
|
1320
1574
|
const head = animation.options.head
|
|
1575
|
+
// Its tick: the frame's, less a long task's time while its Playhead owes its first ticks (#1028).
|
|
1576
|
+
let tick = clamped
|
|
1577
|
+
const owed = animation.owed
|
|
1578
|
+
if (owed !== 0) {
|
|
1579
|
+
tick = owingDt(animation.state, owed)
|
|
1580
|
+
animation.owed = owedAfter(animation.state, owed)
|
|
1581
|
+
}
|
|
1321
1582
|
let by = 0
|
|
1322
1583
|
// Played from partway through, its first step lands there, whatever the `dt`, as `Playback.drive`'s does.
|
|
1323
1584
|
const landing = animation.landing
|
|
1324
1585
|
animation.landing = false
|
|
1325
|
-
if (!landing && !head.paused) by = tickOf(head,
|
|
1586
|
+
if (!landing && !head.paused) by = tickOf(head, tick, Machine.MAX_DT)
|
|
1326
1587
|
animation.dt = by
|
|
1327
1588
|
animation.time = Math.max(0, animation.time + by)
|
|
1328
1589
|
writableOf(head).time = animation.time
|
|
1329
1590
|
return by
|
|
1330
1591
|
}
|
|
1331
1592
|
|
|
1332
|
-
/** Whether the key at `at` is held by a paused Playhead: it hands on no speed, as a held
|
|
1593
|
+
/** Whether the key at `at` is held by a paused Playhead: it hands on no speed, as a held Subject's frames read 0 (#464). */
|
|
1333
1594
|
// Per key per change, while a driven change plays.
|
|
1334
1595
|
const heldAt = <S>(state: State<S>, at: number): boolean => {
|
|
1335
1596
|
const driver = state.drivers[state.rules[at]]
|
|
@@ -1418,9 +1679,18 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1418
1679
|
const { stride, elapsed, rules, positions, velocities, targets, originVelocities, startAts } = state
|
|
1419
1680
|
const startAt = UndefinedOr.getOrThrow(startAts[slot])
|
|
1420
1681
|
startAts[slot] = undefined
|
|
1421
|
-
|
|
1682
|
+
// A start that throws is its member's: it starts from its start, as `NaN` gives (#977).
|
|
1683
|
+
let time = Number.NaN
|
|
1684
|
+
try {
|
|
1685
|
+
time = startAt(slot)
|
|
1686
|
+
} catch (defect) {
|
|
1687
|
+
startFailed(state, slot, defect)
|
|
1688
|
+
}
|
|
1422
1689
|
const base = slot * stride
|
|
1423
1690
|
const started = !Number.isNaN(time)
|
|
1691
|
+
// Taking its Appear animation over, it keeps the frame timeline's time, where that animation's is (#1026);
|
|
1692
|
+
// from its start, `NaN`, it takes over nothing and owes its first steps as any member set off (#1028).
|
|
1693
|
+
if (started) owesNothing(state, slot)
|
|
1424
1694
|
for (let k = 0; k < stride; k++) {
|
|
1425
1695
|
const at = base + k
|
|
1426
1696
|
const turned = Number.isNaN(elapsed[at])
|
|
@@ -1439,16 +1709,79 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1439
1709
|
}
|
|
1440
1710
|
if (started) {
|
|
1441
1711
|
state.flags[slot] = state.flags[slot] & ~DUE
|
|
1442
|
-
|
|
1712
|
+
try {
|
|
1713
|
+
state.write(state.subjects[slot] as S, positions, base)
|
|
1714
|
+
} catch (defect) {
|
|
1715
|
+
writeFailed(state, slot, defect)
|
|
1716
|
+
}
|
|
1443
1717
|
}
|
|
1444
1718
|
return started
|
|
1445
1719
|
}
|
|
1446
1720
|
|
|
1721
|
+
/**
|
|
1722
|
+
* Each step's owing pass, before the loops and after the start pass: each member that owes its first steps
|
|
1723
|
+
* takes its step's dt (the tick's, less what it owes). One whose dt that leaves less is
|
|
1724
|
+
* stepped by it here, drawn, and flagged `STARTED` so its loop keeps it unstepped; one at the tick's, by its
|
|
1725
|
+
* loop. A key a Playhead drives keeps its Playhead's step.
|
|
1726
|
+
*/
|
|
1727
|
+
// #1028: once or twice a member, after a change that sets it off, so out of the loops, as the start pass is
|
|
1728
|
+
// (#706): with a member's own dt read in them, Bun's ruled step ran 5% slower with no member owing.
|
|
1729
|
+
const owingPass = <S>(state: State<S>, clamped: number): void => {
|
|
1730
|
+
owingIn(state, state.plainList, state.plainCount, clamped)
|
|
1731
|
+
owingIn(state, state.ruledList, state.ruledCount, clamped)
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/** The owing pass over `list`'s first `count`: a member that left, or one drawn this step already, skipped. */
|
|
1735
|
+
const owingIn = <S>(state: State<S>, list: Int32Array, count: number, clamped: number): void => {
|
|
1736
|
+
const { flags, owed } = state
|
|
1737
|
+
for (let a = 0; a < count; a++) {
|
|
1738
|
+
const slot = list[a]
|
|
1739
|
+
const was = owed[slot]
|
|
1740
|
+
if (was === 0) continue
|
|
1741
|
+
if ((flags[slot] & (LIVE | STARTED)) !== LIVE) continue
|
|
1742
|
+
const own = owingDt(state, was)
|
|
1743
|
+
const after = owedAfter(state, was)
|
|
1744
|
+
owed[slot] = after
|
|
1745
|
+
if (after === 0) state.owing = state.owing - 1
|
|
1746
|
+
// At the tick's own dt (an on-time first step), its loop steps it.
|
|
1747
|
+
if (own !== clamped) stepOwing(state, slot, clamped, own)
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/** The member at `slot` a step of `own` on, each key as the loops step it, drawn, and kept from its loop this step. */
|
|
1752
|
+
const stepOwing = <S>(state: State<S>, slot: number, clamped: number, own: number): void => {
|
|
1753
|
+
const { stride, rules, drivers } = state
|
|
1754
|
+
const base = slot * stride
|
|
1755
|
+
for (let k = 0; k < stride; k++) {
|
|
1756
|
+
const at = base + k
|
|
1757
|
+
const rule = rules[at]
|
|
1758
|
+
const driver = drivers[rule]
|
|
1759
|
+
if (Predicate.isUndefined(driver)) {
|
|
1760
|
+
stepKey(state, at, rule, own)
|
|
1761
|
+
continue
|
|
1762
|
+
}
|
|
1763
|
+
// Its Playhead's step this frame, worked out once a step whichever reads it first.
|
|
1764
|
+
const driven = drivenStep(driver, clamped, state.frame)
|
|
1765
|
+
if (driven < 0) {
|
|
1766
|
+
stepBack(state, at, rule, driven)
|
|
1767
|
+
continue
|
|
1768
|
+
}
|
|
1769
|
+
stepKey(state, at, rule, driven)
|
|
1770
|
+
}
|
|
1771
|
+
state.flags[slot] = (state.flags[slot] & ~DUE) | STARTED
|
|
1772
|
+
try {
|
|
1773
|
+
state.write(state.subjects[slot] as S, state.positions, base)
|
|
1774
|
+
} catch (defect) {
|
|
1775
|
+
writeFailed(state, slot, defect)
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1447
1779
|
/**
|
|
1448
1780
|
* The key at `at` a step of `dt` on, as the loops step it: a tween's, keyframes', or a spring's by its
|
|
1449
1781
|
* matrix for the part past its delay, landing by its thresholds or its duration.
|
|
1450
1782
|
*/
|
|
1451
|
-
// Rare: a key the loops don't reach this step, of a member started partway that another change moves
|
|
1783
|
+
// Rare: a key the loops don't reach this step, of a member started partway that another change moves, or of
|
|
1784
|
+
// a member that owes its first steps (#1028).
|
|
1452
1785
|
const stepKey = <S>(state: State<S>, at: number, rule: number, dt: number): void => {
|
|
1453
1786
|
const entry = state.entries[rule]
|
|
1454
1787
|
const time = state.elapsed[at] + dt
|
|
@@ -1527,7 +1860,14 @@ const tellIdle = <S>(animation: AnimationState<S>): void => {
|
|
|
1527
1860
|
animation.idleTold = true
|
|
1528
1861
|
const tell = animation.options.onMemberLanded
|
|
1529
1862
|
if (Predicate.isUndefined(tell)) return
|
|
1530
|
-
|
|
1863
|
+
// Each member's own: a landing that throws leaves the others told (#977).
|
|
1864
|
+
Arr.forEach(animation.idle, (slot) => {
|
|
1865
|
+
try {
|
|
1866
|
+
tell(slot)
|
|
1867
|
+
} catch (defect) {
|
|
1868
|
+
report(animation.state, "wardic.batch: a member's landing failed", defect, slot)
|
|
1869
|
+
}
|
|
1870
|
+
})
|
|
1531
1871
|
}
|
|
1532
1872
|
|
|
1533
1873
|
/**
|
|
@@ -1552,7 +1892,12 @@ const tellMembers = <S>(animation: AnimationState<S>, tell: (slot: number) => vo
|
|
|
1552
1892
|
}
|
|
1553
1893
|
if (!kept || !atRest) continue
|
|
1554
1894
|
told[r] = 1
|
|
1555
|
-
|
|
1895
|
+
const slot = slotAt(state, ats[firsts[r]])
|
|
1896
|
+
try {
|
|
1897
|
+
tell(slot)
|
|
1898
|
+
} catch (defect) {
|
|
1899
|
+
report(state, "wardic.batch: a member's landing failed", defect, slot)
|
|
1900
|
+
}
|
|
1556
1901
|
}
|
|
1557
1902
|
}
|
|
1558
1903
|
|
|
@@ -1693,6 +2038,7 @@ const animationFor = <S>(
|
|
|
1693
2038
|
frame: 0,
|
|
1694
2039
|
dt: 0,
|
|
1695
2040
|
landing: false,
|
|
2041
|
+
owed: 0,
|
|
1696
2042
|
tracks: [],
|
|
1697
2043
|
indexAt: new Int32Array(0),
|
|
1698
2044
|
firsts: new Int32Array(0),
|
|
@@ -1976,7 +2322,7 @@ const playRules = <S>(animation: AnimationState<S>): void => {
|
|
|
1976
2322
|
/**
|
|
1977
2323
|
* Plays `animation` from its Playhead's time: from its start at 0, its change worked out then, and from
|
|
1978
2324
|
* wherever a seek put the time, every key it moves taken again there. It returns how many members it
|
|
1979
|
-
* sets off from rest. One that moves nothing lands at once, as
|
|
2325
|
+
* sets off from rest. One that moves nothing lands at once, as a Subject's call with no key does.
|
|
1980
2326
|
*/
|
|
1981
2327
|
export const play = (self: Animation): number => {
|
|
1982
2328
|
const animation = animationOf(self)
|
|
@@ -1993,6 +2339,10 @@ export const play = (self: Animation): number => {
|
|
|
1993
2339
|
animation.playing = true
|
|
1994
2340
|
animation.time = time
|
|
1995
2341
|
animation.landing = time > 0
|
|
2342
|
+
// Played while the run goes on, its Playhead owes its first ticks from now (#1028); played at rest, from
|
|
2343
|
+
// the run's start, as the run's members.
|
|
2344
|
+
animation.owed = 0
|
|
2345
|
+
if (state.running !== 0) animation.owed = owingNow(state)
|
|
1996
2346
|
state.animations.add(animation)
|
|
1997
2347
|
// Once a play, per key it moves: each key's entry, then each entry held once for it and driven by it.
|
|
1998
2348
|
playRules(animation)
|
|
@@ -2179,26 +2529,40 @@ const machineOf = <S>(self: Batch<S>, id: number): Machine.Machine<Frame.Frame<n
|
|
|
2179
2529
|
})
|
|
2180
2530
|
}
|
|
2181
2531
|
|
|
2532
|
+
/** A Batch run's options: on the frame timeline, its members keeping the late-frame rule each. */
|
|
2533
|
+
// #1026, #1028.
|
|
2534
|
+
const ON_THE_FRAME_TIMELINE: Machine.RunOptions = { onFrameTimeline: true }
|
|
2535
|
+
|
|
2182
2536
|
/**
|
|
2183
2537
|
* Runs `self` on the Frame loop while any member moves, from the next tick: each tick steps every
|
|
2184
2538
|
* moving member and writes it. It succeeds once nothing moves. While one runs, another does nothing,
|
|
2185
|
-
* so a binding calls it after each change.
|
|
2539
|
+
* so a binding calls it after each change. A member's failure is reported on the services it runs with,
|
|
2540
|
+
* the Environment's Logger and ErrorReporters, and the run goes on.
|
|
2186
2541
|
*
|
|
2187
2542
|
* @example
|
|
2188
2543
|
* Batch.retarget(grid, slots, targetOf)
|
|
2189
2544
|
* runtime.runFork(Batch.run(grid))
|
|
2190
2545
|
*/
|
|
2546
|
+
|
|
2191
2547
|
// One run, not a fiber per member (ADR-0069, decision 10). Its span is `wardic.batch`.
|
|
2192
2548
|
export const run = <S>(self: Batch<S>): Effect.Effect<void, never, FrameLoop.FrameLoop> =>
|
|
2193
|
-
Effect.
|
|
2549
|
+
Effect.contextWith((services: Context.Context<FrameLoop.FrameLoop>) => {
|
|
2194
2550
|
const state = stateOf(self)
|
|
2195
2551
|
if (state.running !== 0) return Effect.void
|
|
2552
|
+
// Its failures are reported on what it runs on, the Environment's Logger and ErrorReporters, kept
|
|
2553
|
+
// for a draw or a play between runs; a second run while one runs swaps nothing (#977).
|
|
2554
|
+
state.services = services
|
|
2196
2555
|
if (state.plainCount + state.ruledCount === 0) return Effect.void
|
|
2197
2556
|
const id = state.runs + 1
|
|
2198
2557
|
state.runs = id
|
|
2199
2558
|
state.running = id
|
|
2559
|
+
// The run keeps the frame timeline's time, where a member taking its Appear animation over has its
|
|
2560
|
+
// `currentTime` (#1026). Every other member takes no long task's time from before it moved (#1028):
|
|
2561
|
+
// those moving now owe their first steps, and those set off while it runs, at their change.
|
|
2562
|
+
state.ticks = Option.getOrUndefined(FirstSteps.readerOf(Context.get(services, FrameLoop.FrameLoop)))
|
|
2563
|
+
runStarts(state)
|
|
2200
2564
|
return Effect.ensuring(
|
|
2201
|
-
Effect.asVoid(Machine.run(machineOf(self, id), ignore)),
|
|
2565
|
+
Effect.asVoid(Machine.run(machineOf(self, id), ignore, ON_THE_FRAME_TIMELINE)),
|
|
2202
2566
|
Effect.sync(() => {
|
|
2203
2567
|
if (state.running === id) state.running = 0
|
|
2204
2568
|
}),
|