Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9838 was 9838, checked in by georgr, 10 years ago

developing on 2 PCs is a lot of fun, bluetooth is a rare commodity… wiimote should connect properly now

  • Property svn:eol-style set to native
File size: 26.7 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(10);
237        if (!wiimotes.size())
238        {
239                cout << "No wiimotes found." << endl;
240                return;
241                }
242
243            // Setup the wiimotes
244            for(index = 0, i = wiimotes.begin(); i != wiimotes.end(); ++i, ++index)
245            {
246                // Use a reference to make working with the iterator handy.
247            CWiimote & wiimote = *i;
248
249            //Set Leds
250            int LED_MAP[4] =
251              {CWiimote::LED_1, CWiimote::LED_2,
252               CWiimote::LED_3, CWiimote::LED_4};
253            wiimote.SetLEDs(LED_MAP[index]);
254            try
255                       {
256                         orxout()<< "Size of devices vector before wiimote insertion:" << devices_.size() << std::endl;
257                         devices_.push_back(new WiiMote((unsigned int)devices_.size(), *i, wii));
258                         //devices_[2] = new WiiMote(devices_.size(), *(new CWiimote()));
259                         orxout()<< "Size of devices vector after wiimote insertion:" << devices_.size() << std::endl;
260
261                       }
262                       catch(std::exception& e)  //gotta catch em all
263                       {
264                         orxout()<<"Exception loading WiiMote!!!1!11!";
265                       }
266
267
268
269        }
270
271
272    }
273    //! Creates a new orxonox::Mouse
274    void InputManager::loadMouse()
275    {
276        if (oisInputManager_->getNumberOfDevices(OIS::OISMouse) > 0)
277        {
278            try
279            {
280                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_);
281            }
282            catch (const std::exception& ex)
283            {
284                orxout(user_warning, context::input) << "Failed to create Mouse:" << ex.what() << '\n'
285                                                     << "Proceeding without mouse support." << endl;
286            }
287        }
288        else
289            orxout(user_warning, context::input) << "No mouse found! Proceeding without mouse support." << endl;
290    }
291
292    //! Creates as many joy sticks as are available.
293    void InputManager::loadJoySticks()
294    {
295        for (int i = 0; i < oisInputManager_->getNumberOfDevices(OIS::OISJoyStick); i++)
296        {
297            try
298            {
299                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i, oisInputManager_));
300            }
301            catch (const std::exception& ex)
302            {
303                orxout(user_warning, context::input) << "Failed to create joy stick: " << ex.what() << endl;
304            }
305        }
306
307        // inform all JoyStick Device Number Listeners
308        std::vector<JoyStick*> joyStickList;
309        for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
310            joyStickList.push_back(static_cast<JoyStick*>(devices_[i]));
311        JoyStickQuantityListener::changeJoyStickQuantity(joyStickList);
312    }
313
314    // ############################################################
315    // #####                    Destruction                   #####
316    // ##########                                        ##########
317    // ############################################################
318
319    InputManager::~InputManager()
320    {
321        orxout(internal_status, context::input) << "InputManager: Destroying..." << endl;
322
323        // Leave all active InputStates (except "empty")
324        while (this->activeStates_.size() > 1)
325            this->leaveState(this->activeStates_.rbegin()->second->getName());
326        this->activeStates_.clear();
327
328        // Destroy calibrator helper handler and state
329        this->destroyState("calibrator");
330        // Destroy KeyDetector and state
331        delete calibratorCallbackHandler_;
332        // Destroy the empty InputState
333        this->destroyStateInternal(this->emptyState_);
334
335        // Destroy all user InputStates
336        while (statesByName_.size() > 0)
337            this->destroyStateInternal(statesByName_.rbegin()->second);
338
339        if (!(internalState_ & Bad))
340            this->destroyDevices();
341
342        // Reset console commands
343        ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(0);
344        ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(0);
345
346        orxout(internal_status, context::input) << "InputManager: Destruction complete." << endl;
347    }
348
349    /**
350    @brief
351        Destoys all input devices (joy sticks, mouse, keyboard and OIS::InputManager)
352    @throw
353        Method does not throw
354    */
355    void InputManager::destroyDevices()
356    {
357        orxout(verbose, context::input) << "InputManager: Destroying devices..." << endl;
358
359        BOOST_FOREACH(InputDevice*& device, devices_)
360        {
361            if (device == NULL)
362                continue;
363            const std::string& className = device->getClassName();
364            delete device;
365            device = 0;
366            orxout(verbose, context::input) << className << " destroyed." << endl;
367        }
368        devices_.resize(InputDeviceEnumerator::FirstJoyStick);
369
370        assert(oisInputManager_ != NULL);
371        try
372        {
373            OIS::InputManager::destroyInputSystem(oisInputManager_);
374        }
375        catch (const OIS::Exception& ex)
376        {
377            orxout(internal_error, context::input) << "OIS::InputManager destruction failed" << ex.eText << '\n'
378                                                   << "Potential resource leak!" << endl;
379        }
380        oisInputManager_ = NULL;
381
382        internalState_ |= Bad;
383        orxout(verbose, context::input) << "Destroyed devices." << endl;
384    }
385
386    // ############################################################
387    // #####                     Reloading                    #####
388    // ##########                                        ##########
389    // ############################################################
390
391    void InputManager::reload()
392    {
393        if (internalState_ & Calibrating)
394            orxout(internal_warning, context::input) << "Cannot reload input system. Joy sticks are currently being calibrated." << endl;
395        else
396            reloadInternal();
397    }
398
399    //! Internal reload method. Destroys the OIS devices and loads them again.
400    void InputManager::reloadInternal()
401    {
402        orxout(verbose, context::input) << "InputManager: Reloading ..." << endl;
403
404        this->destroyDevices();
405        this->loadDevices();
406
407        internalState_ &= ~Bad;
408        orxout(verbose, context::input) << "InputManager: Reloading complete." << endl;
409    }
410
411    // ############################################################
412    // #####                  Runtime Methods                 #####
413    // ##########                                        ##########
414    // ############################################################
415
416    void InputManager::preUpdate(const Clock& time)
417    {
418        if (internalState_ & Bad)
419            ThrowException(General, "InputManager was not correctly reloaded.");
420
421        // check whether a state has changed its EMPTY situation
422        bool bUpdateRequired = false;
423        for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
424        {
425            if (it->second->hasExpired())
426            {
427                it->second->resetExpiration();
428                bUpdateRequired = true;
429            }
430        }
431        if (bUpdateRequired)
432            updateActiveStates();
433
434        // Capture all the input and collect the function calls
435        // No event gets triggered here yet!
436        BOOST_FOREACH(InputDevice* device, devices_)
437            if (device != NULL)
438                device->update(time);
439
440        // Collect function calls for the update
441        for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
442            activeStatesTicked_[i]->update(time.getDeltaTime());
443
444        // Execute all cached function calls in order
445        // Why so complicated? The problem is that an InputHandler could trigger
446        // a reload that would destroy the OIS devices or it could even leave and
447        // then destroy its own InputState. That would of course lead to access
448        // violations.
449        // If we delay the calls, then OIS and and the InputStates are not anymore
450        // in the call stack and can therefore be edited.
451        for (size_t i = 0; i < this->callBuffer_.size(); ++i)
452            this->callBuffer_[i]();
453
454        this->callBuffer_.clear();
455    }
456
457    /**
458    @brief
459        Updates the currently active states (according to activeStates_) for each device.
460        Also, a list of all active states (no duplicates!) is compiled for the general preUpdate().
461    */
462    void InputManager::updateActiveStates()
463    {
464        // Calculate the stack of input states
465        // and assign it to the corresponding device
466        for (unsigned int i = 0; i < devices_.size(); ++i)
467        {
468            if (devices_[i] == NULL)
469                continue;
470            std::vector<InputState*>& states = devices_[i]->getStateListRef();
471            bool occupied = false;
472            states.clear();
473            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
474            {
475                orxout() << "Checking ID " << i <<std::endl;
476                orxout() << "Checking condition 1: " << rit->second->isInputDeviceEnabled(i) <<std::endl;
477                orxout() << "Checking condition 2: " << rit->second->bAlwaysGetsInput_ <<std::endl;
478                orxout() << "Checking condition 3: " << !occupied <<std::endl;
479                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
480                {
481                    orxout() << "Success with ID " << i <<std::endl;
482                    states.push_back(rit->second);
483                    if (!rit->second->bTransparent_)
484                        occupied = true;
485                }
486            }
487        }
488
489        // See that we only update each InputState once for each device
490        // Using an std::set to avoid duplicates
491        std::set<InputState*> tempSet;
492        for (unsigned int i = 0; i < devices_.size(); ++i)
493            if (devices_[i] != NULL)
494                for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState)
495                    tempSet.insert(devices_[i]->getStateListRef()[iState]);
496
497        // Copy the content of the std::set back to the actual vector
498        activeStatesTicked_.clear();
499        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
500            activeStatesTicked_.push_back(*it);
501
502        // Check whether we have to change the mouse mode
503        tribool requestedMode = dontcare;
504        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
505        if (mouseStates.empty())
506            requestedMode = false;
507        else
508            requestedMode = mouseStates.front()->getMouseExclusive();
509        if (requestedMode != dontcare && exclusiveMouse_ != requestedMode)
510        {
511            assert(requestedMode != dontcare);
512            exclusiveMouse_ = (requestedMode == true);
513            if (!GraphicsManager::getInstance().isFullScreen())
514                this->reloadInternal();
515        }
516    }
517
518    void InputManager::clearBuffers()
519    {
520        BOOST_FOREACH(InputDevice* device, devices_)
521            if (device != NULL)
522                device->clearBuffers();
523    }
524
525    void InputManager::calibrate()
526    {
527        orxout(message) << "Move all joy stick axes fully in all directions." << '\n'
528                        << "When done, put the axex in the middle position and press enter." << endl;
529
530        BOOST_FOREACH(InputDevice* device, devices_)
531            if (device != NULL)
532                device->startCalibration();
533
534        internalState_ |= Calibrating;
535        enterState("calibrator");
536    }
537
538    //! Tells all devices to stop the calibration and evaluate it. Buffers are being cleared as well!
539    void InputManager::stopCalibration()
540    {
541        BOOST_FOREACH(InputDevice* device, devices_)
542            if (device != NULL)
543                device->stopCalibration();
544
545        // restore old input state
546        leaveState("calibrator");
547        internalState_ &= ~Calibrating;
548        // Clear buffers to prevent button hold events
549        this->clearBuffers();
550
551        orxout(message) << "Calibration has been stored." << endl;
552    }
553
554    //! Gets called by WindowEventListener upon focus change --> clear buffers
555    void InputManager::windowFocusChanged(bool bFocus)
556    {
557        this->clearBuffers();
558    }
559
560    std::pair<int, int> InputManager::getMousePosition() const
561    {
562        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
563        if (mouse != NULL)
564        {
565            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
566            return std::make_pair(state.X.abs, state.Y.abs);
567        }
568        else
569            return std::make_pair(0, 0);
570    }
571
572    // ############################################################
573    // #####                    Input States                  #####
574    // ##########                                        ##########
575    // ############################################################
576
577    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
578    {
579        if (name.empty())
580            return 0;
581        if (statesByName_.find(name) == statesByName_.end())
582        {
583            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
584            {
585                // Make sure we don't add two high priority states with the same priority
586                for (std::map<std::string, InputState*>::const_iterator it = this->statesByName_.begin();
587                    it != this->statesByName_.end(); ++it)
588                {
589                    if (it->second->getPriority() == priority)
590                    {
591                        orxout(internal_warning, context::input) << "Could not add an InputState with the same priority '"
592                            << static_cast<int>(priority) << "' != 0." << endl;
593                        return 0;
594                    }
595                }
596            }
597            InputState* state = new InputState(name, bAlwaysGetsInput, bTransparent, priority);
598            statesByName_[name] = state;
599
600            return state;
601        }
602        else
603        {
604            orxout(internal_warning, context::input) << "Could not add an InputState with the same name '" << name << "'." << endl;
605            return 0;
606        }
607    }
608
609    InputState* InputManager::getState(const std::string& name)
610    {
611        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
612        if (it != statesByName_.end())
613            return it->second;
614        else
615            return 0;
616    }
617
618    bool InputManager::enterState(const std::string& name)
619    {
620        // get pointer from the map with all stored handlers
621        std::map<std::string, InputState*>::const_iterator it = statesByName_.find(name);
622        if (it != statesByName_.end() && activeStates_.find(it->second->getPriority()) == activeStates_.end())
623        {
624            // exists and not active
625            if (it->second->getPriority() == 0)
626            {
627                // Get smallest possible priority between 1 and maxStateStackSize_s
628                for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
629                    rit != activeStates_.rend(); ++rit)
630                {
631                    if (rit->first < InputStatePriority::HighPriority)
632                    {
633                        it->second->setPriority(rit->first + 1);
634                        break;
635                    }
636                }
637                // In case no normal handler was on the stack
638                if (it->second->getPriority() == 0)
639                    it->second->setPriority(1);
640            }
641            activeStates_[it->second->getPriority()] = it->second;
642            updateActiveStates();
643            it->second->entered();
644
645            return true;
646        }
647        return false;
648    }
649
650    bool InputManager::leaveState(const std::string& name)
651    {
652        if (name == "empty")
653        {
654            orxout(internal_warning, context::input) << "InputManager: Leaving the empty state is not allowed!" << endl;
655            return false;
656        }
657        // get pointer from the map with all stored handlers
658        std::map<std::string, InputState*>::const_iterator it = statesByName_.find(name);
659        if (it != statesByName_.end() && activeStates_.find(it->second->getPriority()) != activeStates_.end())
660        {
661            // exists and active
662
663            it->second->left();
664
665            activeStates_.erase(it->second->getPriority());
666            if (it->second->getPriority() < InputStatePriority::HighPriority)
667                it->second->setPriority(0);
668            updateActiveStates();
669
670            return true;
671        }
672        return false;
673    }
674
675    bool InputManager::destroyState(const std::string& name)
676    {
677        if (name == "empty")
678        {
679            orxout(internal_warning, context::input) << "InputManager: Removing the empty state is not allowed!" << endl;
680            return false;
681        }
682        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
683        if (it != statesByName_.end())
684        {
685            this->leaveState(name);
686            destroyStateInternal(it->second);
687
688            return true;
689        }
690        return false;
691    }
692
693    //! Destroys an InputState internally.
694    void InputManager::destroyStateInternal(InputState* state)
695    {
696        assert(state && this->activeStates_.find(state->getPriority()) == this->activeStates_.end());
697        statesByName_.erase(state->getName());
698        delete state;
699    }
700
701    bool InputManager::setMouseExclusive(const std::string& name, tribool value)
702    {
703        if (name == "empty")
704        {
705            orxout(internal_warning, context::input) << "InputManager: Changing the empty state is not allowed!" << endl;
706            return false;
707        }
708        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
709        if (it != statesByName_.end())
710        {
711            it->second->setMouseExclusive(value);
712            return true;
713        }
714        return false;
715    }
716}
Note: See TracBrowser for help on using the repository browser.