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.
This commit is contained in:
Sameh Khamis committed 2026-11-16 13:55:07 -08:00
1 parent b2c7144cce
commit 6904ce0e7a
4 files changed
+43 -13

No files matched your search

+2 -2
View File
@@ -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
+11 -9
View File
@@ -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;
+28
View File
@@ -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;
+2 -2
View File
@@ -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;