Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1878


Ignore:
Timestamp:
Oct 3, 2008, 1:26:48 PM (16 years ago)
Author:
rgrieder
Message:

Fixed two issues with input:

  • Buffer gets cleared now when the window focus changes
  • Added a configValue in the InGameConsole:

Until now the input was always transparent to the level when activating the console (exception keyboard input of course)
bHidesAllInput_ can change that setting (configured in orxonox.ini)

@Oli: Sorry, couldn't apply the patch in the network branch because of conflicts (I have already made some changes to the InputManager in the trunk)

Location:
code/trunk/src
Files:
13 edited

Legend:

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

    r1755 r1878  
    366366    void ExtendedInputState::removeAndDestroyAllHandlers()
    367367    {
    368         for (std::vector<InputTickable*>::iterator it = allHandlers_.begin();
     368        for (std::vector<InputHandler*>::iterator it = allHandlers_.begin();
    369369            it != allHandlers_.end(); ++it)
    370370            delete *it;
     
    387387        True if added, false if handler already existed.
    388388    */
    389     bool ExtendedInputState::addHandler(InputTickable* handler)
     389    bool ExtendedInputState::addHandler(InputHandler* handler)
    390390    {
    391391        bool success = false;
     
    406406        True if removal was successful, false if handler was not found.
    407407    */
    408     bool ExtendedInputState::removeHandler(InputTickable* handler)
     408    bool ExtendedInputState::removeHandler(InputHandler* handler)
    409409    {
    410410        bool success = false;
     
    449449    {
    450450        // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
    451         std::set<InputTickable*> tempSet;
     451        std::set<InputHandler*> tempSet;
    452452        for (unsigned int iHandler = 0; iHandler < keyHandlers_.size(); iHandler++)
    453453            tempSet.insert(keyHandlers_[iHandler]);
     
    460460        // copy the content of the map back to the actual vector
    461461        allHandlers_.clear();
    462         for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin();
     462        for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin();
    463463            itHandler != tempSet.end(); itHandler++)
    464464            allHandlers_.push_back(*itHandler);
     
    469469        for (unsigned int i = 0; i < joyStickHandlers_.size(); ++i)
    470470            setInputDeviceEnabled(2 + i, (joyStickHandlers_[i].size() != 0));
     471
     472        this->bHandlersChanged_ = true;
    471473    }
    472474}
  • code/trunk/src/core/input/ExtendedInputState.h

    r1755 r1878  
    6161        bool removeJoyStickHandler(JoyStickHandler* handler);
    6262
    63         bool addHandler(InputTickable* handler);
    64         bool removeHandler(InputTickable* handler);
     63        bool addHandler(InputHandler* handler);
     64        bool removeHandler(InputHandler* handler);
    6565
    6666        void removeAndDestroyAllHandlers();
     
    9696        std::vector<JoyStickHandler*>               joyStickHandlersAll_;
    9797
    98         std::vector<InputTickable*> allHandlers_;
     98        std::vector<InputHandler*> allHandlers_;
    9999    };
    100100}
  • code/trunk/src/core/input/InputInterfaces.h

    r1755 r1878  
    287287
    288288
    289     class _CoreExport InputTickable
    290     {
    291     public:
    292         virtual ~InputTickable() { }
     289    class _CoreExport InputHandler
     290    {
     291    public:
     292        virtual ~InputHandler() { }
    293293        virtual void tickInput(float dt) = 0;
    294294    };
     
    298298        Interface class used for key input listeners.
    299299    */
    300     class _CoreExport KeyHandler : virtual public InputTickable
     300    class _CoreExport KeyHandler : virtual public InputHandler
    301301    {
    302302    public:
     
    312312        Interface class used for mouse input listeners.
    313313    */
    314     class _CoreExport MouseHandler : virtual public InputTickable
     314    class _CoreExport MouseHandler : virtual public InputHandler
    315315    {
    316316    public:
     
    329329        Interface class used for joy stick input listeners.
    330330    */
    331     class _CoreExport JoyStickHandler : virtual public InputTickable
     331    class _CoreExport JoyStickHandler : virtual public InputHandler
    332332    {
    333333    public:
     
    342342    class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
    343343    {
     344        friend class InputManager;
    344345    private:
     346        EmptyHandler() { }
     347        EmptyHandler(EmptyHandler&);
     348        virtual ~EmptyHandler() { }
     349
    345350        void tickInput(float dt) { }
    346351        void tickJoyStick(float dt, unsigned int joyStick) { }
  • code/trunk/src/core/input/InputManager.cc

    r1788 r1878  
    6565
    6666    std::string InputManager::bindingCommmandString_s = "";
     67    EmptyHandler InputManager::EMPTY_HANDLER;
    6768    InputManager* InputManager::singletonRef_s = 0;
    6869
     
    189190
    190191            stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
    191             stateEmpty_->setHandler(new EmptyHandler());
     192            stateEmpty_->setHandler(&EMPTY_HANDLER);
    192193            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    193194
     
    198199
    199200            stateCalibrator_ = createInputState<SimpleInputState>("calibrator", 100);
    200             stateCalibrator_->setHandler(new EmptyHandler());
     201            stateCalibrator_->setHandler(&EMPTY_HANDLER);
    201202            InputBuffer* buffer = new InputBuffer();
    202203            buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true);
     
    430431
    431432                // clear our own states
    432                 stateEmpty_->removeAndDestroyAllHandlers();
    433                 stateCalibrator_->removeAndDestroyAllHandlers();
    434                 stateDetector_->removeAndDestroyAllHandlers();
     433                //stateEmpty_->removeAndDestroyAllHandlers();
     434                //stateCalibrator_->removeAndDestroyAllHandlers();
     435                //stateDetector_->removeAndDestroyAllHandlers();
     436                // TODO: Memory Leak when not deleting the handlers!!!
    435437
    436438                // kick all active states 'nicely'
     
    680682        }
    681683        stateDestroyRequests_.clear();
     684
     685        // check whether a state has changed its EMPTY_HANDLER situation
     686        bool bUpdateRequired = false;
     687        for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
     688        {
     689            if (it->second->handlersChanged())
     690            {
     691                it->second->resetHandlersChanged();
     692                bUpdateRequired = true;
     693            }
     694        }
     695        if (bUpdateRequired)
     696            _updateActiveStates();
    682697
    683698        // mark that we capture and distribute input
     
    826841        requestLeaveState("calibrator");
    827842        bCalibrating_ = false;
     843    }
     844
     845    void InputManager::clearBuffers()
     846    {
     847        this->keysDown_.clear();
     848        this->mouseButtonsDown_.clear();
     849        for (unsigned int i = 0; i < this->joySticksSize_; ++i)
     850            this->joyStickButtonsDown_[i].clear();
    828851    }
    829852
  • code/trunk/src/core/input/InputManager.h

    r1788 r1878  
    108108        void reloadInputSystem(bool joyStickSupport = true);
    109109
     110        void clearBuffers();
     111
    110112        int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
    111113        int  numberOfMice()      { return mouse_    ? 1 : 0; }
     
    115117
    116118        template <class T>
    117         T* createInputState(const std::string& name, int priority)
    118         {
    119             T* state = new T;
    120             if (_configureInputState(state, name, priority))
    121                 return state;
    122             else
    123             {
    124                 delete state;
    125                 return 0;
    126             }
    127         }
     119        T* createInputState(const std::string& name, int priority);
    128120
    129121        InputState* getState       (const std::string& name);
     
    139131        static InputManager* getInstancePtr() { return singletonRef_s; }
    140132
    141     public: // console commands
     133        // console commands
    142134        static void storeKeyStroke(const std::string& name);
    143135        static void keyBind(const std::string& command);
    144136        static void calibrate();
    145137        static void reload(bool joyStickSupport = true);
     138
     139    public: // variables
     140        static EmptyHandler                 EMPTY_HANDLER;
    146141
    147142    private: // functions
     
    197192        InputManagerState                   internalState_;        //!< Current internal state
    198193
    199         // some internally handled states
     194        // some internally handled states and handlers
    200195        SimpleInputState*                   stateDetector_;        //!< KeyDetector instance
    201196        SimpleInputState*                   stateCalibrator_;
     
    234229        static InputManager*                singletonRef_s;
    235230    };
     231
     232    /**
     233    @brief
     234        Creates a new InputState by type, name and priority.
     235       
     236        You will have to use this method because the
     237        c'tors and d'tors are private.
     238    @remarks
     239        The InputManager will take care of the state completely. That also
     240        means it gets deleted when the InputManager is destroyed!
     241    @param name
     242        Name of the InputState when referenced as string
     243    @param priority
     244        Priority matters when multiple states are active. You can specify any
     245        number, but 1 - 99 is preferred (99 means high).
     246    */
     247    template <class T>
     248    T* InputManager::createInputState(const std::string& name, int priority)
     249    {
     250        T* state = new T;
     251        if (_configureInputState(state, name, priority))
     252            return state;
     253        else
     254        {
     255            delete state;
     256            return 0;
     257        }
     258    }
    236259}
    237260
  • code/trunk/src/core/input/InputState.h

    r1755 r1878  
    6060        }
    6161
     62        bool handlersChanged() { return this->bHandlersChanged_; }
     63        void resetHandlersChanged() { bHandlersChanged_ = false; }
     64
    6265        virtual void onEnter() { if (executorOnEnter_) (*executorOnEnter_)(); }
    6366        virtual void onLeave() { if (executorOnLeave_) (*executorOnLeave_)(); }
     
    8790
    8891    protected:
    89         InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) { }
     92        InputState() : priority_(0), bHandlersChanged_(false), executorOnEnter_(0), executorOnLeave_(0) { }
    9093        virtual ~InputState() { }
    9194
     
    9699                bInputDeviceEnabled_[device] = bEnabled;
    97100        }
     101
     102        bool bHandlersChanged_;
    98103
    99104    private:
  • code/trunk/src/core/input/SimpleInputState.cc

    r1755 r1878  
    184184    }
    185185
    186     void SimpleInputState::removeAndDestroyAllHandlers()
    187     {
    188         for (std::vector<InputTickable*>::iterator it = allHandlers_.begin();
    189             it != allHandlers_.end(); ++it)
    190             delete *it;
    191 
    192         allHandlers_.clear();
    193         keyHandler_ = 0;
    194         mouseHandler_ = 0;
    195         joyStickHandlerAll_ = 0;
    196         for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)
    197             joyStickHandler_[iJoyStick] = 0;
    198 
    199         update();
    200     }
     186    //void SimpleInputState::removeAndDestroyAllHandlers()
     187    //{
     188    //    for (std::vector<InputHandler*>::iterator it = allHandlers_.begin();
     189    //        it != allHandlers_.end(); ++it)
     190    //        delete *it;
     191
     192    //    allHandlers_.clear();
     193    //    keyHandler_ = 0;
     194    //    mouseHandler_ = 0;
     195    //    joyStickHandlerAll_ = 0;
     196    //    for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)
     197    //        joyStickHandler_[iJoyStick] = 0;
     198
     199    //    update();
     200    //}
    201201
    202202    /**
     
    208208        True if added, false if handler already existed.
    209209    */
    210     bool SimpleInputState::setHandler(InputTickable* handler)
     210    bool SimpleInputState::setHandler(InputHandler* handler)
    211211    {
    212212        setKeyHandler(dynamic_cast<KeyHandler*>(handler));
     
    247247    {
    248248        // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
    249         std::set<InputTickable*> tempSet;
     249        std::set<InputHandler*> tempSet;
    250250        if (keyHandler_)
    251251            tempSet.insert(keyHandler_);
     
    258258        // copy the content of the map back to the actual vector
    259259        allHandlers_.clear();
    260         for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin();
     260        for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin();
    261261            itHandler != tempSet.end(); itHandler++)
    262262            allHandlers_.push_back(*itHandler);
     
    267267        for (unsigned int i = 0; i < joyStickHandler_.size(); ++i)
    268268            setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0));
     269
     270        // inform InputManager that there might be changes in EMPTY_HANDLER situation
     271        bHandlersChanged_ = true;
    269272    }
    270273}
  • code/trunk/src/core/input/SimpleInputState.h

    r1755 r1878  
    5252        bool setJoyStickHandler   (JoyStickHandler* handler, unsigned int joyStickID);
    5353        bool setJoyStickHandler   (JoyStickHandler* handler);
    54         bool setHandler(InputTickable* handler);
    55         void removeAndDestroyAllHandlers();
     54        bool setHandler(InputHandler* handler);
     55        //void removeAndDestroyAllHandlers();
    5656
    5757    private:
     
    8484        std::vector<JoyStickHandler*> joyStickHandler_;
    8585        JoyStickHandler*              joyStickHandlerAll_;
    86         std::vector<InputTickable*>   allHandlers_;
     86        std::vector<InputHandler*>   allHandlers_;
    8787    };
    8888}
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r1828 r1878  
    140140        using namespace Ogre;
    141141
     142        // remove our WindowEventListener first to avoid bad calls in the procedures
     143        Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
     144
    142145        delete this->guiManager_;
    143146
     
    149152
    150153        // destroy render window
    151         this->renderWindow_->removeAllViewports();
    152         this->renderWindow_->removeAllListeners();
    153154        RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
    154155        renderer->destroyRenderWindow("Orxonox");
     
    360361        The render window it occured in
    361362    */
    362     void GSGraphics::windowFocusChanged(Ogre::RenderWindow *rw)
     363    void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw)
    363364    {
    364365        for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    365366            it->windowFocusChanged();
     367
     368        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
     369        InputManager::getInstance().clearBuffers();
    366370    }
    367371
  • code/trunk/src/orxonox/gamestates/GSGraphics.h

    r1788 r1878  
    6565        void windowMoved       (Ogre::RenderWindow* rw);
    6666        void windowResized     (Ogre::RenderWindow* rw);
    67         void windowFocusChanged(Ogre::RenderWindow* rw);
     67        void windowFocusChange (Ogre::RenderWindow* rw);
    6868        void windowClosed      (Ogre::RenderWindow* rw);
    6969
  • code/trunk/src/orxonox/gui/GUIManager.cc

    r1810 r1878  
    156156                SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui", 30);
    157157                state->setHandler(this);
    158                 state->setJoyStickHandler(new EmptyHandler());
     158                state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
    159159
    160160                // load the background scene
  • code/trunk/src/orxonox/overlays/console/InGameConsole.cc

    r1819 r1878  
    7070        , consoleOverlayBorder_(0)
    7171        , consoleOverlayTextAreas_(0)
     72        , inputState_(0)
    7273    {
    7374        RegisterObject(InGameConsole);
     
    143144        SetConfigValue(noiseSize_, 1.0f);
    144145        SetConfigValue(cursorSymbol_, '|');
     146        SetConfigValue(bHidesAllInput_, false).callback(this, &InGameConsole::bHidesAllInputChanged);
     147    }
     148
     149    /**
     150        @brief Called whenever bHidesAllInput_ changes.
     151    */
     152    void InGameConsole::bHidesAllInputChanged()
     153    {
     154        if (inputState_)
     155        {
     156            if (bHidesAllInput_)
     157            {
     158                inputState_->setMouseHandler(&InputManager::EMPTY_HANDLER);
     159                inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
     160            }
     161            else
     162            {
     163                inputState_->setMouseHandler(0);
     164                inputState_->setJoyStickHandler(0);
     165            }
     166        }
    145167    }
    146168
     
    151173    {
    152174        // create the corresponding input state
    153         InputManager::getInstance().createInputState<SimpleInputState>("console", 40)
    154             ->setKeyHandler(Shell::getInstance().getInputBuffer());
     175        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40);
     176        inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
     177        bHidesAllInputChanged();
    155178
    156179        // create overlay and elements
  • code/trunk/src/orxonox/overlays/console/InGameConsole.h

    r1755 r1878  
    8181        void windowResized(int newWidth, int newHeight);
    8282
     83        // config value related
     84        void bHidesAllInputChanged();
     85
    8386        static Ogre::UTFString convert2UTF(std::string s);
    8487
     
    102105        Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_;
    103106
     107        // input related
     108        SimpleInputState* inputState_;
     109
    104110        // config values
    105111        float relativeWidth;
     
    109115        float noiseSize_;
    110116        char cursorSymbol_;
     117        bool bHidesAllInput_;
    111118
    112119        static InGameConsole* singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.