From fa93449cd5371ec997bc96d6abe8eefee9335478 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sat, 26 Sep 2026 22:15:23 -0300 Subject: [PATCH 1/3] Add Limit fps slider to in-game options --- code/localization/localize.cpp | 2 +- freespace2/freespace.cpp | 54 ++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/code/localization/localize.cpp b/code/localization/localize.cpp index 78868daf554..82b22001425 100644 --- a/code/localization/localize.cpp +++ b/code/localization/localize.cpp @@ -65,7 +65,7 @@ bool *Lcl_unexpected_tstring_check = nullptr; // NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous, // but internal strings should still increment XSTR_SIZE to avoid collisions. // retail XSTR_SIZE = 1570 -// #define XSTR_SIZE 1936 // This is the next available ID +// #define XSTR_SIZE 1938 // This is the next available ID // struct to allow for strings.tbl-determined x offset // offset is 0 for english, by default diff --git a/freespace2/freespace.cpp b/freespace2/freespace.cpp index 98a2ada5c36..c5db79a86a9 100644 --- a/freespace2/freespace.cpp +++ b/freespace2/freespace.cpp @@ -208,6 +208,7 @@ #include +#include #include #include @@ -367,7 +368,9 @@ fix FrametimeOverall = 0; int Show_framerate = 0; #endif -int Framerate_cap = 120; +static constexpr int MIN_FRAMERATE_CAP = 15; +static constexpr int MAX_FRAMERATE_CAP = 120; +int Framerate_cap = 120; // Default value // for the model page in system extern void model_page_in_start(); @@ -1911,6 +1914,34 @@ void game_init() mod_table_init(); // load in all the mod dependent settings + // Keep the old MaxFPS setting as the default when no Graphics.FramerateCap value is saved. + const auto max_fps = os_config_read_uint(nullptr, NOX("MaxFPS"), 0); + if (max_fps >= MIN_FRAMERATE_CAP && max_fps <= MAX_FRAMERATE_CAP) { + Framerate_cap = static_cast(max_fps); + } + + static auto FramerateCapOption __UNUSED = options::OptionBuilder("Graphics.FramerateCap", + std::pair{"Frame Rate Limit", 1936}, + std::pair{"Maximum frames per second. Vertical sync may lower the actual frame rate.", 1937}) + .category(std::make_pair("Graphics", 1825)) + .level(options::ExpertLevel::Advanced) + .range(MIN_FRAMERATE_CAP, MAX_FRAMERATE_CAP) + .default_func([]() { return Framerate_cap; }) + .deserializer([](const json_t* value) { + int saved; + json_error_t err; + if (json_unpack_ex(const_cast(value), &err, 0, "i", &saved) != 0) { + throw json_exception(err); + } + // Clamp saved out-of-range values + return std::clamp(saved, MIN_FRAMERATE_CAP, MAX_FRAMERATE_CAP); + }) + .display([](int value) { return Cmdline_NoFPSCap ? SCP_string("Unlimited") : std::to_string(value); }) + .bind_to(&Framerate_cap) + .importance(71) + .flags({options::OptionFlags::RangeTypeInteger}) + .finish(); + // Must be run after mod table is parsed so we know the value of Using_in_game_options // Must be run before everything else inits so we can init those with the correct // default values or user preferences @@ -1945,6 +1976,11 @@ void game_init() std_init_standalone(); } + if (Cmdline_NoFPSCap) { + options::OptionsManager::instance()->setOverride("Graphics.FramerateCap", + std::unique_ptr(json_integer(Framerate_cap)), "-no_fps_capping"); + } + // verify that he has a valid ships.tbl (will Game_ships_tbl_valid if so) verify_ships_tbl(); @@ -1959,15 +1995,7 @@ void game_init() Use_fullscreen_at_startup = os_config_read_uint( nullptr, NOX("ForceFullscreen"), 1 ); #endif - // change FPS cap if told to do so (for those who can't use vsync or where vsync isn't enough) - uint max_fps = 0; - if ( (max_fps = os_config_read_uint(nullptr, NOX("MaxFPS"), 0)) != 0 ) { - if ( (max_fps > 15) && (max_fps < 120) ) { - Framerate_cap = (int)max_fps; - } - } - - Asteroids_enabled = 1; + Asteroids_enabled = 1; ///////////////////////////// // SOUND INIT START @@ -3004,7 +3032,7 @@ DCF(framerate_cap, "Sets the framerate cap") if (dc_optional_string_either("help", "--help")) { dc_printf("Usage: framerate_cap [n]\nwhere n is the frames per second to cap framerate at.\n"); dc_printf("If n is 0 or omitted, then the framerate cap is removed\n"); - dc_printf("[n] must be from 1 to 120.\n"); + dc_printf("[n] must be from 1 to %d.\n", MAX_FRAMERATE_CAP); process = false; } @@ -3026,8 +3054,8 @@ DCF(framerate_cap, "Sets the framerate cap") Framerate_cap = 0; } - if ((Framerate_cap < 0) || (Framerate_cap > 120)) { - dc_printf( "Illegal value for framerate cap. (Must be from 1-120) \n"); + if ((Framerate_cap < 0) || (Framerate_cap > MAX_FRAMERATE_CAP)) { + dc_printf("Illegal value for framerate cap. (Must be from 1-%d) \n", MAX_FRAMERATE_CAP); Framerate_cap = 0; } From 103be59c9896ced93b292dea42539c9758caf656 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Mon, 12 Oct 2026 15:38:37 -0300 Subject: [PATCH 2/3] add parser() to the fps limiting option --- freespace2/freespace.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/freespace2/freespace.cpp b/freespace2/freespace.cpp index c5db79a86a9..3f45f64c8aa 100644 --- a/freespace2/freespace.cpp +++ b/freespace2/freespace.cpp @@ -1937,6 +1937,11 @@ void game_init() return std::clamp(saved, MIN_FRAMERATE_CAP, MAX_FRAMERATE_CAP); }) .display([](int value) { return Cmdline_NoFPSCap ? SCP_string("Unlimited") : std::to_string(value); }) + .parser([]() { + int value; + stuff_int(&value); + Framerate_cap = std::clamp(value, MIN_FRAMERATE_CAP, MAX_FRAMERATE_CAP); + }) .bind_to(&Framerate_cap) .importance(71) .flags({options::OptionFlags::RangeTypeInteger}) From 9aaa2f3b64a0bb5a1091f1dbce40bfc8bd197fdd Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Mon, 12 Oct 2026 17:03:59 -0300 Subject: [PATCH 3/3] localize "Unlimited" string --- code/localization/localize.cpp | 2 +- freespace2/freespace.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/localization/localize.cpp b/code/localization/localize.cpp index 82b22001425..0581d855664 100644 --- a/code/localization/localize.cpp +++ b/code/localization/localize.cpp @@ -65,7 +65,7 @@ bool *Lcl_unexpected_tstring_check = nullptr; // NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous, // but internal strings should still increment XSTR_SIZE to avoid collisions. // retail XSTR_SIZE = 1570 -// #define XSTR_SIZE 1938 // This is the next available ID +// #define XSTR_SIZE 1939 // This is the next available ID // struct to allow for strings.tbl-determined x offset // offset is 0 for english, by default diff --git a/freespace2/freespace.cpp b/freespace2/freespace.cpp index 3f45f64c8aa..95bcdad604b 100644 --- a/freespace2/freespace.cpp +++ b/freespace2/freespace.cpp @@ -1936,7 +1936,7 @@ void game_init() // Clamp saved out-of-range values return std::clamp(saved, MIN_FRAMERATE_CAP, MAX_FRAMERATE_CAP); }) - .display([](int value) { return Cmdline_NoFPSCap ? SCP_string("Unlimited") : std::to_string(value); }) + .display([](int value) { return Cmdline_NoFPSCap ? SCP_string(XSTR("Unlimited", 1938)) : std::to_string(value); }) .parser([]() { int value; stuff_int(&value);