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
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user