Orxonox  0.0.5 Codename: Arcturus
InputManager.h
Go to the documentation of this file.
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 #ifndef _InputManager_H__
30 #define _InputManager_H__
31 
32 #include "InputPrereqs.h"
33 
34 #include <map>
35 #include <string>
36 #include <vector>
37 #include <functional>
38 
39 #include "util/Singleton.h"
40 #include "util/tribool.h"
42 
43 // tolua_begin
44 namespace orxonox
45 {
67 // tolua_end
68  : public Singleton<InputManager>, public WindowEventListener
69  { // tolua_export
70  friend class Singleton<InputManager>;
71  public:
73  enum State
74  {
75  Nothing = 0x00,
76  Bad = 0x02,
77  Calibrating = 0x04,
78  };
79 
87  InputManager();
89  ~InputManager();
90  void setConfigValues();
91 
99  void preUpdate(const Clock& time);
101  void clearBuffers();
103  void calibrate();
110  void reload();
111 
112  //-------------------------------
113  // Input States
114  //-------------------------------
131  InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
138  InputState* getState(const std::string& name);
146  bool enterState(const std::string& name); // tolua_export
153  bool leaveState(const std::string& name); // tolua_export
163  bool destroyState(const std::string& name); // tolua_export
170  bool setMouseExclusive(const std::string& name, tribool value); // tolua_export
171 
172  //-------------------------------
173  // Various getters and setters
174  //-------------------------------
176  unsigned int getJoyStickQuantity() const
177  { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
179  OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
181  std::pair<int, int> getMousePosition() const;
183  bool isMouseExclusive() const { return this->exclusiveMouse_; } // tolua_export
184 
185  //-------------------------------
186  // Function call caching
187  //-------------------------------
188  void pushCall(const std::function<void ()>& function)
189  { this->callBuffer_.push_back(function); }
190 
191  static InputManager& getInstance() { return Singleton<InputManager>::getInstance(); } // tolua_export
192 
193  private: // functions
194  // non-copyable:
195  InputManager(const InputManager&) = delete;
196  InputManager& operator=(const InputManager&) = delete;
197 
198  // Internal methods
199  void loadDevices();
200  void loadMouse();
201  void loadJoySticks();
202  void destroyDevices();
203 
204  void stopCalibration();
205  void reloadInternal();
206 
207  void destroyStateInternal(InputState* state);
208  void updateActiveStates();
209 
210  // From WindowEventListener
211  virtual void windowFocusChanged(bool bFocus) override;
212 
213  private: // variables
216  std::vector<InputDevice*> devices_;
218 
219  // some internally handled states and handlers
221  InputBuffer* calibratorCallbackHandler_;
223 
224  std::map<std::string, InputState*> statesByName_;
225  std::map<int, InputState*> activeStates_;
226  std::vector<InputState*> activeStatesTicked_;
227 
228  std::vector<std::function<void ()>> callBuffer_;
229 
231  }; // tolua_export
232 } // tolua_export
233 
234 #endif /* _InputManager_H__ */
static constexpr int Dynamic
Definition: InputPrereqs.h:457
State
Represents internal states of the InputManager.
Definition: InputManager.h:73
bool isMouseExclusive() const
Tells whether the mouse is used exclusively to the game.
Definition: InputManager.h:183
std::vector< InputDevice * > devices_
List of all input devices (keyboard, mouse, joy sticks)
Definition: InputManager.h:216
::std::string string
Definition: gtest-port.h:756
Interface for receiving window events like resize, moved and focusChanged.
Definition: WindowEventListener.h:43
State internalState_
Current internal state.
Definition: InputManager.h:214
void pushCall(const std::function< void()> &function)
Definition: InputManager.h:188
Declarations of all key/button/axis code enumeration and string literals and an input device enumerat...
Base for singleton classes.
Definition: Singleton.h:114
unsigned int getJoyStickQuantity() const
Returns the number of joy stick that have been created since the c&#39;tor or last call to reload()...
Definition: InputManager.h:176
Enumeration wrapper for input state priorities.
Definition: InputPrereqs.h:452
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Definition: InputPrereqs.h:447
#define _CoreExport
Definition: CorePrereqs.h:61
std::vector< InputState * > activeStatesTicked_
Like activeStates_, but only contains the ones that currently receive events.
Definition: InputManager.h:226
std::vector< std::function< void()> > callBuffer_
Caches all calls from InputStates to be executed afterwards (see preUpdate)
Definition: InputManager.h:228
A 3-state boolean type.
Definition: tribool.h:38
OIS::InputManager * getOISInputManager()
Returns a pointer to the OIS InputManager. Only you if you know what you&#39;re doing! ...
Definition: InputManager.h:179
std::map< int, InputState * > activeStates_
Contains all active input states by priority (std::map is sorted!)
Definition: InputManager.h:225
static InputManager & getInstance()
Definition: InputManager.h:191
InputStates allow you to customise the input event targets at runtime.
Definition: InputState.h:83
Definition of the Singleton template that is used as base class for classes that allow only one insta...
bool exclusiveMouse_
Currently applied mouse mode.
Definition: InputManager.h:217
Base Manager class.
Definition: OISInputManager.h:38
Simple real time clock based on Ogre::Timer.
Definition: Clock.h:57
OIS::InputManager * oisInputManager_
OIS input manager.
Definition: InputManager.h:215
Definition: InputBuffer.h:76
InputState * emptyState_
Lowest priority states (makes handling easier)
Definition: InputManager.h:220
std::map< std::string, InputState * > statesByName_
Contains all the created input states by name.
Definition: InputManager.h:224
static T & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
Manages the input devices (mouse, keyboard, joy sticks) and the input states.
Definition: InputManager.h:66
static InputManager * singletonPtr_s
Pointer reference to the singleton.
Definition: InputManager.h:230