mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(core): a multi-worker render replays overlapping tweens behind the timeline stand-in (#7231)
* fix(core): a multi-worker render replays overlapping tweens behind the timeline stand-in The overlap and landing-mark walks compared tween parents with the stand-in the producer's GSAP stub hands out, never met it, and lost the overlaps and step times. Both now compare with the real timeline behind the stand-in. * fix(core): drop the moved helper's comment so the file's comment share holds
This commit is contained in:
@@ -1,24 +1,33 @@
|
||||
import gsap from "gsap";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { seekGsapTimeline } from "./gsap";
|
||||
import { producerStandIn } from "./gsapStandIn.test-helpers";
|
||||
import type { RuntimeTimelineLike } from "../types";
|
||||
|
||||
const FPS = 60;
|
||||
const FRAMES = 150;
|
||||
|
||||
// A zoom punch still running when a cut sets the zoom and a slower move starts from wherever the zoom is.
|
||||
function overlappingZoom() {
|
||||
function overlappingZoom(standIn = false) {
|
||||
const params = { z: 1 };
|
||||
const timeline = gsap.timeline({ paused: true });
|
||||
timeline.to(params, { z: 1.45, duration: 0.3, ease: "power4.out" }, 0.573);
|
||||
timeline.set(params, { z: 1.04 }, 0.8);
|
||||
timeline.to(params, { z: 1.12, duration: 1.39, ease: "power1.in" }, 0.869);
|
||||
return { params, timeline: timeline as unknown as RuntimeTimelineLike };
|
||||
return {
|
||||
params,
|
||||
timeline: standIn ? producerStandIn(timeline) : (timeline as unknown as RuntimeTimelineLike),
|
||||
};
|
||||
}
|
||||
|
||||
/** The zoom at each frame a renderer captures, in order; a scene's clock starts at `hostStart`. */
|
||||
function capture(frames: number[], hostStart = 0, seekFirst?: number): Map<number, number> {
|
||||
const { params, timeline } = overlappingZoom();
|
||||
function capture(
|
||||
frames: number[],
|
||||
hostStart = 0,
|
||||
seekFirst?: number,
|
||||
standIn = false,
|
||||
): Map<number, number> {
|
||||
const { params, timeline } = overlappingZoom(standIn);
|
||||
const zoom = new Map<number, number>();
|
||||
if (seekFirst !== undefined) seekGsapTimeline(timeline, seekFirst, true, undefined, FPS);
|
||||
for (const frame of frames) {
|
||||
@@ -42,6 +51,14 @@ describe("a render that captures frames out of order", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("gives every frame the same value when the producer hands out a stand-in for the timeline", () => {
|
||||
for (let worker = 0; worker < 8; worker++) {
|
||||
for (const [frame, z] of capture(range(worker, FRAMES, 8), 0, undefined, true)) {
|
||||
expect([frame, z]).toEqual([frame, inOrder.get(frame)]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("gives every frame the same value when a chunk starts inside the overlap", () => {
|
||||
for (const [frame, z] of capture(range(53, FRAMES))) {
|
||||
expect([frame, z]).toEqual([frame, inOrder.get(frame)]);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
seekGsapTimeline,
|
||||
} from "./gsap";
|
||||
import type { GsapStructureKey } from "./gsap";
|
||||
import { producerStandIn } from "./gsapStandIn.test-helpers";
|
||||
import type { RuntimeTimelineLike } from "../types";
|
||||
|
||||
// Every 0.1 s: hide all three frames, then show one, as frame-by-frame films do.
|
||||
@@ -646,18 +647,24 @@ describe("seekGsapTimeline", () => {
|
||||
expect(scene.field.style.visibility).toBe("visible");
|
||||
});
|
||||
|
||||
it("shows two steps on one later time in authored order after the playhead comes back onto it", () => {
|
||||
const word = document.body.appendChild(document.createElement("span"));
|
||||
const timeline = gsap.timeline({ paused: true });
|
||||
timeline.set(word, { visibility: "hidden" }, 1).set(word, { visibility: "visible" }, 1);
|
||||
timeline.to({}, { duration: 3 }, 0);
|
||||
const scene = timeline as unknown as RuntimeTimelineLike;
|
||||
sceneSeek(scene, 2);
|
||||
sceneSeek(scene, 1);
|
||||
expect(word.style.visibility).toBe("visible");
|
||||
sceneSeek(scene, 1.2);
|
||||
expect(word.style.visibility).toBe("visible");
|
||||
});
|
||||
it.each([
|
||||
["a timeline", (timeline: gsap.core.Timeline) => timeline as unknown as RuntimeTimelineLike],
|
||||
["the producer's stand-in for a timeline", producerStandIn],
|
||||
])(
|
||||
"shows two steps on one later time in authored order after the playhead comes back onto %s",
|
||||
(_, seekable) => {
|
||||
const word = document.body.appendChild(document.createElement("span"));
|
||||
const timeline = gsap.timeline({ paused: true });
|
||||
timeline.set(word, { visibility: "hidden" }, 1).set(word, { visibility: "visible" }, 1);
|
||||
timeline.to({}, { duration: 3 }, 0);
|
||||
const scene = seekable(timeline);
|
||||
sceneSeek(scene, 2);
|
||||
sceneSeek(scene, 1);
|
||||
expect(word.style.visibility).toBe("visible");
|
||||
sceneSeek(scene, 1.2);
|
||||
expect(word.style.visibility).toBe("visible");
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps a scene's steps at 0 through the root's redraw at 0 on every seek", () => {
|
||||
const scene = revealedAtZero();
|
||||
|
||||
@@ -159,9 +159,14 @@ function spanOnParent(
|
||||
return [Number(parent._start) + from / Math.abs(speed), span / Math.abs(speed)];
|
||||
}
|
||||
|
||||
export function gsapTimelineOf(timeline: object): object {
|
||||
return (timeline as { __hfReal?: object }).__hfReal ?? timeline;
|
||||
}
|
||||
|
||||
function writeOf(tween: PlacedTween, timeline: RuntimeTimelineLike): PropertyWrite | null {
|
||||
const owner = gsapTimelineOf(timeline);
|
||||
let span: [number, number] | null = [Number(tween._start), Number(tween.totalDuration?.() ?? 0)];
|
||||
for (let parent = tween.parent; span && parent && parent !== timeline; parent = parent.parent) {
|
||||
for (let parent = tween.parent; span && parent && parent !== owner; parent = parent.parent) {
|
||||
span = spanOnParent(span, parent);
|
||||
}
|
||||
return (
|
||||
@@ -355,8 +360,9 @@ type GsapPlaced = {
|
||||
};
|
||||
|
||||
function startOnOwner(child: GsapPlaced, owner: object): number | null {
|
||||
const timeline = gsapTimelineOf(owner);
|
||||
let at = Number(child._start);
|
||||
for (let parent = child.parent; parent && parent !== owner; parent = parent.parent) {
|
||||
for (let parent = child.parent; parent && parent !== timeline; parent = parent.parent) {
|
||||
if (parent._repeat || !parent._ts) return null;
|
||||
at = Number(parent._start) + at / parent._ts;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type gsap from "gsap";
|
||||
import type { RuntimeTimelineLike } from "../types";
|
||||
|
||||
/** The shape the producer's GSAP stub hands a composition instead of the timeline it created. */
|
||||
export function producerStandIn(real: gsap.core.Timeline): RuntimeTimelineLike {
|
||||
const standIn = {
|
||||
__hfReal: real,
|
||||
__hfIsProxy: true,
|
||||
totalTime: (...args: [number, boolean?]) =>
|
||||
args.length > 0 ? (real.totalTime(...args), standIn) : real.totalTime(),
|
||||
totalDuration: () => real.totalDuration(),
|
||||
getChildren: (...args: Parameters<typeof real.getChildren>) => real.getChildren(...args),
|
||||
};
|
||||
return standIn as unknown as RuntimeTimelineLike;
|
||||
}
|
||||
@@ -57,6 +57,7 @@ import {
|
||||
createGsapAdapter,
|
||||
holdFrameMarks,
|
||||
rerenderGsapTimelineAt,
|
||||
gsapTimelineOf,
|
||||
seekGsapTimeline,
|
||||
type GsapStructureKey,
|
||||
} from "./adapters/gsap";
|
||||
@@ -1641,9 +1642,6 @@ export function initSandboxRuntimeModular(): void {
|
||||
|
||||
// Sub-composition timelines the runtime nested into the root: the host composition id, and where.
|
||||
const autoNested = new WeakMap<object, { hostId: string; parent: unknown; at: number }>();
|
||||
// The producer's GSAP stub registers stand-ins; GSAP's tree holds the timelines behind them.
|
||||
const gsapTimelineOf = (timeline: object): object =>
|
||||
(timeline as { __hfReal?: object }).__hfReal ?? timeline;
|
||||
// The composite that holds the children of a root with no timeline, and how many it holds.
|
||||
let missingRootComposite: { timeline: RuntimeTimelineLike; size: number } | null = null;
|
||||
// Roots the runtime built. One it no longer holds would stay on GSAP's global timeline with all it last held.
|
||||
|
||||
Reference in New Issue
Block a user