From 04b213d4e20ca4e7ea66b059329771f6fd36c650 Mon Sep 17 00:00:00 2001 From: ClarkeCode Date: Fri, 14 Apr 2023 23:41:57 -0400 Subject: Removing TestSingleton Extracted game advancement behaviour to separate class --- extension/src/openvic2/GameAdvancementHook.hpp | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 extension/src/openvic2/GameAdvancementHook.hpp (limited to 'extension/src/openvic2/GameAdvancementHook.hpp') diff --git a/extension/src/openvic2/GameAdvancementHook.hpp b/extension/src/openvic2/GameAdvancementHook.hpp new file mode 100644 index 0000000..72af4ac --- /dev/null +++ b/extension/src/openvic2/GameAdvancementHook.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +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; + + private: + std::chrono::time_point 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; + + public: + bool isPaused; + GameSpeed currentSpeed; + + GameAdvancementHook(AdvancementFunction function = nullptr, bool startPaused = false, GameSpeed startingSpeed = GameSpeed::Speed1); + + void increaseSimulationSpeed(); + void decreaseSimulationSpeed(); + GameAdvancementHook operator++(int); + GameAdvancementHook operator--(int); + void conditionallyAdvanceGame(); + }; +} \ No newline at end of file -- cgit v1.2.3-56-ga3b1