VR-Engage  2.2
Loading...
Searching...
No Matches
driverControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file driverControlLogic.h
7//! \brief Defines the DtDriverControlLogic component for controlling ground vehicle operation.
8//!
9//! This component provides comprehensive vehicle control functionality including steering,
10//! throttle, braking, gear shifting, and auxiliary systems (headlights, differential lock, etc.)
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
17
19
21
22namespace makVre
23{
24//! \brief Forward declaration of the initialization table class
25class DtInitTable;
26
28{
29//! \ingroup RoleConfigParams
30//! \defgroup DriverControlLogicRoleParams Driver Control Logic Role Parameters
31//! \roleInherits{EntityControlLogicRoleParams}
32//! Configuration Options for driver role.
33//! @{
34
35//! \vreRoleParam{hasDifferentialLock,bool,false,driverControlLogic,Determines whether or not this role will have diff lock.}
36constexpr const char* hasDifferentialLock = "hasDifferentialLock";
37
38//! \vreRoleParam{canPivot,bool,false,driverControlLogic,Determines whether or not this role has the ability to pivot.}
39constexpr const char* canPivot = "canPivot";
40
41//! \vreRoleParam{hasTowHook,bool,false,driverControlLogic,Does this role have the ability for towing.}
42constexpr const char* hasTowHook = "hasTowHook";
43
44//! \vreRoleParam{showInclinometer,bool,false,driverControlLogic,Determines whether to show the inclinometer instrument displaying entity pitch and roll.}
45constexpr const char* showInclinometer = "showInclinometer";
46//! @}
47} // namespace DriverControlLogicConfig
48
49//! \brief Type identifier for DtDriverControlLogic component
50constexpr const char* DtDriverControlLogicType = "DtDriverControlLogic";
51
52//! \brief Component for controlling ground vehicle operation
53//!
54//! The DtDriverControlLogic provides functionality for controlling various aspects of ground
55//! vehicles. This includes basic driving controls (steering, throttle, braking), transmission
56//! controls (gear shifting), and auxiliary systems (engine, differential lock, parking brake,
57//! headlights, pivot steering, and towing hook).
58//!
59//! It also maintains vehicle state information through attributes and handles resource
60//! updates for systems like fuel levels and towing targets.
62{
63public:
64 //! \brief Constructor for DtDriverControlLogic
65 //!
66 //! Initializes the component with default values and checks out the required
67 //! VR Engage Ground license.
69
70 //! \brief Virtual destructor for DtDriverControlLogic
71 virtual ~DtDriverControlLogic() override;
72
73 //! \brief Initializes the component with configuration from Lua
74 //!
75 //! Sets up input handlers, initializes state attributes, and subscribes to resource updates.
76 //! Configures vehicle capabilities based on Lua settings (differential lock, pivot steering,
77 //! and tow hook availability).
78 //!
79 //! \param player Pointer to the player station this component belongs to
80 //! \param config Configuration table containing initialization parameters
81 //! \return True if initialization succeeds, false otherwise
83
84 //! \brief Updates the component state
85 //!
86 //! Updates the headlight state attribute based on the vehicle's current appearance.
87 //!
88 //! \param dt Delta time in seconds since the last tick
89 virtual void tick(double dt) override;
90
91 //! \brief Shuts down the component
92 //!
93 //! Unsubscribes from resource updates, removes callbacks, and cleans up input handlers.
94 virtual void shutdown() override;
95
96 //! \brief Returns the component type identifier
97 //! \return The component type string
98 virtual const char* type() const override;
99
100 //! \brief Input handler functions
101 //! @{
102
103 //! \brief Handles left steering input
104 //!
105 //! Inverts the value and passes it to setSteering().
106 //!
107 //! \param val The input value, typically from 0.0 to 1.0
108 virtual void steerLeft(float val);
109
110 //! \brief Handles right steering input
111 //!
112 //! Passes the value directly to setSteering().
113 //!
114 //! \param val The input value, typically from 0.0 to 1.0
115 virtual void steerRight(float val);
116
117 //! \brief Sets the vehicle's steering value
118 //!
119 //! Sends a "Steering" joystick message with the provided value.
120 //!
121 //! \param val The steering value, from -1.0 (full left) to 1.0 (full right)
122 virtual void setSteering(double val);
123
124 //! \brief Sets the vehicle's throttle value
125 //!
126 //! Sends a "Throttle" joystick message with the provided value.
127 //!
128 //! \param val The throttle value, typically from 0.0 to 1.0
129 virtual void setThrottle(double val);
130
131 //! \brief Sets the vehicle's brake value
132 //!
133 //! Sends a "Brake" joystick message with the provided value.
134 //!
135 //! \param val The brake value, typically from 0.0 to 1.0
136 virtual void setBrake(double val);
137
138 //! \brief Shifts up to the next gear
139 //!
140 //! Sends a "GearUp" joystick message with the provided value.
141 //!
142 //! \param val The input value, a value of 1.0 triggers the gear shift
143 virtual void setGearUp(double val);
144
145 //! \brief Shifts down to the previous gear
146 //!
147 //! Sends a "GearDown" joystick message with the provided value.
148 //!
149 //! \param val The input value, a value of 1.0 triggers the gear shift
150 virtual void setGearDown(double val);
151
152 //! \brief Toggles the engine on/off
153 //!
154 //! Sends an "EngineEnable" joystick message with the provided value.
155 //!
156 //! \param val The input value, a value of 1.0 typically toggles the engine state
157 virtual void setEngineEnable(double val);
158
159 //! \brief Toggles the differential lock
160 //!
161 //! Sends a "DifferentialLock" joystick message with the provided value.
162 //! Only applies to vehicles with differential lock capability.
163 //!
164 //! \param val The input value, a value of 1.0 typically toggles the differential lock
165 virtual void setDifferentialLock(double val);
166
167 //! \brief Toggles the parking brake
168 //!
169 //! Sends a "ParkingBrake" joystick message with the provided value.
170 //!
171 //! \param val The input value, a value of 1.0 typically toggles the parking brake
172 virtual void setParkingBrake(double val);
173
174 //! \brief Toggles the headlights
175 //!
176 //! Sends a "Headlights" joystick message with the provided value.
177 //!
178 //! \param val The input value, a value of 1.0 typically toggles the headlights
179 virtual void setHeadlights(double val);
180
181 //! \brief Controls pivot steering
182 //!
183 //! Sends a "Pivot" joystick message with the provided value.
184 //! Only applies to vehicles with pivot steering capability.
185 //!
186 //! \param val The input value
187 virtual void setPivot(double val);
188
189 //! \brief Controls the towing hook
190 //!
191 //! Sends a "Hook" joystick message with the provided value.
192 //! Only applies to vehicles with towing hook capability.
193 //!
194 //! \param val The input value, typically toggles hook engagement
195 virtual void setHook(double val);
196
197 //! @}
198
199 //! \brief Sends a joystick message to the simulation
200 //!
201 //! Helper function called by the various control functions to send
202 //! joystick messages with the appropriate parameters.
203 //!
204 //! \param function The function name to include in the message
205 //! \param val The function value to include in the message
206 //! \param delay Optional delay before sending the message (defaults to 0)
207 virtual void sendJoystickMessage(const std::string& function, double val, double delay = 0);
208
209protected:
210 //! \brief Handles resource update messages
211 //!
212 //! Processes resource updates, particularly for fuel levels.
213 //! Updates the "fuel" state attribute with the current amount.
214 //!
215 //! \param msg The resource update message to process
216 //! \return HANDLED if the message was processed
218
219 //! \brief Callback for changes to the hook target UUID
220 //!
221 //! When a nearby towing target is found, its entity ID (UUID) is published.
222 //! This callback updates the "hasHookTarget" and "hook-target-marking-text"
223 //! state attributes accordingly.
224 //!
225 //! \param hookTargetUuid The UUID of the potential hook target
226 virtual void onHookTargetUuidChanged(const std::string& hookTargetUuid);
227
228protected:
229 //! \brief Marking text for the current entity used in resource subscription
230 std::string myMarkingText;
231
232 //! \brief Input handler logic for processing input device events
234
235 //! \brief Main joystick function group name from configuration
236 //!
237 //! Used to identify the function group when sending joystick messages.
239
240 //! \brief Flag indicating if this vehicle is capable of pivot steering
241 //!
242 //! When true, enables pivot steering functionality. This value is stored in
243 //! the "canPivot" state attribute. Defaults to false.
245
246 //! \brief Flag indicating if this vehicle has a differential lock
247 //!
248 //! When true, enables differential lock functionality. This value is stored in
249 //! the "hasDifferentialLock" state attribute. Defaults to false.
251
252 //! \brief Flag indicating if this vehicle has a tow hook
253 //!
254 //! When true, enables towing hook functionality. This value is stored in
255 //! the "hasTowHook" state attribute. Defaults to false.
257
258 // Sets whether to show the inclinometer instrument. This shows the entity's pitch and roll.
260};
261
262} // namespace makVre
virtual void setSteering(double val)
Sets the vehicle's steering value.
virtual void setHook(double val)
Controls the towing hook.
bool myShowInclinometer
Definition driverControlLogic.h:259
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with configuration from Lua.
std::string myMainJoystickGroup
Main joystick function group name from configuration.
Definition driverControlLogic.h:238
bool myHasTowHook
Flag indicating if this vehicle has a tow hook.
Definition driverControlLogic.h:256
virtual makVre::DtVreMessageResult handleResourceUpdate(makVre::DtVreMessage *msg)
Handles resource update messages.
virtual void setHeadlights(double val)
Toggles the headlights.
bool myHasDifferentialLock
Flag indicating if this vehicle has a differential lock.
Definition driverControlLogic.h:250
virtual void setPivot(double val)
Controls pivot steering.
bool myCanPivot
Flag indicating if this vehicle is capable of pivot steering.
Definition driverControlLogic.h:244
virtual void steerLeft(float val)
Input handler functions.
virtual void setGearDown(double val)
Shifts down to the previous gear.
virtual void setEngineEnable(double val)
Toggles the engine on/off.
virtual void shutdown() override
Shuts down the component.
virtual void setParkingBrake(double val)
Toggles the parking brake.
virtual const char * type() const override
Returns the component type identifier.
DtDriverControlLogic()
Constructor for DtDriverControlLogic.
DtInputLogic myDriverInputLogic
Input handler logic for processing input device events.
Definition driverControlLogic.h:233
std::string myMarkingText
Marking text for the current entity used in resource subscription.
Definition driverControlLogic.h:230
virtual void setGearUp(double val)
Shifts up to the next gear.
virtual void setDifferentialLock(double val)
Toggles the differential lock.
virtual void sendJoystickMessage(const std::string &function, double val, double delay=0)
Sends a joystick message to the simulation.
virtual void onHookTargetUuidChanged(const std::string &hookTargetUuid)
Callback for changes to the hook target UUID.
virtual ~DtDriverControlLogic() override
Virtual destructor for DtDriverControlLogic.
virtual void setBrake(double val)
Sets the vehicle's brake value.
virtual void steerRight(float val)
Handles right steering input.
virtual void setThrottle(double val)
Sets the vehicle's throttle value.
virtual void tick(double dt) override
Updates the component state.
Component that provides entity control functionality.
Definition entityControlLogic.h:60
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:35
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines the logic for controlling entities in VR-Engage.
constexpr const char * canPivot
Definition driverControlLogic.h:39
constexpr const char * hasTowHook
Definition driverControlLogic.h:42
constexpr const char * hasDifferentialLock
Definition driverControlLogic.h:36
constexpr const char * showInclinometer
Definition driverControlLogic.h:45
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition driverControlLogic.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtDriverControlLogicType
Type identifier for DtDriverControlLogic component.
Definition driverControlLogic.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.