|
VR-Engage
2.2
|
PATTERN: Extending VR-Forces Projectile Classes To create custom munition types in VR-Forces:
This Example: Adds a time-in-flight value that accumulates the total flight time at runtime. The value is not configurable in data files and is not serialized; it exists only while the projectile is active in the simulation. This simple example can be extended with:
REUSABLE: This class structure is directly reusable for any custom projectile type. Replace myTimeInFlight with your custom parameters and update() logic with your custom behavior.
#include <customProjectile.h>
Public Member Functions | |
| DtCustomProjectile (const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr) | |
| DtCustomProjectile (const DtSymbolString &name, DtReaderWriterRegistry *const parentRegistry=nullptr) | |
| DtCustomProjectile (const DtCustomProjectile &orig, DtReaderWriterRegistry *const parentRegistry=nullptr) | |
| virtual | ~DtCustomProjectile () override |
| DtCustomProjectile & | operator= (const DtCustomProjectile &orig) |
| virtual makVre::DtProjectile * | clone () const override |
| bool | operator== (const DtCustomProjectile &) const |
| bool | operator!= (const DtCustomProjectile &rhs) const |
| virtual DtString | type () const override |
| virtual makVre::DtProjectileDetonationResult | update (double deltaTime) override |
Public Member Functions inherited from makVre::DtProjectile | |
| DtProjectile (const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL) | |
| DtProjectile (const DtSymbolString &name, DtReaderWriterRegistry *const parentRegistry=NULL) | |
| DtProjectile (const DtProjectile &orig, DtReaderWriterRegistry *const parentRegistry=NULL) | |
| virtual | ~DtProjectile () override |
| DtProjectile & | operator= (const DtProjectile &orig) |
| bool | operator== (const DtProjectile &) const |
| bool | operator!= (const DtProjectile &rhs) |
| virtual void | setMunitionType (const DtEntityType &munitionType) |
| virtual void | setCrossSection (double crossSection) |
| virtual void | setDragCoefficient (double dragCoefficient) |
| virtual void | setMass (double mass) |
| virtual void | setMaxRange (double maxRange) |
| virtual void | setPosition (DtVector position) |
| virtual void | setVelocity (DtVector velocity) |
| virtual void | setDistanceTraveled (double distanceTraveled) |
| virtual void | setFiringEntity (DtSimObject *firingEntity) |
| virtual void | setPhysicalWorld (DtPhysicalWorld *physicalWorld) |
| virtual const DtEntityType & | munitionType () |
| virtual DtVector | velocity () |
| virtual void | putData (std::string &fp, int indentLevel=0) override |
| virtual DtlObjPtr | getData (DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings) override |
Static Public Member Functions | |
| static makVre::DtProjectile * | creator (const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr) |
Static Public Member Functions inherited from makVre::DtProjectile | |
| static void | addProjectileCreatorFcn (const std::string &type, makVre::DtProjectileCreatorFcn fcn) |
| static DtProjectile * | createProjectile (DtlObjPtr mtlStream) |
| static DtProjectile * | createProjectile (const char *type, const char *pName, DtReaderWriterRegistry *const parentRegistry=NULL) |
| static DtProjectile * | creator (const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL) |
| static DtProjectileFactory * | factory () |
| static void | setFactory (DtProjectileFactory *factory) |
Protected Member Functions | |
| DtCustomProjectile () | |
Protected Member Functions inherited from makVre::DtProjectile | |
| DtProjectile () | |
| virtual ProjectileUpdateResult | updateProjectilePosition (double deltaTime) |
| virtual DtProjectileDetonationResult | checkForProjectileCollision (const ProjectileUpdateResult &projectUpdateResult) |
Protected Attributes | |
| double | myTimeInFlight |
Protected Attributes inherited from makVre::DtProjectile | |
| DtRwEntityType | myMunitionType |
| DtRwReal | myCrossSection |
| DtRwReal | myDragCoefficient |
| DtRwReal | myMass |
| DtRwReal | myMaxRange |
| DtRwVector | myPosition |
| DtRwVector | myVelocity |
| DtRwReal | myDistanceTraveled |
| DtSimObject * | myFiringEntity |
| DtPhysicalWorld * | myPhysicalWorld |
Additional Inherited Members | |
Static Protected Attributes inherited from makVre::DtProjectile | |
| static DtProjectileFactory * | theFactory |
| DtCustomProjectile::DtCustomProjectile | ( | const DtString & | name, |
| DtReaderWriterRegistry *const | parentRegistry = nullptr ) |
Construct projectile with string name.
PATTERN: Projectile Construction Projectiles are constructed with a name (used for identification and debugging) and an optional parent registry (for hierarchical parameter organization used by the base class).
The constructor must:
| name | Unique identifier for this projectile instance |
| parentRegistry | Optional parent registry for hierarchical organization |
Referenced by DtCustomProjectile(), operator!=(), operator=(), and operator==().
| DtCustomProjectile::DtCustomProjectile | ( | const DtSymbolString & | name, |
| DtReaderWriterRegistry *const | parentRegistry = nullptr ) |
Construct projectile with symbol string name.
| name | Symbol string identifier for this projectile instance |
| parentRegistry | Optional parent registry for hierarchical organization |
| DtCustomProjectile::DtCustomProjectile | ( | const DtCustomProjectile & | orig, |
| DtReaderWriterRegistry *const | parentRegistry = nullptr ) |
Copy constructor for projectile cloning.
PATTERN: Projectile Copying Projectiles must be copyable for cloning (for example, when creating multiple rounds from a template). The copy constructor must:
| orig | Source projectile to copy |
| parentRegistry | Optional parent registry for the copy |
References DtCustomProjectile().
|
inlineoverridevirtual |
Destructor - base class handles cleanup.
|
protected |
Default constructor - not implemented (projectiles require names)
| DtCustomProjectile & DtCustomProjectile::operator= | ( | const DtCustomProjectile & | orig | ) |
Assignment operator for projectile state copying.
Must copy both base class state and all custom parameters.
| orig | Source projectile to copy from |
References DtCustomProjectile().
|
overridevirtual |
Create a deep copy of this projectile.
Required by VR-Forces framework for projectile instantiation from templates. When multiple rounds of the same munition type are fired, the framework clones a template projectile rather than re-reading configuration files.
Reimplemented from makVre::DtProjectile.
| bool DtCustomProjectile::operator== | ( | const DtCustomProjectile & | ) | const |
Equality comparison for projectile state.
| rhs | Projectile to compare against |
References DtCustomProjectile().
|
inline |
Inequality comparison for projectile state.
| rhs | Projectile to compare against |
References DtCustomProjectile().
|
overridevirtual |
Return the class type identifier string.
PATTERN: Projectile Type Identification The type() method returns a unique string identifying this projectile class. This string is used by:
The type string must match the string used in factory registration.
Reimplemented from makVre::DtProjectile.
|
overridevirtual |
Update projectile state for one simulation frame.
PATTERN: Custom Projectile Update Logic The update() method is called once per simulation frame to advance projectile physics and behavior. Custom projectiles override this to implement:
This Example: Increments the time-in-flight parameter by deltaTime, then calls the base class update() to perform standard projectile physics (position integration, collision detection, detonation logic).
REUSABLE: This override pattern applies to any custom update logic. Always call the base class update() unless completely replacing default physics.
| deltaTime | Time elapsed since last update in seconds |
Reimplemented from makVre::DtProjectile.
|
static |
Static factory creator method.
PATTERN: Projectile Factory Pattern VR-Forces uses factory methods to instantiate projectiles by type name. The creator() method must be static and return a new instance of this class.
This method is registered with the projectile factory during plugin initialization: DtProjectileFactory::instance().registerProjectile( DtCustomProjectileType, &DtCustomProjectile::creator);
When MTL files reference this projectile type, the factory uses this creator to instantiate objects.
REUSABLE: This exact signature is required for all custom projectiles.
| name | Name for the new projectile instance |
| parentRegistry | Optional parent registry for the new instance |
|
protected |
Custom time-in-flight parameter.
The time-in-flight value is internal simulation state. It is not configured from data files and is not serialized; it is reset to zero when the projectile is constructed and accumulates while the projectile is active.