Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2009, 4:12:04 PM (15 years ago)
Author:
rgrieder
Message:

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/input/InputManager.h

    r3270 r3274  
    3737#define _InputManager_H__
    3838
    39 #include "core/CorePrereqs.h"
     39#include "InputPrereqs.h"
    4040
    4141#include <map>
     
    4343#include <string>
    4444#include <vector>
    45 #include <ois/OISKeyboard.h>
    46 #include <ois/OISMouse.h>
    47 #include <ois/OISJoyStick.h>
    4845
    4946#include "util/Math.h"
    5047#include "util/OrxEnum.h"
    5148#include "core/OrxonoxClass.h"
    52 #include "InputInterfaces.h"
    5349
    5450namespace orxonox
     
    7167        Captures and distributes mouse and keyboard input.
    7268    */
    73     class _CoreExport InputManager
    74         : public OrxonoxClass,
    75         public OIS::KeyListener, public OIS::MouseListener
     69    class _CoreExport InputManager : public OrxonoxClass
    7670    {
    7771        // --> setConfigValues is private
    7872        friend class ClassIdentifier<InputManager>;
    79         friend class JoyStick;
    8073
    8174    public:
     
    9992        void clearBuffers();
    10093
    101         unsigned int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
    102         unsigned int  numberOfMice()      { return mouse_    ? 1 : 0; }
    103         unsigned int  numberOfJoySticks() { return joySticks_.size(); }
    104 
    10594        void setWindowExtents(const int width, const int height);
    10695        void setKeyDetectorCallback(const std::string& command);
    10796
    108         template <class T>
    109         T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
     97        InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    11098
    11199        InputState* getState       (const std::string& name);
     
    114102        bool requestEnterState     (const std::string& name);
    115103        bool requestLeaveState     (const std::string& name);
     104
     105        OIS::InputManager* getInputSystem() { return this->inputSystem_; }
     106        bool checkJoyStickID(const std::string& idString) const;
     107        unsigned int getJoyStickQuantity() const
     108            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
    116109
    117110#ifdef ORXONOX_PLATFORM_LINUX
     
    130123        static void reload();
    131124
    132     public: // variables
    133         static EmptyHandler                 EMPTY_HANDLER;
    134 
    135     private: // functions for friends
    136         OIS::InputManager* getInputSystem() { return this->inputSystem_; }
    137         bool checkJoyStickID(const std::string&);
    138 
    139125    private: // functions
    140126        // don't mess with a Singleton
    141         InputManager (const InputManager&);
     127        InputManager(const InputManager&);
    142128
    143129        // Intenal methods
     
    145131        void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight);
    146132        void _initialiseJoySticks();
    147         void _configureJoySticks();
    148133
    149         void _loadCalibration();
    150134        void _startCalibration();
    151         void _completeCalibration();
    152         void _evaluateCalibration();
     135        void _stopCalibration();
    153136
    154         void _destroyKeyboard();
    155         void _destroyMouse();
    156         void _destroyJoySticks();
    157137        void _destroyState(InputState* state);
    158138
    159139        void _reload();
    160140
    161         void _fireAxis(unsigned int iJoyStick, int axis, int value);
    162         unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
    163 
    164141        void _updateActiveStates();
    165142        bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    166143
    167         // input events
    168         bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
    169         bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
    170         bool mouseMoved    (const OIS::MouseEvent    &arg);
    171         bool keyPressed    (const OIS::KeyEvent      &arg);
    172         bool keyReleased   (const OIS::KeyEvent      &arg);
    173 
    174144        void setConfigValues();
    175         void _calibrationFileCallback();
    176145
    177146    private: // variables
    178147        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
    179         OIS::Keyboard*                      keyboard_;             //!< OIS mouse
    180         OIS::Mouse*                         mouse_;                //!< OIS keyboard
    181         std::vector<JoyStick*>              joySticks_;            //!< Orxonox joy sticks
    182         unsigned int                        devicesNum_;
     148        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    183149        size_t                              windowHnd_;            //!< Render window handle
    184150        InputManagerState                   internalState_;        //!< Current internal state
    185151
    186152        // some internally handled states and handlers
    187         SimpleInputState*                   stateEmpty_;
     153        InputState*                         stateEmpty_;
    188154        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    189155        InputBuffer*                        calibratorCallbackBuffer_;
     
    196162
    197163        std::map<int, InputState*>          activeStates_;
    198         std::vector<std::vector<InputState*> > activeStatesTriggered_;
    199164        std::vector<InputState*>            activeStatesTicked_;
    200 
    201         unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
    202 
    203         std::vector<Key>                    keysDown_;
    204         std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_;
    205165
    206166        static InputManager*                singletonRef_s;
    207167    };
    208 
    209     /**
    210     @brief
    211         Creates a new InputState by type, name and priority.
    212        
    213         You will have to use this method because the
    214         c'tors and d'tors are private.
    215     @remarks
    216         The InputManager will take care of the state completely. That also
    217         means it gets deleted when the InputManager is destroyed!
    218     @param name
    219         Name of the InputState when referenced as string
    220     @param priority
    221         Priority matters when multiple states are active. You can specify any
    222         number, but 1 - 99 is preferred (99 means high).
    223     */
    224     template <class T>
    225     T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    226     {
    227         T* state = new T;
    228         if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
    229             return state;
    230         else
    231         {
    232             delete state;
    233             return 0;
    234         }
    235     }
    236168}
    237169
Note: See TracChangeset for help on using the changeset viewer.