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/InputManager.h

    r1630 r1637  
    4141#include <map>
    4242#include <vector>
     43#include <stack>
    4344#include "util/Math.h"
    4445#include "core/OrxonoxClass.h"
     
    6869    };
    6970
    70     /**
    71     @brief
    72         Struct for storing a custom input state
    73     */
    74     struct StoredState
    75     {
    76         std::vector<KeyHandler*>                    activeKeyHandlers_;
    77         std::vector<MouseHandler*>                  activeMouseHandlers_;
    78         std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
    79         std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
    80     };
    81 
    8271    struct JoyStickCalibration
    8372    {
     
    9584        public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
    9685    {
    97     public: // enumerations
    98         /**
    99         @brief
    100             Designates the way input is handled and redirected.
    101         */
    102         enum InputState
    103         {
    104             IS_UNINIT,    //!< InputManager has not yet been initialised.
    105             IS_NONE,      //!< Input is discarded.
    106             IS_NORMAL,    //!< Normal play state. Key and button bindings are active.
    107             IS_GUI,       //!< All OIS input events are passed to CEGUI.
    108             IS_CONSOLE,   //!< Keyboard input is redirected to the InputBuffer.
    109             IS_DETECT,    //!< All the input additionally goes to the KeyDetector
    110             IS_NODETECT,  //!< remove KeyDetector
    111             IS_NOCALIBRATE,
    112             IS_CALIBRATE,
    113             IS_CUSTOM     //!< Any possible configuration.
    114         };
    115 
    116     public: // member functions
    117         void setConfigValues();
     86        // --> setConfigValues is private
     87        friend ClassIdentifier<InputManager>;
    11888
    11989    public: // static functions
     
    139109        static void setWindowExtents(const int width, const int height);
    140110
    141         static void setInputState(const InputState state);
    142         static InputState getInputState();
    143 
    144111        static void storeKeyStroke(const std::string& name);
    145112        static void keyBind(const std::string& command);
     
    149116        static void tick(float dt);
    150117
    151         static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
    152         static bool removeKeyHandler              (const std::string& name);
    153         static KeyHandler* getKeyHandler          (const std::string& name);
    154         static bool enableKeyHandler              (const std::string& name);
    155         static bool disableKeyHandler             (const std::string& name);
    156         static bool isKeyHandlerActive            (const std::string& name);
    157 
    158         static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
    159         static bool removeMouseHandler            (const std::string& name);
    160         static MouseHandler* getMouseHandler      (const std::string& name);
    161         static bool enableMouseHandler            (const std::string& name);
    162         static bool disableMouseHandler           (const std::string& name);
    163         static bool isMouseHandlerActive          (const std::string& name);
    164 
    165         static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
    166         static bool removeJoyStickHandler         (const std::string& name);
    167         static JoyStickHandler* getJoyStickHandler(const std::string& name);
    168         static bool enableJoyStickHandler         (const std::string& name, unsigned int id);
    169         static bool disableJoyStickHandler        (const std::string& name, unsigned int id);
    170         static bool isJoyStickHandlerActive       (const std::string& name, unsigned int id);
     118        static SimpleInputState*   createSimpleInputState  (const std::string& name, int priority);
     119        static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
     120        static bool destroyState (const std::string& name);
     121        //static bool removeState (const std::string& name);
     122        static InputState* getState       (const std::string& name);
     123        static InputState* getCurrentState();
     124        static bool requestEnterState     (const std::string& name);
     125        static bool requestLeaveState     (const std::string& name);
    171126
    172127    private: // functions
     
    181136        bool _initialiseMouse();
    182137        bool _initialiseJoySticks();
     138        void _redimensionLists();
    183139
    184140        void _destroy();
     
    186142        void _destroyMouse();
    187143        void _destroyJoySticks();
    188 
    189         void _updateTickables();
    190 
    191         void _saveState();
    192         void _restoreState();
     144        void _destroyState(InputState* state);
    193145
    194146        void _completeCalibration();
     
    198150
    199151        void _tick(float dt);
     152
     153        void _updateActiveStates();
     154        bool _configureInputState(InputState* state, const std::string& name, int priority);
    200155
    201156        // input events
     
    210165        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    211166        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    212         //bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
    213 
    214         static InputManager& _getSingleton();
    215         static InputManager* _getSingletonPtr() { return &_getSingleton(); }
     167
     168        void setConfigValues();
     169
     170        static InputManager& _getInstance();
    216171
    217172    private: // variables
     
    221176        std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
    222177        unsigned int                                joySticksSize_;
    223 
    224         KeyBinder*                                  keyBinder_;       //!< KeyBinder instance
    225         KeyDetector*                                keyDetector_;     //!< KeyDetector instance
    226         InputBuffer*                                buffer_;          //!< InputBuffer instance
    227         CalibratorCallback*                         calibratorCallback_;
    228 
    229         InputState state_;
    230         InputState stateRequest_;
    231         InputState savedState_;
    232         unsigned int keyboardModifiers_;
    233         StoredState savedHandlers_;
     178        unsigned int                                devicesNum_;
     179
     180        // some internally handled states
     181        SimpleInputState*                                 stateDetector_;   //!< KeyDetector instance
     182        SimpleInputState*                                 stateCalibrator_;
     183        SimpleInputState*                                 stateEmpty_;
     184
     185        std::map<std::string, InputState*>          inputStatesByName_;
     186        std::map<int, InputState*>                  inputStatesByPriority_;
     187
     188        std::vector<InputState*> stateEnterRequests_;                  //!< Request to enter a new state
     189        std::vector<InputState*> stateLeaveRequests_;                    //!< Request to leave the current state
     190
     191        std::map<int, InputState*> activeStates_;
     192        std::vector<InputState*>   activeStatesTop_;    //!< Current input states for joy stick events.
     193        std::vector<InputState*>   activeStatesTicked_;    //!< Current input states for joy stick events.
    234194
    235195        // joystick calibration
     
    239199        int marginalsMin_[24];
    240200        bool bCalibrated_;
    241 
     201        bool bCalibrating_;
     202
     203        unsigned int keyboardModifiers_;           //!< Bit mask representing keyboard modifiers
    242204        //! Keeps track of the joy stick POV states
    243205        std::vector<POVStates>                      povStates_;
     
    246208        std::vector<JoyStickCalibration>            joySticksCalibration_;
    247209
    248         std::map<std::string, KeyHandler*>          keyHandlers_;
    249         std::map<std::string, MouseHandler*>        mouseHandlers_;
    250         std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
    251 
    252         std::vector<KeyHandler*>                    activeKeyHandlers_;
    253         std::vector<MouseHandler*>                  activeMouseHandlers_;
    254         std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
    255         std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
    256 
    257210        std::vector<Key>                            keysDown_;
    258211        std::vector<MouseButton::Enum>              mouseButtonsDown_;
Note: See TracChangeset for help on using the changeset viewer.