Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/InputManager.cc @ 5738

Last change on this file since 5738 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

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