Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1215


Ignore:
Timestamp:
May 2, 2008, 9:31:20 PM (17 years ago)
Author:
rgrieder
Message:
  • SpaceShip is now a default listener for mouse input. still a hack..
  • several changes in InputManager.cc regarding joy sticks
  • Key bindings work, but not very advanced
Location:
code/branches/input
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/bin/keybindings.ini

    r1213 r1215  
    33R_UNASSIGNED=
    44H_UNASSIGNED=
    5 P_ESCAPE=exit
     5P_ESCAPE="exit"
    66R_ESCAPE=
    77H_ESCAPE=
  • code/branches/input/src/core/InputHandler.cc

    r1213 r1215  
    267267        switch (j)
    268268        {
     269          // note: the first element in the struct is the string, so the following pointer
     270          //       arithmetic works.
    269271          case 0:
    270             cont->getValue(bindingsKeyPress_ + i);
     272            cont->getValue(&bindingsKeyPress_[i].commandStr);
    271273            break;
    272274          case 1:
     
    337339    for (int i = 0; i < numberOfKeys_s; i++)
    338340    {
    339       bindingsKeyPress_  [i] = "";
    340       bindingsKeyRelease_[i] = "";
    341       bindingsKeyHold_   [i] = "";
     341      bindingsKeyPress_  [i].commandStr = "";
     342      bindingsKeyRelease_[i].commandStr = "";
     343      bindingsKeyHold_   [i].commandStr = "";
    342344    }
    343345    for (int i = 0; i < numberOfMouseButtons_s; i++)
     
    366368    setConfigValues();
    367369
     370    // evaluate the key bindings
     371    // TODO: what if binding is invalid?
     372    //for (int i = 0; i < numberOfKeys_s; i++)
     373    //{
     374    //  if (bindingsKeyPress_[i].commandStr != "")
     375    //  {
     376    //    bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);
     377    //    bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();
     378    //  }
     379    //}
     380
    368381    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
     382    return true;
     383  }
     384
     385  bool KeyBinder::executeBinding(KeyBinding& binding)
     386  {
     387    if (binding.commandStr != "")
     388    {
     389      //if (binding.commandStr != binding.evaluation.getCommandString())
     390      //{
     391      //  // key binding has changed, reevaluate the command string.
     392      //  binding.evaluation = CommandExecutor::evaluate(binding.commandStr);
     393      //  binding.commandStr = binding.evaluation.getCommandString();
     394      //}
     395      COUT(3) << "Executing command: " << binding.commandStr << std::endl;
     396      CommandExecutor::execute(binding.commandStr);
     397    }
     398
    369399    return true;
    370400  }
     
    379409    COUT(3) << "Key: " << e.key << std::endl;
    380410    // find the appropriate key binding
    381     std::string cmdStr = bindingsKeyPress_[int(e.key)];
    382     if (cmdStr != "")
    383     {
    384       CommandExecutor::execute(cmdStr);
    385       COUT(3) << "Executing command: " << cmdStr << std::endl;
    386     }
    387    
     411    executeBinding(bindingsKeyPress_[int(e.key)]);
     412     
    388413    return true;
    389414  }
     
    396421  {
    397422    // find the appropriate key binding
    398     std::string cmdStr = bindingsKeyRelease_[int(e.key)];
    399     if (cmdStr != "")
    400     {
    401       CommandExecutor::execute(cmdStr);
    402       COUT(3) << "Executing command: " << cmdStr << std::endl;
    403     }
     423    executeBinding(bindingsKeyRelease_[int(e.key)]);
    404424
    405425    return true;
     
    413433  {
    414434    // find the appropriate key binding
    415     std::string cmdStr = bindingsKeyHold_[int(e.key)];
    416     if (cmdStr != "")
    417     {
    418       CommandExecutor::execute(cmdStr);
    419       COUT(3) << "Executing command: " << cmdStr << std::endl;
    420     }
     435    executeBinding(bindingsKeyHold_[int(e.key)]);
    421436
    422437    return true;
     
    486501  }
    487502
    488   bool KeyBinder::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     503  bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    489504  {
    490505    // find the appropriate key binding
     
    499514  }
    500515
    501   bool KeyBinder::buttonReleased(const OIS::JoyStickEvent &arg, int button)
     516  bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    502517  {
    503518    // find the appropriate key binding
     
    512527  }
    513528
    514   bool KeyBinder::buttonHeld(const OIS::JoyStickEvent &arg, int button)
     529  bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    515530  {
    516531    // find the appropriate key binding
     
    525540  }
    526541
    527   bool KeyBinder::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    528   {
    529     return true;
    530   }
    531 
    532   bool KeyBinder::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    533   {
    534     return true;
    535   }
    536 
    537   bool KeyBinder::povMoved(const OIS::JoyStickEvent &arg, int id)
     542  bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis)
     543  {
     544    return true;
     545  }
     546
     547  bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     548  {
     549    return true;
     550  }
     551
     552  bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     553  {
     554    return true;
     555  }
     556
     557  bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
    538558  {
    539559    return true;
  • code/branches/input/src/core/InputHandler.h

    r1213 r1215  
    4040#include "ois/OIS.h"
    4141#include "OrxonoxClass.h"
     42#include "CommandExecutor.h"
    4243
    4344namespace orxonox
     
    6061  {
    6162  public:
     63    virtual ~KeyHandler() { }
    6264    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
    6365  };
     
    6971  {
    7072  public:
     73    virtual ~MouseHandler() { }
    7174    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
    7275  };
     
    7578    @brief Interface class used for joy stick input listeners.
    7679  */
    77   class _CoreExport JoyStickHandler : public OIS::JoyStickListener
    78   {
    79   public:
    80     virtual bool buttonHeld(const OIS::JoyStickEvent &arg, int button) = 0;
     80  class _CoreExport JoyStickHandler
     81  {
     82  public:
     83    virtual ~JoyStickHandler() { }
     84                virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     85                virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     86    virtual bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     87                virtual bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis)   = 0;
     88                virtual bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     89                virtual bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     90                virtual bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     91  };
     92
     93  struct _CoreExport KeyBinding
     94  {
     95    std::string commandStr;
     96    CommandEvaluation evaluation;
    8197  };
    8298 
     
    100116
    101117  private: // functions
     118
     119    bool executeBinding(KeyBinding &binding);
     120
    102121                bool keyPressed   (const OIS::KeyEvent   &arg);
    103122                bool keyReleased  (const OIS::KeyEvent   &arg);
     
    109128    bool mouseMoved   (const OIS::MouseEvent &arg);
    110129
    111                 bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
    112                 bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
    113                 bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
    114                 bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
    115                 bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    116                 bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     130                bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     131                bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);
     132                bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     133                bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis);
     134                bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     135                bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     136                bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int id);
    117137
    118138  private: // variables
     
    121141    static const int numberOfKeys_s = 0xEE;
    122142    //! Array of input events for every pressed key
    123     std::string bindingsKeyPress_  [numberOfKeys_s];
     143    KeyBinding bindingsKeyPress_  [numberOfKeys_s];
    124144    //! Array of input events for every released key
    125     std::string bindingsKeyRelease_[numberOfKeys_s];
     145    KeyBinding bindingsKeyRelease_[numberOfKeys_s];
    126146    //! Array of input events for every held key
    127     std::string bindingsKeyHold_   [numberOfKeys_s];
     147    KeyBinding bindingsKeyHold_   [numberOfKeys_s];
    128148    //! Names of the keys as strings
    129149    std::string keyNames_[numberOfKeys_s];
  • code/branches/input/src/core/InputManager.cc

    r1213 r1215  
    5555  {
    5656    RegisterObject(InputManager);
     57
     58    this->joySticks_.reserve(5);
     59    //this->activeJoyStickHandlers_.reserve(10);
     60    this->activeKeyHandlers_.reserve(10);
     61    this->activeMouseHandlers_.reserve(10);
    5762  }
    5863
     
    242247        {
    243248          OIS::JoyStick* stig = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true));
    244           joySticks_[stig->getID()] = stig;
     249          joySticks_.push_back(stig);
    245250          // register our listener in OIS.
    246251          stig->setEventCallback(this);
     
    278283        delete keyHandlers_["keybinder"];
    279284
    280       activeKeyHandlers_.clear();
    281       activeMouseHandlers_.clear();
    282       activeJoyStickHandlers_.clear();
    283285      keyHandlers_.clear();
    284286      mouseHandlers_.clear();
    285287      joyStickHandlers_.clear();
    286 
    287       keysDown_.clear();
    288       mouseButtonsDown_.clear();
    289       joyStickButtonsDown_.clear();
    290288
    291289      _destroyKeyboard();
     
    314312      inputSystem_->destroyInputObject(keyboard_);
    315313    keyboard_ = 0;
     314    activeKeyHandlers_.clear();
     315    keysDown_.clear();
    316316    CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl;
    317317  }
     
    326326      inputSystem_->destroyInputObject(mouse_);
    327327    mouse_ = 0;
     328    activeMouseHandlers_.clear();
     329    mouseButtonsDown_.clear();
    328330    CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl;
    329331  }
     
    337339    {
    338340      // note: inputSystem_ can never be 0, or else the code is mistaken
    339       for (std::map<int, OIS::JoyStick*>::iterator itstick = joySticks_.begin(); itstick != joySticks_.end(); itstick++)
    340       {
    341         if ((*itstick).second != 0)
    342           inputSystem_->destroyInputObject((*itstick).second);
    343       }
     341      for (unsigned int i = 0; i < joySticks_.size(); i++)
     342        if (joySticks_[i] != 0)
     343          inputSystem_->destroyInputObject(joySticks_[i]);
     344
    344345      joySticks_.clear();
     346      activeJoyStickHandlers_.clear();
     347      joyStickButtonsDown_.clear();
    345348    }
    346349    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
     
    375378        case IS_NORMAL:
    376379          // normal play mode
    377           if (keyHandlers_.find("keybinder") != keyHandlers_.end())
    378             activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
    379           if (mouseHandlers_.find("keybinder") != mouseHandlers_.end())
    380             activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    381           if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end())
    382           {
    383             for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin();
    384                   it != joySticks_.end(); it++)
    385               activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]);
    386           }
     380          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
     381          activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
     382          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"]);
    387387          break;
    388388
     
    392392
    393393        case IS_CONSOLE:
    394           if (mouseHandlers_.find("keybinder") != mouseHandlers_.end())
    395             activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    396           if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end())
    397           {
    398             for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin();
    399                   it != joySticks_.end(); it++)
    400               activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]);
    401           }
    402 
    403           if (keyHandlers_.find("buffer") != keyHandlers_.end())
    404             activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
    405           else
    406           {
    407             // someone fiddled with the InputBuffer
    408             CCOUT(2) << "Error: Cannot redirect input to console, InputBuffer instance missing." << std::endl;
    409             if (keyHandlers_.find("keybinder") != keyHandlers_.end())
    410               activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
    411             else
    412               // this is bad
    413               CCOUT(2) << "Error: Cannot reactivate key binder: not found!" << std::endl;
    414           }
     394          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"]);
     398
     399          activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
    415400          break;
    416401
     
    434419    {
    435420      OIS::KeyEvent keyArg(keyboard_, *itKey, 0);
    436       for (std::list<KeyHandler*>::const_iterator itKeyHandler = activeKeyHandlers_.begin();
    437             itKeyHandler != activeKeyHandlers_.end(); itKeyHandler++)
    438       {
    439         (*itKeyHandler)->keyHeld(keyArg);
    440       }
     421      for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     422        activeKeyHandlers_[i]->keyHeld(keyArg);
    441423    }
    442424
     
    446428    {
    447429      OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState());
    448       for (std::list<MouseHandler*>::const_iterator itMouseHandler = activeMouseHandlers_.begin();
    449             itMouseHandler != activeMouseHandlers_.end(); itMouseHandler++)
    450       {
    451         (*itMouseHandler)->mouseHeld(mouseButtonArg, *itMouseButton);
    452       }
     430      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     431        activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton);
    453432    }
    454433
    455434    // call all the handlers for the held joy stick button events
    456     for (std::map<int, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();
     435    for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();
    457436          itJoyStick != joyStickButtonsDown_.end(); itJoyStick++)
    458437    {
    459       int id = (*itJoyStick).first;
     438      OIS::JoyStick* joyStick = (*itJoyStick).first;
    460439      for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin();
    461440            itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++)
    462441      {
    463         OIS::JoyStickEvent joyStickButtonArg(joySticks_[id], joySticks_[id]->getJoyStickState());
    464         for (std::list<JoyStickHandler*>::const_iterator itJoyStickHandler = activeJoyStickHandlers_[id].begin();
    465               itJoyStickHandler != activeJoyStickHandlers_[id].end(); itJoyStickHandler++)
    466         {
    467           (*itJoyStickHandler)->buttonHeld(joyStickButtonArg, *itJoyStickButton);
    468         }
    469       }
    470     }
    471   }
    472 
     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
     449
     450  // ###### Key Events ######
    473451
    474452  /**
     
    478456  bool InputManager::keyPressed(const OIS::KeyEvent &e)
    479457  {
    480     // check whether the key is already in the list (can happen when focus was lost)
     458    // check whether the key already is in the list (can happen when focus was lost)
    481459    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    482460    {
     
    489467    keysDown_.push_back(e.key);
    490468
    491     for (std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++)
    492       (*it)->keyPressed(e);
     469    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     470      activeKeyHandlers_[i]->keyPressed(e);
    493471
    494472    return true;
     
    511489    }
    512490
    513     for (std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++)
    514       (*it)->keyReleased(e);
    515 
    516     return true;
    517   }
     491    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     492      activeKeyHandlers_[i]->keyReleased(e);
     493
     494    return true;
     495  }
     496
     497
     498  // ###### Mouse Events ######
    518499
    519500  /**
     
    523504  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
    524505  {
    525     for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++)
    526       (*it)->mouseMoved(e);
     506    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     507      activeMouseHandlers_[i]->mouseMoved(e);
    527508
    528509    return true;
     
    536517  bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    537518  {
    538     // check whether the button is already in the list (can happen when focus was lost)
     519    // check whether the button already is in the list (can happen when focus was lost)
    539520    for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
    540521    {
     
    547528    mouseButtonsDown_.push_back(id);
    548529
    549     for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++)
    550       (*it)->mousePressed(e, id);
     530    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     531      activeMouseHandlers_[i]->mousePressed(e, id);
    551532
    552533    return true;
     
    570551    }
    571552
    572     for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++)
    573       (*it)->mouseReleased(e, id);
    574 
    575     return true;
    576   }
     553    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     554      activeMouseHandlers_[i]->mouseReleased(e, id);
     555
     556    return true;
     557  }
     558
     559
     560  // ###### Joy Stick Events ######
    577561
    578562  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
    579563  {
    580     int devID = arg.device->getID();
    581 
    582     // check whether the button is already in the list (can happen when focus was lost)
    583     std::list<int>& buttonsDownList = joyStickButtonsDown_[devID];
     564    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     565
     566    // check whether the button already is in the list (can happen when focus was lost)
     567    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
    584568    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
    585569    {
     
    590574      }
    591575    }
    592     joyStickButtonsDown_[devID].push_back(button);
    593 
    594     std::list<JoyStickHandler*>::iterator end = activeJoyStickHandlers_[devID].end();
    595     for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++)
    596       (*it)->buttonPressed(arg, button);
     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);
    597580
    598581    return true;
     
    601584  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
    602585  {
    603     int devID = arg.device->getID();
     586    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    604587
    605588    // remove the button from the joyStickButtonsDown_ list
    606     std::list<int>& buttonsDownList = joyStickButtonsDown_[devID];
     589    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
    607590    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
    608591    {
     
    614597    }
    615598
    616     std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end();
    617     for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++)
    618       (*it)->buttonReleased(arg, button);
     599    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     600      activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button);
    619601
    620602    return true;
     
    623605  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    624606  {
    625     int devID = arg.device->getID();
    626     std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end();
    627     for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++)
    628       (*it)->axisMoved(arg, axis);
     607    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);
    629610
    630611    return true;
     
    633614  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    634615  {
    635     int devID = arg.device->getID();
    636     std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end();
    637     for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++)
    638       (*it)->sliderMoved(arg, id);
     616    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);
    639619
    640620    return true;
     
    643623  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
    644624  {
    645     int devID = arg.device->getID();
    646     std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end();
    647     for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++)
    648       (*it)->povMoved(arg, id);
     625    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);
    649637
    650638    return true;
     
    679667  }
    680668
    681   bool InputManager::isKeyboardInitialised()
    682   {
    683     return (_getSingleton().keyboard_ != 0);
    684   }
    685 
    686   bool InputManager::isMouseInitialised()
    687   {
    688     return (_getSingleton().mouse_ != 0);
    689   }
    690 
    691   bool InputManager::areJoySticksInitialised()
    692   {
    693     return (_getSingleton().joySticks_.size() > 0);
     669  int InputManager::numberOfKeyboards()
     670  {
     671    if (_getSingleton().keyboard_ != 0)
     672      return 1;
     673    else
     674      return 0;
     675  }
     676
     677  int InputManager::numberOfMice()
     678  {
     679    if (_getSingleton().mouse_ != 0)
     680      return 1;
     681    else
     682      return 0;
     683  }
     684
     685  int InputManager::numberOfJoySticks()
     686  {
     687    return _getSingleton().joySticks_.size();
    694688  }
    695689
     
    817811    if (mapIt == _getSingleton().keyHandlers_.end())
    818812      return false;
    819     // see whether the handler is already in the list
    820     for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     813    // see whether the handler already is in the list
     814    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
    821815          it != _getSingleton().activeKeyHandlers_.end(); it++)
    822816    {
     
    844838      return false;
    845839    // look for the handler in the list
    846     for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     840    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
    847841          it != _getSingleton().activeKeyHandlers_.end(); it++)
    848842    {
     
    869863    if (mapIt == _getSingleton().keyHandlers_.end())
    870864      return false;
    871     // see whether the handler is already in the list
    872     for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     865    // see whether the handler already is in the list
     866    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
    873867          it != _getSingleton().activeKeyHandlers_.end(); it++)
    874868    {
     
    943937    if (mapIt == _getSingleton().mouseHandlers_.end())
    944938      return false;
    945     // see whether the handler is already in the list
    946     for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     939    // see whether the handler already is in the list
     940    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
    947941          it != _getSingleton().activeMouseHandlers_.end(); it++)
    948942    {
     
    970964      return false;
    971965    // look for the handler in the list
    972     for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     966    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
    973967          it != _getSingleton().activeMouseHandlers_.end(); it++)
    974968    {
     
    995989    if (mapIt == _getSingleton().mouseHandlers_.end())
    996990      return false;
    997     // see whether the handler is already in the list
    998     for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     991    // see whether the handler already is in the list
     992    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
    999993          it != _getSingleton().activeMouseHandlers_.end(); it++)
    1000994    {
     
    10321026  bool InputManager::removeJoyStickHandler(const std::string &name)
    10331027  {
    1034     for (std::map<int, OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin(); itstick != _getSingleton().joySticks_.end(); itstick++)
    1035       disableJoyStickHandler(name, (*itstick).first);
     1028    for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();
     1029          itstick != _getSingleton().joySticks_.end(); itstick++)
     1030      disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());
    10361031
    10371032    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
     
    10661061    @return False if name or id was not found, true otherwise.
    10671062  */
    1068   bool InputManager::enableJoyStickHandler(const std::string& name, const int id)
    1069   {
    1070     // get pointer from the map with all stored handlers
     1063  bool InputManager::enableJoyStickHandler(const std::string& name, const int ID)
     1064  {
     1065    // get handler pointer from the map with all stored handlers
    10711066    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
    10721067    if (handlerIt == _getSingleton().joyStickHandlers_.end())
    10731068      return false;
    10741069
    1075     // check for existance of the ID
    1076     std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);
    1077     if (joyStickIt == _getSingleton().joySticks_.end())
    1078       return false;
    1079 
    1080     // see whether the handler is already in the list
    1081     for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();
    1082           it != _getSingleton().activeJoyStickHandlers_[id].end(); it++)
     1070    // check for existence of the ID
     1071    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1072      return false;
     1073    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1074
     1075    // 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++)
    10831078    {
    10841079      if ((*it) == (*handlerIt).second)
     
    10881083      }
    10891084    }
    1090     _getSingleton().activeJoyStickHandlers_[id].push_back((*handlerIt).second);
     1085    _getSingleton().activeJoyStickHandlers_[joyStick].push_back((*handlerIt).second);
    10911086    _getSingleton().stateRequest_ = IS_CUSTOM;
    10921087    return true;
     
    10981093    @return False if name or id was not found, true otherwise.
    10991094  */
    1100   bool InputManager::disableJoyStickHandler(const std::string &name, int id)
    1101   {
    1102     // get pointer from the map with all stored handlers
     1095  bool InputManager::disableJoyStickHandler(const std::string &name, int ID)
     1096  {
     1097    // get handler pointer from the map with all stored handlers
    11031098    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
    11041099    if (handlerIt == _getSingleton().joyStickHandlers_.end())
    11051100      return false;
    11061101
    1107     // check for existance of the ID
    1108     std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);
    1109     if (joyStickIt == _getSingleton().joySticks_.end())
    1110       return false;
     1102    // check for existence of the ID
     1103    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1104      return false;
     1105    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
    11111106
    11121107    // look for the handler in the list
    1113     for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();
    1114           it != _getSingleton().activeJoyStickHandlers_[id].end(); it++)
     1108    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
     1109          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
    11151110    {
    11161111      if ((*it) == (*handlerIt).second)
    11171112      {
    1118         _getSingleton().activeJoyStickHandlers_[id].erase(it);
     1113        _getSingleton().activeJoyStickHandlers_[joyStick].erase(it);
    11191114        _getSingleton().stateRequest_ = IS_CUSTOM;
    11201115        return true;
    11211116      }
    11221117    }
    1123     _getSingleton().stateRequest_ = IS_CUSTOM;
    11241118    return true;
    11251119  }
     
    11301124    @return False if key handler is not active or doesn't exist, true otherwise.
    11311125  */
    1132   bool InputManager::isJoyStickHandlerActive(const std::string& name, const int id)
    1133   {
    1134     // get pointer from the map with all stored handlers
     1126  bool InputManager::isJoyStickHandlerActive(const std::string& name, const int ID)
     1127  {
     1128    // get handler pointer from the map with all stored handlers
    11351129    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
    11361130    if (handlerIt == _getSingleton().joyStickHandlers_.end())
    11371131      return false;
    11381132
    1139     // check for existance of the ID
    1140     std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);
    1141     if (joyStickIt == _getSingleton().joySticks_.end())
    1142       return false;
    1143 
    1144     // see whether the handler is already in the list
    1145     for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();
    1146           it != _getSingleton().activeJoyStickHandlers_[id].end(); it++)
     1133    // check for existence of the ID
     1134    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1135      return false;
     1136    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1137
     1138    // 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++)
    11471141    {
    11481142      if ((*it) == (*handlerIt).second)
  • code/branches/input/src/core/InputManager.h

    r1204 r1215  
    7777    static bool initialiseMouse();
    7878    static bool initialiseJoySticks();
    79     static bool isKeyboardInitialised();
    80     static bool isMouseInitialised();
    81     static bool areJoySticksInitialised();
     79    static int  numberOfKeyboards();
     80    static int  numberOfMice();
     81    static int  numberOfJoySticks();
    8282
    8383    static void destroy();
     
    148148                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    149149                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     150                bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
    150151
    151152    static InputManager& _getSingleton();
     
    156157    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
    157158    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
    158     std::map<int, OIS::JoyStick*>               joySticks_;   //!< OIS joy sticks
     159    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
    159160
    160161    InputState state_;
     
    165166    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
    166167
    167     std::list<KeyHandler*>                      activeKeyHandlers_;
    168     std::list<MouseHandler*>                    activeMouseHandlers_;
    169     std::map<int, std::list<JoyStickHandler*> > activeJoyStickHandlers_;
     168    std::vector<KeyHandler*>                    activeKeyHandlers_;
     169    std::vector<MouseHandler*>                  activeMouseHandlers_;
     170    std::map< OIS::JoyStick*, std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
    170171
    171172    std::list<OIS::KeyCode>                     keysDown_;
    172173    std::list<OIS::MouseButtonID>               mouseButtonsDown_;
    173     std::map< int, std::list<int> >             joyStickButtonsDown_;
     174    std::map< OIS::JoyStick*, std::list<int> >  joyStickButtonsDown_;
    174175
    175176  };
  • code/branches/input/src/orxonox/Orxonox.cc

    r1213 r1215  
    398398          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    399399      abortImmediateForce();
    400     InputManager::setInputState(InputManager::IS_CUSTOM);
    401     InputManager::enableKeyHandler("keybinder");
    402     InputManager::enableMouseHandler("keybinder");
    403     InputManager::enableJoyStickHandler("keybinder", 0);
     400    InputManager::setInputState(InputManager::IS_NORMAL);
    404401  }
    405402
  • code/branches/input/src/orxonox/objects/SpaceShip.cc

    r1213 r1215  
    431431        {
    432432          InputManager::addMouseHandler(this, "SpaceShip");
    433           InputManager::enableMouseHandler("SpaceShip");
    434433          setMouseEventCallback_ = true;
    435434        }
Note: See TracChangeset for help on using the changeset viewer.