MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inputmanager.h
1 // © Copyright 2010 - 2014 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 "managerbase.h"
44 #include "managerfactory.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  typedef std::vector< Controller* > ControllerContainer;
132  typedef ControllerContainer::iterator ControllerIterator;
133  typedef ControllerContainer::const_iterator ConstControllerIterator;
134  protected:
135  friend class DeviceUpdateWorkUnit;
136 
137  /// @internal
138  /// @brief Container storing all the cross-device sequences this manager is to check for.
140  /// @internal
141  /// @brief Container storing all the MetaCodes generated for the current frame.
142  MetaCodeContainer InputDeltas;
143 
144  /// @internal
145  /// @brief The pointer to the internal data handled by this manager.
147  /// @internal
148  /// @brief The pointer to the object representing the system mouse.
150  /// @internal
151  /// @brief The pointer to the object representing the system keyboard.
153 
154  /// @internal
155  /// @brief The work unit that updates the input devices with the newest data.
157  /// @internal
158  /// @brief Can be used for thread safe logging and other thread specific resources.
160  public:
161  /// @brief Class constructor.
162  InputManager();
163  /// @brief XML constructor.
164  /// @param XMLNode The node of the xml document to construct from.
165  InputManager(XML::Node& XMLNode);
166  /// @brief Class destructor.
167  virtual ~InputManager();
168 
169  ///////////////////////////////////////////////////////////////////////////////
170  // InputDevice Management
171 
172  /// @brief Gets the system mouse.
173  /// @return Returns a pointer to the mouse device.
174  Mouse* GetSystemMouse() const;
175  /// @brief Gets the system keyboard.
176  /// @return Returns a pointer to the keyboard device.
177  Keyboard* GetSystemKeyboard() const;
178 
179  /// @brief Gets a controller by index.
180  /// @return Returns a pointer to the controller at the specified index.
181  Controller* GetController(const UInt16 Index) const;
182  /// @brief Gets the number of controllers detected.
183  /// @return Returns the number of controllers that have been detected on this system.
184  UInt16 GetNumControllers() const;
185 
186  ///////////////////////////////////////////////////////////////////////////////
187  // InputDevice Detection
188 
189  /// @brief Gathers all of the controllers that are connected to the system and creates corresponding devices for each one.
190  /// @return Returns the number of controllers that have been detected.
191  UInt16 DetectControllers();
192  /// @brief Releases all controller devices from this manager.
193  void ReleaseAllControllers();
194 
195  ///////////////////////////////////////////////////////////////////////////////
196  // Sequenced Input Management
197 
198  /// @copydoc SequenceContainer::AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID)
199  void AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID);
200  /// @copydoc SequenceContainer::InputSequenceExists(const MetaCodeContainer& Codes)
201  bool InputSequenceExists(const MetaCodeContainer& Codes);
202  /// @copydoc SequenceContainer::GetIDofInputSequence(const MetaCodeContainer& Codes)
203  Int32 GetIDofInputSequence(const MetaCodeContainer& Codes);
204  /// @copydoc SequenceContainer::RemoveInputSequence(const MetaCodeContainer& Codes)
205  void RemoveInputSequence(const MetaCodeContainer& Codes);
206  /// @copydoc SequenceContainer::RemoveAllInputSequences()
207  void RemoveAllInputSequences();
208 
209  ///////////////////////////////////////////////////////////////////////////////
210  // Utility
211 
212  /// @brief Gets all the input codes that were generated this frame.
213  /// @return Returns a const reference to a vector containing all the inputs updated this frame.
214  const MetaCodeContainer& GetInputDeltas() const;
215 
216  /// @copydoc ManagerBase::Initialize()
217  virtual void Initialize();
218  /// @copydoc ManagerBase::Deinitialize()
219  virtual void Deinitialize();
220 
221  /// @brief Gets the work unit responsible for updating the input device classes.
222  /// @return Returns a pointer to the DeviceUpdateWorkUnit used by this manager.
223  DeviceUpdateWorkUnit* GetDeviceUpdateWork();
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Type Identifier Methods
227 
228  /// @copydoc ManagerBase::GetInterfaceType()
229  virtual ManagerType GetInterfaceType() const;
230  /// @copydoc ManagerBase::GetImplementationTypeName()
231  virtual String GetImplementationTypeName() const;
232  };//InputManager
233 
234  ///////////////////////////////////////////////////////////////////////////////
235  /// @class DefaultInputManagerFactory
236  /// @headerfile inputmanager.h
237  /// @brief A factory responsible for the creation and destruction of the default inputmanager.
238  ///////////////////////////////////////
240  {
241  public:
242  /// @brief Class constructor.
244  /// @brief Class destructor.
245  virtual ~DefaultInputManagerFactory();
246 
247  /// @copydoc ManagerFactory::GetManagerTypeName()
248  String GetManagerTypeName() const;
249 
250  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
251  ManagerBase* CreateManager(NameValuePairList& Params);
252  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
253  ManagerBase* CreateManager(XML::Node& XMLNode);
254  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
255  void DestroyManager(ManagerBase* ToBeDestroyed);
256  };//DefaultInputManagerFactory
257  }//Input
258 }//Mezzanine
259 
260 #endif