VR-Engage  2.3
Loading...
Searching...
No Matches
towingControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file towingControlLogic.h
7//! \brief Defines the DtTowingControlLogic component for towing-related frontend control.
8//!
9//! \ingroup vreCommonComponents
10
11#pragma once
12
14
17
18#include <map>
19#include <string>
20
21#include <vlpi/simulationAddress.h>
22#include <vrfutil/uuid.h>
23
24namespace makVre
25{
26//! \brief Forward declaration of the initialization table class
27class DtInitTable;
28
30{
31//! \ingroup RoleConfigParams
32//! \defgroup TowingControlLogicRoleParams Towing Control Logic Role Parameters
33//! \roleInherits{EntityControlLogicRoleParams}
34//! Configuration options for towing role behavior.
35//! @{
36
37//! \vreRoleParam{hasTowHook,bool,false,towingControlLogic,Does this role have the ability for towing.}
38constexpr auto hasTowHook = "hasTowHook";
39
40//! \vreRoleParam{ownershipAcquireDelaySeconds,double,0.5,towingControlLogic,Delay in seconds before sending the tow-target ownership acquire request so the transfer marker can propagate.}
41constexpr auto ownershipAcquireDelaySeconds = "ownershipAcquireDelaySeconds";
42
43//! \vreRoleParam{ownershipReleaseDelaySeconds,double,1.0,towingControlLogic,Delay in seconds after the towed target leaves sensor range before releasing ownership back.}
44constexpr auto ownershipReleaseDelaySeconds = "ownershipReleaseDelaySeconds";
45
46//! \vreRoleParam{hookHandoffTimeoutSeconds,double,10.0,towingControlLogic,Timeout in seconds to wait for the tow hook to engage after an ownership transfer succeeds.}
47constexpr auto hookHandoffTimeoutSeconds = "hookHandoffTimeoutSeconds";
48//! @}
49} // namespace TowingControlLogicConfig
50
51//! \brief Type identifier for DtTowingControlLogic component
52constexpr auto DtTowingControlLogicType = "DtTowingControlLogic";
53
54//! \brief Component that owns towing-specific input and shared player state
55//!
56//! The DtTowingControlLogic provides towing-related frontend behavior including
57//! hook input handling, tow-target state attributes, and tow-hook sensor contact
58//! subscriptions.
60{
61 using TowSensorContactsMap = std::map<DtUUID, DtEntityType>;
62 using TowCandidateSimEngineAttrMap = std::map<DtUUID, DtAttributeHandleType<DtSimulationAddress>>;
63
64public:
65 //! \brief Constructor for DtTowingControlLogic
67
68 //! \brief Virtual destructor for DtTowingControlLogic
69 virtual ~DtTowingControlLogic() override;
70
71 //! \brief Initializes the towing control logic from Lua configuration
72 //! \param player Pointer to the player station this component belongs to
73 //! \param config Configuration table containing initialization parameters
74 //! \return True if initialization succeeds, false otherwise
75 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
76
77 //! \brief Shuts down the component and removes towing callbacks and input handlers
78 virtual void shutdown() override;
79
80 //! \brief Returns the component type identifier
81 //! \return The component type string
82 virtual const char* type() const override;
83
84 //! \brief Updates pending tow-transfer handoff state.
85 //! \param dt Time in seconds since the previous update
86 virtual void tick(double dt) override;
87
88 //! \brief Controls the towing hook
89 //! \param val The input value, typically toggling hook engagement
90 virtual void setHook(double val);
91
92 //! \brief Sends a joystick message to the simulation
93 //! \param function The function name to include in the message
94 //! \param val The function value to include in the message
95 //! \param delay Optional delay before sending the message
96 virtual void sendJoystickMessage(const std::string& function, double val, double delay = 0);
97
98 //! \brief Handles towing-related action-menu messages
99 //! \param msg The message to process
100 //! \return HANDLED if the towing menu action was processed, IGNORED otherwise
102
103 //! \brief Handles ownership-transfer responses for tow-candidate acquires.
104 //! \param msg The response message to process
105 //! \return HANDLED if the response was for the pending towing request
107
108protected:
109 //! \brief Callback for changes to the hook target UUID
110 //! \param hookTargetUuid The UUID of the potential hook target
111 virtual void onHookTargetUuidChanged(const std::string& hookTargetUuid);
112
113 //! \brief Callback for changes to the tow-hook sensor contact map
114 //! \param sensorContacts The current set of tow-hook sensor contacts
115 virtual void onTowSensorContactsChanged(const TowSensorContactsMap& sensorContacts);
116
117 //! \brief Callback for changes to local hooked state
118 //! \param hooked True when the ownship is currently hooked
119 virtual void onHookedChanged(bool hooked);
120
121 //! \brief Callback for changes to the local VRE backend address
122 //! \param vreBackendAddress Current VRE backend sim address
123 virtual void onVreBackendChanged(const DtSimulationAddress& vreBackendAddress);
124
125 //! \brief Callback for tracked tow-candidate sim-engine updates
126 //! \param attr The simEngineAddress attribute handle that changed
128
129 //! \brief Synchronizes persistent simEngineAddress handles for the current contact set
130 //! \param sensorContacts The current tow-hook sensor contacts
131 virtual void updateTowCandidateSimEngineAttrs(const TowSensorContactsMap& sensorContacts);
132
133 //! \brief Refreshes fallback tow-candidate state from the tow-hook sensor contact map
135
136 //! \brief Refreshes whether the towing menu has a visible interaction target.
138
139 //! \brief Returns true when towing should stay in prep-only mode
140 //!
141 //! Prep-only mode is used when we have exactly one tow sensor candidate but no
142 //! authoritative same-backend hook target yet.
143 virtual bool shouldUseTowCandidatePrepMode() const;
144
145 //! \brief Starts ownership transfer for the current fallback tow candidate.
147
148 //! \brief Clears pending towing ownership-transfer state.
150
151 //! \brief Releases an acquired tow target that could not be hooked.
153
154 //! \brief Releases the transferred tow target after towing stops.
156
157 //! \brief Releases the transferred tow target after it leaves sensor range and the delay expires.
158 virtual void updateTransferredTowTargetRelease(double dt);
159
160 //! \brief Starts or cancels the release delay based on whether the transferred target is still in sensor contacts.
162
163 //! \brief Returns true if the transferred tow target is still in tow-hook sensor contacts.
165
166 //! \brief Attempts to hand off to the normal Vortex hook path after acquire success.
168
169 //! \brief Returns the tracked sim-engine address for a fallback tow candidate.
170 virtual DtSimulationAddress towCandidateSimEngine(const DtUUID& candidateUuid) const;
171
172 //! \brief Queues a set-state-property request for a tow target entity.
174 const DtEntityIdentifier& entityId, const std::string& name, const std::string& value, bool isBoolean);
175
176 //! \brief Refreshes the dynamic towing action-menu label.
177 virtual void updateHookActionLabel();
178
179 //! \brief Input handler logic for processing towing input device events
181
182 //! \brief Main joystick function group name from configuration
184
185 //! \brief Configuration flag indicating if this role should expose towing support.
187
188 //! \brief Delay in seconds before sending the tow-target ownership acquire request.
190
191 //! \brief Delay in seconds after the towed target leaves sensor range before releasing ownership.
193
194 //! \brief Timeout in seconds to wait for the tow hook to engage after transfer succeeds.
196
197 //! \brief Source attribute handle tracking whether the ownship is already hooked.
198 //! Reads the extended-state alias produced by DtExtendedStateLogic.
200
201 //! \brief Source attribute handle storing the authoritative same-backend hook target UUID.
202 //! Reads the extended-state alias produced by DtExtendedStateLogic.
204
205 //! \brief Sensor contacts used to discover nearby tow targets
206 //! \vreAttrKey{sensors.tow-hook-sensor.contacts}
208
209 //! \brief Simulation address of this station's VRE backend.
210 //! \vreAttrKey{vreBackendStatus.SimAddress}
212
213 //! \brief Attribute handle tracking live tow-hook availability.
214 //! Consumed by the towing HUD.
215 //! \vreAttrKey{towing.can-tow}
217
218 //! \brief Attribute handle tracking whether the ownship is already hooked.
219 //! Consumed by the towing HUD.
220 //! \vreAttrKey{towing.hooked}
222
223 //! \brief Attribute handle storing the marking text of the current tow hook target entity.
224 //! Consumed by the towing HUD.
225 //! \vreAttrKey{towing.hook-target-marking-text}
227
228 //! \brief Attribute handle indicating whether the towing menu should surface an interaction target.
229 //!
230 //! This remains true during ownership transfer so the action menu does not disappear
231 //! while the tow target is temporarily unavailable as a normal hook target.
232 //! Consumed by the towing action menu.
233 //! \vreAttrKey{towing.hasTowMenuTarget}
235
236 //! \brief Attribute handle storing the dynamic label for the towing action-menu item.
237 //! Consumed by the towing action menu.
238 //! \vreAttrKey{towing.hookActionLabel}
240
241 //! \brief Persistent per-contact simEngineAddress handles for fallback tow candidates.
243
244 //! \brief Callback manager for tracked tow-candidate simEngineAddress attributes.
246
247 //! \brief True when there is a valid authoritative tow hook target entity.
249
250 //! \brief True when a single fallback tow candidate exists.
252
253 //! \brief UUID of the fallback tow candidate.
255
256 //! \brief Entity identifier of the fallback tow candidate.
257 DtEntityIdentifier myTowCandidateEntityId;
258
259 //! \brief True when the fallback tow candidate is on another sim backend.
261
262 //! \brief True while a tow-target ownership acquire is in flight.
264
265 //! \brief True after acquire success while waiting for the normal hook target to appear.
267
268 //! \brief True after the hook command has been sent for a transferred target.
270
271 //! \brief Request id for the active tow-target ownership acquire.
273
274 //! \brief UUID of the tow target being acquired.
276
277 //! \brief Entity identifier of the tow target being acquired.
279
280 //! \brief Seconds remaining while waiting for the acquired target to become hookable and hooked.
282
283 //! \brief UUID of the transferred tow target while it is being towed.
285
286 //! \brief Entity identifier of the transferred tow target while it is being towed.
288
289 //! \brief True after unhooking while waiting for the transferred target to leave tow-hook sensor contacts.
291
292 //! \brief Seconds remaining before releasing the transferred tow target after it leaves sensor contacts.
294};
295
296} // namespace makVre
Provides a callback mechanism for attribute changes in the VREngage system.
Convenience manager that owns and organises a collection of attribute callbacks.
Definition attributeCallback.h:223
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Type-specific handle class for attributes.
Definition attributeHandle.h:229
DtEntityControlLogic()
Constructor.
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:39
virtual DtPlayerStation & player()
Gets the player station.
virtual const std::string & name()
Gets the component name.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
unsigned long long myPendingTowOwnershipRequestId
Request id for the active tow-target ownership acquire.
Definition towingControlLogic.h:272
DtAttributeHandleType< std::string > myHookTargetMarkingTextAttr
Attribute handle storing the marking text of the current tow hook target entity. Consumed by the towi...
Definition towingControlLogic.h:226
virtual bool transferredTowTargetInSensorContacts() const
Returns true if the transferred tow target is still in tow-hook sensor contacts.
virtual void shutdown() override
Shuts down the component and removes towing callbacks and input handlers.
double myTowOwnershipReleaseDelaySeconds
Delay in seconds after the towed target leaves sensor range before releasing ownership.
Definition towingControlLogic.h:192
double myPendingTowHookTimeout
Seconds remaining while waiting for the acquired target to become hookable and hooked.
Definition towingControlLogic.h:281
double myTowOwnershipAcquireDelaySeconds
Delay in seconds before sending the tow-target ownership acquire request.
Definition towingControlLogic.h:189
TowCandidateSimEngineAttrMap myTowCandidateSimEngineAttrs
Persistent per-contact simEngineAddress handles for fallback tow candidates.
Definition towingControlLogic.h:242
virtual DtVreMessageResult handleOwnershipTransferResponse(DtVreMessage *msg)
Handles ownership-transfer responses for tow-candidate acquires.
bool myTowCandidateNeedsOwnershipTransfer
True when the fallback tow candidate is on another sim backend.
Definition towingControlLogic.h:260
DtAttributeHandleType< bool > myCanTowAttr
Attribute handle tracking live tow-hook availability. Consumed by the towing HUD.
Definition towingControlLogic.h:216
DtTowingControlLogic()
Constructor for DtTowingControlLogic.
virtual void updateTransferredTowReleaseDelayFromSensorContacts()
Starts or cancels the release delay based on whether the transferred target is still in sensor contac...
DtEntityIdentifier myTowCandidateEntityId
Entity identifier of the fallback tow candidate.
Definition towingControlLogic.h:257
std::map< DtUUID, DtEntityType > TowSensorContactsMap
Definition towingControlLogic.h:61
bool myTransferredTowReleaseWaitingForSensorClear
True after unhooking while waiting for the transferred target to leave tow-hook sensor contacts.
Definition towingControlLogic.h:290
DtAttributeHandleType< DtSimulationAddress > myVreBackendAttr
Simulation address of this station's VRE backend.
Definition towingControlLogic.h:211
DtUUID myPendingTowTransferUuid
UUID of the tow target being acquired.
Definition towingControlLogic.h:275
bool myHasTowCandidate
True when a single fallback tow candidate exists.
Definition towingControlLogic.h:251
bool myTowHookCommandSent
True after the hook command has been sent for a transferred target.
Definition towingControlLogic.h:269
DtAttributeHandleType< bool > myHasTowMenuTargetAttr
Attribute handle indicating whether the towing menu should surface an interaction target.
Definition towingControlLogic.h:234
DtInputLogic myTowingInputLogic
Input handler logic for processing towing input device events.
Definition towingControlLogic.h:180
bool myHasTowHook
Configuration flag indicating if this role should expose towing support.
Definition towingControlLogic.h:186
virtual DtSimulationAddress towCandidateSimEngine(const DtUUID &candidateUuid) const
Returns the tracked sim-engine address for a fallback tow candidate.
DtAttributeCallbackManager myTowCandidateAttributeCallbacks
Callback manager for tracked tow-candidate simEngineAddress attributes.
Definition towingControlLogic.h:245
DtAttributeHandleType< bool > myHookedAttr
Attribute handle tracking whether the ownship is already hooked. Consumed by the towing HUD.
Definition towingControlLogic.h:221
std::string myMainJoystickGroup
Main joystick function group name from configuration.
Definition towingControlLogic.h:183
virtual void onHookTargetUuidChanged(const std::string &hookTargetUuid)
Callback for changes to the hook target UUID.
virtual DtVreMessageResult handleMenuMessage(DtVreMessage *msg)
Handles towing-related action-menu messages.
virtual void onTowSensorContactsChanged(const TowSensorContactsMap &sensorContacts)
Callback for changes to the tow-hook sensor contact map.
virtual bool shouldUseTowCandidatePrepMode() const
Returns true when towing should stay in prep-only mode.
virtual void sendJoystickMessage(const std::string &function, double val, double delay=0)
Sends a joystick message to the simulation.
virtual void updateTowMenuTargetState()
Refreshes whether the towing menu has a visible interaction target.
virtual void clearTowOwnershipTransferState()
Clears pending towing ownership-transfer state.
virtual void onVreBackendChanged(const DtSimulationAddress &vreBackendAddress)
Callback for changes to the local VRE backend address.
bool myTowOwnershipTransferWaitingForHook
True after acquire success while waiting for the normal hook target to appear.
Definition towingControlLogic.h:266
double myTowHookHandoffTimeoutSeconds
Timeout in seconds to wait for the tow hook to engage after transfer succeeds.
Definition towingControlLogic.h:195
virtual void updateTowCandidateState()
Refreshes fallback tow-candidate state from the tow-hook sensor contact map.
DtEntityIdentifier myTransferredTowTargetEntityId
Entity identifier of the transferred tow target while it is being towed.
Definition towingControlLogic.h:287
virtual const char * type() const override
Returns the component type identifier.
DtUUID myTowCandidateUuid
UUID of the fallback tow candidate.
Definition towingControlLogic.h:254
virtual void updateTransferredTowTargetRelease(double dt)
Releases the transferred tow target after it leaves sensor range and the delay expires.
virtual void onTowCandidateSimEngineAddressChanged(const DtAttributeHandle &attr)
Callback for tracked tow-candidate sim-engine updates.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the towing control logic from Lua configuration.
virtual void releaseTransferredTowTarget()
Releases the transferred tow target after towing stops.
virtual void startTowOwnershipTransfer()
Starts ownership transfer for the current fallback tow candidate.
DtUUID myTransferredTowTargetUuid
UUID of the transferred tow target while it is being towed.
Definition towingControlLogic.h:284
virtual void tick(double dt) override
Updates pending tow-transfer handoff state.
virtual void updateTowCandidateSimEngineAttrs(const TowSensorContactsMap &sensorContacts)
Synchronizes persistent simEngineAddress handles for the current contact set.
virtual void updateHookActionLabel()
Refreshes the dynamic towing action-menu label.
virtual ~DtTowingControlLogic() override
Virtual destructor for DtTowingControlLogic.
DtAttributeHandleType< bool > myHookedSourceAttr
Source attribute handle tracking whether the ownship is already hooked. Reads the extended-state alia...
Definition towingControlLogic.h:199
DtAttributeHandleType< std::string > myHookTargetUuidSourceAttr
Source attribute handle storing the authoritative same-backend hook target UUID. Reads the extended-s...
Definition towingControlLogic.h:203
virtual void releasePendingTowTransferTarget()
Releases an acquired tow target that could not be hooked.
DtAttributeHandleType< TowSensorContactsMap > mySensorContactsAttr
Sensor contacts used to discover nearby tow targets.
Definition towingControlLogic.h:207
bool myTowOwnershipTransferInProgress
True while a tow-target ownership acquire is in flight.
Definition towingControlLogic.h:263
virtual void setHook(double val)
Controls the towing hook.
bool myHasHookTarget
True when there is a valid authoritative tow hook target entity.
Definition towingControlLogic.h:248
virtual void tryAutoHookAfterTransfer()
Attempts to hand off to the normal Vortex hook path after acquire success.
std::map< DtUUID, DtAttributeHandleType< DtSimulationAddress > > TowCandidateSimEngineAttrMap
Definition towingControlLogic.h:62
virtual void onHookedChanged(bool hooked)
Callback for changes to local hooked state.
DtEntityIdentifier myPendingTowTransferEntityId
Entity identifier of the tow target being acquired.
Definition towingControlLogic.h:278
virtual void queueTowTargetStateProperty(const DtEntityIdentifier &entityId, const std::string &name, const std::string &value, bool isBoolean)
Queues a set-state-property request for a tow target entity.
double myTransferredTowReleaseDelay
Seconds remaining before releasing the transferred tow target after it leaves sensor contacts.
Definition towingControlLogic.h:293
DtAttributeHandleType< std::string > myHookActionLabelAttr
Attribute handle storing the dynamic label for the towing action-menu item. Consumed by the towing ac...
Definition towingControlLogic.h:239
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines the logic for controlling entities in VR-Engage.
constexpr auto ownershipReleaseDelaySeconds
Definition towingControlLogic.h:44
constexpr auto ownershipAcquireDelaySeconds
Definition towingControlLogic.h:41
constexpr auto hookHandoffTimeoutSeconds
Definition towingControlLogic.h:47
constexpr auto hasTowHook
Definition towingControlLogic.h:38
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition towingControlLogic.h:30
!
Definition glsVreMessageUtil.h:50
constexpr auto DtTowingControlLogicType
Type identifier for DtTowingControlLogic component.
Definition towingControlLogic.h:52
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33