Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/libraries/core/input/InputManager.cc @ 9805

Last change on this file since 9805 was 9805, checked in by smerkli, 12 years ago
  • Converted some absolute paths into relative ones
  • Increased the handlers_ vector size by 1 as a hack to get the wiimote working in this branch (This will have to be cleanly redone once I have a better concept for wiimotes and joysticks)
  • Removed a local inputStates_ variable that georgr added in wiimote, it shadowed the one from the basis class and hence never got any entries

To be discussed with georgr on monday.

  • Property svn:eol-style set to native
File size: 26.6 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
32    Implementation of the InputManager and a static variable from the InputHandler.
33*/
34
35#include "InputManager.h"
36
37#include <cassert>
38#include <climits>
39#include <ois/OISException.h>
40#include <ois/OISInputManager.h>
41#include <boost/foreach.hpp>
42#include <loki/ScopeGuard.h>
43
44#include "util/Clock.h"
45#include "util/Convert.h"
46#include "util/Exception.h"
47#include "core/CoreIncludes.h"
48#include "core/GraphicsManager.h"
49#include "core/config/ConfigValueIncludes.h"
50#include "core/config/CommandLineParser.h"
51#include "core/command/ConsoleCommand.h"
52#include "core/command/Functor.h"
53
54#include "InputBuffer.h"
55#include "JoyStick.h"
56#include "JoyStickQuantityListener.h"
57#include "Mouse.h"
58#include "Keyboard.h"
59
60#include "WiiMote.h"
61
62
63namespace orxonox
64{
65    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
66
67    static const std::string __CC_InputManager_name = "InputManager";
68    static const std::string __CC_calibrate_name = "calibrate";
69    static const std::string __CC_reload_name = "reload";
70
71    SetConsoleCommand(__CC_InputManager_name, __CC_calibrate_name, &InputManager::calibrate).addShortcut();
72    SetConsoleCommand(__CC_InputManager_name, __CC_reload_name,    &InputManager::reload   );
73
74    // Abuse of this source file for the InputHandler
75    InputHandler InputHandler::EMPTY;
76
77    InputManager* InputManager::singletonPtr_s = 0;
78
79    //! Defines the |= operator for easier use.
80    inline InputManager::State operator|=(InputManager::State& lval, InputManager::State rval)
81    {
82        return (lval = (InputManager::State)(lval | rval));
83    }
84
85    //! Defines the &= operator for easier use.
86    inline InputManager::State operator&=(InputManager::State& lval, int rval)
87    {
88        return (lval = (InputManager::State)(lval & rval));
89    }
90
91    // ############################################################
92    // #####                  Initialisation                  #####
93    // ##########                                        ##########
94    // ############################################################
95    InputManager::InputManager()
96        : internalState_(Bad)
97        , oisInputManager_(0)
98        , devices_(2)
99        , exclusiveMouse_(false)
100        , emptyState_(0)
101        , calibratorCallbackHandler_(0)
102    {
103        RegisterObject(InputManager);
104
105        orxout(internal_status, context::input) << "InputManager: Constructing..." << endl;
106
107        // Allocate space for the function call buffer
108        this->callBuffer_.reserve(16);
109
110        this->setConfigValues();
111
112        if (GraphicsManager::getInstance().isFullScreen())
113            exclusiveMouse_ = true;
114        this->loadDevices();
115
116        // Lowest priority empty InputState
117        emptyState_ = createInputState("empty", false, false, InputStatePriority::Empty);
118        emptyState_->setHandler(&InputHandler::EMPTY);
119        activeStates_[emptyState_->getPriority()] = emptyState_;
120
121        // Joy stick calibration helper callback
122        InputState* calibrator = createInputState("calibrator", false, false, InputStatePriority::Calibrator);
123        calibrator->setHandler(&InputHandler::EMPTY);
124        calibratorCallbackHandler_ = new InputBuffer();
125        calibratorCallbackHandler_->registerListener(this, &InputManager::stopCalibration, '\r', true);
126        calibrator->setKeyHandler(calibratorCallbackHandler_);
127
128        this->updateActiveStates();
129
130        ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(this);
131        ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(this);
132
133        orxout(internal_status, context::input) << "InputManager: Construction complete." << endl;
134        internalState_ = Nothing;
135    }
136
137    void InputManager::setConfigValues()
138    {
139    }
140
141    /**
142    @brief
143        Creates the OIS::InputMananger, the keyboard, the mouse and
144        the joys ticks. If either of the first two fail, this method throws an exception.
145    */
146    void InputManager::loadDevices()
147    {
148        orxout(verbose, context::input) << "InputManager: Loading input devices..." << endl;
149
150        // When loading the devices they should not already be loaded
151        assert(internalState_ & Bad);
152        assert(devices_[InputDeviceEnumerator::Mouse] == 0);
153        assert(devices_[InputDeviceEnumerator::Keyboard] == 0);
154        assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
155
156        typedef std::pair<std::string, std::string> StringPair;
157
158        // Fill parameter list
159        OIS::ParamList paramList;
160        size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle();
161        paramList.insert(StringPair("WINDOW", multi_cast<std::string>(windowHnd)));
162#if defined(ORXONOX_PLATFORM_WINDOWS)
163        paramList.insert(StringPair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
164        paramList.insert(StringPair("w32_keyboard", "DISCL_FOREGROUND"));
165        paramList.insert(StringPair("w32_mouse", "DISCL_FOREGROUND"));
166        if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
167        {
168            // Disable Windows key plus special keys (like play, stop, next, etc.)
169            paramList.insert(StringPair("w32_keyboard", "DISCL_NOWINKEY"));
170            paramList.insert(StringPair("w32_mouse", "DISCL_EXCLUSIVE"));
171        }
172        else
173            paramList.insert(StringPair("w32_mouse", "DISCL_NONEXCLUSIVE"));
174#elif defined(ORXONOX_PLATFORM_LINUX)
175        // Enabling this is probably a bad idea, but whenever orxonox crashes, the setting stays on
176        // Trouble might be that the Pressed event occurs a bit too often...
177        paramList.insert(StringPair("XAutoRepeatOn", "true"));
178
179        if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
180        {
181            if (CommandLineParser::getValue("keyboard_no_grab").get<bool>())
182                paramList.insert(StringPair("x11_keyboard_grab", "false"));
183            else
184                paramList.insert(StringPair("x11_keyboard_grab", "true"));
185            paramList.insert(StringPair("x11_mouse_grab",  "true"));
186            paramList.insert(StringPair("x11_mouse_hide", "true"));
187        }
188        else
189        {
190            paramList.insert(StringPair("x11_keyboard_grab", "false"));
191            paramList.insert(StringPair("x11_mouse_grab",  "false"));
192            paramList.insert(StringPair("x11_mouse_hide", "false"));
193        }
194#endif
195
196        try
197        {
198            oisInputManager_ = OIS::InputManager::createInputSystem(paramList);
199            // Exception-safety
200            Loki::ScopeGuard guard = Loki::MakeGuard(OIS::InputManager::destroyInputSystem, oisInputManager_);
201            orxout(verbose, context::input) << "Created OIS input manager." << endl;
202
203            if (oisInputManager_->getNumberOfDevices(OIS::OISKeyboard) > 0)
204                devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard, oisInputManager_);
205            else
206                ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!");
207
208            // Successful initialisation
209            guard.Dismiss();
210        }
211        catch (const std::exception& ex)
212        {
213            oisInputManager_ = NULL;
214            internalState_ |= Bad;
215            ThrowException(InitialisationFailed, "Could not initialise the input system: " << ex.what());
216        }
217
218        this->loadMouse();
219        this->loadJoySticks();
220        this->loadWiiMote();
221        // Reorder states in case some joy sticks were added/removed
222        this->updateActiveStates();
223
224        orxout(verbose, context::input) << "Input devices loaded." << endl;
225    }
226
227    void InputManager::loadWiiMote()
228    {
229
230        CWii wii; // Defaults to 4 remotes
231        std::vector< ::CWiimote>::iterator i;
232        int reloadWiimotes = 0;
233        int index;
234
235        // Find and connect to the wiimotes
236        std::vector<CWiimote>& wiimotes = wii.FindAndConnect();
237        if (!wiimotes.size())
238        {
239                cout << "No wiimotes found." << endl;
240                }
241
242            // Setup the wiimotes
243            for(index = 0, i = wiimotes.begin(); i != wiimotes.end(); ++i, ++index)
244            {
245                // Use a reference to make working with the iterator handy.
246            CWiimote & wiimote = *i;
247
248            //Set Leds
249            int LED_MAP[4] =
250              {CWiimote::LED_1, CWiimote::LED_2,
251               CWiimote::LED_3, CWiimote::LED_4};
252            wiimote.SetLEDs(LED_MAP[index]);
253
254
255        }
256            try
257            {
258              orxout()<< "Size of devices vector before wiimote insertion:" << devices_.size() << std::endl;
259              devices_.push_back(new WiiMote(devices_.size(), *(new CWiimote())));
260              //devices_[2] = new WiiMote(devices_.size(), *(new CWiimote()));
261              orxout()<< "Size of devices vector after wiimote insertion:" << devices_.size() << std::endl;
262
263            }
264            catch(std::exception& e)  //gotta catch em all
265            {
266              orxout()<<"Exception loading WiiMote!!!1!11!";
267            }
268
269    }
270    //! Creates a new orxonox::Mouse
271    void InputManager::loadMouse()
272    {
273        if (oisInputManager_->getNumberOfDevices(OIS::OISMouse) > 0)
274        {
275            try
276            {
277                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_);
278            }
279            catch (const std::exception& ex)
280            {
281                orxout(user_warning, context::input) << "Failed to create Mouse:" << ex.what() << '\n'
282                                                     << "Proceeding without mouse support." << endl;
283            }
284        }
285        else
286            orxout(user_warning, context::input) << "No mouse found! Proceeding without mouse support." << endl;
287    }
288
289    //! Creates as many joy sticks as are available.
290    void InputManager::loadJoySticks()
291    {
292        for (int i = 0; i < oisInputManager_->getNumberOfDevices(OIS::OISJoyStick); i++)
293        {
294            try
295            {
296                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i, oisInputManager_));
297            }
298            catch (const std::exception& ex)
299            {
300                orxout(user_warning, context::input) << "Failed to create joy stick: " << ex.what() << endl;
301            }
302        }
303
304        // inform all JoyStick Device Number Listeners
305        std::vector<JoyStick*> joyStickList;
306        for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
307            joyStickList.push_back(static_cast<JoyStick*>(devices_[i]));
308        JoyStickQuantityListener::changeJoyStickQuantity(joyStickList);
309    }
310
311    // ############################################################
312    // #####                    Destruction                   #####
313    // ##########                                        ##########
314    // ############################################################
315
316    InputManager::~InputManager()
317    {
318        orxout(internal_status, context::input) << "InputManager: Destroying..." << endl;
319
320        // Leave all active InputStates (except "empty")
321        while (this->activeStates_.size() > 1)
322            this->leaveState(this->activeStates_.rbegin()->second->getName());
323        this->activeStates_.clear();
324
325        // Destroy calibrator helper handler and state
326        this->destroyState("calibrator");
327        // Destroy KeyDetector and state
328        delete calibratorCallbackHandler_;
329        // Destroy the empty InputState
330        this->destroyStateInternal(this->emptyState_);
331
332        // Destroy all user InputStates
333        while (statesByName_.size() > 0)
334            this->destroyStateInternal(statesByName_.rbegin()->second);
335
336        if (!(internalState_ & Bad))
337            this->destroyDevices();
338
339        // Reset console commands
340        ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(0);
341        ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(0);
342
343        orxout(internal_status, context::input) << "InputManager: Destruction complete." << endl;
344    }
345
346    /**
347    @brief
348        Destoys all input devices (joy sticks, mouse, keyboard and OIS::InputManager)
349    @throw
350        Method does not throw
351    */
352    void InputManager::destroyDevices()
353    {
354        orxout(verbose, context::input) << "InputManager: Destroying devices..." << endl;
355
356        BOOST_FOREACH(InputDevice*& device, devices_)
357        {
358            if (device == NULL)
359                continue;
360            const std::string& className = device->getClassName();
361            delete device;
362            device = 0;
363            orxout(verbose, context::input) << className << " destroyed." << endl;
364        }
365        devices_.resize(InputDeviceEnumerator::FirstJoyStick);
366
367        assert(oisInputManager_ != NULL);
368        try
369        {
370            OIS::InputManager::destroyInputSystem(oisInputManager_);
371        }
372        catch (const OIS::Exception& ex)
373        {
374            orxout(internal_error, context::input) << "OIS::InputManager destruction failed" << ex.eText << '\n'
375                                                   << "Potential resource leak!" << endl;
376        }
377        oisInputManager_ = NULL;
378
379        internalState_ |= Bad;
380        orxout(verbose, context::input) << "Destroyed devices." << endl;
381    }
382
383    // ############################################################
384    // #####                     Reloading                    #####
385    // ##########                                        ##########
386    // ############################################################
387
388    void InputManager::reload()
389    {
390        if (internalState_ & Calibrating)
391            orxout(internal_warning, context::input) << "Cannot reload input system. Joy sticks are currently being calibrated." << endl;
392        else
393            reloadInternal();
394    }
395
396    //! Internal reload method. Destroys the OIS devices and loads them again.
397    void InputManager::reloadInternal()
398    {
399        orxout(verbose, context::input) << "InputManager: Reloading ..." << endl;
400
401        this->destroyDevices();
402        this->loadDevices();
403
404        internalState_ &= ~Bad;
405        orxout(verbose, context::input) << "InputManager: Reloading complete." << endl;
406    }
407
408    // ############################################################
409    // #####                  Runtime Methods                 #####
410    // ##########                                        ##########
411    // ############################################################
412
413    void InputManager::preUpdate(const Clock& time)
414    {
415        if (internalState_ & Bad)
416            ThrowException(General, "InputManager was not correctly reloaded.");
417
418        // check whether a state has changed its EMPTY situation
419        bool bUpdateRequired = false;
420        for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
421        {
422            if (it->second->hasExpired())
423            {
424                it->second->resetExpiration();
425                bUpdateRequired = true;
426            }
427        }
428        if (bUpdateRequired)
429            updateActiveStates();
430
431        // Capture all the input and collect the function calls
432        // No event gets triggered here yet!
433        BOOST_FOREACH(InputDevice* device, devices_)
434            if (device != NULL)
435                device->update(time);
436
437        // Collect function calls for the update
438        for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
439            activeStatesTicked_[i]->update(time.getDeltaTime());
440
441        // Execute all cached function calls in order
442        // Why so complicated? The problem is that an InputHandler could trigger
443        // a reload that would destroy the OIS devices or it could even leave and
444        // then destroy its own InputState. That would of course lead to access
445        // violations.
446        // If we delay the calls, then OIS and and the InputStates are not anymore
447        // in the call stack and can therefore be edited.
448        for (size_t i = 0; i < this->callBuffer_.size(); ++i)
449            this->callBuffer_[i]();
450
451        this->callBuffer_.clear();
452    }
453
454    /**
455    @brief
456        Updates the currently active states (according to activeStates_) for each device.
457        Also, a list of all active states (no duplicates!) is compiled for the general preUpdate().
458    */
459    void InputManager::updateActiveStates()
460    {
461        // Calculate the stack of input states
462        // and assign it to the corresponding device
463        for (unsigned int i = 0; i < devices_.size(); ++i)
464        {
465            if (devices_[i] == NULL)
466                continue;
467            std::vector<InputState*>& states = devices_[i]->getStateListRef();
468            bool occupied = false;
469            states.clear();
470            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
471            {
472                orxout() << "Checking ID " << i <<std::endl;
473                orxout() << "Checking condition 1: " << rit->second->isInputDeviceEnabled(i) <<std::endl;
474                orxout() << "Checking condition 2: " << rit->second->bAlwaysGetsInput_ <<std::endl;
475                orxout() << "Checking condition 3: " << !occupied <<std::endl;
476                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
477                {
478                    orxout() << "Success with ID " << i <<std::endl;
479                    states.push_back(rit->second);
480                    if (!rit->second->bTransparent_)
481                        occupied = true;
482                }
483            }
484        }
485
486        // See that we only update each InputState once for each device
487        // Using an std::set to avoid duplicates
488        std::set<InputState*> tempSet;
489        for (unsigned int i = 0; i < devices_.size(); ++i)
490            if (devices_[i] != NULL)
491                for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState)
492                    tempSet.insert(devices_[i]->getStateListRef()[iState]);
493
494        // Copy the content of the std::set back to the actual vector
495        activeStatesTicked_.clear();
496        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
497            activeStatesTicked_.push_back(*it);
498
499        // Check whether we have to change the mouse mode
500        tribool requestedMode = dontcare;
501        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
502        if (mouseStates.empty())
503            requestedMode = false;
504        else
505            requestedMode = mouseStates.front()->getMouseExclusive();
506        if (requestedMode != dontcare && exclusiveMouse_ != requestedMode)
507        {
508            assert(requestedMode != dontcare);
509            exclusiveMouse_ = (requestedMode == true);
510            if (!GraphicsManager::getInstance().isFullScreen())
511                this->reloadInternal();
512        }
513    }
514
515    void InputManager::clearBuffers()
516    {
517        BOOST_FOREACH(InputDevice* device, devices_)
518            if (device != NULL)
519                device->clearBuffers();
520    }
521
522    void InputManager::calibrate()
523    {
524        orxout(message) << "Move all joy stick axes fully in all directions." << '\n'
525                        << "When done, put the axex in the middle position and press enter." << endl;
526
527        BOOST_FOREACH(InputDevice* device, devices_)
528            if (device != NULL)
529                device->startCalibration();
530
531        internalState_ |= Calibrating;
532        enterState("calibrator");
533    }
534
535    //! Tells all devices to stop the calibration and evaluate it. Buffers are being cleared as well!
536    void InputManager::stopCalibration()
537    {
538        BOOST_FOREACH(InputDevice* device, devices_)
539            if (device != NULL)
540                device->stopCalibration();
541
542        // restore old input state
543        leaveState("calibrator");
544        internalState_ &= ~Calibrating;
545        // Clear buffers to prevent button hold events
546        this->clearBuffers();
547
548        orxout(message) << "Calibration has been stored." << endl;
549    }
550
551    //! Gets called by WindowEventListener upon focus change --> clear buffers
552    void InputManager::windowFocusChanged(bool bFocus)
553    {
554        this->clearBuffers();
555    }
556
557    std::pair<int, int> InputManager::getMousePosition() const
558    {
559        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
560        if (mouse != NULL)
561        {
562            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
563            return std::make_pair(state.X.abs, state.Y.abs);
564        }
565        else
566            return std::make_pair(0, 0);
567    }
568
569    // ############################################################
570    // #####                    Input States                  #####
571    // ##########                                        ##########
572    // ############################################################
573
574    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
575    {
576        if (name.empty())
577            return 0;
578        if (statesByName_.find(name) == statesByName_.end())
579        {
580            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
581            {
582                // Make sure we don't add two high priority states with the same priority
583                for (std::map<std::string, InputState*>::const_iterator it = this->statesByName_.begin();
584                    it != this->statesByName_.end(); ++it)
585                {
586                    if (it->second->getPriority() == priority)
587                    {
588                        orxout(internal_warning, context::input) << "Could not add an InputState with the same priority '"
589                            << static_cast<int>(priority) << "' != 0." << endl;
590                        return 0;
591                    }
592                }
593            }
594            InputState* state = new InputState(name, bAlwaysGetsInput, bTransparent, priority);
595            statesByName_[name] = state;
596
597            return state;
598        }
599        else
600        {
601            orxout(internal_warning, context::input) << "Could not add an InputState with the same name '" << name << "'." << endl;
602            return 0;
603        }
604    }
605
606    InputState* InputManager::getState(const std::string& name)
607    {
608        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
609        if (it != statesByName_.end())
610            return it->second;
611        else
612            return 0;
613    }
614
615    bool InputManager::enterState(const std::string& name)
616    {
617        // get pointer from the map with all stored handlers
618        std::map<std::string, InputState*>::const_iterator it = statesByName_.find(name);
619        if (it != statesByName_.end() && activeStates_.find(it->second->getPriority()) == activeStates_.end())
620        {
621            // exists and not active
622            if (it->second->getPriority() == 0)
623            {
624                // Get smallest possible priority between 1 and maxStateStackSize_s
625                for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
626                    rit != activeStates_.rend(); ++rit)
627                {
628                    if (rit->first < InputStatePriority::HighPriority)
629                    {
630                        it->second->setPriority(rit->first + 1);
631                        break;
632                    }
633                }
634                // In case no normal handler was on the stack
635                if (it->second->getPriority() == 0)
636                    it->second->setPriority(1);
637            }
638            activeStates_[it->second->getPriority()] = it->second;
639            updateActiveStates();
640            it->second->entered();
641
642            return true;
643        }
644        return false;
645    }
646
647    bool InputManager::leaveState(const std::string& name)
648    {
649        if (name == "empty")
650        {
651            orxout(internal_warning, context::input) << "InputManager: Leaving the empty state is not allowed!" << endl;
652            return false;
653        }
654        // get pointer from the map with all stored handlers
655        std::map<std::string, InputState*>::const_iterator it = statesByName_.find(name);
656        if (it != statesByName_.end() && activeStates_.find(it->second->getPriority()) != activeStates_.end())
657        {
658            // exists and active
659
660            it->second->left();
661
662            activeStates_.erase(it->second->getPriority());
663            if (it->second->getPriority() < InputStatePriority::HighPriority)
664                it->second->setPriority(0);
665            updateActiveStates();
666
667            return true;
668        }
669        return false;
670    }
671
672    bool InputManager::destroyState(const std::string& name)
673    {
674        if (name == "empty")
675        {
676            orxout(internal_warning, context::input) << "InputManager: Removing the empty state is not allowed!" << endl;
677            return false;
678        }
679        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
680        if (it != statesByName_.end())
681        {
682            this->leaveState(name);
683            destroyStateInternal(it->second);
684
685            return true;
686        }
687        return false;
688    }
689
690    //! Destroys an InputState internally.
691    void InputManager::destroyStateInternal(InputState* state)
692    {
693        assert(state && this->activeStates_.find(state->getPriority()) == this->activeStates_.end());
694        statesByName_.erase(state->getName());
695        delete state;
696    }
697
698    bool InputManager::setMouseExclusive(const std::string& name, tribool value)
699    {
700        if (name == "empty")
701        {
702            orxout(internal_warning, context::input) << "InputManager: Changing the empty state is not allowed!" << endl;
703            return false;
704        }
705        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
706        if (it != statesByName_.end())
707        {
708            it->second->setMouseExclusive(value);
709            return true;
710        }
711        return false;
712    }
713}
Note: See TracBrowser for help on using the repository browser.