Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/input/InputManager.h @ 1630

Last change on this file since 1630 was 1630, checked in by rgrieder, 16 years ago

converted input system to 4 spaces/tab

  • Property svn:eol-style set to native
File size: 9.9 KB
RevLine 
[918]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1502]3 *                    > www.orxonox.net <
[918]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
[973]28
[918]29/**
[1630]30@file
31@brief
32    Implementation of a little Input handler that distributes everything
33    coming from OIS.
34*/
[973]35
36#ifndef _InputManager_H__
37#define _InputManager_H__
38
[1519]39#include "core/CorePrereqs.h"
[1062]40
[1219]41#include <map>
[1293]42#include <vector>
[1349]43#include "util/Math.h"
[1524]44#include "core/OrxonoxClass.h"
[1293]45#include "InputInterfaces.h"
[973]46
47namespace orxonox
48{
[1630]49    /**
50    @brief
51        Helper class to realise a vector<int[4]>
52    */
53    class POVStates
54    {
55    public:
56        int operator[](unsigned int index) { return povStates[index]; }
57        int povStates[4];
58    };
[1349]59
[1630]60    /**
61    @brief
62        Helper class to realise a vector< {int[4], int[4]} >
63    */
64    class SliderStates
65    {
66    public:
67        IntVector2 sliderStates[4];
68    };
[1349]69
[1630]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    };
[1502]81
[1630]82    struct JoyStickCalibration
83    {
84        int zeroStates[24];
85        float positiveCoeff[24];
86        float negativeCoeff[24];
87    };
[1502]88
[1219]89    /**
[1630]90    @brief
91        Captures and distributes mouse and keyboard input.
[1219]92    */
[1630]93    class _CoreExport InputManager
94        : public OrxonoxClass,
95        public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
[1219]96    {
[1630]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        };
[973]115
[1630]116    public: // member functions
117        void setConfigValues();
[1502]118
[1630]119    public: // static functions
120        static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
121                               bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
122        static bool initialiseKeyboard();
123        static bool initialiseMouse();
124        static bool initialiseJoySticks();
125        static int  numberOfKeyboards();
126        static int  numberOfMice();
127        static int  numberOfJoySticks();
[1066]128
[1630]129        static void destroy();
130        static void destroyKeyboard();
131        static void destroyMouse();
132        static void destroyJoySticks();
[1219]133
[1630]134        //static bool isModifierDown(KeyboardModifier::Enum modifier);
135        //static bool isKeyDown(KeyCode::Enum key);
136        //static const MouseState getMouseState();
137        //static const JoyStickState getJoyStickState(unsigned int ID);
[1293]138
[1630]139        static void setWindowExtents(const int width, const int height);
[1219]140
[1630]141        static void setInputState(const InputState state);
142        static InputState getInputState();
[1219]143
[1630]144        static void storeKeyStroke(const std::string& name);
145        static void keyBind(const std::string& command);
[1502]146
[1630]147        static void calibrate();
[1502]148
[1630]149        static void tick(float dt);
[1524]150
[1630]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);
[1219]157
[1630]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);
[1219]164
[1630]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);
[1219]171
[1630]172    private: // functions
173        // don't mess with a Singleton
174        InputManager ();
175        InputManager (const InputManager&);
176        ~InputManager();
[973]177
[1630]178        // Intenal methods
179        bool _initialise(const size_t, int, int, bool, bool, bool);
180        bool _initialiseKeyboard();
181        bool _initialiseMouse();
182        bool _initialiseJoySticks();
[973]183
[1630]184        void _destroy();
185        void _destroyKeyboard();
186        void _destroyMouse();
187        void _destroyJoySticks();
[973]188
[1630]189        void _updateTickables();
[1349]190
[1630]191        void _saveState();
192        void _restoreState();
[1502]193
[1630]194        void _completeCalibration();
[1502]195
[1630]196        void _fireAxis(unsigned int iJoyStick, int axis, int value);
197        unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
[1502]198
[1630]199        void _tick(float dt);
[1219]200
[1630]201        // input events
202        bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
203        bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
204        bool mouseMoved    (const OIS::MouseEvent    &arg);
205        bool keyPressed    (const OIS::KeyEvent      &arg);
206        bool keyReleased   (const OIS::KeyEvent      &arg);
207        bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
208        bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
209        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
210        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
211        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
212        //bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
[1219]213
[1630]214        static InputManager& _getSingleton();
215        static InputManager* _getSingletonPtr() { return &_getSingleton(); }
[1219]216
[1630]217    private: // variables
218        OIS::InputManager*                          inputSystem_;     //!< OIS input manager
219        OIS::Keyboard*                              keyboard_;        //!< OIS mouse
220        OIS::Mouse*                                 mouse_;           //!< OIS keyboard
221        std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
222        unsigned int                                joySticksSize_;
[1219]223
[1630]224        KeyBinder*                                  keyBinder_;       //!< KeyBinder instance
225        KeyDetector*                                keyDetector_;     //!< KeyDetector instance
226        InputBuffer*                                buffer_;          //!< InputBuffer instance
227        CalibratorCallback*                         calibratorCallback_;
[1502]228
[1630]229        InputState state_;
230        InputState stateRequest_;
231        InputState savedState_;
232        unsigned int keyboardModifiers_;
233        StoredState savedHandlers_;
[1219]234
[1630]235        // joystick calibration
236        //std::vector<int> marginalsMaxConfig_;
237        //std::vector<int> marginalsMinConfig_;
238        int marginalsMax_[24];
239        int marginalsMin_[24];
240        bool bCalibrated_;
[1502]241
[1630]242        //! Keeps track of the joy stick POV states
243        std::vector<POVStates>                      povStates_;
244        //! Keeps track of the possibly two slider axes
245        std::vector<SliderStates>                   sliderStates_;
246        std::vector<JoyStickCalibration>            joySticksCalibration_;
[1349]247
[1630]248        std::map<std::string, KeyHandler*>          keyHandlers_;
249        std::map<std::string, MouseHandler*>        mouseHandlers_;
250        std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
[1219]251
[1630]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_;
[1219]256
[1630]257        std::vector<Key>                            keysDown_;
258        std::vector<MouseButton::Enum>              mouseButtonsDown_;
259        std::vector<std::vector<int> >              joyStickButtonsDown_;
[1219]260
[1630]261        static std::string                          bindingCommmandString_s;
262    };
[1293]263
[973]264}
265
266#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.