Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1428 was 1428, checked in by rgrieder, 16 years ago
  • added SetConfigValueGeneric to set the config value of the actual class when using hierarchies
  • fixed a bug when handling derived mouse input
  • refined 'keybind' command so that input goes to KeyDetector only
File size: 43.4 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::_saveState()
374  {
375    savedHandlers_.activeHandlers_ = activeHandlers_;
376    savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_;
377    savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_;
378    savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_;
379  }
380
381  void InputManager::_restoreState()
382  {
383    activeHandlers_ = savedHandlers_.activeHandlers_;
384    activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_;
385    activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_;
386    activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_;
387  }
388
389  void InputManager::_updateTickables()
390  {
391    // we can use a map to have a list of unique pointers (an object can implement all 3 handlers)
392    std::map<InputTickable*, HandlerState> tempSet;
393    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
394      tempSet[activeKeyHandlers_[iHandler]].joyStick = true;
395    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
396      tempSet[activeMouseHandlers_[iHandler]].mouse = true;
397    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
398      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
399        tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true;
400
401    // copy the content of the map back to the actual vector
402    activeHandlers_.clear();
403    for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin();
404        itHandler != tempSet.end(); itHandler++)
405      activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second));
406  }
407
408
409  // #################################
410  // ### Private Interface Methods ###
411  // #################################
412  // #################################
413
414  /**
415    @brief Updates the InputManager. Tick is called by Orxonox.
416    @param dt Delta time
417  */
418  void InputManager::tick(float dt)
419  {
420    if (state_ == IS_UNINIT)
421      return;
422
423    if (state_ != stateRequest_)
424    {
425      if (stateRequest_ != IS_CUSTOM)
426      {
427        if (stateRequest_ != IS_DETECT)
428        {
429          activeKeyHandlers_.clear();
430          activeMouseHandlers_.clear();
431          for (unsigned int i = 0; i < joySticksSize_; i++)
432            activeJoyStickHandlers_[i].clear();
433        }
434
435        switch (stateRequest_)
436        {
437        case IS_NORMAL:
438          // normal play mode
439          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
440          enableKeyHandler("keybinder");
441          enableMouseHandler("keybinder");
442          enableJoyStickHandler("keybinder", 0);
443          break;
444
445        case IS_GUI:
446          break;
447
448        case IS_CONSOLE:
449          enableMouseHandler("keybinder");
450          enableJoyStickHandler("keybinder", 0);
451          enableKeyHandler("buffer");
452          break;
453
454        case IS_DETECT:
455          savedState_ = state_;
456          _saveState();
457
458          activeKeyHandlers_.clear();
459          activeMouseHandlers_.clear();
460          for (unsigned int i = 0; i < joySticksSize_; i++)
461            activeJoyStickHandlers_[i].clear();
462
463          enableKeyHandler("keydetector");
464          enableMouseHandler("keydetector");
465          enableJoyStickHandler("keydetector", 0);
466          break;
467
468        case IS_NODETECT:
469          _restoreState();
470          break;
471
472        default:
473          break;
474        }
475
476        if (stateRequest_ == IS_NODETECT)
477          state_ = savedState_;
478        else
479          state_ = stateRequest_;
480      }
481    }
482
483    // Capture all the input. This calls the event handlers in InputManager.
484    if (mouse_)
485      mouse_->capture();
486    if (keyboard_)
487      keyboard_->capture();
488    for (unsigned  int i = 0; i < joySticksSize_; i++)
489      joySticks_[i]->capture();
490
491
492    // call all the handlers for the held key events
493    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
494      for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
495        activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
496
497    // call all the handlers for the held mouse button events
498    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
499      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
500        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
501
502    // call all the handlers for the held joy stick button events
503    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
504      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
505        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
506          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
507
508
509    // call the ticks for the handlers (need to be treated specially)
510    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
511      activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second);
512
513    /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
514      activeKeyHandlers_[iHandler]->tickKey(dt);
515    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
516      activeMouseHandlers_[iHandler]->tickMouse(dt);
517    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
518      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
519        activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/
520  }
521
522  // ###### Key Events ######
523
524  /**
525    @brief Event handler for the keyPressed Event.
526    @param e Event information
527  */
528  bool InputManager::keyPressed(const OIS::KeyEvent &e)
529  {
530    // check whether the key already is in the list (can happen when focus was lost)
531    unsigned int iKey = 0;
532    while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key)
533      iKey++;
534    if (iKey == keysDown_.size())
535      keysDown_.push_back(Key(e));
536
537    // update modifiers
538    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
539      keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
540    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
541      keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
542    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
543      keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
544
545    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
546      activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_));
547
548    return true;
549  }
550
551  /**
552    @brief Event handler for the keyReleased Event.
553    @param e Event information
554  */
555  bool InputManager::keyReleased(const OIS::KeyEvent &e)
556  {
557    // remove the key from the keysDown_ list
558    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
559    {
560      if (keysDown_[iKey].key == (KeyCode::Enum)e.key)
561      {
562        keysDown_.erase(keysDown_.begin() + iKey);
563        break;
564      }
565    }
566
567    // update modifiers
568    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
569      keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
570    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
571      keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
572    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
573      keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
574
575    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
576      activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_));
577
578    return true;
579  }
580
581
582  // ###### Mouse Events ######
583
584  /**
585    @brief Event handler for the mouseMoved Event.
586    @param e Event information
587  */
588  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
589  {
590    // check for actual moved event
591    if (e.state.X.rel != 0 || e.state.Y.rel != 0)
592    {
593      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
594        activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
595            IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
596    }
597
598    // check for mouse scrolled event
599    if (e.state.Z.rel != 0)
600    {
601      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
602        activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
603    }
604
605    return true;
606  }
607
608  /**
609    @brief Event handler for the mousePressed Event.
610    @param e Event information
611    @param id The ID of the mouse button
612  */
613  bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
614  {
615    // check whether the button already is in the list (can happen when focus was lost)
616    unsigned int iButton = 0;
617    while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id)
618      iButton++;
619    if (iButton == mouseButtonsDown_.size())
620      mouseButtonsDown_.push_back((MouseButton::Enum)id);
621
622    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
623      activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id);
624
625    return true;
626  }
627
628  /**
629    @brief Event handler for the mouseReleased Event.
630    @param e Event information
631    @param id The ID of the mouse button
632  */
633  bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
634  {
635    // remove the button from the keysDown_ list
636    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
637    {
638      if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id)
639      {
640        mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
641        break;
642      }
643    }
644
645    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
646      activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id);
647
648    return true;
649  }
650
651
652  // ###### Joy Stick Events ######
653
654  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
655  {
656    // use the device to identify which one called the method
657    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
658    unsigned int iJoyStick = 0;
659    while (joySticks_[iJoyStick] != joyStick)
660      iJoyStick++;
661
662    // check whether the button already is in the list (can happen when focus was lost)
663    std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
664    unsigned int iButton = 0;
665    while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
666      iButton++;
667    if (iButton == buttonsDown.size())
668      buttonsDown.push_back(button);
669
670    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
671      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button);
672
673    return true;
674  }
675
676  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
677  {
678    // use the device to identify which one called the method
679    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
680    unsigned int iJoyStick = 0;
681    while (joySticks_[iJoyStick] != joyStick)
682      iJoyStick++;
683
684    // remove the button from the joyStickButtonsDown_ list
685    std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
686    for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
687    {
688      if (buttonsDown[iButton] == button)
689      {
690        buttonsDown.erase(buttonsDown.begin() + iButton);
691        break;
692      }
693    }
694
695    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
696      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button);
697
698    return true;
699  }
700
701  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
702  {
703    //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000)
704    //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;}
705    // use the device to identify which one called the method
706    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
707    unsigned int iJoyStick = 0;
708    while (joySticks_[iJoyStick] != joyStick)
709      iJoyStick++;
710
711    // keep in mind that the first 8 axes are reserved for the sliders
712    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
713      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
714
715    return true;
716  }
717
718  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
719  {
720    //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000)
721    //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;}
722    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
723    // use the device to identify which one called the method
724    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
725    unsigned int iJoyStick = 0;
726    while (joySticks_[iJoyStick] != joyStick)
727      iJoyStick++;
728
729    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
730    {
731      // slider X axis changed
732      sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
733      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
734        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
735    }
736    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
737    {
738      // slider Y axis changed
739      sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
740      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
741        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
742    }
743
744    return true;
745  }
746
747  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
748  {
749    // use the device to identify which one called the method
750    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
751    unsigned int iJoyStick = 0;
752    while (joySticks_[iJoyStick] != joyStick)
753      iJoyStick++;
754
755    // translate the POV into 8 simple buttons
756    int lastState = povStates_[iJoyStick][id];
757    if (lastState & OIS::Pov::North)
758      buttonReleased(arg, 32 + id * 4 + 0);
759    if (lastState & OIS::Pov::South)
760      buttonReleased(arg, 32 + id * 4 + 1);
761    if (lastState & OIS::Pov::East)
762      buttonReleased(arg, 32 + id * 4 + 2);
763    if (lastState & OIS::Pov::West)
764      buttonReleased(arg, 32 + id * 4 + 3);
765   
766    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
767    int currentState = povStates_[iJoyStick][id];
768    if (currentState & OIS::Pov::North)
769      buttonPressed(arg, 32 + id * 4 + 0);
770    if (currentState & OIS::Pov::South)
771      buttonPressed(arg, 32 + id * 4 + 1);
772    if (currentState & OIS::Pov::East)
773      buttonPressed(arg, 32 + id * 4 + 2);
774    if (currentState & OIS::Pov::West)
775      buttonPressed(arg, 32 + id * 4 + 3);
776
777    return true;
778  }
779
780  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
781  {
782    // use the device to identify which one called the method
783    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
784    unsigned int iJoyStick = 0;
785    while (joySticks_[iJoyStick] != joyStick)
786      iJoyStick++;
787
788    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
789      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id);
790
791    return true;
792  }*/
793
794
795  // ################################
796  // ### Static Interface Methods ###
797  // ################################
798  // ################################
799
800  std::string InputManager::bindingCommmandString_s = "";
801
802  bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
803    bool createKeyboard, bool createMouse, bool createJoySticks)
804  {
805    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
806          createKeyboard, createMouse, createJoySticks);
807  }
808
809  bool InputManager::initialiseKeyboard()
810  {
811    return _getSingleton()._initialiseKeyboard();
812  }
813
814  bool InputManager::initialiseMouse()
815  {
816    return _getSingleton()._initialiseMouse();
817  }
818
819  bool InputManager::initialiseJoySticks()
820  {
821    return _getSingleton()._initialiseJoySticks();
822  }
823
824  int InputManager::numberOfKeyboards()
825  {
826    if (_getSingleton().keyboard_ != 0)
827      return 1;
828    else
829      return 0;
830  }
831
832  int InputManager::numberOfMice()
833  {
834    if (_getSingleton().mouse_ != 0)
835      return 1;
836    else
837      return 0;
838  }
839
840  int InputManager::numberOfJoySticks()
841  {
842    return _getSingleton().joySticksSize_;
843  }
844
845  /*bool InputManager::isKeyDown(KeyCode::Enum key)
846  {
847    if (_getSingleton().keyboard_)
848      return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key);
849    else
850      return false;
851  }*/
852
853  /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
854  {
855    if (_getSingleton().keyboard_)
856      return isModifierDown(modifier);
857    else
858      return false;
859  }*/
860
861  /*const MouseState InputManager::getMouseState()
862  {
863    if (_getSingleton().mouse_)
864      return _getSingleton().mouse_->getMouseState();
865    else
866      return MouseState();
867  }*/
868
869  /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
870  {
871    if (ID < _getSingleton().joySticksSize_)
872      return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID);
873    else
874      return JoyStickState();
875  }*/
876
877  void InputManager::destroy()
878  {
879    _getSingleton()._destroy();
880  }
881
882  void InputManager::destroyKeyboard()
883  {
884    return _getSingleton()._destroyKeyboard();
885  }
886
887  void InputManager::destroyMouse()
888  {
889    return _getSingleton()._destroyMouse();
890  }
891
892  void InputManager::destroyJoySticks()
893  {
894    return _getSingleton()._destroyJoySticks();
895  }
896
897
898  /**
899    @brief Adjusts the mouse window metrics.
900    This method has to be called every time the size of the window changes.
901    @param width The new width of the render window
902    @param height the new height of the render window
903  */
904  void InputManager::setWindowExtents(const int width, const int height)
905  {
906    if (_getSingleton().mouse_)
907    {
908      // Set mouse region (if window resizes, we should alter this to reflect as well)
909      const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
910      mouseState.width  = width;
911      mouseState.height = height;
912    }
913  }
914
915  /**
916    @brief Sets the input mode to either GUI, inGame or Buffer
917    @param mode The new input mode
918    @remark Only has an affect if the mode actually changes
919  */
920  void InputManager::setInputState(const InputState state)
921  {
922    _getSingleton().stateRequest_ = state;
923  }
924
925  /**
926    @brief Returns the current input handling method
927    @return The current input mode.
928  */
929  InputManager::InputState InputManager::getInputState()
930  {
931    return _getSingleton().state_;
932  }
933
934  void InputManager::storeKeyStroke(const std::string& name)
935  {
936    setInputState(IS_NODETECT);
937    COUT(3) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;
938    CommandExecutor::execute("set KeyBinder " + name + " " + bindingCommmandString_s, false);
939  }
940
941  void InputManager::keyBind(const std::string& command)
942  {
943    bindingCommmandString_s = command;
944    setInputState(IS_DETECT);
945  }
946
947  // ###### KeyHandler ######
948
949  /**
950    @brief Adds a new key handler.
951    @param handler Pointer to the handler object.
952    @param name Unique name of the handler.
953    @return True if added, false if name already existed.
954  */
955  bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name)
956  {
957    if (!handler)
958      return false;
959    if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end())
960    {
961      _getSingleton().keyHandlers_[name] = handler;
962      return true;
963    }
964    else
965      return false;
966  }
967
968  /**
969    @brief Removes a Key handler from the list.
970    @param name Unique name of the handler.
971    @return True if removal was successful, false if name was not found.
972  */
973  bool InputManager::removeKeyHandler(const std::string &name)
974  {
975    disableKeyHandler(name);
976    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
977    if (it != _getSingleton().keyHandlers_.end())
978    {
979      _getSingleton().keyHandlers_.erase(it);
980      return true;
981    }
982    else
983      return false;
984  }
985
986  /**
987    @brief Returns the pointer to a handler.
988    @param name Unique name of the handler.
989    @return Pointer to the instance, 0 if name was not found.
990  */
991  KeyHandler* InputManager::getKeyHandler(const std::string& name)
992  {
993    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
994    if (it != _getSingleton().keyHandlers_.end())
995    {
996      return (*it).second;
997    }
998    else
999      return 0;
1000  }
1001
1002  /**
1003    @brief Enables a specific key handler that has already been added.
1004    @param name Unique name of the handler.
1005    @return False if name was not found, true otherwise.
1006  */
1007  bool InputManager::enableKeyHandler(const std::string& name)
1008  {
1009    // get pointer from the map with all stored handlers
1010    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
1011    if (mapIt == _getSingleton().keyHandlers_.end())
1012      return false;
1013    // see whether the handler already is in the list
1014    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
1015          it != _getSingleton().activeKeyHandlers_.end(); it++)
1016    {
1017      if ((*it) == (*mapIt).second)
1018      {
1019        return true;
1020      }
1021    }
1022    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
1023    _getSingleton().stateRequest_ = IS_CUSTOM;
1024    _getSingleton()._updateTickables();
1025    return true;
1026  }
1027
1028  /**
1029    @brief Disables a specific key handler.
1030    @param name Unique name of the handler.
1031    @return False if name was not found, true otherwise.
1032  */
1033  bool InputManager::disableKeyHandler(const std::string &name)
1034  {
1035    // get pointer from the map with all stored handlers
1036    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
1037    if (mapIt == _getSingleton().keyHandlers_.end())
1038      return false;
1039    // look for the handler in the list
1040    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
1041          it != _getSingleton().activeKeyHandlers_.end(); it++)
1042    {
1043      if ((*it) == (*mapIt).second)
1044      {
1045        _getSingleton().activeKeyHandlers_.erase(it);
1046        _getSingleton().stateRequest_ = IS_CUSTOM;
1047        _getSingleton()._updateTickables();
1048        return true;
1049      }
1050    }
1051    return true;
1052  }
1053
1054  /**
1055    @brief Checks whether a key handler is active
1056    @param name Unique name of the handler.
1057    @return False if key handler is not active or doesn't exist, true otherwise.
1058  */
1059  bool InputManager::isKeyHandlerActive(const std::string& name)
1060  {
1061    // get pointer from the map with all stored handlers
1062    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
1063    if (mapIt == _getSingleton().keyHandlers_.end())
1064      return false;
1065    // see whether the handler already is in the list
1066    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
1067          it != _getSingleton().activeKeyHandlers_.end(); it++)
1068    {
1069      if ((*it) == (*mapIt).second)
1070        return true;
1071    }
1072    return false;
1073  }
1074
1075
1076  // ###### MouseHandler ######
1077  /**
1078    @brief Adds a new mouse handler.
1079    @param handler Pointer to the handler object.
1080    @param name Unique name of the handler.
1081    @return True if added, false if name already existed.
1082  */
1083  bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)
1084  {
1085    if (!handler)
1086      return false;
1087    if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())
1088    {
1089      _getSingleton().mouseHandlers_[name] = handler;
1090      return true;
1091    }
1092    else
1093      return false;
1094  }
1095
1096  /**
1097    @brief Removes a Mouse handler from the list.
1098    @param name Unique name of the handler.
1099    @return True if removal was successful, false if name was not found.
1100  */
1101  bool InputManager::removeMouseHandler(const std::string &name)
1102  {
1103    disableMouseHandler(name);
1104    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
1105    if (it != _getSingleton().mouseHandlers_.end())
1106    {
1107      _getSingleton().mouseHandlers_.erase(it);
1108      return true;
1109    }
1110    else
1111      return false;
1112  }
1113
1114  /**
1115    @brief Returns the pointer to a handler.
1116    @param name Unique name of the handler.
1117    @return Pointer to the instance, 0 if name was not found.
1118  */
1119  MouseHandler* InputManager::getMouseHandler(const std::string& name)
1120  {
1121    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
1122    if (it != _getSingleton().mouseHandlers_.end())
1123    {
1124      return (*it).second;
1125    }
1126    else
1127      return 0;
1128  }
1129
1130  /**
1131    @brief Enables a specific mouse handler that has already been added.
1132    @param name Unique name of the handler.
1133    @return False if name was not found, true otherwise.
1134  */
1135  bool InputManager::enableMouseHandler(const std::string& name)
1136  {
1137    // get pointer from the map with all stored handlers
1138    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1139    if (mapIt == _getSingleton().mouseHandlers_.end())
1140      return false;
1141    // see whether the handler already is in the list
1142    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1143          it != _getSingleton().activeMouseHandlers_.end(); it++)
1144    {
1145      if ((*it) == (*mapIt).second)
1146      {
1147        return true;
1148      }
1149    }
1150    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
1151    _getSingleton().stateRequest_ = IS_CUSTOM;
1152    _getSingleton()._updateTickables();
1153    return true;
1154  }
1155
1156  /**
1157    @brief Disables a specific mouse handler.
1158    @param name Unique name of the handler.
1159    @return False if name was not found, true otherwise.
1160  */
1161  bool InputManager::disableMouseHandler(const std::string &name)
1162  {
1163    // get pointer from the map with all stored handlers
1164    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1165    if (mapIt == _getSingleton().mouseHandlers_.end())
1166      return false;
1167    // look for the handler in the list
1168    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1169          it != _getSingleton().activeMouseHandlers_.end(); it++)
1170    {
1171      if ((*it) == (*mapIt).second)
1172      {
1173        _getSingleton().activeMouseHandlers_.erase(it);
1174        _getSingleton().stateRequest_ = IS_CUSTOM;
1175        _getSingleton()._updateTickables();
1176        return true;
1177      }
1178    }
1179    return true;
1180  }
1181
1182  /**
1183    @brief Checks whether a mouse handler is active
1184    @param name Unique name of the handler.
1185    @return False if key handler is not active or doesn't exist, true otherwise.
1186  */
1187  bool InputManager::isMouseHandlerActive(const std::string& name)
1188  {
1189    // get pointer from the map with all stored handlers
1190    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
1191    if (mapIt == _getSingleton().mouseHandlers_.end())
1192      return false;
1193    // see whether the handler already is in the list
1194    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
1195          it != _getSingleton().activeMouseHandlers_.end(); it++)
1196    {
1197      if ((*it) == (*mapIt).second)
1198        return true;
1199    }
1200    return false;
1201  }
1202
1203
1204  // ###### JoyStickHandler ######
1205
1206  /**
1207    @brief Adds a new joy stick handler.
1208    @param handler Pointer to the handler object.
1209    @param name Unique name of the handler.
1210    @return True if added, false if name already existed.
1211  */
1212  bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)
1213  {
1214    if (!handler)
1215      return false;
1216    if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())
1217    {
1218      _getSingleton().joyStickHandlers_[name] = handler;
1219      return true;
1220    }
1221    else
1222      return false;
1223  }
1224
1225  /**
1226    @brief Removes a JoyStick handler from the list.
1227    @param name Unique name of the handler.
1228    @return True if removal was successful, false if name was not found.
1229  */
1230  bool InputManager::removeJoyStickHandler(const std::string &name)
1231  {
1232    for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();
1233          itstick != _getSingleton().joySticks_.end(); itstick++)
1234      disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());
1235
1236    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
1237    if (it != _getSingleton().joyStickHandlers_.end())
1238    {
1239      _getSingleton().joyStickHandlers_.erase(it);
1240      return true;
1241    }
1242    else
1243      return false;
1244  }
1245
1246  /**
1247    @brief Returns the pointer to a handler.
1248    @param name Unique name of the handler.
1249    @return Pointer to the instance, 0 if name was not found.
1250  */
1251  JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name)
1252  {
1253    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
1254    if (it != _getSingleton().joyStickHandlers_.end())
1255    {
1256      return (*it).second;
1257    }
1258    else
1259      return 0;
1260  }
1261
1262  /**
1263    @brief Enables a specific joy stick handler that has already been added.
1264    @param name Unique name of the handler.
1265    @return False if name or id was not found, true otherwise.
1266  */
1267  bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)
1268  {
1269    // get handler pointer from the map with all stored handlers
1270    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1271    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1272      return false;
1273
1274    // check for existence of the ID
1275    if (ID >= _getSingleton().joySticksSize_)
1276      return false;
1277
1278    // see whether the handler already is in the list
1279    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1280          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
1281    {
1282      if ((*it) == (*handlerIt).second)
1283      {
1284        return true;
1285      }
1286    }
1287    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
1288    _getSingleton().stateRequest_ = IS_CUSTOM;
1289    _getSingleton()._updateTickables();
1290    return true;
1291  }
1292
1293  /**
1294    @brief Disables a specific joy stick handler.
1295    @param name Unique name of the handler.
1296    @return False if name or id was not found, true otherwise.
1297  */
1298  bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)
1299  {
1300    // get handler pointer from the map with all stored handlers
1301    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1302    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1303      return false;
1304
1305    // check for existence of the ID
1306    if (ID >= _getSingleton().joySticksSize_)
1307      return false;
1308
1309    // look for the handler in the list
1310    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1311          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
1312    {
1313      if ((*it) == (*handlerIt).second)
1314      {
1315        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
1316        _getSingleton().stateRequest_ = IS_CUSTOM;
1317        _getSingleton()._updateTickables();
1318        return true;
1319      }
1320    }
1321    return true;
1322  }
1323
1324  /**
1325    @brief Checks whether a joy stick handler is active
1326    @param name Unique name of the handler.
1327    @return False if key handler is not active or doesn't exist, true otherwise.
1328  */
1329  bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)
1330  {
1331    // get handler pointer from the map with all stored handlers
1332    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
1333    if (handlerIt == _getSingleton().joyStickHandlers_.end())
1334      return false;
1335
1336    // check for existence of the ID
1337    if (ID >= _getSingleton().joySticksSize_)
1338      return false;
1339
1340    // see whether the handler already is in the list
1341    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
1342          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
1343    {
1344      if ((*it) == (*handlerIt).second)
1345        return true;
1346    }
1347    return false;
1348  }
1349
1350}
Note: See TracBrowser for help on using the repository browser.