Add new refresh_rate pref to better handle --max-fps
The pre-processing for --max-fps was basically identical to what draw_manager::get_frame_length does.
This replaces the draw_delay preference with a new refresh_rate preference that more accurately describes
what is being set. video::current_refresh_rate will now take this preference into account, meaning the
build info report will correctly report player-set FPS limits.
The Limit FPS option in the prefs UI was also removed. When it was first introduced (cca79afe4b
)
it specifically affected the map rendering code, not the rendering pipeline as a whole. With the 1.17
rendering refactor, this is no longer the case, and so its current usage as the lower bound for frametime
calculations did nothing (all it did was change the lower bound from 0 to -1 when enabled).
It might be worth adding a slider to the UI to dynamically set max fps, but that's a separate change.
This commit is contained in:
parent
6fcf46a208
commit
b859060627
7 changed files with 8 additions and 36 deletions
|
@ -133,22 +133,6 @@
|
|||
|
||||
{GUI_FILLER}
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[toggle_button]
|
||||
id = "fps_limiter"
|
||||
label = _ "Limit FPS"
|
||||
tooltip = _ "Disabling this increases CPU usage, but may slightly improve performance (requires restart to take effect)"
|
||||
[/toggle_button]
|
||||
[/column]
|
||||
|
||||
{GUI_FILLER}
|
||||
[/row]
|
||||
#enddef
|
||||
|
||||
#define _GUI_PREFERENCES_DISPLAY_UI_GRID
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "exceptions.hpp"
|
||||
#include "log.hpp"
|
||||
#include "gui/core/top_level_drawable.hpp"
|
||||
#include "preferences/preferences.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "utils/general.hpp"
|
||||
#include "video.hpp"
|
||||
|
@ -186,8 +185,7 @@ std::chrono::milliseconds get_frame_length()
|
|||
}
|
||||
// allow 1ms for general processing
|
||||
auto vsync_delay = (1000ms / rr) - 1ms;
|
||||
// if there's a preferred limit, limit to that
|
||||
return std::clamp(vsync_delay, std::chrono::milliseconds{prefs::get().draw_delay()}, 1000ms);
|
||||
return std::min(vsync_delay, 1000ms);
|
||||
}
|
||||
|
||||
static void wait_for_vsync()
|
||||
|
|
|
@ -161,13 +161,7 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts)
|
|||
load_data_ = savegame::load_game_metadata{
|
||||
savegame::save_index_class::default_saves_dir(), *cmdline_opts_.load};
|
||||
if(cmdline_opts_.max_fps) {
|
||||
int fps = std::clamp(*cmdline_opts_.max_fps, 1, 1000);
|
||||
fps = 1000 / fps;
|
||||
// increase the delay to avoid going above the maximum
|
||||
if(1000 % fps != 0) {
|
||||
++fps;
|
||||
}
|
||||
prefs::get().set_draw_delay(fps);
|
||||
prefs::get().set_refresh_rate(std::clamp(*cmdline_opts_.max_fps, 1, 1000));
|
||||
}
|
||||
if(cmdline_opts_.nogui || cmdline_opts_.headless_unit_test) {
|
||||
no_sound = true;
|
||||
|
|
|
@ -575,10 +575,6 @@ void preferences_dialog::initialize_callbacks()
|
|||
//register_integer("scaling_slider", true,
|
||||
// font_scaling, set_font_scaling);
|
||||
|
||||
/* FPS LIMITER */
|
||||
register_bool("fps_limiter", true,
|
||||
[]() { return prefs::get().draw_delay() != 0; }, [](bool v) { prefs::get().set_draw_delay(v ? -1 : 0); });
|
||||
|
||||
/* VSYNC */
|
||||
register_bool("vsync", true,
|
||||
[]() {return prefs::get().vsync();},
|
||||
|
|
|
@ -503,7 +503,7 @@ class prefs
|
|||
PREF_GETTER_SETTER(stop_music_in_background, bool, false)
|
||||
PREF_GETTER_SETTER(tile_size, unsigned, 0)
|
||||
PREF_GETTER_SETTER(mouse_scrolling, bool, true)
|
||||
PREF_GETTER_SETTER(draw_delay, int, -1)
|
||||
PREF_GETTER_SETTER(refresh_rate, int, -1)
|
||||
PREF_GETTER_SETTER(animate_map, bool, true)
|
||||
PREF_GETTER_SETTER(animate_water, bool, true)
|
||||
PREF_GETTER_SETTER(minimap_movement_coding, bool, true)
|
||||
|
@ -819,7 +819,7 @@ class prefs
|
|||
static constexpr std::array unsynced_attributes_{
|
||||
prefs_list::auto_pixel_scale,
|
||||
prefs_list::core,
|
||||
prefs_list::draw_delay,
|
||||
prefs_list::refresh_rate,
|
||||
prefs_list::editor_chosen_addon,
|
||||
prefs_list::gui2_theme,
|
||||
prefs_list::mp_server_program_name,
|
||||
|
|
|
@ -77,8 +77,8 @@ struct preferences_list_defines
|
|||
ADDPREF(dir_bookmarks)
|
||||
/** whether to automatically move units that were previously told to move towards hexes more than one turn away */
|
||||
ADDPREF(disable_auto_moves)
|
||||
/** used to enforce the FPS limit - minimum time between frame updates if the player's PC is capable of updating the screen faster than this */
|
||||
ADDPREF(draw_delay)
|
||||
/** maximum FPS, if set, at which to refresh the screen */
|
||||
ADDPREF(refresh_rate)
|
||||
/** whether to have the editor automatically update terrain transitions when placing terrain immediately, after the mouse click is released, or not at all */
|
||||
ADDPREF(editor_auto_update_transitions)
|
||||
/** the current add-on being used in the editor */
|
||||
|
@ -405,7 +405,7 @@ struct preferences_list_defines
|
|||
delete_saves,
|
||||
dir_bookmarks,
|
||||
disable_auto_moves,
|
||||
draw_delay,
|
||||
refresh_rate,
|
||||
editor_auto_update_transitions,
|
||||
editor_chosen_addon,
|
||||
editor_draw_hex_coordinates,
|
||||
|
|
|
@ -486,7 +486,7 @@ int get_pixel_scale()
|
|||
int current_refresh_rate()
|
||||
{
|
||||
// TODO: this should be more clever, depending on usage
|
||||
return refresh_rate_;
|
||||
return std::min(prefs::get().refresh_rate(), refresh_rate_);
|
||||
}
|
||||
|
||||
void force_render_target(const texture& t)
|
||||
|
|
Loading…
Add table
Reference in a new issue