Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2009, 11:08:50 PM (15 years ago)
Author:
rgrieder
Message:

Heavy clean up in the InputManager; not many real code changes though.
And temporary hack-fixed a problem in the Keybinder with std::vector.reserve(1000) ;)

File:
1 edited

Legend:

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

    r3276 r3279  
    4444#include <vector>
    4545
    46 #include "util/Math.h"
    47 #include "util/OrxEnum.h"
    4846#include "core/OrxonoxClass.h"
     47#include "InputState.h"
    4948
    5049namespace orxonox
    5150{
    52     struct InputStatePriority : OrxEnum<InputStatePriority>
    53     {
    54         OrxEnumConstructors(InputStatePriority);
    55 
    56         static const int Empty        = -1;
    57         static const int Dynamic      = 0;
    58 
    59         static const int HighPriority = 1000;
    60         static const int Console      = HighPriority + 0;
    61         static const int Calibrator   = HighPriority + 1;
    62         static const int Detector     = HighPriority + 2;
    63     };
    64 
    6551    /**
    6652    @brief
     
    6955    class _CoreExport InputManager : public OrxonoxClass
    7056    {
    71         // --> setConfigValues is private
    72         friend class ClassIdentifier<InputManager>;
    73 
    7457    public:
    75         enum InputManagerState
     58        enum State
    7659        {
    77             Uninitialised    = 0x00,
    78             OISReady         = 0x01,
    79             InternalsReady   = 0x02,
    80             Ticking          = 0x04,
    81             Calibrating      = 0x08,
    82             ReloadRequest    = 0x10,
     60            Nothing       = 0x00,
     61            Bad           = 0x02,
     62            Ticking       = 0x04,
     63            Calibrating   = 0x08,
     64            ReloadRequest = 0x10,
    8365        };
    8466
    8567        InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
    8668        ~InputManager();
     69        void setConfigValues();
    8770
    88         void initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
     71        void update(const Clock& time);
     72        void clearBuffers();
     73        void calibrate();
     74        void reload();
    8975
    90         void reloadInputSystem();
     76        //-------------------------------
     77        // Input States
     78        //-------------------------------
     79        InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
     80        InputState* getState(const std::string& name);
     81        bool enterState     (const std::string& name);
     82        bool leaveState     (const std::string& name);
     83        bool destroyState   (const std::string& name);
    9184
    92         void clearBuffers();
    93 
    94         void setWindowExtents(const int width, const int height);
     85        //-------------------------------
     86        // Various getters and setters
     87        //-------------------------------
    9588        void setKeyDetectorCallback(const std::string& command);
    96 
    97         InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    98 
    99         InputState* getState       (const std::string& name);
    100         InputState* getCurrentState();
    101         bool requestDestroyState   (const std::string& name);
    102         bool requestEnterState     (const std::string& name);
    103         bool requestLeaveState     (const std::string& name);
    104 
    105         OIS::InputManager* getInputSystem() { return this->inputSystem_; }
    10689        bool checkJoyStickID(const std::string& idString) const;
    10790        unsigned int getJoyStickQuantity() const
    10891            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
    109 
    110         void update(const Clock& time);
     92        OIS::InputManager* getOISInputManager()
     93            { return this->oisInputManager_; }
    11194
    11295        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
    113         static InputManager* getInstancePtr() { return singletonRef_s; }
    114 
    115         // console commands
    116         static void calibrate();
    117         static void reload();
    11896
    11997    private: // functions
     
    122100
    123101        // Intenal methods
    124         void _initialiseKeyboard();
    125         void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight);
    126         void _initialiseJoySticks();
     102        void loadDevices(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
     103        void loadMouse(unsigned int windowWidth, unsigned int windowHeight);
     104        void loadJoySticks();
     105        void destroyDevices();
    127106
    128         void _startCalibration();
    129         void _stopCalibration();
     107        void stopCalibration();
    130108
    131         void _destroyState(InputState* state);
     109        void destroyStateInternal(InputState* state);
     110        void updateActiveStates();
     111        bool configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    132112
    133         void _reload();
    134 
    135         void _updateActiveStates();
    136         bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    137 
    138         void setConfigValues();
     113        void reloadInternal();
    139114
    140115    private: // variables
    141         OIS::InputManager*                  inputSystem_;          //!< OIS input manager
     116        State                               internalState_;        //!< Current internal state
     117        OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
    142118        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    143119        size_t                              windowHnd_;            //!< Render window handle
    144         InputManagerState                   internalState_;        //!< Current internal state
    145120
    146121        // some internally handled states and handlers
    147         InputState*                         stateEmpty_;
     122        InputState*                         emptyState_;
    148123        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    149         InputBuffer*                        calibratorCallbackBuffer_;
     124        InputBuffer*                        calibratorCallbackHandler_;
    150125
    151         std::map<std::string, InputState*>  inputStatesByName_;
     126        std::map<std::string, InputState*>  statesByName_;
     127        std::map<int, InputState*>          activeStates_;
     128        std::vector<InputState*>            activeStatesTicked_;
    152129
    153130        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
    154131        std::set<InputState*>               stateLeaveRequests_;   //!< Request to leave a running state
    155132        std::set<InputState*>               stateDestroyRequests_; //!< Request to destroy a state
    156 
    157         std::map<int, InputState*>          activeStates_;
    158         std::vector<InputState*>            activeStatesTicked_;
    159133
    160134        static InputManager*                singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.