VR-Engage
2.2
Loading...
Searching...
No Matches
qmlGamepadInputDevice.h
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright (c) 2025 MAK Technologies, Inc.
3
** All rights reserved.
4
******************************************************************************/
5
//! \file qmlGamepadInputDevice.h
6
//! \brief Custom input device integration example for VR-Engage input system
7
//!
8
//! DtQmlGamepadInputDevice demonstrates the complete pattern for integrating a
9
//! non-standard input device (not using HID protocols) with VR-Engage's input
10
//! mapping system. This example uses a QML-based virtual gamepad as the device,
11
//! but the pattern applies to any custom input source: serial devices, network
12
//! protocols, motion capture systems, or proprietary hardware.
13
//!
14
//! Key Patterns Demonstrated:
15
//! - Deriving from DtInputDevice for custom input sources
16
//! - Event collection and queuing between device and framework
17
//! - Transformation of device-specific data into DtInputData structures
18
//! - Integration with VR-Engage's input mapping configuration system
19
//! - Device lifecycle management (init, tick, shutdown)
20
21
#pragma once
22
23
#include "
export.h
"
24
25
#include "
vreInput/inputDevice.h
"
26
#include "
vreInput/inputData.h
"
27
28
#include "
qmlGamepad.h
"
29
30
#include <list>
31
32
//! \brief Custom input device adapter for VR-Engage's input mapping system
33
//!
34
//! PATTERN: Custom Input Device Integration
35
//! To integrate a non-standard input device with VR-Engage:
36
//!
37
//! 1. Derive from DtInputDevice base class
38
//! 2. Implement init(), tick(), and shutdown() lifecycle methods
39
//! 3. Gather device input asynchronously (callbacks, polling, events)
40
//! 4. Queue input events as DtInputData structures
41
//! 5. During tick(), pass queued events to DtVreInputManager::processInput()
42
//!
43
//! DtInputDevice Integration:
44
//! Once registered with the input device factory (in plugin.cxx), this class
45
//! is automatically instantiated and ticked by the input manager. The tick()
46
//! method is called once per frame, providing the opportunity to process any
47
//! input gathered since the last frame.
48
//!
49
//! Input Mapping Configuration:
50
//! After device input is transformed into DtInputData structures and passed to
51
//! the input manager, VR-Engage's input mapping system (configured via XML files)
52
//! matches the input to player actions. For example, "Virtual Gamepad button 0"
53
//! can be mapped to "FireWeapon" action in the input mapping configuration.
54
//!
55
//! REUSABLE: This class serves as a template for integrating any custom input
56
//! device. Replace DtQmlGamepad with your device's API and adapt the event
57
//! collection mechanism, but keep the overall structure:
58
//! init() → register for device events
59
//! tick() → process queued events → call myManager->processInput()
60
//! shutdown() → unregister from device events
61
//!
62
//! Device-Specific vs Generic Patterns:
63
//! - Device-specific: myVirtualGamepad and its event callback (lines 60-65)
64
//! - Generic/reusable: DtInputDevice lifecycle, event queue, DtInputData creation
65
//!
66
class
INPUTDEVICE_DLL
DtQmlGamepadInputDevice
:
public
makVre::DtInputDevice
67
{
68
public
:
69
DtQmlGamepadInputDevice
();
70
virtual
~DtQmlGamepadInputDevice
();
71
72
// Inherited framework functions:
73
// ------------------------------
74
75
//! \brief Initialize input device and register for device events
76
//!
77
//! Called once on application startup after the input manager is initialized.
78
//! Custom devices should:
79
//! 1. Store the input manager pointer for later use
80
//! 2. Initialize device-specific hardware/connections
81
//! 3. Register callbacks/handlers to receive device events
82
//!
83
//! PATTERN: Device Event Registration
84
//! Custom input devices often use callbacks to receive asynchronous input
85
//! rather than polling. Register callbacks during init() to start receiving
86
//! device events. Events should be queued (not processed immediately) and
87
//! processed during tick() to ensure frame-synchronous input handling.
88
//!
89
//! \param mgr Reference to VR-Engage's input manager for event submission
90
//! \return true if initialization succeeded, false on failure
91
//!
92
virtual
bool
init
(
makVre::DtVreInputManager
& mgr)
override
;
93
94
//! \brief Clean up device resources and unregister event handlers
95
//!
96
//! Called once during application shutdown. Custom devices should:
97
//! 1. Unregister all event callbacks to prevent callbacks to destroyed objects
98
//! 2. Close device connections/hardware
99
//! 3. Free device-specific resources
100
//!
101
virtual
void
shutdown
()
override
;
102
103
//! \brief Process queued input events and submit to input manager
104
//!
105
//! Called once per frame by the input manager. This is where queued device
106
//! events are transformed into DtInputData structures and submitted for
107
//! input mapping processing.
108
//!
109
//! PATTERN: Event Queue Processing
110
//! Custom input devices typically use a two-phase approach:
111
//! 1. Asynchronously collect input events (callbacks/polling) and queue them
112
//! 2. During tick(), iterate through queue and call myManager->processInput()
113
//!
114
//! This ensures all input is processed at a consistent point in the frame
115
//! rather than at random times when device events occur.
116
//!
117
//! Frame Timing:
118
//! The dt parameter provides time elapsed since last frame in seconds.
119
//! Most input devices don't need this (events have their own timestamps),
120
//! but it's useful for devices that require time-based accumulation or
121
//! filtering (e.g., motion smoothing, button debouncing).
122
//!
123
//! \param dt Time elapsed since previous frame in seconds
124
//!
125
virtual
void
tick
(
double
dt)
override
;
126
127
//! \brief Report current device state (required by base class, not used)
128
//!
129
//! Some input device implementations use this for state debugging or
130
//! diagnostics. Not currently utilized by this example.
131
//!
132
void
reportCurrentState
() {};
133
134
// Custom device interface:
135
// ------------------------
136
137
//! \brief Callback receiving events from the virtual gamepad device
138
//!
139
//! This callback function receives events from the example device (virtual
140
//! gamepad UI). When a user interacts with the on-screen gamepad, the
141
//! DtQmlGamepad invokes this callback with event details.
142
//!
143
//! PATTERN: Device Event Callback
144
//! Events are received asynchronously (triggered by user interaction with QML UI)
145
//! but must be processed synchronously during tick(). This function creates a
146
//! DtInputData structure for each event and pushes it into myEventQueue for
147
//! processing in the next tick() call.
148
//!
149
//! REUSABLE: For a different custom device, replace this callback with your
150
//! device's event notification mechanism. The pattern remains the same:
151
//! receive event → create DtInputData → queue for processing in tick().
152
//!
153
//! \param eventType Device-specific event type string (e.g., "axis", "button")
154
//! \param eventId Control identifier within that type (button 0, axis 1, etc.)
155
//! \param eventValue Event value (button: 0.0/1.0, axis: -1.0 to +1.0)
156
//!
157
void
deviceEventCallback
(std::string eventType,
int
eventId,
double
eventValue);
158
159
protected
:
160
//! Event queue to gather device events between tick calls
161
//! Events received via callbacks are queued here, then processed in tick()
162
std::list<makVre::DtInputData>
myEventQueue
;
163
164
//! The custom device instance (virtual on-screen gamepad in this example)
165
//! For a real hardware device, this would be replaced with your device's
166
//! API interface (serial port, USB, network connection, etc.)
167
makVre::DtQmlGampad
myVirtualGamepad
;
168
};
DtQmlGamepadInputDevice::shutdown
virtual void shutdown() override
Clean up device resources and unregister event handlers.
DtQmlGamepadInputDevice::myEventQueue
std::list< makVre::DtInputData > myEventQueue
Event queue to gather device events between tick calls Events received via callbacks are queued here,...
Definition
qmlGamepadInputDevice.h:162
DtQmlGamepadInputDevice::init
virtual bool init(makVre::DtVreInputManager &mgr) override
Initialize input device and register for device events.
DtQmlGamepadInputDevice::~DtQmlGamepadInputDevice
virtual ~DtQmlGamepadInputDevice()
DtQmlGamepadInputDevice::deviceEventCallback
void deviceEventCallback(std::string eventType, int eventId, double eventValue)
Callback receiving events from the virtual gamepad device.
DtQmlGamepadInputDevice::tick
virtual void tick(double dt) override
Process queued input events and submit to input manager.
DtQmlGamepadInputDevice::myVirtualGamepad
makVre::DtQmlGampad myVirtualGamepad
The custom device instance (virtual on-screen gamepad in this example) For a real hardware device,...
Definition
qmlGamepadInputDevice.h:167
DtQmlGamepadInputDevice::DtQmlGamepadInputDevice
DtQmlGamepadInputDevice()
DtQmlGamepadInputDevice::reportCurrentState
void reportCurrentState()
Report current device state (required by base class, not used)
Definition
qmlGamepadInputDevice.h:132
makVre::DtInputDevice
Abstract base class for hardware input device implementations.
Definition
inputDevice.h:25
makVre::DtQmlGampad
QML-based virtual gamepad UI that bridges QML events to C++ input callbacks.
Definition
qmlGamepad.h:53
makVre::DtVreInputManager
Central manager for input device handling, action mapping, and input processing.
Definition
vreInputManager.h:81
export.h
INPUTDEVICE_DLL
#define INPUTDEVICE_DLL
Definition
export.h:15
inputData.h
Defines data structures and enumerations for input device data.
inputDevice.h
Abstract base class for input device implementations.
qmlGamepad.h
QML-based virtual gamepad UI component for custom input device example.
Generated on 2026-01-13 from SVN revision 282860 - Copyright © 2005-2026 MAK Technologies. All Rights Reserved.