diff --git a/runtime/rtss_decide.h b/runtime/rtss_decide.h index ef97c8b9..15fd9814 100644 --- a/runtime/rtss_decide.h +++ b/runtime/rtss_decide.h @@ -30,16 +30,22 @@ static inline const char *rtss_out_limiter(int64_t want) { // 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 -// (SyncScanline0 and SyncScanline1); 0 is off for each. +// (SyncScanline0 and SyncScanline1), 0 off for each; and the modes beside them, for the log: SyncDisplay, ReflexSleep +// and PassiveWait. typedef struct { int limit, limit_den, time, time_den, scan0, scan1; + int sync_display, reflex_sleep, passive_wait; } RtssSettings; // RTSS holds the game's frames by a setting of its own. static inline int rtss_settings_limit(const RtssSettings *s) { return s->limit || s->time || s->scan0 || s->scan1; } -// "limit L/D, frame time limit T/TD, scanline sync S0/S1", the values as the file holds them. -static inline void rtss_settings_text(char *out, size_t n, const RtssSettings *s) { - snprintf(out, n, "limit %d/%d, frame time limit %d/%d, scanline sync %d/%d", s->limit, s->limit_den, s->time, - s->time_den, s->scan0, s->scan1); +// "limit L/D, frame time limit T/TD, scanline sync S0/S1", and with modes ", display sync X, Reflex sleep R, passive +// wait P": the values as the file holds them. +static inline void rtss_settings_text(char *out, size_t n, const RtssSettings *s, int modes) { + int k = snprintf(out, n, "limit %d/%d, frame time limit %d/%d, scanline sync %d/%d", s->limit, s->limit_den, s->time, + s->time_den, s->scan0, s->scan1); + if (modes && k >= 0 && (size_t)k < n) + snprintf(out + k, n - (size_t)k, ", display sync %d, Reflex sleep %d, passive wait %d", s->sync_display, + s->reflex_sleep, s->passive_wait); } diff --git a/runtime/rtss_limit.c b/runtime/rtss_limit.c index f864aa84..113ba899 100644 --- a/runtime/rtss_limit.c +++ b/runtime/rtss_limit.c @@ -255,7 +255,7 @@ static const char *fail_reason(int f) { // RTSS's own settings for the game, read from its profile file as RTSS keeps it: Profiles\.cfg, else // Profiles\Global, and a key the game's profile lacks from Global. The system's ini reader does it, so no call goes into // RTSS's hooks library, which a run that keeps RTSS out never loads. The files are read again only when the time -// either was written changes. Worker thread only. +// either was written changes. Worker thread only, while RTSS lists the game (watch). static RtssSettings settings; static char settings_file[MAX_PATH + 16]; // which file they came from, as Profiles\ @@ -283,23 +283,35 @@ static void read_settings(void) { const char *p = a ? own : NULL; settings = (RtssSettings){cfg_int(p, global, "Limit"), cfg_int(p, global, "LimitDenominator"), cfg_int(p, global, "LimitTime"), cfg_int(p, global, "LimitTimeDenominator"), - cfg_int(p, global, "SyncScanline0"), cfg_int(p, global, "SyncScanline1")}; + cfg_int(p, global, "SyncScanline0"), cfg_int(p, global, "SyncScanline1"), + cfg_int(p, global, "SyncDisplay"), cfg_int(p, global, "ReflexSleep"), + cfg_int(p, global, "PassiveWait")}; if (a) snprintf(settings_file, sizeof settings_file, "Profiles\\%s.cfg", profile); else snprintf(settings_file, sizeof settings_file, "Profiles\\Global"); } -// While RTSS is kept out (w < 0) the game's own limiter, the driver's low latency or frame generation holds the frames, -// and a limit the player set in RTSS itself for the game (its global profile or the game's own, a frame time limit or -// scanline sync) still holds them a second time. Logged once per change and shown in the menu (rtss_limit_state 4). +// While RTSS lists the game, the settings it holds for it are logged once per change: what RTSS applies may be more than +// the FramerateLimit the game writes (a frame time limit, scanline sync, its own Reflex). While RTSS is kept out +// (w < 0) the game's own limiter, the driver's low latency or frame generation holds the frames, and a limit the player +// set in RTSS itself for the game (its global profile or the game's own, a frame time limit or scanline sync) still +// holds them a second time. Logged once per change and shown in the menu (rtss_limit_state 4). static void watch(int64_t w, int listed) { - static int said, lines; - static char said_text[128]; + static int said, lines, settings_lines; + static char said_text[128], said_settings[MAX_PATH + 256]; int on = 0; char text[128] = ""; - if (w < 0 && listed) { + if (listed) { read_settings(); + char all[MAX_PATH + 256], modes[192]; + rtss_settings_text(modes, sizeof modes, &settings, 1); + snprintf(all, sizeof all, "(%s): %s", settings_file, modes); + if (strcmp(all, said_settings) && settings_lines++ < 40) + rt_log("frame rate: RivaTuner Statistics Server's settings for the game %s", all); + snprintf(said_settings, sizeof said_settings, "%s", all); + } + if (w < 0 && listed) { on = rtss_settings_limit(&settings); - rtss_settings_text(text, sizeof text, &settings); + rtss_settings_text(text, sizeof text, &settings, 0); } if (w >= 0) said = 0; // a later kept-out want logs afresh else if (on != said || (on && strcmp(text, said_text))) { diff --git a/tests/rtss_limit_check.c b/tests/rtss_limit_check.c index 22c8d10b..417e17c0 100644 --- a/tests/rtss_limit_check.c +++ b/tests/rtss_limit_check.c @@ -10,7 +10,7 @@ static int fails; // RTSS's own settings: which of them hold the game's frames, and the log's text of them. static void settings(void) { - RtssSettings none = {0, 1, 0, 0, 0, 0}; + RtssSettings none = {0, 1, 0, 0, 0, 0, 1, 1, 1}; CHECK(!rtss_settings_limit(&none), "no limit, no frame time limit, no scanline sync: RTSS holds nothing"); RtssSettings s = none; s.limit = 50; @@ -23,13 +23,20 @@ static void settings(void) { CHECK(rtss_settings_limit(&s), "the second scanline sync holds the frames"); s = none, s.limit_den = 1000, s.time_den = 7; CHECK(!rtss_settings_limit(&s), "denominators alone hold nothing"); - char text[128]; - s = (RtssSettings){59940, 1000, 16667, 1, -40, 0}; - rtss_settings_text(text, sizeof text, &s); + CHECK(!rtss_settings_limit(&none), "display sync, Reflex sleep and passive wait alone hold nothing"); + char text[192]; + s = (RtssSettings){59940, 1000, 16667, 1, -40, 0, 1, 2, 0}; + rtss_settings_text(text, sizeof text, &s, 0); CHECK(!strcmp(text, "limit 59940/1000, frame time limit 16667/1, scanline sync -40/0"), "text: %s", text); - char small[16]; - rtss_settings_text(small, sizeof small, &s); + rtss_settings_text(text, sizeof text, &s, 1); + CHECK(!strcmp(text, "limit 59940/1000, frame time limit 16667/1, scanline sync -40/0, display sync 1, Reflex sleep 2, " + "passive wait 0"), + "text with the modes: %s", text); + char small[16], mid[70]; + rtss_settings_text(small, sizeof small, &s, 1); CHECK(strlen(small) == sizeof small - 1, "a short buffer is cut, not overrun"); + rtss_settings_text(mid, sizeof mid, &s, 1); + CHECK(strlen(mid) == sizeof mid - 1 && !strncmp(mid, text, sizeof mid - 1), "the modes cut at the buffer's end"); } // The kept-out reasons, for the log. diff --git a/tests/rtss_worker_check.c b/tests/rtss_worker_check.c index 47125c93..753c7d4e 100644 --- a/tests/rtss_worker_check.c +++ b/tests/rtss_worker_check.c @@ -52,10 +52,10 @@ static int fails; typedef struct { int exists; DWORD limit, denom; // FramerateLimit and FramerateLimitDenominator: Limit and LimitDenominator in the file - int time, time_den, scan0, scan1; + int time, time_den, scan0, scan1, sync_display, reflex, passive; DWORD stamp; } Prof; -static Prof global = {1, 0, 1, 0, 0, 0, 0, 1}, own, loaded; +static Prof global = {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, own, loaded; static int no_denominator; // an RTSS that does not know FramerateLimitDenominator static int readonly; // SaveProfile does not reach the file (no administrator rights) static volatile LONG saves, deletes, updates, loads, created, removed; @@ -190,6 +190,9 @@ DWORD stub_GetPrivateProfileStringA(LPCSTR sec, LPCSTR key, LPCSTR def, LPSTR ou else if (!strcmp(key, "LimitTimeDenominator")) v = f->time_den; else if (!strcmp(key, "SyncScanline0")) v = f->scan0; else if (!strcmp(key, "SyncScanline1")) v = f->scan1; + else if (!strcmp(key, "SyncDisplay")) v = f->sync_display; + else if (!strcmp(key, "ReflexSleep")) v = f->reflex; + else if (!strcmp(key, "PassiveWait")) v = f->passive; else have = 0; } if (have) return (DWORD)snprintf(out, n, "%ld", v); @@ -307,7 +310,7 @@ static void restore_race(void) { // The same with the player's own profile: it keeps the player's limit. static void restore_player(void) { - own = (Prof){1, 30, 1, 0, 0, 0, 0, 1}; + own = (Prof){1, 30, 1, 0, 0, 0, 0, 0, 0, 0, 1}; app_set(1, 0xA, 1000, 2000, 60); ask(60000); poll(); @@ -383,7 +386,7 @@ static void kept_two(void) { // Low latency keeps RTSS out from the first present, with scanline sync set in the game's own profile (a negative line // counts from the bottom); once low latency is off, a limit starts RTSS's part as usual. static void kept_lowlat_then_limit(void) { - own = (Prof){1, 0, 1, 0, 0, -40, 0, 1}; + own = (Prof){1, 0, 1, 0, 0, -40, 0, 0, 0, 0, 1}; app_set(0, 0xA, 1000, 2000, 60); ask(RTSS_OUT_LOWLAT); poll(); @@ -494,6 +497,33 @@ static void not_installed(void) { CHECK(!loads && !saves && !own.exists, "nothing loaded or written"); } +// While RTSS lists the game, its settings for the game are logged once per change: Global's before the game has a +// profile of its own, then the game's own with the limit it wrote, frame time limit, scanline sync and the modes. +static int count(const char *text) { + int n = 0; + for (const char *p = logged_lines; (p = strstr(p, text)); p++) n++; + return n; +} +static void settings_logged(void) { + global.time = 16667, global.time_den = 1, global.sync_display = 1, global.reflex = 1, global.passive = 1; + app_set(0, 0xA, 1000, 2000, 60); + ask(60000); + poll(); + CHECK(!count("settings for the game"), "not listed: nothing read"); + app_set(1, 0xA, 1000, 2000, 60); + poll(); + poll(); + CHECK(logged("frame rate: RivaTuner Statistics Server's settings for the game (Profiles\\ocarina.exe.cfg): limit " + "60/1, frame time limit 16667/1, scanline sync 0/0, display sync 1, Reflex sleep 1, passive wait 1\n"), + "the game's profile, with what it took from Global"); + CHECK(count("settings for the game") == 1, "logged once while nothing changes (%d)", count("settings for the game")); + ask(144000); + poll(); + poll(); + CHECK(logged("(Profiles\\ocarina.exe.cfg): limit 144/1, frame time limit 16667/1"), "logged again on a change"); + CHECK(count("settings for the game") == 2, "once per change (%d)", count("settings for the game")); +} + static const struct { const char *name; void (*run)(void); } scenarios[] = { {"restore_race", restore_race}, {"restore_player", restore_player}, @@ -508,6 +538,7 @@ static const struct { const char *name; void (*run)(void); } scenarios[] = { {"round_logged_whole", round_logged_whole}, {"start_off_present", start_off_present}, {"not_installed", not_installed}, + {"settings_logged", settings_logged}, }; int main(int argc, char **argv) {