aboutsummaryrefslogtreecommitdiff
path: root/src/engine/engine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/engine.cpp')
-rw-r--r--src/engine/engine.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp
index fda1fc2..774220a 100644
--- a/src/engine/engine.cpp
+++ b/src/engine/engine.cpp
@@ -2,6 +2,7 @@
#include "util/function.hpp"
+#include <chrono>
#include <thread>
#include <utility>
@@ -45,9 +46,28 @@ void CLIGameEngine::start() noexcept
_input_handler->listen();
}));
+ auto last_update_time = std::chrono::system_clock::now();
+
+ const auto get_millis_since_update = [&last_update_time]()
+ {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::system_clock::now() - last_update_time);
+ };
+
while (true)
{
+ const auto time_since_last_update = get_millis_since_update();
+
+ if (time_since_last_update.count() < MIN_TIME_SINCE_LAST_UPDATE_MILLIS)
+ {
+ while (get_millis_since_update().count() < MIN_TIME_SINCE_LAST_UPDATE_MILLIS)
+ {
+ }
+ }
+
game->on_update();
+
+ last_update_time = std::chrono::system_clock::now();
}
}