summaryrefslogtreecommitdiff
path: root/ui/mainApplication.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-07-02 18:20:22 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-07-02 18:20:22 +0100
commit9d6d2c0eb21b6295b2668c23f0ef386d5827a83f (patch)
treeec4bedce6f3a695aa75412f30259e0f791f46f82 /ui/mainApplication.cpp
parentAdd an InstanceVertices partition perf test (diff)
parentBuild ImGui as a static library (diff)
downloadilt-9d6d2c0eb21b6295b2668c23f0ef386d5827a83f.tar.bz2
ilt-9d6d2c0eb21b6295b2668c23f0ef386d5827a83f.tar.xz
ilt-9d6d2c0eb21b6295b2668c23f0ef386d5827a83f.zip
Psycho-rebased branch imgui on top of main
Diffstat (limited to 'ui/mainApplication.cpp')
-rw-r--r--ui/mainApplication.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/ui/mainApplication.cpp b/ui/mainApplication.cpp
new file mode 100644
index 0000000..6cb1037
--- /dev/null
+++ b/ui/mainApplication.cpp
@@ -0,0 +1,43 @@
+#include "mainApplication.h"
+#include "game/gamestate.h"
+#include "game/worldobject.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include "backends/imgui_impl_sdl2.h"
+#pragma GCC diagnostic pop
+
+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);
+ ImGui::UpdatePlatformWindows();
+ ImGui::RenderPlatformWindowsDefault();
+
+ t_start = t_end;
+ }
+}
+
+void
+MainApplication::processInputs()
+{
+ for (SDL_Event e; SDL_PollEvent(&e);) {
+ if (e.type == SDL_QUIT) {
+ isRunning = false;
+ return;
+ }
+ ImGui_ImplSDL2_ProcessEvent(&e);
+ if (!ImGui::GetIO().WantCaptureMouse) {
+ windows.applyOne(&Window::handleInput, e);
+ }
+ }
+}