Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/core/InputManager.cc @ 1426

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