From 186f8b76d996635775e0aa63c1fda054a3f6fed7 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:20:55 -0800 Subject: [PATCH] Scenes: a clip restarted without a media gate plays its hold out A resumed hold waited only its rest unless the layer gave a media gate, and only trimmed clips have one, so an untrimmed clip started again (as on Gyirong) was cut short. The layer now says when a run going on from a seek started its clip again, and the hold then plays out as from its start: through the media gate when there is one, else for the whole hold. --- docs/DIRECTOR.md | 7 ++-- src/data/bhoteKoshiEvent.js | 24 +++++++++++++ src/data/bhoteKoshiEvent.test.mjs | 60 +++++++++++++++++++++++++++++++ src/scenes/director.js | 19 +++++++--- src/scenes/director.test.mjs | 4 ++- 5 files changed, 106 insertions(+), 8 deletions(-) diff --git a/docs/DIRECTOR.md b/docs/DIRECTOR.md index fd2c6eeda..3a81ef96d 100644 --- a/docs/DIRECTOR.md +++ b/docs/DIRECTOR.md @@ -41,8 +41,11 @@ 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. 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, +joined partway), while one the moment is past stays finished. A clip started +again plays the hold out as from its start: until its media gate opens (a +trimmed clip, with its fade), or for the shot's whole hold (a clip without +one). 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/data/bhoteKoshiEvent.js b/src/data/bhoteKoshiEvent.js index 86d17e710..b47dca8e2 100644 --- a/src/data/bhoteKoshiEvent.js +++ b/src/data/bhoteKoshiEvent.js @@ -1090,6 +1090,8 @@ export function createBhoteKoshiEventLayer({ let _sceneRevealProgress = 1; // How far a timeline seek's settled-camera reveal had come (0..1, linear). let _sceneSeekRevealLinear = 1; + // The beat whose clip a run going on from a seek in its hold started again. + let _sceneMediaRestartBeatId = null; let _cinematicKeyframes = []; let _cinematicActive = false; let _cinematicReplayArmed = false; @@ -1552,6 +1554,19 @@ export function createBhoteKoshiEventLayer({ ); } + /** + * Whether a run going on from a seek in this beat's hold started its clip + * again, so the hold has to play out as from its start. + */ + function sceneShotRestartsMedia(beatId) { + return ( + _enabled && + _sceneBeatId === beatId && + _sceneMediaRestartBeatId === beatId && + sceneEvidenceMediaAutoplays() + ); + } + function getSceneShotMediaHold(beatId) { if ( !_enabled || @@ -3896,6 +3911,14 @@ export function createBhoteKoshiEventLayer({ nowDeferred; if (resumesSeek && sceneSeekPassedMedia(previousSeek)) _sceneMediaPlaybackCompletedBeatId = _sceneBeatId; + if ( + resumesSeek && + sceneEvidenceMediaAutoplays() && + !sceneSeekPassedMedia(previousSeek) + ) + _sceneMediaRestartBeatId = _sceneBeatId; + else if (beatChanged || sceneTimelineSeek()) + _sceneMediaRestartBeatId = null; if (!nowDeferred) { stopSceneEvidenceReveal(); _sceneRevealProgress = 1; @@ -4010,6 +4033,7 @@ export function createBhoteKoshiEventLayer({ setParams, getParams, getSceneShotMediaHold, + sceneShotRestartsMedia, setSceneMediaPlayback, getStats() { return { diff --git a/src/data/bhoteKoshiEvent.test.mjs b/src/data/bhoteKoshiEvent.test.mjs index 87159fd18..5eb4b7863 100644 --- a/src/data/bhoteKoshiEvent.test.mjs +++ b/src/data/bhoteKoshiEvent.test.mjs @@ -529,6 +529,66 @@ test('a run going on from a seek in Timure’s hold resumes its evidence sequenc } finally { await layer.destroy(); Object.assign(globalThis, previous); } }); +test('a run going on from a seek in Gyirong’s hold plays its restarted clip out before the next shot', async () => { + const previous = { document: globalThis.document, window: globalThis.window, + requestAnimationFrame: globalThis.requestAnimationFrame, cancelAnimationFrame: globalThis.cancelAnimationFrame }; + installEventDom(); + globalThis.window = { setTimeout: () => 1, clearTimeout() {} }; + globalThis.requestAnimationFrame = () => 1; + globalThis.cancelAnimationFrame = () => {}; + const event = JSON.parse(await readFile(eventUrl, 'utf8')); + let plays = 0; + const layer = createBhoteKoshiEventLayer({ + eventLoader: async () => event, + imagerySpecFactory: async (url) => ({ url }), + terrainSampler: async (_viewer, observations) => observations.map(() => ({ height: 800 })), + mediaLoader: async () => { throw Object.assign(new Error('No bundled clip'), { name: 'AbortError' }); }, + overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} }, + renderHost: { request() {}, hold() {}, release() {} }, + embeddedMediaFactory: () => ({ warm: () => true, show: () => true, play() { plays++; }, pause() {}, + getPlaybackState: () => ({ phase: 'playing' }), hide() {}, destroy() {} }), + }); + const recipe = getSceneAppendRecipeById('bhote-koshi-nepal-evidence-pack'); + const controls = { ...recipe.runtimeControlsByBeat['gyirong-border-gate'], cameraSettled: true }; + const params = (sceneControls) => ({ presentation: 'scene-beat', sceneSurface: 'evidence-beat', + beatId: 'gyirong-border-gate', sceneContext: { sceneId: 'scene', shotId: 'shot', holdSec: 9.15 }, sceneControls }); + const token = { cancelled: false, signal: new AbortController().signal }; + const hold = async (resume) => { + const waits = []; + await SceneDirector.prototype._holdShot.call({ + _layerStatesForShot: () => ({ [layer.id]: { enabled: true, params: params(controls) } }), + dataManager: { layers: new Map([[layer.id, { module: layer }]]) }, + _effectiveShotHoldSec: () => 9.15, + _sleep: async (ms) => waits.push(ms), + stopScene: () => assert.fail('no timeout'), + }, { id: 'scene' }, { id: 'shot' }, token, resume); + return waits; + }; + try { + const viewer = eventViewer(); + await layer.init(viewer); + layer.setSceneMediaPlayback({ sceneId: 'scene', shotId: 'shot', token }); + // 5 s into the 9.15 s hold, inside the 6 s clip, which has no media gate. + const resume = { holdElapsedSec: 5, holdDurationSec: 9.15 }; + layer.setParams(params({ ...controls, timelineSeek: { cameraProgress: 1, ...resume, flightDurationSec: 2 } }), + { origin: 'scene' }); + await layer.enable(viewer, { origin: 'scene' }); + assert.equal(layer.getSceneShotMediaHold('gyirong-border-gate'), null, 'the clip is not trimmed'); + layer.setParams(params(controls), { origin: 'scene' }); + assert.ok(plays > 0, 'the clip starts again'); + assert.equal(layer.sceneShotRestartsMedia('gyirong-border-gate'), true); + assert.deepEqual(await hold(resume), [9150], 'the hold plays out as from its start, not 4.15 s'); + // A seek after the clip: only the rest of the hold. + const late = { holdElapsedSec: 8, holdDurationSec: 9.15 }; + layer.setParams(params({ ...controls, timelineSeek: { cameraProgress: 1, ...late, flightDurationSec: 2 } }), + { origin: 'scene' }); + layer.setParams(params(controls), { origin: 'scene' }); + assert.equal(layer.sceneShotRestartsMedia('gyirong-border-gate'), false); + const [rest] = await hold(late); + assert.ok(Math.abs(rest - 1150) < 1e-6, String(rest)); + } finally { await layer.destroy(); Object.assign(globalThis, previous); } +}); + test('Pinokio source-card fallback selects authored Director dwell, not an impossible player hold', async () => { const previous = { document: globalThis.document, window: globalThis.window }; installEventDom(); diff --git a/src/scenes/director.js b/src/scenes/director.js index edc141e01..35387ecba 100644 --- a/src/scenes/director.js +++ b/src/scenes/director.js @@ -2957,11 +2957,20 @@ 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)) { + // Resumed inside the hold, its layers play on from that moment. A clip + // they started again plays the hold out as from its start (its media + // gate, or the shot's whole hold for a clip without one); otherwise only + // the rest of the hold is left to wait. + const restartedClip = + resume?.holdElapsedSec > 0 && + Object.entries(this._layerStatesForShot(scene, shot)).some( + ([id, state]) => + state.enabled && + this.dataManager?.layers + ?.get(id) + ?.module?.sceneShotRestartsMedia?.(state.params?.beatId) === true, + ); + if (resume?.holdElapsedSec > 0 && !restartedClip) { await this._sleep( Math.max(0, resume.holdDurationSec - resume.holdElapsedSec) * 1000, token, diff --git a/src/scenes/director.test.mjs b/src/scenes/director.test.mjs index f742db981..dd36ec389 100644 --- a/src/scenes/director.test.mjs +++ b/src/scenes/director.test.mjs @@ -2140,6 +2140,7 @@ test('a hold resumed partway waits for a clip that starts again, else only its r let reads = 0; const module = { getSceneShotMediaHold: () => ({ pending: reads++ < pendingReads, maxWaitMs: 20000 }), + sceneShotRestartsMedia: () => pendingReads > 0, }; const waits = []; await SceneDirector.prototype._holdShot.call( @@ -2158,7 +2159,8 @@ test('a hold resumed partway waits for a clip that starts again, else only its r return waits; }; // The clip plays again: the hold polls until it is done, as any hold does. - assert.deepEqual(await hold(4), [70, 70]); + const polls = await hold(4); + assert.ok(polls.length && polls.every((ms) => ms === 70), String(polls)); // The moment was past the clip: only the rest of the hold. assert.deepEqual(await hold(0), [2000]); });