mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 15:59:59 -04:00
Hold the game at 60 fps while a movie plays, so the intro's narration no longer doubles and the dream shows at high refresh rates.
The game's event script times the intro movie's narration and fades by counting updates as 60 Hz frames. At 144 fps everything ran 2.4 times early: each line started over the one before, and the closing fade hid the dream. frame_step_cap_ns caps the rate at the movie's 60 fps from the decoder's start to its end of stream (ov_movie_live); with fps_limit = unlimited the cap is the movie's rate. With RTSS limiting, the game's own limiter holds a new rate until RTSS has applied it. NX2NAVI_MOVIE_FPS sets the cap, 0 turns it off. From a tester's fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
|
||||
// Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
|
||||
static const char *const known[] = {
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "OCARINA_STEP", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_FPS", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "OCARINA_STEP", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"AB", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_OFF", "AUDIO_PREFILL_MS",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
|
||||
"BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS",
|
||||
|
||||
@@ -185,6 +185,20 @@ static void frame_limit_live(void) {
|
||||
else rt_log("frame rate: limit at the monitor's refresh rate (60 until the window measures it)");
|
||||
}
|
||||
|
||||
// NX2NAVI_MOVIE_FPS (default 60; 0 = off): the game's frame rate while a movie plays (ov_movie2.c ov_movie_live). A
|
||||
// movie's event counts the game's updates as 60 Hz frames whatever the step: at 144 fps the intro's narration lines
|
||||
// started 2.4 times too early, each over the one before, and its closing fade to black came at 65 s of the movie's
|
||||
// 154, hiding the whole dream. The movies are 60 fps, so the cap shows the same pictures.
|
||||
static int movie_cap_hz(void) {
|
||||
static int hz = -1;
|
||||
if (hz < 0) {
|
||||
const char *e = cfg_get("NX2NAVI_MOVIE_FPS");
|
||||
hz = e && *e ? atoi(e) : 60;
|
||||
if (hz && hz < LIMIT_MIN_HZ) hz = 60;
|
||||
}
|
||||
return hz && ov_movie_live() ? hz : 0;
|
||||
}
|
||||
|
||||
// RivaTuner Statistics Server (rtss_limit.c) gets the same limit; while it limits this process the pacer holds no
|
||||
// frames, so the two never stack. NX2NAVI_RTSS=0 and frame generation (RTSS would count the generated frames) keep it out.
|
||||
uint64_t frame_step_cap_ns(void) {
|
||||
@@ -194,16 +208,28 @@ uint64_t frame_step_cap_ns(void) {
|
||||
const char *e = cfg_get("NX2NAVI_RTSS");
|
||||
rtss = !(e && !strcmp(e, "0")) && !vk_fg_wanted();
|
||||
}
|
||||
if (limit_hz == -2) { // unlimited: the pacer does not hold frames, and RTSS's limit is cleared
|
||||
int movie_hz = movie_cap_hz();
|
||||
static int movie_was, movie_logs;
|
||||
if (!!movie_hz != movie_was) {
|
||||
movie_was = !!movie_hz;
|
||||
if (movie_logs++ < 40) { // the first 20 movies
|
||||
if (movie_hz) rt_log("frame rate: a movie plays: at most %d fps until it ends (NX2NAVI_MOVIE_FPS)", movie_hz);
|
||||
else rt_log("frame rate: the movie ended: the frame limit again");
|
||||
}
|
||||
}
|
||||
if (limit_hz == -2 && !movie_hz) { // unlimited: the pacer does not hold frames, and RTSS's limit is cleared
|
||||
rtss_limit_want(rtss ? 0 : -1);
|
||||
return 0;
|
||||
}
|
||||
double hz = shown_hz(limit_hz ? limit_hz : gfx_window_refresh_hz());
|
||||
// unlimited during a movie: the movie's rate, doubled for frame generation's halving below
|
||||
double hz = limit_hz == -2 ? movie_hz * (vk_fg_generating() ? 2 : 1)
|
||||
: shown_hz(limit_hz ? limit_hz : gfx_window_refresh_hz());
|
||||
double max = frame_free_running() ? LIMIT_FREE_MAX_HZ : LIMIT_MAX_HZ;
|
||||
if (hz > max) hz = max;
|
||||
// Frame generation presents a generated frame between each two of the game's (vk_fg.cpp): the game is paced at
|
||||
// half the limit then, so the screen shows the limit
|
||||
if (vk_fg_generating()) hz /= 2;
|
||||
if (movie_hz && hz > movie_hz) hz = movie_hz;
|
||||
rtss_limit_want(rtss ? (int64_t)(hz * 1000 + 0.5) : -1);
|
||||
if (rtss_limit_active()) return 0;
|
||||
return (uint64_t)(1e9 / hz + 0.5);
|
||||
|
||||
@@ -296,12 +296,13 @@ void *rt_patch_page(void); // the page the patch
|
||||
void frame_step_init(void); // after rt_patches_init: the real-time step's first value
|
||||
int frame_step_realtime(void); // the real-time step is on: presents ignore the interval
|
||||
uint64_t frame_step_cap_ns(void); // with the real-time step: the shortest frame in ns
|
||||
int ov_movie_live(void); // ov_movie2.c: a movie plays (frame_rate.c movie_cap_hz)
|
||||
int frame_limit_adjustable(void); // the frame limit setting changes the rate (always)
|
||||
int frame_free_running(void); // no fps60/realtime patch set: the game steps by the clock
|
||||
double frame_step_limit_hz(void); // the frame rate the limit gives (overlay); 0 unknown
|
||||
// rtss_limit.c: RivaTuner Statistics Server takes the frame limit where it runs
|
||||
void rtss_limit_want(int64_t mhz); // the pacer's limit in millihertz: >0, 0 none, -1 keep RTSS out
|
||||
int rtss_limit_active(void); // RTSS limits this process: the pacer holds no frames
|
||||
int rtss_limit_active(void); // RTSS limits to the wanted rate: the pacer holds no frames
|
||||
int rtss_limit_state(void); // menu: 1 RTSS limits, 2 its profile is read-only, 3 it let the
|
||||
// game run past its limit
|
||||
void rtss_limit_restore(void); // before the process ends: the profile's old limit back
|
||||
|
||||
@@ -66,9 +66,19 @@ typedef struct {
|
||||
int quit, eos_queued;
|
||||
uint64_t generation; // bumped by Flush: pictures of an older one are dropped
|
||||
uint64_t decoded, shown;
|
||||
int live; // counted in movies_live: from Initialize, or a sample after a Flush, to the end-of-stream
|
||||
// picture, Finalize or the destructor
|
||||
} Video;
|
||||
|
||||
static Video *video_of(void *obj) { return obj ? *(Video **)obj : NULL; }
|
||||
static int movies_live; // decoders playing (Video.live); frame_rate.c movie_cap_hz holds the frame rate meanwhile
|
||||
|
||||
int ov_movie_live(void) { return __atomic_load_n(&movies_live, __ATOMIC_RELAXED) > 0; }
|
||||
|
||||
static void set_live(Video *v, int live) { // the guest's decode and acquire threads may race here
|
||||
if (__atomic_exchange_n(&v->live, live, __ATOMIC_RELAXED) != live)
|
||||
__atomic_add_fetch(&movies_live, live ? 1 : -1, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
// under v->lock
|
||||
static void update_events(Video *v) {
|
||||
@@ -411,6 +421,7 @@ static void ov_dtor(Cpu *c) {
|
||||
Video **slot = arg_p(c, 0);
|
||||
if (!slot || !*slot) return;
|
||||
finalize(*slot);
|
||||
set_live(*slot, 0);
|
||||
free(*slot); // the bound events' kernel handles stay, as for any guest event never destroyed
|
||||
*slot = NULL;
|
||||
gfx_movie_stop();
|
||||
@@ -427,6 +438,7 @@ static void ov_initialize(Cpu *c) {
|
||||
}
|
||||
Video *v = *slot;
|
||||
finalize(v);
|
||||
set_live(v, 1);
|
||||
Dav1dSettings s;
|
||||
dav1d_default_settings(&s);
|
||||
// Frame threading on (dav1d picks the delay): heavy stretches of the title movie took longer than a frame to
|
||||
@@ -452,6 +464,7 @@ static void ov_finalize(Cpu *c) {
|
||||
rt_log("movie: video decoder finalised (%llu frames decoded, %llu shown)", (unsigned long long)v->decoded,
|
||||
(unsigned long long)v->shown);
|
||||
finalize(v);
|
||||
set_live(v, 0);
|
||||
}
|
||||
gfx_movie_stop();
|
||||
ret_x(c, 0);
|
||||
@@ -561,6 +574,7 @@ static void ov_decode(Cpu *c) {
|
||||
}
|
||||
v->in[(v->ih + v->in_n) % INMAX] = s;
|
||||
v->in_n++;
|
||||
if (!eos && !v->eos_queued) set_live(v, 1); // playing again after its end (a Flush clears eos_queued)
|
||||
if (eos) v->eos_queued = 1;
|
||||
update_events(v);
|
||||
plat_cond_signal(&v->work);
|
||||
@@ -630,7 +644,7 @@ static void ov_acquire(Cpu *c) {
|
||||
update_events(v);
|
||||
plat_mutex_unlock(&v->lock);
|
||||
if (p.rgba) gfx_movie_frame_own(p.rgba, p.w, p.h), p.rgba = NULL; // the overlay takes the buffer
|
||||
if (p.eos) gfx_movie_stop();
|
||||
if (p.eos) gfx_movie_stop(), set_live(v, 0);
|
||||
picture_free(&p);
|
||||
*out = v->frame[f];
|
||||
ret_x(c, 0);
|
||||
|
||||
@@ -265,8 +265,8 @@ static void worker(void *arg) {
|
||||
over = 0;
|
||||
if (r < 0) atomic_store(&failed, FAIL_READONLY), set_active(0, fail_reason(FAIL_READONLY));
|
||||
else if (r == 0) set_active(0, "RivaTuner Statistics Server refused this limit");
|
||||
else set_active(hooked, "RivaTuner Statistics Server has not hooked the game yet");
|
||||
} else {
|
||||
else if (atomic_load(&want) == w) set_active(hooked, "RivaTuner Statistics Server has not hooked the game yet");
|
||||
} else if (atomic_load(&want) == w) { // a newer limit waits for the next poll (rtss_limit_want)
|
||||
set_active(hooked, "RivaTuner Statistics Server has not hooked the game yet");
|
||||
// RTSS's own count of the game's frames while the game's limiter stands aside: well above the limit for
|
||||
// three seconds means RTSS does not hold the game to it, and the game takes the limiting back for the run
|
||||
@@ -311,7 +311,9 @@ static void start(void) {
|
||||
void rtss_limit_want(int64_t mhz) {
|
||||
if (!started && mhz < 0) return; // kept out from the start, for the whole run (both reasons need a restart)
|
||||
if (!started) start();
|
||||
atomic_store(&want, mhz);
|
||||
// a new limit: the game's own limiter holds it until the worker had RTSS apply it, up to POLL_MS later (a movie's
|
||||
// cap that waited for that ran the movie's 60 Hz count fast for half a second)
|
||||
if (atomic_exchange(&want, mhz) != mhz) atomic_store(&active, 0);
|
||||
}
|
||||
|
||||
int rtss_limit_active(void) { return atomic_load_explicit(&active, memory_order_relaxed); }
|
||||
|
||||
Reference in New Issue
Block a user