diff options
author | markomitos <markomitosevic9@gmail.com> | 2023-03-01 23:20:58 +0100 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-04-14 21:46:32 +0200 |
commit | 48558fdfec509942515b0e2d92e3f1357b201400 (patch) | |
tree | 2c49198c3cbbbb575dc14795132a20c7b9267a2c /extension/src/Simulation.cpp | |
parent | 436b038c1806e326ff6458f1692e9009d3a54346 (diff) |
Add Date to extension
For absolute simulation dates
Add TimeSpan to extension
For relative simulation time
Add Simulation Speed Management to extension
Add Visual Studio directory to .gitignore
Co-authored-by: ClarkeCode <clarke.john.robert@gmail.com>
Co-authored-by: Hop311 <hop3114@gmail.com>
Diffstat (limited to 'extension/src/Simulation.cpp')
-rw-r--r-- | extension/src/Simulation.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/extension/src/Simulation.cpp b/extension/src/Simulation.cpp new file mode 100644 index 0000000..5ea99c5 --- /dev/null +++ b/extension/src/Simulation.cpp @@ -0,0 +1,64 @@ +#include "Simulation.hpp" + +namespace OpenVic2 { + void Simulation::togglePauseState() { + this->isPaused = !isPaused; + } + + bool Simulation::getPauseState() { + return this->isPaused; + } + + void Simulation::increaseSimulationSpeed() { + switch (this->currentSpeed) { + case(Speed::Speed1): + this->currentSpeed = Speed::Speed2; + break; + case(Speed::Speed2): + this->currentSpeed = Speed::Speed3; + break; + case(Speed::Speed3): + this->currentSpeed = Speed::Speed4; + break; + case(Speed::Speed4): + this->currentSpeed = Speed::Speed5; + break; + } + } + + void Simulation::decreaseSimulationSpeed() { + switch (this->currentSpeed) { + case(Speed::Speed2): + this->currentSpeed = Speed::Speed1; + break; + case(Speed::Speed3): + this->currentSpeed = Speed::Speed2; + break; + case(Speed::Speed4): + this->currentSpeed = Speed::Speed3; + break; + case(Speed::Speed5): + this->currentSpeed = Speed::Speed4; + break; + } + } + + void Simulation::setSimulationSpeed(Speed speed) { + this->currentSpeed = speed; + } + + int Simulation::getSimulationSpeed() { + return static_cast<int>(this->currentSpeed); + } + + void Simulation::conditionallyAdvanceSimulation() { + if (!(this->isPaused)) { + std::chrono::time_point<std::chrono::high_resolution_clock> previousTime = this->lastPolledTime; + std::chrono::time_point<std::chrono::high_resolution_clock> currentTime = std::chrono::high_resolution_clock::now(); + if (std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - previousTime).count() >= this->getSimulationSpeed()) { + this->lastPolledTime = currentTime; + this->inGameDate++; + } + } + } +} |