Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.
(cherry picked from commit c3dc27e37e
)
# Conflicts:
# src/gfx.cpp
# src/gfx_func.h
# src/settings_type.h
# src/video/cocoa/cocoa_v.mm
# src/video/video_driver.cpp
# src/video/win32_v.cpp
This commit is contained in:

committed by
Jonathan G Rennison

parent
535fdb5c89
commit
f183ded9fe
11
src/gfx.cpp
11
src/gfx.cpp
@@ -40,7 +40,7 @@ bool _ctrl_pressed; ///< Is Ctrl pressed?
|
|||||||
bool _shift_pressed; ///< Is Shift pressed?
|
bool _shift_pressed; ///< Is Shift pressed?
|
||||||
bool _invert_ctrl;
|
bool _invert_ctrl;
|
||||||
bool _invert_shift;
|
bool _invert_shift;
|
||||||
byte _fast_forward;
|
uint16 _game_speed = 100; ///< Current game-speed; 100 is 1x, 0 is infinite.
|
||||||
bool _left_button_down; ///< Is left mouse button pressed?
|
bool _left_button_down; ///< Is left mouse button pressed?
|
||||||
bool _left_button_clicked; ///< Is left mouse button clicked?
|
bool _left_button_clicked; ///< Is left mouse button clicked?
|
||||||
bool _right_button_down; ///< Is right mouse button pressed?
|
bool _right_button_down; ///< Is right mouse button pressed?
|
||||||
@@ -2212,3 +2212,12 @@ void UpdateGUIZoom()
|
|||||||
_font_zoom = static_cast<ZoomLevel>(_font_zoom_cfg);
|
_font_zoom = static_cast<ZoomLevel>(_font_zoom_cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeGameSpeed(bool enable_fast_forward)
|
||||||
|
{
|
||||||
|
if (enable_fast_forward) {
|
||||||
|
_game_speed = _settings_client.gui.fast_forward_speed_limit;
|
||||||
|
} else {
|
||||||
|
_game_speed = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -56,7 +56,7 @@ extern bool _ctrl_pressed; ///< Is Ctrl pressed?
|
|||||||
extern bool _shift_pressed; ///< Is Shift pressed?
|
extern bool _shift_pressed; ///< Is Shift pressed?
|
||||||
extern bool _invert_ctrl;
|
extern bool _invert_ctrl;
|
||||||
extern bool _invert_shift;
|
extern bool _invert_shift;
|
||||||
extern byte _fast_forward;
|
extern uint16 _game_speed;
|
||||||
|
|
||||||
extern bool _left_button_down;
|
extern bool _left_button_down;
|
||||||
extern bool _left_button_clicked;
|
extern bool _left_button_clicked;
|
||||||
@@ -76,6 +76,7 @@ void HandleCtrlChanged();
|
|||||||
void HandleShiftChanged();
|
void HandleShiftChanged();
|
||||||
void HandleMouseEvents();
|
void HandleMouseEvents();
|
||||||
void UpdateWindows();
|
void UpdateWindows();
|
||||||
|
void ChangeGameSpeed(bool enable_fast_forward);
|
||||||
|
|
||||||
void DrawMouseCursor();
|
void DrawMouseCursor();
|
||||||
void ScreenSizeChanged();
|
void ScreenSizeChanged();
|
||||||
|
@@ -1629,6 +1629,10 @@ STR_CONFIG_SETTING_EXPENSES_LAYOUT :Group expenses
|
|||||||
STR_CONFIG_SETTING_EXPENSES_LAYOUT_HELPTEXT :Define the layout for the company expenses window
|
STR_CONFIG_SETTING_EXPENSES_LAYOUT_HELPTEXT :Define the layout for the company expenses window
|
||||||
STR_CONFIG_SETTING_AUTO_REMOVE_SIGNALS :Automatically remove signals during rail construction: {STRING2}
|
STR_CONFIG_SETTING_AUTO_REMOVE_SIGNALS :Automatically remove signals during rail construction: {STRING2}
|
||||||
STR_CONFIG_SETTING_AUTO_REMOVE_SIGNALS_HELPTEXT :Automatically remove signals during rail construction if the signals are in the way. Note that this can potentially lead to train crashes.
|
STR_CONFIG_SETTING_AUTO_REMOVE_SIGNALS_HELPTEXT :Automatically remove signals during rail construction if the signals are in the way. Note that this can potentially lead to train crashes.
|
||||||
|
STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT :Fast forward speed limit: {STRING2}
|
||||||
|
STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT_HELPTEXT :Limit on how fast the game goes when fast forward is enabled. 0 = no limit (as fast as your computer allows). Values below 100% slow the game down. The upper-limit depends on the specification of your computer and can vary depending on the game.
|
||||||
|
STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT_VAL :{NUM}% normal game speed
|
||||||
|
STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT_ZERO :No limit (as fast as your computer allows)
|
||||||
|
|
||||||
STR_CONFIG_SETTING_ENABLE_BUILD_RIVER :Enable building rivers: {STRING2}
|
STR_CONFIG_SETTING_ENABLE_BUILD_RIVER :Enable building rivers: {STRING2}
|
||||||
STR_CONFIG_SETTING_ENABLE_BUILD_RIVER_HELPTEXT :Enable building rivers outside of the scenario editor
|
STR_CONFIG_SETTING_ENABLE_BUILD_RIVER_HELPTEXT :Enable building rivers outside of the scenario editor
|
||||||
|
@@ -76,7 +76,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
|||||||
ClearDesyncMsgLog();
|
ClearDesyncMsgLog();
|
||||||
|
|
||||||
_pause_mode = PM_UNPAUSED;
|
_pause_mode = PM_UNPAUSED;
|
||||||
_fast_forward = 0;
|
_game_speed = 100;
|
||||||
_tick_counter = 0;
|
_tick_counter = 0;
|
||||||
_tick_skip_counter = 0;
|
_tick_skip_counter = 0;
|
||||||
_cur_tileloop_tile = 1;
|
_cur_tileloop_tile = 1;
|
||||||
|
@@ -228,7 +228,7 @@ struct SaveLoadParams {
|
|||||||
StringID error_str; ///< the translatable error message to show
|
StringID error_str; ///< the translatable error message to show
|
||||||
char *extra_msg; ///< the error message
|
char *extra_msg; ///< the error message
|
||||||
|
|
||||||
byte ff_state; ///< The state of fast-forward when saving started.
|
uint16 game_speed; ///< The game speed when saving started.
|
||||||
bool saveinprogress; ///< Whether there is currently a save in progress.
|
bool saveinprogress; ///< Whether there is currently a save in progress.
|
||||||
bool networkserversave; ///< Whether this save is being sent to a network client
|
bool networkserversave; ///< Whether this save is being sent to a network client
|
||||||
};
|
};
|
||||||
@@ -2907,8 +2907,8 @@ static inline void ClearSaveLoadState()
|
|||||||
*/
|
*/
|
||||||
static void SaveFileStart()
|
static void SaveFileStart()
|
||||||
{
|
{
|
||||||
_sl.ff_state = _fast_forward;
|
_sl.game_speed = _game_speed;
|
||||||
_fast_forward = 0;
|
_game_speed = 100;
|
||||||
SetMouseCursorBusy(true);
|
SetMouseCursorBusy(true);
|
||||||
|
|
||||||
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START);
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START);
|
||||||
@@ -2918,7 +2918,7 @@ static void SaveFileStart()
|
|||||||
/** Update the gui accordingly when saving is done and release locks on saveload. */
|
/** Update the gui accordingly when saving is done and release locks on saveload. */
|
||||||
static void SaveFileDone()
|
static void SaveFileDone()
|
||||||
{
|
{
|
||||||
if (_game_mode != GM_MENU) _fast_forward = _sl.ff_state;
|
if (_game_mode != GM_MENU) _game_speed = _sl.game_speed;
|
||||||
SetMouseCursorBusy(false);
|
SetMouseCursorBusy(false);
|
||||||
|
|
||||||
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH);
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH);
|
||||||
|
@@ -1624,6 +1624,7 @@ static SettingsContainer &GetSettingsTree()
|
|||||||
advsig->Add(new SettingEntry("gui.show_adv_tracerestrict_features"));
|
advsig->Add(new SettingEntry("gui.show_adv_tracerestrict_features"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface->Add(new SettingEntry("gui.fast_forward_speed_limit"));
|
||||||
interface->Add(new SettingEntry("gui.autosave"));
|
interface->Add(new SettingEntry("gui.autosave"));
|
||||||
interface->Add(new SettingEntry("gui.autosave_on_network_disconnect"));
|
interface->Add(new SettingEntry("gui.autosave_on_network_disconnect"));
|
||||||
interface->Add(new SettingEntry("gui.savegame_overwrite_confirm"));
|
interface->Add(new SettingEntry("gui.savegame_overwrite_confirm"));
|
||||||
|
@@ -197,6 +197,7 @@ struct GUISettings : public TimeSettings {
|
|||||||
bool show_newgrf_name; ///< Show the name of the NewGRF in the build vehicle window
|
bool show_newgrf_name; ///< Show the name of the NewGRF in the build vehicle window
|
||||||
bool auto_remove_signals; ///< automatically remove signals when in the way during rail construction
|
bool auto_remove_signals; ///< automatically remove signals when in the way during rail construction
|
||||||
uint16 refresh_rate; ///< How often we refresh the screen (time between draw-ticks).
|
uint16 refresh_rate; ///< How often we refresh the screen (time between draw-ticks).
|
||||||
|
uint16 fast_forward_speed_limit; ///< Game speed to use when fast-forward is enabled.
|
||||||
bool show_vehicle_route_steps; ///< when a window related to a specific vehicle is focused, show route steps
|
bool show_vehicle_route_steps; ///< when a window related to a specific vehicle is focused, show route steps
|
||||||
bool show_vehicle_list_company_colour; ///< show the company colour of vehicles which have an owner different to the owner of the vehicle list
|
bool show_vehicle_list_company_colour; ///< show the company colour of vehicles which have an owner different to the owner of the vehicle list
|
||||||
bool enable_single_veh_shared_order_gui; ///< enable showing a single vehicle in the shared order GUI window
|
bool enable_single_veh_shared_order_gui; ///< enable showing a single vehicle in the shared order GUI window
|
||||||
|
@@ -5202,6 +5202,20 @@ max = 1000
|
|||||||
cat = SC_EXPERT
|
cat = SC_EXPERT
|
||||||
startup = true
|
startup = true
|
||||||
|
|
||||||
|
[SDTC_VAR]
|
||||||
|
var = gui.fast_forward_speed_limit
|
||||||
|
type = SLE_UINT16
|
||||||
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
|
guiflags = SGF_0ISDISABLED | SGF_NO_NETWORK
|
||||||
|
def = 2500
|
||||||
|
min = 0
|
||||||
|
max = 100000
|
||||||
|
interval = 10
|
||||||
|
str = STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT
|
||||||
|
strhelp = STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT_HELPTEXT
|
||||||
|
strval = STR_CONFIG_SETTING_FAST_FORWARD_SPEED_LIMIT_VAL
|
||||||
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTC_BOOL]
|
[SDTC_BOOL]
|
||||||
var = sound.news_ticker
|
var = sound.news_ticker
|
||||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
|
@@ -290,7 +290,8 @@ static CallBackFunction ToolbarPauseClick(Window *w)
|
|||||||
*/
|
*/
|
||||||
static CallBackFunction ToolbarFastForwardClick(Window *w)
|
static CallBackFunction ToolbarFastForwardClick(Window *w)
|
||||||
{
|
{
|
||||||
_fast_forward ^= true;
|
ChangeGameSpeed(_game_speed == 100);
|
||||||
|
|
||||||
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
||||||
return CBF_NONE;
|
return CBF_NONE;
|
||||||
}
|
}
|
||||||
@@ -2177,7 +2178,7 @@ struct MainToolbarWindow : Window {
|
|||||||
this->SetWidgetDirty(WID_TN_PAUSE);
|
this->SetWidgetDirty(WID_TN_PAUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
|
if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != (_game_speed != 100)) {
|
||||||
this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
|
this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
|
||||||
this->SetWidgetDirty(WID_TN_FAST_FORWARD);
|
this->SetWidgetDirty(WID_TN_FAST_FORWARD);
|
||||||
}
|
}
|
||||||
@@ -2564,7 +2565,7 @@ struct ScenarioEditorToolbarWindow : Window {
|
|||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
|
if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != (_game_speed != 100)) {
|
||||||
this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
|
this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
#include "../rev.h"
|
#include "../rev.h"
|
||||||
#include "../blitter/factory.hpp"
|
#include "../blitter/factory.hpp"
|
||||||
#include "../network/network.h"
|
|
||||||
#include "../core/random_func.hpp"
|
#include "../core/random_func.hpp"
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
#include "../framerate_type.h"
|
#include "../framerate_type.h"
|
||||||
@@ -455,17 +454,12 @@ void VideoDriver_Allegro::InputLoop()
|
|||||||
_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG) != _invert_shift;
|
_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG) != _invert_shift;
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_shift_pressed)
|
this->fast_forward_key_pressed = _shift_pressed;
|
||||||
#else
|
#else
|
||||||
/* Speedup when pressing tab, except when using ALT+TAB
|
/* Speedup when pressing tab, except when using ALT+TAB
|
||||||
* to switch to another application. */
|
* to switch to another application. */
|
||||||
if (key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0)
|
this->fast_forward_key_pressed = key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0;
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
||||||
} else if (_fast_forward & 2) {
|
|
||||||
_fast_forward = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine which directional keys are down. */
|
/* Determine which directional keys are down. */
|
||||||
_dirkeys =
|
_dirkeys =
|
||||||
|
@@ -33,7 +33,6 @@
|
|||||||
#include "cocoa_wnd.h"
|
#include "cocoa_wnd.h"
|
||||||
#include "../../blitter/factory.hpp"
|
#include "../../blitter/factory.hpp"
|
||||||
#include "../../framerate_type.h"
|
#include "../../framerate_type.h"
|
||||||
#include "../../network/network.h"
|
|
||||||
#include "../../gfx_func.h"
|
#include "../../gfx_func.h"
|
||||||
#include "../../thread.h"
|
#include "../../thread.h"
|
||||||
#include "../../core/random_func.hpp"
|
#include "../../core/random_func.hpp"
|
||||||
@@ -606,14 +605,10 @@ void VideoDriver_Cocoa::InputLoop()
|
|||||||
_shift_pressed = ((cur_mods & NSShiftKeyMask) != 0) != _invert_shift;
|
_shift_pressed = ((cur_mods & NSShiftKeyMask) != 0) != _invert_shift;
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_shift_pressed) {
|
this->fast_forward_key_pressed = _shift_pressed;
|
||||||
#else
|
#else
|
||||||
if (_tab_is_down) {
|
this->fast_forward_key_pressed = _tab_is_down;
|
||||||
#endif
|
#endif
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
||||||
} else if (_fast_forward & 2) {
|
|
||||||
_fast_forward = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
|
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
|
||||||
if (old_shift_pressed != _shift_pressed) HandleShiftChanged();
|
if (old_shift_pressed != _shift_pressed) HandleShiftChanged();
|
||||||
|
@@ -279,7 +279,7 @@ void VideoDriver_Dedicated::MainLoop()
|
|||||||
|
|
||||||
if (!_dedicated_forks) DedicatedHandleKeyInput();
|
if (!_dedicated_forks) DedicatedHandleKeyInput();
|
||||||
|
|
||||||
_fast_forward = _ddc_fastforward;
|
ChangeGameSpeed(_ddc_fastforward);
|
||||||
this->Tick();
|
this->Tick();
|
||||||
this->SleepTillNextTick();
|
this->SleepTillNextTick();
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
#include "../rev.h"
|
#include "../rev.h"
|
||||||
#include "../blitter/factory.hpp"
|
#include "../blitter/factory.hpp"
|
||||||
#include "../network/network.h"
|
|
||||||
#include "../thread.h"
|
#include "../thread.h"
|
||||||
#include "../progress.h"
|
#include "../progress.h"
|
||||||
#include "../core/random_func.hpp"
|
#include "../core/random_func.hpp"
|
||||||
@@ -1076,17 +1075,12 @@ void VideoDriver_SDL::InputLoop()
|
|||||||
_shift_pressed = !!(mod & KMOD_SHIFT) != _invert_shift;
|
_shift_pressed = !!(mod & KMOD_SHIFT) != _invert_shift;
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_shift_pressed)
|
this->fast_forward_key_pressed = _shift_pressed;
|
||||||
#else
|
#else
|
||||||
/* Speedup when pressing tab, except when using ALT+TAB
|
/* Speedup when pressing tab, except when using ALT+TAB
|
||||||
* to switch to another application. */
|
* to switch to another application. */
|
||||||
if (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 0)
|
this->fast_forward_key_pressed = keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 0;
|
||||||
#endif /* defined(_DEBUG) */
|
#endif /* defined(_DEBUG) */
|
||||||
{
|
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
||||||
} else if (_fast_forward & 2) {
|
|
||||||
_fast_forward = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine which directional keys are down. */
|
/* Determine which directional keys are down. */
|
||||||
_dirkeys =
|
_dirkeys =
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
#include "../rev.h"
|
#include "../rev.h"
|
||||||
#include "../blitter/factory.hpp"
|
#include "../blitter/factory.hpp"
|
||||||
#include "../network/network.h"
|
|
||||||
#include "../thread.h"
|
#include "../thread.h"
|
||||||
#include "../progress.h"
|
#include "../progress.h"
|
||||||
#include "../core/random_func.hpp"
|
#include "../core/random_func.hpp"
|
||||||
@@ -668,17 +667,12 @@ void VideoDriver_SDL::InputLoop()
|
|||||||
_shift_pressed = !!(mod & KMOD_SHIFT) != _invert_shift;
|
_shift_pressed = !!(mod & KMOD_SHIFT) != _invert_shift;
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_shift_pressed)
|
this->fast_forward_key_pressed = _shift_pressed;
|
||||||
#else
|
#else
|
||||||
/* Speedup when pressing tab, except when using ALT+TAB
|
/* Speedup when pressing tab, except when using ALT+TAB
|
||||||
* to switch to another application. */
|
* to switch to another application. */
|
||||||
if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0)
|
this->fast_forward_key_pressed = keys[SDLK_TAB] && (mod & KMOD_ALT) == 0;
|
||||||
#endif /* defined(_DEBUG) */
|
#endif /* defined(_DEBUG) */
|
||||||
{
|
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
||||||
} else if (_fast_forward & 2) {
|
|
||||||
_fast_forward = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine which directional keys are down. */
|
/* Determine which directional keys are down. */
|
||||||
_dirkeys =
|
_dirkeys =
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
|
#include "../network/network.h"
|
||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
#include "../progress.h"
|
#include "../progress.h"
|
||||||
#include "../thread.h"
|
#include "../thread.h"
|
||||||
@@ -19,14 +20,10 @@ bool VideoDriver::Tick()
|
|||||||
{
|
{
|
||||||
auto cur_ticks = std::chrono::steady_clock::now();
|
auto cur_ticks = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
if (cur_ticks >= this->next_game_tick || (_fast_forward && !_pause_mode)) {
|
if (cur_ticks >= this->next_game_tick) {
|
||||||
if (_fast_forward && !_pause_mode) {
|
this->next_game_tick += this->GetGameInterval();
|
||||||
this->next_game_tick = cur_ticks + this->GetGameInterval();
|
/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
|
||||||
} else {
|
if (this->next_game_tick < cur_ticks - ALLOWED_DRIFT * this->GetGameInterval()) this->next_game_tick = cur_ticks;
|
||||||
this->next_game_tick += this->GetGameInterval();
|
|
||||||
/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
|
|
||||||
if (this->next_game_tick < cur_ticks - ALLOWED_DRIFT * this->GetGameInterval()) this->next_game_tick = cur_ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The game loop is the part that can run asynchronously.
|
/* The game loop is the part that can run asynchronously.
|
||||||
* The rest except sleeping can't. */
|
* The rest except sleeping can't. */
|
||||||
@@ -50,6 +47,16 @@ bool VideoDriver::Tick()
|
|||||||
if (this->next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = cur_ticks;
|
if (this->next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = cur_ticks;
|
||||||
|
|
||||||
this->InputLoop();
|
this->InputLoop();
|
||||||
|
|
||||||
|
/* Check if the fast-forward button is still pressed. */
|
||||||
|
if (fast_forward_key_pressed && !_networking && _game_mode != GM_MENU) {
|
||||||
|
ChangeGameSpeed(true);
|
||||||
|
this->fast_forward_via_key = true;
|
||||||
|
} else if (this->fast_forward_via_key) {
|
||||||
|
ChangeGameSpeed(false);
|
||||||
|
this->fast_forward_via_key = false;
|
||||||
|
}
|
||||||
|
|
||||||
::InputLoop();
|
::InputLoop();
|
||||||
UpdateWindows();
|
UpdateWindows();
|
||||||
this->CheckPaletteAnim();
|
this->CheckPaletteAnim();
|
||||||
@@ -62,16 +69,13 @@ bool VideoDriver::Tick()
|
|||||||
|
|
||||||
void VideoDriver::SleepTillNextTick()
|
void VideoDriver::SleepTillNextTick()
|
||||||
{
|
{
|
||||||
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
|
/* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
|
||||||
if (!_fast_forward || _pause_mode) {
|
auto next_tick = std::min(this->next_draw_tick, this->next_game_tick);
|
||||||
/* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
|
auto now = std::chrono::steady_clock::now();
|
||||||
auto next_tick = std::min(this->next_draw_tick, this->next_game_tick);
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
if (next_tick > now) {
|
if (next_tick > now) {
|
||||||
this->UnlockVideoBuffer();
|
this->UnlockVideoBuffer();
|
||||||
std::this_thread::sleep_for(next_tick - now);
|
std::this_thread::sleep_for(next_tick - now);
|
||||||
this->LockVideoBuffer();
|
this->LockVideoBuffer();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "../driver.h"
|
#include "../driver.h"
|
||||||
#include "../core/geometry_type.hpp"
|
#include "../core/geometry_type.hpp"
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
|
#include "../gfx_func.h"
|
||||||
#include "../settings_type.h"
|
#include "../settings_type.h"
|
||||||
#include "../zoom_type.h"
|
#include "../zoom_type.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -202,7 +203,12 @@ protected:
|
|||||||
|
|
||||||
std::chrono::steady_clock::duration GetGameInterval()
|
std::chrono::steady_clock::duration GetGameInterval()
|
||||||
{
|
{
|
||||||
return std::chrono::milliseconds(MILLISECONDS_PER_TICK);
|
/* If we are paused, run on normal speed. */
|
||||||
|
if (_pause_mode) return std::chrono::milliseconds(MILLISECONDS_PER_TICK);
|
||||||
|
/* Infinite speed, as quickly as you can. */
|
||||||
|
if (_game_speed == 0) return std::chrono::microseconds(0);
|
||||||
|
|
||||||
|
return std::chrono::microseconds(MILLISECONDS_PER_TICK * 1000 * 100 / _game_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::steady_clock::duration GetDrawInterval()
|
std::chrono::steady_clock::duration GetDrawInterval()
|
||||||
@@ -212,6 +218,9 @@ protected:
|
|||||||
|
|
||||||
std::chrono::steady_clock::time_point next_game_tick;
|
std::chrono::steady_clock::time_point next_game_tick;
|
||||||
std::chrono::steady_clock::time_point next_draw_tick;
|
std::chrono::steady_clock::time_point next_draw_tick;
|
||||||
|
|
||||||
|
bool fast_forward_key_pressed; ///< The fast-forward key is being pressed.
|
||||||
|
bool fast_forward_via_key; ///< The fast-forward was enabled by key press.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_VIDEO_DRIVER_HPP */
|
#endif /* VIDEO_VIDEO_DRIVER_HPP */
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
#include "../os/windows/win32.h"
|
#include "../os/windows/win32.h"
|
||||||
#include "../rev.h"
|
#include "../rev.h"
|
||||||
#include "../blitter/factory.hpp"
|
#include "../blitter/factory.hpp"
|
||||||
#include "../network/network.h"
|
|
||||||
#include "../core/geometry_func.hpp"
|
#include "../core/geometry_func.hpp"
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
#include "../core/random_func.hpp"
|
#include "../core/random_func.hpp"
|
||||||
@@ -911,17 +910,12 @@ void VideoDriver_Win32Base::InputLoop()
|
|||||||
_shift_pressed = (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0) != _invert_shift;
|
_shift_pressed = (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0) != _invert_shift;
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_shift_pressed)
|
this->fast_forward_key_pressed = _shift_pressed;
|
||||||
#else
|
#else
|
||||||
/* Speedup when pressing tab, except when using ALT+TAB
|
/* Speedup when pressing tab, except when using ALT+TAB
|
||||||
* to switch to another application. */
|
* to switch to another application. */
|
||||||
if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0)
|
this->fast_forward_key_pressed = _wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0;
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
||||||
} else if (_fast_forward & 2) {
|
|
||||||
_fast_forward = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine which directional keys are down. */
|
/* Determine which directional keys are down. */
|
||||||
if (_wnd.has_focus) {
|
if (_wnd.has_focus) {
|
||||||
|
Reference in New Issue
Block a user