Created
May 24, 2013 12:25
-
-
Save i8degrees/5643148 to your computer and use it in GitHub Desktop.
GameState && SDLInput Interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SDLInput | |
{ | |
virtual void Input ( SDL_Event *input ) | |
{ | |
// while ( SDL_PollEvent ( input ) ) | |
switch ( input->type ) | |
{ | |
case SDL_KEYDOWN: | |
onKeyDown ( input->key.keysym.sym, input->key.keysym.mod ); | |
break; | |
case SDL_KEYUP: | |
// Temporary state crash workaround by commenting below line out of exec: | |
//onKeyUp ( input->key.keysym.sym, input->key.keysym.mod ); | |
break; | |
case SDL_MOUSEMOTION: | |
// Temporary state crash workaround by commenting below line out of exec: | |
//onMouseMotion ( input->motion.x, input->motion.y ); | |
break; | |
// ... | |
} | |
} | |
virtual void onKeyDown ( SDLKey key, SDLMod mod ); | |
{ | |
// empty implement | |
} | |
virtual void onKeyUp ( SDLKey key, SDLMod mod ) | |
{ | |
// empty implement | |
} | |
}; | |
class GameState: public SDLInput | |
{ | |
}; | |
class GameEngine | |
{ | |
void GameEngine::HandleInput ( void ) | |
{ | |
// let the state handle events | |
states.back()->HandleInput (); | |
} | |
}; | |
class CardsMenuState: public GameState | |
{ | |
void HandleInput ( void ) | |
{ | |
SDL_Event event; | |
while ( SDL_PollEvent ( &event ) ) | |
SDLInput::Input ( &event ); | |
// Previously: | |
// SDLInput::Input (); | |
} | |
void onKeyDown ( SDLKey key, SDLMod mod ) | |
{ | |
switch ( key ) | |
{ | |
// ... | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment