Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1195 was 1195, checked in by rgrieder, 17 years ago
  • added OIS to the orxonox src directory
  • adapted VS files
File size: 7.8 KB
RevLine 
[918]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]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
[1062]38#include "CorePrereqs.h"
39
[1182]40#include <map>
41#include <list>
[973]42
[1195]43#include "ois/OIS.h"
[1062]44#include "Tickable.h"
[973]45#include "InputEvent.h"
46
47namespace orxonox
48{
49  /**
50    @brief Captures and distributes mouse and keyboard input.
51    It resolves the key bindings to InputEvents which can be heard by
52    implementing the InputEventListener interface.
53  */
54  class _CoreExport InputManager
[1182]55        : public Tickable,
56          public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener
[973]57  {
[1193]58  public: // enumerations
[1182]59    /**
[1193]60      @brief Designates the way input is handled and redirected.
[1182]61    */
62    enum InputState
63    {
[1193]64      IS_UNINIT,  //!< InputManager has not yet been initialised.
65      IS_NONE,    //!< Input is discarded.
66      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
67      IS_GUI,     //!< All OIS input events are passed to CEGUI.
68      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
69      IS_CUSTOM   //!< Any possible configuration.
[1182]70    };
71
[1193]72  public: // functions
73    // METHODS OF THE STATIC INTERFACE
[973]74
[1193]75    static bool initialise(size_t windowHnd, int windowWidth, int windowHeight,
76          bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
[1182]77    static void destroy();
[1066]78
[1182]79    static void setWindowExtents(int width, int height);
[1193]80
[1182]81    static void setInputState(const InputState state);
82    static InputState getInputState();
[1193]83    static void setKeyBindingState           (bool bActive);
84    static void setMouseButtonBindingState   (bool bActive);
85    static void setJoyStickButtonBindingState(bool bActive);
[1182]86
87    static bool addKeyListener(OIS::KeyListener* listener, const std::string& name);
[1193]88    static bool removeKeyListener  (const std::string& name);
89    static bool enableKeyListener  (const std::string& name);
90    static bool disableKeyListener (const std::string& name);
91    static bool isKeyListenerActive(const std::string& name);
[1182]92    static OIS::KeyListener* getKeyListener(const std::string& name);
93
94    static bool addMouseListener(OIS::MouseListener* listener, const std::string& name);
[1193]95    static bool removeMouseListener  (const std::string& name);
96    static bool enableMouseListener  (const std::string& name);
97    static bool disableMouseListener (const std::string& name);
98    static bool isMouseListenerActive(const std::string& name);
[1182]99    static OIS::MouseListener* getMouseListener(const std::string& name);
100
101    static bool addJoyStickListener(OIS::JoyStickListener* listener, const std::string& name);
[1193]102    static bool removeJoyStickListener  (const std::string& name);
103    static bool enableJoyStickListener  (const std::string& name);
104    static bool disableJoyStickListener (const std::string& name);
105    static bool isJoyStickListenerActive(const std::string& name);
[1182]106    static OIS::JoyStickListener* getJoyStickListener(const std::string& name);
107
[973]108    // Temporary solutions. Will be removed soon!
[1182]109    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
110    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
[973]111
[1193]112  private: // functions
[973]113    // don't mess with a Singleton
114    InputManager ();
115    InputManager (const InputManager&);
116    ~InputManager();
117
[1193]118    // Intenal methods
119    bool _initialise(size_t, int, int, bool, bool, bool);
120    void _initialiseKeyboard();
121    void _initialiseMouse();
122    void _initialiseJoySticks();
[1182]123    void _destroy();
[1193]124    //void _setDefaultState();
125    bool _loadBindings();
126    void _clearBindings();
127    void _setNumberOfJoysticks(int size);
[973]128
[1193]129    void tick(float dt);
130
[1182]131    // input events
132                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
133                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
134    bool mouseMoved    (const OIS::MouseEvent    &arg);
135                bool keyPressed    (const OIS::KeyEvent      &arg);
136                bool keyReleased   (const OIS::KeyEvent      &arg);
137                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
138                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
139                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
140                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
141                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
[973]142
[1182]143    static InputManager& _getSingleton();
144    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
145
[1193]146  private: // variables
[1182]147    OIS::InputManager* inputSystem_;    //!< OIS input manager
148    OIS::Keyboard*     keyboard_;       //!< OIS mouse
149    OIS::Mouse*        mouse_;          //!< OIS keyboard
[1193]150    std::vector<OIS::JoyStick*> joySticks_;       //!< OIS joy sticks
[1182]151
152    InputState state_;
153    InputState stateRequest_;
154
[1193]155    bool bKeyBindingsActive_;
156    bool bMouseButtonBindingsActive_;
157    std::vector<bool> bJoyStickButtonBindingsActive_;
[1182]158
[1193]159    std::map<std::string, OIS::KeyListener*>      listenersKey_;
160    std::map<std::string, OIS::MouseListener*>    listenersMouse_;
161    std::map<std::string, OIS::JoyStickListener*> listenersJoySticks_;
[1182]162
[1193]163    std::list<OIS::KeyListener*>      listenersKeyActive_;
164    std::list<OIS::MouseListener*>    listenersMouseActive_;
165    std::list<OIS::JoyStickListener*> listenersJoySticksActive_;
[1182]166
[1193]167    std::list<OIS::KeyCode>         keysDown_;
168    std::list<OIS::MouseButtonID>   mouseButtonsDown_;
169    std::vector< std::list<int> >   joyStickButtonsDown_;
[1182]170
[1193]171
[1182]172    /** denotes the maximum number of different keys there are in OIS.
[1193]173        256 should be ok since the highest number in the OIS enum is 237. */
[1182]174    static const int numberOfKeys_s = 256;
175    //! Array of input events for every pressed key
176    std::string bindingsKeyPress_  [numberOfKeys_s];
177    //! Array of input events for every released key
178    std::string bindingsKeyRelease_[numberOfKeys_s];
179    //! Array of input events for every held key
180    std::string bindingsKeyHold_   [numberOfKeys_s];
181
182    /** denotes the maximum number of different buttons there are in OIS.
[1193]183        16 should be ok since the highest number in the OIS enum is 7. */
[1182]184    static const int numberOfMouseButtons_s = 16;
185    //! Array of input events for every pressed mouse button
186    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
187    //! Array of input events for every released mouse button
188    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
189    //! Array of input events for every held mouse button
190    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
191
192    /** denotes the maximum number of different buttons there are in OIS.
193        32 should be ok. */
194    static const int numberOfJoyStickButtons_s = 32;
[1193]195    std::vector< std::vector< std::string > > bindingsJoyStickButtonPress_;
196    std::vector< std::vector< std::string > > bindingsJoyStickButtonRelease_;
197    std::vector< std::vector< std::string > > bindingsJoyStickButtonHold_;
[1182]198
[973]199  };
200}
201
202#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.