Yake's input handling using action maps for typical FPS controls:

   bool GameSession::initInput(   input::IInputSystem & rInputSystem, 
                           input::KeyboardDevice & rKeyboard, 
                           input::MouseDevice & rMouse, 
                           input::KeyboardEventGenerator & rKeyboardEventGenerator, 
                           input::MouseEventGenerator & rMouseEventGenerator ) 
   { 
      mActionMap.reg(   ACTIONID_QUIT, new input::KeyboardActionCondition( &rKeyboard, input::KC_ESCAPE ) ); 

      mActionMap.subscribeToActionId( ACTIONID_QUIT, boost::bind(GameSession::requestQuit,this) ); 

      mActionMap.reg(   ACTIONID_INGAME_UP, new input::KeyboardActionCondition( &rKeyboard, input::KC_W, input::KAM_CONTINUOUS ) ); 
      mActionMap.reg(   ACTIONID_INGAME_DOWN, new input::KeyboardActionCondition( &rKeyboard, input::KC_S, input::KAM_CONTINUOUS ) ); 
      mActionMap.reg(   ACTIONID_INGAME_LEFT, new input::KeyboardActionCondition( &rKeyboard, input::KC_A, input::KAM_CONTINUOUS ) ); 
      mActionMap.reg(   ACTIONID_INGAME_RIGHT, new input::KeyboardActionCondition( &rKeyboard, input::KC_D, input::KAM_CONTINUOUS ) ); 
      mActionMap.reg( ACTIONID_INGAME_JUMP, new input::KeyboardActionCondition( &rKeyboard, input::KC_SPACE, input::KAM_PRESSED ) ); 
      mActionMap.reg( ACTIONID_INGAME_PRIMARY_FIRE, new input::KeyboardActionCondition( &rKeyboard, input::KC_G, input::KAM_PRESSED ) ); 
      mActionMap.reg( ACTIONID_INGAME_USE, new input::KeyboardActionCondition( &rKeyboard, input::KC_Q, input::KAM_PRESSED ) ); 
      mActionMap.reg( ACTIONID_INGAME_USE, new input::KeyboardActionCondition( &rKeyboard, input::KC_RETURN, input::KAM_PRESSED ) ); 

      mActionMap.subscribeToActionId(   ACTIONID_INGAME_UP, boost::bind(GameSession::onPlayerUp,this) ); 
      mActionMap.subscribeToActionId(   ACTIONID_INGAME_DOWN, boost::bind(GameSession::onPlayerDown,this) ); 
      mActionMap.subscribeToActionId(   ACTIONID_INGAME_LEFT, boost::bind(GameSession::onPlayerLeft,this) ); 
      mActionMap.subscribeToActionId(   ACTIONID_INGAME_RIGHT, boost::bind(GameSession::onPlayerRight,this) ); 
      mActionMap.subscribeToActionId( ACTIONID_INGAME_JUMP, boost::bind(GameSession::onPlayerJump,this) ); 
      mActionMap.subscribeToActionId( ACTIONID_INGAME_PRIMARY_FIRE, boost::bind(GameSession::onPrimaryFire,this) ); 
      mActionMap.subscribeToActionId( ACTIONID_INGAME_USE, boost::bind(GameSession::onPlayerUse,this) ); 

      //mActionMap.subscribeToActionId( ACTIONID_INGAME_USE, boost::bind(PlayerController::event_use,this) ); 
      //mActionMap.subscribeToActionId( ACTIONID_INGAME_PRIMARY_FIRE, boost::bind(PlayerController::event_firePrimary,this) ); 
      //mActionMap.subscribeToActionId( ACTIONID_INGAME_SECONDARY_FIRE, boost::bind(PlayerController::event_fireSecondary,this) ); 

      rMouseEventGenerator.subscribeToMouseMoved( boost::bind(&GameSession::onMouseMoved,this,_1) ); 

      return true; 
   }
 
codesnippets/mouse.txt · Last modified: 2008/02/21 21:54 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki