From 6904ce0e7adc44bc0e7b8bf5ca0090768bd3a49b Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 13:55:07 -0800 Subject: [PATCH] Scenes: a hold resumed partway waits for the clip it started again The resumed hold reads scene media like any hold: a clip still playing is waited for, and only without one does it wait out the rest of the hold. --- docs/DIRECTOR.md | 4 ++-- src/scenes/director.js | 20 +++++++++++--------- src/scenes/director.test.mjs | 28 ++++++++++++++++++++++++++++ src/scenes/playbackAdapter.js | 4 ++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/docs/DIRECTOR.md b/docs/DIRECTOR.md index 01ada0127..fd2c6eeda 100644 --- a/docs/DIRECTOR.md +++ b/docs/DIRECTOR.md @@ -41,8 +41,8 @@ goes on from there along the rest of the path a seek samples, over the rest of t flight; inside its hold, the layers take that moment's state as a seek gives them and then play on from it: a reveal goes on from where the seek put it, and a clip the moment falls in starts again from its beginning (a clip cannot be -joined partway), while one the moment is past stays finished. Only the rest of -the hold is waited out. The scene clock carries on from the same point. `SceneDirector` still owns editor state, saved-project import/export, +joined partway), while one the moment is past stays finished. A clip started again is waited +for as in any hold; otherwise only the rest of the hold is waited out. The scene clock carries on from the same point. `SceneDirector` still owns editor state, saved-project import/export, camera ownership and asynchronous load/seek arbitration. Pure seek calculations live in `src/director/timeline.js`; `src/director/clock.js` owns the run/load/shot tickers, hold deadlines, snapshots and clock subscriptions. Stop settles pending diff --git a/src/scenes/director.js b/src/scenes/director.js index 75d8174f5..cadf2c007 100644 --- a/src/scenes/director.js +++ b/src/scenes/director.js @@ -2933,15 +2933,6 @@ export class SceneDirector { /** Let an opt-in media owner finish playback and its fade before the next flight. */ async _holdShot(scene, shot, token, resume = null) { - // Resumed inside the hold: its layers were set to that moment, as a seek - // sets them, so only the rest of the hold is left to wait. - if (resume?.holdElapsedSec > 0) { - await this._sleep( - Math.max(0, resume.holdDurationSec - resume.holdElapsedSec) * 1000, - token, - ); - return; - } const readers = Object.entries( this._layerStatesForShot(scene, shot), ).flatMap(([id, state]) => { @@ -2962,6 +2953,17 @@ export class SceneDirector { ] : []; }); + // Resumed inside the hold, its layers play on from that moment: a clip + // they started again is waited for as in any hold; otherwise only the + // rest of the hold is left to wait. + const resumed = resume?.holdElapsedSec > 0; + if (resumed && !readers.some(({ read }) => read()?.pending === true)) { + await this._sleep( + Math.max(0, resume.holdDurationSec - resume.holdElapsedSec) * 1000, + token, + ); + return; + } if (!readers.length) { await this._sleep(this._effectiveShotHoldSec(scene, shot) * 1000, token); return; diff --git a/src/scenes/director.test.mjs b/src/scenes/director.test.mjs index b75858a4a..e84394a08 100644 --- a/src/scenes/director.test.mjs +++ b/src/scenes/director.test.mjs @@ -2108,6 +2108,34 @@ test('a revocation also covers the release a stopped run reaches later', async ( } finally { await director.destroy(); restore(); } }); +test('a hold resumed partway waits for a clip that starts again, else only its rest', async () => { + const hold = async (pendingReads) => { + let reads = 0; + const module = { + getSceneShotMediaHold: () => ({ pending: reads++ < pendingReads, maxWaitMs: 20000 }), + }; + const waits = []; + await SceneDirector.prototype._holdShot.call( + { + _layerStatesForShot: () => ({ media: { enabled: true, params: { beatId: 'b' } } }), + dataManager: { layers: new Map([['media', { module }]]) }, + _effectiveShotHoldSec: () => 3, + _sleep: async (ms) => waits.push(ms), + stopScene: () => assert.fail('no timeout'), + }, + { id: 'scene' }, + { id: 'shot' }, + { cancelled: false }, + { holdElapsedSec: 1, holdDurationSec: 3 }, + ); + return waits; + }; + // The clip plays again: the hold polls until it is done, as any hold does. + assert.deepEqual(await hold(4), [70, 70]); + // The moment was past the clip: only the rest of the hold. + assert.deepEqual(await hold(0), [2000]); +}); + /** Drive frame-by-frame camera motion headlessly for one test. */ function installAnimationFrames() { const original = globalThis.requestAnimationFrame; diff --git a/src/scenes/playbackAdapter.js b/src/scenes/playbackAdapter.js index e22937f0f..abc29cbb6 100644 --- a/src/scenes/playbackAdapter.js +++ b/src/scenes/playbackAdapter.js @@ -5,8 +5,8 @@ import { displaySceneTitle, displayShotTitle } from './recipes.js'; /** * A run resumed partway into its first shot carries the seek state of that * moment (`resume`). Inside the shot's hold, its layers take that moment's - * state as a seek gives it and then play on from it, and only the rest of the - * hold is waited out; inside + * state as a seek gives it and then play on from it, and the hold waits for a + * clip started again or else only its rest; inside * its flight, the camera goes on from where it is along the rest of the path. */ const inHold = (resume) => resume?.holdElapsedSec > 0;