Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/InputManager.h @ 1308

Last change on this file since 1308 was 1293, checked in by scheusso, 17 years ago

merged changes from input & camera & network branch into trunk

File size: 6.7 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 Implementation of a little Input handler that distributes everything
32        coming from OIS.
33 */
34
35#ifndef _InputManager_H__
36#define _InputManager_H__
37
38#include "CorePrereqs.h"
39
40#include <map>
41#include <vector>
42
43#include "ois/OIS.h"
44#include "Tickable.h"
45#include "InputInterfaces.h"
46
47namespace orxonox
48{
49  /**
50    @brief Captures and distributes mouse and keyboard input.
51  */
52  class _CoreExport InputManager
53        : public TickableReal,
54          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
55  {
56  public: // enumerations
57    /**
58      @brief Designates the way input is handled and redirected.
59    */
60    enum InputState
61    {
62      IS_UNINIT,  //!< InputManager has not yet been initialised.
63      IS_NONE,    //!< Input is discarded.
64      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
65      IS_GUI,     //!< All OIS input events are passed to CEGUI.
66      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
67      IS_CUSTOM   //!< Any possible configuration.
68    };
69
70  public: // static functions
71    static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
72          bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
73    static bool initialiseKeyboard();
74    static bool initialiseMouse();
75    static bool initialiseJoySticks();
76    static int  numberOfKeyboards();
77    static int  numberOfMice();
78    static int  numberOfJoySticks();
79
80    static void destroy();
81    static void destroyKeyboard();
82    static void destroyMouse();
83    static void destroyJoySticks();
84
85    static bool isModifierDown(KeyboardModifier::Enum modifier);
86    static bool isKeyDown(KeyCode::Enum key);
87    static const MouseState getMouseState();
88    static const JoyStickState getJoyStickState(unsigned int ID);
89
90    static void setWindowExtents(const int width, const int height);
91
92    static void setInputState(const InputState state);
93    static InputState getInputState();
94
95    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
96    static bool removeKeyHandler              (const std::string& name);
97    static KeyHandler* getKeyHandler          (const std::string& name);
98    static bool enableKeyHandler              (const std::string& name);
99    static bool disableKeyHandler             (const std::string& name);
100    static bool isKeyHandlerActive            (const std::string& name);
101
102    static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
103    static bool removeMouseHandler            (const std::string& name);
104    static MouseHandler* getMouseHandler      (const std::string& name);
105    static bool enableMouseHandler            (const std::string& name);
106    static bool disableMouseHandler           (const std::string& name);
107    static bool isMouseHandlerActive          (const std::string& name);
108
109    static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
110    static bool removeJoyStickHandler         (const std::string& name);
111    static JoyStickHandler* getJoyStickHandler(const std::string& name);
112    static bool enableJoyStickHandler         (const std::string& name, unsigned int id);
113    static bool disableJoyStickHandler        (const std::string& name, unsigned int id);
114    static bool isJoyStickHandlerActive       (const std::string& name, unsigned int id);
115
116  private: // functions
117    // don't mess with a Singleton
118    InputManager ();
119    InputManager (const InputManager&);
120    ~InputManager();
121
122    // Intenal methods
123    bool _initialise(const size_t, int, int, bool, bool, bool);
124    bool _initialiseKeyboard();
125    bool _initialiseMouse();
126    bool _initialiseJoySticks();
127
128    void _destroy();
129    void _destroyKeyboard();
130    void _destroyMouse();
131    void _destroyJoySticks();
132
133    void tick(float dt);
134
135    // input events
136    bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
137    bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
138    bool mouseMoved    (const OIS::MouseEvent    &arg);
139    bool keyPressed    (const OIS::KeyEvent      &arg);
140    bool keyReleased   (const OIS::KeyEvent      &arg);
141    bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
142    bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
143    bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
144    bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
145    bool povMoved      (const OIS::JoyStickEvent &arg, int id);
146    bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
147
148    static InputManager& _getSingleton();
149    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
150
151  private: // variables
152    OIS::InputManager*                          inputSystem_; //!< OIS input manager
153    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
154    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
155    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
156    unsigned int                                joySticksSize_;
157
158    InputState state_;
159    InputState stateRequest_;
160    unsigned int keyboardModifiers_;
161
162    std::map<std::string, KeyHandler*>          keyHandlers_;
163    std::map<std::string, MouseHandler*>        mouseHandlers_;
164    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
165
166    std::vector<KeyHandler*>                    activeKeyHandlers_;
167    std::vector<MouseHandler*>                  activeMouseHandlers_;
168    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
169
170    std::vector<Key>                            keysDown_;
171    std::vector<MouseButton::Enum>              mouseButtonsDown_;
172    std::vector<std::vector<int> >              joyStickButtonsDown_;
173
174  };
175
176}
177
178#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.