From 321103ea84cf61f58a26d59700284d84f11833f5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 15 Jun 2024 17:35:13 +0100 Subject: Move main application loop into the library --- ui/mainApplication.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ui/mainApplication.cpp (limited to 'ui/mainApplication.cpp') 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(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); + } +} -- cgit v1.2.3 From 3d7a2f7cbc69bcfb5b04d343cb15c3027721b2e7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 16 Jun 2024 12:28:42 +0100 Subject: Integrate ImGUI main calls --- ui/mainApplication.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ui/mainApplication.cpp') diff --git a/ui/mainApplication.cpp b/ui/mainApplication.cpp index 08f49a4..d843ef1 100644 --- a/ui/mainApplication.cpp +++ b/ui/mainApplication.cpp @@ -1,6 +1,10 @@ #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() @@ -16,6 +20,8 @@ MainApplication::mainLoop() } windows.apply(&Window::tick, t_passed); windows.apply(&Window::refresh); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); t_start = t_end; } @@ -29,6 +35,7 @@ MainApplication::processInputs() isRunning = false; return; } + ImGui_ImplSDL2_ProcessEvent(&e); windows.applyOne(&Window::handleInput, e); } } -- cgit v1.2.3 From 65c9432714c166cd79bdc24c07b18d8b15670063 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 24 Jun 2024 23:37:07 +0100 Subject: Don't process input events which ImGui handled --- ui/mainApplication.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui/mainApplication.cpp') diff --git a/ui/mainApplication.cpp b/ui/mainApplication.cpp index d843ef1..6cb1037 100644 --- a/ui/mainApplication.cpp +++ b/ui/mainApplication.cpp @@ -36,6 +36,8 @@ MainApplication::processInputs() return; } ImGui_ImplSDL2_ProcessEvent(&e); - windows.applyOne(&Window::handleInput, e); + if (!ImGui::GetIO().WantCaptureMouse) { + windows.applyOne(&Window::handleInput, e); + } } } -- cgit v1.2.3