Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 29, 2008, 11:13:11 PM (16 years ago)
Author:
rgrieder
Message:
  • InputManager fully functional (most parts tested), if there wasn't that selfish SpaceShip who claims all the mouse input…
  • InputHandler still loads hard coded key bindings, but works fine otherwise
  • I've tried to give full multiple joy stick support. Couldn't yet test that however. And more than one Joystick still doesn't make sense as long as we don't have split view ;)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/InputHandler.cc

    r1182 r1203  
    3535#include "Debug.h"
    3636#include "util/Convert.h"
    37 #include "InputEventListener.h"
    38 #include "InputEvent.h"
    39 #include "InputManager.h"
    4037#include "core/CommandExecutor.h"
    4138
     
    4340{
    4441  // ###############################
    45   // ###    InputHandlerGame     ###
     42  // ######     KeyBinder     ######
    4643  // ###############################
    4744
    4845  /**
    49     @brief standard constructor
    50   */
    51   InputHandlerGame::InputHandlerGame()
    52   {
     46    @brief Constructor that does as little as necessary.
     47  */
     48  KeyBinder::KeyBinder()
     49  {
     50    clearBindings();
    5351  }
    5452
     
    5654    @brief Destructor
    5755  */
    58   InputHandlerGame::~InputHandlerGame()
    59   {
    60   }
    61 
    62   /**
    63     @brief Loads the key bindings from the ini file.
    64     Currently, this is just a simple test routine that fills the list with numbers.
    65   */
    66   bool InputHandlerGame::loadBindings()
     56  KeyBinder::~KeyBinder()
     57  {
     58  }
     59
     60  /**
     61    @brief Overwrites all bindings with ""
     62  */
     63  void KeyBinder::clearBindings()
    6764  {
    6865    for (int i = 0; i < numberOfKeys_s; i++)
    6966    {
    70       // simply write the key number (i) in the string
    71       this->bindingsKeyPress_[i] = "";
    72       this->bindingsKeyRelease_[i] = "";
    73     }
    74     this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
    75     this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
    76     this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
    77     return true;
    78   }
     67      bindingsKeyPress_  [i] = "";
     68      bindingsKeyRelease_[i] = "";
     69      bindingsKeyHold_   [i] = "";
     70    }
     71    for (int i = 0; i < numberOfMouseButtons_s; i++)
     72    {
     73      bindingsMouseButtonPress_  [i] = "";
     74      bindingsMouseButtonRelease_[i] = "";
     75      bindingsMouseButtonHold_   [i] = "";
     76    }
     77    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     78    {
     79      bindingsJoyStickButtonPress_  [i] = "";
     80      bindingsJoyStickButtonRelease_[i] = "";
     81      bindingsJoyStickButtonHold_   [i] = "";
     82    }
     83  }
     84
     85  /**
     86    @brief Loads the key and button bindings.
     87    @return True if loading succeeded.
     88  */
     89  bool KeyBinder::loadBindings()
     90  {
     91    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl;
     92
     93    // clear all the bindings at first.
     94    clearBindings();
     95
     96    // TODO: Insert the code to load the bindings from file.
     97    bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole";
     98    bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
     99    bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
     100
     101    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
     102    return true;
     103  }
     104
    79105
    80106  /**
     
    82108    @param e Event information
    83109  */
    84   bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
    85   {
    86     this->keysDown_.push_back(e.key);
     110  bool KeyBinder::keyPressed(const OIS::KeyEvent &e)
     111  {
    87112    // find the appropriate key binding
    88113    std::string cmdStr = bindingsKeyPress_[int(e.key)];
     
    92117      COUT(3) << "Executing command: " << cmdStr << std::endl;
    93118    }
     119   
    94120    return true;
    95121  }
     
    99125    @param e Event information
    100126  */
    101   bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
    102   {
    103     // remove the key from the keysDown_ list
    104     for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    105     {
    106       if (*it == e.key)
    107       {
    108         keysDown_.erase(it);
    109         break;
    110       }
    111     }
    112 
     127  bool KeyBinder::keyReleased(const OIS::KeyEvent &e)
     128  {
    113129    // find the appropriate key binding
    114130    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
     
    118134      COUT(3) << "Executing command: " << cmdStr << std::endl;
    119135    }
     136
     137    return true;
     138  }
     139
     140  /**
     141    @brief Event handler for the keyHeld Event.
     142    @param e Event information
     143  */
     144  bool KeyBinder::keyHeld(const OIS::KeyEvent &e)
     145  {
     146    // find the appropriate key binding
     147    std::string cmdStr = bindingsKeyHold_[int(e.key)];
     148    if (cmdStr != "")
     149    {
     150      CommandExecutor::execute(cmdStr);
     151      COUT(3) << "Executing command: " << cmdStr << std::endl;
     152    }
     153
    120154    return true;
    121155  }
     
    125159    @param e Event information
    126160  */
    127   bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
     161  bool KeyBinder::mouseMoved(const OIS::MouseEvent &e)
    128162  {
    129163    return true;
     
    135169    @param id The ID of the mouse button
    136170  */
    137   bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    138   {
     171  bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     172  {
     173    // find the appropriate key binding
     174    std::string cmdStr = bindingsMouseButtonPress_[int(id)];
     175    if (cmdStr != "")
     176    {
     177      CommandExecutor::execute(cmdStr);
     178      COUT(3) << "Executing command: " << cmdStr << std::endl;
     179    }
     180
    139181    return true;
    140182  }
     
    145187    @param id The ID of the mouse button
    146188  */
    147   bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    148   {
    149     return true;
    150   }
    151 
    152   /**
    153     @brief Tick method to do additional calculations.
    154     @param dt Delta time.
    155   */
    156   void InputHandlerGame::tick(float dt)
    157   {
    158     // iterate through all the pressed keys
    159     for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    160     {
    161       // find the appropriate key binding
    162       std::string cmdStr = bindingsKeyHold_[*it];
    163       if (cmdStr != "")
    164       {
    165         CommandExecutor::execute(cmdStr);
    166         COUT(3) << "Executing command: " << cmdStr << std::endl;
    167       }
    168     }
    169   }
    170 
    171   /**
    172     @brief Calls all the objects from classes that derive from InputEventListener.
    173     @param evt The input event that occured.
    174   */
    175   inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt)
    176   {
    177     for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; )
    178     {
    179       if (it->bActive_)
    180         (it++)->eventOccured(evt);
    181       else
    182         it++;
    183     }
    184   }
     189  bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     190  {
     191    // find the appropriate key binding
     192    std::string cmdStr = bindingsMouseButtonRelease_[int(id)];
     193    if (cmdStr != "")
     194    {
     195      CommandExecutor::execute(cmdStr);
     196      COUT(3) << "Executing command: " << cmdStr << std::endl;
     197    }
     198
     199    return true;
     200  }
     201
     202  /**
     203    @brief Event handler for the mouseHeld Event.
     204    @param e Event information
     205    @param id The ID of the mouse button
     206  */
     207  bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     208  {
     209    // find the appropriate key binding
     210    std::string cmdStr = bindingsMouseButtonHold_[int(id)];
     211    if (cmdStr != "")
     212    {
     213      CommandExecutor::execute(cmdStr);
     214      COUT(3) << "Executing command: " << cmdStr << std::endl;
     215    }
     216
     217    return true;
     218  }
     219
     220  bool KeyBinder::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     221  {
     222    // find the appropriate key binding
     223    std::string cmdStr = bindingsJoyStickButtonPress_[button];
     224    if (cmdStr != "")
     225    {
     226      CommandExecutor::execute(cmdStr);
     227      COUT(3) << "Executing command: " << cmdStr << std::endl;
     228    }
     229
     230    return true;
     231  }
     232
     233  bool KeyBinder::buttonReleased(const OIS::JoyStickEvent &arg, int button)
     234  {
     235    // find the appropriate key binding
     236    std::string cmdStr = bindingsJoyStickButtonRelease_[button];
     237    if (cmdStr != "")
     238    {
     239      CommandExecutor::execute(cmdStr);
     240      COUT(3) << "Executing command: " << cmdStr << std::endl;
     241    }
     242
     243    return true;
     244  }
     245
     246  bool KeyBinder::buttonHeld(const OIS::JoyStickEvent &arg, int button)
     247  {
     248    // find the appropriate key binding
     249    std::string cmdStr = bindingsJoyStickButtonHold_[button];
     250    if (cmdStr != "")
     251    {
     252      CommandExecutor::execute(cmdStr);
     253      COUT(3) << "Executing command: " << cmdStr << std::endl;
     254    }
     255
     256    return true;
     257  }
     258
     259  bool KeyBinder::axisMoved(const OIS::JoyStickEvent &arg, int axis)
     260  {
     261    return true;
     262  }
     263
     264  bool KeyBinder::sliderMoved(const OIS::JoyStickEvent &arg, int id)
     265  {
     266    return true;
     267  }
     268
     269  bool KeyBinder::povMoved(const OIS::JoyStickEvent &arg, int id)
     270  {
     271    return true;
     272  }
     273
    185274
    186275
    187276  // ###############################
    188   // ###     InputHandlerGUI     ###
     277  // ###     GUIInputHandler     ###
    189278  // ###############################
    190279
    191   /**
    192     @brief standard constructor
    193   */
    194   InputHandlerGUI::InputHandlerGUI()
    195   {
    196   }
    197 
    198   /**
    199     @brief Destructor
    200   */
    201   InputHandlerGUI::~InputHandlerGUI()
    202   {
    203   }
    204 
    205   /**
    206     @brief Event handler for the keyPressed Event.
    207     @param e Event information
    208   */
    209   bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e)
    210   {
    211                 //CEGUI::System::getSingleton().injectKeyDown( arg.key );
    212                 //CEGUI::System::getSingleton().injectChar( arg.text );
    213     return true;
    214   }
    215 
    216   /**
    217     @brief Event handler for the keyReleased Event.
    218     @param e Event information
    219   */
    220   bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e)
    221   {
    222                 //CEGUI::System::getSingleton().injectKeyUp( arg.key );
    223     return true;
    224   }
    225 
    226   /**
    227     @brief Event handler for the mouseMoved Event.
    228     @param e Event information
    229   */
    230   bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e)
    231   {
    232                 //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
    233     return true;
    234   }
    235 
    236   /**
    237     @brief Event handler for the mousePressed Event.
    238     @param e Event information
    239     @param id The ID of the mouse button
    240   */
    241   bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    242   {
    243                 //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
    244     return true;
    245   }
    246 
    247   /**
    248     @brief Event handler for the mouseReleased Event.
    249     @param e Event information
    250     @param id The ID of the mouse button
    251   */
    252   bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    253   {
    254                 //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
    255     return true;
    256   }
    257 
    258   /**
    259     @brief Tick method to do additional calculations.
    260     @param dt Delta time.
    261   */
    262   void InputHandlerGUI::tick(float dt)
    263   {
    264    
    265   }
     280  ///**
     281  //  @brief standard constructor
     282  //*/
     283  //GUIInputHandler::GUIInputHandler()
     284  //{
     285  //}
     286
     287  ///**
     288  //  @brief Destructor
     289  //*/
     290  //GUIInputHandler::~GUIInputHandler()
     291  //{
     292  //}
     293
     294  ///**
     295  //  @brief Event handler for the keyPressed Event.
     296  //  @param e Event information
     297  //*/
     298  //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e)
     299  //{
     300                ////CEGUI::System::getSingleton().injectKeyDown( arg.key );
     301                ////CEGUI::System::getSingleton().injectChar( arg.text );
     302  //  return true;
     303  //}
     304
     305  ///**
     306  //  @brief Event handler for the keyReleased Event.
     307  //  @param e Event information
     308  //*/
     309  //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e)
     310  //{
     311                ////CEGUI::System::getSingleton().injectKeyUp( arg.key );
     312  //  return true;
     313  //}
     314
     315  ///**
     316  //  @brief Event handler for the mouseMoved Event.
     317  //  @param e Event information
     318  //*/
     319  //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e)
     320  //{
     321                ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
     322  //  return true;
     323  //}
     324
     325  ///**
     326  //  @brief Event handler for the mousePressed Event.
     327  //  @param e Event information
     328  //  @param id The ID of the mouse button
     329  //*/
     330  //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     331  //{
     332                ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
     333  //  return true;
     334  //}
     335
     336  ///**
     337  //  @brief Event handler for the mouseReleased Event.
     338  //  @param e Event information
     339  //  @param id The ID of the mouse button
     340  //*/
     341  //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     342  //{
     343                ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
     344  //  return true;
     345  //}
    266346
    267347}
Note: See TracChangeset for help on using the changeset viewer.