Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some de-bugging
added enum for joy stick buttons
some more little fixes

  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
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 */
28
29/**
30@file
31@brief
32    Implementation of a little Input handler that distributes everything
33    coming from OIS.
34*/
35
36#ifndef _InputManager_H__
37#define _InputManager_H__
38
39#include "core/CorePrereqs.h"
40
41#include <map>
42#include <vector>
43#include <stack>
44#include "util/Math.h"
45#include "core/OrxonoxClass.h"
46#include "InputInterfaces.h"
47
48namespace orxonox
49{
50    /**
51    @brief
52        Helper class to realise a vector<int[4]>
53    */
54    class POVStates
55    {
56    public:
57        int operator[](unsigned int index) { return povStates[index]; }
58        int povStates[4];
59    };
60
61    /**
62    @brief
63        Helper class to realise a vector< {int[4], int[4]} >
64    */
65    class SliderStates
66    {
67    public:
68        IntVector2 sliderStates[4];
69    };
70
71    struct JoyStickCalibration
72    {
73        int zeroStates[24];
74        float positiveCoeff[24];
75        float negativeCoeff[24];
76    };
77
78    /**
79    @brief
80        Captures and distributes mouse and keyboard input.
81    */
82    class _CoreExport InputManager
83        : public OrxonoxClass,
84        public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
85    {
86        // --> setConfigValues is private
87        friend ClassIdentifier<InputManager>;
88
89    public: // static functions
90        static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
91                               bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
92        static int  numberOfKeyboards();
93        static int  numberOfMice();
94        static int  numberOfJoySticks();
95
96        static void destroy();
97
98        //static bool isModifierDown(KeyboardModifier::Enum modifier);
99        //static bool isKeyDown(KeyCode::Enum key);
100        //static const MouseState getMouseState();
101        //static const JoyStickState getJoyStickState(unsigned int ID);
102
103        static void setWindowExtents(const int width, const int height);
104
105        static void storeKeyStroke(const std::string& name);
106        static void keyBind(const std::string& command);
107
108        static void calibrate();
109
110        static void tick(float dt);
111
112        static SimpleInputState*   createSimpleInputState  (const std::string& name, int priority);
113        static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
114        static bool destroyState (const std::string& name);
115        static InputState* getState       (const std::string& name);
116        static InputState* getCurrentState();
117        static bool requestEnterState     (const std::string& name);
118        static bool requestLeaveState     (const std::string& name);
119
120    private: // functions
121        // don't mess with a Singleton
122        InputManager ();
123        InputManager (const InputManager&);
124        ~InputManager();
125
126        // Intenal methods
127        bool _initialise(const size_t, int, int, bool, bool, bool);
128        bool _initialiseKeyboard();
129        bool _initialiseMouse();
130        bool _initialiseJoySticks();
131        void _redimensionLists();
132
133        void _destroy();
134        void _destroyKeyboard();
135        void _destroyMouse();
136        void _destroyJoySticks();
137        void _destroyState(InputState* state);
138
139        void _completeCalibration();
140
141        void _fireAxis(unsigned int iJoyStick, int axis, int value);
142        unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
143
144        void _tick(float dt);
145
146        void _updateActiveStates();
147        bool _configureInputState(InputState* state, const std::string& name, int priority);
148
149        // input events
150        bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
151        bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
152        bool mouseMoved    (const OIS::MouseEvent    &arg);
153        bool keyPressed    (const OIS::KeyEvent      &arg);
154        bool keyReleased   (const OIS::KeyEvent      &arg);
155        bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
156        bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
157        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
158        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
159        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
160
161        void setConfigValues();
162
163        static InputManager& _getInstance();
164
165    private: // variables
166        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
167        OIS::Keyboard*                      keyboard_;             //!< OIS mouse
168        OIS::Mouse*                         mouse_;                //!< OIS keyboard
169        std::vector<OIS::JoyStick*>         joySticks_;            //!< OIS joy sticks
170        unsigned int                        joySticksSize_;
171        unsigned int                        devicesNum_;
172
173        // some internally handled states
174        SimpleInputState*                   stateDetector_;        //!< KeyDetector instance
175        SimpleInputState*                   stateCalibrator_;
176        SimpleInputState*                   stateEmpty_;
177
178        std::map<std::string, InputState*>  inputStatesByName_;
179        std::map<int, InputState*>          inputStatesByPriority_;
180
181        std::vector<InputState*>            stateEnterRequests_;   //!< Request to enter a new state
182        std::vector<InputState*>            stateLeaveRequests_;   //!< Request to leave the current state
183
184        std::map<int, InputState*>          activeStates_;
185        std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
186        std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
187
188        // joystick calibration
189        //std::vector<int> marginalsMaxConfig_;
190        //std::vector<int> marginalsMinConfig_;
191        int                                 marginalsMax_[24];
192        int                                 marginalsMin_[24];
193        bool                                bCalibrated_;
194        bool                                bCalibrating_;
195
196        unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
197        std::vector<POVStates>              povStates_;            //!< Keeps track of the joy stick POV states.
198        std::vector<SliderStates>           sliderStates_;         //!< Keeps track of the possibly two slider axes.
199        std::vector<JoyStickCalibration>    joySticksCalibration_; 
200
201        std::vector<Key>                    keysDown_;
202        std::vector<MouseButton::Enum>      mouseButtonsDown_;
203        std::vector<std::vector<JoyStickButton::Enum> >  joyStickButtonsDown_;
204
205        static std::string                  bindingCommmandString_s;
206    };
207
208}
209
210#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.