Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2814


Ignore:
Timestamp:
Mar 21, 2009, 5:30:16 PM (15 years ago)
Author:
rgrieder
Message:

InputManager upgrade number one: InputState priorities are managed automatically. However you can still use the enum in InputManager.h and get yourself a high priority.
High priorities are only to be used for special cases like calibrator, console or detector.
All other states are simply pushed onto the normal stack.

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

Legend:

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

    r2800 r2814  
    174174            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
    175175            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    176 #if defined OIS_LINUX_PLATFORM
     176#if defined ORXONOX_PLATFORM_LINUX
    177177            paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    178178            paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
     
    219219
    220220            // Lowest priority empty InputState
    221             stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
     221            stateEmpty_ = createInputState<SimpleInputState>("empty", InputStatePriority::Empty);
    222222            stateEmpty_->setHandler(&EMPTY_HANDLER);
    223223            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
     
    229229
    230230            // KeyDetector to evaluate a pressed key's name
    231             SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
     231            SimpleInputState* detector = createInputState<SimpleInputState>("detector", InputStatePriority::Detector);
    232232            keyDetector_ = new KeyDetector();
    233233            detector->setHandler(keyDetector_);
    234234
    235235            // Joy stick calibration helper callback
    236             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);
     236            SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", InputStatePriority::Calibrator);
    237237            calibrator->setHandler(&EMPTY_HANDLER);
    238238            calibratorCallbackBuffer_ = new InputBuffer();
     
    428428
    429429        // inform all states
    430         for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    431             it != inputStatesByPriority_.end(); ++it)
     430        for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin();
     431            it != inputStatesByName_.end(); ++it)
    432432        {
    433433            it->second->setNumOfJoySticks(joySticksSize_);
     
    555555
    556556                // destroy all user InputStates
    557                 while (inputStatesByPriority_.size() > 0)
    558                     _destroyState((*inputStatesByPriority_.rbegin()).second);
     557                while (inputStatesByName_.size() > 0)
     558                    _destroyState((*inputStatesByName_.rbegin()).second);
    559559
    560560                // destroy the devices
     
    640640            _updateActiveStates();
    641641        }
    642         inputStatesByPriority_.erase(state->getPriority());
    643642        inputStatesByName_.erase(state->getName());
    644643        delete state;
     
    768767
    769768                activeStates_.erase((*rit)->getPriority());
     769                if ((*rit)->getPriority() < InputStatePriority::HighPriority)
     770                    (*rit)->setPriority(0);
    770771                _updateActiveStates();
    771772            }
     
    782783                assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    783784
     785                if ((*rit)->getPriority() == 0)
     786                {
     787                    // Get smallest possible priority between 1 and maxStateStackSize_s
     788                    for(std::map<int, InputState*>::const_reverse_iterator rit2 = activeStates_.rbegin();
     789                        rit2 != activeStates_.rend(); ++rit2)
     790                    {
     791                        if (rit2->first < InputStatePriority::HighPriority)
     792                        {
     793                            (*rit)->setPriority(rit2->first + 1);
     794                            break;
     795                        }
     796                    }
     797                    // In case no normal handler was on the stack
     798                    if ((*rit)->getPriority() == 0)
     799                        (*rit)->setPriority(1);
     800                }
    784801                activeStates_[(*rit)->getPriority()] = (*rit);
    785802                _updateActiveStates();
     
    813830            _updateActiveStates();
    814831
    815         // mark that we capture and distribute input
     832        // mark that we now start capturing and distributing input
    816833        internalState_ |= Ticking;
    817834
     
    12461263        Unique name of the handler.
    12471264    @param priority
    1248         Unique integer number. Higher means more prioritised.
     1265        Determines which InputState gets the input. Higher is better.
     1266        Use 0 to handle it implicitely by the order of activation.
     1267        Otherwise numbers larger than maxStateStackSize_s have to be used!
    12491268    @return
    12501269        True if added, false if name or priority already existed.
     
    12581277        if (inputStatesByName_.find(name) == inputStatesByName_.end())
    12591278        {
    1260             if (inputStatesByPriority_.find(priority)
    1261                 == inputStatesByPriority_.end())
    1262             {
    1263                 inputStatesByName_[name] = state;
    1264                 inputStatesByPriority_[priority] = state;
    1265                 state->setNumOfJoySticks(numberOfJoySticks());
    1266                 state->setName(name);
     1279            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
     1280            {
     1281                // Make sure we don't add two high priority states with the same priority
     1282                for (std::map<std::string, InputState*>::const_iterator it = this->inputStatesByName_.begin();
     1283                    it != this->inputStatesByName_.end(); ++it)
     1284                {
     1285                    if (it->second->getPriority() == priority)
     1286                    {
     1287                        COUT(2) << "Warning: Could not add an InputState with the same priority '"
     1288                            << priority << "' != 0." << std::endl;
     1289                        return false;
     1290                    }
     1291                }
     1292            }
     1293            inputStatesByName_[name] = state;
     1294            state->setNumOfJoySticks(numberOfJoySticks());
     1295            state->setName(name);
     1296            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
    12671297                state->setPriority(priority);
    1268                 return true;
    1269             }
    1270             else
    1271             {
    1272                 COUT(2) << "Warning: Could not add an InputState with the same priority '"
    1273                     << priority << "'." << std::endl;
    1274                 return false;
    1275             }
     1298            return true;
    12761299        }
    12771300        else
     
    13721395                {
    13731396                    // not scheduled for destruction
    1374                     // set prevents a state being added multiple times
     1397                    // prevents a state being added multiple times
    13751398                    stateEnterRequests_.insert(it->second);
    13761399                    return true;
     
    13911414    bool InputManager::requestLeaveState(const std::string& name)
    13921415    {
     1416        if (name == "empty")
     1417        {
     1418            COUT(2) << "InputManager: Leaving the empty state is not allowed!" << std::endl;
     1419            return false;
     1420        }
    13931421        // get pointer from the map with all stored handlers
    13941422        std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
  • code/branches/gui/src/core/input/InputManager.h

    r2800 r2814  
    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, InputStatePriority priority = InputStatePriority::Dynamic);
    119133
    120134        InputState* getState       (const std::string& name);
     
    202216
    203217        std::map<std::string, InputState*>  inputStatesByName_;
    204         std::map<int, InputState*>          inputStatesByPriority_;
    205218
    206219        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
     
    249262    */
    250263    template <class T>
    251     T* InputManager::createInputState(const std::string& name, int priority)
     264    T* InputManager::createInputState(const std::string& name, InputStatePriority priority)
    252265    {
    253266        T* state = new T;
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r2801 r2814  
    8282        if (Core::showsGraphics())
    8383        {
    84             inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
     84            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
    8585            keyBinder_ = new KeyBinder();
    8686            keyBinder_->loadBindings("keybindings.ini");
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r2808 r2814  
    167167
    168168                // register us as input handler
    169                 SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui", 30);
     169                SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui");
    170170                state->setHandler(this);
    171171                state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

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