diff --git a/changelog b/changelog index 8e81aa420af..ecbaba70829 100644 --- a/changelog +++ b/changelog @@ -55,8 +55,6 @@ Version 1.13.8+dev: * Miscellaneous and Bug Fixes: * Add --report/-R command line switch for printing the same report from the Game Version dialog's clipboard function to stdout. - * Removed the --max-fps command line switch. The new FPS cap implementation - queries the screen refresh rate instead. * WFL Engine * Add owner key to terrain space callable, for villages * Location formulas in [tunnel] now have a teleport_unit variable diff --git a/src/commandline_options.cpp b/src/commandline_options.cpp index be746647418..56d2e68b8a1 100644 --- a/src/commandline_options.cpp +++ b/src/commandline_options.cpp @@ -97,6 +97,7 @@ commandline_options::commandline_options (const std::vector& args) multiplayer_scenario(), multiplayer_side(), multiplayer_turns(), + max_fps(), noaddons(false), nocache(false), nodelay(false), @@ -213,6 +214,7 @@ commandline_options::commandline_options (const std::vector& args) display_opts.add_options() ("fps", "displays the number of frames per second the game is currently running at, in a corner of the screen.") ("fullscreen,f", "runs the game in full screen mode.") + ("max-fps", po::value(), "the maximum fps the game tries to run at. Values should be between 1 and 1000, the default is 50.") ("new-widgets", "there is a new WIP widget toolkit this switch enables the new toolkit (VERY EXPERIMENTAL don't file bug reports since most are known). Parts of the library are deemed stable and will work without this switch.") ("resolution,r", po::value(), "sets the screen resolution. should have format XxY. Example: --resolution 800x600") ("windowed,w", "runs the game in windowed mode.") @@ -366,6 +368,8 @@ commandline_options::commandline_options (const std::vector& args) log_precise_timestamps = true; if (vm.count("log-strict")) parse_log_strictness(vm["log-strict"].as()); + if (vm.count("max-fps")) + max_fps = vm["max-fps"].as(); if (vm.count("mp-test")) mptest = true; if (vm.count("multiplayer")) diff --git a/src/commandline_options.hpp b/src/commandline_options.hpp index 32b961dfbce..e96eabcd500 100644 --- a/src/commandline_options.hpp +++ b/src/commandline_options.hpp @@ -125,6 +125,8 @@ public: boost::optional > > multiplayer_side; /// Non-empty if --turns was given on the command line. Dependent on --multiplayer. boost::optional multiplayer_turns; + /// Max FPS specified by --max-fps option. + boost::optional max_fps; /// True if --noaddons was given on the command line. Disables the loading of all add-ons. bool noaddons; /// True if --nocache was given on the command line. Disables cache usage. diff --git a/src/display.cpp b/src/display.cpp index 14978d40b85..8923a47441f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1673,7 +1673,10 @@ void display::draw_init() void display::draw_wrap(bool update, bool force) { - static const int time_between_draws = 1000 / screen_.current_refresh_rate(); + static int time_between_draws = preferences::draw_delay(); + if(time_between_draws == 0) { + time_between_draws = 1000 / screen_.current_refresh_rate(); + } if(redrawMinimap_) { redrawMinimap_ = false; diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 072fb204d09..bdb1d85264c 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -55,6 +55,7 @@ #include "game_initialization/singleplayer.hpp" // for sp_create_mode #include "statistics.hpp" #include "tstring.hpp" // for operator==, operator!= +#include "utils/general.hpp" // for clamp #include "video.hpp" // for CVideo #include "wesnothd_connection_error.hpp" #include "wml_exception.hpp" // for wml_exception @@ -186,6 +187,15 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char video().set_fullscreen(true); if (cmdline_opts_.load) load_data_.reset(new savegame::load_game_metadata{ *cmdline_opts_.load }); + if (cmdline_opts_.max_fps) { + int fps = utils::clamp(*cmdline_opts_.max_fps, 1, 1000); + fps = 1000 / fps; + // increase the delay to avoid going above the maximum + if(1000 % fps != 0) { + ++fps; + } + preferences::set_draw_delay(fps); + } if (cmdline_opts_.nogui || cmdline_opts_.headless_unit_test) { no_sound = true; preferences::disable_preferences_save(); diff --git a/src/preferences/general.cpp b/src/preferences/general.cpp index 1dd6483e374..beb86cc9167 100644 --- a/src/preferences/general.cpp +++ b/src/preferences/general.cpp @@ -49,6 +49,8 @@ bool no_preferences_save = false; bool fps = false; +int draw_delay_ = 0; + config prefs; } @@ -977,6 +979,16 @@ void set_show_fps(bool value) fps = value; } +int draw_delay() +{ + return draw_delay_; +} + +void set_draw_delay(int value) +{ + draw_delay_ = value; +} + bool use_color_cursors() { return get("color_cursors", true); diff --git a/src/preferences/general.hpp b/src/preferences/general.hpp index 08a82b17d99..9cd9ef37efe 100644 --- a/src/preferences/general.hpp +++ b/src/preferences/general.hpp @@ -236,6 +236,9 @@ namespace preferences { */ int mouse_scroll_threshold(); + int draw_delay(); + void set_draw_delay(int value); + bool animate_map(); void set_animate_map(bool value);