blob: 72af4acf3d5e639b2a70b4ad00ced4626143af35 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#pragma once
#include <chrono>
#include <functional>
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()>;
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;
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();
};
}
|