From: <the...@us...> - 2007-06-27 17:54:16
|
Revision: 74 http://qonk.svn.sourceforge.net/qonk/?rev=74&view=rev Author: thebohemian Date: 2007-06-27 10:54:15 -0700 (Wed, 27 Jun 2007) Log Message: ----------- - fixed actionmap key overflow Modified Paths: -------------- branches/input-abstraction-2007-06-12/src/sdl_driver.cpp branches/input-abstraction-2007-06-12/src/sdl_driver.h Modified: branches/input-abstraction-2007-06-12/src/sdl_driver.cpp =================================================================== --- branches/input-abstraction-2007-06-12/src/sdl_driver.cpp 2007-06-27 17:21:44 UTC (rev 73) +++ branches/input-abstraction-2007-06-12/src/sdl_driver.cpp 2007-06-27 17:54:15 UTC (rev 74) @@ -15,6 +15,8 @@ #include <iostream> #include <map> +using namespace std; + const int DEADZONE_MOUSE = 0; const int DEADZONE_STICK = 1000; @@ -57,7 +59,7 @@ GameAction ga = (GameAction) i; Input input = Settings::getInput(ga); - int k = key(input.inputType, input.id0, input.id1, input.id2); + pair< int, int> k = key(input.inputType, input.id0, input.id1, input.id2); if (input.inputType != IT_NONE) actionMap[k] = ga; @@ -82,21 +84,26 @@ SDL_Quit(); } -inline int +inline pair <int, int> SDLDriver::key(InputType it, int id0, int id1, int id2) { - return it << 24 | id0 << 16 | id1 << 8 | id2; + return pair< int, int> (it << 24 | id0, id1 << 16 | id2); } void SDLDriver::input(InputType type, int id0, int id1, int id2, int value) { - GameAction ga = actionMap[key(type, id0, id1, id2)]; + map< pair < int, int >, GameAction >::iterator iter = actionMap.find(key(type, id0, id1, id2)); - if (ga == GA_TOGGLE_GRAB && value) - toggleGrab(); - else if (ga) - inputHandler.handle(ga, value); + if (iter != actionMap.end()) + { + GameAction ga = iter->second; + + if (ga == GA_TOGGLE_GRAB && value) + toggleGrab(); + else if (ga) + inputHandler.handle(ga, value); + } } void @@ -133,6 +140,8 @@ case SDL_KEYDOWN: case SDL_KEYUP: + //std::cerr << "key: " << SDL_GetKeyName(ev.key.keysym.sym) << (ev.key.state ? " pressed" : " released") << std::endl; + sdlInput->pushInput(ev); input(IT_KEYBOARD, ev.key.keysym.sym, 0, 0, ev.key.state<<3); break; Modified: branches/input-abstraction-2007-06-12/src/sdl_driver.h =================================================================== --- branches/input-abstraction-2007-06-12/src/sdl_driver.h 2007-06-27 17:21:44 UTC (rev 73) +++ branches/input-abstraction-2007-06-12/src/sdl_driver.h 2007-06-27 17:54:15 UTC (rev 74) @@ -26,7 +26,7 @@ gcn::SDLInput *getSDLInput(); private: - int key(InputType, int, int, int); + std::pair< int, int> key(InputType, int, int, int); void input(InputType, int, int, int, int); @@ -34,7 +34,7 @@ InputHandler &inputHandler; - std::map< int, GameAction > actionMap; + std::map< std::pair<int, int>, GameAction > actionMap; SDL_Joystick **sticks; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |