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.
This commit is contained in:
Sameh Khamis committed 2026-11-16 14:20:55 -08:00
1 parent 5cce9d0705
commit 186f8b76d9
5 files changed
+106 -8

No files matched your search

+24
View File
@@ -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 {
+60
View File
@@ -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();
+14 -5
View File
@@ -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,
+3 -1
View File
@@ -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]);
});