aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/GameAdvancementHook.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-05-04 15:47:20 +0200
committer GitHub <noreply@github.com>2023-05-04 15:47:20 +0200
commit7791a18094efaf62377606a7e5a7cba85a4c7a64 (patch)
treecd3ebcae0f67b07488fadb31ba3b376b306e03f6 /extension/src/openvic2/GameAdvancementHook.cpp
parent6fd8fc3a786370207508631e569c1e8f5ab0e4e3 (diff)
parent2420f8b8fdd2db84e053ebb2d7f6e4840171009e (diff)
Merge pull request #106 from OpenVic2Project/simulation-submodule
Moved simulation code to separate submodule
Diffstat (limited to 'extension/src/openvic2/GameAdvancementHook.cpp')
-rw-r--r--extension/src/openvic2/GameAdvancementHook.cpp75
1 files changed, 0 insertions, 75 deletions
diff --git a/extension/src/openvic2/GameAdvancementHook.cpp b/extension/src/openvic2/GameAdvancementHook.cpp
deleted file mode 100644
index a68f55c..0000000
--- a/extension/src/openvic2/GameAdvancementHook.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-#include "GameAdvancementHook.hpp"
-
-using namespace OpenVic2;
-
-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 }
-};
-
-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)
- currentSpeed = 0;
- else if (speed >= GAME_SPEEDS.size())
- currentSpeed = GAME_SPEEDS.size() - 1;
- else
- currentSpeed = speed;
-}
-
-GameAdvancementHook::speed_t GameAdvancementHook::getSimulationSpeed() const {
- return currentSpeed;
-}
-
-void GameAdvancementHook::increaseSimulationSpeed() {
- setSimulationSpeed(currentSpeed + 1);
-}
-
-void GameAdvancementHook::decreaseSimulationSpeed() {
- setSimulationSpeed(currentSpeed - 1);
-}
-
-bool GameAdvancementHook::canIncreaseSimulationSpeed() const {
- return currentSpeed + 1 < GAME_SPEEDS.size();
-}
-
-bool GameAdvancementHook::canDecreaseSimulationSpeed() const {
- return currentSpeed > 0;
-}
-
-GameAdvancementHook& GameAdvancementHook::operator++() {
- increaseSimulationSpeed();
- return *this;
-};
-
-GameAdvancementHook& GameAdvancementHook::operator--() {
- decreaseSimulationSpeed();
- return *this;
-};
-
-void GameAdvancementHook::conditionallyAdvanceGame() {
- if (!isPaused) {
- std::chrono::time_point<std::chrono::high_resolution_clock> 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 (refreshFunction) refreshFunction();
-}
-
-void GameAdvancementHook::reset() {
- isPaused = true;
- currentSpeed = 0;
-}