summaryrefslogtreecommitdiff
path: root/ui/mainApplication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui/mainApplication.cpp')
-rw-r--r--ui/mainApplication.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/ui/mainApplication.cpp b/ui/mainApplication.cpp
new file mode 100644
index 0000000..08f49a4
--- /dev/null
+++ b/ui/mainApplication.cpp
@@ -0,0 +1,34 @@
+#include "mainApplication.h"
+#include "game/gamestate.h"
+#include "game/worldobject.h"
+
+void
+MainApplication::mainLoop()
+{
+ auto t_start = std::chrono::high_resolution_clock::now();
+ while (isRunning) {
+ processInputs();
+ const auto t_end = std::chrono::high_resolution_clock::now();
+ const auto t_passed = std::chrono::duration_cast<TickDuration>(t_end - t_start);
+
+ if (gameState) {
+ gameState->world.apply(&WorldObject::tick, t_passed);
+ }
+ windows.apply(&Window::tick, t_passed);
+ windows.apply(&Window::refresh);
+
+ t_start = t_end;
+ }
+}
+
+void
+MainApplication::processInputs()
+{
+ for (SDL_Event e; SDL_PollEvent(&e);) {
+ if (e.type == SDL_QUIT) {
+ isRunning = false;
+ return;
+ }
+ windows.applyOne(&Window::handleInput, e);
+ }
+}