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 --- application/main.cpp | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'application') diff --git a/application/main.cpp b/application/main.cpp index 04c88f3..d58cf6d 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,7 +1,7 @@ +#include "ui/mainApplication.h" #include "ui/mainWindow.h" #include #include -#include #include #include #include @@ -32,16 +32,13 @@ static const int DISPLAY_WIDTH = 1280; static const int DISPLAY_HEIGHT = 1024; -class MainApplication : public GameState, public ApplicationBase { +class DummyMainApplication : public GameState, public MainApplication { public: - using Windows = Collection; - int run() { geoData = std::make_shared(GeoData::loadFromAsciiGrid("test/fixtures/height/SD19.asc")); - Windows windows; windows.create(DISPLAY_WIDTH, DISPLAY_HEIGHT)->setContent(); world.create(geoData); @@ -90,41 +87,15 @@ public: } } - auto t_start = std::chrono::high_resolution_clock::now(); - while (isRunning) { - processInputs(windows); - const auto t_end = std::chrono::high_resolution_clock::now(); - const auto t_passed = std::chrono::duration_cast(t_end - t_start); - - world.apply(&WorldObject::tick, t_passed); - windows.apply(&Window::tick, t_passed); - windows.apply(&Window::refresh); - - t_start = t_end; - } + mainLoop(); world.objects.clear(); return 0; } - -private: - void - processInputs(const Windows & windows) - { - for (SDL_Event e; SDL_PollEvent(&e);) { - if (e.type == SDL_QUIT) { - isRunning = false; - return; - } - windows.applyOne(&Window::handleInput, e); - } - } - - bool isRunning {true}; }; int main(int, char **) { - return std::make_shared()->run(); + return std::make_shared()->run(); } -- cgit v1.2.3