|
VR-Engage
2.2
|
PATTERN: Custom Input Device Integration To integrate a non-standard input device with VR-Engage:
DtInputDevice Integration: Once registered with the input device factory (in plugin.cxx), this class is automatically instantiated and ticked by the input manager. The tick() method is called once per frame, providing the opportunity to process any input gathered since the last frame.
Input Mapping Configuration: After device input is transformed into DtInputData structures and passed to the input manager, VR-Engage's input mapping system (configured via XML files) matches the input to player actions. For example, "Virtual Gamepad button 0" can be mapped to "FireWeapon" action in the input mapping configuration.
REUSABLE: This class serves as a template for integrating any custom input device. Replace DtQmlGamepad with your device's API and adapt the event collection mechanism, but keep the overall structure: init() → register for device events tick() → process queued events → call myManager->processInput() shutdown() → unregister from device events
Device-Specific vs Generic Patterns:
#include <qmlGamepadInputDevice.h>
Public Member Functions | |
| DtQmlGamepadInputDevice () | |
| virtual | ~DtQmlGamepadInputDevice () |
| virtual bool | init (makVre::DtVreInputManager &mgr) override |
| virtual void | shutdown () override |
| virtual void | tick (double dt) override |
| void | reportCurrentState () |
| void | deviceEventCallback (std::string eventType, int eventId, double eventValue) |
Public Member Functions inherited from makVre::DtInputDevice | |
| DtInputDevice () | |
| virtual | ~DtInputDevice () |
| DtInputDevice (const DtInputDevice &mapping)=delete | |
| DtInputDevice & | operator= (const DtInputDevice &)=delete |
Protected Attributes | |
| std::list< makVre::DtInputData > | myEventQueue |
| makVre::DtQmlGampad | myVirtualGamepad |
Protected Attributes inherited from makVre::DtInputDevice | |
| DtVreInputManager * | myManager |
| DtQmlGamepadInputDevice::DtQmlGamepadInputDevice | ( | ) |
|
virtual |
|
overridevirtual |
Initialize input device and register for device events.
Called once on application startup after the input manager is initialized. Custom devices should:
PATTERN: Device Event Registration Custom input devices often use callbacks to receive asynchronous input rather than polling. Register callbacks during init() to start receiving device events. Events should be queued (not processed immediately) and processed during tick() to ensure frame-synchronous input handling.
| mgr | Reference to VR-Engage's input manager for event submission |
Implements makVre::DtInputDevice.
|
overridevirtual |
Clean up device resources and unregister event handlers.
Called once during application shutdown. Custom devices should:
Implements makVre::DtInputDevice.
|
overridevirtual |
Process queued input events and submit to input manager.
Called once per frame by the input manager. This is where queued device events are transformed into DtInputData structures and submitted for input mapping processing.
PATTERN: Event Queue Processing Custom input devices typically use a two-phase approach:
This ensures all input is processed at a consistent point in the frame rather than at random times when device events occur.
Frame Timing: The dt parameter provides time elapsed since last frame in seconds. Most input devices don't need this (events have their own timestamps), but it's useful for devices that require time-based accumulation or filtering (e.g., motion smoothing, button debouncing).
| dt | Time elapsed since previous frame in seconds |
Implements makVre::DtInputDevice.
|
inlinevirtual |
Report current device state (required by base class, not used)
Some input device implementations use this for state debugging or diagnostics. Not currently utilized by this example.
Implements makVre::DtInputDevice.
| void DtQmlGamepadInputDevice::deviceEventCallback | ( | std::string | eventType, |
| int | eventId, | ||
| double | eventValue ) |
Callback receiving events from the virtual gamepad device.
This callback function receives events from the example device (virtual gamepad UI). When a user interacts with the on-screen gamepad, the DtQmlGamepad invokes this callback with event details.
PATTERN: Device Event Callback Events are received asynchronously (triggered by user interaction with QML UI) but must be processed synchronously during tick(). This function creates a DtInputData structure for each event and pushes it into myEventQueue for processing in the next tick() call.
REUSABLE: For a different custom device, replace this callback with your device's event notification mechanism. The pattern remains the same: receive event → create DtInputData → queue for processing in tick().
| eventType | Device-specific event type string (e.g., "axis", "button") |
| eventId | Control identifier within that type (button 0, axis 1, etc.) |
| eventValue | Event value (button: 0.0/1.0, axis: -1.0 to +1.0) |
|
protected |
Event queue to gather device events between tick calls Events received via callbacks are queued here, then processed in tick()
|
protected |
The custom device instance (virtual on-screen gamepad in this example) For a real hardware device, this would be replaced with your device's API interface (serial port, USB, network connection, etc.)