aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameAdvancementHook.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-10-29 21:14:55 +0100
committer GitHub <noreply@github.com>2023-10-29 21:14:55 +0100
commit06cc0606156d009026930c785c62434276fbe782 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/GameAdvancementHook.cpp
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
parent1b5e43fa7750cc4025d32f18390593cbce3ba842 (diff)
Merge pull request #67 from OpenVicProject/format
Formating
Diffstat (limited to 'src/openvic-simulation/GameAdvancementHook.cpp')
-rw-r--r--src/openvic-simulation/GameAdvancementHook.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/openvic-simulation/GameAdvancementHook.cpp b/src/openvic-simulation/GameAdvancementHook.cpp
index ac16158..4a6449c 100644
--- a/src/openvic-simulation/GameAdvancementHook.cpp
+++ b/src/openvic-simulation/GameAdvancementHook.cpp
@@ -3,30 +3,26 @@
using namespace OpenVic;
const std::vector<std::chrono::milliseconds> GameAdvancementHook::GAME_SPEEDS = {
- std::chrono::milliseconds { 4000 },
- std::chrono::milliseconds { 3000 },
- std::chrono::milliseconds { 2000 },
- std::chrono::milliseconds { 1000 },
- std::chrono::milliseconds { 100 },
- std::chrono::milliseconds { 1 }
+ std::chrono::milliseconds { 4000 }, std::chrono::milliseconds { 3000 }, std::chrono::milliseconds { 2000 },
+ std::chrono::milliseconds { 1000 }, std::chrono::milliseconds { 100 }, std::chrono::milliseconds { 1 }
};
-GameAdvancementHook::GameAdvancementHook(AdvancementFunction tickFunction,
- RefreshFunction updateFunction, bool startPaused, speed_t startingSpeed)
- : triggerFunction { tickFunction },
- refreshFunction { updateFunction },
- isPaused { startPaused } {
+GameAdvancementHook::GameAdvancementHook(
+ AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused, speed_t startingSpeed
+)
+ : triggerFunction { tickFunction }, refreshFunction { updateFunction }, isPaused { startPaused } {
lastPolledTime = std::chrono::high_resolution_clock::now();
setSimulationSpeed(startingSpeed);
}
void GameAdvancementHook::setSimulationSpeed(speed_t speed) {
- if (speed < 0)
+ if (speed < 0) {
currentSpeed = 0;
- else if (speed >= GAME_SPEEDS.size())
+ } else if (speed >= GAME_SPEEDS.size()) {
currentSpeed = GAME_SPEEDS.size() - 1;
- else
+ } else {
currentSpeed = speed;
+ }
}
GameAdvancementHook::speed_t GameAdvancementHook::getSimulationSpeed() const {
@@ -64,10 +60,14 @@ void GameAdvancementHook::conditionallyAdvanceGame() {
time_point_t currentTime = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - lastPolledTime) >= GAME_SPEEDS[currentSpeed]) {
lastPolledTime = currentTime;
- if (triggerFunction) triggerFunction();
+ if (triggerFunction) {
+ triggerFunction();
+ }
}
}
- if (refreshFunction) refreshFunction();
+ if (refreshFunction) {
+ refreshFunction();
+ }
}
void GameAdvancementHook::reset() {