Manages all input devices and some other helpful stuff. More...
#include <GainputInputManager.h>
Classes | |
struct | DeviceInput |
Public Types | |
typedef HashMap< DeviceId, InputDevice * > | DeviceMap |
typedef DeviceMap::iterator | iterator |
Iterator over all registered devices. | |
typedef DeviceMap::const_iterator | const_iterator |
Const iterator over all registered devices. | |
Public Member Functions | |
InputManager (bool useSystemTime=true, Allocator &allocator=GetDefaultAllocator()) | |
Initializes the manager. More... | |
~InputManager () | |
Destructs the manager. | |
void | SetDisplaySize (int width, int height) |
Sets the window resolution. More... | |
void | HandleEvent (XEvent &event) |
[LINUX ONLY] Lets the InputManager handle the given X event. More... | |
void | HandleMessage (const MSG &msg) |
[WINDOWS ONLY] Lets the InputManager handle the given Windows message. More... | |
int32_t | HandleInput (AInputEvent *event) |
[ANDROID ONLY] Lets the InputManager handle the given input event. | |
void | HandleDeviceInput (DeviceInput const &input) |
void | Update () |
Updates the input state, call this every frame. More... | |
void | Update (uint64_t deltaTime) |
Updates the input state and the manager's time, call this every frame. More... | |
Allocator & | GetAllocator () const |
Returns the allocator to be used for memory allocations. | |
uint64_t | GetTime () const |
Returns a monotonic time in milliseconds. | |
template<class T > | |
DeviceId | CreateDevice (unsigned index=InputDevice::AutoIndex, InputDevice::DeviceVariant variant=InputDevice::DV_STANDARD) |
Creates an input device and registers it with the manager. More... | |
template<class T > | |
T * | CreateAndGetDevice (unsigned index=InputDevice::AutoIndex, InputDevice::DeviceVariant variant=InputDevice::DV_STANDARD) |
Creates an input device, registers it with the manager and returns it. More... | |
InputDevice * | GetDevice (DeviceId deviceId) |
Returns the input device with the given ID. More... | |
const InputDevice * | GetDevice (DeviceId deviceId) const |
Returns the input device with the given ID. More... | |
DeviceId | FindDeviceId (const char *typeName, unsigned index) const |
Returns the ID of the device with the given type and index. More... | |
DeviceId | FindDeviceId (InputDevice::DeviceType type, unsigned index) const |
Returns the ID of the device with the given type and index. More... | |
iterator | begin () |
Returns the begin iterator over all registered devices. | |
iterator | end () |
Returns the end iterator over all registered devices. | |
const_iterator | begin () const |
Returns the begin iterator over all registered devices. | |
const_iterator | end () const |
Returns the end iterator over all registered devices. | |
ListenerId | AddListener (InputListener *listener) |
Registers a listener to be notified when a button state changes. More... | |
void | RemoveListener (ListenerId listenerId) |
De-registers the given listener. | |
void | ReorderListeners () |
Sorts the list of listeners which controls the order in which listeners are called. More... | |
size_t | GetAnyButtonDown (DeviceButtonSpec *outButtons, size_t maxButtonCount) const |
Checks if any button on any device is down. More... | |
unsigned | GetDeviceCountByType (InputDevice::DeviceType type) const |
Returns the number of devices with the given type. | |
int | GetDisplayWidth () const |
Returns the graphical display's width in pixels. | |
int | GetDisplayHeight () const |
Returns the graphical display's height in pixels. | |
ModifierId | AddDeviceStateModifier (DeviceStateModifier *modifier) |
Registers a modifier that will be called after devices have been updated. | |
void | RemoveDeviceStateModifier (ModifierId modifierId) |
De-registers the given modifier. | |
void | EnqueueConcurrentChange (InputDevice &device, InputState &state, InputDeltaState *delta, DeviceButtonId buttonId, bool value) |
void | EnqueueConcurrentChange (InputDevice &device, InputState &state, InputDeltaState *delta, DeviceButtonId buttonId, float value) |
void | ConnectForStateSync (const char *ip, unsigned port) |
[IN dev BUILDS ONLY] Connect to a remote host to send device state changes to. | |
void | StartDeviceStateSync (DeviceId deviceId) |
[IN dev BUILDS ONLY] Initiate sending of device state changes to the given device. | |
void | SetDebugRenderingEnabled (bool enabled) |
Enable/disable debug rendering of input devices. | |
bool | IsDebugRenderingEnabled () const |
Returns true if debug rendering is enabled, false otherwise. | |
void | SetDebugRenderer (DebugRenderer *debugRenderer) |
Sets the debug renderer to be used if debug rendering is enabled. | |
DebugRenderer * | GetDebugRenderer () const |
Returns the previously set debug renderer. | |
Manages all input devices and some other helpful stuff.
This manager takes care of all device-related things. Normally, you should only need one that contains all your input devices.
After instantiating an InputManager, you have to call SetDisplaySize(). You should also create some input devices using the template function CreateDevice() which returns the device ID that is needed to do anything further with the device (for example, see InputMap).
The manager has to be updated every frame by calling Update(). Depending on the platform, you may have to call another function as part of your message handling code (see HandleMessage(), HandleInput()).
Note that destruction of an InputManager invalidates all input maps based on it and all devices created through it.
gainput::InputManager::InputManager | ( | bool | useSystemTime = true , |
Allocator & | allocator = GetDefaultAllocator() |
||
) |
Initializes the manager.
Further initialization is typically necessary.
useSystemTime | Specifies if the GetTime() function uses system time or the time supplied to Update(uint64_t). |
allocator | The memory allocator to be used for all allocations. |
ListenerId gainput::InputManager::AddListener | ( | InputListener * | listener | ) |
Registers a listener to be notified when a button state changes.
If there are listeners registered, all input devices will have to record their state changes. This incurs extra runtime costs.
|
inline |
Creates an input device, registers it with the manager and returns it.
T | The input device class, muste be derived from InputDevice. |
variant | Requests the specified device variant. Note that this is only a request. Another implementation variant of the device may silently be instantiated instead. To determine what variant was instantiated, call InputDevice::GetVariant(). |
|
inline |
Creates an input device and registers it with the manager.
T | The input device class, muste be derived from InputDevice. |
variant | Requests the specified device variant. Note that this is only a request. Another implementation variant of the device may silently be instantiated instead. To determine what variant was instantiated, call InputDevice::GetVariant(). |
DeviceId gainput::InputManager::FindDeviceId | ( | const char * | typeName, |
unsigned | index | ||
) | const |
Returns the ID of the device with the given type and index.
typeName | The name of the device type. Should come from InputDevice::GetTypeName(). |
index | The index of the device. Should come from InputDevice::GetIndex(). |
DeviceId gainput::InputManager::FindDeviceId | ( | InputDevice::DeviceType | type, |
unsigned | index | ||
) | const |
Returns the ID of the device with the given type and index.
type | The device type. Should come from InputDevice::GetType(). |
index | The index of the device. Should come from InputDevice::GetIndex(). |
size_t gainput::InputManager::GetAnyButtonDown | ( | DeviceButtonSpec * | outButtons, |
size_t | maxButtonCount | ||
) | const |
Checks if any button on any device is down.
[out] | outButtons | An array with maxButtonCount fields to receive the device buttons that are down. |
maxButtonCount | The number of fields in outButtons. |
|
inline |
Returns the input device with the given ID.
|
inline |
Returns the input device with the given ID.
void gainput::InputManager::HandleEvent | ( | XEvent & | event | ) |
[LINUX ONLY] Lets the InputManager handle the given X event.
Call this function for event types MotionNotify, ButtonPress, ButtonRelease, KeyPress, KeyRelease.
void gainput::InputManager::HandleMessage | ( | const MSG & | msg | ) |
[WINDOWS ONLY] Lets the InputManager handle the given Windows message.
Call this function for message types WM_CHAR, WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_?BUTTON*, WM_MOUSEMOVE, WM_MOUSEWHEEL.
void gainput::InputManager::ReorderListeners | ( | ) |
Sorts the list of listeners which controls the order in which listeners are called.
The order of listeners may be important as the functions being called to notify a listener of a state change can control if the state change will be passed to any consequent listeners. Call this function whenever listener priorites have changed. It is automatically called by AddListener() and RemoveListener().
|
inline |
Sets the window resolution.
Informs the InputManager and its devices of the size of the window that is used for receiving inputs. For example, the size is used to to normalize mouse inputs.
void gainput::InputManager::Update | ( | ) |
Updates the input state, call this every frame.
If the InputManager was initialized with useSystemTime
set to false
, you have to call Update(uint64_t) instead.
void gainput::InputManager::Update | ( | uint64_t | deltaTime | ) |
Updates the input state and the manager's time, call this every frame.
Updates the time returned by GetTime() and then calls the regular Update(). This function should only be called if the InputManager was initialized with useSystemTime
set to false
.
deltaTime | The provided must be in milliseconds. |