aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/GameAdvancementHook.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-05-16 20:59:39 +0200
committer Hop311 <hop3114@gmail.com>2023-05-16 20:59:39 +0200
commit42d9d1d5417deb5979a9d5775cfe97dcff4b77ba (patch)
tree440634772615531e704a5554aa59c9890cd9cd85 /src/openvic/GameAdvancementHook.hpp
parent339e0278a2064f7eeb152fe8c5778840b609e9f3 (diff)
Changed from OpenVic2 to OpenVic
Diffstat (limited to 'src/openvic/GameAdvancementHook.hpp')
-rw-r--r--src/openvic/GameAdvancementHook.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/openvic/GameAdvancementHook.hpp b/src/openvic/GameAdvancementHook.hpp
new file mode 100644
index 0000000..5d904bc
--- /dev/null
+++ b/src/openvic/GameAdvancementHook.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <chrono>
+#include <functional>
+#include <vector>
+
+namespace OpenVic {
+ //Conditionally advances game with provided behaviour
+ //Class governs game speed and pause state
+ class GameAdvancementHook {
+ public:
+ using AdvancementFunction = std::function<void()>;
+ using RefreshFunction = std::function<void()>;
+ using speed_t = int8_t;
+
+ //Minimum number of miliseconds before the simulation advances
+ static const std::vector<std::chrono::milliseconds> GAME_SPEEDS;
+
+ private:
+ std::chrono::time_point<std::chrono::high_resolution_clock> lastPolledTime;
+ //A function pointer that advances the simulation, intended to be a capturing lambda or something similar. May need to be reworked later
+ AdvancementFunction triggerFunction;
+ RefreshFunction refreshFunction;
+ speed_t currentSpeed;
+
+ public:
+ bool isPaused;
+
+ GameAdvancementHook(AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused = true, speed_t startingSpeed = 0);
+
+ void setSimulationSpeed(speed_t speed);
+ speed_t getSimulationSpeed() const;
+ void increaseSimulationSpeed();
+ void decreaseSimulationSpeed();
+ bool canIncreaseSimulationSpeed() const;
+ bool canDecreaseSimulationSpeed() const;
+ GameAdvancementHook& operator++();
+ GameAdvancementHook& operator--();
+ void conditionallyAdvanceGame();
+ void reset();
+ };
+} \ No newline at end of file