mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 09:39:58 -04:00
Keep movies with their sound at any frame rate: one movie frame per update, and the pacer keeps the movie's slots through a late frame.
The game's movie player adds the time manager's step to an accumulator at each update and advances the movie by whole pictures of it, at most the player's limit per update, which is one for the Triforce movie. While a movie plays the game is held at 60 updates a second, but every late frame cost an update, the pacer started its slots again from the late one, and the steady step's payback of the lost time came as steps over one frame, which the player cannot turn into more than one picture. So each late frame put the picture further behind the sound, which plays by the clock, and it never caught up. While a movie plays the step is now exactly one movie frame, and the pacer keeps the movie's slots through a lateness of up to a second, presenting the frames after a late one at once until the game is back on them. The updates then average the movie's rate, and the picture, the event's update count and the game's clock all stay with the sound. movie_clock = 0 gives the earlier behaviour. The movie log now measures the picture on screen against real time where the game releases it (the game fetches pictures ahead into a list of its own) and reports it at the end of each movie. test_hitch = <every>:<ms> makes a frame that much late every so many presents, for test runs. Measured on the Triforce movie (event Dm_Kokiri_0095, 7,040 pictures, 117 s), one exe with movie_clock = 0 against 1, and a 70 ms late frame every two seconds (test_hitch = 120:70), as a run with natural hitches had shown a drift of 40 ms every ten seconds. Drift of the picture on screen behind real time, from the movie's first 10 s to its end: fps_limit before (updates/s, drift at the end) after (updates/s, drift over the movie) unlimited 58.86, 2,187 ms behind 60.22, flat at 53 to 55 ms 144 58.86, 2,196 ms behind 60.04, flat at -11 to -15 ms 120 58.98, 2,257 ms behind 60.20, flat at -1 to 0 ms 60 58.88, 2,220 ms behind 59.98, flat at -21 to -22 ms Without the late frames both kept time (unlimited: before flat at 21 ms, after flat at -13 ms). The selftest, --probe-cfg, --probe-kernel, --probe-movie and tests/frame_step_check.py pass; the check now plays a movie started at 240 fps with late and short frames and needs exactly one frame every update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -773,12 +773,20 @@ static uint64_t present_period(const win_t *o) {
|
||||
|
||||
// The present slot is the previous slot plus one period. Early: wait for the slot. Late by
|
||||
// less than a period: present at once and keep the phase. Behind by a period or more: restart from now, no catch-up
|
||||
// burst. Returns the ns to wait.
|
||||
// burst, except while a movie plays (frame_step_movie_hz): then the slots are kept through a lateness up to
|
||||
// MOVIE_CATCHUP_NS and the frames after a late one go at once until the game is back on them. A movie shows one
|
||||
// picture per game update and its sound plays by the clock (frame_rate.c ocarina_step), so every period dropped here
|
||||
// was a picture the movie fell behind for good: with a 70 ms frame every two seconds (NX2NAVI_TEST_HITCH=120:70) the
|
||||
// updates averaged 58.9 a second and the Triforce movie's picture fell 190 ms behind its sound every ten seconds, 2.2 s
|
||||
// by the end of its 117 s, at every frame limit from 60 to unlimited; with the slots kept it stayed within 22 ms. A
|
||||
// stall of a second or more (a load) restarts the slots as before. Returns the ns to wait.
|
||||
#define MOVIE_CATCHUP_NS 1000000000ull
|
||||
static uint64_t pace(uint64_t *target, uint64_t now, uint64_t period) {
|
||||
if (!period || !*target) { *target = now; return 0; }
|
||||
uint64_t next = *target + period;
|
||||
if (now <= next) { *target = next; return next - now; }
|
||||
*target = now - next < period ? next : now;
|
||||
uint64_t keep = frame_step_movie_hz() > 0 ? MOVIE_CATCHUP_NS : period;
|
||||
*target = now - next < keep ? next : now;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -873,6 +881,15 @@ NVN_API(nvnQueuePresentTexture) {
|
||||
o->presents++;
|
||||
__atomic_store_n(&nvn_submits_in_frame, 0, __ATOMIC_RELAXED);
|
||||
const tex_t *t = (const tex_t *)o->tex[idx];
|
||||
static int hitch_every = -1, hitch_ms; // NX2NAVI_TEST_HITCH=<every>:<ms>: a late frame every so many presents
|
||||
if (hitch_every < 0) {
|
||||
const char *e = cfg_get("NX2NAVI_TEST_HITCH");
|
||||
int every = 0, ms = 0;
|
||||
hitch_every = e && sscanf(e, "%d:%d", &every, &ms) == 2 && every > 0 && ms > 0 ? every : 0;
|
||||
hitch_ms = ms;
|
||||
if (hitch_every) rt_log("nvn: a %d ms late frame every %d presents (NX2NAVI_TEST_HITCH)", hitch_ms, hitch_every);
|
||||
}
|
||||
if (hitch_every && o->presents % (uint64_t)hitch_every == 0) plat_wait_ns((uint64_t)hitch_ms * 1000000);
|
||||
uint64_t period = present_period(o), now = kern_now_ns();
|
||||
uint64_t slot = now + pace(&o->pace, now, period);
|
||||
gfx_backend()->present(t, o->crop, slot);
|
||||
|
||||
Reference in New Issue
Block a user