Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1203 was 1203, checked in by rgrieder, 16 years ago
  • InputManager fully functional (most parts tested), if there wasn't that selfish SpaceShip who claims all the mouse input…
  • InputHandler still loads hard coded key bindings, but works fine otherwise
  • I've tried to give full multiple joy stick support. Couldn't yet test that however. And more than one Joystick still doesn't make sense as long as we don't have split view ;)
File size: 6.5 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 <list>
42
43#include "ois/OIS.h"
44#include "Tickable.h"
45//#include "InputEvent.h"
46#include "InputHandler.h"
47
48namespace orxonox
49{
50  class Mouse : public OIS::Mouse
51  {
52  };
53
54  /**
55    @brief Captures and distributes mouse and keyboard input.
56    It resolves the key bindings to InputEvents which can be heard by
57    implementing the InputEventListener interface.
58  */
59  class _CoreExport InputManager
60        : public Tickable,
61          public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener
62  {
63  public: // enumerations
64    /**
65      @brief Designates the way input is handled and redirected.
66    */
67    enum InputState
68    {
69      IS_UNINIT,  //!< InputManager has not yet been initialised.
70      IS_NONE,    //!< Input is discarded.
71      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
72      IS_GUI,     //!< All OIS input events are passed to CEGUI.
73      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
74      IS_CUSTOM   //!< Any possible configuration.
75    };
76
77  public: // static functions
78    static bool initialise(size_t windowHnd, int windowWidth, int windowHeight,
79          bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
80    static bool initialiseKeyboard();
81    static bool initialiseMouse();
82    static bool initialiseJoySticks();
83
84    static void destroy();
85    static void destroyKeyboard();
86    static void destroyMouse();
87    static void destroyJoySticks();
88
89    static void setWindowExtents(int width, int height);
90
91    static void setInputState(const InputState state);
92    static InputState getInputState();
93    static void setKeyBindingState           (bool bActive);
94    static void setMouseButtonBindingState   (bool bActive);
95    static void setJoyStickButtonBindingState(bool bActive);
96
97    static bool addKeyListener(KeyHandler* listener, const std::string& name);
98    static bool removeKeyListener  (const std::string& name);
99    static bool enableKeyListener  (const std::string& name);
100    static bool disableKeyListener (const std::string& name);
101    static bool isKeyListenerActive(const std::string& name);
102    static KeyHandler* getKeyListener(const std::string& name);
103
104    static bool addMouseListener(MouseHandler* listener, const std::string& name);
105    static bool removeMouseListener  (const std::string& name);
106    static bool enableMouseListener  (const std::string& name);
107    static bool disableMouseListener (const std::string& name);
108    static bool isMouseListenerActive(const std::string& name);
109    static MouseHandler* getMouseListener(const std::string& name);
110
111    static bool addJoyStickListener(JoyStickHandler* listener, const std::string& name);
112    static bool removeJoyStickListener  (const std::string& name);
113    static bool enableJoyStickListener  (const std::string& name, const int id);
114    static bool disableJoyStickListener (const std::string& name, const int id);
115    static bool isJoyStickListenerActive(const std::string& name);
116    static JoyStickHandler* getJoyStickListener(const std::string& name);
117
118    // Temporary solutions. Will be removed soon!
119    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
120    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
121
122  private: // functions
123    // don't mess with a Singleton
124    InputManager ();
125    InputManager (const InputManager&);
126    ~InputManager();
127
128    // Intenal methods
129    bool _initialise(size_t, int, int, bool, bool, bool);
130    bool _initialiseKeyboard();
131    bool _initialiseMouse();
132    bool _initialiseJoySticks();
133
134    void _destroy();
135    void _destroyKeyboard();
136    void _destroyMouse();
137    void _destroyJoySticks();
138
139    //void _setNumberOfJoysticks(int size);
140
141    void tick(float dt);
142
143    // input events
144                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
145                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
146    bool mouseMoved    (const OIS::MouseEvent    &arg);
147                bool keyPressed    (const OIS::KeyEvent      &arg);
148                bool keyReleased   (const OIS::KeyEvent      &arg);
149                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
150                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
151                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
152                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
153                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
154
155    static InputManager& _getSingleton();
156    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
157
158  private: // variables
159    OIS::InputManager* inputSystem_;            //!< OIS input manager
160    OIS::Keyboard*     keyboard_;               //!< OIS mouse
161    OIS::Mouse*        mouse_;                  //!< OIS keyboard
162    std::map<int, OIS::JoyStick*> joySticks_;   //!< OIS joy sticks
163
164    InputState state_;
165    InputState stateRequest_;
166
167    std::map<std::string, KeyHandler*>      listenersKey_;
168    std::map<std::string, MouseHandler*>    listenersMouse_;
169    std::map<std::string, JoyStickHandler*> listenersJoySticks_;
170
171    std::list<KeyHandler*>      listenersKeyActive_;
172    std::list<MouseHandler*>    listenersMouseActive_;
173    std::map< int, std::list<JoyStickHandler*> > listenersJoySticksActive_;
174
175    std::list<OIS::KeyCode>         keysDown_;
176    std::list<OIS::MouseButtonID>   mouseButtonsDown_;
177    std::map< int, std::list<int> > joySticksButtonsDown_;
178
179  };
180}
181
182#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.