diff options
author | Hop311 <Hop3114@gmail.com> | 2023-04-23 20:52:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-23 20:52:33 +0200 |
commit | 7f433fe019310ecfd1d1c46afd97cbfcb210c88f (patch) | |
tree | 60971db586e78761341f2b48110d149b1ba0db9d /extension/src/openvic2/GameAdvancementHook.hpp | |
parent | c041b291c887db90a4e1112ffdd1e56865c27b13 (diff) | |
parent | d3f3187209cb4085f27f95ce8ad2a77af25704fd (diff) |
Merge pull request #94 from OpenVic2Project/province-buildings
Province buildings
Diffstat (limited to 'extension/src/openvic2/GameAdvancementHook.hpp')
-rw-r--r-- | extension/src/openvic2/GameAdvancementHook.hpp | 29 |
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 |