aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/GameAdvancementHook.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-04-23 20:49:01 +0200
committer Hop311 <hop3114@gmail.com>2023-04-23 20:49:01 +0200
commitd3f3187209cb4085f27f95ce8ad2a77af25704fd (patch)
tree60971db586e78761341f2b48110d149b1ba0db9d /extension/src/openvic2/GameAdvancementHook.hpp
parent1084a5d64df5d3465ef90b3b85fe3374636a3fe8 (diff)
C++ refactoring + simulation prototype
Diffstat (limited to 'extension/src/openvic2/GameAdvancementHook.hpp')
-rw-r--r--extension/src/openvic2/GameAdvancementHook.hpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/extension/src/openvic2/GameAdvancementHook.hpp b/extension/src/openvic2/GameAdvancementHook.hpp
index 72af4ac..572494a 100644
--- a/extension/src/openvic2/GameAdvancementHook.hpp
+++ b/extension/src/openvic2/GameAdvancementHook.hpp
@@ -2,39 +2,40 @@
#include <chrono>
#include <functional>
+#include <vector>
namespace OpenVic2 {
- //Value of different game speeds are the minimum number of miliseconds before the simulation advances
- enum class GameSpeed {
- Speed1 = 4000,
- Speed2 = 3000,
- Speed3 = 2000,
- Speed4 = 1000,
- Speed5 = 100,
- Speed6 = 1
- };
-
//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;
public:
bool isPaused;
- GameSpeed currentSpeed;
+ speed_t currentSpeed;
- GameAdvancementHook(AdvancementFunction function = nullptr, bool startPaused = false, GameSpeed startingSpeed = GameSpeed::Speed1);
+ GameAdvancementHook(AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused = false, speed_t startingSpeed = 0);
+ void setSimulationSpeed(speed_t speed);
+ speed_t getSimulationSpeed() const;
void increaseSimulationSpeed();
void decreaseSimulationSpeed();
- GameAdvancementHook operator++(int);
- GameAdvancementHook operator--(int);
+ bool canIncreaseSimulationSpeed() const;
+ bool canDecreaseSimulationSpeed() const;
+ GameAdvancementHook& operator++();
+ GameAdvancementHook& operator--();
void conditionallyAdvanceGame();
};
} \ No newline at end of file