VR-Engage  2.2
Loading...
Searching...
No Matches
vrePlayerLaserController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vrePlayerLaserController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for player-controlled laser designation
9//!
10//! This file defines the DtVrePlayerLaserController class which provides an interface
11//! that a VR-Engage player can use to control a laser designator. The interface between
12//! the player in the front-end and this back-end controller uses these messages:
13//! - StartLasing - turn the laser on
14//! - StopLasing - turn the laser off
15//! - UpdateLasingState - update current laser target or spot location
16//!
17//! This class is intended to provide inputs to the VR-Forces DtLasingController, which
18//! creates and manages the published designator object associated with the laser.
19
20#pragma once
21
22#include "vreVrfmodel/export.h"
24
26
27#include <vrfobjcore/controllerComponent.h>
28
29class DtLasingPSR;
30class DtBooleanOutputPort;
31class DtVectorOutputPort;
32class DtStringOutputPort;
33
34namespace makVre
35{
36//! \brief Type identifier for the VRE player laser controller component
37const char DtVrePlayerLaserControllerType[] = "vre-player-laser-controller";
38
39//! \brief Controller for player-controlled laser designation functionality
40//!
41//! DtVrePlayerLaserController provides an interface for VR-Engage players to
42//! control a laser designator. It handles messages from the front-end to activate,
43//! deactivate, and update the laser's target. The controller sets appropriate output
44//! ports that can be connected to a DtLasingController to actually create the
45//! laser designation object in the simulation.
47{
48private:
49 //! \brief Default constructor (not implemented)
50 //!
51 //! Default constructor is private and not implemented to prevent
52 //! creation of instances without proper initialization.
54
55 //! \brief Copy constructor (not implemented)
56 //!
57 //! Copy constructor is private and not implemented to prevent
58 //! copy construction.
60
61 //! \brief Assignment operator (not implemented)
62 //! \return Reference to this object
63 //!
64 //! Assignment operator is private and not implemented to prevent assignment.
66
67public:
68 //! \brief Constructor
69 //! \param name The name of this component
70 //! \param owner The local object that owns this component
71 //! \param simManager The simulation services manager
72 //! \param desc Component descriptor with configuration parameters
73 //! \param parentRegistry Optional parent registry for reader/writer functionality
74 //!
75 //! Creates a new player laser controller component with the specified parameters.
76 DtVrePlayerLaserController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
77 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
78
79 //! \brief Virtual destructor
80 //!
81 //! Cleans up resources used by the player laser controller component.
82 virtual ~DtVrePlayerLaserController() override;
83
84 //! \brief Gets the type identifier for this component
85 //! \return String identifying the component type (DtVrePlayerLaserControllerType)
86 //!
87 //! Implements the DtSimComponent::type() method to return the
88 //! type identifier for this component.
89 virtual const char* type() const override;
90
91 //! \brief Performs initialization before the first simulation tick
92 //!
93 //! Gets initial laser designator code from the Process State Repository (PSR)
94 //! and copies it to the state property "laserCode". This ensures that the
95 //! GUI displays the correct laser code when the simulation starts.
96 virtual void preFirstTickInit() override;
97
98 //! \brief Updates the controller state each simulation frame
99 //!
100 //! Processes laser controller logic each simulation frame, updating
101 //! output ports based on the current lasing state and target information.
102 virtual void tick() override;
103
104 //! \brief Initializes the player laser controller
105 //! \return True if initialization is successful, false otherwise
106 //!
107 //! Sets the state property named "HasLaser" to True. This property is defined
108 //! in the platform sysdef file under state-data and is used by the VR-Engage menu
109 //! system to determine whether to show laser designation options in the user interface.
110 //! Also creates necessary ports and registers message callbacks.
111 virtual bool init() override;
112
113 //! \brief Factory method to create a new instance of this component
114 //! \param name The name for the new component
115 //! \param owner The local object that will own this component
116 //! \param simManager The simulation services manager
117 //! \param desc Optional component descriptor
118 //! \param parentRegistry Optional parent registry for reader/writer functionality
119 //! \return Pointer to the newly created component
120 //!
121 //! Static factory method used by the component creation system to instantiate
122 //! new instances of this component type.
123 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
124 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
125
126 //! \brief Callback for entity restoration events
127 //! \param msg The message containing restoration information
128 //! \param usrData User data pointer, typically pointing to the instance of this class
129 //!
130 //! Static callback function invoked when an entity is restored. This function forwards
131 //! the message to the instance's processSetRestore method to reinitialize state properties.
132 static void setRestoreCallback(DtSimMessage* msg, void* usrData);
133
134 //! \brief Callback for laser code change requests
135 //! \param msg The message containing the new laser code
136 //! \param usrData User data pointer, typically pointing to the instance of this class
137 //!
138 //! Static callback function invoked when a request to change the laser code is received.
139 //! This function forwards the message to the instance's processSetLaserCodeRequestMessage method.
140 static void setLaserCodeRequestCallback(DtSimMessage* msg, void* usrData);
141
142protected:
143 //! \brief Handles messages to start lasing
144 //! \param msg The message containing lasing start request
145 //! \return Message processing result indicating success or failure
146 //!
147 //! Processes StartLasing messages from the front-end, which activate
148 //! the laser designator. Sets the appropriate output ports to enable
149 //! the laser in the simulation.
151
152 //! \brief Handles messages to stop lasing
153 //! \param msg The message containing lasing stop request
154 //! \return Message processing result indicating success or failure
155 //!
156 //! Processes StopLasing messages from the front-end, which deactivate
157 //! the laser designator. Sets the appropriate output ports to disable
158 //! the laser in the simulation.
160
161 //! \brief Handles messages to update the lasing state
162 //! \param msg The message containing updated lasing information
163 //! \return Message processing result indicating success or failure
164 //!
165 //! Processes UpdateLasingState messages from the front-end, which update
166 //! the location being designated by the laser. Updates the appropriate output
167 //! ports with the new target information.
169
170 //! \brief Processes entity restoration messages
171 //! \param msg The message containing restoration information
172 //!
173 //! Reinitializes the state property "HasLaser" when a set restore operation
174 //! is executed. This ensures that the entity's laser capabilities are properly
175 //! restored after entity restoration, allowing the VR-Engage menu to correctly
176 //! display laser options.
177 virtual void processSetRestore(DtSimMessage* msg);
178
179 //! \brief Processes laser code change requests
180 //! \param msg The message containing the new laser code
181 //!
182 //! Sets the state property for laser code based on the message contents,
183 //! so the updated code can be reflected in the GUI. This allows users to
184 //! change laser codes through the user interface, ensuring that laser-guided
185 //! weapons are properly configured for the selected code.
186 virtual void processSetLaserCodeRequestMessage(DtSimMessage* msg);
187
188 //! \brief Creates input and output ports for the component
189 //! \return True if ports are successfully created, false otherwise
190 //!
191 //! Creates and initializes all the output ports needed by this component,
192 //! including ports for laser state (on/off), target location, and target object.
193 //! These ports connect to the actual laser controller component.
194 virtual bool createPorts() override;
195
196 //! \brief Retrieves the process state repository
197 //!
198 //! Gets the process state repository (PSR) for this component, storing
199 //! it in the myProcessState member variable for later access. The PSR
200 //! contains persistent state information for the controller.
202
203 //! \brief Pointer to the lasing process state repository
204 //!
205 //! Contains the persistent state information for the laser controller,
206 //! including the laser code and target information.
207 DtLasingPSR* myProcessState;
208
209 //! \brief Flag indicating whether the player is currently lasing
210 //!
211 //! When true, indicates that the player has activated the laser designator
212 //! and is currently designating a target.
214
215 //! \brief Flag indicating whether the player was lasing a target in the previous tick
216 //!
217 //! Used to track changes in lasing state between ticks, for determining
218 //! when state transitions occur.
220
221 //! \brief Output port for the laser on/off state
222 //!
223 //! Boolean output port that controls whether the laser is active.
224 //! When true, the laser is on and designating a target.
225 DtBooleanOutputPort* myLaserOnOutputPort;
226
227 //! \brief Output port for the laser target location
228 //!
229 //! Vector output port that specifies the 3D location being designated
230 //! by the laser when targeting a location rather than an object.
231 DtVectorOutputPort* myTargetLocationOutputPort;
232
233 //! \brief Output port for the laser target object
234 //!
235 //! String output port that specifies the unique identifier of an object
236 //! being designated by the laser when targeting an object rather than a location.
237 DtStringOutputPort* myTargetObjectOutputPort;
238};
239} // namespace makVre
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
DtVectorOutputPort * myTargetLocationOutputPort
Output port for the laser target location.
Definition vrePlayerLaserController.h:231
virtual makVre::DtVreMessageResult handleStartLasing(makVre::DtVreMessage *msg)
Handles messages to start lasing.
virtual void processSetRestore(DtSimMessage *msg)
Processes entity restoration messages.
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Factory method to create a new instance of this component.
static void setLaserCodeRequestCallback(DtSimMessage *msg, void *usrData)
Callback for laser code change requests.
virtual ~DtVrePlayerLaserController() override
Virtual destructor.
DtLasingPSR * myProcessState
Pointer to the lasing process state repository.
Definition vrePlayerLaserController.h:207
virtual void preFirstTickInit() override
Performs initialization before the first simulation tick.
virtual makVre::DtVreMessageResult handleStopLasing(makVre::DtVreMessage *msg)
Handles messages to stop lasing.
bool myLasingTargetLastTick
Flag indicating whether the player was lasing a target in the previous tick.
Definition vrePlayerLaserController.h:219
virtual const char * type() const override
Gets the type identifier for this component.
virtual bool init() override
Initializes the player laser controller.
const DtVrePlayerLaserController & operator=(const DtVrePlayerLaserController &orig)
Assignment operator (not implemented)
DtBooleanOutputPort * myLaserOnOutputPort
Output port for the laser on/off state.
Definition vrePlayerLaserController.h:225
virtual void tick() override
Updates the controller state each simulation frame.
DtVrePlayerLaserController(const DtVrePlayerLaserController &orig)
Copy constructor (not implemented)
static void setRestoreCallback(DtSimMessage *msg, void *usrData)
Callback for entity restoration events.
void getProcessSR()
Retrieves the process state repository.
virtual void processSetLaserCodeRequestMessage(DtSimMessage *msg)
Processes laser code change requests.
DtVrePlayerLaserController()
Default constructor (not implemented)
bool myPlayerIsLasing
Flag indicating whether the player is currently lasing.
Definition vrePlayerLaserController.h:213
virtual makVre::DtVreMessageResult handleUpdateLasingState(makVre::DtVreMessage *msg)
Handles messages to update the lasing state.
virtual bool createPorts() override
Creates input and output ports for the component.
DtStringOutputPort * myTargetObjectOutputPort
Output port for the laser target object.
Definition vrePlayerLaserController.h:237
DtVrePlayerLaserController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtVrePlayerLaserControllerType[]
Type identifier for the VRE player laser controller component.
Definition vrePlayerLaserController.h:37
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.
Base template class for VR-Engage simulation components.