Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2008, 12:31:32 AM (16 years ago)
Author:
rgrieder
Message:

FIRST THINGS FIRST: Delete or rename your keybindings.ini (def_keybindings.ini already has the most important bindings) or else you won't be able to do anything!

Changes:

  • Multiple joy stick support should now fully work with KeyBinder too (only tested with 0/1 joystick)
  • Reloading the OIS Devices now works with KeyBinder too
  • Modified ConfigValueContainer to accept arbitrary section names
  • added tkeybind to temporary bind a command to a key
  • Fixed dlleport issue in ArgumentCompletionFunctions.h

Internal changes:

  • General cleanup in initialisation of KeyBinder
  • All names of keys/buttons/axes are now statically saved in InputInterfaces.h
  • Move a magic value in KeyBinder to a configValue (MouseWheelStepSize_)
  • Separated ConfigValues from Keybinding ConfigValueContainer in KeyBinder (looks much nicer now ;))
  • Moved some performance critical small function to the inline section
  • Removed the ugly keybind function construct from the InputManager
  • More 'harmonising' work in KeyBinder
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/input/KeyBinder.h

    r1755 r1887  
    3939
    4040#include <vector>
    41 
    42 #include "core/OrxonoxClass.h"
    4341#include "InputInterfaces.h"
    4442#include "Button.h"
    4543#include "HalfAxis.h"
     44#include "InputCommands.h"
     45#include "JoyStickDeviceNumberListener.h"
    4646
    4747namespace orxonox
     
    5252        Manages the key bindings.
    5353    */
    54     class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
     54    class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler,
     55                                  public JoyStickDeviceNumberListener
    5556    {
    5657    public:
     
    5859        virtual ~KeyBinder();
    5960
    60         void loadBindings();
     61        void loadBindings(const std::string& filename);
    6162        void clearBindings();
     63        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
    6264        void setConfigValues();
    6365        void resetJoyStickAxes();
     
    6567    protected: // functions
    6668        void tickInput(float dt);
    67         //void tickInput(float dt, int device);
    6869        void tickKey(float dt) { }
    6970        void tickMouse(float dt);
    7071        void tickJoyStick(float dt, unsigned int joyStick);
    71         void tickDevices(unsigned int begin, unsigned int end);
    72 
    73         virtual void readTrigger(Button& button);
     72        // internal
     73        void tickDevices(HalfAxis* begin, HalfAxis* end);
     74
     75        void buttonThresholdChanged();
     76        // from JoyStickDeviceNumberListener interface
     77        virtual void JoyStickDeviceNumberChanged(unsigned int value);
     78        void initialiseJoyStickBindings();
     79        void compilePointerLists();
    7480
    7581        void keyPressed (const KeyEvent& evt);
     
    7783        void keyHeld    (const KeyEvent& evt);
    7884
    79         void mouseButtonPressed (MouseButton::Enum id);
    80         void mouseButtonReleased(MouseButton::Enum id);
    81         void mouseButtonHeld    (MouseButton::Enum id);
     85        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     86        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     87        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
    8288        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    8389        void mouseScrolled      (int abs, int rel);
    8490
    85         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
    86         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
    87         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
     91        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     92        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     93        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    8894        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
    8995
    9096    protected: // variables
    91         //! denotes the number of different keys there are in OIS.
    92         static const unsigned int nKeys_s = 0xEE;
    93         //! Actual key bindings as bundle for Press, Hold and Release
    94         Button keys_ [nKeys_s];
    95 
    96         //! denotes the number of different mouse buttons there are in OIS.
    97         static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels
    98         //! Actual key bindings as bundle for Press, Hold and Release
    99         Button mouseButtons_ [nMouseButtons_s];
    100 
    101         //! denotes the number of different joy stick buttons there are in OIS.
    102         static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
    103         //! Actual key bindings as bundle for Press, Hold and Release
    104         Button joyStickButtons_ [nJoyStickButtons_s];
    105 
    106         //! denotes the number of half axes (every axis twice) there can be.
    107         static const unsigned int nHalfAxes_s = 56;
    108         /**
    109         * Array with all the half axes for mouse and joy sticks.
    110         * Keep in mind that the positions are fixed and that the first entry is the
    111         * positive one and the second is negative.
    112         * Sequence is as follows:
    113         *  0 -  3: Mouse x and y
    114         *  4 -  7: empty
    115         *  8 - 23: joy stick slider axes 1 to 8
    116         * 24 - 55: joy stick axes 1 - 16
    117         */
    118         HalfAxis halfAxes_[nHalfAxes_s];
     97        //! Currently active joy sticks
     98        unsigned int numberOfJoySticks_;
     99
     100        //! Actual key bindings for keys on the keyboard
     101        Button keys_            [KeyCode::numberOfKeys];
     102        //! Number of mouse buttons in KeyBinder (+4)
     103        static const int numberOfMouseButtons_ = MouseButtonCode::numberOfButtons + 4;
     104        //! Actual key bindings for mouse buttons including the wheel(s)
     105        Button mouseButtons_    [numberOfMouseButtons_];
     106        //! Actual key bindings for mouse axes
     107        HalfAxis mouseAxes_     [MouseAxisCode::numberOfAxes * 2];
     108
     109        //! Helper class to use something like std:vector<Button[64]>
     110        struct JoyStickButtonVector
     111        {
     112            Button& operator[](unsigned int index) { return buttons[index]; }
     113            Button buttons[JoyStickButtonCode::numberOfButtons];
     114        };
     115        //! Actual key bindings for joy stick buttons
     116        std::vector<JoyStickButtonVector> joyStickButtons_;
     117        //! Helper class to use something like std:vector<HalfAxis[48]>
     118        struct JoyStickAxisVector
     119        {
     120            HalfAxis& operator[](unsigned int index) { return halfAxes[index]; }
     121            HalfAxis halfAxes[JoyStickAxisCode::numberOfAxes * 2];
     122        };
     123        //! Actual key bindings for joy stick axes (and sliders)
     124        std::vector<JoyStickAxisVector> joyStickAxes_;
     125
     126        //! Pointer map with all Buttons, including half axes
     127        std::map<std::string, Button*> allButtons_;
     128        //! Pointer list with all half axes
     129        std::vector<HalfAxis*> allHalfAxes_;
    119130
    120131        /**
     
    131142        float deriveTime_;
    132143
    133 
     144        //! Config file used. "" in case of KeyDetector. Also indicates whether we've already loaded.
     145        std::string configFile_;
     146
     147    private:
    134148        //##### ConfigValues #####
    135 
     149        //! Filename of default keybindings.
     150        std::string defaultKeybindings_;
    136151        //! Threshold for analog triggers until which the state is 0.
    137152        float analogThreshold_;
     
    146161        //! mouse sensitivity if mouse input is derived
    147162        float mouseSensitivityDerived_;
    148         //! Whether or not to clip abslute mouse values to 1024
    149         bool bClipMouse_;
     163        //! Equals one step of the mousewheel
     164        float mouseWheelStepSize_;
     165
     166        //##### Constant config variables #####
     167        // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway.
     168        static const int mouseClippingSize_ = 1024;
    150169    };
     170
     171    inline void KeyBinder::keyPressed (const KeyEvent& evt)
     172    { keys_[evt.key].execute(KeybindMode::OnPress); }
     173
     174    inline void KeyBinder::keyReleased(const KeyEvent& evt)
     175    { keys_[evt.key].execute(KeybindMode::OnRelease); }
     176
     177    inline void KeyBinder::keyHeld    (const KeyEvent& evt)
     178    { keys_[evt.key].execute(KeybindMode::OnHold); }
     179
     180
     181    inline void KeyBinder::mouseButtonPressed (MouseButtonCode::ByEnum id)
     182    { mouseButtons_[id].execute(KeybindMode::OnPress); }
     183
     184    inline void KeyBinder::mouseButtonReleased(MouseButtonCode::ByEnum id)
     185    { mouseButtons_[id].execute(KeybindMode::OnRelease); }
     186
     187    inline void KeyBinder::mouseButtonHeld    (MouseButtonCode::ByEnum id)
     188    { mouseButtons_[id].execute(KeybindMode::OnHold); }
     189
     190
     191    inline void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     192    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnPress); }
     193
     194    inline void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     195    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnRelease); }
     196
     197    inline void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     198    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
     199
     200    inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     201    {
     202        tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]);
     203    }
     204
     205    inline void KeyBinder::tickInput(float dt)
     206    {
     207        // execute all buffered bindings (additional parameter)
     208        for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     209            paramCommandBuffer_[i]->execute();
     210
     211        // always reset the relative movement of the mouse
     212        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     213            mouseAxes_[i].relVal_ = 0.0f;
     214    }
    151215}
    152216
Note: See TracChangeset for help on using the changeset viewer.