Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2008, 5:44:55 PM (17 years ago)
Author:
scheusso
Message:

merged changes from input & camera & network branch into trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/InputManager.cc

    r1219 r1293  
    3030  @file
    3131  @brief Implementation of the InputManager that captures all the input from OIS
    32          and redirects it to handlers if necessary.
     32         and redirects it to handlers.
    3333 */
    3434
     
    5252  InputManager::InputManager() :
    5353      inputSystem_(0), keyboard_(0), mouse_(0),
    54       state_(IS_UNINIT), stateRequest_(IS_UNINIT)
     54      joySticksSize_(0),
     55      state_(IS_UNINIT), stateRequest_(IS_UNINIT),
     56      keyboardModifiers_(0)
    5557  {
    5658    RegisterObject(InputManager);
    57 
    58     this->joySticks_.reserve(5);
    59     //this->activeJoyStickHandlers_.reserve(10);
    60     this->activeKeyHandlers_.reserve(10);
    61     this->activeMouseHandlers_.reserve(10);
    6259  }
    6360
     
    8784    @param windowHeight The height of the render window
    8885  */
    89   bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
    90         const bool createKeyboard, const bool createMouse, const bool createJoySticks)
     86  bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight,
     87        bool createKeyboard, bool createMouse, bool createJoySticks)
    9188  {
    9289    if (state_ == IS_UNINIT)
    9390    {
     91      CCOUT(3) << "Initialising Input System..." << std::endl;
    9492      CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
    9593
     
    145143    addKeyHandler(binder, "keybinder");
    146144    addMouseHandler(binder, "keybinder");
     145    addJoyStickHandler(binder, "keybinder");
    147146
    148147    // Read all the key bindings and assign them
     
    234233  bool InputManager::_initialiseJoySticks()
    235234  {
    236     if (joySticks_.size() > 0)
     235    if (joySticksSize_ > 0)
    237236    {
    238237      CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
     
    265264      return false;
    266265    }
     266    joySticksSize_ = joySticks_.size();
     267    activeJoyStickHandlers_.resize(joySticksSize_);
     268    joyStickButtonsDown_.resize(joySticksSize_);
    267269    return success;
    268270  }
     
    273275  void InputManager::_destroy()
    274276  {
    275     CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
    276 
    277277    if (state_ != IS_UNINIT)
    278278    {
     279      CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
     280
    279281      if (keyHandlers_.find("buffer") != keyHandlers_.end())
    280282        delete keyHandlers_["buffer"];
     
    296298
    297299      state_ = IS_UNINIT;
    298     }
    299     else
    300       CCOUT(ORX_WARNING) << "Warning: Cannot be destroyed, since not initialised." << std::endl;
    301 
    302     CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
     300      CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
     301    }
    303302  }
    304303
     
    336335  void InputManager::_destroyJoySticks()
    337336  {
    338     if (joySticks_.size() > 0)
     337    if (joySticksSize_ > 0)
    339338    {
    340339      // note: inputSystem_ can never be 0, or else the code is mistaken
    341       for (unsigned int i = 0; i < joySticks_.size(); i++)
     340      for (unsigned int i = 0; i < joySticksSize_; i++)
    342341        if (joySticks_[i] != 0)
    343342          inputSystem_->destroyInputObject(joySticks_[i]);
    344343
    345344      joySticks_.clear();
     345      joySticksSize_ = 0;
    346346      activeJoyStickHandlers_.clear();
    347347      joyStickButtonsDown_.clear();
     
    372372        activeKeyHandlers_.clear();
    373373        activeMouseHandlers_.clear();
    374         activeJoyStickHandlers_.clear();
     374        for (unsigned int i = 0; i < joySticksSize_; i++)
     375          activeJoyStickHandlers_[i].clear();
    375376
    376377        switch (stateRequest_)
     
    381382          activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
    382383          activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    383           activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
    384           for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
    385                 it != joySticks_.end(); it++)
    386             activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
     384          if (getMouseHandler("SpaceShip"))
     385            activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
     386          for (unsigned int i = 0; i < joySticksSize_; i++)
     387            activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
    387388          break;
    388389
     
    393394        case IS_CONSOLE:
    394395          activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    395           for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
    396                 it != joySticks_.end(); it++)
    397             activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
     396          if (getMouseHandler("SpaceShip"))
     397            activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
     398          for (unsigned int i = 0; i < joySticksSize_; i++)
     399            activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
    398400
    399401          activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
     
    412414    if (keyboard_)
    413415      keyboard_->capture();
     416    for (unsigned  int i = 0; i < joySticksSize_; i++)
     417      joySticks_[i]->capture();
    414418
    415419
    416420    // call all the handlers for the held key events
    417     for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin();
    418           itKey != keysDown_.end(); itKey++)
    419     {
    420       OIS::KeyEvent keyArg(keyboard_, *itKey, 0);
    421       for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
    422         activeKeyHandlers_[i]->keyHeld(keyArg);
    423     }
     421    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
     422      for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     423        activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
    424424
    425425    // call all the handlers for the held mouse button events
    426     for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin();
    427           itMouseButton != mouseButtonsDown_.end(); itMouseButton++)
    428     {
    429       OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState());
    430       for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    431         activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton);
    432     }
     426    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
     427      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     428        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]);
    433429
    434430    // call all the handlers for the held joy stick button events
    435     for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();
    436           itJoyStick != joyStickButtonsDown_.end(); itJoyStick++)
    437     {
    438       OIS::JoyStick* joyStick = (*itJoyStick).first;
    439       for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin();
    440             itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++)
    441       {
    442         OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState());
    443         for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    444           activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton);
    445       }
    446     }
    447   }
    448 
     431    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     432      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
     433        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     434          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(
     435              JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]);
     436  }
    449437
    450438  // ###### Key Events ######
     
    457445  {
    458446    // check whether the key already is in the list (can happen when focus was lost)
    459     for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    460     {
    461       if (*it == e.key)
    462       {
    463         keysDown_.erase(it);
    464         break;
    465       }
    466     }
    467     keysDown_.push_back(e.key);
     447    unsigned int iKey = 0;
     448    while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key)
     449      iKey++;
     450    if (iKey == keysDown_.size())
     451      keysDown_.push_back(Key(e));
     452
     453    // update modifiers
     454    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
     455      keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
     456    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
     457      keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
     458    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
     459      keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
    468460
    469461    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
    470       activeKeyHandlers_[i]->keyPressed(e);
     462      activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_));
    471463
    472464    return true;
     
    480472  {
    481473    // remove the key from the keysDown_ list
    482     for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    483     {
    484       if (*it == e.key)
    485       {
    486         keysDown_.erase(it);
     474    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
     475    {
     476      if (keysDown_[iKey].key == (KeyCode::Enum)e.key)
     477      {
     478        keysDown_.erase(keysDown_.begin() + iKey);
    487479        break;
    488480      }
    489481    }
    490482
     483    // update modifiers
     484    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
     485      keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
     486    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
     487      keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
     488    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
     489      keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
     490
    491491    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
    492       activeKeyHandlers_[i]->keyReleased(e);
     492      activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_));
    493493
    494494    return true;
     
    504504  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
    505505  {
    506     for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    507       activeMouseHandlers_[i]->mouseMoved(e);
     506    // check for actual moved event
     507    if (e.state.X.rel != 0 || e.state.Y.rel != 0)
     508    {
     509      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     510        activeMouseHandlers_[i]->mouseMoved(e.state);
     511    }
     512
     513    // check for mouse scrolled event
     514    if (e.state.Z.rel != 0)
     515    {
     516      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     517        activeMouseHandlers_[i]->mouseScrolled(e.state);
     518    }
    508519
    509520    return true;
     
    518529  {
    519530    // check whether the button already is in the list (can happen when focus was lost)
    520     for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
    521     {
    522       if (*it == id)
    523       {
    524         mouseButtonsDown_.erase(it);
    525         break;
    526       }
    527     }
    528     mouseButtonsDown_.push_back(id);
     531    unsigned int iButton = 0;
     532    while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id)
     533      iButton++;
     534    if (iButton == mouseButtonsDown_.size())
     535      mouseButtonsDown_.push_back((MouseButton::Enum)id);
    529536
    530537    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    531       activeMouseHandlers_[i]->mousePressed(e, id);
     538      activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id);
    532539
    533540    return true;
     
    542549  {
    543550    // remove the button from the keysDown_ list
    544     for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
    545     {
    546       if (*it == id)
    547       {
    548         mouseButtonsDown_.erase(it);
     551    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
     552    {
     553      if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id)
     554      {
     555        mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
    549556        break;
    550557      }
     
    552559
    553560    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    554       activeMouseHandlers_[i]->mouseReleased(e, id);
     561      activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id);
    555562
    556563    return true;
     
    562569  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
    563570  {
     571    // use the device to identify which one called the method
    564572    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     573    unsigned int iJoyStick = 0;
     574    while (joySticks_[iJoyStick] != joyStick)
     575      iJoyStick++;
    565576
    566577    // check whether the button already is in the list (can happen when focus was lost)
    567     std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
    568     for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
    569     {
    570       if (*it == button)
    571       {
    572         buttonsDownList.erase(it);
     578    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
     579    unsigned int iButton = 0;
     580    while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
     581      iButton++;
     582    if (iButton == buttonsDown.size())
     583      buttonsDown.push_back(button);
     584
     585    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     586      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button);
     587
     588    return true;
     589  }
     590
     591  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
     592  {
     593    // use the device to identify which one called the method
     594    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     595    unsigned int iJoyStick = 0;
     596    while (joySticks_[iJoyStick] != joyStick)
     597      iJoyStick++;
     598
     599    // remove the button from the joyStickButtonsDown_ list
     600    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
     601    for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
     602    {
     603      if (buttonsDown[iButton] == button)
     604      {
     605        buttonsDown.erase(buttonsDown.begin() + iButton);
    573606        break;
    574607      }
    575608    }
    576     joyStickButtonsDown_[joyStick].push_back(button);
    577 
    578     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    579       activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button);
    580 
    581     return true;
    582   }
    583 
    584   bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
    585   {
     609
     610    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     611      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button);
     612
     613    return true;
     614  }
     615
     616  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
     617  {
     618    // use the device to identify which one called the method
    586619    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    587 
    588     // remove the button from the joyStickButtonsDown_ list
    589     std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
    590     for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
    591     {
    592       if (*it == button)
    593       {
    594         buttonsDownList.erase(it);
    595         break;
    596       }
    597     }
    598 
    599     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    600       activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button);
    601 
    602     return true;
    603   }
    604 
    605   bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    606   {
     620    unsigned int iJoyStick = 0;
     621    while (joySticks_[iJoyStick] != joyStick)
     622      iJoyStick++;
     623
     624    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     625      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis);
     626
     627    return true;
     628  }
     629
     630  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
     631  {
     632    // use the device to identify which one called the method
    607633    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    608     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    609       activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis);
    610 
    611     return true;
    612   }
    613 
    614   bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    615   {
     634    unsigned int iJoyStick = 0;
     635    while (joySticks_[iJoyStick] != joyStick)
     636      iJoyStick++;
     637
     638    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     639      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id);
     640
     641    return true;
     642  }
     643
     644  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
     645  {
     646    // use the device to identify which one called the method
    616647    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    617     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    618       activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id);
    619 
    620     return true;
    621   }
    622 
    623   bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
    624   {
     648    unsigned int iJoyStick = 0;
     649    while (joySticks_[iJoyStick] != joyStick)
     650      iJoyStick++;
     651
     652    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     653      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id);
     654
     655    return true;
     656  }
     657
     658  bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
     659  {
     660    // use the device to identify which one called the method
    625661    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    626     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    627       activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id);
    628 
    629     return true;
    630   }
    631 
    632   bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    633   {
    634     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    635     for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
    636       activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id);
     662    unsigned int iJoyStick = 0;
     663    while (joySticks_[iJoyStick] != joyStick)
     664      iJoyStick++;
     665
     666    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     667      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id);
    637668
    638669    return true;
     
    645676  // ################################
    646677
    647   bool InputManager::initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
    648     const bool createKeyboard, const bool createMouse, const bool createJoySticks)
     678  bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
     679    bool createKeyboard, bool createMouse, bool createJoySticks)
    649680  {
    650681    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
     
    685716  int InputManager::numberOfJoySticks()
    686717  {
    687     return _getSingleton().joySticks_.size();
     718    return _getSingleton().joySticksSize_;
     719  }
     720
     721  bool InputManager::isKeyDown(KeyCode::Enum key)
     722  {
     723    if (_getSingleton().keyboard_)
     724      return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key);
     725    else
     726      return false;
     727  }
     728
     729  bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
     730  {
     731    if (_getSingleton().keyboard_)
     732      return isModifierDown(modifier);
     733    else
     734      return false;
     735  }
     736
     737  const MouseState InputManager::getMouseState()
     738  {
     739    if (_getSingleton().mouse_)
     740      return _getSingleton().mouse_->getMouseState();
     741    else
     742      return MouseState();
     743  }
     744
     745  const JoyStickState InputManager::getJoyStickState(unsigned int ID)
     746  {
     747    if (ID < _getSingleton().joySticksSize_)
     748      return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID);
     749    else
     750      return JoyStickState();
    688751  }
    689752
     
    757820  bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name)
    758821  {
     822    if (!handler)
     823      return false;
    759824    if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end())
    760825    {
     
    883948  bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)
    884949  {
     950    if (!handler)
     951      return false;
    885952    if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())
    886953    {
     
    10101077  bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)
    10111078  {
     1079    if (!handler)
     1080      return false;
    10121081    if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())
    10131082    {
     
    10611130    @return False if name or id was not found, true otherwise.
    10621131  */
    1063   bool InputManager::enableJoyStickHandler(const std::string& name, const int ID)
     1132  bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)
    10641133  {
    10651134    // get handler pointer from the map with all stored handlers
     
    10691138
    10701139    // check for existence of the ID
    1071     if ((unsigned int)ID >= _getSingleton().joySticks_.size())
    1072       return false;
    1073     OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1140    if (ID >= _getSingleton().joySticksSize_)
     1141      return false;
    10741142
    10751143    // see whether the handler already is in the list
    1076     for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
    1077           it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1144    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
     1145          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
    10781146    {
    10791147      if ((*it) == (*handlerIt).second)
     
    10831151      }
    10841152    }
    1085     _getSingleton().activeJoyStickHandlers_[joyStick].push_back((*handlerIt).second);
     1153    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
    10861154    _getSingleton().stateRequest_ = IS_CUSTOM;
    10871155    return true;
     
    10931161    @return False if name or id was not found, true otherwise.
    10941162  */
    1095   bool InputManager::disableJoyStickHandler(const std::string &name, int ID)
     1163  bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)
    10961164  {
    10971165    // get handler pointer from the map with all stored handlers
     
    11011169
    11021170    // check for existence of the ID
    1103     if ((unsigned int)ID >= _getSingleton().joySticks_.size())
    1104       return false;
    1105     OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1171    if (ID >= _getSingleton().joySticksSize_)
     1172      return false;
    11061173
    11071174    // look for the handler in the list
    1108     for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
    1109           it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1175    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
     1176          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
    11101177    {
    11111178      if ((*it) == (*handlerIt).second)
    11121179      {
    1113         _getSingleton().activeJoyStickHandlers_[joyStick].erase(it);
     1180        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
    11141181        _getSingleton().stateRequest_ = IS_CUSTOM;
    11151182        return true;
     
    11241191    @return False if key handler is not active or doesn't exist, true otherwise.
    11251192  */
    1126   bool InputManager::isJoyStickHandlerActive(const std::string& name, const int ID)
     1193  bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)
    11271194  {
    11281195    // get handler pointer from the map with all stored handlers
     
    11321199
    11331200    // check for existence of the ID
    1134     if ((unsigned int)ID >= _getSingleton().joySticks_.size())
    1135       return false;
    1136     OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1201    if (ID >= _getSingleton().joySticksSize_)
     1202      return false;
    11371203
    11381204    // see whether the handler already is in the list
    1139     for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
    1140           it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1205    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
     1206          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
    11411207    {
    11421208      if ((*it) == (*handlerIt).second)
Note: See TracChangeset for help on using the changeset viewer.