Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/input/InputManager.h @ 1751

Last change on this file since 1751 was 1555, checked in by landauf, 17 years ago
  • ParticleInterface uses Orxonox::getTimeFactor to make particle effects independend of gamespeed (but there's still a drawback with thrusters)
  • reduced OIS includes in input-related classes, changed OIS search and include to avoid conflicts with other versions of OIS (for example in Ogre). not yet tested on tardis.
  • Property svn:eol-style set to native
File size: 9.2 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/**
30 @file
31 @brief Implementation of a little Input handler that distributes everything
32        coming from OIS.
33 */
[973]34
35#ifndef _InputManager_H__
36#define _InputManager_H__
37
[1519]38#include "core/CorePrereqs.h"
[1062]39
[1219]40#include <map>
[1293]41#include <vector>
[973]42
[1349]43#include "util/Math.h"
[1524]44#include "core/OrxonoxClass.h"
[1293]45#include "InputInterfaces.h"
[973]46
47namespace orxonox
48{
49  /**
[1349]50  * Helper class to realise a vector<int[4]>
51  */
52  class POVStates
53  {
54  public:
55    int operator[](unsigned int index) { return povStates[index]; }
56    int povStates[4];
57  };
58
59  /**
60  * Helper class to realise a vector< {int[4], int[4]} >
61  */
62  class SliderStates
63  {
64  public:
65    IntVector2 sliderStates[4];
66  };
67
68  /**
[1502]69  * Struct for storing a custom input state
70  */
71  struct StoredState
72  {
73    std::vector<KeyHandler*>                    activeKeyHandlers_;
74    std::vector<MouseHandler*>                  activeMouseHandlers_;
75    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
76    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
77  };
78
79  struct JoyStickCalibration
80  {
81    int zeroStates[24];
82    float positiveCoeff[24];
83    float negativeCoeff[24];
84  };
85
86  /**
[973]87    @brief Captures and distributes mouse and keyboard input.
88  */
89  class _CoreExport InputManager
[1524]90        : public OrxonoxClass,
[1219]91          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
[973]92  {
[1219]93  public: // enumerations
94    /**
95      @brief Designates the way input is handled and redirected.
96    */
97    enum InputState
98    {
[1502]99      IS_UNINIT,    //!< InputManager has not yet been initialised.
100      IS_NONE,      //!< Input is discarded.
101      IS_NORMAL,    //!< Normal play state. Key and button bindings are active.
102      IS_GUI,       //!< All OIS input events are passed to CEGUI.
103      IS_CONSOLE,   //!< Keyboard input is redirected to the InputBuffer.
104      IS_DETECT,    //!< All the input additionally goes to the KeyDetector
105      IS_NODETECT,  //!< remove KeyDetector
106      IS_NOCALIBRATE,
107      IS_CALIBRATE,
108      IS_CUSTOM     //!< Any possible configuration.
[1219]109    };
[973]110
[1502]111  public: // member functions
112    void setConfigValues();
113
[1219]114  public: // static functions
[1293]115    static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
116          bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
[1219]117    static bool initialiseKeyboard();
118    static bool initialiseMouse();
119    static bool initialiseJoySticks();
120    static int  numberOfKeyboards();
121    static int  numberOfMice();
122    static int  numberOfJoySticks();
[1066]123
[1219]124    static void destroy();
125    static void destroyKeyboard();
126    static void destroyMouse();
127    static void destroyJoySticks();
128
[1502]129    //static bool isModifierDown(KeyboardModifier::Enum modifier);
130    //static bool isKeyDown(KeyCode::Enum key);
[1349]131    //static const MouseState getMouseState();
132    //static const JoyStickState getJoyStickState(unsigned int ID);
[1293]133
[1219]134    static void setWindowExtents(const int width, const int height);
135
136    static void setInputState(const InputState state);
137    static InputState getInputState();
138
[1502]139    static void storeKeyStroke(const std::string& name);
140    static void keyBind(const std::string& command);
141
142    static void calibrate();
143
[1524]144    static void tick(float dt);
145
[1219]146    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
147    static bool removeKeyHandler              (const std::string& name);
148    static KeyHandler* getKeyHandler          (const std::string& name);
149    static bool enableKeyHandler              (const std::string& name);
150    static bool disableKeyHandler             (const std::string& name);
151    static bool isKeyHandlerActive            (const std::string& name);
152
153    static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
154    static bool removeMouseHandler            (const std::string& name);
155    static MouseHandler* getMouseHandler      (const std::string& name);
156    static bool enableMouseHandler            (const std::string& name);
157    static bool disableMouseHandler           (const std::string& name);
158    static bool isMouseHandlerActive          (const std::string& name);
159
160    static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
161    static bool removeJoyStickHandler         (const std::string& name);
162    static JoyStickHandler* getJoyStickHandler(const std::string& name);
[1293]163    static bool enableJoyStickHandler         (const std::string& name, unsigned int id);
164    static bool disableJoyStickHandler        (const std::string& name, unsigned int id);
165    static bool isJoyStickHandlerActive       (const std::string& name, unsigned int id);
[1219]166
167  private: // functions
[973]168    // don't mess with a Singleton
169    InputManager ();
170    InputManager (const InputManager&);
171    ~InputManager();
172
[1219]173    // Intenal methods
[1293]174    bool _initialise(const size_t, int, int, bool, bool, bool);
[1219]175    bool _initialiseKeyboard();
176    bool _initialiseMouse();
177    bool _initialiseJoySticks();
[973]178
[1219]179    void _destroy();
180    void _destroyKeyboard();
181    void _destroyMouse();
182    void _destroyJoySticks();
[973]183
[1349]184    void _updateTickables();
185
[1502]186    void _saveState();
187    void _restoreState();
188
189    void _completeCalibration();
190
191    void _fireAxis(unsigned int iJoyStick, int axis, int value);
192    unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
193
[1524]194    void _tick(float dt);
[1219]195
196    // input events
[1293]197    bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
198    bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
[1219]199    bool mouseMoved    (const OIS::MouseEvent    &arg);
[1293]200    bool keyPressed    (const OIS::KeyEvent      &arg);
201    bool keyReleased   (const OIS::KeyEvent      &arg);
[1502]202    bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
203    bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
204    bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
205    bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
206    bool povMoved      (const OIS::JoyStickEvent &arg, int id);
207    //bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
[1219]208
209    static InputManager& _getSingleton();
210    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
211
212  private: // variables
[1502]213    OIS::InputManager*                          inputSystem_;     //!< OIS input manager
214    OIS::Keyboard*                              keyboard_;        //!< OIS mouse
215    OIS::Mouse*                                 mouse_;           //!< OIS keyboard
216    std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
[1293]217    unsigned int                                joySticksSize_;
[1219]218
[1502]219    KeyBinder*                                  keyBinder_;       //!< KeyBinder instance
220    KeyDetector*                                keyDetector_;     //!< KeyDetector instance
221    InputBuffer*                                buffer_;          //!< InputBuffer instance
222    CalibratorCallback*                         calibratorCallback_;
223
[1219]224    InputState state_;
225    InputState stateRequest_;
[1502]226    InputState savedState_;
[1293]227    unsigned int keyboardModifiers_;
[1502]228    StoredState savedHandlers_;
[1219]229
[1502]230    // joystick calibration
231    //std::vector<int> marginalsMaxConfig_;
232    //std::vector<int> marginalsMinConfig_;
233    int marginalsMax_[24];
234    int marginalsMin_[24];
235    bool bCalibrated_;
236
[1349]237    //! Keeps track of the joy stick POV states
238    std::vector<POVStates>                      povStates_;
239    //! Keeps track of the possibly two slider axes
240    std::vector<SliderStates>                   sliderStates_;
[1502]241    std::vector<JoyStickCalibration>            joySticksCalibration_;
[1349]242
[1219]243    std::map<std::string, KeyHandler*>          keyHandlers_;
244    std::map<std::string, MouseHandler*>        mouseHandlers_;
245    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
246
247    std::vector<KeyHandler*>                    activeKeyHandlers_;
248    std::vector<MouseHandler*>                  activeMouseHandlers_;
[1293]249    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
[1502]250    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
[1219]251
[1293]252    std::vector<Key>                            keysDown_;
253    std::vector<MouseButton::Enum>              mouseButtonsDown_;
254    std::vector<std::vector<int> >              joyStickButtonsDown_;
[1219]255
[1502]256    static std::string                          bindingCommmandString_s;
[973]257  };
[1293]258
[973]259}
260
261#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.