aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameAdvancementHook.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-09 23:49:54 +0200
committer GitHub <noreply@github.com>2023-09-09 23:49:54 +0200
commit6278a35f4704574933464700026d8deb997da5c1 (patch)
treeeb36a9b030b263d825eb93638e64deb0dbd38a78 /src/openvic-simulation/GameAdvancementHook.hpp
parentbec619fc8f554cb075fcef2428f3b6bdb5e88e82 (diff)
parent3d7fbd9b376811ca0ed226fa78bcc8b6279ba8dc (diff)
Merge pull request #14 from OpenVicProject/dataloading
Dataloading scaffolding + basic culture and pop history loading
Diffstat (limited to 'src/openvic-simulation/GameAdvancementHook.hpp')
-rw-r--r--src/openvic-simulation/GameAdvancementHook.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/openvic-simulation/GameAdvancementHook.hpp b/src/openvic-simulation/GameAdvancementHook.hpp
new file mode 100644
index 0000000..59e43a4
--- /dev/null
+++ b/src/openvic-simulation/GameAdvancementHook.hpp
@@ -0,0 +1,44 @@
+#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:
+ using time_point_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
+
+ time_point_t 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