diff --git a/code/localization/localize.cpp b/code/localization/localize.cpp index 78868daf554..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 1936 // 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 98a2ada5c36..95bcdad604b 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,39 @@ 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(XSTR("Unlimited", 1938)) : 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}) + .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 +1981,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 +2000,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 +3037,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 +3059,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; }