Spinning Topp Logo BlackTopp Studios
inc
inputmanager.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _inputinputmanager_h
41 #define _inputinputmanager_h
42 
43 #include "entresolmanager.h"
44 #include "entresolmanagerfactory.h"
45 #include "singleton.h"
46 #include "Input/metacode.h"
47 #include "Input/sequencecontainer.h"
48 #include "Threading/workunit.h"
49 
50 namespace Mezzanine
51 {
52  namespace Input
53  {
54  class Timer;
55  class Controller;
56  class Keyboard;
57  class Mouse;
58  class InputManager;
59  class InputManagerInternalData;
60 
61  ///////////////////////////////////////////////////////////////////////////////
62  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of the physics debug drawer.
63  /// @details
64  ///////////////////////////////////////
66  {
67  protected:
68  /// @internal
69  /// @brief A pointer to the manager this work unit is processing.
71  /// @internal
72  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
73  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
75  /// @internal
76  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
77  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
78  DeviceUpdateWorkUnit& operator=(const DeviceUpdateWorkUnit& Other);
79  public:
80  /// @brief Class constructor.
81  /// @param Target The InputManager this work unit will process during the frame.
83  /// @brief Class destructor.
84  virtual ~DeviceUpdateWorkUnit();
85 
86  ///////////////////////////////////////////////////////////////////////////////
87  // Utility
88 
89  /// @brief This does any required update of the input devices detected on this system.
90  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
91  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
92  };//DeviceUpdateWorkUnit
93 
94  // Used by the scripting language binder to help create bindgings for this class. SWIG does know to creation template instances
95  #ifdef SWIG
96  %template(SingletonInputManager) Singleton<InputManager>;
97  #endif
98 
99  ///////////////////////////////////////////////////////////////////////////////
100  /// @class InputManager
101  /// @headerfile inputmanager.h
102  /// @brief This is the manager responsible for the handling of input devices and events.
103  /// @details Inputs can be checked one of two ways in the input system. Either you can get the class instance
104  /// for the device you want to query and use the query methods on it to check it's current state, or you can
105  /// access the inputs that were raised for the current frame by getting the container storing the Input Delta's. @n @n
106  /// Another feature of the input system is the ability to set custom input sequences that can be raised via MetaCode
107  /// for use elsewhere (such as the UI system). These sequences can be any number of MetaCode's of any type (that is
108  /// valid) in any order. Any sequence passed in must be terminated with a "Null" MetaCode. A "Null" MetaCode is a
109  /// MetaCode constructed using the default constructor, having it's Input code set to "KEY_UNKNOWN", it's meta value
110  /// to 0, and it's device index set to the max value of UInt16. If the sequence is not terminated an exception will
111  /// be thrown. @n @n
112  /// Input Sequences can be stored on the manager, or any input device, and their behavior is different based on where
113  /// it is inserted. Input Sequences stored on the manager will look at all of the most recent inputs from all devices
114  /// and use that to compare against the stored Input Sequences. If you have a single player game on the PC and want to
115  /// use an Input Sequence that combines input from both the mouse and keyboard, then the InputManager is the place to
116  /// store it. If however, you have a multiplayer fighter game (or split screen shooter) and want to track inputs from
117  /// each of two or more controllers individually, then you'll want to place the Input Sequences on the proper controller
118  /// device. @n @n
119  /// The InputManager can take any sequence, provided it is terminated. Input devices however can only take sequences with
120  /// MetaCode's that pertain to their own device, otherwise an exception will be thrown. At each place of storage Input
121  /// Sequences are forced to be unique(but they can exist on multiple devices). Input Sequence ID's however are not forced
122  /// to be unique at any point in the system. Furthermore when a MetaCode is generated after an Input Sequence occurs, it
123  /// is only given the ID the sequence, but not which sequence generated it. In the case of controllers they will be given
124  /// a device ID, but otherwise the origin will not be reported. This allows you to provide multiple ways to generating
125  /// the appropriate MetaCode(which could trigger something else in the UI system), but this also means great care must be
126  /// taken when deciding on the ID's for each Input Sequence.
127  ///////////////////////////////////////
129  {
130  public:
131  /// @brief Basic container type for game controller instances.
132  typedef std::vector< Controller* > ControllerContainer;
133  /// @brief Iterator type for game controller instances stored by this class.
134  typedef ControllerContainer::iterator ControllerIterator;
135  /// @brief Const Iterator type for game controller instances stored by this class.
136  typedef ControllerContainer::const_iterator ConstControllerIterator;
137 
138  /// @brief A String containing the name of this manager implementation.
140  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
142  protected:
143  friend class DeviceUpdateWorkUnit;
144 
145  /// @internal
146  /// @brief Container storing all the cross-device sequences this manager is to check for.
148  /// @internal
149  /// @brief Container storing all the MetaCodes generated for the current frame.
151 
152  /// @internal
153  /// @brief The pointer to the internal data handled by this manager.
155  /// @internal
156  /// @brief The pointer to the object representing the system mouse.
158  /// @internal
159  /// @brief The pointer to the object representing the system keyboard.
161 
162  /// @internal
163  /// @brief The work unit that updates the input devices with the newest data.
165  /// @internal
166  /// @brief Can be used for thread safe logging and other thread specific resources.
168  public:
169  /// @brief Class constructor.
170  InputManager();
171  /// @brief XML constructor.
172  /// @param XMLNode The node of the xml document to construct from.
173  InputManager(const XML::Node& XMLNode);
174  /// @brief Class destructor.
175  virtual ~InputManager();
176 
177  ///////////////////////////////////////////////////////////////////////////////
178  // InputDevice Management
179 
180  /// @brief Gets the system mouse.
181  /// @return Returns a pointer to the mouse device.
182  Mouse* GetSystemMouse() const;
183  /// @brief Gets the system keyboard.
184  /// @return Returns a pointer to the keyboard device.
185  Keyboard* GetSystemKeyboard() const;
186 
187  /// @brief Gets a controller by index.
188  /// @return Returns a pointer to the controller at the specified index.
189  Controller* GetController(const UInt16 Index) const;
190  /// @brief Gets the number of controllers detected.
191  /// @return Returns the number of controllers that have been detected on this system.
192  UInt16 GetNumControllers() const;
193 
194  ///////////////////////////////////////////////////////////////////////////////
195  // InputDevice Detection
196 
197  /// @brief Gathers all of the controllers that are connected to the system and creates corresponding devices for each one.
198  /// @return Returns the number of controllers that have been detected.
199  UInt16 DetectControllers();
200  /// @brief Releases all controller devices from this manager.
201  void ReleaseAllControllers();
202 
203  ///////////////////////////////////////////////////////////////////////////////
204  // Sequenced Input Management
205 
206  /// @copydoc SequenceContainer::AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID)
207  void AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID);
208  /// @copydoc SequenceContainer::InputSequenceExists(const MetaCodeContainer& Codes)
209  Boole InputSequenceExists(const MetaCodeContainer& Codes);
210  /// @copydoc SequenceContainer::GetIDofInputSequence(const MetaCodeContainer& Codes)
211  Int32 GetIDofInputSequence(const MetaCodeContainer& Codes);
212  /// @copydoc SequenceContainer::RemoveInputSequence(const MetaCodeContainer& Codes)
213  void RemoveInputSequence(const MetaCodeContainer& Codes);
214  /// @copydoc SequenceContainer::RemoveAllInputSequences()
215  void RemoveAllInputSequences();
216 
217  ///////////////////////////////////////////////////////////////////////////////
218  // Utility
219 
220  /// @brief Gets all the input codes that were generated this frame.
221  /// @return Returns a const reference to a vector containing all the inputs updated this frame.
222  const MetaCodeContainer& GetInputDeltas() const;
223 
224  /// @copydoc ManagerBase::Initialize()
225  virtual void Initialize();
226  /// @copydoc ManagerBase::Deinitialize()
227  virtual void Deinitialize();
228 
229  /// @brief Gets the work unit responsible for updating the input device classes.
230  /// @return Returns a pointer to the DeviceUpdateWorkUnit used by this manager.
231  DeviceUpdateWorkUnit* GetDeviceUpdateWork();
232 
233  ///////////////////////////////////////////////////////////////////////////////
234  // Type Identifier Methods
235 
236  /// @copydoc ManagerBase::GetInterfaceType()
237  virtual ManagerType GetInterfaceType() const;
238  /// @copydoc ManagerBase::GetImplementationTypeName()
239  virtual String GetImplementationTypeName() const;
240  };//InputManager
241 
242  ///////////////////////////////////////////////////////////////////////////////
243  /// @class DefaultInputManagerFactory
244  /// @headerfile inputmanager.h
245  /// @brief A factory responsible for the creation and destruction of the default inputmanager.
246  ///////////////////////////////////////
248  {
249  public:
250  /// @brief Class constructor.
252  /// @brief Class destructor.
253  virtual ~DefaultInputManagerFactory();
254 
255  /// @copydoc ManagerFactory::GetManagerImplName()
256  String GetManagerImplName() const;
257  /// @copydoc ManagerFactory::GetManagerType() const
258  ManagerBase::ManagerType GetManagerType() const;
259 
260  /// @copydoc EntresolManagerFactory::CreateManager(const NameValuePairList&)
261  EntresolManager* CreateManager(const NameValuePairList& Params);
262  /// @copydoc EntresolManagerFactory::CreateManager(const XML::Node&)
263  EntresolManager* CreateManager(const XML::Node& XMLNode);
264  /// @copydoc EntresolManagerFactory::DestroyManager(EntresolManager*)
265  void DestroyManager(EntresolManager* ToBeDestroyed);
266  };//DefaultInputManagerFactory
267  }//Input
268 }//Mezzanine
269 
270 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
This class represents a controller input device, such as a gamepad or joystick.
Definition: controller.h:54
This class represents the mouse input device.
Definition: mouse.h:60
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Default implementation of WorkUnit. This represents on piece of work through time.
Definition: workunit.h:160
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
Definition: inputmanager.h:141
ControllerContainer::iterator ControllerIterator
Iterator type for game controller instances stored by this class.
Definition: inputmanager.h:134
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread specific resources.
Definition: inputmanager.h:167
This class represents the keyboard input device. ////////////////////////////////////.
Definition: keyboard.h:55
InputManager * TargetManager
A pointer to the manager this work unit is processing.
Definition: inputmanager.h:70
This is a base class for factories that construct managers used by the Entresol class.
Keyboard * SystemKeyboard
The pointer to the object representing the system keyboard.
Definition: inputmanager.h:160
This class stores and provides utilities for sequenced inputs and their operations.
InputManagerInternalData * IMID
The pointer to the internal data handled by this manager.
Definition: inputmanager.h:154
ControllerContainer::const_iterator ConstControllerIterator
Const Iterator type for game controller instances stored by this class.
Definition: inputmanager.h:136
This is the manager responsible for the handling of input devices and events.
Definition: inputmanager.h:128
Mouse * SystemMouse
The pointer to the object representing the system mouse.
Definition: inputmanager.h:157
A thread specific collection of double-buffered and algorithm specific resources. ...
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
This is a Mezzanine::Threading::iWorkUnit for the updating of the physics debug drawer.
Definition: inputmanager.h:65
This is the base class for all managers that do no describe properties of a single world...
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
static const String ImplementationName
A String containing the name of this manager implementation.
Definition: inputmanager.h:139
This is an class for the handling of internal input data.
DeviceUpdateWorkUnit * DeviceUpdateWork
The work unit that updates the input devices with the newest data.
Definition: inputmanager.h:164
SequenceContainer Sequences
Container storing all the cross-device sequences this manager is to check for.
Definition: inputmanager.h:147
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
Input::MetaCode::MetaCodeContainer MetaCodeContainer
Convenience datatype for storage of MetaCodes.
Definition: metacode.h:351
MetaCodeContainer InputDeltas
Container storing all the MetaCodes generated for the current frame.
Definition: inputmanager.h:150
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
A factory responsible for the creation and destruction of the default inputmanager.
Definition: inputmanager.h:247
std::vector< Controller * > ControllerContainer
Basic container type for game controller instances.
Definition: inputmanager.h:132
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This file has the definition of the workunit.