Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2008, 6:49:24 PM (16 years ago)
Author:
rgrieder
Message:

Finally! The InputManager is now working like I imagined it to. And it's even easier to use it as well.
A little explanation: Every time you change something about the input distribution, it is a change of 'state' represented by the class 'InputState'.
That can be for instance: "console", "game", "gui", etc. Every state has a name and a priority which describes who comes first. Now if one state doesn't handle mouse input or instance, then the one with the next lower priority gets it. To prevent that, you can add the 'EmptyHandler' to the state with setMouseHandler.
InputState is just an abstract base class. There are two classes implementing it: SimpleInputState and ExtendedInputState. The latter allows for multiple input handlers for one single device.

Basically, what you need to know is what you see in Orxonox.cc, InGameConsole.cc and Shell.cc.

File:
1 edited

Legend:

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

    r1540 r1637  
    3434#include "ConsoleCommand.h"
    3535#include "input/InputInterfaces.h"
     36#include "input/SimpleInputState.h"
     37#include "input/InputManager.h"
    3638
    3739#define SHELL_UPDATE_LISTENERS(function) \
     
    5759        this->clearLines();
    5860
    59         this->inputBuffer_ = 0;
    60         this->setInputBuffer(new InputBuffer());
     61        this->inputBuffer_ = new InputBuffer();
     62        this->configureInputBuffer();
     63        InputManager::createSimpleInputState("console", 40)->setKeyHandler(this->inputBuffer_);
    6164
    6265        this->outputBuffer_.registerListener(this);
    6366
    6467        this->setConfigValues();
     68    }
     69
     70    Shell::~Shell()
     71    {
     72        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
     73        if (inputState)
     74        {
     75            inputState->removeAndDestroyAllHandlers();
     76            InputManager::destroyState("console");
     77        }
    6578    }
    6679
     
    97110    }
    98111
    99     void Shell::setInputBuffer(InputBuffer* buffer)
    100     {
    101         if (this->inputBuffer_)
    102         {
    103             this->inputBuffer_->unregisterListener(this);
    104             // TODO: may be very dangerous. InputManager already deletes InputBuffer instance!!!
    105             delete this->inputBuffer_;
    106         }
    107 
    108         this->inputBuffer_ = buffer;
     112    void Shell::configureInputBuffer()
     113    {
    109114        this->inputBuffer_->registerListener(this, &Shell::inputChanged, true);
    110115        this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
Note: See TracChangeset for help on using the changeset viewer.