move SDL event handling to a function, to make the main

loop simpler
This commit is contained in:
Glenn Maynard
2003-03-17 06:20:57 +00:00
parent bbb416d615
commit be78746167
+15 -12
View File
@@ -500,13 +500,7 @@ static void HandleInputEvents(float fDeltaTime)
} }
} }
static void GameLoop() static bool HandleSDLEvents()
{
for(int hack = 0; hack < 1024; ++hack)
SDL_PumpEvents();
RageTimer timer;
while(1)
{ {
// process all queued events // process all queued events
SDL_Event event; SDL_Event event;
@@ -519,7 +513,7 @@ static void GameLoop()
{ {
case SDL_QUIT: case SDL_QUIT:
LOG->Trace("SDL_QUIT: shutting down"); LOG->Trace("SDL_QUIT: shutting down");
return; /* exit the main loop */ return false; /* exit the main loop */
case SDL_VIDEORESIZE: case SDL_VIDEORESIZE:
DISPLAY->ResolutionChanged(event.resize.w, event.resize.h); DISPLAY->ResolutionChanged(event.resize.w, event.resize.h);
break; break;
@@ -543,6 +537,17 @@ static void GameLoop()
} }
} }
return true;
}
static void GameLoop()
{
RageTimer timer;
while(1)
{
if(!HandleSDLEvents())
return; /* exit the main loop (quit) */
/* /*
* Update * Update
*/ */
@@ -562,16 +567,14 @@ static void GameLoop()
SCREENMAN->Update( fDeltaTime ); SCREENMAN->Update( fDeltaTime );
SOUNDMAN->Update( fDeltaTime ); SOUNDMAN->Update( fDeltaTime );
/* Important: Process input AFTER updaing game logic, or input will be acting on song beat from last frame */ /* Important: Process input AFTER updating game logic, or input will be acting on song beat from last frame */
HandleInputEvents( fDeltaTime ); HandleInputEvents( fDeltaTime );
/* /*
* Render * Render
*/ */
DISPLAY->Clear(); DISPLAY->Clear();
SCREENMAN->Draw();
SCREENMAN->Draw(); // draw the game
DISPLAY->Flip(); DISPLAY->Flip();
if(g_bHasFocus) if(g_bHasFocus)