VR-Engage  2.2
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
21#include <string>
22#include <vector>
23
24namespace makVre
25{
27{
28//! \ingroup RoleConfigParams
29//! \defgroup EntityControlLogicRoleParams Entity Control Logic Role Parameters
30//! Configuration Options for Entity Control Logic.
31//! @{
32
33//! \vreRoleParamRequired{inputConfigFile,string,entityControlLogic,"driverInput.lua",The input file to reference to get all keybinds and actions.}
34constexpr const char* inputConfigFile = "inputConfigFile";
35
36//! \vreRoleParam{mouseControlSupport,bool,false,entityControlLogic,Determines whether or not this role has mouse control enabled.}
37constexpr const char* mouseControlSupport = "mouseControlSupport";
38
39//! \vreRoleParamRequired{joystickFunctionGroups,DtInitTable,entityControlLogic,{"Human Movement";},The function groups to reference for sending inputs to the backend}
40constexpr const char* joystickFunctionGroups = "joystickFunctionGroups";
41//! @}
42} // namespace EntityControlLogicConfig
43
44//! \brief Type identifier constant for DtEntityControlLogic components
45//!
46//! This constant defines the string identifier used to identify DtEntityControlLogic
47//! component types within the VR-Engage framework. It is used for component
48//! registration, type checking, and serialization operations.
49constexpr const char* DtEntityControlLogicType = "DtEntityControlLogic";
50
51//! \brief Component that provides entity control functionality
52//!
53//! DtEntityControlLogic is responsible for translating user input into entity control commands and managing the state
54//! of player-controlled entities. It handles input mapping for different control modes (mouse, joystick, etc.), entity
55//! state synchronization, and specific control operations like reset.
56//!
57//! This component serves as the primary interface between user input and
58//! entity behavior in the simulation.
60{
61public:
62 //! \brief Constructor
63 //! \param type Type identifier for the component
64 //!
65 //! Creates a new entity control logic component with the specified type.
66 //! The default type is "DtEntityControlLogic".
68
69 //! \brief Virtual destructor
70 //!
71 //! Ensures proper cleanup of entity control resources.
72 virtual ~DtEntityControlLogic() override;
73
74 //! \brief Initializes the entity control logic
75 //! \param player Pointer to the player station this component belongs to
76 //! \param config Configuration table with initialization parameters
77 //! \return True if initialization was successful, false otherwise
78 //!
79 //! Initializes the entity control component with the specified player station
80 //! and configuration. Registers message handlers and sets up input mappings.
81 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
82
83 //! \brief Performs post-initialization setup
84 //! \return True if post-initialization was successful, false otherwise
85 //!
86 //! Completes initialization tasks that require other components to be
87 //! already initialized. This typically includes setting up connections
88 //! to other components and starting entity control.
89 virtual bool postInitialize() override;
90
91 //! \brief Updates the entity control logic each frame
92 //! \param dt Time in seconds since the last update
93 //!
94 //! Handles per-frame updates for entity control, including processing
95 //! input and updating entity states. This is called once per frame.
96 virtual void tick(double dt) override;
97
98 //! \brief Shuts down the entity control logic
99 //!
100 //! Cleans up resources, disconnects from input handlers, and releases
101 //! control of entities. Called when the player station is shutting down.
102 virtual void shutdown() override;
103
104 //! \brief Returns the component type identifier
105 //! \return String identifier for this component type
106 //!
107 //! Returns the type identifier string for this component, which is used
108 //! by the VR-Engage framework for component identification and management.
109 //! The returned value matches DtEntityControlLogicType.
110 virtual const char* type() const override;
111
112 //! \brief Message handlers
113 //! @{
114
115 //! \brief Handles simulation state update messages
116 //! \param msg Pointer to the simulation state message
117 //! \return Message handling result
118 //!
119 //! Processes simulation state messages, updating the component's
120 //! understanding of the current entity state in the simulation.
122
123 //! \brief Handles general state messages
124 //! \param message Pointer to the state message
125 //! \return Message handling result
126 //!
127 //! Processes various state-related messages that affect entity control.
129
130 //! \brief Handles reset messages
131 //! \param message Pointer to the reset message
132 //! \return Message handling result
133 //!
134 //! Processes messages requesting an entity reset, either in place
135 //! or to a default position/state.
137 //! @}
138
139 //! \brief Sets extended data for an entity
140 //! \param key Key identifier for the data being set
141 //! \param value Value to set for the specified key
142 //! \param entity Entity identifier to set data for (defaults to ownship entity)
143 //!
144 //! Sets extended data values for an entity, typically used for custom
145 //! properties or state information that isn't part of the standard entity state.
146 //! If no entity is specified, applies to the player's own entity (ownship).
147 virtual void setExtendedData(
148 const std::string& key, const std::string& value, DtEntityIdentifier entity = DtEntityIdentifier::nullId());
149
150 //! \brief Entity reset methods
151 //! @{
152
153 //! \brief Resets the entity to its default state
154 //! \param val Input value (typically 1.0 for pressed actions)
155 //!
156 //! Resets the player's entity to its default position and state.
157 //! This is typically triggered by a user input action.
158 virtual void reset(float val);
159
160 //! \brief Resets the entity while maintaining its current position
161 //! \param val Input value (typically 1.0 for pressed actions)
162 //!
163 //! Resets the player's entity to its default state except for position,
164 //! which remains unchanged. Useful for clearing problems without relocating.
165 virtual void resetInPlace(float val);
166 //! @}
167
168 //! \brief Mouse control methods
169 //! @{
170
171 //! \brief Toggles mouse control mode on/off
172 //! \param val Input value (typically 1.0 for pressed actions)
173 //!
174 //! Toggles between mouse control being enabled and disabled.
175 //! This is typically triggered by a user input action.
176 virtual void toggleMouseControl(float val);
177
178 //! \brief Enables mouse control mode
179 //! \param val Input value (typically 1.0 for pressed actions)
180 //!
181 //! Explicitly enables mouse control without toggling.
182 //! This is typically triggered by a user input action.
183 virtual void enableMouseControl(float val);
184
185 //! \brief Handles application focus change messages
186 //! \param message Pointer to the focus message
187 //! \return Message handling result
188 //!
189 //! Processes messages about application focus changes, which may
190 //! affect how input control works (e.g., disabling control when
191 //! the application loses focus).
193 //! @}
194
195 //! \brief Sets whether mouse control is enabled
196 //! \param enabled True to enable mouse control, false to disable it
197 //!
198 //! Controls whether mouse input is used for entity control.
199 //! When disabled, other input methods like joystick may still work.
200 virtual void setMouseControlEnabled(bool enabled);
201
202 //! \brief Checks if mouse control is currently enabled
203 //! \return True if mouse control is enabled, false otherwise
204 //!
205 //! Determines whether mouse input is currently being used for entity control.
206 virtual bool isMouseControlEnabled();
207
208 //! \brief Checks if mouse control support is allowed
209 //! \return True if mouse control is allowed, false if explicitly disallowed
210 //!
211 //! Determines whether mouse control is allowed for the current entity or mode.
212 //! Some entity types or control modes may not support mouse control.
213 virtual bool isMouseControlSupportAllowed() const;
214
215 //! \brief Sets whether mouse control support is allowed
216 //! \param enable True to allow mouse control, false to disallow it
217 //!
218 //! Controls whether mouse control is allowed as an option for the current
219 //! entity or mode. This affects whether mouse control can be enabled at all.
220 virtual void setMouseControlSupportAllowed(bool enable);
221
222 //! \brief Gets the joystick function groups
223 //! \return Reference to the vector of joystick function group names
224 //!
225 //! Retrieves the list of joystick function groups used by this entity controller.
226 //! These groups organize joystick input mappings by function.
227 virtual const std::vector<std::string>& joystickGroups() const;
228
229protected:
230 //! \brief Takes control of the player's entity
231 //!
232 //! Establishes control over the player's assigned entity, enabling
233 //! input to affect the entity's state and behavior. Typically called
234 //! during initialization or when a new entity is assigned.
236
237 //! \brief Releases control of the player's entity
238 //!
239 //! Relinquishes control over the player's assigned entity, preventing
240 //! further input from affecting the entity. Typically called during
241 //! shutdown or when changing entities.
243
244
245 //! \brief List of joystick function groups used by this controller
246 std::vector<std::string> myJoystickFunctionGroups;
247
248 //! \brief Input logic handler for common controls
249 //!
250 //! Manages input mappings and action handlers for general entity control.
252
253 //! \brief Name of the input configuration file
254 //!
255 //! Identifies the configuration file containing input mappings for this controller.
256 std::string myInputConfigFile;
257
258 //! \brief Flag indicating whether mouse control is currently enabled
260
261 //! \brief Flag indicating whether mouse control is allowed for the current entity/mode
263};
264
265} // namespace makVre
virtual void enableMouseControl(float val)
Enables mouse control mode.
virtual void resetInPlace(float val)
Resets the entity while maintaining its current position.
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:251
virtual void setExtendedData(const std::string &key, const std::string &value, DtEntityIdentifier entity=DtEntityIdentifier::nullId())
Sets extended data for an entity.
virtual void tick(double dt) override
Updates the entity control logic each frame.
virtual makVre::DtVreMessageResult handleReset(makVre::DtVreMessage *message)
Handles reset messages.
bool myMouseControlEnabled
Flag indicating whether mouse control is currently enabled.
Definition entityControlLogic.h:259
virtual void shutdown() override
Shuts down the entity control logic.
virtual void reset(float val)
Entity reset methods.
virtual void toggleMouseControl(float val)
Mouse control methods.
virtual bool postInitialize() override
Performs post-initialization setup.
virtual ~DtEntityControlLogic() override
Virtual destructor.
virtual makVre::DtVreMessageResult handleStateMessages(makVre::DtVreMessage *message)
Handles general state messages.
virtual const std::vector< std::string > & joystickGroups() const
Gets the joystick function groups.
virtual bool isMouseControlSupportAllowed() const
Checks if mouse control support is allowed.
virtual void takeControlOfPlayerEntity()
Takes control of the player's entity.
virtual const char * type() const override
Returns the component type identifier.
bool myMouseControlSupportAllowed
Flag indicating whether mouse control is allowed for the current entity/mode.
Definition entityControlLogic.h:262
virtual bool isMouseControlEnabled()
Checks if mouse control is currently enabled.
std::string myInputConfigFile
Name of the input configuration file.
Definition entityControlLogic.h:256
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:246
DtEntityControlLogic()
Constructor.
virtual void releaseControlOfPlayerEntity()
Releases control of the player's 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:35
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
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:34
constexpr const char * joystickFunctionGroups
Definition entityControlLogic.h:40
constexpr const char * mouseControlSupport
Definition entityControlLogic.h:37
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:27
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtEntityControlLogicType
Type identifier constant for DtEntityControlLogic components.
Definition entityControlLogic.h:49
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines the base class for all VREngage messages.