Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2816


Ignore:
Timestamp:
Mar 21, 2009, 8:47:11 PM (16 years ago)
Author:
rgrieder
Message:

Upgrade number two for the InputManager: An InputState can have two new properties. You can tell it to always receive input, no matter what the input stack actually is. Secondly there is a 'transparent' option to be kind of invisible to the other states. I have found no use yet, but three more lines weren't a big deal ;)
This change ultimately supersedes the need for a master InputState.

Location:
code/branches/gui/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/input/InputManager.cc

    r2814 r2816  
    109109        , internalState_(Uninitialised)
    110110        , stateEmpty_(0)
    111         , stateMaster_(0)
    112111        , keyDetector_(0)
    113112        , calibratorCallbackBuffer_(0)
     
    219218
    220219            // Lowest priority empty InputState
    221             stateEmpty_ = createInputState<SimpleInputState>("empty", InputStatePriority::Empty);
     220            stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty);
    222221            stateEmpty_->setHandler(&EMPTY_HANDLER);
    223222            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    224223
    225             // Always active master InputState
    226             stateMaster_ = new ExtendedInputState();
    227             stateMaster_->setName("master");
    228             stateMaster_->setNumOfJoySticks(joySticksSize_);
    229 
    230224            // KeyDetector to evaluate a pressed key's name
    231             SimpleInputState* detector = createInputState<SimpleInputState>("detector", InputStatePriority::Detector);
     225            SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector);
    232226            keyDetector_ = new KeyDetector();
    233227            detector->setHandler(keyDetector_);
    234228
    235229            // Joy stick calibration helper callback
    236             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", InputStatePriority::Calibrator);
     230            SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);
    237231            calibrator->setHandler(&EMPTY_HANDLER);
    238232            calibratorCallbackBuffer_ = new InputBuffer();
     
    425419
    426420        // state management
    427         activeStatesTop_.resize(devicesNum_);
     421        activeStatesTriggered_.resize(devicesNum_);
    428422
    429423        // inform all states
     
    433427            it->second->setNumOfJoySticks(joySticksSize_);
    434428        }
    435         // inform master state
    436         if (stateMaster_)
    437             this->stateMaster_->setNumOfJoySticks(joySticksSize_);
    438429
    439430        // inform all JoyStick Device Number Listeners
     
    550541                // destroy the empty InputState
    551542                _destroyState(this->stateEmpty_);
    552                 // destroy the master input state. This might trigger a memory leak
    553                 // because the user has forgotten to destroy the KeyBinder or any Handler!
    554                 delete stateMaster_;
    555543
    556544                // destroy all user InputStates
     
    847835            {
    848836                KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
    849                 activeStatesTop_[Keyboard]->keyHeld(kEvt);
    850                 stateMaster_->keyHeld(kEvt);
     837
     838                for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     839                    activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt);
    851840            }
    852841
     
    854843            for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    855844            {
    856                 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    857                 stateMaster_->mouseButtonHeld(mouseButtonsDown_[iButton]);
     845                for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     846                    activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    858847            }
    859848
     
    862851                for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    863852                {
    864                     activeStatesTop_[JoyStick0 + iJoyStick]
    865                         ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    866                     stateMaster_->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     853                    for (unsigned int iState = 0; iState < activeStatesTriggered_[JoyStick0 + iJoyStick].size(); ++iState)
     854                        activeStatesTriggered_[JoyStick0 + iJoyStick][iState]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    867855                }
    868856
     
    870858            for (unsigned int i = 0; i < devicesNum_; ++i)
    871859            {
    872                 activeStatesTop_[i]->updateInput(time.getDeltaTime(), i);
    873                 if (stateMaster_->isInputDeviceEnabled(i))
    874                     stateMaster_->updateInput(time.getDeltaTime(), i);
     860                for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     861                    activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i);
    875862            }
    876863
     
    878865            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    879866                activeStatesTicked_[i]->updateInput(time.getDeltaTime());
    880             stateMaster_->updateInput(time.getDeltaTime());
    881867        }
    882868
     
    891877    void InputManager::_updateActiveStates()
    892878    {
    893         for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    894             for (unsigned int i = 0; i < devicesNum_; ++i)
    895                 if (it->second->isInputDeviceEnabled(i))
    896                     activeStatesTop_[i] = it->second;
     879        for (unsigned int i = 0; i < devicesNum_; ++i)
     880        {
     881            bool occupied = false;
     882            activeStatesTriggered_[i].clear();
     883            for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     884            {
     885                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
     886                {
     887                    activeStatesTriggered_[i].push_back(rit->second);
     888                    if (!rit->second->bTransparent_)
     889                        occupied = true;
     890                }
     891            }
     892        }
    897893
    898894        // update tickables (every state will only appear once)
     
    900896        std::set<InputState*> tempSet;
    901897        for (unsigned int i = 0; i < devicesNum_; ++i)
    902             tempSet.insert(activeStatesTop_[i]);
    903 
    904         // copy the content of the set back to the actual vector
     898            for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     899                tempSet.insert(activeStatesTriggered_[i][iState]);
     900
     901        // copy the content of the std::set back to the actual vector
    905902        activeStatesTicked_.clear();
    906903        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
     
    960957
    961958        KeyEvent kEvt(e, keyboardModifiers_);
    962         activeStatesTop_[Keyboard]->keyPressed(kEvt);
    963         stateMaster_->keyPressed(kEvt);
     959        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     960            activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt);
    964961
    965962        return true;
     
    993990
    994991        KeyEvent kEvt(e, keyboardModifiers_);
    995         activeStatesTop_[Keyboard]->keyReleased(kEvt);
    996         stateMaster_->keyReleased(kEvt);
     992        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     993            activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt);
    997994
    998995        return true;
     
    10161013            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    10171014            IntVector2 clippingSize(e.state.width, e.state.height);
    1018             activeStatesTop_[Mouse]->mouseMoved(abs, rel, clippingSize);
    1019             stateMaster_->mouseMoved(abs, rel, clippingSize);
     1015            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1016                activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize);
    10201017        }
    10211018
     
    10231020        if (e.state.Z.rel != 0)
    10241021        {
    1025             activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    1026             stateMaster_->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
     1022            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1023                activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    10271024        }
    10281025
     
    10471044            mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
    10481045
    1049         activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    1050         stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id);
     1046        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1047            activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    10511048
    10521049        return true;
     
    10731070        }
    10741071
    1075         activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    1076         stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id);
     1072        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1073            activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    10771074
    10781075        return true;
     
    11101107            buttonsDown.push_back((JoyStickButtonCode::ByEnum)button);
    11111108
    1112         activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1113         stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1109        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1110            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    11141111
    11151112        return true;
     
    11311128        }
    11321129
    1133         activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1134         stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1130        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1131            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    11351132
    11361133        return true;
     
    11591156                fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis];
    11601157
    1161             activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);
    1162             stateMaster_->joyStickAxisMoved(iJoyStick, axis, fValue);
     1158            for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1159                activeStatesTriggered_[2 + iJoyStick][iState]->joyStickAxisMoved(iJoyStick, axis, fValue);
    11631160        }
    11641161    }
     
    12691266        True if added, false if name or priority already existed.
    12701267    */
    1271     bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)
     1268    bool InputManager::_configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority)
    12721269    {
    12731270        if (name == "")
     
    12941291            state->setNumOfJoySticks(numberOfJoySticks());
    12951292            state->setName(name);
     1293            state->bAlwaysGetsInput_ = bAlwaysGetsInput;
     1294            state->bTransparent_ = bTransparent;
    12961295            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
    12971296                state->setPriority(priority);
  • code/branches/gui/src/core/input/InputManager.h

    r2814 r2816  
    130130
    131131        template <class T>
    132         T* createInputState(const std::string& name, InputStatePriority priority = InputStatePriority::Dynamic);
     132        T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    133133
    134134        InputState* getState       (const std::string& name);
    135135        InputState* getCurrentState();
    136         ExtendedInputState* getMasterInputState() { return this->stateMaster_; }
    137136        bool requestDestroyState   (const std::string& name);
    138137        bool requestEnterState     (const std::string& name);
     
    179178
    180179        void _updateActiveStates();
    181         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);
    182181
    183182        // input events
     
    211210        // some internally handled states and handlers
    212211        SimpleInputState*                   stateEmpty_;
    213         ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    214212        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    215213        InputBuffer*                        calibratorCallbackBuffer_;
     
    222220
    223221        std::map<int, InputState*>          activeStates_;
    224         std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
    225         std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
     222        std::vector<std::vector<InputState*> > activeStatesTriggered_;
     223        std::vector<InputState*>            activeStatesTicked_;
    226224
    227225        // joystick calibration
     
    262260    */
    263261    template <class T>
    264     T* InputManager::createInputState(const std::string& name, InputStatePriority priority)
     262    T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    265263    {
    266264        T* state = new T;
    267         if (_configureInputState(state, name, priority))
     265        if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
    268266            return state;
    269267        else
  • code/branches/gui/src/core/input/InputState.h

    r2800 r2816  
    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/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r2805 r2816  
    3939#include "core/input/InputManager.h"
    4040#include "core/input/KeyBinder.h"
    41 #include "core/input/ExtendedInputState.h"
     41#include "core/input/SimpleInputState.h"
    4242#include "core/Loader.h"
    4343#include "core/XMLFile.h"
     
    5757        , graphicsManager_(0)
    5858        , masterKeyBinder_(0)
     59        , masterInputState_(0)
    5960        , debugOverlay_(0)
    6061    {
     
    9192        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
    9293        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
    93         // Configure master input state with a KeyBinder
     94
     95        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
    9496        masterKeyBinder_ = new KeyBinder();
    9597        masterKeyBinder_->loadBindings("masterKeybindings.ini");
    96         inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
     98        masterInputState_->setKeyHandler(masterKeyBinder_);
    9799
    98100        // Load the InGameConsole
     
    103105        guiManager_ = new GUIManager();
    104106        guiManager_->initialise(renderWindow);
     107
     108        InputManager::getInstance().requestEnterState("master");
    105109    }
    106110
    107111    void GSGraphics::leave()
    108112    {
     113        if (Core::showsGraphics())
     114            InputManager::getInstance().requestLeaveState("master");
     115
    109116        delete this->guiManager_;
    110117
     
    119126
    120127        delete graphicsManager_;
     128
     129        if (Core::showsGraphics())
     130        {
     131            masterInputState_->setHandler(0);
     132            InputManager::getInstance().requestDestroyState("master");
     133            if (this->masterKeyBinder_)
     134            {
     135                delete this->masterKeyBinder_;
     136                this->masterKeyBinder_ = 0;
     137            }
     138        }
    121139    }
    122140
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r2801 r2816  
    6565
    6666        KeyBinder*            masterKeyBinder_;
     67        SimpleInputState*     masterInputState_;
    6768        XMLFile*              debugOverlay_;
    6869    };
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

    r2814 r2816  
    173173    {
    174174        // create the corresponding input state
    175         inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", InputStatePriority::Console);
     175        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", false, false, InputStatePriority::Console);
    176176        inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
    177177        bHidesAllInputChanged();
Note: See TracChangeset for help on using the changeset viewer.