VR-Engage  2.2
Loading...
Searching...
No Matches
customProjectile.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file customProjectile.h
7//! \brief Custom projectile class demonstrating VR-Forces projectile extension pattern
8//!
9//! DtCustomProjectile extends the standard DtProjectile class to add custom behavior
10//! and an internal time-in-flight state. This example demonstrates the complete
11//! pattern for creating custom munition types in VR-Forces, including update logic
12//! and factory integration.
13//!
14//! Key Patterns Demonstrated:
15//! - Extending VR-Forces projectile base class
16//! - Tracking additional runtime state in a custom projectile
17//! - Overriding update() for custom physics or behavior
18//! - Factory creator pattern for projectile instantiation
19
20#pragma once
22
23//! Type identifier string for custom projectile class
24//! Used by factory system to create instances and for MTL file serialization
25constexpr char DtCustomProjectileType[] = "DtCustomProjectile";
26
27//! \brief Custom projectile class with additional time-in-flight tracking
28//!
29//! PATTERN: Extending VR-Forces Projectile Classes
30//! To create custom munition types in VR-Forces:
31//! 1. Derive from makVre::DtProjectile (or DtBallistic, DtGuided for specific types)
32//! 2. Add any additional state needed for your behavior (for example, accumulated
33//! time in flight)
34//! 3. Override update() to implement custom physics or behavior
35//! 4. Implement clone(), operator==, type(), and static creator() methods
36//! 5. Register with projectile factory in plugin initialization
37//!
38//! This Example:
39//! Adds a time-in-flight value that accumulates the total flight time at runtime.
40//! The value is not configurable in data files and is not serialized; it exists
41//! only while the projectile is active in the simulation. This simple example can
42//! be extended with:
43//! - Custom guidance algorithms (target tracking, waypoint following)
44//! - Environmental effects (wind, gravity variations)
45//! - Special detonation logic (proximity fuze, timed fuze)
46//! - Visual effects (smoke trails, exhaust plumes)
47//! - Performance characteristics (fuel consumption, thrust curves)
48//!
49//! REUSABLE: This class structure is directly reusable for any custom projectile type.
50//! Replace myTimeInFlight with your custom parameters and update() logic with your
51//! custom behavior.
52//!
54{
55public:
56 //! \brief Construct projectile with string name
57 //!
58 //! PATTERN: Projectile Construction
59 //! Projectiles are constructed with a name (used for identification and debugging)
60 //! and an optional parent registry (for hierarchical parameter organization used
61 //! by the base class).
62 //!
63 //! The constructor must:
64 //! 1. Initialize the base class (DtProjectile)
65 //! 2. Initialize any custom state
66 //!
67 //! \param name Unique identifier for this projectile instance
68 //! \param parentRegistry Optional parent registry for hierarchical organization
69 //!
70 DtCustomProjectile(const DtString& name, DtReaderWriterRegistry* const parentRegistry = nullptr);
71
72 //! \brief Construct projectile with symbol string name
73 //! \param name Symbol string identifier for this projectile instance
74 //! \param parentRegistry Optional parent registry for hierarchical organization
75 DtCustomProjectile(const DtSymbolString& name, DtReaderWriterRegistry* const parentRegistry = nullptr);
76
77 //! \brief Copy constructor for projectile cloning
78 //!
79 //! PATTERN: Projectile Copying
80 //! Projectiles must be copyable for cloning (for example, when creating multiple
81 //! rounds from a template). The copy constructor must:
82 //! 1. Copy base class state
83 //! 2. Copy all custom state
84 //!
85 //! \param orig Source projectile to copy
86 //! \param parentRegistry Optional parent registry for the copy
87 //!
88 DtCustomProjectile(const DtCustomProjectile& orig, DtReaderWriterRegistry* const parentRegistry = nullptr);
89
90 //! \brief Destructor - base class handles cleanup
91 virtual ~DtCustomProjectile() override {}
92
93 //! \brief Assignment operator for projectile state copying
94 //!
95 //! Must copy both base class state and all custom parameters.
96 //!
97 //! \param orig Source projectile to copy from
98 //! \return Reference to this projectile for assignment chaining
99 //!
101
102 //! \brief Create a deep copy of this projectile
103 //!
104 //! Required by VR-Forces framework for projectile instantiation from templates.
105 //! When multiple rounds of the same munition type are fired, the framework clones
106 //! a template projectile rather than re-reading configuration files.
107 //!
108 //! \return New projectile instance with copied state
109 //!
110 virtual makVre::DtProjectile* clone() const override;
111
112 //! \brief Equality comparison for projectile state
113 //! \param rhs Projectile to compare against
114 //! \return true if all parameters match, false otherwise
115 bool operator==(const DtCustomProjectile&) const;
116
117 //! \brief Inequality comparison for projectile state
118 //! \param rhs Projectile to compare against
119 //! \return true if any parameters differ, false if all match
120 bool operator!=(const DtCustomProjectile& rhs) const { return !(*this == rhs); };
121
122 //! \brief Return the class type identifier string
123 //!
124 //! PATTERN: Projectile Type Identification
125 //! The type() method returns a unique string identifying this projectile class.
126 //! This string is used by:
127 //! - Factory system to create correct class instances
128 //! - MTL file serialization to identify projectile class on load
129 //! - Runtime type identification (alternative to dynamic_cast)
130 //!
131 //! The type string must match the string used in factory registration.
132 //!
133 //! \return Type identifier string (DtCustomProjectileType constant)
134 //!
135 virtual DtString type() const override;
136
137 //! \brief Update projectile state for one simulation frame
138 //!
139 //! PATTERN: Custom Projectile Update Logic
140 //! The update() method is called once per simulation frame to advance projectile
141 //! physics and behavior. Custom projectiles override this to implement:
142 //! - Custom guidance algorithms (updating velocity/orientation)
143 //! - Time-based effects (fuel depletion, stage separation)
144 //! - Environmental interactions (wind drift, drag calculations)
145 //! - Custom detonation conditions (proximity detection, time fuzes)
146 //!
147 //! This Example:
148 //! Increments the time-in-flight parameter by deltaTime, then calls the base
149 //! class update() to perform standard projectile physics (position integration,
150 //! collision detection, detonation logic).
151 //!
152 //! REUSABLE: This override pattern applies to any custom update logic. Always
153 //! call the base class update() unless completely replacing default physics.
154 //!
155 //! \param deltaTime Time elapsed since last update in seconds
156 //! \return Detonation result indicating if projectile should be removed
157 //!
158 virtual makVre::DtProjectileDetonationResult update(double deltaTime) override;
159
160 //! \brief Static factory creator method
161 //!
162 //! PATTERN: Projectile Factory Pattern
163 //! VR-Forces uses factory methods to instantiate projectiles by type name.
164 //! The creator() method must be static and return a new instance of this class.
165 //!
166 //! This method is registered with the projectile factory during plugin initialization:
167 //! DtProjectileFactory::instance().registerProjectile(
168 //! DtCustomProjectileType, &DtCustomProjectile::creator);
169 //!
170 //! When MTL files reference this projectile type, the factory uses this creator
171 //! to instantiate objects.
172 //!
173 //! REUSABLE: This exact signature is required for all custom projectiles.
174 //!
175 //! \param name Name for the new projectile instance
176 //! \param parentRegistry Optional parent registry for the new instance
177 //! \return Newly created projectile instance
178 //!
179 static makVre::DtProjectile* creator(const DtString& name, DtReaderWriterRegistry* const parentRegistry = nullptr);
180
181protected:
182 //! Default constructor - not implemented (projectiles require names)
184
185protected:
186 //! Custom time-in-flight parameter
187 //!
188 //! The time-in-flight value is internal simulation state. It is not configured
189 //! from data files and is not serialized; it is reset to zero when the projectile
190 //! is constructed and accumulates while the projectile is active.
192};
bool operator!=(const DtCustomProjectile &rhs) const
Inequality comparison for projectile state.
Definition customProjectile.h:120
double myTimeInFlight
Custom time-in-flight parameter.
Definition customProjectile.h:191
virtual DtString type() const override
Return the class type identifier string.
virtual makVre::DtProjectile * clone() const override
Create a deep copy of this projectile.
DtCustomProjectile(const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
Construct projectile with string name.
DtCustomProjectile(const DtCustomProjectile &orig, DtReaderWriterRegistry *const parentRegistry=nullptr)
Copy constructor for projectile cloning.
DtCustomProjectile & operator=(const DtCustomProjectile &orig)
Assignment operator for projectile state copying.
bool operator==(const DtCustomProjectile &) const
Equality comparison for projectile state.
DtCustomProjectile(const DtSymbolString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
Construct projectile with symbol string name.
virtual ~DtCustomProjectile() override
Destructor - base class handles cleanup.
Definition customProjectile.h:91
DtCustomProjectile()
Default constructor - not implemented (projectiles require names)
virtual makVre::DtProjectileDetonationResult update(double deltaTime) override
Update projectile state for one simulation frame.
static makVre::DtProjectile * creator(const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
Static factory creator method.
Class representing the result of a projectile detonation.
Definition projectileDetonationResult.h:33
Class representing ballistic projectiles in simulations.
Definition projectile.h:42
constexpr char DtCustomProjectileType[]
Type identifier string for custom projectile class Used by factory system to create instances and for...
Definition customProjectile.h:25
Projectile class for VREngage.