VR-Engage  2.2
Loading...
Searching...
No Matches
deviceMapping.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
6//! \file
7//! \brief Defines mapping between device inputs and actions
8
9#pragma once
10
11#include "vreInput/export.h"
12
13#include <unordered_map>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace makVre
19{
20//! Forward declarations
23class DtInitTable;
24struct DtInputData;
25
26//! \brief Maps device inputs to actions through evaluators
27//!
28//! This class manages the mapping between raw device inputs and logical actions
29//! using evaluators. It maintains the current state of device inputs and processes
30//! incoming input events, forwarding them to the appropriate evaluators.
32{
33public:
34 //! \brief Type for storing the current state of device inputs
35 //!
36 //! Maps input IDs to their current values
37 using DeviceState = std::unordered_map<int, float>;
38
39 //! \brief Constructor that initializes the device mapping
40 //!
41 //! Creates a new device mapping with the given input manager and configuration.
42 //! The configuration defines which evaluators to create and how to map inputs.
43 //!
44 //! \param mgr Reference to the input manager that owns this mapping
45 //! \param group The input group name for organizing related input mappings
46 //! \param config Pointer to the configuration data for this mapping
47 DtDeviceMapping(DtVreInputManager& mgr, const std::string& group, DtInitTable* config);
48 //! \brief Virtual destructor
49 //!
50 //! Cleans up resources owned by this mapping
52
53 //! \brief Copy constructor (deleted)
54 //!
55 //! Device mappings cannot be copied due to unique ownership of evaluators
56 DtDeviceMapping(const DtDeviceMapping& mapping) = delete;
57
58 //! \brief Assignment operator (deleted)
59 //!
60 //! Device mappings cannot be assigned due to unique ownership of evaluators
62
63 //! \brief Initialize the mapper and all evaluators
64 //!
65 //! Resets the device state and initializes all evaluators. Called during construction
66 //! and can be called again to reset the mapping to its initial state.
67 virtual void initialize();
68
69 //! \brief Process an input event from a device
70 //!
71 //! Updates the device state with the new input value and passes the input
72 //! to any evaluators registered for that input ID. If any evaluator handles
73 //! the input, processing stops.
74 //!
75 //! \param data The input data structure containing the event information
76 //! \return True if this mapping handled the input and processing should stop, false otherwise
77 virtual bool processInput(const DtInputData& data);
78
79 //! \brief Update method called each frame
80 //!
81 //! Updates all evaluators, allowing them to check for time-based triggers
82 //! and other conditions based on the current device state.
83 //!
84 //! \param dt Delta time in seconds since the last frame
85 virtual void tick(double dt);
86
87 //! \brief Get the current state of all device inputs
88 //!
89 //! Returns a map of input IDs to their current values, representing
90 //! the current state of the device's inputs.
91 //!
92 //! \return Constant reference to the device state map
93 virtual const DeviceState& deviceState() const;
94
95 //! \brief Structure for representing a single input mapping
96 //!
97 //! Contains information about how a specific input maps to an action
99 {
100 //! \brief Type of input (button, axis, key, etc.)
102
103 //! \brief Input ID (button number, axis number, key code, etc.)
105
106 //! \brief Input flags (hat position, axis direction, etc.)
108
109 //! \brief Input modifiers (alt, ctrl, shift for keys)
111
112 //! \brief Name of the action this input triggers
113 std::string actionName;
114
115 //! \brief Human-readable description of the input
116 std::string inputDescription;
117 };
118
119 //! \brief Get all input mappings configured for this device
120 //!
121 //! Returns a list of all input mappings that have been configured
122 //! for this device, including the input details and associated actions.
123 //!
124 //! \return Vector of InputMapping structures describing all configured mappings
125 virtual std::vector<InputMapping> getInputMappings() const;
126
127 virtual std::string getGroup() const { return myGroup; }
128
129 using EvaluatorMap = std::unordered_map<int, std::vector<std::unique_ptr<DtInputEvaluator>>>;
130
131protected:
132 //! \brief Clear the current device input state
133 //!
134 //! Virtual method that can be overridden by derived classes to provide
135 //! custom state clearing behavior.
136 virtual void clearInputState() {};
137
138 //! \brief Current state of all device inputs (input ID -> value)
140
141 //! \brief Map of input IDs to their associated evaluators
142 //!
143 //! Each input ID can have multiple evaluators that process its values
145
146 std::string myGroup;
147
148 //! \brief Reference to the input manager that owns this mapping
150
151private:
152 //! \brief Helper method to create human-readable input descriptions
153 std::string createInputDescription(int inputType, int inputId, int inputFlags, int inputModifiers) const;
154
155 //! \brief Helper method to convert input ID to key name
156 std::string inputIdToKeyName(int keyId) const;
157
158 //! \brief Helper method to convert hat flags to string
159 std::string hatFlagsToString(int hatFlags) const;
160
161 //! \brief Helper method to convert axis flags to string
162 std::string axisFlagsToString(int axisFlags) const;
163};
164
165} // namespace makVre
virtual std::vector< InputMapping > getInputMappings() const
Get all input mappings configured for this device.
DtDeviceMapping(DtVreInputManager &mgr, const std::string &group, DtInitTable *config)
Constructor that initializes the device mapping.
DtDeviceMapping & operator=(const DtDeviceMapping &)=delete
Assignment operator (deleted)
DtDeviceMapping(const DtDeviceMapping &mapping)=delete
Copy constructor (deleted)
std::unordered_map< int, float > DeviceState
Type for storing the current state of device inputs.
Definition deviceMapping.h:37
DeviceState myDeviceState
Current state of all device inputs (input ID -> value)
Definition deviceMapping.h:139
virtual void clearInputState()
Clear the current device input state.
Definition deviceMapping.h:136
virtual void initialize()
Initialize the mapper and all evaluators.
virtual ~DtDeviceMapping()
Virtual destructor.
virtual bool processInput(const DtInputData &data)
Process an input event from a device.
std::unordered_map< int, std::vector< std::unique_ptr< DtInputEvaluator > > > EvaluatorMap
Definition deviceMapping.h:129
virtual void tick(double dt)
Update method called each frame.
virtual const DeviceState & deviceState() const
Get the current state of all device inputs.
std::string myGroup
Definition deviceMapping.h:146
virtual std::string getGroup() const
Definition deviceMapping.h:127
EvaluatorMap myEvaluators
Map of input IDs to their associated evaluators.
Definition deviceMapping.h:144
std::string axisFlagsToString(int axisFlags) const
Helper method to convert axis flags to string.
DtVreInputManager & myManager
Reference to the input manager that owns this mapping.
Definition deviceMapping.h:149
std::string inputIdToKeyName(int keyId) const
Helper method to convert input ID to key name.
std::string hatFlagsToString(int hatFlags) const
Helper method to convert hat flags to string.
std::string createInputDescription(int inputType, int inputId, int inputFlags, int inputModifiers) const
Helper method to create human-readable input descriptions.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Evaluates input data and converts it to actions.
Definition inputEvaluator.h:32
Central manager for input device handling, action mapping, and input processing.
Definition vreInputManager.h:81
Defines DLL export/import macros for the vreInput library.
#define VREINPUT_DLL
DLL export/import macro for the vreInput library.
Definition export.h:25
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Structure for representing a single input mapping.
Definition deviceMapping.h:99
int inputId
Input ID (button number, axis number, key code, etc.)
Definition deviceMapping.h:104
int inputType
Type of input (button, axis, key, etc.)
Definition deviceMapping.h:101
std::string actionName
Name of the action this input triggers.
Definition deviceMapping.h:113
int inputModifiers
Input modifiers (alt, ctrl, shift for keys)
Definition deviceMapping.h:110
std::string inputDescription
Human-readable description of the input.
Definition deviceMapping.h:116
int inputFlags
Input flags (hat position, axis direction, etc.)
Definition deviceMapping.h:107
Structure for transferring input data through the input system.
Definition inputData.h:89