mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 22:19:57 -04:00
Keep RivaTuner Statistics Server's profile as it was in rtss-profile.txt, so a start after a kill or crash puts it back, and leave it to that start at a crash.
An exit that skipped rtss_limit_restore (Task Manager, a hang, lost_wait_exit, a kill during the pipeline save) left the game's limit in Profiles\<exe>.cfg, and the next run's first apply took it for the player's own: that run then put the stale limit back at its close, and a profile the game had made stayed for good (lane A's probe: kill1, then kill2 'held a limit of 60/1'). The crash handler and the fatal error's end also called into RTSSHooks64.dll from a process that had failed (P-13). rtss_limit.c now keeps one line per profile in rtss-profile.txt next to the executable (rtss_decide.h RtssSaved: whether the profile existed, its old limit and denominator, the value the run wrote), written atomically before the run's first change of the profile, updated with each value written, and removed once the profile is back (put_back; also when the first write did not stick). On the first poll with the hooks library a start that finds a line of its profile puts the profile back first (restore_left, rtss_restore_plan): the old limit, or no profile, unless the player changed or removed it since, which the written value tells. main.c crash_handler and dispatch.c fatal_end call the new rtss_limit_crash, which closes the run and leaves the profile to that start with no call into RTSS's library; only when the file could not be written does it put the profile back as before, and never from the worker's own thread. A file that cannot be written leaves the run as it was, with one line in the log. Profiles frozen by earlier versions cannot be told from the player's own. Not reproduced before the change. rtss_limit_check (T12: the line's format and parse, the file's rewrite, each plan; the static check that both crash paths go through rtss_limit_crash), rtss_worker_check (state_record, state_player, state_unwritable, crash_recorded, and kill_restart with its player and edited variants, each a killed run and the next start in processes of their own), fatal_exit_check and exit_order_check pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -122,12 +122,10 @@ static void fatal_end(int code, const char *fmt, va_list ap) {
|
||||
kern_free_cores_note();
|
||||
fs_save_crash_wait(); // a save the game already reported as done finishes first (bounded)
|
||||
prof_sampler_write(); // NX2NAVI_PROFILE: what was sampled until now, else a crash loses the whole profile
|
||||
// RivaTuner Statistics Server's profile as it was: left with the game's limit in it, the next run would take that
|
||||
// limit for the player's own (rtss_limit.c; it gives up after a second if the failing thread holds its lock). Not
|
||||
// from RTSS's own thread, which may hold that lock: the restore would spend its second for nothing (as in main.c
|
||||
// crash_handler).
|
||||
const char *thread = plat_thread_name();
|
||||
if (!thread || strcmp(thread, "rtss")) rtss_limit_restore();
|
||||
// RivaTuner Statistics Server's profile goes back at the next start, from the line the run keeps for it in
|
||||
// rtss-profile.txt (rtss_limit.c rtss_limit_crash, as in main.c crash_handler): no call into RTSS's library here,
|
||||
// from any thread
|
||||
rtss_limit_crash();
|
||||
rt_rumble_stop_bounded(); // a controller on HD rumble: nothing renews or stops its vibration after the end
|
||||
// "frametime: at a fatal error" and the stutter map, the session's last period: after what a kill of the process
|
||||
// must not lose, as in the orderly end (gfx_present.c rt_exit_steps); ft_stop waits up to 50 ms
|
||||
|
||||
@@ -472,6 +472,8 @@ int rtss_limit_state(void); // menu: 1 RTSS limits
|
||||
// game run past its limit, 4 kept out while a limit set in
|
||||
// RTSS itself holds the game too
|
||||
void rtss_limit_restore(void); // before the process ends: the profile's old limit back
|
||||
void rtss_limit_crash(void); // a crash or fatal error: no call into RTSS, the next start
|
||||
// puts the profile back (rtss-profile.txt)
|
||||
int64_t frame_step_world_us(void); // game time since the loaded save's first frame, -1 before
|
||||
// (NX2NAVI_FPS_LIMIT, live)
|
||||
uint64_t frame_step_ticks(void); // game time since the first present in 60 Hz ticks (input scripts)
|
||||
|
||||
@@ -436,9 +436,9 @@ static void crash_handler(const PlatCrash *x) {
|
||||
rt_fatal_notes(); // the card, its driver and the memory settings in effect (vk_device.c fatal_note)
|
||||
kern_free_cores_note();
|
||||
fs_save_crash_wait(); // a save the game already reported as done finishes first (bounded; fs_host.c)
|
||||
// after the report: RivaTuner Statistics Server's profile as it was; not from its own thread, which holds the lock
|
||||
// the restore would try for a second
|
||||
if (!on_rtss) rtss_limit_restore();
|
||||
// after the report: RivaTuner Statistics Server's profile goes back at the next start, from the line the run keeps
|
||||
// for it (rtss_limit.c rtss_limit_crash): no call into RTSS's library from a process that failed
|
||||
rtss_limit_crash();
|
||||
rt_rumble_stop_bounded(); // a controller on HD rumble stops (dispatch.c: 300 ms at most, SDL may be the crash)
|
||||
fflush(stderr);
|
||||
prof_sampler_write(); // NX2NAVI_PROFILE: what was sampled until the crash (it gives up after 2 s if the sampler hangs)
|
||||
|
||||
@@ -231,11 +231,11 @@ static inline void rtss_why_text(char *out, size_t n, const RtssOut *o, int fail
|
||||
// gfx_present.c gfx_window_hosted_ns, 0 before the first). The limit's own period while RTSS does not hold the game,
|
||||
// while a movie plays (from its first frame: the pacer keeps the movie's slots, which RTSS does not know, and the
|
||||
// worker's next poll gives the movie to the pacer for its length, rtss_target), before the first host present, and
|
||||
// once no host present went out for RTSS_HOLD_IDLE_NS: a minimised window or a
|
||||
// frame hold (vk_backend.c frame_hold) gives RTSS nothing to hold, and a pacer that held nothing then let the quick menu
|
||||
// run at the 640-700 fps that read address 0 (frame_rate.c LIMIT_FREE_MAX_HZ). While RTSS holds, the ceiling's period
|
||||
// and never 0: the frames RTSS lets through come further apart than that, so pace() waits for none of them, and it
|
||||
// still holds the game's frames to the ceiling the game's code needs.
|
||||
// once no host present went out for RTSS_HOLD_IDLE_NS: a minimised window or a frame hold (vk_backend.c frame_hold)
|
||||
// gives RTSS nothing to hold, and a pacer that held nothing then let the quick menu run at the 640-700 fps that read
|
||||
// address 0 (frame_rate.c LIMIT_FREE_MAX_HZ). While RTSS holds, the ceiling's period and never 0: the frames RTSS lets
|
||||
// through come further apart than that, so pace() waits for none of them, and it still holds the game's frames to the
|
||||
// ceiling the game's code needs.
|
||||
static inline uint64_t rtss_pace_period(int holds, int movie, uint64_t now_ns, uint64_t hosted_ns, uint64_t period,
|
||||
uint64_t ceiling) {
|
||||
uint64_t idle = now_ns > hosted_ns ? now_ns - hosted_ns : 0;
|
||||
@@ -243,6 +243,111 @@ static inline uint64_t rtss_pace_period(int holds, int movie, uint64_t now_ns, u
|
||||
return ceiling < period ? ceiling : period;
|
||||
}
|
||||
|
||||
// ---- the state file (rtss_limit.c, rtss-profile.txt next to the executable): each RTSS profile a run changed, as it
|
||||
// was before, so that a start after a run that did not close (a kill, a hang, a crash) puts it back. One line per
|
||||
// profile, so executables that share the folder keep their own:
|
||||
// rtss1 <existed 0|1> <old limit> <old denominator> <written limit> <written denominator> <profile name>
|
||||
// The name comes last and may hold spaces; lines that start with # are comments.
|
||||
#define RTSS_SAVED_HEADER \
|
||||
"# RivaTuner Statistics Server's profiles as they were before the game changed them (rtss_limit.c): existed, old\n" \
|
||||
"# limit and denominator, the game's limit and denominator, profile. The game puts a profile back and removes its\n" \
|
||||
"# line when it closes; a start that finds a line puts that profile back first.\n"
|
||||
enum { RTSS_NAME_MAX = 260 };
|
||||
|
||||
typedef struct {
|
||||
int existed; // the profile existed before the run changed it
|
||||
uint32_t old_limit, old_den; // what it held then
|
||||
uint32_t limit, den; // what the run wrote last
|
||||
char name[RTSS_NAME_MAX]; // the profile's name, the executable's (ocarina.exe)
|
||||
} RtssSaved;
|
||||
|
||||
// The line of r, with its newline: its length, 0 when it does not fit n.
|
||||
static inline size_t rtss_saved_format(char *out, size_t n, const RtssSaved *r) {
|
||||
int k = snprintf(out, n, "rtss1 %d %u %u %u %u %s\n", r->existed ? 1 : 0, r->old_limit, r->old_den, r->limit,
|
||||
r->den, r->name);
|
||||
return k > 0 && (size_t)k < n ? (size_t)k : 0;
|
||||
}
|
||||
|
||||
// One line (len bytes, no newline) into r: 1 when it is a well-formed line of this format, 0 otherwise.
|
||||
static inline int rtss_saved_parse(const char *line, size_t len, RtssSaved *r) {
|
||||
char buf[RTSS_NAME_MAX + 96];
|
||||
while (len && (line[len - 1] == '\r' || line[len - 1] == ' ')) len--;
|
||||
if (len >= sizeof buf) return 0;
|
||||
memcpy(buf, line, len);
|
||||
buf[len] = 0;
|
||||
int existed = -1, at = 0;
|
||||
unsigned v[4];
|
||||
if (sscanf(buf, "rtss1 %d %u %u %u %u %n", &existed, &v[0], &v[1], &v[2], &v[3], &at) != 5 || !at) return 0;
|
||||
size_t name = len - (size_t)at;
|
||||
if ((existed != 0 && existed != 1) || !v[1] || !v[3] || !name || name >= RTSS_NAME_MAX) return 0;
|
||||
r->existed = existed, r->old_limit = v[0], r->old_den = v[1], r->limit = v[2], r->den = v[3];
|
||||
memcpy(r->name, buf + at, name + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Profile names compare as Windows compares file names: ASCII letters in either case.
|
||||
static inline int rtss_name_eq(const char *a, const char *b) {
|
||||
for (;; a++, b++) {
|
||||
int x = *a >= 'A' && *a <= 'Z' ? *a + 32 : *a, y = *b >= 'A' && *b <= 'Z' ? *b + 32 : *b;
|
||||
if (x != y) return 0;
|
||||
if (!x) return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// The line of profile name in the file's text (NUL-terminated): 1 and r, or 0. A line that is not well formed is
|
||||
// passed over, and the lines after it are still read.
|
||||
static inline int rtss_saved_find(const char *text, const char *name, RtssSaved *r) {
|
||||
for (const char *p = text; p && *p;) {
|
||||
const char *end = strchr(p, '\n');
|
||||
size_t len = end ? (size_t)(end - p) : strlen(p);
|
||||
if (*p != '#' && rtss_saved_parse(p, len, r) && rtss_name_eq(r->name, name)) return 1;
|
||||
p = end ? end + 1 : NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The file's text with profile name's line replaced by r's (r NULL: removed): the header, every other profile's
|
||||
// well-formed line as it was, then r's. Comments, blank and malformed lines are dropped. Writes the text into out and
|
||||
// returns its length (0 when it does not fit cap); *records is the number of profile lines in it, 0 when the file is
|
||||
// to go.
|
||||
static inline size_t rtss_saved_update(const char *text, const char *name, const RtssSaved *r, char *out, size_t cap,
|
||||
int *records) {
|
||||
size_t at = (size_t)snprintf(out, cap, "%s", RTSS_SAVED_HEADER);
|
||||
*records = 0;
|
||||
if (at >= cap) return 0;
|
||||
for (const char *p = text; p && *p;) {
|
||||
const char *end = strchr(p, '\n');
|
||||
size_t len = end ? (size_t)(end - p) : strlen(p);
|
||||
RtssSaved other;
|
||||
if (*p != '#' && rtss_saved_parse(p, len, &other) && !rtss_name_eq(other.name, name)) {
|
||||
size_t k = rtss_saved_format(out + at, cap - at, &other);
|
||||
if (!k) return 0;
|
||||
at += k, ++*records;
|
||||
}
|
||||
p = end ? end + 1 : NULL;
|
||||
}
|
||||
if (r) {
|
||||
size_t k = rtss_saved_format(out + at, cap - at, r);
|
||||
if (!k) return 0;
|
||||
at += k, ++*records;
|
||||
}
|
||||
return at;
|
||||
}
|
||||
|
||||
// What a start does with a line a run that did not close left (r), given the profile as it is now: whether it exists
|
||||
// and the limit and denominator it holds.
|
||||
enum {
|
||||
RTSS_PLAN_NONE, // no profile, and there was none before that run: as it was
|
||||
RTSS_PLAN_LEAVE, // the player changed or removed the profile since: theirs as it is
|
||||
RTSS_PLAN_WRITE, // it still holds what the run wrote: the old limit and denominator back
|
||||
RTSS_PLAN_DELETE, // the same, for a profile that run made: removed
|
||||
};
|
||||
static inline int rtss_restore_plan(const RtssSaved *r, int exists, uint32_t limit, uint32_t den) {
|
||||
if (!exists) return r->existed ? RTSS_PLAN_LEAVE : RTSS_PLAN_NONE;
|
||||
if (limit != r->limit || (den ? den : 1) != r->den) return RTSS_PLAN_LEAVE;
|
||||
return r->existed ? RTSS_PLAN_WRITE : RTSS_PLAN_DELETE;
|
||||
}
|
||||
|
||||
// ---- RTSS's own settings
|
||||
// RTSS's own [Framerate] settings for the game, as its profile file holds them (rtss_limit.c read_settings): a frame
|
||||
// rate limit (Limit over LimitDenominator), a frame time limit (LimitTime over LimitTimeDenominator) and scanline sync
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
// The calls run on a thread of their own, every half second, which also looks RTSS up (find_rtss), so a present never
|
||||
// waits on the registry or profile files. On every orderly exit (rtss_limit_restore) the profile gets back what it held
|
||||
// before the game changed it: the old limit, or no profile of its own when there was none; from then on no want reaches
|
||||
// it and the game's own limiter paces the frames left. An exit that skips it (a kill, the device-lost watchdog, a crash
|
||||
// inside the crash handler) leaves the game's limit in the profile, and the next run takes that limit for the player's
|
||||
// own.
|
||||
// it and the game's own limiter paces the frames left. What it held is also kept in rtss-profile.txt next to the
|
||||
// executable (rtss_decide.h RtssSaved), written before the run's first change of the profile and removed once the
|
||||
// profile is back: an exit that skips the restore (a kill, a hang, the device-lost watchdog) leaves the line, and the
|
||||
// next start puts the profile back from it before it changes anything (restore_left), unless the player changed the
|
||||
// profile since. A crash and a fatal error leave it to that start too (rtss_limit_crash), with no call into RTSS's
|
||||
// library from the failing process.
|
||||
//
|
||||
// NX2NAVI_RTSS=0 keeps RTSS out of it. Frame generation keeps it out too (RTSS counts every presented frame, the
|
||||
// generated ones included), and so does a driver's low latency (vk_lowlat.c), which holds the frames where they start.
|
||||
@@ -34,6 +37,7 @@
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "host.h"
|
||||
@@ -70,6 +74,11 @@ static int has_denominator; // this RTSS knows FramerateLimitDenominator
|
||||
static int had_profile; // the profile existed before this run changed it
|
||||
static DWORD old_limit, old_denominator = 1;
|
||||
static int creations, removals; // the profile's "created" and "removed" lines this run, numbered (under lock)
|
||||
static char state_path[MAX_PATH + 32]; // rtss-profile.txt next to the executable; "" when its path is unknown
|
||||
static RtssSaved rec; // this run's line in it, while the profile holds a value of this run
|
||||
static _Atomic int recorded; // the file holds rec: a crash leaves the profile to the next start
|
||||
static int state_off; // a line this run could not act on stays as it is: no writes of the file
|
||||
static _Atomic uint32_t rtss_tid; // the worker's thread, which may hold the lock when a crash comes
|
||||
|
||||
// RTSS's shared memory as rtss_parse reads it: whether RTSS runs, whether it lists this process, and its frame count.
|
||||
static void rtss_map(RtssApp *a) {
|
||||
@@ -150,8 +159,48 @@ static int write_limit(DWORD limit, DWORD denominator) {
|
||||
return l == limit && (!has_denominator || d == denominator) ? 1 : -1;
|
||||
}
|
||||
|
||||
// The state file with this profile's line set to r, or removed for r NULL; the file goes once it holds no line. Worker
|
||||
// thread only, under lock. 1 when the file holds what was asked.
|
||||
static int state_put(const RtssSaved *r) {
|
||||
if (state_off || !*state_path) return 0;
|
||||
uint64_t n = 0;
|
||||
char *text = (char *)plat_file_read(state_path, &n);
|
||||
size_t cap = (size_t)(text ? n : 0) + sizeof RTSS_SAVED_HEADER + 2 * (RTSS_NAME_MAX + 96);
|
||||
char *out = malloc(cap);
|
||||
int records = 0, ok = 0;
|
||||
size_t len = out ? rtss_saved_update(text ? text : "", profile, r, out, cap, &records) : 0;
|
||||
if (len && !records) {
|
||||
plat_file_delete(state_path);
|
||||
ok = !plat_file_exists(state_path);
|
||||
} else if (len) {
|
||||
ok = plat_file_write_atomic(state_path, out, len);
|
||||
}
|
||||
free(out);
|
||||
free(text);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The state file did not take this run's line: a crash then puts the profile back as an orderly exit does
|
||||
// (rtss_limit_crash). Logged once a run.
|
||||
static void unrecorded(void) {
|
||||
static int said;
|
||||
atomic_store(&recorded, 0);
|
||||
if (!state_off && !said++)
|
||||
rt_log("frame rate: %s could not be written; a crash would leave the game's limit in RivaTuner Statistics "
|
||||
"Server's profile %s", *state_path ? state_path : "rtss-profile.txt", profile);
|
||||
}
|
||||
|
||||
// rec's written value is limit/denominator now: the line follows it, so that the next start tells the game's value from
|
||||
// a value the player set since.
|
||||
static void record(DWORD limit, DWORD denominator) {
|
||||
if (!atomic_load(&recorded) || (rec.limit == limit && rec.den == denominator)) return;
|
||||
rec.limit = limit, rec.den = denominator;
|
||||
if (!state_put(&rec)) unrecorded();
|
||||
}
|
||||
|
||||
// Writes mhz into the profile (rtss_poll's RtssOps.apply): RTSS_WROTE_*. first: the run's first write, which records
|
||||
// what to put back on exit; clear: on a refusal, clear the limit of this run the profile holds.
|
||||
// what to put back on exit, in the state file too before anything changes; clear: on a refusal, clear the limit of this
|
||||
// run the profile holds.
|
||||
static int apply(void *ctx, int64_t mhz, int first, int clear) {
|
||||
(void)ctx;
|
||||
if (first) { // what to put back on exit
|
||||
@@ -166,10 +215,17 @@ static int apply(void *ctx, int64_t mhz, int first, int clear) {
|
||||
if (mhz % 1000 == 0) limit = (DWORD)(mhz / 1000);
|
||||
else if (has_denominator) limit = (DWORD)mhz, denominator = 1000;
|
||||
else limit = (DWORD)((mhz + 500) / 1000);
|
||||
if (first) { // the line goes in before the profile changes: a kill between the two finds it as it was
|
||||
rec = (RtssSaved){had_profile, old_limit, old_denominator, limit, denominator, ""};
|
||||
snprintf(rec.name, sizeof rec.name, "%s", profile);
|
||||
if (state_put(&rec)) atomic_store(&recorded, 1);
|
||||
else unrecorded();
|
||||
}
|
||||
int r = write_limit(limit, denominator);
|
||||
if (r < 0) {
|
||||
rt_log("frame rate: RivaTuner Statistics Server's profile %s did not keep the limit: its Profiles folder needs the "
|
||||
"game run as administrator", profile);
|
||||
if (first && atomic_exchange(&recorded, 0)) state_put(NULL); // the profile is as it was
|
||||
return RTSS_WROTE_READONLY;
|
||||
}
|
||||
if (first) {
|
||||
@@ -183,11 +239,13 @@ static int apply(void *ctx, int64_t mhz, int first, int clear) {
|
||||
if (r == 0) { // RTSS must not keep an earlier limit of this run under the game's own one
|
||||
rt_log("frame rate: RivaTuner Statistics Server refused a limit of %.3f fps", mhz / 1000.0);
|
||||
if (clear && write_limit(0, 1) > 0) {
|
||||
record(0, 1);
|
||||
update_profiles();
|
||||
return RTSS_WROTE_REFUSED_CLEARED;
|
||||
}
|
||||
return RTSS_WROTE_REFUSED;
|
||||
}
|
||||
record(limit, denominator);
|
||||
update_profiles();
|
||||
if (!mhz) rt_log("frame rate: RivaTuner Statistics Server's profile %s has no limit", profile);
|
||||
else if ((int64_t)limit * 1000 == mhz * denominator)
|
||||
@@ -198,8 +256,10 @@ static int apply(void *ctx, int64_t mhz, int first, int clear) {
|
||||
return RTSS_WROTE_HELD;
|
||||
}
|
||||
|
||||
// The profile as it was before this run changed it (the caller checked S.changed, and marks it done).
|
||||
// The profile as it was before this run changed it (the caller checked S.changed, and marks it done). Its line in the
|
||||
// state file goes once it is back; one that did not take its old limit keeps it for the next start.
|
||||
static void put_back(void) {
|
||||
int back = 1;
|
||||
if (!had_profile) {
|
||||
delete_profile(profile);
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s removed, as before the game started "
|
||||
@@ -209,8 +269,54 @@ static void put_back(void) {
|
||||
old_denominator);
|
||||
} else {
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s did not take its old limit back", profile);
|
||||
back = 0;
|
||||
}
|
||||
update_profiles();
|
||||
if (back && atomic_exchange(&recorded, 0)) state_put(NULL);
|
||||
}
|
||||
|
||||
// A line of this profile in the state file, left by a run that did not close: on the first poll with the hooks library,
|
||||
// before this run changes anything, the profile gets back what it held before that run (rtss_restore_plan), unless the
|
||||
// player changed it since, and the line goes. A profile that does not take its old limit keeps the line, and this run
|
||||
// leaves the file alone.
|
||||
static void restore_left(void) {
|
||||
uint64_t n = 0;
|
||||
char *text = *state_path ? (char *)plat_file_read(state_path, &n) : NULL;
|
||||
RtssSaved r;
|
||||
int found = text && rtss_saved_find(text, profile, &r);
|
||||
free(text);
|
||||
if (!found) return;
|
||||
int exists = profile_exists();
|
||||
load_profile(profile);
|
||||
DWORD limit = 0, den = 1;
|
||||
get_property("FramerateLimit", (LPBYTE)&limit, sizeof limit);
|
||||
has_denominator = get_property("FramerateLimitDenominator", (LPBYTE)&den, sizeof den);
|
||||
int plan = rtss_restore_plan(&r, exists, limit, den);
|
||||
if (plan == RTSS_PLAN_WRITE && write_limit(r.old_limit, r.old_den) <= 0) {
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s still has the game's limit of %u/%u from a run that "
|
||||
"did not close, and did not take its old limit back; %s keeps its line", profile, r.limit, r.den,
|
||||
state_path);
|
||||
state_off = 1;
|
||||
return;
|
||||
}
|
||||
if (plan == RTSS_PLAN_DELETE) delete_profile(profile);
|
||||
if (plan == RTSS_PLAN_WRITE || plan == RTSS_PLAN_DELETE) update_profiles();
|
||||
if (plan == RTSS_PLAN_WRITE)
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s had the game's limit of %u/%u from a run that did not "
|
||||
"close (%s); its limit of %u/%u is back", profile, r.limit, r.den, state_path, r.old_limit, r.old_den);
|
||||
else if (plan == RTSS_PLAN_DELETE)
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s had the game's limit of %u/%u from a run that did not "
|
||||
"close (%s); removed, as before that run", profile, r.limit, r.den, state_path);
|
||||
else if (plan == RTSS_PLAN_LEAVE)
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s changed since a run that did not close (%s); left as "
|
||||
"it is", profile, state_path);
|
||||
else
|
||||
rt_log("frame rate: RivaTuner Statistics Server profile %s is as it was before a run that did not close (%s)",
|
||||
profile, state_path);
|
||||
if (!state_put(NULL)) {
|
||||
rt_log("frame rate: %s could not be written; its line for %s stays", state_path, profile);
|
||||
state_off = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void put_back_op(void *ctx, const RtssOut *o) { // rtss_poll's RtssOps.put_back
|
||||
@@ -339,6 +445,9 @@ static int find_rtss(void) {
|
||||
for (const char *s = exe; *s; s++)
|
||||
if (*s == '\\' || *s == '/') base = s + 1;
|
||||
snprintf(profile, sizeof profile, "%s", base); // RTSS names a profile after the executable, as ocarina.exe
|
||||
char path[MAX_PATH], *cut; // the state file next to the executable, where nx2navi.ini is (cfg.c find_ini)
|
||||
if (plat_exe_path(path, sizeof path) && (cut = plat_last_sep(path)))
|
||||
snprintf(state_path, sizeof state_path, "%.*s%s", (int)(cut + 1 - path), path, "rtss-profile.txt");
|
||||
int64_t first = atomic_load(&want);
|
||||
if (first >= 0)
|
||||
rt_log("frame rate: RivaTuner Statistics Server found in %s; it takes the frame limit while it runs", dir);
|
||||
@@ -351,9 +460,10 @@ static int find_rtss(void) {
|
||||
|
||||
static void worker(void *arg) {
|
||||
(void)arg;
|
||||
atomic_store(&rtss_tid, plat_thread_id());
|
||||
if (!find_rtss()) return;
|
||||
atomic_store_explicit(&ready, 1, memory_order_release); // rtss_limit_restore may read the names now
|
||||
int was_running = -1, was_listed = 0;
|
||||
int was_running = -1, was_listed = 0, left_checked = 0;
|
||||
const RtssOps ops = {NULL, apply, put_back_op};
|
||||
for (;; plat_sleep_ms(POLL_MS)) {
|
||||
int64_t w = atomic_load(&want);
|
||||
@@ -372,6 +482,7 @@ static void worker(void *arg) {
|
||||
was_running = in.app.running, was_listed = in.app.listed;
|
||||
}
|
||||
in.hooks = dll ? 1 : rtss_wants_hooks(&S, &in) ? load_hooks() : -1;
|
||||
if (in.hooks == 1 && !left_checked) left_checked = 1, restore_left();
|
||||
in.current = atomic_load(&want) == w;
|
||||
RtssOut o = rtss_poll(&S, &in, &ops);
|
||||
atomic_store(&failed, S.fail);
|
||||
@@ -432,10 +543,23 @@ void rtss_limit_restore(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// A crash's and a fatal error's end (main.c crash_handler, dispatch.c fatal_end), from any thread: no want reaches the
|
||||
// profile any more, and no call goes into RTSS's library, which may be what failed and is no safe call on a damaged
|
||||
// heap. The state file keeps this run's line, and the next start puts the profile back from it (restore_left). Without
|
||||
// that line (the file could not be written) the profile goes back as at an orderly exit, but not from the worker's own
|
||||
// thread, which may hold the lock that takes.
|
||||
void rtss_limit_crash(void) {
|
||||
atomic_store(&closed, 1);
|
||||
atomic_store(&active_for, RTSS_UNSET);
|
||||
if (atomic_load(&recorded) || plat_thread_id() == atomic_load(&rtss_tid)) return;
|
||||
rtss_limit_restore();
|
||||
}
|
||||
|
||||
#else
|
||||
void rtss_limit_want(int64_t mhz) { (void)mhz; }
|
||||
void rtss_limit_movie(int hz) { (void)hz; }
|
||||
int rtss_limit_active(void) { return 0; }
|
||||
int rtss_limit_state(void) { return 0; }
|
||||
void rtss_limit_restore(void) {}
|
||||
void rtss_limit_crash(void) {}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user