move input handling into a function

This commit is contained in:
Glenn Maynard
2002-12-15 20:16:14 +00:00
parent 40ed43f10d
commit d5dd8aedca
+51 -47
View File
@@ -434,52 +434,8 @@ int main(int argc, char* argv[])
return 0;
}
void GameLoop()
static void HandleInputEvents(float fDeltaTime)
{
bool do_exit = false;
SDL_Event event;
while(!do_exit)
{
// process all queued events
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
do_exit = 1;
break;
case SDL_VIDEORESIZE:
PREFSMAN->m_iDisplayWidth = event.resize.w;
PREFSMAN->m_iDisplayHeight = event.resize.h;
ApplyGraphicOptions();
break;
}
}
/*
* Update
*/
float fDeltaTime = TIMER->GetDeltaTime();
// This was a hack to fix timing issues with the old ScreenSelectSong
// See ScreenManager::Update comments for why we shouldn't do this. -glenn
//if( fDeltaTime > 0.050f ) // we dropped a bunch of frames
// fDeltaTime = 0.050f;
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_TAB) ) ) {
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
fDeltaTime = 0; /* both; stop time */
else
fDeltaTime *= 4;
} else
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
fDeltaTime /= 4;
TEXTUREMAN->Update( fDeltaTime );
MUSIC->Update( fDeltaTime );
SCREENMAN->Update( fDeltaTime );
CLIENT->Update( fDeltaTime );
SOUNDMAN->Update( fDeltaTime );
static InputEventArray ieArray;
ieArray.clear(); // empty the array
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
@@ -488,8 +444,6 @@ void GameLoop()
DeviceInput DeviceI = (DeviceInput)ieArray[i];
InputEventType type = ieArray[i].type;
/* ALT-F4 -> quit (better place for this? in ScreenManager perhaps?) */
/* Nah. this is fine. -Chris */
if(type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_F4))
{
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
@@ -508,6 +462,8 @@ void GameLoop()
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
ApplyGraphicOptions();
// fall through
/* why fall through? other code shouldn't be using
* globally-bound keys -glenn */
}
}
else if( type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_F5))
@@ -556,6 +512,54 @@ void GameLoop()
SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI );
}
}
void GameLoop()
{
bool do_exit = false;
SDL_Event event;
while(!do_exit)
{
// process all queued events
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
do_exit = 1;
break;
case SDL_VIDEORESIZE:
PREFSMAN->m_iDisplayWidth = event.resize.w;
PREFSMAN->m_iDisplayHeight = event.resize.h;
ApplyGraphicOptions();
break;
}
}
/*
* Update
*/
float fDeltaTime = TIMER->GetDeltaTime();
// This was a hack to fix timing issues with the old ScreenSelectSong
// See ScreenManager::Update comments for why we shouldn't do this. -glenn
//if( fDeltaTime > 0.050f ) // we dropped a bunch of frames
// fDeltaTime = 0.050f;
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_TAB) ) ) {
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
fDeltaTime = 0; /* both; stop time */
else
fDeltaTime *= 4;
} else
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
fDeltaTime /= 4;
TEXTUREMAN->Update( fDeltaTime );
MUSIC->Update( fDeltaTime );
SCREENMAN->Update( fDeltaTime );
CLIENT->Update( fDeltaTime );
SOUNDMAN->Update( fDeltaTime );
HandleInputEvents( fDeltaTime );
/*
* Render