Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 6, 2009, 12:03:05 PM (16 years ago)
Author:
rgrieder
Message:

Extracted joy stick related code from InputManager to a new JoyStick class in order to make the InputManger less of a monster class and to apply a little bit more OO.

File:
1 edited

Legend:

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

    r3196 r3270  
    5454namespace orxonox
    5555{
    56     /**
    57     @brief
    58         Helper class to realise a vector<int[4]>
    59     */
    60     class POVStates
    61     {
    62     public:
    63         int& operator[](unsigned int index) { return povStates[index]; }
    64         int povStates[4];
    65     };
    66 
    67     /**
    68     @brief
    69         Helper class to realise a vector< {int[4], int[4]} >
    70     */
    71     class SliderStates
    72     {
    73     public:
    74         IntVector2 sliderStates[4];
    75     };
    76 
    77     struct JoyStickCalibration
    78     {
    79         int middleValue[24];
    80         float positiveCoeff[24];
    81         float negativeCoeff[24];
    82     };
    83 
    8456    struct InputStatePriority : OrxEnum<InputStatePriority>
    8557    {
     
    10173    class _CoreExport InputManager
    10274        : public OrxonoxClass,
    103         public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
     75        public OIS::KeyListener, public OIS::MouseListener
    10476    {
    10577        // --> setConfigValues is private
    10678        friend class ClassIdentifier<InputManager>;
     79        friend class JoyStick;
    10780
    10881    public:
     
    11588            Calibrating      = 0x08,
    11689            ReloadRequest    = 0x10,
    117             JoyStickSupport  = 0x20 // used with ReloadRequest to store a bool
    11890        };
    11991
    120         InputManager ();
     92        InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
    12193        ~InputManager();
    12294
    123         void initialise(size_t windowHnd, int windowWidth, int windowHeight, bool joyStickSupport = true);
    124 
    125         void reloadInputSystem(bool joyStickSupport = true);
     95        void initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
     96
     97        void reloadInputSystem();
    12698
    12799        void clearBuffers();
     
    129101        unsigned int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
    130102        unsigned int  numberOfMice()      { return mouse_    ? 1 : 0; }
    131         unsigned int  numberOfJoySticks() { return joySticksSize_; }
     103        unsigned int  numberOfJoySticks() { return joySticks_.size(); }
    132104
    133105        void setWindowExtents(const int width, const int height);
     
    156128        // console commands
    157129        static void calibrate();
    158         static void reload(bool joyStickSupport = true);
     130        static void reload();
    159131
    160132    public: // variables
    161133        static EmptyHandler                 EMPTY_HANDLER;
    162         static const unsigned int           sliderAxes = 8;
     134
     135    private: // functions for friends
     136        OIS::InputManager* getInputSystem() { return this->inputSystem_; }
     137        bool checkJoyStickID(const std::string&);
    163138
    164139    private: // functions
     
    168143        // Intenal methods
    169144        void _initialiseKeyboard();
    170         void _initialiseMouse();
     145        void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight);
    171146        void _initialiseJoySticks();
    172147        void _configureJoySticks();
     
    181156        void _destroyJoySticks();
    182157        void _destroyState(InputState* state);
    183         void _clearBuffers();
    184 
    185         void _reload(bool joyStickSupport);
     158
     159        void _reload();
    186160
    187161        void _fireAxis(unsigned int iJoyStick, int axis, int value);
     
    197171        bool keyPressed    (const OIS::KeyEvent      &arg);
    198172        bool keyReleased   (const OIS::KeyEvent      &arg);
    199         bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
    200         bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
    201         bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
    202         bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    203         bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    204         // don't remove that! Or else add OIS as dependency library to orxonox.
    205         bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
    206173
    207174        void setConfigValues();
     
    212179        OIS::Keyboard*                      keyboard_;             //!< OIS mouse
    213180        OIS::Mouse*                         mouse_;                //!< OIS keyboard
    214         std::vector<OIS::JoyStick*>         joySticks_;            //!< OIS joy sticks
    215         unsigned int                        joySticksSize_;
    216         std::vector<std::string>            joyStickIDs_;          //!< Execution unique identification strings for the joy sticks
     181        std::vector<JoyStick*>              joySticks_;            //!< Orxonox joy sticks
    217182        unsigned int                        devicesNum_;
    218183        size_t                              windowHnd_;            //!< Render window handle
     
    234199        std::vector<InputState*>            activeStatesTicked_;
    235200
    236         // joystick calibration
    237         std::vector<std::vector<int> >      joyStickMinValues_;
    238         std::vector<std::vector<int> >      joyStickMaxValues_;
    239         std::vector<std::vector<int> >      joyStickMiddleValues_;
    240         std::vector<ConfigValueContainer*>  calibrationConfigValueContainers_;
    241         std::vector<JoyStickCalibration>    joyStickCalibrations_;
    242 
    243201        unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
    244         std::vector<POVStates>              povStates_;            //!< Keeps track of the joy stick POV states.
    245         std::vector<SliderStates>           sliderStates_;         //!< Keeps track of the possibly two slider axes.
    246202
    247203        std::vector<Key>                    keysDown_;
    248         std::vector<MouseButtonCode::ByEnum>      mouseButtonsDown_;
    249         std::vector<std::vector<JoyStickButtonCode::ByEnum> >  joyStickButtonsDown_;
    250 
    251         // ConfigValues
    252         std::string                         calibrationFilename_;  //!< Joy stick calibration ini filename
     204        std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_;
    253205
    254206        static InputManager*                singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.