Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.
This commit is contained in:

committed by
Charles Pigott

parent
73fd634209
commit
c3dc27e37e
@@ -19,7 +19,6 @@
|
||||
#include "../gfx_func.h"
|
||||
#include "../rev.h"
|
||||
#include "../blitter/factory.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../core/random_func.hpp"
|
||||
#include "../core/math_func.hpp"
|
||||
#include "../framerate_type.h"
|
||||
@@ -457,17 +456,12 @@ void VideoDriver_Allegro::InputLoop()
|
||||
_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG);
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (_shift_pressed)
|
||||
this->fast_forward_key_pressed = _shift_pressed;
|
||||
#else
|
||||
/* Speedup when pressing tab, except when using ALT+TAB
|
||||
* 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
|
||||
{
|
||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
||||
} else if (_fast_forward & 2) {
|
||||
_fast_forward = 0;
|
||||
}
|
||||
|
||||
/* Determine which directional keys are down. */
|
||||
_dirkeys =
|
||||
|
@@ -33,7 +33,6 @@
|
||||
#include "cocoa_wnd.h"
|
||||
#include "../../blitter/factory.hpp"
|
||||
#include "../../framerate_type.h"
|
||||
#include "../../network/network.h"
|
||||
#include "../../gfx_func.h"
|
||||
#include "../../thread.h"
|
||||
#include "../../core/random_func.hpp"
|
||||
@@ -420,14 +419,10 @@ void VideoDriver_Cocoa::InputLoop()
|
||||
_shift_pressed = (cur_mods & NSShiftKeyMask) != 0;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (_shift_pressed) {
|
||||
this->fast_forward_key_pressed = _shift_pressed;
|
||||
#else
|
||||
if (_tab_is_down) {
|
||||
this->fast_forward_key_pressed = _tab_is_down;
|
||||
#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();
|
||||
}
|
||||
|
@@ -277,7 +277,7 @@ void VideoDriver_Dedicated::MainLoop()
|
||||
while (!_exit_game) {
|
||||
if (!_dedicated_forks) DedicatedHandleKeyInput();
|
||||
|
||||
_fast_forward = _ddc_fastforward;
|
||||
ChangeGameSpeed(_ddc_fastforward);
|
||||
this->Tick();
|
||||
this->SleepTillNextTick();
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include "../gfx_func.h"
|
||||
#include "../rev.h"
|
||||
#include "../blitter/factory.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../thread.h"
|
||||
#include "../progress.h"
|
||||
#include "../core/random_func.hpp"
|
||||
@@ -604,17 +603,12 @@ void VideoDriver_SDL_Base::InputLoop()
|
||||
_shift_pressed = !!(mod & KMOD_SHIFT);
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (_shift_pressed)
|
||||
this->fast_forward_key_pressed = _shift_pressed;
|
||||
#else
|
||||
/* Speedup when pressing tab, except when using ALT+TAB
|
||||
* 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) */
|
||||
{
|
||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
||||
} else if (_fast_forward & 2) {
|
||||
_fast_forward = 0;
|
||||
}
|
||||
|
||||
/* Determine which directional keys are down. */
|
||||
_dirkeys =
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#include "../gfx_func.h"
|
||||
#include "../rev.h"
|
||||
#include "../blitter/factory.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../thread.h"
|
||||
#include "../progress.h"
|
||||
#include "../core/random_func.hpp"
|
||||
@@ -662,17 +661,12 @@ void VideoDriver_SDL::InputLoop()
|
||||
_shift_pressed = !!(mod & KMOD_SHIFT);
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (_shift_pressed)
|
||||
this->fast_forward_key_pressed = _shift_pressed;
|
||||
#else
|
||||
/* Speedup when pressing tab, except when using ALT+TAB
|
||||
* 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) */
|
||||
{
|
||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
||||
} else if (_fast_forward & 2) {
|
||||
_fast_forward = 0;
|
||||
}
|
||||
|
||||
/* Determine which directional keys are down. */
|
||||
_dirkeys =
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../debug.h"
|
||||
#include "../core/random_func.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../gfx_func.h"
|
||||
#include "../progress.h"
|
||||
#include "../thread.h"
|
||||
@@ -20,14 +21,10 @@ bool VideoDriver::Tick()
|
||||
{
|
||||
auto cur_ticks = std::chrono::steady_clock::now();
|
||||
|
||||
if (cur_ticks >= this->next_game_tick || (_fast_forward && !_pause_mode)) {
|
||||
if (_fast_forward && !_pause_mode) {
|
||||
this->next_game_tick = cur_ticks + this->GetGameInterval();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
if (cur_ticks >= this->next_game_tick) {
|
||||
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 rest except sleeping can't. */
|
||||
@@ -55,6 +52,16 @@ bool VideoDriver::Tick()
|
||||
|
||||
while (this->PollEvent()) {}
|
||||
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();
|
||||
UpdateWindows();
|
||||
this->CheckPaletteAnim();
|
||||
@@ -67,16 +74,13 @@ bool VideoDriver::Tick()
|
||||
|
||||
void VideoDriver::SleepTillNextTick()
|
||||
{
|
||||
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
|
||||
if (!_fast_forward || _pause_mode) {
|
||||
/* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
|
||||
auto next_tick = std::min(this->next_draw_tick, this->next_game_tick);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
/* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
|
||||
auto next_tick = std::min(this->next_draw_tick, this->next_game_tick);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
if (next_tick > now) {
|
||||
this->UnlockVideoBuffer();
|
||||
std::this_thread::sleep_for(next_tick - now);
|
||||
this->LockVideoBuffer();
|
||||
}
|
||||
if (next_tick > now) {
|
||||
this->UnlockVideoBuffer();
|
||||
std::this_thread::sleep_for(next_tick - now);
|
||||
this->LockVideoBuffer();
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "../driver.h"
|
||||
#include "../core/geometry_type.hpp"
|
||||
#include "../core/math_func.hpp"
|
||||
#include "../gfx_func.h"
|
||||
#include "../settings_type.h"
|
||||
#include "../zoom_type.h"
|
||||
#include <chrono>
|
||||
@@ -268,7 +269,12 @@ protected:
|
||||
|
||||
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()
|
||||
@@ -278,6 +284,9 @@ protected:
|
||||
|
||||
std::chrono::steady_clock::time_point next_game_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 */
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include "../os/windows/win32.h"
|
||||
#include "../rev.h"
|
||||
#include "../blitter/factory.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../core/geometry_func.hpp"
|
||||
#include "../core/math_func.hpp"
|
||||
#include "../core/random_func.hpp"
|
||||
@@ -831,17 +830,12 @@ void VideoDriver_Win32Base::InputLoop()
|
||||
_shift_pressed = this->has_focus && GetAsyncKeyState(VK_SHIFT) < 0;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (_shift_pressed)
|
||||
this->fast_forward_key_pressed = _shift_pressed;
|
||||
#else
|
||||
/* Speedup when pressing tab, except when using ALT+TAB
|
||||
* to switch to another application. */
|
||||
if (this->has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0)
|
||||
this->fast_forward_key_pressed = this->has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0;
|
||||
#endif
|
||||
{
|
||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
||||
} else if (_fast_forward & 2) {
|
||||
_fast_forward = 0;
|
||||
}
|
||||
|
||||
/* Determine which directional keys are down. */
|
||||
if (this->has_focus) {
|
||||
|
Reference in New Issue
Block a user