VR-Engage  2.2
Loading...
Searching...
No Matches
vreVrfBalGunPSR.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreVrfBalGunPSR.h
7//! \ingroup vreVrfobjcore
8//! \brief Ballistic gun process state repository for VREngage
9//!
10//! This file defines the DtVreVrfBalGunPSR class, which extends the basic ballistic gun PSR
11//! to provide VREngage-specific functionality for ballistic gun weapons. It adds support for
12//! managing projectiles in flight, including tracking and updating their positions and handling
13//! detonation events.
14
15#pragma once
19
20#include <vrfobjcore/vrfTurretedBalGunPSR.h>
21
22namespace makVre
23{
25
26//! \brief Type identifier string for the VREngage ballistic gun PSR
27const char DtVreVrfBalGunPSRType[] = "vre-vrf-bal-gun-psr";
28
29//! \brief Extended ballistic gun process state repository for VREngage
30//!
31//! This class extends the basic turreted ballistic gun PSR to provide VREngage-specific
32//! functionality for ballistic gun weapons. It adds support for managing projectiles
33//! in flight, including tracking and updating their positions and handling detonation
34//! events. This is used to implement more realistic ballistic behavior in VREngage.
35class VREVRFOBJCORE_DLL DtVreVrfBalGunPSR : public DtVrfTurretedBalGunPSR
36{
37public:
38 //! \brief Constructor with VRF object and optional name
39 //! \param vrfObject Pointer to the local object this PSR is associated with
40 //! \param rwName Optional reader/writer name
41 //! \param parentRegistry Optional parent registry for reader/writer functionality
42 //!
43 //! Creates a new ballistic gun PSR for the specified VRF object.
44 DtVreVrfBalGunPSR(DtLocalObject* vrfObject, const DtString& rwName = DtString::nullString(),
45 DtReaderWriterRegistry* parentRegistry = 0);
46
47 //! \brief Copy constructor
48 //! \param orig The source PSR to copy from
49 //! \param rwName Optional reader/writer name
50 //! \param parentRegistry Optional parent registry for reader/writer functionality
51 //!
52 //! Creates a new ballistic gun PSR as a copy of the provided original.
53 DtVreVrfBalGunPSR(const DtVreVrfBalGunPSR& orig, const DtString& rwName = DtString::nullString(),
54 DtReaderWriterRegistry* parentRegistry = 0);
55
56 //! \brief Virtual destructor
57 //!
58 //! Cleans up resources used by the PSR.
59 virtual ~DtVreVrfBalGunPSR() override {}
60
61 //! \brief Assignment operator
62 //! \param orig The source PSR to copy from
63 //! \return Reference to this PSR after assignment
64 //!
65 //! Assigns the contents of the provided PSR to this one.
67
68 //! \brief Creates a clone of this PSR
69 //! \param rwName Optional reader/writer name for the clone
70 //! \param parentRegistry Optional parent registry for reader/writer functionality
71 //! \return Pointer to a new PSR that is a clone of this one
72 //!
73 //! Creates a new ballistic gun PSR as a deep copy of this one.
74 virtual DtVrfProcessStateRepository* clone(const DtString& rwName = DtString::nullString(),
75 DtReaderWriterRegistry* parentRegistry = 0) const override;
76
77 //! \brief Gets the type identifier for this PSR
78 //! \return String identifying this PSR type
79 //!
80 //! Returns a unique type identifier string for this PSR type.
81 //! Will return DtVreVrfBalGunPSRType.
82 virtual DtString type() const override;
83
84 //! \brief Sets the physical world pointer
85 //! \param physicalWorld Pointer to the physical world
86 //!
87 //! Sets a pointer to the physical world, caching it so it can be passed on to
88 //! any DtProjectile objects the PSR is maintaining. This is needed when reading
89 //! in the contents of the projectile list from the order of battle, and for
90 //! projectile collision detection with terrain.
91 virtual void setPhysicalWorld(DtPhysicalWorld* physicalWorld);
92
93 //! \brief Sets the firing entity
94 //! \param firingEntity Pointer to the entity that is firing the weapon
95 //!
96 //! Sets the identity of the firing entity, caching it so it can be passed on to
97 //! any DtProjectile objects the PSR is maintaining. This is needed when reading
98 //! in the contents of the projectile list from the order of battle, and for
99 //! tracking which entity fired each projectile.
100 virtual void setFiringEntity(DtSimObject* firingEntity);
101
102 //! \brief Adds a projectile to the tracking list
103 //! \param projectile The projectile to add
104 //!
105 //! Adds a new projectile to the set of projectiles being tracked by this PSR.
106 //! The projectile's position will be updated during calls to updateProjectiles().
107 //! A copy of the projectile is made and stored in the internal projectile list.
108 virtual void addProjectile(const DtProjectile& projectile);
109
110 //! \brief Removes all tracked projectiles
111 //!
112 //! Removes and destroys all projectiles currently being tracked by this PSR.
113 //! This is typically called when the weapon is destroyed or when clearing
114 //! the simulation state.
115 virtual void removeAllProjectiles();
116
117 //! \brief Updates all tracked projectiles
118 //! \param deltaTime Time elapsed since the last update in seconds
119 //! \return List of detonation results for projectiles that detonated during this update
120 //!
121 //! Iterates over the list of active projectiles, calling their update() function to
122 //! update their positions based on physics. For any projectiles that detonate (hit
123 //! something or reach maximum range), they are removed from the list and information
124 //! about their detonation is returned.
125 virtual std::list<DtProjectileDetonationResult> updateProjectiles(double deltaTime);
126
127 //! \brief Processes an MTL stream to initialize this PSR
128 //! \param args Input stream from an MTL file
129 //! \param searchPaths Search paths for resolving references
130 //! \param variableBindings Variable bindings for resolving references
131 //!
132 //! Overrides the base class getSelf method to handle reading the projectile list
133 //! and other VREngage-specific ballistic gun state from an MTL stream.
134 virtual void getSelf(DtlObjPtr args,
135 const DtReaderWriter::SearchPaths& searchPaths,
136 const DtVariableBindingsList& variableBindings) override;
137
138 //! \brief Factory function to create a new instance of this PSR
139 //! \param rwName The reader/writer name for the new instance
140 //! \param vrfObject Pointer to the local object this PSR will be associated with
141 //! \param parentRegistry Parent registry for reader/writer functionality
142 //! \return Pointer to a newly created PSR instance
143 //!
144 //! Static factory function used by the PSR creation system to instantiate
145 //! new instances of this PSR type.
146 static DtVrfProcessStateRepository* creator(
147 const DtString& rwName, DtLocalObject* vrfObject, DtReaderWriterRegistry* parentRegistry);
148
149protected:
150 //! \brief List of tracked projectiles
151 //!
152 //! Stores the list of projectiles whose positions are updated every frame.
153 //! This list is managed by addProjectile(), removeAllProjectiles(), and updateProjectiles().
155
156 //! \brief Pointer to the physical world
157 //!
158 //! Stores a pointer to the physical world for terrain queries and gravity direction.
159 //! This is passed to projectiles so they can detect collisions with terrain.
160 DtPhysicalWorld* myPhysicalWorld;
161
162 //! \brief Pointer to the firing entity
163 //!
164 //! Stores a pointer to the entity that is firing the weapon.
165 //! This is passed to projectiles so they know which entity fired them.
166 DtSimObject* myFiringEntity;
167};
168} // namespace makVre
Class representing ballistic projectiles in simulations.
Definition projectile.h:42
Class representing a list of projectiles.
Definition projectileList.h:38
Extended ballistic gun process state repository for VREngage.
Definition vreVrfBalGunPSR.h:36
DtSimObject * myFiringEntity
Pointer to the firing entity.
Definition vreVrfBalGunPSR.h:166
virtual void getSelf(DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings) override
Processes an MTL stream to initialize this PSR.
DtVreVrfBalGunPSR(const DtVreVrfBalGunPSR &orig, const DtString &rwName=DtString::nullString(), DtReaderWriterRegistry *parentRegistry=0)
Copy constructor.
DtProjectileList myProjectileList
List of tracked projectiles.
Definition vreVrfBalGunPSR.h:154
DtPhysicalWorld * myPhysicalWorld
Pointer to the physical world.
Definition vreVrfBalGunPSR.h:160
DtVreVrfBalGunPSR & operator=(const DtVreVrfBalGunPSR &orig)
Assignment operator.
virtual void setPhysicalWorld(DtPhysicalWorld *physicalWorld)
Sets the physical world pointer.
DtVreVrfBalGunPSR(DtLocalObject *vrfObject, const DtString &rwName=DtString::nullString(), DtReaderWriterRegistry *parentRegistry=0)
Constructor with VRF object and optional name.
virtual void setFiringEntity(DtSimObject *firingEntity)
Sets the firing entity.
virtual ~DtVreVrfBalGunPSR() override
Virtual destructor.
Definition vreVrfBalGunPSR.h:59
static DtVrfProcessStateRepository * creator(const DtString &rwName, DtLocalObject *vrfObject, DtReaderWriterRegistry *parentRegistry)
Factory function to create a new instance of this PSR.
virtual DtString type() const override
Gets the type identifier for this PSR.
virtual DtVrfProcessStateRepository * clone(const DtString &rwName=DtString::nullString(), DtReaderWriterRegistry *parentRegistry=0) const override
Creates a clone of this PSR.
virtual std::list< DtProjectileDetonationResult > updateProjectiles(double deltaTime)
Updates all tracked projectiles.
virtual void addProjectile(const DtProjectile &projectile)
Adds a projectile to the tracking list.
virtual void removeAllProjectiles()
Removes all tracked projectiles.
Export macros for the VREngage Object Core library.
#define VREVRFOBJCORE_DLL
Platform-specific DLL export/import declaration.
Definition export.h:27
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtVreVrfBalGunPSRType[]
Type identifier string for the VREngage ballistic gun PSR.
Definition vreVrfBalGunPSR.h:27
Projectile detonation result class for VREngage.
Projectile list class for VREngage.