Skip to content

Commit

Permalink
Call EventHandler::pump() first in game loop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DanRStevens committed Feb 26, 2025
1 parent 0b1af07 commit 5efbb46
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions NAS2D/StateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void StateManager::setState(State* state)
*/
bool StateManager::update()
{
Utility<EventHandler>::get().pump();

if (mActiveState)
{
State* nextState = mActiveState->update();
Expand All @@ -80,8 +82,6 @@ bool StateManager::update()
{
setState(nextState);
}

Utility<EventHandler>::get().pump();
}
else
{
Expand Down

0 comments on commit 5efbb46

Please sign in to comment.