diff --git a/src/Application.cpp b/src/Application.cpp index e287eb0..536995e 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -20,9 +20,9 @@ void Application::run() { // measure start time for this tick auto start = SDL_GetTicks(); - // handle events + // handle all events from event queue SDL_Event event; - if (SDL_PollEvent(&event)) { + while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = true; @@ -33,10 +33,11 @@ void Application::run() { default: quit = handle_event(event); } + if (quit) break; } // update windows - for (const Window& window : Window::windows()) { + for (Window& window : Window::windows()) { window.update(); } @@ -51,11 +52,11 @@ void Application::run() { // calculate how long this tick took, and how much is left // if we want to maintain a steady fps auto elapsed = end - start; - auto available = 1000 / _fps - elapsed; + int available = 1000 / _fps - elapsed; // if there's any time left, sleep that much if (available > 0) { - // SDL_Delay(available); + SDL_Delay(available); } } }