VR-Engage  2.3
Loading...
Searching...
No Matches
entityControlLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file entityControlLogic.h
7//! \brief Defines the logic for controlling entities in VR-Engage
8//!
9//! This file contains the DtEntityControlLogic class which provides the core
10//! functionality for controlling entities in the simulation. It handles user
11//! input mapping, entity state updates, and simulation control operations.
12
13#pragma once
14
18
20
22
23#include <string>
24#include <vector>
25
26#include <QString>
27
28namespace makVre
29{
31{
32//! \ingroup RoleConfigParams
33//! \defgroup EntityControlLogicRoleParams Entity Control Logic Role Parameters
34//! Configuration Options for Entity Control Logic.
35//! @{
36
37//! \vreRoleParamRequired{inputConfigFile,string,entityControlLogic,"driverInput.lua",The input file to reference to get all keybinds and actions.}
38constexpr const char* inputConfigFile = "inputConfigFile";
39
40//! \vreRoleParam{mouseControlSupport,bool,false,entityControlLogic,Determines whether or not this role has mouse control enabled.}
41constexpr const char* mouseControlSupport = "mouseControlSupport";
42
43//! \vreRoleParamRequired{joystickFunctionGroups,DtInitTable,entityControlLogic,{"Human Movement";},The function groups to reference for sending inputs to the backend}
44constexpr const char* joystickFunctionGroups = "joystickFunctionGroups";
45//! @}
46} // namespace EntityControlLogicConfig
47
48//! \brief Type identifier constant for DtEntityControlLogic components
49//!
50//! This constant defines the string identifier used to identify DtEntityControlLogic
51//! component types within the VR-Engage framework. It is used for component
52//! registration, type checking, and serialization operations.
53constexpr const char* DtEntityControlLogicType = "DtEntityControlLogic";
54
55//! \brief Component that provides entity control functionality
56//!
57//! DtEntityControlLogic is responsible for translating user input into entity control commands and managing the state
58//! of player-controlled entities. It handles input mapping for different control modes (mouse, joystick, etc.), entity
59//! state synchronization, and specific control operations like reset.
60//!
61//! This component serves as the primary interface between user input and
62//! entity behavior in the simulation.
64{
65public:
66 //! \brief Constructor
67 //! \param type Type identifier for the component
68 //!
69 //! Creates a new entity control logic component with the specified type.
70 //! The default type is "DtEntityControlLogic".
72
73 //! \brief Virtual destructor
74 //!
75 //! Ensures proper cleanup of entity control resources.
76 virtual ~DtEntityControlLogic() override;
77
78 //! \brief Initializes the entity control logic
79 //! \param player Pointer to the player station this component belongs to
80 //! \param config Configuration table with initialization parameters
81 //! \return True if initialization was successful, false otherwise
82 //!
83 //! Initializes the entity control component with the specified player station
84 //! and configuration. Registers message handlers and sets up input mappings.
85 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
86
87 //! \brief Performs post-initialization setup
88 //! \return True if post-initialization was successful, false otherwise
89 //!
90 //! Completes initialization tasks that require other components to be
91 //! already initialized. This typically includes setting up connections
92 //! to other components and starting entity control.
93 virtual bool postInitialize() override;
94
95 //! \brief Updates the entity control logic each frame
96 //! \param dt Time in seconds since the last update
97 //!
98 //! Handles per-frame updates for entity control, including processing
99 //! input and updating entity states. This is called once per frame.
100 virtual void tick(double dt) override;
101
102 //! \brief Shuts down the entity control logic
103 //!
104 //! Cleans up resources, disconnects from input handlers, and releases
105 //! joystick function-group control. Role occupancy remains until the
106 //! player station is permanently destroyed.
107 virtual void shutdown() override;
108
109 //! \brief Returns the component type identifier
110 //! \return String identifier for this component type
111 //!
112 //! Returns the type identifier string for this component, which is used
113 //! by the VR-Engage framework for component identification and management.
114 //! The returned value matches DtEntityControlLogicType.
115 virtual const char* type() const override;
116
117 //! \brief Message handlers
118 //! @{
119
120 //! \brief Handles simulation state update messages
121 //! \param msg Pointer to the simulation state message
122 //! \return Message handling result
123 //!
124 //! Processes simulation state messages, updating the component's
125 //! understanding of the current entity state in the simulation.
127
128 //! \brief Handles reset messages
129 //! \param message Pointer to the reset message
130 //! \return Message handling result
131 //!
132 //! Processes messages requesting an entity reset, either in place
133 //! or to a default position/state.
135
136 //! \brief Handles player station creation status messages
137 //! \param message Pointer to the creation status message
138 //! \return Message handling result
139 //!
140 //! When the current phase reaches ComponentsReady, this handler calls
141 //! takeControlOfPlayerEntity() and then removes itself. This replaces
142 //! the previous direct call in postInitialize().
144 //! @}
145
146 //! \brief Entity reset methods
147 //! @{
148
149 //! \brief Resets the entity to its default state
150 //! \param val Input value (typically 1.0 for pressed actions)
151 //!
152 //! Resets the player's entity to its default position and state.
153 //! This is typically triggered by a user input action.
154 virtual void reset(float val);
155
156 //! \brief Resets the entity while maintaining its current position
157 //! \param val Input value (typically 1.0 for pressed actions)
158 //!
159 //! Resets the player's entity to its default state except for position,
160 //! which remains unchanged. Useful for clearing problems without relocating.
161 virtual void resetInPlace(float val);
162 //! @}
163
164 //! \brief Mouse control methods
165 //! @{
166
167 //! \brief Toggles mouse control mode on/off
168 //! \param val Input value (typically 1.0 for pressed actions)
169 //!
170 //! Toggles between mouse control being enabled and disabled.
171 //! This is typically triggered by a user input action.
172 virtual void toggleMouseControl(float val);
173
174 //! \brief Enables mouse control mode
175 //! \param val Input value (typically 1.0 for pressed actions)
176 //!
177 //! Explicitly enables mouse control without toggling.
178 //! This is typically triggered by a user input action.
179 virtual void enableMouseControl(float val);
180
181 //! \brief Handles application focus change messages
182 //! \param message Pointer to the focus message
183 //! \return Message handling result
184 //!
185 //! Processes messages about application focus changes, which may
186 //! affect how input control works (e.g., disabling control when
187 //! the application loses focus).
189 //! @}
190
191 //! \brief Sets whether mouse control is enabled
192 //! \param enabled True to enable mouse control, false to disable it
193 //!
194 //! Controls whether mouse input is used for entity control.
195 //! When disabled, other input methods like joystick may still work.
196 virtual void setMouseControlEnabled(bool enabled);
197
198 //! \brief Checks if mouse control is currently enabled
199 //! \return True if mouse control is enabled, false otherwise
200 //!
201 //! Determines whether mouse input is currently being used for entity control.
202 virtual bool isMouseControlEnabled();
203
204 //! \brief Checks if mouse control support is allowed
205 //! \return True if mouse control is allowed, false if explicitly disallowed
206 //!
207 //! Determines whether mouse control is allowed for the current entity or mode.
208 //! Some entity types or control modes may not support mouse control.
209 virtual bool isMouseControlSupportAllowed() const;
210
211 //! \brief Sets whether mouse control support is allowed
212 //! \param enable True to allow mouse control, false to disallow it
213 //!
214 //! Controls whether mouse control is allowed as an option for the current
215 //! entity or mode. This affects whether mouse control can be enabled at all.
216 virtual void setMouseControlSupportAllowed(bool enable);
217
218 //! \brief Gets the joystick function groups
219 //! \return Reference to the vector of joystick function group names
220 //!
221 //! Retrieves the list of joystick function groups used by this entity controller.
222 //! These groups organize joystick input mappings by function.
223 virtual const std::vector<std::string>& joystickGroups() const;
224
225 //! \brief Sends a joystick command to a controlled entity
226 virtual void sendJoystickCommand(const DtEntityIdentifier& id,
227 const std::string& functionGroup,
228 const std::string& function,
229 double val,
230 bool repeat = false);
231
232protected:
233
234 //! \brief Returns true if the player is not a spectator and health > 0
235 bool requiresControl() const;
236
237 //! \brief Returns true if posture attribute is JUMPING or PARACHUTING
238 bool isAirborne() const;
239
240 //! \brief Displays a temporary notification via the player app
241 void showNotification(const QString& text, double duration);
242
243//! \brief Takes control of the player's entity
244 //!
245 //! Establishes control over the player's assigned entity, enabling
246 //! input to affect the entity's state and behavior. Typically called
247 //! during initialization or when a new entity is assigned.
249
250 //! \brief Releases joystick control of the player's entity
251 //!
252 //! Relinquishes joystick function groups for the player's assigned entity,
253 //! preventing further input from affecting the entity. Role occupancy is
254 //! released by the player station destructor.
256
257
258 //! \brief List of joystick function groups used by this controller
259 std::vector<std::string> myJoystickFunctionGroups;
260
261 //! \brief Input logic handler for common controls
262 //!
263 //! Manages input mappings and action handlers for general entity control.
265
266 //! \brief Name of the input configuration file
267 //!
268 //! Identifies the configuration file containing input mappings for this controller.
269 std::string myInputConfigFile;
270
271 //! \brief Flag indicating whether mouse control is currently enabled
273
274 //! \brief Flag indicating whether mouse control is allowed for the current entity/mode
276
277 //! \brief Handle root for ownship attributes.
278 //! \vreAttrKey{ownship}
280
281 //! \brief Handle for embarked state.
282 //! \vreAttrKey{ownship.embarked}
284
285 //! \brief Handle for embarked host entity identifier.
286 //! \vreAttrKey{ownship.embarked.host}
288
289 //! \brief Handle for embarked host entity type.
290 //! \vreAttrKey{ownship.embarked.hostType}
292
293 //! \brief Handle for embarked host marking text.
294 //! \vreAttrKey{ownship.embarked.hostMarking}
296
297 //! \brief Handle indicating whether ownship is embarked on an aircraft.
298 //! \vreAttrKey{ownship.embarked.embarkedOnAircraft}
300
301 //! \brief Handle for embarked slot name.
302 //! \vreAttrKey{ownship.embarked.embarkedInSlot}
304
305 //! \brief Handle for ownship appearance bits.
306 //! \vreAttrKey{ownship.appearance}
308
309 //! \brief Handle for ownship world position.
310 //! \vreAttrKey{ownship.position}
312
313 //! \brief Handle for ownship world orientation.
314 //! \vreAttrKey{ownship.orientation}
316
317 //! \brief Handle for ownship speed magnitude.
318 //! \vreAttrKey{ownship.speed}
320
321 //! \brief Handle for ownship world velocity.
322 //! \vreAttrKey{ownship.velocity}
324
325 //! \brief Handle for ownship world acceleration.
326 //! \vreAttrKey{ownship.acceleration}
328
329 //! \brief Handle for ownship rotational velocity.
330 //! \vreAttrKey{ownship.rotationVelocity}
332
333 //! \brief Handle for ownship entity type.
334 //! \vreAttrKey{ownship.entityType}
336
337 //! \brief Handle for ownship relative velocity.
338 //! \vreAttrKey{ownship.relativeVelocity}
340
341 //! \brief Handle for ownship damage state.
342 //! \vreAttrKey{ownship.damageState}
344
345 //! \brief Handle for simulation state update index.
346 //! \vreAttrKey{simStateUpdateIndex}
348
349 //! \brief Handle indicating whether occupants should be hidden.
350 //! \vreAttrKey{HideOccupants}
352};
353
354} // namespace makVre
Provides handle classes for safe access to attributes.
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Type-specific handle class for attributes.
Definition attributeHandle.h:229
virtual void enableMouseControl(float val)
Enables mouse control mode.
virtual void resetInPlace(float val)
Resets the entity while maintaining its current position.
DtAttributeHandleType< DtVector > myPositionAttr
Handle for ownship world position.
Definition entityControlLogic.h:311
virtual void setMouseControlEnabled(bool enabled)
Sets whether mouse control is enabled.
virtual void setMouseControlSupportAllowed(bool enable)
Sets whether mouse control support is allowed.
virtual makVre::DtVreMessageResult handleFocusMessage(makVre::DtVreMessage *message)
Handles application focus change messages.
DtInputLogic myCommonInputLogic
Input logic handler for common controls.
Definition entityControlLogic.h:264
DtAttributeHandle myOwnshipAttr
Handle root for ownship attributes.
Definition entityControlLogic.h:279
DtAttributeHandleType< DtVector32 > myRelativeVelocityAttr
Handle for ownship relative velocity.
Definition entityControlLogic.h:339
virtual void tick(double dt) override
Updates the entity control logic each frame.
bool isAirborne() const
Returns true if posture attribute is JUMPING or PARACHUTING.
virtual makVre::DtVreMessageResult handleCreationStatus(makVre::DtVreMessage *message)
Handles player station creation status messages.
virtual makVre::DtVreMessageResult handleReset(makVre::DtVreMessage *message)
Handles reset messages.
DtAttributeHandleType< bool > myHideOccupantsAttr
Handle indicating whether occupants should be hidden.
Definition entityControlLogic.h:351
DtAttributeHandleType< DtDamageState > myDamageStateAttr
Handle for ownship damage state.
Definition entityControlLogic.h:343
bool myMouseControlEnabled
Flag indicating whether mouse control is currently enabled.
Definition entityControlLogic.h:272
DtAttributeHandleType< DtEntityType > myEmbarkedHostTypeAttr
Handle for embarked host entity type.
Definition entityControlLogic.h:291
DtAttributeHandleType< DtVector32 > myAccelerationAttr
Handle for ownship world acceleration.
Definition entityControlLogic.h:327
virtual void shutdown() override
Shuts down the entity control logic.
virtual void reset(float val)
Entity reset methods.
bool requiresControl() const
Returns true if the player is not a spectator and health > 0.
virtual void toggleMouseControl(float val)
Mouse control methods.
virtual bool postInitialize() override
Performs post-initialization setup.
virtual ~DtEntityControlLogic() override
Virtual destructor.
virtual const std::vector< std::string > & joystickGroups() const
Gets the joystick function groups.
virtual bool isMouseControlSupportAllowed() const
Checks if mouse control support is allowed.
DtAttributeHandleType< DtEntityIdentifier > myEmbarkedHostAttr
Handle for embarked host entity identifier.
Definition entityControlLogic.h:287
void showNotification(const QString &text, double duration)
Displays a temporary notification via the player app.
DtAttributeHandleType< unsigned int > myAppearanceAttr
Handle for ownship appearance bits.
Definition entityControlLogic.h:307
DtAttributeHandleType< DtTaitBryan > myOrientationAttr
Handle for ownship world orientation.
Definition entityControlLogic.h:315
DtAttributeHandleType< double > mySpeedAttr
Handle for ownship speed magnitude.
Definition entityControlLogic.h:319
DtAttributeHandleType< DtVector32 > myVelocityAttr
Handle for ownship world velocity.
Definition entityControlLogic.h:323
virtual void takeControlOfPlayerEntity()
Takes control of the player's entity.
virtual const char * type() const override
Returns the component type identifier.
DtAttributeHandleType< bool > myEmbarkedOnAircraftAttr
Handle indicating whether ownship is embarked on an aircraft.
Definition entityControlLogic.h:299
bool myMouseControlSupportAllowed
Flag indicating whether mouse control is allowed for the current entity/mode.
Definition entityControlLogic.h:275
virtual bool isMouseControlEnabled()
Checks if mouse control is currently enabled.
std::string myInputConfigFile
Name of the input configuration file.
Definition entityControlLogic.h:269
virtual makVre::DtVreMessageResult handleSimState(makVre::DtVreMessage *msg)
Message handlers.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the entity control logic.
std::vector< std::string > myJoystickFunctionGroups
List of joystick function groups used by this controller.
Definition entityControlLogic.h:259
DtAttributeHandleType< bool > myEmbarkedAttr
Handle for embarked state.
Definition entityControlLogic.h:283
DtEntityControlLogic()
Constructor.
DtAttributeHandleType< std::string > myEmbarkedHostMarkingAttr
Handle for embarked host marking text.
Definition entityControlLogic.h:295
DtAttributeHandleType< std::string > myEmbarkedInSlotAttr
Handle for embarked slot name.
Definition entityControlLogic.h:303
DtAttributeHandleType< DtEntityType > myEntityTypeAttr
Handle for ownship entity type.
Definition entityControlLogic.h:335
virtual void releaseControlOfPlayerEntity()
Releases joystick control of the player's entity.
DtAttributeHandleType< DtVector32 > myRotVelAttr
Handle for ownship rotational velocity.
Definition entityControlLogic.h:331
DtAttributeHandleType< int > mySimStateUpdateIndexAttr
Handle for simulation state update index.
Definition entityControlLogic.h:347
virtual void sendJoystickCommand(const DtEntityIdentifier &id, const std::string &functionGroup, const std::string &function, double val, bool repeat=false)
Sends a joystick command to a controlled entity.
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
Base class for all role components in VR-Engage.
Definition playerComponent.h:102
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
constexpr const char * inputConfigFile
Definition entityControlLogic.h:38
constexpr const char * joystickFunctionGroups
Definition entityControlLogic.h:44
constexpr const char * mouseControlSupport
Definition entityControlLogic.h:41
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Defines the DtInputLogic class for handling input in VR-Engage.
Definition entityControlLogic.h:31
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtEntityControlLogicType
Type identifier constant for DtEntityControlLogic components.
Definition entityControlLogic.h:53
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines the base class for all VREngage messages.