move input handling into a function
This commit is contained in:
+51
-47
@@ -434,52 +434,8 @@ int main(int argc, char* argv[])
|
|||||||
return 0;
|
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;
|
static InputEventArray ieArray;
|
||||||
ieArray.clear(); // empty the array
|
ieArray.clear(); // empty the array
|
||||||
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
|
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
|
||||||
@@ -488,8 +444,6 @@ void GameLoop()
|
|||||||
DeviceInput DeviceI = (DeviceInput)ieArray[i];
|
DeviceInput DeviceI = (DeviceInput)ieArray[i];
|
||||||
InputEventType type = ieArray[i].type;
|
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(type == IET_FIRST_PRESS && DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_F4))
|
||||||
{
|
{
|
||||||
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
||||||
@@ -508,6 +462,8 @@ void GameLoop()
|
|||||||
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
|
PREFSMAN->m_bWindowed = !PREFSMAN->m_bWindowed;
|
||||||
ApplyGraphicOptions();
|
ApplyGraphicOptions();
|
||||||
// fall through
|
// 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))
|
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 );
|
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
|
* Render
|
||||||
|
|||||||
Reference in New Issue
Block a user