A video used to run on its own clock as soon as a sprite wore it. An animation could switch the sprite on and off, but never say which picture shows at which frame. Cutting a video in an animation needs the opposite: the animation sets the time and the video follows. - Sprites wearing a video or a clip get two rows, Video clock and Video time. They show only while the texture holds a video. - With Video clock on Driven the video does not play by itself. It shows the picture at Video time, counted from the clip's start. Past the end it goes round with Loop and holds the last picture without. - Video time is a number like any other, so keys, step, easing and curves give stills, slow motion and ramps. - A driven sprite gets a player of its own, keyed by the wearer's name. The same clip can run twice at different times. - Following has two ways (`videoFollow.ts`). Running forward at 0.25x to 4x the video plays at that rate and is nudged. A still, a scrub or a step backwards seeks, and only the newest seek counts. - Sound is heard only near 1x. The animation tab now plays it too, so a cut can follow the sound. Scrubbing is silent. - Scene, game view, the inspector's PREVIEW and the shader preview show the driven picture. In a running game Play animation sets it. Found on the way: - After a scrub the video in the animation tab kept running. The preview redrew only while the playhead moved, so nobody asked for the video once it stood. `AnimationEditor.tick` now redraws it every frame while it shows a video. - Every sprite has two more defaults (`videoClock: 'free'`, `videoTime: 0`). Eight tests in five files pinned the old list and are updated. Tests: - Unit: video-clock and video-follow new, 4 files with 42 tests green. - e2e 66 (melektaus-atx): ALL PASSED, 22 checks, 3 new. 66i: two sprites on one clip stand at 0.2 s red and 0.7 s green. 66j: a scrub to frames 2, 7, 12 and 3 shows red, green, blue, red, and each colour still stands 0.7 s later. 66k: playing runs 10-30 ms behind at rate 1.00-1.03 and is not muted. - Counterchecks: a seek that keeps the rate turns the seek test red. Not seeing Driven turns 66i, 66j and 66k red. - Gate (melektaus-atx): exit 0, 297 files, 4546 tests. - Not tested in the browser: Play animation in a running game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
/**
|
|
* When the video library lets a player go (#402): after 2 s nobody asked for it, but never while
|
|
* the page is hidden. Chrome draws no frames for a hidden page and so nothing asks, while the
|
|
* sweeper's timer goes on; a sprite still wearing the video lost it and Pixi warned about the
|
|
* destroyed source on the way back.
|
|
*/
|
|
const KEY = `video:a1b2c3d4e5f6/${'c7'.repeat(32)}.mp4#0~0~1~1`;
|
|
|
|
function fakeVideo() {
|
|
return {
|
|
muted: false,
|
|
playsInline: false,
|
|
preload: '',
|
|
src: '',
|
|
currentTime: 0,
|
|
loop: false,
|
|
paused: true,
|
|
addEventListener: () => {},
|
|
requestVideoFrameCallback: () => 0,
|
|
play: () => Promise.resolve(),
|
|
pause: () => {},
|
|
removeAttribute: () => {},
|
|
load: () => {},
|
|
};
|
|
}
|
|
|
|
const page = { hidden: false, listeners: [] as (() => void)[] };
|
|
|
|
function setHidden(hidden: boolean): void {
|
|
page.hidden = hidden;
|
|
for (const listener of page.listeners) listener();
|
|
}
|
|
|
|
async function freshLibrary() {
|
|
const { VideoLibrary } = await import('../../src/viewport/VideoLibrary');
|
|
return new VideoLibrary();
|
|
}
|
|
|
|
describe('VideoLibrary sweeping', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval', 'performance'] });
|
|
page.hidden = false;
|
|
page.listeners = [];
|
|
vi.stubGlobal('document', {
|
|
get hidden() {
|
|
return page.hidden;
|
|
},
|
|
addEventListener: (_type: string, listener: () => void) => page.listeners.push(listener),
|
|
createElement: fakeVideo,
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it('lets a player go that nobody asked for in 2 s', async () => {
|
|
const videos = await freshLibrary();
|
|
videos.get(KEY);
|
|
vi.advanceTimersByTime(4100);
|
|
expect(videos.debugInfo()).toEqual([]);
|
|
});
|
|
|
|
it('keeps it while the page is hidden, however long', async () => {
|
|
const videos = await freshLibrary();
|
|
videos.get(KEY);
|
|
setHidden(true);
|
|
vi.advanceTimersByTime(60_000);
|
|
expect(videos.debugInfo()).toHaveLength(1);
|
|
});
|
|
|
|
it('does not count the time hidden as idle once the page is back', async () => {
|
|
const videos = await freshLibrary();
|
|
videos.get(KEY);
|
|
setHidden(true);
|
|
vi.advanceTimersByTime(60_000);
|
|
setHidden(false);
|
|
vi.advanceTimersByTime(1900);
|
|
expect(videos.debugInfo()).toHaveLength(1);
|
|
vi.advanceTimersByTime(2200);
|
|
expect(videos.debugInfo()).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('VideoLibrary driven players (#404)', () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal('document', { hidden: false, addEventListener: () => {}, createElement: fakeVideo });
|
|
});
|
|
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
const REF = { file: KEY, smooth: true, rect: null, sourceWidth: 320, sourceHeight: 180, slice: null };
|
|
|
|
it('leaves a sprite with a free clock on the shared player', async () => {
|
|
const videos = await freshLibrary();
|
|
expect(videos.wear(REF, { videoTime: 1 }, 'view1:a', false)).toBe(REF);
|
|
expect(videos.debugInfo()).toEqual([]);
|
|
});
|
|
|
|
it('gives every wearer of a driven video a player of its own, opened at its time', async () => {
|
|
const videos = await freshLibrary();
|
|
const a = videos.wear(REF, { videoClock: 'driven', videoTime: 0.5 }, 'view1:a', false);
|
|
const b = videos.wear(REF, { videoClock: 'driven', videoTime: 1.25 }, 'view1:b', false);
|
|
expect([a.file, b.file]).toEqual([`${KEY}@view1:a`, `${KEY}@view1:b`]);
|
|
expect(videos.debugInfo().map(({ key, time }) => [key, time])).toEqual([
|
|
[`${KEY}@view1:a`, 0.5],
|
|
[`${KEY}@view1:b`, 1.25],
|
|
]);
|
|
});
|
|
});
|