Skip to content

Commit

Permalink
Restore --max-fps
Browse files Browse the repository at this point in the history
@gfgtdf explained in IRC that it's often used to slow Wesnoth down (instead
of speeding it up, as I had assumed).

This should also allow unit tests to compile again.
  • Loading branch information
jyrkive committed Jul 22, 2017
1 parent 4e4d7b5 commit dc5e8b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
2 changes: 0 additions & 2 deletions changelog
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/commandline_options.cpp
Expand Up @@ -97,6 +97,7 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
multiplayer_scenario(),
multiplayer_side(),
multiplayer_turns(),
max_fps(),
noaddons(false),
nocache(false),
nodelay(false),
Expand Down Expand Up @@ -213,6 +214,7 @@ commandline_options::commandline_options (const std::vector<std::string>& 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<int>(), "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<std::string>(), "sets the screen resolution. <arg> should have format XxY. Example: --resolution 800x600")
("windowed,w", "runs the game in windowed mode.")
Expand Down Expand Up @@ -366,6 +368,8 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
log_precise_timestamps = true;
if (vm.count("log-strict"))
parse_log_strictness(vm["log-strict"].as<std::string>());
if (vm.count("max-fps"))
max_fps = vm["max-fps"].as<int>();
if (vm.count("mp-test"))
mptest = true;
if (vm.count("multiplayer"))
Expand Down
2 changes: 2 additions & 0 deletions src/commandline_options.hpp
Expand Up @@ -125,6 +125,8 @@ friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmd
boost::optional<std::vector<std::pair<unsigned int, std::string> > > multiplayer_side;
/// Non-empty if --turns was given on the command line. Dependent on --multiplayer.
boost::optional<std::string> multiplayer_turns;
/// Max FPS specified by --max-fps option.
boost::optional<int> 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.
Expand Down
5 changes: 4 additions & 1 deletion src/display.cpp
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/game_launcher.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions src/preferences/general.cpp
Expand Up @@ -49,6 +49,8 @@ bool no_preferences_save = false;

bool fps = false;

int draw_delay_ = 0;

config prefs;
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/preferences/general.hpp
Expand Up @@ -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);

Expand Down

0 comments on commit dc5e8b3

Please sign in to comment.