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/input/KeyBinder.cc

    r1630 r1637  
    333333    }
    334334
    335     void KeyBinder::tickInput(float dt, const HandlerState& state)
    336     {
    337         // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event.
    338         unsigned int iBegin = 8;
    339         unsigned int iEnd   = 8;
    340         if (state.joyStick)
    341             iEnd = nHalfAxes_s;
    342         if (state.mouse)
    343             iBegin = 0;
    344         for (unsigned int i = iBegin; i < iEnd; i++)
    345         {
    346             if (halfAxes_[i].hasChanged_)
    347             {
    348                 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_)
    349                 {
    350                     halfAxes_[i].wasDown_ = true;
    351                     if (halfAxes_[i].nCommands_[KeybindMode::OnPress])
    352                         halfAxes_[i].execute(KeybindMode::OnPress);
    353                 }
    354                 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_)
    355                 {
    356                     halfAxes_[i].wasDown_ = false;
    357                     if (halfAxes_[i].nCommands_[KeybindMode::OnRelease])
    358                         halfAxes_[i].execute(KeybindMode::OnRelease);
    359                 }
    360                 halfAxes_[i].hasChanged_ = false;
    361             }
    362 
    363             if (halfAxes_[i].wasDown_)
    364             {
    365                 if (halfAxes_[i].nCommands_[KeybindMode::OnHold])
    366                     halfAxes_[i].execute(KeybindMode::OnHold);
    367             }
    368 
    369             // these are the actually useful axis bindings for analog input AND output
    370             if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_)
    371             {
    372                 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl;
    373                 halfAxes_[i].execute();
    374             }
    375         }
    376 
    377         if (bDeriveMouseInput_ && state.mouse)
     335    void KeyBinder::tickMouse(float dt)
     336    {
     337        tickDevices(0, 8);
     338
     339        if (bDeriveMouseInput_)
    378340        {
    379341            if (deriveTime_ > derivePeriod_)
     
    410372                deriveTime_ += dt;
    411373        }
    412 
    413         // execute all buffered bindings (addional parameter)
     374    }
     375
     376    void KeyBinder::tickJoyStick(float dt, int device)
     377    {
     378        tickDevices(8, nHalfAxes_s);
     379    }
     380
     381    void KeyBinder::tickInput(float dt)
     382    {
     383        // execute all buffered bindings (additional parameter)
    414384        for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
    415385            paramCommandBuffer_[i]->execute();
    416386
    417387        // always reset the relative movement of the mouse
    418         if (state.mouse)
    419             for (unsigned int i = 0; i < 8; i++)
    420                 halfAxes_[i].relVal_ = 0.0f;
     388        for (unsigned int i = 0; i < 8; i++)
     389            halfAxes_[i].relVal_ = 0.0f;
     390    }
     391
     392    void KeyBinder::tickDevices(unsigned int begin, unsigned int end)
     393    {
     394        for (unsigned int i = begin; i < end; i++)
     395        {
     396            // button mode
     397            // TODO: optimize out all the half axes that don't act as a button at the moment
     398            if (halfAxes_[i].hasChanged_)
     399            {
     400                if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_)
     401                {
     402                    halfAxes_[i].wasDown_ = true;
     403                    if (halfAxes_[i].nCommands_[KeybindMode::OnPress])
     404                        halfAxes_[i].execute(KeybindMode::OnPress);
     405                }
     406                else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_)
     407                {
     408                    halfAxes_[i].wasDown_ = false;
     409                    if (halfAxes_[i].nCommands_[KeybindMode::OnRelease])
     410                        halfAxes_[i].execute(KeybindMode::OnRelease);
     411                }
     412                halfAxes_[i].hasChanged_ = false;
     413            }
     414
     415            if (halfAxes_[i].wasDown_)
     416            {
     417                if (halfAxes_[i].nCommands_[KeybindMode::OnHold])
     418                    halfAxes_[i].execute(KeybindMode::OnHold);
     419            }
     420
     421            // these are the actually useful axis bindings for analog input
     422            if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_)
     423            {
     424                //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl;
     425                halfAxes_[i].execute();
     426            }
     427        }
    421428    }
    422429
     
    441448
    442449
    443     void KeyBinder::joyStickButtonPressed (int joyStickID, int button)
     450    void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, unsigned int button)
    444451    { joyStickButtons_[button].execute(KeybindMode::OnPress); }
    445452
    446     void KeyBinder::joyStickButtonReleased(int joyStickID, int button)
     453    void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
    447454    { joyStickButtons_[button].execute(KeybindMode::OnRelease); }
    448455
    449     void KeyBinder::joyStickButtonHeld    (int joyStickID, int button)
     456    void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, unsigned int button)
    450457    { joyStickButtons_[button].execute(KeybindMode::OnHold); }
    451458
     
    525532    }
    526533
    527     void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, float value)
    528     {
    529         // TODO: Use proper calibration values instead of generally 16-bit integer
     534    void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
     535    {
    530536        int i = 8 + axis * 2;
    531537        if (value >= 0)
Note: See TracChangeset for help on using the changeset viewer.