Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1788 for code/trunk/src


Ignore:
Timestamp:
Sep 15, 2008, 12:40:40 PM (16 years ago)
Author:
rgrieder
Message:

Added a master InputState that is always active (except of course in game state 'ioConsole' when there is no InputManager in the first place)
This is necessary to call the console whenever you like. The state is of 'extended' nature, so it can hold an arbitrary number of Handlers.
The KeyBinder however is not yet configured to manage multiple keybindings.ini —> next job ;)

Location:
code/trunk/src
Files:
4 edited

Legend:

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

    r1770 r1788  
    109109        , stateCalibrator_(0)
    110110        , stateEmpty_(0)
     111        , stateMaster_(0)
    111112        , bCalibrating_(false)
    112113        , keyboardModifiers_(0)
     
    201202            buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true);
    202203            stateCalibrator_->setKeyHandler(buffer);
     204
     205            stateMaster_ = new ExtendedInputState();
     206            stateMaster_->setName("master");
    203207
    204208            internalState_ |= InternalsReady;
     
    441445                    _destroyState((*inputStatesByPriority_.rbegin()).second);
    442446
     447                // destroy the master input state. This might trigger a memory leak
     448                // because the user has forgotten to destroy the KeyBinder or any Handler!
     449                delete stateMaster_;
     450
    443451                // destroy the devices
    444452                _destroyKeyboard();
     
    688696            // call all the handlers for the held key events
    689697            for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    690                 activeStatesTop_[Keyboard]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
     698            {
     699                KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
     700                activeStatesTop_[Keyboard]->keyHeld(kEvt);
     701                stateMaster_->keyHeld(kEvt);
     702            }
    691703
    692704            // call all the handlers for the held mouse button events
    693705            for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
     706            {
    694707                activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]);
     708                stateMaster_->mouseButtonHeld(mouseButtonsDown_[iButton]);
     709            }
    695710
    696711            // call all the handlers for the held joy stick button events
    697712            for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    698713                for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
     714                {
    699715                    activeStatesTop_[JoyStick0 + iJoyStick]
    700716                        ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     717                    stateMaster_->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     718                }
    701719
    702720            // tick the handlers for each active handler
    703721            for (unsigned int i = 0; i < devicesNum_; ++i)
     722            {
    704723                activeStatesTop_[i]->tickInput(dt, i);
     724                if (stateMaster_->isInputDeviceEnabled(i))
     725                    stateMaster_->tickInput(dt, i);
     726            }
    705727
    706728            // tick the handler with a general tick afterwards
    707729            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    708730                activeStatesTicked_[i]->tickInput(dt);
     731            stateMaster_->tickInput(dt);
    709732        }
    710733
     
    828851            keysDown_.push_back(Key(e));
    829852        else
     853        {
     854            // This happens when XAutoRepeat is set under linux. The KeyPressed event gets then sent
     855            // continuously.
    830856            return true;
     857        }
    831858
    832859        // update modifiers
     
    838865            keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
    839866
    840         activeStatesTop_[Keyboard]->keyPressed(KeyEvent(e, keyboardModifiers_));
     867        KeyEvent kEvt(e, keyboardModifiers_);
     868        activeStatesTop_[Keyboard]->keyPressed(kEvt);
     869        stateMaster_->keyPressed(kEvt);
    841870
    842871        return true;
     
    869898            keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
    870899
    871         activeStatesTop_[Keyboard]->keyReleased(KeyEvent(e, keyboardModifiers_));
     900        KeyEvent kEvt(e, keyboardModifiers_);
     901        activeStatesTop_[Keyboard]->keyReleased(kEvt);
     902        stateMaster_->keyReleased(kEvt);
    872903
    873904        return true;
     
    888919        if (e.state.X.rel != 0 || e.state.Y.rel != 0)
    889920        {
    890             activeStatesTop_[Mouse]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
    891                     IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
     921            IntVector2 abs(e.state.X.abs, e.state.Y.abs);
     922            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
     923            IntVector2 clippingSize(e.state.width, e.state.height);
     924            activeStatesTop_[Mouse]->mouseMoved(abs, rel, clippingSize);
     925            stateMaster_->mouseMoved(abs, rel, clippingSize);
    892926        }
    893927
     
    896930        {
    897931            activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
     932            stateMaster_->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    898933        }
    899934
     
    919954
    920955        activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton::Enum)id);
     956        stateMaster_->mouseButtonPressed((MouseButton::Enum)id);
    921957
    922958        return true;
     
    944980
    945981        activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton::Enum)id);
     982        stateMaster_->mouseButtonReleased((MouseButton::Enum)id);
    946983
    947984        return true;
     
    9801017
    9811018        activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
     1019        stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
    9821020
    9831021        return true;
     
    10001038
    10011039        activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
     1040        stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
    10021041
    10031042        return true;
     
    10271066
    10281067            activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);
     1068            stateMaster_->joyStickAxisMoved(iJoyStick, axis, fValue);
    10291069        }
    10301070    }
  • code/trunk/src/core/input/InputManager.h

    r1755 r1788  
    129129        InputState* getState       (const std::string& name);
    130130        InputState* getCurrentState();
     131        ExtendedInputState* getMasterInputState() { return this->stateMaster_; }
    131132        bool requestDestroyState   (const std::string& name);
    132133        bool requestEnterState     (const std::string& name);
     
    200201        SimpleInputState*                   stateCalibrator_;
    201202        SimpleInputState*                   stateEmpty_;
     203        ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    202204
    203205        std::map<std::string, InputState*>  inputStatesByName_;
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r1764 r1788  
    4646#include "core/CoreIncludes.h"
    4747#include "core/input/InputManager.h"
     48#include "core/input/KeyBinder.h"
     49#include "core/input/ExtendedInputState.h"
    4850#include "overlays/console/InGameConsole.h"
    4951#include "gui/GUIManager.h"
     
    6264        , console_(0)
    6365        , guiManager_(0)
     66        , masterKeyBinder_(0)
    6467        , frameCount_(0)
    6568        , statisticsRefreshCycle_(0)
     
    108111        this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
    109112        inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
     113        // Configure master input state with a KeyBinder
     114        //masterKeyBinder_ = new KeyBinder();
     115        //inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
    110116
    111117        // Load the InGameConsole
     
    135141        delete this->console_;
    136142
     143        //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_);
     144        //delete this->masterKeyBinder_;
    137145        delete this->inputManager_;
    138146
  • code/trunk/src/orxonox/gamestates/GSGraphics.h

    r1755 r1788  
    7777        GUIManager*           guiManager_;
    7878
     79        KeyBinder*            masterKeyBinder_;
     80
    7981        // variables for time statistics
    8082        unsigned long         frameCount_;
Note: See TracChangeset for help on using the changeset viewer.