Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/InputManager.cc @ 1383

Last change on this file since 1383 was 1349, checked in by rgrieder, 17 years ago
  • merged input branch back to trunk
File size: 40.5 KB
RevLine 
[918]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[918]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
[934]25 *      ...
[918]26 *
27 */
[973]28
[918]29/**
[1219]30  @file
31  @brief Implementation of the InputManager that captures all the input from OIS
[1293]32         and redirects it to handlers.
[918]33 */
34
[1062]35#include "InputManager.h"
36#include "CoreIncludes.h"
37#include "Debug.h"
[1219]38#include "InputBuffer.h"
[1022]39#include "InputHandler.h"
[918]40
41namespace orxonox
42{
[1219]43  // ###############################
44  // ###    Internal Methods     ###
45  // ###############################
46  // ###############################
[1084]47
[919]48  /**
[1219]49    @brief Constructor only sets member fields to initial zero values
50           and registers the class in the class hierarchy.
[919]51  */
[973]52  InputManager::InputManager() :
[1034]53      inputSystem_(0), keyboard_(0), mouse_(0),
[1293]54      joySticksSize_(0),
55      state_(IS_UNINIT), stateRequest_(IS_UNINIT),
56      keyboardModifiers_(0)
[918]57  {
[1089]58    RegisterObject(InputManager);
[929]59  }
60
61  /**
[973]62    @brief The one instance of the InputManager is stored in this function.
[1035]63    @return A reference to the only instance of the InputManager
[919]64  */
[1219]65  InputManager& InputManager::_getSingleton()
[919]66  {
[1035]67    static InputManager theOnlyInstance;
68    return theOnlyInstance;
[919]69  }
70
71  /**
[1219]72    @brief Destructor only called at the end of the program, after main.
73  */
74  InputManager::~InputManager()
75  {
76    _destroy();
77  }
78
79  /**
80    @brief Creates the OIS::InputMananger, the keyboard, the mouse and
81           the joysticks and assigns the key bindings.
[919]82    @param windowHnd The window handle of the render window
83    @param windowWidth The width of the render window
84    @param windowHeight The height of the render window
85  */
[1293]86  bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight,
87        bool createKeyboard, bool createMouse, bool createJoySticks)
[919]88  {
[1219]89    if (state_ == IS_UNINIT)
[918]90    {
[1293]91      CCOUT(3) << "Initialising Input System..." << std::endl;
[1219]92      CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
93
[918]94      OIS::ParamList paramList;
95      std::ostringstream windowHndStr;
96
97      // Fill parameter list
98      windowHndStr << (unsigned int)windowHnd;
99      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
[1349]100      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
101      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
[1219]102//#if defined OIS_LINUX_PLATFORM
103//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
104//#endif
[928]105
[934]106      try
[918]107      {
[934]108        inputSystem_ = OIS::InputManager::createInputSystem(paramList);
[1219]109        CCOUT(ORX_DEBUG) << "Created OIS input system" << std::endl;
[918]110      }
[934]111      catch (OIS::Exception ex)
112      {
[1219]113        CCOUT(ORX_ERROR) << "Error: Failed creating an OIS input system."
114            << "OIS message: \"" << ex.eText << "\"" << std::endl;
115        inputSystem_ = 0;
[934]116        return false;
117      }
[1219]118
119      if (createKeyboard)
120        _initialiseKeyboard();
121
122      if (createMouse)
123        _initialiseMouse();
124
125      if (createJoySticks)
126        _initialiseJoySticks();
127
128      // Set mouse/joystick region
[1349]129      if (mouse_)
130      {
131        //// hack the mouse position
132        //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;
133        //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;
134        setWindowExtents(windowWidth, windowHeight);
135      }
[1219]136
137      state_ = IS_NONE;
138      CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
[918]139    }
[1219]140    else
141    {
142      CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
143    }
[922]144
[1219]145    // InputManager holds the input buffer --> create one and add it.
146    addKeyHandler(new InputBuffer(), "buffer");
[1022]147
[1219]148    KeyBinder* binder = new KeyBinder();
149    binder->loadBindings();
150    addKeyHandler(binder, "keybinder");
151    addMouseHandler(binder, "keybinder");
[1293]152    addJoyStickHandler(binder, "keybinder");
[922]153
[1219]154    // Read all the key bindings and assign them
155    //if (!_loadBindings())
156    //  return false;
[934]157
[1219]158    CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
[934]159    return true;
[918]160  }
161
[919]162  /**
[1219]163    @brief Creates a keyboard and sets the event handler.
164    @return False if keyboard stays uninitialised, true otherwise.
[928]165  */
[1219]166  bool InputManager::_initialiseKeyboard()
[928]167  {
[1219]168    if (keyboard_ != 0)
169    {
170      CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl;
171      return true;
172    }
173    try
174    {
175      if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
176      {
177        keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true);
178        // register our listener in OIS.
179        keyboard_->setEventCallback(this);
180        // note: OIS will not detect keys that have already been down when the keyboard was created.
181        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
182        return true;
183      }
184      else
185      {
186        CCOUT(ORX_WARNING) << "Warning: No keyboard found!" << std::endl;
187        return false;
188      }
189    }
190    catch (OIS::Exception ex)
191    {
192      // TODO: Test this output regarding formatting
193      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n"
194          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
195      keyboard_ = 0;
196      return false;
197    }
198  }
[928]199
[1219]200  /**
201    @brief Creates a mouse and sets the event handler.
202    @return False if mouse stays uninitialised, true otherwise.
203  */
204  bool InputManager::_initialiseMouse()
205  {
206    if (mouse_ != 0)
207    {
208      CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl;
209      return true;
210    }
211    try
212    {
213      if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
214      {
215        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
216        // register our listener in OIS.
217        mouse_->setEventCallback(this);
218        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
219        return true;
220      }
221      else
222      {
223        CCOUT(ORX_WARNING) << "Warning: No mouse found!" << std::endl;
224        return false;
225      }
226    }
227    catch (OIS::Exception ex)
228    {
229      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n"
230          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
231      mouse_ = 0;
232      return false;
233    }
234  }
[1035]235
[1219]236  /**
237    @brief Creates all joy sticks and sets the event handler.
238    @return False joy stick stay uninitialised, true otherwise.
239  */
240  bool InputManager::_initialiseJoySticks()
241  {
[1293]242    if (joySticksSize_ > 0)
[1219]243    {
244      CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
245      return true;
246    }
247    bool success = false;
248    if (inputSystem_->getNumberOfDevices(OIS::OISJoyStick) > 0)
249    {
250      for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++)
251      {
252        try
253        {
254          OIS::JoyStick* stig = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true));
255          joySticks_.push_back(stig);
256          // register our listener in OIS.
257          stig->setEventCallback(this);
258          CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl;
259          success = true;
260        }
261        catch (OIS::Exception ex)
262        {
263          CCOUT(ORX_WARNING) << "Warning: Failed to create OIS joy number" << i << "\n"
264              << "OIS error message: \"" << ex.eText << "\"" << std::endl;
265        }
266      }
267    }
268    else
269    {
270      CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl;
271      return false;
272    }
[1293]273    joySticksSize_ = joySticks_.size();
274    activeJoyStickHandlers_.resize(joySticksSize_);
275    joyStickButtonsDown_.resize(joySticksSize_);
[1349]276    povStates_.resize(joySticksSize_);
277    sliderStates_.resize(joySticksSize_);
[1219]278    return success;
279  }
[1035]280
[1219]281  /**
282    @brief Destroys all the created input devices and sets the InputManager to construction state.
283  */
284  void InputManager::_destroy()
285  {
286    if (state_ != IS_UNINIT)
287    {
[1293]288      CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
289
[1219]290      if (keyHandlers_.find("buffer") != keyHandlers_.end())
291        delete keyHandlers_["buffer"];
292
293      if (keyHandlers_.find("keybinder") != keyHandlers_.end())
294        delete keyHandlers_["keybinder"];
295
296      keyHandlers_.clear();
297      mouseHandlers_.clear();
298      joyStickHandlers_.clear();
299
300      _destroyKeyboard();
301      _destroyMouse();
302      _destroyJoySticks();
303
304      // inputSystem_ can never be 0, or else the code is mistaken
305      OIS::InputManager::destroyInputSystem(inputSystem_);
306      inputSystem_ = 0;
307
308      state_ = IS_UNINIT;
[1293]309      CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
[1219]310    }
[928]311  }
312
313  /**
[1219]314    @brief Destroys the keyboard and sets it to 0.
315  */
316  void InputManager::_destroyKeyboard()
317  {
318    if (keyboard_)
319      // inputSystem_ can never be 0, or else the code is mistaken
320      inputSystem_->destroyInputObject(keyboard_);
321    keyboard_ = 0;
322    activeKeyHandlers_.clear();
323    keysDown_.clear();
324    CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl;
325  }
326
327  /**
328    @brief Destroys the mouse and sets it to 0.
329  */
330  void InputManager::_destroyMouse()
331  {
332    if (mouse_)
333      // inputSystem_ can never be 0, or else the code is mistaken
334      inputSystem_->destroyInputObject(mouse_);
335    mouse_ = 0;
336    activeMouseHandlers_.clear();
337    mouseButtonsDown_.clear();
338    CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl;
339  }
340
341  /**
342    @brief Destroys all the joy sticks and resizes the lists to 0.
343  */
344  void InputManager::_destroyJoySticks()
345  {
[1293]346    if (joySticksSize_ > 0)
[1219]347    {
348      // note: inputSystem_ can never be 0, or else the code is mistaken
[1293]349      for (unsigned int i = 0; i < joySticksSize_; i++)
[1219]350        if (joySticks_[i] != 0)
351          inputSystem_->destroyInputObject(joySticks_[i]);
352
353      joySticks_.clear();
[1293]354      joySticksSize_ = 0;
[1219]355      activeJoyStickHandlers_.clear();
356      joyStickButtonsDown_.clear();
357    }
358    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
359  }
360
[1349]361  void InputManager::_updateTickables()
362  {
363    // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
364    std::set<InputTickable*> tempSet;
365    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
366      tempSet.insert(activeKeyHandlers_[iHandler]);
367    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
368      tempSet.insert(activeMouseHandlers_[iHandler]);
369    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
370      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
371        tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]);
[1219]372
[1349]373    // copy the content of the set back to the actual vector
374    activeHandlers_.clear();
375    for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
376      activeHandlers_.push_back(*itHandler);
377  }
378
379
[1219]380  // #################################
381  // ### Private Interface Methods ###
382  // #################################
383  // #################################
384
385  /**
386    @brief Updates the InputManager. Tick is called by Orxonox.
[919]387    @param dt Delta time
388  */
[973]389  void InputManager::tick(float dt)
[918]390  {
[1219]391    if (state_ == IS_UNINIT)
392      return;
393
[1022]394    // reset the game if it has changed
[1219]395    if (state_ != stateRequest_)
[1022]396    {
[1219]397      if (stateRequest_ != IS_CUSTOM)
[1022]398      {
[1219]399        activeKeyHandlers_.clear();
400        activeMouseHandlers_.clear();
[1293]401        for (unsigned int i = 0; i < joySticksSize_; i++)
402          activeJoyStickHandlers_[i].clear();
[1219]403
404        switch (stateRequest_)
405        {
406        case IS_NORMAL:
407          // normal play mode
408          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
[1349]409          enableKeyHandler("keybinder");
410          enableMouseHandler("keybinder");
411          enableMouseHandler("SpaceShip");
412          enableJoyStickHandler("keybinder", 0);
[1219]413          break;
414
415        case IS_GUI:
[1349]416          // TODO: do stuff
[1219]417          break;
418
419        case IS_CONSOLE:
[1349]420          enableMouseHandler("keybinder");
421          enableMouseHandler("SpaceShip");
422          enableJoyStickHandler("keybinder", 0);
423          enableKeyHandler("buffer");
[1219]424          break;
425
426        default:
427          break;
428        }
429        state_ = stateRequest_;
430      }
431    }
432
433    // Capture all the input. This calls the event handlers in InputManager.
434    if (mouse_)
435      mouse_->capture();
436    if (keyboard_)
437      keyboard_->capture();
[1293]438    for (unsigned  int i = 0; i < joySticksSize_; i++)
439      joySticks_[i]->capture();
[1219]440
441
442    // call all the handlers for the held key events
[1293]443    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
444      for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
445        activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
[1219]446
447    // call all the handlers for the held mouse button events
[1293]448    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
449      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
[1349]450        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
[1219]451
452    // call all the handlers for the held joy stick button events
[1293]453    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
454      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
455        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
[1349]456          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
457
458
459    // call the ticks
460    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
461      activeHandlers_[iHandler]->tick(dt);
[1219]462  }
463
464  // ###### Key Events ######
465
466  /**
467    @brief Event handler for the keyPressed Event.
468    @param e Event information
469  */
470  bool InputManager::keyPressed(const OIS::KeyEvent &e)
471  {
472    // check whether the key already is in the list (can happen when focus was lost)
[1293]473    unsigned int iKey = 0;
474    while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key)
475      iKey++;
476    if (iKey == keysDown_.size())
477      keysDown_.push_back(Key(e));
[1219]478
[1293]479    // update modifiers
480    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
481      keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
482    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
483      keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
484    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
485      keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
486
[1219]487    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
[1293]488      activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_));
[1219]489
490    return true;
491  }
492
493  /**
494    @brief Event handler for the keyReleased Event.
495    @param e Event information
496  */
497  bool InputManager::keyReleased(const OIS::KeyEvent &e)
498  {
499    // remove the key from the keysDown_ list
[1293]500    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
[1219]501    {
[1293]502      if (keysDown_[iKey].key == (KeyCode::Enum)e.key)
[1219]503      {
[1293]504        keysDown_.erase(keysDown_.begin() + iKey);
[1022]505        break;
[1219]506      }
507    }
508
[1293]509    // update modifiers
510    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
511      keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
512    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
513      keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
514    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
515      keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
516
[1219]517    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
[1293]518      activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_));
[1219]519
520    return true;
521  }
522
523
524  // ###### Mouse Events ######
525
526  /**
527    @brief Event handler for the mouseMoved Event.
528    @param e Event information
529  */
530  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
531  {
[1293]532    // check for actual moved event
533    if (e.state.X.rel != 0 || e.state.Y.rel != 0)
534    {
535      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
[1349]536        activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
537            IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
[1293]538    }
[1219]539
[1293]540    // check for mouse scrolled event
541    if (e.state.Z.rel != 0)
542    {
543      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
[1349]544        activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
[1293]545    }
546
[1219]547    return true;
548  }
549
550  /**
551    @brief Event handler for the mousePressed Event.
552    @param e Event information
553    @param id The ID of the mouse button
554  */
555  bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
556  {
557    // check whether the button already is in the list (can happen when focus was lost)
[1293]558    unsigned int iButton = 0;
559    while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id)
560      iButton++;
561    if (iButton == mouseButtonsDown_.size())
562      mouseButtonsDown_.push_back((MouseButton::Enum)id);
[1219]563
564    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
[1349]565      activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id);
[1219]566
567    return true;
568  }
569
570  /**
571    @brief Event handler for the mouseReleased Event.
572    @param e Event information
573    @param id The ID of the mouse button
574  */
575  bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
576  {
577    // remove the button from the keysDown_ list
[1293]578    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
[1219]579    {
[1293]580      if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id)
[1219]581      {
[1293]582        mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
[1022]583        break;
584      }
585    }
586
[1219]587    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
[1349]588      activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id);
[918]589
[1219]590    return true;
[918]591  }
592
[1219]593
594  // ###### Joy Stick Events ######
595
596  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
597  {
[1293]598    // use the device to identify which one called the method
[1219]599    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]600    unsigned int iJoyStick = 0;
601    while (joySticks_[iJoyStick] != joyStick)
602      iJoyStick++;
[1219]603
604    // check whether the button already is in the list (can happen when focus was lost)
[1293]605    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
606    unsigned int iButton = 0;
607    while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
608      iButton++;
609    if (iButton == buttonsDown.size())
610      buttonsDown.push_back(button);
[1219]611
[1293]612    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
[1349]613      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button);
[1219]614
615    return true;
616  }
617
618  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
619  {
[1293]620    // use the device to identify which one called the method
[1219]621    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]622    unsigned int iJoyStick = 0;
623    while (joySticks_[iJoyStick] != joyStick)
624      iJoyStick++;
[1219]625
626    // remove the button from the joyStickButtonsDown_ list
[1293]627    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
628    for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
[1219]629    {
[1293]630      if (buttonsDown[iButton] == button)
[1219]631      {
[1293]632        buttonsDown.erase(buttonsDown.begin() + iButton);
[1219]633        break;
634      }
635    }
636
[1293]637    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
[1349]638      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button);
[1219]639
640    return true;
641  }
642
643  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
644  {
[1349]645    //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl;
[1293]646    // use the device to identify which one called the method
[1219]647    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]648    unsigned int iJoyStick = 0;
649    while (joySticks_[iJoyStick] != joyStick)
650      iJoyStick++;
[1219]651
[1349]652    // keep in mind that the first 8 axes are reserved for the sliders
[1293]653    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
[1349]654      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
[1293]655
[1219]656    return true;
657  }
658
659  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
660  {
[1349]661    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
[1293]662    // use the device to identify which one called the method
[1219]663    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]664    unsigned int iJoyStick = 0;
665    while (joySticks_[iJoyStick] != joyStick)
666      iJoyStick++;
667
[1349]668    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
669    {
670      // slider X axis changed
671      sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
672      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
673        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
674    }
675    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
676    {
677      // slider Y axis changed
678      sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
679      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
680        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
681    }
[1219]682
683    return true;
684  }
685
686  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
687  {
[1293]688    // use the device to identify which one called the method
[1219]689    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]690    unsigned int iJoyStick = 0;
691    while (joySticks_[iJoyStick] != joyStick)
692      iJoyStick++;
693
[1349]694    // translate the POV into 8 simple buttons
695    int lastState = povStates_[iJoyStick][id];
696    if (lastState & OIS::Pov::North)
697      buttonReleased(arg, 32 + id * 4 + 0);
698    if (lastState & OIS::Pov::South)
699      buttonReleased(arg, 32 + id * 4 + 1);
700    if (lastState & OIS::Pov::East)
701      buttonReleased(arg, 32 + id * 4 + 2);
702    if (lastState & OIS::Pov::West)
703      buttonReleased(arg, 32 + id * 4 + 3);
704   
705    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
706    int currentState = povStates_[iJoyStick][id];
707    if (currentState & OIS::Pov::North)
708      buttonPressed(arg, 32 + id * 4 + 0);
709    if (currentState & OIS::Pov::South)
710      buttonPressed(arg, 32 + id * 4 + 1);
711    if (currentState & OIS::Pov::East)
712      buttonPressed(arg, 32 + id * 4 + 2);
713    if (currentState & OIS::Pov::West)
714      buttonPressed(arg, 32 + id * 4 + 3);
[1219]715
716    return true;
717  }
718
[1349]719  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
[1219]720  {
[1293]721    // use the device to identify which one called the method
[1219]722    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
[1293]723    unsigned int iJoyStick = 0;
724    while (joySticks_[iJoyStick] != joyStick)
725      iJoyStick++;
726
727    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
728      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id);
[1219]729
730    return true;
[1349]731  }*/
[1219]732
733
734  // ################################
735  // ### Static Interface Methods ###
736  // ################################
737  // ################################
738
[1293]739  bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
740    bool createKeyboard, bool createMouse, bool createJoySticks)
[1219]741  {
742    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
743          createKeyboard, createMouse, createJoySticks);
744  }
745
746  bool InputManager::initialiseKeyboard()
747  {
748    return _getSingleton()._initialiseKeyboard();
749  }
750
751  bool InputManager::initialiseMouse()
752  {
753    return _getSingleton()._initialiseMouse();
754  }
755
756  bool InputManager::initialiseJoySticks()
757  {
758    return _getSingleton()._initialiseJoySticks();
759  }
760
761  int InputManager::numberOfKeyboards()
762  {
763    if (_getSingleton().keyboard_ != 0)
764      return 1;
765    else
766      return 0;
767  }
768
769  int InputManager::numberOfMice()
770  {
771    if (_getSingleton().mouse_ != 0)
772      return 1;
773    else
774      return 0;
775  }
776
777  int InputManager::numberOfJoySticks()
778  {
[1293]779    return _getSingleton().joySticksSize_;
[1219]780  }
781
[1293]782  bool InputManager::isKeyDown(KeyCode::Enum key)
783  {
784    if (_getSingleton().keyboard_)
785      return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key);
786    else
787      return false;
788  }
[1219]789
[1293]790  bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
791  {
792    if (_getSingleton().keyboard_)
793      return isModifierDown(modifier);
794    else
795      return false;
796  }
797
[1349]798  /*const MouseState InputManager::getMouseState()
[1293]799  {
800    if (_getSingleton().mouse_)
801      return _getSingleton().mouse_->getMouseState();
802    else
803      return MouseState();
[1349]804  }*/
[1293]805
[1349]806  /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
[1293]807  {
808    if (ID < _getSingleton().joySticksSize_)
809      return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID);
810    else
811      return JoyStickState();
[1349]812  }*/
[1293]813
814
[1219]815  void InputManager::destroy()
816  {
817    _getSingleton()._destroy();
818  }
819
820  void InputManager::destroyKeyboard()
821  {
822    return _getSingleton()._destroyKeyboard();
823  }
824
825  void InputManager::destroyMouse()
826  {
827    return _getSingleton()._destroyMouse();
828  }
829
830  void InputManager::destroyJoySticks()
831  {
832    return _getSingleton()._destroyJoySticks();
833  }
834
835
[919]836  /**
837    @brief Adjusts the mouse window metrics.
838    This method has to be called every time the size of the window changes.
839    @param width The new width of the render window
840    @param height the new height of the render window
841  */
[1219]842  void InputManager::setWindowExtents(const int width, const int height)
[918]843  {
[1219]844    if (_getSingleton().mouse_)
845    {
846      // Set mouse region (if window resizes, we should alter this to reflect as well)
847      const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
848      mouseState.width  = width;
849      mouseState.height = height;
850    }
[918]851  }
852
[919]853  /**
[1022]854    @brief Sets the input mode to either GUI, inGame or Buffer
855    @param mode The new input mode
856    @remark Only has an affect if the mode actually changes
[922]857  */
[1219]858  void InputManager::setInputState(const InputState state)
[922]859  {
[1219]860    _getSingleton().stateRequest_ = state;
[922]861  }
862
863  /**
[1022]864    @brief Returns the current input handling method
865    @return The current input mode.
[919]866  */
[1219]867  InputManager::InputState InputManager::getInputState()
[918]868  {
[1219]869    return _getSingleton().state_;
[918]870  }
871
[1219]872
873  // ###### KeyHandler ######
874
875  /**
876    @brief Adds a new key handler.
877    @param handler Pointer to the handler object.
878    @param name Unique name of the handler.
879    @return True if added, false if name already existed.
880  */
881  bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name)
[1066]882  {
[1293]883    if (!handler)
884      return false;
[1219]885    if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end())
886    {
887      _getSingleton().keyHandlers_[name] = handler;
888      return true;
889    }
890    else
891      return false;
[1066]892  }
893
[1219]894  /**
895    @brief Removes a Key handler from the list.
896    @param name Unique name of the handler.
897    @return True if removal was successful, false if name was not found.
898  */
899  bool InputManager::removeKeyHandler(const std::string &name)
900  {
901    disableKeyHandler(name);
902    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
903    if (it != _getSingleton().keyHandlers_.end())
904    {
905      _getSingleton().keyHandlers_.erase(it);
906      return true;
907    }
908    else
909      return false;
910  }
[1066]911
[1219]912  /**
913    @brief Returns the pointer to a handler.
914    @param name Unique name of the handler.
915    @return Pointer to the instance, 0 if name was not found.
916  */
917  KeyHandler* InputManager::getKeyHandler(const std::string& name)
918  {
919    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
920    if (it != _getSingleton().keyHandlers_.end())
921    {
922      return (*it).second;
923    }
924    else
925      return 0;
926  }
927
928  /**
929    @brief Enables a specific key handler that has already been added.
930    @param name Unique name of the handler.
931    @return False if name was not found, true otherwise.
932  */
933  bool InputManager::enableKeyHandler(const std::string& name)
934  {
935    // get pointer from the map with all stored handlers
936    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
937    if (mapIt == _getSingleton().keyHandlers_.end())
938      return false;
939    // see whether the handler already is in the list
940    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
941          it != _getSingleton().activeKeyHandlers_.end(); it++)
942    {
943      if ((*it) == (*mapIt).second)
944      {
945        return true;
946      }
947    }
948    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
949    _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]950    _getSingleton()._updateTickables();
[1219]951    return true;
952  }
953
954  /**
955    @brief Disables a specific key handler.
956    @param name Unique name of the handler.
957    @return False if name was not found, true otherwise.
958  */
959  bool InputManager::disableKeyHandler(const std::string &name)
960  {
961    // get pointer from the map with all stored handlers
962    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
963    if (mapIt == _getSingleton().keyHandlers_.end())
964      return false;
965    // look for the handler in the list
966    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
967          it != _getSingleton().activeKeyHandlers_.end(); it++)
968    {
969      if ((*it) == (*mapIt).second)
970      {
971        _getSingleton().activeKeyHandlers_.erase(it);
972        _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]973        _getSingleton()._updateTickables();
[1219]974        return true;
975      }
976    }
977    return true;
978  }
979
980  /**
981    @brief Checks whether a key handler is active
982    @param name Unique name of the handler.
983    @return False if key handler is not active or doesn't exist, true otherwise.
984  */
985  bool InputManager::isKeyHandlerActive(const std::string& name)
986  {
987    // get pointer from the map with all stored handlers
988    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
989    if (mapIt == _getSingleton().keyHandlers_.end())
990      return false;
991    // see whether the handler already is in the list
992    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
993          it != _getSingleton().activeKeyHandlers_.end(); it++)
994    {
995      if ((*it) == (*mapIt).second)
996        return true;
997    }
998    return false;
999  }
1000
1001
1002  // ###### MouseHandler ######
1003  /**
1004    @brief Adds a new mouse handler.
1005    @param handler Pointer to the handler object.
1006    @param name Unique name of the handler.
1007    @return True if added, false if name already existed.
1008  */
1009  bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)
1010  {
[1293]1011    if (!handler)
1012      return false;
[1219]1013    if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())
1014    {
1015      _getSingleton().mouseHandlers_[name] = handler;
1016      return true;
1017    }
1018    else
1019      return false;
1020  }
1021
1022  /**
1023    @brief Removes a Mouse handler from the list.
1024    @param name Unique name of the handler.
1025    @return True if removal was successful, false if name was not found.
1026  */
1027  bool InputManager::removeMouseHandler(const std::string &name)
1028  {
1029    disableMouseHandler(name);
1030    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
1031    if (it != _getSingleton().mouseHandlers_.end())
1032    {
1033      _getSingleton().mouseHandlers_.erase(it);
1034      return true;
1035    }
1036    else
1037      return false;
1038  }
1039
1040  /**
1041    @brief Returns the pointer to a handler.
1042    @param name Unique name of the handler.
1043    @return Pointer to the instance, 0 if name was not found.
1044  */
1045  MouseHandler* InputManager::getMouseHandler(const std::string& name)
1046  {
1047    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
1048    if (it != _getSingleton().mouseHandlers_.end())
1049    {
1050      return (*it).second;
1051    }
1052    else
1053      return 0;
1054  }
1055
1056  /**
1057    @brief Enables a specific mouse handler that has already been added.
1058    @param name Unique name of the handler.
1059    @return False if name was not found, true otherwise.
1060  */
1061  bool InputManager::enableMouseHandler(const std::string& name)
1062  {
1063    // get pointer from the map with all stored handlers
1064    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1065    if (mapIt == _getSingleton().mouseHandlers_.end())
1066      return false;
1067    // see whether the handler already is in the list
1068    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1069          it != _getSingleton().activeMouseHandlers_.end(); it++)
1070    {
1071      if ((*it) == (*mapIt).second)
1072      {
1073        return true;
1074      }
1075    }
1076    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
1077    _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]1078    _getSingleton()._updateTickables();
[1219]1079    return true;
1080  }
1081
1082  /**
1083    @brief Disables a specific mouse handler.
1084    @param name Unique name of the handler.
1085    @return False if name was not found, true otherwise.
1086  */
1087  bool InputManager::disableMouseHandler(const std::string &name)
1088  {
1089    // get pointer from the map with all stored handlers
1090    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1091    if (mapIt == _getSingleton().mouseHandlers_.end())
1092      return false;
1093    // look for the handler in the list
1094    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1095          it != _getSingleton().activeMouseHandlers_.end(); it++)
1096    {
1097      if ((*it) == (*mapIt).second)
1098      {
1099        _getSingleton().activeMouseHandlers_.erase(it);
1100        _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]1101        _getSingleton()._updateTickables();
[1219]1102        return true;
1103      }
1104    }
1105    return true;
1106  }
1107
1108  /**
1109    @brief Checks whether a mouse handler is active
1110    @param name Unique name of the handler.
1111    @return False if key handler is not active or doesn't exist, true otherwise.
1112  */
1113  bool InputManager::isMouseHandlerActive(const std::string& name)
1114  {
1115    // get pointer from the map with all stored handlers
1116    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1117    if (mapIt == _getSingleton().mouseHandlers_.end())
1118      return false;
1119    // see whether the handler already is in the list
1120    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1121          it != _getSingleton().activeMouseHandlers_.end(); it++)
1122    {
1123      if ((*it) == (*mapIt).second)
1124        return true;
1125    }
1126    return false;
1127  }
1128
1129
1130  // ###### JoyStickHandler ######
1131
1132  /**
1133    @brief Adds a new joy stick handler.
1134    @param handler Pointer to the handler object.
1135    @param name Unique name of the handler.
1136    @return True if added, false if name already existed.
1137  */
1138  bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)
1139  {
[1293]1140    if (!handler)
1141      return false;
[1219]1142    if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())
1143    {
1144      _getSingleton().joyStickHandlers_[name] = handler;
1145      return true;
1146    }
1147    else
1148      return false;
1149  }
1150
1151  /**
1152    @brief Removes a JoyStick handler from the list.
1153    @param name Unique name of the handler.
1154    @return True if removal was successful, false if name was not found.
1155  */
1156  bool InputManager::removeJoyStickHandler(const std::string &name)
1157  {
1158    for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();
1159          itstick != _getSingleton().joySticks_.end(); itstick++)
1160      disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());
1161
1162    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
1163    if (it != _getSingleton().joyStickHandlers_.end())
1164    {
1165      _getSingleton().joyStickHandlers_.erase(it);
1166      return true;
1167    }
1168    else
1169      return false;
1170  }
1171
1172  /**
1173    @brief Returns the pointer to a handler.
1174    @param name Unique name of the handler.
1175    @return Pointer to the instance, 0 if name was not found.
1176  */
1177  JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name)
1178  {
1179    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
1180    if (it != _getSingleton().joyStickHandlers_.end())
1181    {
1182      return (*it).second;
1183    }
1184    else
1185      return 0;
1186  }
1187
1188  /**
1189    @brief Enables a specific joy stick handler that has already been added.
1190    @param name Unique name of the handler.
1191    @return False if name or id was not found, true otherwise.
1192  */
[1293]1193  bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)
[1219]1194  {
1195    // get handler pointer from the map with all stored handlers
1196    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1197    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1198      return false;
1199
1200    // check for existence of the ID
[1293]1201    if (ID >= _getSingleton().joySticksSize_)
[1219]1202      return false;
1203
1204    // see whether the handler already is in the list
[1293]1205    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1206          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
[1219]1207    {
1208      if ((*it) == (*handlerIt).second)
1209      {
1210        return true;
1211      }
1212    }
[1293]1213    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
[1219]1214    _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]1215    _getSingleton()._updateTickables();
[1219]1216    return true;
1217  }
1218
1219  /**
1220    @brief Disables a specific joy stick handler.
1221    @param name Unique name of the handler.
1222    @return False if name or id was not found, true otherwise.
1223  */
[1293]1224  bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)
[1219]1225  {
1226    // get handler pointer from the map with all stored handlers
1227    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1228    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1229      return false;
1230
1231    // check for existence of the ID
[1293]1232    if (ID >= _getSingleton().joySticksSize_)
[1219]1233      return false;
1234
1235    // look for the handler in the list
[1293]1236    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1237          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
[1219]1238    {
1239      if ((*it) == (*handlerIt).second)
1240      {
[1293]1241        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
[1219]1242        _getSingleton().stateRequest_ = IS_CUSTOM;
[1349]1243        _getSingleton()._updateTickables();
[1219]1244        return true;
1245      }
1246    }
1247    return true;
1248  }
1249
1250  /**
1251    @brief Checks whether a joy stick handler is active
1252    @param name Unique name of the handler.
1253    @return False if key handler is not active or doesn't exist, true otherwise.
1254  */
[1293]1255  bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)
[1219]1256  {
1257    // get handler pointer from the map with all stored handlers
1258    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1259    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1260      return false;
1261
1262    // check for existence of the ID
[1293]1263    if (ID >= _getSingleton().joySticksSize_)
[1219]1264      return false;
1265
1266    // see whether the handler already is in the list
[1293]1267    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1268          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
[1219]1269    {
1270      if ((*it) == (*handlerIt).second)
1271        return true;
1272    }
1273    return false;
1274  }
1275
[918]1276}
Note: See TracBrowser for help on using the repository browser.