Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 6, 2009, 1:59:00 AM (16 years ago)
Author:
landauf
Message:

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

Location:
code/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/input/CalibratorCallback.h

    r1755 r2896  
    5252        void keyHeld    (const KeyEvent& evt) { }
    5353
    54         void tickInput(float dt) { }
     54        void updateInput(float dt) { }
    5555    };
    5656}
  • code/trunk/src/core/input/ExtendedInputState.cc

    r2773 r2896  
    402402    }
    403403
    404     void ExtendedInputState::tickInput(float dt)
     404    void ExtendedInputState::updateInput(float dt)
    405405    {
    406406        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
    407407        {
    408             allHandlers_[i]->tickInput(dt);
    409         }
    410     }
    411 
    412     void ExtendedInputState::tickInput(float dt, unsigned int device)
     408            allHandlers_[i]->updateInput(dt);
     409        }
     410    }
     411
     412    void ExtendedInputState::updateInput(float dt, unsigned int device)
    413413    {
    414414        switch (device)
     
    416416        case Keyboard:
    417417            for (unsigned int i = 0; i < keyHandlers_.size(); ++i)
    418                 keyHandlers_[i]->tickKey(dt);
     418                keyHandlers_[i]->updateKey(dt);
    419419            break;
    420420
    421421        case Mouse:
    422422            for (unsigned int i = 0; i < mouseHandlers_.size(); ++i)
    423                 mouseHandlers_[i]->tickMouse(dt);
     423                mouseHandlers_[i]->updateMouse(dt);
    424424            break;
    425425
    426426        default: // joy sticks
    427427            for (unsigned int i = 0; i < joyStickHandlers_[device - 2].size(); ++i)
    428                 joyStickHandlers_[device - 2][i]->tickJoyStick(dt, device - 2);
     428                joyStickHandlers_[device - 2][i]->updateJoyStick(dt, device - 2);
    429429            break;
    430430        }
  • code/trunk/src/core/input/ExtendedInputState.h

    r1887 r2896  
    6868        ~ExtendedInputState() { }
    6969
    70         void tickInput(float dt);
    71         void tickInput(float dt, unsigned int device);
     70        void updateInput(float dt);
     71        void updateInput(float dt, unsigned int device);
    7272
    7373        void keyPressed (const KeyEvent& evt);
  • code/trunk/src/core/input/InputBuffer.cc

    r2662 r2896  
    224224
    225225    /**
    226         @brief This tick() function is called by the InputManager if the InputBuffer is active.
     226        @brief This update() function is called by the InputManager if the InputBuffer is active.
    227227        @param dt Delta time
    228228    */
    229     void InputBuffer::tickInput(float dt)
     229    void InputBuffer::updateInput(float dt)
    230230    {
    231231        timeSinceKeyPressed_ += dt;
  • code/trunk/src/core/input/InputBuffer.h

    r2662 r2896  
    127127                for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
    128128                {
    129                     InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it);
     129                    InputBufferListenerTuple<T>* refListener = static_cast<InputBufferListenerTuple<T>*>(*it);
    130130                    if (refListener && refListener->listener_ == listener)
    131131                        this->listeners_.erase(it++);
     
    171171            void processKey (const KeyEvent &e);
    172172
    173             void tickInput(float dt);
    174             void tickKey(float dt) { }
     173            void updateInput(float dt);
     174            void updateKey(float dt) { }
    175175
    176176            std::string buffer_;
  • code/trunk/src/core/input/InputInterfaces.h

    r2662 r2896  
    474474    public:
    475475        virtual ~InputHandler() { }
    476         virtual void tickInput(float dt) = 0;
     476        virtual void updateInput(float dt) = 0;
    477477    };
    478478
     
    488488        virtual void keyReleased(const KeyEvent& evt) = 0;
    489489        virtual void keyHeld    (const KeyEvent& evt) = 0;
    490         virtual void tickKey    (float dt) = 0;
     490        virtual void updateKey    (float dt) = 0;
    491491    };
    492492
     
    504504        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    505505        virtual void mouseScrolled      (int abs, int rel)     = 0;
    506         virtual void tickMouse          (float dt) = 0;
     506        virtual void updateMouse          (float dt) = 0;
    507507    };
    508508
     
    520520        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
    521521        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    522         virtual void tickJoyStick          (float dt, unsigned int joyStick) = 0;
     522        virtual void updateJoyStick          (float dt, unsigned int joyStick) = 0;
    523523    };
    524524
     
    531531        virtual ~EmptyHandler() { }
    532532
    533         void tickInput(float dt) { }
    534         void tickJoyStick(float dt, unsigned int joyStick) { }
    535         void tickMouse(float dt) { }
    536         void tickKey(float dt) { }
     533        void updateInput(float dt) { }
     534        void updateJoyStick(float dt, unsigned int joyStick) { }
     535        void updateMouse(float dt) { }
     536        void updateKey(float dt) { }
    537537
    538538        void keyPressed (const KeyEvent& evt) { }
  • code/trunk/src/core/input/InputManager.cc

    r2662 r2896  
    4343
    4444#include "util/Exception.h"
     45#include "core/Clock.h"
    4546#include "core/CoreIncludes.h"
    4647#include "core/ConfigValueIncludes.h"
     
    108109        , internalState_(Uninitialised)
    109110        , stateEmpty_(0)
    110         , stateMaster_(0)
    111111        , keyDetector_(0)
    112112        , calibratorCallbackBuffer_(0)
     
    173173            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
    174174            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    175 #if defined OIS_LINUX_PLATFORM
     175#if defined ORXONOX_PLATFORM_LINUX
    176176            paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    177177            paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
     
    218218
    219219            // Lowest priority empty InputState
    220             stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
     220            stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty);
    221221            stateEmpty_->setHandler(&EMPTY_HANDLER);
    222222            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    223223
    224             // Always active master InputState
    225             stateMaster_ = new ExtendedInputState();
    226             stateMaster_->setName("master");
    227             stateMaster_->setNumOfJoySticks(joySticksSize_);
    228 
    229224            // KeyDetector to evaluate a pressed key's name
    230             SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
     225            SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector);
    231226            keyDetector_ = new KeyDetector();
    232227            detector->setHandler(keyDetector_);
    233228
    234229            // Joy stick calibration helper callback
    235             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);
     230            SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);
    236231            calibrator->setHandler(&EMPTY_HANDLER);
    237232            calibratorCallbackBuffer_ = new InputBuffer();
     
    424419
    425420        // state management
    426         activeStatesTop_.resize(devicesNum_);
     421        activeStatesTriggered_.resize(devicesNum_);
    427422
    428423        // inform all states
    429         for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    430             it != inputStatesByPriority_.end(); ++it)
     424        for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin();
     425            it != inputStatesByName_.end(); ++it)
    431426        {
    432427            it->second->setNumOfJoySticks(joySticksSize_);
    433428        }
    434         // inform master state
    435         if (stateMaster_)
    436             this->stateMaster_->setNumOfJoySticks(joySticksSize_);
    437429
    438430        // inform all JoyStick Device Number Listeners
     
    454446        }
    455447    }
    456    
     448
    457449    void InputManager::_startCalibration()
    458450    {
     
    549541                // destroy the empty InputState
    550542                _destroyState(this->stateEmpty_);
    551                 // destroy the master input state. This might trigger a memory leak
    552                 // because the user has forgotten to destroy the KeyBinder or any Handler!
    553                 delete stateMaster_;
    554543
    555544                // destroy all user InputStates
    556                 while (inputStatesByPriority_.size() > 0)
    557                     _destroyState((*inputStatesByPriority_.rbegin()).second);
     545                while (inputStatesByName_.size() > 0)
     546                    _destroyState((*inputStatesByName_.rbegin()).second);
    558547
    559548                // destroy the devices
     
    639628            _updateActiveStates();
    640629        }
    641         inputStatesByPriority_.erase(state->getPriority());
    642630        inputStatesByName_.erase(state->getName());
    643631        delete state;
     
    670658    @brief
    671659        Public interface. Only reloads immediately if the call stack doesn't
    672         include the tick() method.
     660        include the update() method.
    673661    @param joyStickSupport
    674662        Whether or not to initialise joy sticks as well.
     
    742730    @brief
    743731        Updates the states and the InputState situation.
    744     @param dt
    745         Delta time
    746     */
    747     void InputManager::tick(float dt)
     732    @param time
     733        Clock holding the current time.
     734    */
     735    void InputManager::update(const Clock& time)
    748736    {
    749737        if (internalState_ == Uninitialised)
     
    759747        if (!stateLeaveRequests_.empty())
    760748        {
    761             for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
    762                 rit != stateLeaveRequests_.rend(); ++rit)
    763             {
    764                 (*rit)->onLeave();
     749            for (std::set<InputState*>::iterator it = stateLeaveRequests_.begin();
     750                it != stateLeaveRequests_.end(); ++it)
     751            {
     752                (*it)->onLeave();
    765753                // just to be sure that the state actually is registered
    766                 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    767 
    768                 activeStates_.erase((*rit)->getPriority());
     754                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     755
     756                activeStates_.erase((*it)->getPriority());
     757                if ((*it)->getPriority() < InputStatePriority::HighPriority)
     758                    (*it)->setPriority(0);
    769759                _updateActiveStates();
    770760            }
     
    775765        if (!stateEnterRequests_.empty())
    776766        {
    777             for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
    778                 rit != stateEnterRequests_.rend(); ++rit)
     767            for (std::set<InputState*>::const_iterator it = stateEnterRequests_.begin();
     768                it != stateEnterRequests_.end(); ++it)
    779769            {
    780770                // just to be sure that the state actually is registered
    781                 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    782 
    783                 activeStates_[(*rit)->getPriority()] = (*rit);
     771                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     772
     773                if ((*it)->getPriority() == 0)
     774                {
     775                    // Get smallest possible priority between 1 and maxStateStackSize_s
     776#if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator
     777                    for(std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
     778                        rit != activeStates_.rend(); ++rit)
     779#else
     780                    for(std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin();
     781                        rit != activeStates_.rend(); ++rit)
     782#endif
     783                    {
     784                        if (rit->first < InputStatePriority::HighPriority)
     785                        {
     786                            (*it)->setPriority(rit->first + 1);
     787                            break;
     788                        }
     789                    }
     790                    // In case no normal handler was on the stack
     791                    if ((*it)->getPriority() == 0)
     792                        (*it)->setPriority(1);
     793                }
     794                activeStates_[(*it)->getPriority()] = (*it);
    784795                _updateActiveStates();
    785                 (*rit)->onEnter();
     796                (*it)->onEnter();
    786797            }
    787798            stateEnterRequests_.clear();
     
    791802        if (!stateDestroyRequests_.empty())
    792803        {
    793             for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
    794                 rit != stateDestroyRequests_.rend(); ++rit)
    795             {
    796                 _destroyState((*rit));
     804            for (std::set<InputState*>::iterator it = stateDestroyRequests_.begin();
     805                it != stateDestroyRequests_.end(); ++it)
     806            {
     807                _destroyState((*it));
    797808            }
    798809            stateDestroyRequests_.clear();
     
    812823            _updateActiveStates();
    813824
    814         // mark that we capture and distribute input
     825        // mark that we now start capturing and distributing input
    815826        internalState_ |= Ticking;
    816827
     
    829840            {
    830841                KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
    831                 activeStatesTop_[Keyboard]->keyHeld(kEvt);
    832                 stateMaster_->keyHeld(kEvt);
     842
     843                for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     844                    activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt);
    833845            }
    834846
     
    836848            for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    837849            {
    838                 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    839                 stateMaster_->mouseButtonHeld(mouseButtonsDown_[iButton]);
     850                for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     851                    activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    840852            }
    841853
     
    844856                for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    845857                {
    846                     activeStatesTop_[JoyStick0 + iJoyStick]
    847                         ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    848                     stateMaster_->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     858                    for (unsigned int iState = 0; iState < activeStatesTriggered_[JoyStick0 + iJoyStick].size(); ++iState)
     859                        activeStatesTriggered_[JoyStick0 + iJoyStick][iState]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    849860                }
    850861
    851             // tick the handlers for each active handler
     862            // update the handlers for each active handler
    852863            for (unsigned int i = 0; i < devicesNum_; ++i)
    853864            {
    854                 activeStatesTop_[i]->tickInput(dt, i);
    855                 if (stateMaster_->isInputDeviceEnabled(i))
    856                     stateMaster_->tickInput(dt, i);
    857             }
    858 
    859             // tick the handler with a general tick afterwards
     865                for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     866                    activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i);
     867            }
     868
     869            // update the handler with a general tick afterwards
    860870            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    861                 activeStatesTicked_[i]->tickInput(dt);
    862             stateMaster_->tickInput(dt);
     871                activeStatesTicked_[i]->updateInput(time.getDeltaTime());
    863872        }
    864873
     
    869878    @brief
    870879        Updates the currently active states (according to activeStates_) for each device.
    871         Also, a list of all active states (no duplicates!) is compiled for the general tick.
     880        Also, a list of all active states (no duplicates!) is compiled for the general update().
    872881    */
    873882    void InputManager::_updateActiveStates()
    874883    {
    875         for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    876             for (unsigned int i = 0; i < devicesNum_; ++i)
    877                 if (it->second->isInputDeviceEnabled(i))
    878                     activeStatesTop_[i] = it->second;
     884        for (unsigned int i = 0; i < devicesNum_; ++i)
     885        {
     886            bool occupied = false;
     887            activeStatesTriggered_[i].clear();
     888#if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator
     889            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     890            {
     891#else
     892            for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     893            {
     894#endif
     895                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
     896                {
     897                    activeStatesTriggered_[i].push_back(rit->second);
     898                    if (!rit->second->bTransparent_)
     899                        occupied = true;
     900                }
     901            }
     902        }
    879903
    880904        // update tickables (every state will only appear once)
     
    882906        std::set<InputState*> tempSet;
    883907        for (unsigned int i = 0; i < devicesNum_; ++i)
    884             tempSet.insert(activeStatesTop_[i]);
    885 
    886         // copy the content of the set back to the actual vector
     908            for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     909                tempSet.insert(activeStatesTriggered_[i][iState]);
     910
     911        // copy the content of the std::set back to the actual vector
    887912        activeStatesTicked_.clear();
    888913        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
     
    942967
    943968        KeyEvent kEvt(e, keyboardModifiers_);
    944         activeStatesTop_[Keyboard]->keyPressed(kEvt);
    945         stateMaster_->keyPressed(kEvt);
     969        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     970            activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt);
    946971
    947972        return true;
     
    9751000
    9761001        KeyEvent kEvt(e, keyboardModifiers_);
    977         activeStatesTop_[Keyboard]->keyReleased(kEvt);
    978         stateMaster_->keyReleased(kEvt);
     1002        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     1003            activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt);
    9791004
    9801005        return true;
     
    9981023            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    9991024            IntVector2 clippingSize(e.state.width, e.state.height);
    1000             activeStatesTop_[Mouse]->mouseMoved(abs, rel, clippingSize);
    1001             stateMaster_->mouseMoved(abs, rel, clippingSize);
     1025            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1026                activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize);
    10021027        }
    10031028
     
    10051030        if (e.state.Z.rel != 0)
    10061031        {
    1007             activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    1008             stateMaster_->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
     1032            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1033                activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    10091034        }
    10101035
     
    10291054            mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
    10301055
    1031         activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    1032         stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id);
     1056        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1057            activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    10331058
    10341059        return true;
     
    10551080        }
    10561081
    1057         activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    1058         stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id);
     1082        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1083            activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    10591084
    10601085        return true;
     
    10921117            buttonsDown.push_back((JoyStickButtonCode::ByEnum)button);
    10931118
    1094         activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1095         stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1119        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1120            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    10961121
    10971122        return true;
     
    11131138        }
    11141139
    1115         activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1116         stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1140        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1141            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    11171142
    11181143        return true;
     
    11411166                fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis];
    11421167
    1143             activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);
    1144             stateMaster_->joyStickAxisMoved(iJoyStick, axis, fValue);
     1168            for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1169                activeStatesTriggered_[2 + iJoyStick][iState]->joyStickAxisMoved(iJoyStick, axis, fValue);
    11451170        }
    11461171    }
     
    12451270        Unique name of the handler.
    12461271    @param priority
    1247         Unique integer number. Higher means more prioritised.
     1272        Determines which InputState gets the input. Higher is better.
     1273        Use 0 to handle it implicitely by the order of activation.
     1274        Otherwise numbers larger than maxStateStackSize_s have to be used!
    12481275    @return
    12491276        True if added, false if name or priority already existed.
    12501277    */
    1251     bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)
     1278    bool InputManager::_configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority)
    12521279    {
    12531280        if (name == "")
     
    12571284        if (inputStatesByName_.find(name) == inputStatesByName_.end())
    12581285        {
    1259             if (inputStatesByPriority_.find(priority)
    1260                 == inputStatesByPriority_.end())
    1261             {
    1262                 inputStatesByName_[name] = state;
    1263                 inputStatesByPriority_[priority] = state;
    1264                 state->setNumOfJoySticks(numberOfJoySticks());
    1265                 state->setName(name);
     1286            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
     1287            {
     1288                // Make sure we don't add two high priority states with the same priority
     1289                for (std::map<std::string, InputState*>::const_iterator it = this->inputStatesByName_.begin();
     1290                    it != this->inputStatesByName_.end(); ++it)
     1291                {
     1292                    if (it->second->getPriority() == priority)
     1293                    {
     1294                        COUT(2) << "Warning: Could not add an InputState with the same priority '"
     1295                            << priority << "' != 0." << std::endl;
     1296                        return false;
     1297                    }
     1298                }
     1299            }
     1300            inputStatesByName_[name] = state;
     1301            state->setNumOfJoySticks(numberOfJoySticks());
     1302            state->setName(name);
     1303            state->bAlwaysGetsInput_ = bAlwaysGetsInput;
     1304            state->bTransparent_ = bTransparent;
     1305            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
    12661306                state->setPriority(priority);
    1267                 return true;
    1268             }
    1269             else
    1270             {
    1271                 COUT(2) << "Warning: Could not add an InputState with the same priority '"
    1272                     << priority << "'." << std::endl;
    1273                 return false;
    1274             }
     1307            return true;
    12751308        }
    12761309        else
     
    12901323    @remarks
    12911324        You can't remove the internal states "empty", "calibrator" and "detector".
    1292         The removal process is being postponed if InputManager::tick() is currently running.
     1325        The removal process is being postponed if InputManager::update() is currently running.
    12931326    */
    12941327    bool InputManager::requestDestroyState(const std::string& name)
     
    13711404                {
    13721405                    // not scheduled for destruction
    1373                     // set prevents a state being added multiple times
     1406                    // prevents a state being added multiple times
    13741407                    stateEnterRequests_.insert(it->second);
    13751408                    return true;
     
    13901423    bool InputManager::requestLeaveState(const std::string& name)
    13911424    {
     1425        if (name == "empty")
     1426        {
     1427            COUT(2) << "InputManager: Leaving the empty state is not allowed!" << std::endl;
     1428            return false;
     1429        }
    13921430        // get pointer from the map with all stored handlers
    13931431        std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
  • code/trunk/src/core/input/InputManager.h

    r2662 r2896  
    4343#include <stack>
    4444#include "util/Math.h"
     45#include "util/OrxEnum.h"
    4546#include "core/OrxonoxClass.h"
    4647#include "InputInterfaces.h"
     
    7475        float positiveCoeff[24];
    7576        float negativeCoeff[24];
     77    };
     78
     79    struct InputStatePriority : OrxEnum<InputStatePriority>
     80    {
     81        OrxEnumConstructors(InputStatePriority);
     82
     83        static const int Empty        = -1;
     84        static const int Dynamic      = 0;
     85
     86        static const int HighPriority = 1000;
     87        static const int Console      = HighPriority + 0;
     88        static const int Calibrator   = HighPriority + 1;
     89        static const int Detector     = HighPriority + 2;
    7690    };
    7791
     
    116130
    117131        template <class T>
    118         T* createInputState(const std::string& name, int priority);
     132        T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    119133
    120134        InputState* getState       (const std::string& name);
    121135        InputState* getCurrentState();
    122         ExtendedInputState* getMasterInputState() { return this->stateMaster_; }
    123136        bool requestDestroyState   (const std::string& name);
    124137        bool requestEnterState     (const std::string& name);
    125138        bool requestLeaveState     (const std::string& name);
    126139
    127         void tick(float dt);
     140        void update(const Clock& time);
    128141
    129142        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
     
    165178
    166179        void _updateActiveStates();
    167         bool _configureInputState(InputState* state, const std::string& name, int priority);
     180        bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    168181
    169182        // input events
     
    197210        // some internally handled states and handlers
    198211        SimpleInputState*                   stateEmpty_;
    199         ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    200212        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    201213        InputBuffer*                        calibratorCallbackBuffer_;
    202214
    203215        std::map<std::string, InputState*>  inputStatesByName_;
    204         std::map<int, InputState*>          inputStatesByPriority_;
    205216
    206217        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
     
    209220
    210221        std::map<int, InputState*>          activeStates_;
    211         std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
    212         std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
     222        std::vector<std::vector<InputState*> > activeStatesTriggered_;
     223        std::vector<InputState*>            activeStatesTicked_;
    213224
    214225        // joystick calibration
     
    249260    */
    250261    template <class T>
    251     T* InputManager::createInputState(const std::string& name, int priority)
     262    T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    252263    {
    253264        T* state = new T;
    254         if (_configureInputState(state, name, priority))
     265        if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
    255266            return state;
    256267        else
  • code/trunk/src/core/input/InputState.h

    r1887 r2896  
    7171        virtual void unRegisterOnLeave()                      { executorOnLeave_ = 0; }
    7272
    73         virtual void tickInput(float dt, unsigned int device) = 0;
    74         virtual void tickInput(float dt) = 0;
     73        virtual void updateInput(float dt, unsigned int device) = 0;
     74        virtual void updateInput(float dt) = 0;
    7575
    7676        virtual void keyPressed (const KeyEvent& evt) = 0;
     
    9090
    9191    protected:
    92         InputState() : bHandlersChanged_(false), priority_(0), executorOnEnter_(0), executorOnLeave_(0) { }
     92        InputState()
     93            : bHandlersChanged_(false)
     94            , priority_(0)
     95            , bAlwaysGetsInput_(false)
     96            , bTransparent_(false)
     97            , executorOnEnter_(0)
     98            , executorOnLeave_(0)
     99        { }
    93100        virtual ~InputState() { }
    94101
     
    114121        int                                         priority_;
    115122        std::vector<bool>                           bInputDeviceEnabled_;
     123        bool                                        bAlwaysGetsInput_;
     124        bool                                        bTransparent_;
    116125
    117126        Executor*                                   executorOnEnter_;
  • code/trunk/src/core/input/KeyBinder.cc

    r2713 r2896  
    4242#include "core/CoreIncludes.h"
    4343#include "core/ConfigFileManager.h"
    44 #include "core/Core.h"
    4544#include "InputCommands.h"
    4645#include "InputManager.h"
     
    309308    }
    310309
    311     void KeyBinder::tickMouse(float dt)
     310    void KeyBinder::updateMouse(float dt)
    312311    {
    313312        if (bDeriveMouseInput_)
     
    349348            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
    350349            // press a button that has relative movement, that value has to be multiplied by dt to be
    351             // frame rate independent. This can easily (and only) be done in tickInput(float).
     350            // frame rate independent. This can easily (and only) be done in updateInput(float).
    352351            // Hence we need to divide by dt here for the mouse to compensate, because the relative
    353352            // move movements have nothing to do with dt.
     
    362361    }
    363362
    364     void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     363    void KeyBinder::updateJoyStick(float dt, unsigned int joyStick)
    365364    {
    366365        for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
  • code/trunk/src/core/input/KeyBinder.h

    r2710 r2896  
    6868
    6969    protected: // functions
    70         void tickInput(float dt);
    71         void tickKey(float dt) { }
    72         void tickMouse(float dt);
    73         void tickJoyStick(float dt, unsigned int joyStick);
     70        void updateInput(float dt);
     71        void updateKey(float dt) { }
     72        void updateMouse(float dt);
     73        void updateJoyStick(float dt, unsigned int joyStick);
    7474        // internal
    7575        void tickHalfAxis(HalfAxis& halfAxis);
     
    134134        @brief
    135135            Commands that have additional parameters (axes) are executed at the end of
    136             the tick() so that all values can be buffered for single execution.
     136            update() so that all values can be buffered for single execution.
    137137        */
    138138        std::vector<BufferedParamCommand*> paramCommandBuffer_;
     
    200200    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
    201201
    202     inline void KeyBinder::tickInput(float dt)
     202    inline void KeyBinder::updateInput(float dt)
    203203    {
    204204        // execute all buffered bindings (additional parameter)
  • code/trunk/src/core/input/SimpleInputState.h

    r1887 r2896  
    5959        ~SimpleInputState() { }
    6060
    61         void tickInput(float dt);
    62         void tickInput(float dt, unsigned int device);
     61        void updateInput(float dt);
     62        void updateInput(float dt, unsigned int device);
    6363
    6464        void keyPressed (const KeyEvent& evt);
     
    8787    };
    8888
    89     inline void SimpleInputState::tickInput(float dt)
     89    inline void SimpleInputState::updateInput(float dt)
    9090    {
    9191        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
    9292        {
    93             allHandlers_[i]->tickInput(dt);
     93            allHandlers_[i]->updateInput(dt);
    9494        }
    9595    }
    9696
    97     inline void SimpleInputState::tickInput(float dt, unsigned int device)
     97    inline void SimpleInputState::updateInput(float dt, unsigned int device)
    9898    {
    9999        switch (device)
     
    101101        case InputDevice::Keyboard:
    102102            if (keyHandler_)
    103                 keyHandler_->tickKey(dt);
     103                keyHandler_->updateKey(dt);
    104104            break;
    105105
    106106        case InputDevice::Mouse:
    107107            if (mouseHandler_)
    108                 mouseHandler_->tickMouse(dt);
     108                mouseHandler_->updateMouse(dt);
    109109            break;
    110110
    111111        default: // joy sticks
    112112            if (joyStickHandler_[device - 2])
    113                 joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);
     113                joyStickHandler_[device - 2]->updateJoyStick(dt, device - 2);
    114114            break;
    115115        }
Note: See TracChangeset for help on using the changeset viewer.