VR-Engage  2.2
Loading...
Searching...
No Matches
vreGunActuator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreGunActuator.h
7//! \ingroup vreVrfmodel
8//! \brief Actuator that models firing a mounted gun
9//!
10//! This file defines the DtVreGunActuator class which provides a model of a
11//! mounted gun actuator. It handles firing events, ammunition management, and
12//! integrates with input controls for weapon operation.
13#pragma once
14
15#include "vreVrfmodel/export.h"
16
18
20
21#include <vrfobjcore/simObjectReference.h>
22
23class DtBooleanInputPort;
24class DtBooleanOutputPort;
25class DtInputPortGroup;
26
27//! \brief Type identifier for the VRE gun actuator component
28const char DtVreGunActuatorType[] = "vre-gun-actuator";
29
30//! \brief Timer type for gun detonation events
31const unsigned int DtVreGunDetonationTimerType = 500;
32
33namespace makVrfEvents
34{
35class DtFireEvent;
36class DtDetonationEvent;
37} // namespace makVrfEvents
38
39//! \brief Actuator that models firing a mounted gun
40//!
41//! DtVreGunActuator provides a model of a mounted gun, handling firing events,
42//! ammunition management, and weapon operation through input controls. This actuator
43//! manages the firing logic, ammunition resources, and targeting for guns mounted on
44//! entities such as vehicles or fixed emplacements.
45//!
46//! Uses Descriptor Type: DtVreGunActuatorDescriptor
47
48namespace makVre
49{
51
52class VREVRFMODEL_DLL DtVreGunActuator : public DtActuatorComponent
53{
54protected:
55 //! \brief Default constructor (not implemented)
56 //!
57 //! Default constructor is protected and not implemented to prevent
58 //! creation of instances without proper initialization.
60
61 //! \brief Copy constructor (not implemented)
62 //!
63 //! Copy constructor is protected and not implemented to prevent
64 //! copy construction.
66
67 //! \brief Assignment operator (not implemented)
68 //! \return Reference to this object
69 //!
70 //! Assignment operator is protected and not implemented to prevent assignment.
72
73public:
74 //! \brief Constructor
75 //! \param name The name of this component
76 //! \param owner The local object that owns this component
77 //! \param simManager The simulation services manager
78 //! \param desc Component descriptor with configuration parameters
79 //! \param parentRegistry Optional parent registry for reader/writer functionality
80 //!
81 //! Creates a new gun actuator component with the specified parameters.
82 DtVreGunActuator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
83 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
84
85
86 //! \brief Virtual destructor
87 //!
88 //! Cleans up resources used by the gun actuator component, including
89 //! any pending detonation timers.
90 virtual ~DtVreGunActuator() override;
91
92 //! \brief Initializes the gun actuator
93 //! \return True if initialization is successful, false otherwise
94 //!
95 //! Performs initial setup of the gun actuator, including port connections
96 //! and state initialization. Called during component initialization.
97 virtual bool init() override;
98
99 //! \brief Gets the type identifier for this component
100 //! \return String identifying the component type (DtVreGunActuatorType)
101 //!
102 //! Implements the DtSimComponent::type() method to return the
103 //! type identifier for this component.
104 virtual const char* type() const override;
105
106 //! \brief Updates the actuator state each simulation frame
107 //!
108 //! Processes input controls, manages firing state, and handles ammunition
109 //! consumption during each simulation frame. This is the main update method
110 //! called every simulation tick.
111 virtual void tick() override;
112
113 //! \brief Performs initialization before the first simulation tick
114 //!
115 //! Sets up initial states and configurations before the simulation begins.
116 //! This initialization is performed once before the first tick of the simulation.
117 virtual void preFirstTickInit() override;
118
119
120 //! \brief Factory method to create a new instance of this component
121 //! \param name The name for the new component
122 //! \param owner The local object that will own this component
123 //! \param simManager The simulation services manager
124 //! \param desc Optional component descriptor
125 //! \param parentRegistry Optional parent registry for reader/writer functionality
126 //! \return Pointer to the newly created component
127 //!
128 //! Static factory method used by the component creation system to instantiate
129 //! new instances of this component type.
130 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
131 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
132
133protected:
134 //! \brief Creates the port groups for weapon control
135 //! \return True if port groups are successfully created, false otherwise
136 //!
137 //! Overridden to create the weapon control input port group. This method creates
138 //! the port group structure needed for handling weapon control inputs.
139 virtual bool createPortGroups() override;
140
141 //! \brief Creates the input and output ports for the actuator
142 //! \return True if ports are successfully created, false otherwise
143 //!
144 //! Overridden to create local ports for weapon control inputs and outputs,
145 //! such as fire, next weapon, previous weapon, and firing state ports.
146 virtual bool createPorts() override;
147
148 //! \brief Creates the process state repository for the actuator
149 //! \return True if the PSR is successfully created, false otherwise
150 //!
151 //! Creates the myProcessState data member and adds it to the process state
152 //! repository manager. Uses the name and type specified in the component
153 //! descriptor (if they exist) or appropriate defaults if not specified.
154 //! This PSR is used to maintain state across simulation frames and saves.
155 virtual bool createPSR();
156
157 //! \brief Structure containing the results of a firing action
159 {
160 DtDetonationResult result; //!< Result of the detonation calculation
161 double rangeToTarget; //!< Range to the target in meters
162 DtSimObjectReference targetEntity; //!< Reference to the targeted entity, if any
163 };
164
165 //! \brief Calculates the result of firing the weapon
166 //! \param shooterPosition The geocentric position of the shooter
167 //! \param shooterOrienation The orientation of the shooter
168 //! \param fireResult Output parameter that will contain the fire result
169 //!
170 //! Calculates the result of firing the weapon from the given position and orientation.
171 //! This includes determining if a target was hit, the range to the target, and
172 //! the detonation result. The results are stored in the provided fireResult structure.
173 virtual void getFireResult(
174 const DtVector& shooterPosition, const DtTaitBryan shooterOrienation, DtFireResult& fireResult);
175
176 //! \brief Creates a fire event for interaction processing
177 //! \param firingPosition The geocentric position of the firing point
178 //! \param firingOrientation The orientation of the firing point
179 //! \return Pointer to the created fire event, or nullptr if creation failed
180 //!
181 //! Creates and initializes a fire event based on the specified position and orientation.
182 //! This event represents the firing of the weapon and is used in the interaction system.
183 virtual makVrfEvents::DtFireEvent* createFireInteraction(
184 const DtVector& firingPosition, const DtTaitBryan firingOrientation);
185
186 //! \brief Creates a detonation event for interaction processing
187 //! \param firingPosition The geocentric position of the firing point
188 //! \param firingOrientation The orientation of the firing point
189 //! \param fireResult The results of the firing calculation
190 //! \param detTime Output parameter that will contain the detonation time
191 //! \return Pointer to the created detonation event, or nullptr if creation failed
192 //!
193 //! Creates and initializes a detonation event based on the specified position,
194 //! orientation, and fire result. This event represents the detonation of a projectile
195 //! and is used in the interaction system. The detonation time is calculated and
196 //! returned in the detTime parameter.
197 virtual makVrfEvents::DtDetonationEvent* createDetonationInteraction(const DtVector& firingPosition,
198 const DtTaitBryan firingOrientation, const DtFireResult& fireResult, DtReal& detTime);
199
200 //! \brief Decrements the ammunition resource count
201 //!
202 //! Decrements the available ammunition count for the current munition type.
203 //! This is called after firing the weapon to reflect ammunition consumption.
204 virtual void decrementResource();
205
206 //! \brief Schedules a detonation event to occur at a specific time
207 //! \param detInter Pointer to the detonation event to schedule
208 //! \param detTime The simulation time at which the detonation should occur
209 //!
210 //! Schedules a detonation event to occur at the specified simulation time.
211 //! This creates a timer that will trigger the detonation callback when the time is reached.
212 virtual void scheduleDetonation(makVrfEvents::DtDetonationEvent* detInter, DtTime detTime);
213
214 //! \brief Calculates the current muzzle position in world coordinates
215 //! \return Vector containing the muzzle position coordinates
216 //!
217 //! Calculates the current world position of the weapon muzzle based on
218 //! the entity position, orientation, and configured muzzle offset.
220
221 //! \brief Sets the current munition type for the weapon
222 //! \param munition Index of the munition type to set as current
223 //!
224 //! Updates the current munition type used by the weapon, which affects
225 //! the ammunition type consumed and the firing characteristics.
226 void setCurrentMunition(int munition);
227
228 //! \brief Finds a specific resource by type
229 //! \param resourceType The entity type of the resource to find
230 //! \return Pointer to the resource if found, nullptr otherwise
231 //!
232 //! Searches for and returns a pointer to a resource of the specified type.
233 //! This is used to access ammunition resources for the weapon.
234 DtSimResource* findResource(DtEntityType resourceType);
235
236 //! \brief Callback function for detonation timers
237 //! \param timer Pointer to the timer that triggered this callback
238 //!
239 //! Static callback function called when a detonation timer expires.
240 //! This processes the detonation event associated with the timer.
241 static void detonationCallback(DtTimer* timer);
242
243 //! \brief Port group for weapon control inputs
244 DtInputPortGroup* myWeaponPortGroup;
245
246 //! \brief Input port for fire command
247 DtBooleanInputPort* myFirePort;
248
249 //! \brief Input port for next weapon selection
250 DtBooleanInputPort* myNextWeaponPort;
251
252 //! \brief Input port for previous weapon selection
253 DtBooleanInputPort* myPreviousWeaponPort;
254
255 //! \brief Output port for firing state
256 DtBooleanOutputPort* myFiringPort;
257
258 //! \brief Flag indicating whether the weapon is currently firing
260
261 //! \brief Index of the currently selected munition type
263
264 //! \brief Part ID of the articulated part the weapon is attached to
266
267 //! \brief Muzzle velocity of fired projectiles in meters per second
269
270 //! \brief Number of rounds per magazine for ammunition management
272
273 //! \brief Rate of fire in rounds per minute
275
276 //! \brief Offset vector from entity origin to muzzle position
278
279 //! \brief Time required to load the weapon in seconds
281
282 //! \brief Time required to unload the weapon in seconds
284
285 //! \brief Maximum effective range of the weapon in meters
286 double myRange;
287
288 //! \brief Name of the range parameter for configuration
289 std::string myRangeName;
290
291 //! \brief Number of rounds consumed per detonation event
293
294 //! \brief List of available munition types for this weapon
295 std::vector<DtEntityType> myMunitionList;
296
297 //! \brief List of active detonation timers
299
300 //! \brief Flag indicating whether a missing articulation warning has been reported
302
303 //! \brief Process state repository for preserving state data
304 //!
305 //! Container for state data associated with this component. This state
306 //! is saved and restored as part of a scenario (or checkpoint).
307 DtVrfBalGunPSR* myProcessState;
308
309 //! \brief Pointer to the gun actuator descriptor with configuration parameters
311
312 //! \brief Reference to the current target entity
313 //!
314 //! Set by createFireInteraction and used by createDetonationInteraction.
315 DtSimObjectReference myCurrentTarget;
316
317 //! \brief Current event ID for tracking interaction events
318 //!
319 //! Set by createFireInteraction and used by createDetonationInteraction.
321
322 //! \brief Current range to target in meters
323 //!
324 //! Set by createFireInteraction and used by createDetonationInteraction.
326};
327
328} // namespace makVre
Extends the DtBallisticGun class with joystick control capabilities.
Gun actuator descriptor for VREngage weapon systems.
Definition vreGunActuatorDescriptor.h:33
std::string myRangeName
Name of the range parameter for configuration.
Definition vreGunActuator.h:289
double myUnloadTime
Time required to unload the weapon in seconds.
Definition vreGunActuator.h:283
virtual bool init() override
Initializes the gun actuator.
int myRoundsPerDetonation
Number of rounds consumed per detonation event.
Definition vreGunActuator.h:292
int myRoundsPerMagazine
Number of rounds per magazine for ammunition management.
Definition vreGunActuator.h:271
double myRange
Maximum effective range of the weapon in meters.
Definition vreGunActuator.h:286
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.
virtual void preFirstTickInit() override
Performs initialization before the first simulation tick.
DtVreGunActuator(const DtVreGunActuator &orig)
Copy constructor (not implemented)
int myCurrentMunition
Index of the currently selected munition type.
Definition vreGunActuator.h:262
virtual makVrfEvents::DtDetonationEvent * createDetonationInteraction(const DtVector &firingPosition, const DtTaitBryan firingOrientation, const DtFireResult &fireResult, DtReal &detTime)
Creates a detonation event for interaction processing.
DtString myCurrentEventId
Current event ID for tracking interaction events.
Definition vreGunActuator.h:320
DtInputPortGroup * myWeaponPortGroup
Port group for weapon control inputs.
Definition vreGunActuator.h:244
virtual void scheduleDetonation(makVrfEvents::DtDetonationEvent *detInter, DtTime detTime)
Schedules a detonation event to occur at a specific time.
virtual void tick() override
Updates the actuator state each simulation frame.
DtVrfBalGunPSR * myProcessState
Process state repository for preserving state data.
Definition vreGunActuator.h:307
double myMuzzleSpeed
Muzzle velocity of fired projectiles in meters per second.
Definition vreGunActuator.h:268
DtVreGunActuatorDescriptor * myGunDescriptor
Pointer to the gun actuator descriptor with configuration parameters.
Definition vreGunActuator.h:310
DtBooleanInputPort * myPreviousWeaponPort
Input port for previous weapon selection.
Definition vreGunActuator.h:253
virtual const char * type() const override
Gets the type identifier for this component.
DtSimObjectReference myCurrentTarget
Reference to the current target entity.
Definition vreGunActuator.h:315
DtBooleanInputPort * myNextWeaponPort
Input port for next weapon selection.
Definition vreGunActuator.h:250
DtBooleanInputPort * myFirePort
Input port for fire command.
Definition vreGunActuator.h:247
const DtVreGunActuator & operator=(const DtVreGunActuator &orig)
Assignment operator (not implemented)
bool myReportedNoArticulation
Flag indicating whether a missing articulation warning has been reported.
Definition vreGunActuator.h:301
virtual ~DtVreGunActuator() override
Virtual destructor.
void setCurrentMunition(int munition)
Sets the current munition type for the weapon.
DtVreGunActuator()
Default constructor (not implemented)
DtBooleanOutputPort * myFiringPort
Output port for firing state.
Definition vreGunActuator.h:256
virtual bool createPSR()
Creates the process state repository for the actuator.
static void detonationCallback(DtTimer *timer)
Callback function for detonation timers.
virtual bool createPortGroups() override
Creates the port groups for weapon control.
int myRoundsPerMinute
Rate of fire in rounds per minute.
Definition vreGunActuator.h:274
DtVreGunActuator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual void getFireResult(const DtVector &shooterPosition, const DtTaitBryan shooterOrienation, DtFireResult &fireResult)
Calculates the result of firing the weapon.
DtList myTimerList
List of active detonation timers.
Definition vreGunActuator.h:298
int myAttachedPart
Part ID of the articulated part the weapon is attached to.
Definition vreGunActuator.h:265
DtReal myCurrentRange
Current range to target in meters.
Definition vreGunActuator.h:325
DtSimResource * findResource(DtEntityType resourceType)
Finds a specific resource by type.
virtual void decrementResource()
Decrements the ammunition resource count.
DtVector calculateMuzzlePosition()
Calculates the current muzzle position in world coordinates.
std::vector< DtEntityType > myMunitionList
List of available munition types for this weapon.
Definition vreGunActuator.h:295
virtual bool createPorts() override
Creates the input and output ports for the actuator.
double myLoadTime
Time required to load the weapon in seconds.
Definition vreGunActuator.h:280
DtVector myMuzzleOffset
Offset vector from entity origin to muzzle position.
Definition vreGunActuator.h:277
bool myIsFiring
Flag indicating whether the weapon is currently firing.
Definition vreGunActuator.h:259
virtual makVrfEvents::DtFireEvent * createFireInteraction(const DtVector &firingPosition, const DtTaitBryan firingOrientation)
Creates a fire event for interaction processing.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition vrfRemoteControlConnector.h:87
Structure containing the results of a firing action.
Definition vreGunActuator.h:159
DtSimObjectReference targetEntity
Reference to the targeted entity, if any.
Definition vreGunActuator.h:162
DtDetonationResult result
Result of the detonation calculation.
Definition vreGunActuator.h:160
double rangeToTarget
Range to the target in meters.
Definition vreGunActuator.h:161
const char DtVreGunActuatorType[]
Type identifier for the VRE gun actuator component.
Definition vreGunActuator.h:28
const unsigned int DtVreGunDetonationTimerType
Timer type for gun detonation events.
Definition vreGunActuator.h:31
Defines the base class for all VREngage messages.