VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtVreGunJoyActuator Class Reference

Detailed Description

DtVreGunJoyActuator provides a model of a turret mounted gun controllable via joystick. It extends the ballistic gun actuator and adds the ability to aim the gun using joystick inputs without needing a separate aiming actuator. The component manages firing mechanics, ammunition tracking, weapon switching, and projectile creation for various turret-mounted weapons.

Uses Descriptor Type: DtVreBallisticGunDescriptor

#include <vreGunJoyActuator.h>

Inheritance diagram for makVre::DtVreGunJoyActuator:
[legend]

Classes

struct  DtFireResult
 
struct  Munition
 

Public Member Functions

 DtVreGunJoyActuator (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 
virtual ~DtVreGunJoyActuator () override
 
virtual bool init () override
 
virtual const char * type () const override
 
virtual void tick () override
 
virtual void preFirstTickInit () override
 
virtual void updateStateProperties ()
 
- Public Member Functions inherited from makVre::DtVreSimComponent< DtBallisticGunJoy >
 DtVreSimComponent (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 
virtual ~DtVreSimComponent ()
 
bool isPlayerControlled (const std::string &role="") const
 
DtString entitySystemName () const
 
- Public Member Functions inherited from makVre::DtBallisticGunJoy
 DtBallisticGunJoy (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *const parentRegistry=0)
 
virtual ~DtBallisticGunJoy () override
 
virtual void setComponentDescriptor (DtComponentDescriptor *descriptor) override
 
virtual DtReal setTarget (makVrf::DtArticulatedPartStateRepository *rotBody)
 
virtual makVrfEvents::DtFireEvent * manualFireInteraction (makVrf::DtArticulatedPartStateRepository *rotBody)
 
virtual makVrfEvents::DtDetonationEvent * manualDetonationInteraction (makVrf::DtArticulatedPartStateRepository *rotBody, DtReal &detTime, DtReal dist)
 
virtual DtUUID targetSelection (makVrf::DtArticulatedPartStateRepository *rotBody, DtReal &dist)
 
virtual DtReal distanceToTarget ()
 

Static Public Member Functions

static DtSimComponent * creator (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 
- Static Public Member Functions inherited from makVre::DtBallisticGunJoy
static void detonationCallback (DtTimer *timer)
 
static DtSimComponent * creator (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 

Protected Member Functions

virtual DtVreMessageResult handleCommanderOverride (DtVreMessage *msg)
 
virtual double getAmmoLoadTime (const DtEntityType &ammoType)
 
bool aimGunElevation ()
 
virtual bool createPortGroups () override
 
virtual bool createPorts () override
 
virtual bool aimGun () override
 
virtual void getFireResult (const DtVector &shooterPosition, const DtTaitBryan shooterOrienation, DtFireResult &fireResult)
 
virtual bool createFlyOutProjectile (const DtVector &shooterPosition, const DtTaitBryan shooterOrienation)
 
virtual void createDetonation (const DtVector &detonationPosition, const DtFireResult &fireResult)
 
virtual makVrfEvents::DtFireEvent * createFireInteraction (const DtVector &firingPosition, const DtTaitBryan firingOrientation)
 
virtual makVrfEvents::DtDetonationEvent * createDetonationInteraction (const DtVector &firingPosition, const DtTaitBryan firingOrientation, const DtFireResult &fireResult, DtReal &detTime)
 
virtual void decrementResource ()
 
virtual int currentResourceCount () const
 
 DtVreGunJoyActuator ()
 
 DtVreGunJoyActuator (const DtVreGunJoyActuator &orig)
 
const DtVreGunJoyActuatoroperator= (const DtVreGunJoyActuator &orig)
 
void setCurrentMunition (int munition)
 
DtSimResource * findResource (DtEntityType resourceType)
 
const DtSimResource * findResource (DtEntityType resourceType) const
 
virtual makVre::DtVreMessageResult handleFireInput (makVre::DtVreMessage *msg)
 
virtual makVre::DtVreMessageResult handleWeaponGeometry (makVre::DtVreMessage *msg)
 
virtual void initializeResource (const DtSimResource *resource)
 
virtual DtSimMunition * getMunitionFromResourceType (const DtEntityType &resourceType) const
 
virtual const DtSimResource * lookupMunitionResource (const DtEntityType &resource) const
 

Protected Attributes

DtVreBallisticGunDescriptormyVreBallisticGunDescriptor
 
makVre::DtAmmoLoadTimeList myAmmoLoadTimeList
 
DtInputPortGroup * myWeaponPortGroup
 
DtBooleanInputPort * myFirePort
 
DtBooleanInputPort * myNextWeaponPort
 
DtBooleanInputPort * myPreviousWeaponPort
 
DtBooleanOutputPort * myFiringPort
 
DtVreAmmunitionManagermyAmmunitionManager
 
std::vector< MunitionmyMunitions
 
bool myIsFiring
 
int myCurrentMunition
 
DtVector myWorldFiringPosition
 
DtTaitBryan myWorldFiringOrientation
 
bool myOverrideArtPartGeometry
 
bool myCommanderOverrideActive
 
bool myPreviouslyEngaged
 
double myDisengageElapsedTime
 
double myReturnGunToCgfControlDuration = 2.0
 
- Protected Attributes inherited from makVre::DtBallisticGunJoy
bool myReportedNoArticulation
 
DtConstrainedAnalogInputPort * myElevationPort
 
DtBooleanInputPort * myActiveJoystickPort
 

Constructor & Destructor Documentation

◆ DtVreGunJoyActuator() [1/3]

makVre::DtVreGunJoyActuator::DtVreGunJoyActuator ( const DtString & name,
DtLocalObject * owner,
DtSimulationServices * simManager,
DtComponentDescriptor * desc = 0,
DtReaderWriterRegistry * parentRegistry = 0 )

Constructor.

Parameters
nameThe name of this component
ownerThe local object that owns this component
simManagerThe simulation services manager
descComponent descriptor with configuration parameters
parentRegistryOptional parent registry for reader/writer functionality

Creates a new gun joystick actuator component with the specified parameters.

Referenced by DtVreGunJoyActuator(), and operator=().

◆ ~DtVreGunJoyActuator()

virtual makVre::DtVreGunJoyActuator::~DtVreGunJoyActuator ( )
overridevirtual

Virtual destructor.

Cleans up resources used by the gun joystick actuator component, including ammunition manager and port connections.

◆ DtVreGunJoyActuator() [2/3]

makVre::DtVreGunJoyActuator::DtVreGunJoyActuator ( )
protected

Default constructor (not implemented)

Default constructor is protected and not implemented to prevent creation of instances without proper initialization.

◆ DtVreGunJoyActuator() [3/3]

makVre::DtVreGunJoyActuator::DtVreGunJoyActuator ( const DtVreGunJoyActuator & orig)
protected

Copy constructor (not implemented)

Copy constructor is protected and not implemented to prevent copy construction.

References DtVreGunJoyActuator().

Member Function Documentation

◆ init()

virtual bool makVre::DtVreGunJoyActuator::init ( )
overridevirtual

Initializes the gun joystick actuator.

Returns
True if initialization is successful, false otherwise

Performs initial setup of the gun joystick actuator, including port connections, ammunition management, and message handling. Called during component initialization.

◆ type()

virtual const char * makVre::DtVreGunJoyActuator::type ( ) const
overridevirtual

Gets the type identifier for this component.

Returns
String identifying the component type (DtVreGunJoyActuatorType)

Implements the DtSimComponent::type() method to return the type identifier for this component.

Reimplemented from makVre::DtBallisticGunJoy.

◆ tick()

virtual void makVre::DtVreGunJoyActuator::tick ( )
overridevirtual

Updates the actuator state each simulation frame.

Processes input controls, manages firing state, aims the gun using joystick inputs, and handles ammunition consumption during each simulation frame. This is the main update method called every simulation tick.

Reimplemented from makVre::DtBallisticGunJoy.

◆ preFirstTickInit()

virtual void makVre::DtVreGunJoyActuator::preFirstTickInit ( )
overridevirtual

Performs initialization before the first simulation tick.

Sets up initial states and configurations before the simulation begins, including loading ammunition types and initializing resources. This initialization is performed once before the first tick of the simulation.

◆ updateStateProperties()

virtual void makVre::DtVreGunJoyActuator::updateStateProperties ( )
virtual

Updates the state properties for the gun actuator.

Synchronizes and updates simulation state properties related to the gun actuator, such as ammunition counts, and weapon status. This method ensures that the current state of the gun is accurately reflected in the simulation's state properties for use by the VRE Frontend, networking, and other systems that monitor or display weapon status.

Typically called after firing, reloading, or changing ammunition to keep state properties consistent with the gun's actual state.

◆ creator()

static DtSimComponent * makVre::DtVreGunJoyActuator::creator ( const DtString & name,
DtLocalObject * owner,
DtSimulationServices * simManager,
DtComponentDescriptor * desc = 0,
DtReaderWriterRegistry * parentRegistry = 0 )
static

Factory method to create a new instance of this component.

Parameters
nameThe name for the new component
ownerThe local object that will own this component
simManagerThe simulation services manager
descOptional component descriptor
parentRegistryOptional parent registry for reader/writer functionality
Returns
Pointer to the newly created component

Static factory method used by the component creation system to instantiate new instances of this component type.

◆ handleCommanderOverride()

virtual DtVreMessageResult makVre::DtVreGunJoyActuator::handleCommanderOverride ( DtVreMessage * msg)
protectedvirtual

Handles commander override message.

Parameters
msgPointer to the message containing override parameters
Returns
Message processing result indicating success or failure

Processes CommanderOverride messages, which activate or deactivate commander override mode. When in commander override mode, direct control inputs take precedence over AI control or other input methods.

◆ getAmmoLoadTime()

virtual double makVre::DtVreGunJoyActuator::getAmmoLoadTime ( const DtEntityType & ammoType)
protectedvirtual

Gets the load time for a specific ammunition type.

Parameters
ammoTypeThe entity type ID of the ammunition
Returns
The load time in seconds for the specified ammunition type

Looks up the load time for the given ammunition type from the configured ammunition load time list. This determines how long it takes to switch to this ammunition type.

◆ aimGunElevation()

bool makVre::DtVreGunJoyActuator::aimGunElevation ( )
protected

Controls the elevation aspect of gun aiming.

Returns
True if elevation aiming is complete, false otherwise

Adjusts the elevation component of the gun's aim based on input controls. This method specifically handles the vertical movement of the gun turret.

◆ createPortGroups()

virtual bool makVre::DtVreGunJoyActuator::createPortGroups ( )
overrideprotectedvirtual

Creates the port groups for weapon control.

Returns
True if port groups are successfully created, false otherwise

Overridden to create the weapon control input port group. This method creates the port group structure needed for handling weapon control inputs via joystick.

◆ createPorts()

virtual bool makVre::DtVreGunJoyActuator::createPorts ( )
overrideprotectedvirtual

Creates the input and output ports for the actuator.

Returns
True if ports are successfully created, false otherwise

Overridden to create local ports for weapon control inputs (fire, next/previous weapon) and outputs (firing state) needed for joystick control.

Reimplemented from makVre::DtBallisticGunJoy.

◆ aimGun()

virtual bool makVre::DtVreGunJoyActuator::aimGun ( )
overrideprotectedvirtual

Aims the gun based on joystick input ports.

Returns
True if aiming is complete, false otherwise

Aims the gun based on joystick input ports. Uses the elevation input port to determine the correct elevation angle and the azimuth input port to determine the correct azimuth angle. Returns true when the gun has reached the desired aim position.

◆ getFireResult()

virtual void makVre::DtVreGunJoyActuator::getFireResult ( const DtVector & shooterPosition,
const DtTaitBryan shooterOrienation,
DtFireResult & fireResult )
protectedvirtual

Calculates the result of firing the weapon.

Parameters
shooterPositionThe geocentric position of the shooter
shooterOrienationThe orientation of the shooter
fireResultOutput parameter that will contain the fire result

Calculates the result of firing the weapon from the given position and orientation. This includes determining if a target was hit, the range to the target, and the detonation result. The results are stored in the provided fireResult structure.

◆ createFlyOutProjectile()

virtual bool makVre::DtVreGunJoyActuator::createFlyOutProjectile ( const DtVector & shooterPosition,
const DtTaitBryan shooterOrienation )
protectedvirtual

Creates a flyout projectile from the weapon.

Parameters
shooterPositionThe geocentric position of the shooter
shooterOrienationThe orientation of the shooter
Returns
True if projectile was successfully created, false otherwise

Creates a physical flyout projectile from the weapon at the specified position and with the specified orientation. This creates a visual representation of the projectile as it moves through the simulation.

◆ createDetonation()

virtual void makVre::DtVreGunJoyActuator::createDetonation ( const DtVector & detonationPosition,
const DtFireResult & fireResult )
protectedvirtual

Creates a detonation at the specified position.

Parameters
detonationPositionThe geocentric position where detonation occurs
fireResultThe fire result containing detonation parameters

Creates a detonation at the given position using the fire result to determine detonation characteristics. This handles the effects and damage processing when a projectile reaches its target or maximum range.

◆ createFireInteraction()

virtual makVrfEvents::DtFireEvent * makVre::DtVreGunJoyActuator::createFireInteraction ( const DtVector & firingPosition,
const DtTaitBryan firingOrientation )
protectedvirtual

Creates a fire event for interaction processing.

Parameters
firingPositionThe geocentric position of the firing point
firingOrientationThe orientation of the firing point
Returns
Pointer to the created fire event, or nullptr if creation failed

Creates and initializes a fire event based on the specified position and orientation. This event represents the firing of the weapon and is used in the interaction system.

◆ createDetonationInteraction()

virtual makVrfEvents::DtDetonationEvent * makVre::DtVreGunJoyActuator::createDetonationInteraction ( const DtVector & firingPosition,
const DtTaitBryan firingOrientation,
const DtFireResult & fireResult,
DtReal & detTime )
protectedvirtual

Creates a detonation event for interaction processing.

Parameters
firingPositionThe geocentric position of the firing point
firingOrientationThe orientation of the firing point
fireResultThe results of the firing calculation
detTimeOutput parameter that will contain the detonation time
Returns
Pointer to the created detonation event, or nullptr if creation failed

Creates and initializes a detonation event based on the specified position, orientation, and fire result. This event represents the detonation of a projectile and is used in the interaction system. The detonation time is calculated and returned in the detTime parameter.

◆ decrementResource()

virtual void makVre::DtVreGunJoyActuator::decrementResource ( )
protectedvirtual

Decrements the ammunition resource count.

Decrements the available ammunition count for the current munition type. This is called after firing the weapon to reflect ammunition consumption.

◆ currentResourceCount()

virtual int makVre::DtVreGunJoyActuator::currentResourceCount ( ) const
protectedvirtual

Gets the current ammunition resource count.

Returns
The number of available rounds for the current munition type

Returns the number of available rounds remaining for the currently selected munition type. Used to track ammunition availability.

◆ operator=()

const DtVreGunJoyActuator & makVre::DtVreGunJoyActuator::operator= ( const DtVreGunJoyActuator & orig)
protected

Assignment operator (not implemented)

Returns
Reference to this object

Assignment operator is protected and not implemented to prevent assignment.

References DtVreGunJoyActuator().

◆ setCurrentMunition()

void makVre::DtVreGunJoyActuator::setCurrentMunition ( int munition)
protected

Sets the current munition type for the weapon.

Parameters
munitionIndex of the munition type to set as current

Updates the current munition type used by the weapon, which affects the ammunition type consumed and the firing characteristics.

◆ findResource() [1/2]

DtSimResource * makVre::DtVreGunJoyActuator::findResource ( DtEntityType resourceType)
protected

Finds a specific resource by type.

Parameters
resourceTypeThe entity type of the resource to find
Returns
Pointer to the resource if found, nullptr otherwise

Searches for and returns a pointer to a resource of the specified type. This is used to access ammunition resources for the weapon.

◆ findResource() [2/2]

const DtSimResource * makVre::DtVreGunJoyActuator::findResource ( DtEntityType resourceType) const
protected

Finds a specific resource by type (const version)

Parameters
resourceTypeThe entity type of the resource to find
Returns
Const pointer to the resource if found, nullptr otherwise

Const version of findResource that searches for and returns a constant pointer to a resource of the specified type.

◆ handleFireInput()

virtual makVre::DtVreMessageResult makVre::DtVreGunJoyActuator::handleFireInput ( makVre::DtVreMessage * msg)
protectedvirtual

Handles fire input messages from external sources.

Parameters
msgPointer to the message containing fire input parameters
Returns
Message processing result indicating success or failure

Processes FireInput messages, which provide external control over the firing state of the weapon. This allows the weapon to be fired through message-based commands rather than joystick inputs.

◆ handleWeaponGeometry()

virtual makVre::DtVreMessageResult makVre::DtVreGunJoyActuator::handleWeaponGeometry ( makVre::DtVreMessage * msg)
protectedvirtual

Handles weapon geometry messages for positioning.

Parameters
msgPointer to the message containing weapon geometry parameters
Returns
Message processing result indicating success or failure

Processes WeaponGeometry messages, which provide information about the position and orientation of the weapon. This is used for external control of weapon positioning, overriding articulated part geometry.

◆ initializeResource()

virtual void makVre::DtVreGunJoyActuator::initializeResource ( const DtSimResource * resource)
protectedvirtual

Initializes a resource for use with this weapon.

Parameters
resourcePointer to the resource to initialize

Sets up a simulation resource for use with this weapon, including configuring any necessary properties based on the weapon characteristics. This is typically called during initialization for each available ammunition type.

◆ getMunitionFromResourceType()

virtual DtSimMunition * makVre::DtVreGunJoyActuator::getMunitionFromResourceType ( const DtEntityType & resourceType) const
protectedvirtual

Gets a munition object from a resource type.

Parameters
resourceTypeThe entity type of the resource
Returns
Pointer to the munition object, or nullptr if not found

Retrieves a munition object corresponding to the specified resource type. This translates between resource types and the actual munition objects that define the projectile characteristics.

◆ lookupMunitionResource()

virtual const DtSimResource * makVre::DtVreGunJoyActuator::lookupMunitionResource ( const DtEntityType & resource) const
protectedvirtual

Looks up a munition resource by entity type.

Parameters
resourceThe entity type of the resource to find
Returns
Const pointer to the resource if found, nullptr otherwise

Looks up a munition resource by its entity type. This method searches through available resources to find a matching munition resource.

Member Data Documentation

◆ myVreBallisticGunDescriptor

DtVreBallisticGunDescriptor* makVre::DtVreGunJoyActuator::myVreBallisticGunDescriptor
protected

Cached pointer to the ballistic gun descriptor.

Caching expected derived descriptor pointer for convenience. Contains the configuration parameters for this gun component.

◆ myAmmoLoadTimeList

makVre::DtAmmoLoadTimeList makVre::DtVreGunJoyActuator::myAmmoLoadTimeList
protected

List of ammunition load times.

Contains the load time information for different ammunition types, used to determine how long it takes to switch between ammunitions.

◆ myWeaponPortGroup

DtInputPortGroup* makVre::DtVreGunJoyActuator::myWeaponPortGroup
protected

Port group for weapon control inputs.

◆ myFirePort

DtBooleanInputPort* makVre::DtVreGunJoyActuator::myFirePort
protected

Input port for fire command.

◆ myNextWeaponPort

DtBooleanInputPort* makVre::DtVreGunJoyActuator::myNextWeaponPort
protected

Input port for next weapon selection.

◆ myPreviousWeaponPort

DtBooleanInputPort* makVre::DtVreGunJoyActuator::myPreviousWeaponPort
protected

Input port for previous weapon selection.

◆ myFiringPort

DtBooleanOutputPort* makVre::DtVreGunJoyActuator::myFiringPort
protected

Output port for firing state.

◆ myAmmunitionManager

DtVreAmmunitionManager* makVre::DtVreGunJoyActuator::myAmmunitionManager
protected

Manager for ammunition resources.

Handles tracking and management of ammunition resources for this weapon, including finding, loading, and decrementing ammunition counts.

◆ myMunitions

std::vector<Munition> makVre::DtVreGunJoyActuator::myMunitions
protected

List of available munitions for this weapon.

◆ myIsFiring

bool makVre::DtVreGunJoyActuator::myIsFiring
protected

Flag indicating whether the weapon is currently firing.

◆ myCurrentMunition

int makVre::DtVreGunJoyActuator::myCurrentMunition
protected

Index of the currently selected munition type.

◆ myWorldFiringPosition

DtVector makVre::DtVreGunJoyActuator::myWorldFiringPosition
protected

Current world position for firing the weapon.

◆ myWorldFiringOrientation

DtTaitBryan makVre::DtVreGunJoyActuator::myWorldFiringOrientation
protected

Current world orientation for firing the weapon.

◆ myOverrideArtPartGeometry

bool makVre::DtVreGunJoyActuator::myOverrideArtPartGeometry
protected

Flag for overriding articulated part geometry.

Set to true when FireInput and WeaponGeometry messages are used for firing the weapon, false when using joystick input. Determines how myWorldFiringPosition and myWorldFiringOrientation values are set (either from FireInput/WeaponGeometry messages, or from articulated parts).

◆ myCommanderOverrideActive

bool makVre::DtVreGunJoyActuator::myCommanderOverrideActive
protected

Flag for commander override mode.

When true, indicates that commander override mode is active, which gives direct control inputs precedence over AI control or other input methods.

◆ myPreviouslyEngaged

bool makVre::DtVreGunJoyActuator::myPreviouslyEngaged
protected

Flag tracking previous engagement state.

Keeps track of engagement state so weapon can unload on disengagement. This prevents VR-Forces from using non-optimal ammunition under CGF control, which could occur when this component loads a munition and then CGF control fires on a valid target that might not be the best match by level of DIS enumeration specificity.

◆ myDisengageElapsedTime

double makVre::DtVreGunJoyActuator::myDisengageElapsedTime
protected

Elapsed time since player disengaged from gunner role.

Accumulates time in seconds since the player disengaged from the gunner role. Used to buffer the aimGun function to prevent CGF from immediately resetting gun elevation to 0 when swapping roles. Reset to 0.0 when player regains control.

See also
myReturnGunToCgfControlDuration

◆ myReturnGunToCgfControlDuration

double makVre::DtVreGunJoyActuator::myReturnGunToCgfControlDuration = 2.0
protected

Duration before returning gun control to CGF.

Time in seconds to wait after player disengages before allowing CGF to control gun aiming. This prevents unwanted elevation resets during role swaps. The value is read from the descriptor during initialization.

Note
Default value is 2.0 seconds
See also
myDisengageElapsedTime
DtVreBallisticGunDescriptor::returnGunToCGFControlDuration()

The documentation for this class was generated from the following file: