From 5efbb46d9de2492eecd90df456b81421ebfabf64 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Wed, 26 Feb 2025 05:02:34 -0700 Subject: [PATCH] Call `EventHandler::pump()` first in game loop According to the SDL documentation: https://wiki.libsdl.org/SDL2/SDL_PollEvent > The common practice is to fully process the event queue once every frame, usually as a first step before updating the game's state In particular, we probably don't want to put event polling between drawing and swapping of the back buffer, like we had it previously. That may be particularly bad when handling a resize event. --- NAS2D/StateManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NAS2D/StateManager.cpp b/NAS2D/StateManager.cpp index aea87af0b..2747e2edf 100644 --- a/NAS2D/StateManager.cpp +++ b/NAS2D/StateManager.cpp @@ -68,6 +68,8 @@ void StateManager::setState(State* state) */ bool StateManager::update() { + Utility::get().pump(); + if (mActiveState) { State* nextState = mActiveState->update(); @@ -80,8 +82,6 @@ bool StateManager::update() { setState(nextState); } - - Utility::get().pump(); } else {