VR-Engage  2.2
Loading...
Searching...
No Matches
DtDriverQmlHudComponent Class Reference

Detailed Description

This component shows how to:

  • Create and manage player attribute store entries for QML data binding
  • Subscribe to simulation state messages to track entity appearance changes
  • Extract DIS appearance bits and interpret damage states (mobility-kill, firepower-kill)
  • Publish data to QML overlays through the VR-Engage attribute store system

The component inherits from DtPlayerComponent and is registered with the player station's component factory for role-based instantiation. It works in conjunction with a QML overlay (configured separately) that displays the vehicle damage information.

Integration Pattern: This component creates attribute store entries that QML files can bind to using the VR-Engage QML bridge. The QML overlay reads these attributes reactively and updates the UI when values change.

Message Handling: Uses the legacy delegate-based message handling pattern. For new code, consider using the lambda-based subscription pattern shown in other examples.

See also
DtPlayerComponent for base class lifecycle methods
DtPlayerAttributeStore for reactive data binding with QML

#include <driverQmlHudComponent.h>

Inheritance diagram for DtDriverQmlHudComponent:
[legend]

Public Member Functions

 DtDriverQmlHudComponent ()
 
virtual ~DtDriverQmlHudComponent () override=default
 
virtual bool initialize (makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
 
virtual bool postInitialize () override
 
virtual void tick (double dt) override
 
virtual void shutdown () override
 
virtual const char * type () const override
 
virtual makVre::DtVreMessageResult handleSimState (makVre::DtVreMessage *msg)
 
- Public Member Functions inherited from makVre::DtPlayerComponent
 DtPlayerComponent ()
 
virtual ~DtPlayerComponent ()
 
virtual void setName (const std::string &name)
 
virtual const std::string & name ()
 
virtual DtPlayerStationplayer ()
 
virtual DtAttributeHandleplayerAttributeStore ()
 
virtual const DtAttributeHandleplayerAttributeStore () const
 

Protected Attributes

makVre::DtAttributeHandle myVehicleDamageState
 
- Protected Attributes inherited from makVre::DtPlayerComponent
std::string myName
 
DtInitTable myConfig
 
DtPlayerStationmyPlayer
 
makVrv::DtDe * myDe
 
DtEntityResolvermyResolver
 
DtAttributeCallbackManager myAttributeCallbacks
 

Additional Inherited Members

- Protected Member Functions inherited from makVre::DtPlayerComponent
virtual void initializeStateAttributes ()
 

Constructor & Destructor Documentation

◆ DtDriverQmlHudComponent()

DtDriverQmlHudComponent::DtDriverQmlHudComponent ( )

Constructs the driver QML HUD component.

Default constructor. Actual initialization is deferred to the initialize() method following the VR-Engage component lifecycle pattern.

◆ ~DtDriverQmlHudComponent()

virtual DtDriverQmlHudComponent::~DtDriverQmlHudComponent ( )
overridevirtualdefault

Destructor (compiler-generated).

Member Function Documentation

◆ initialize()

virtual bool DtDriverQmlHudComponent::initialize ( makVre::DtPlayerStation * player,
makVre::DtInitTable & config )
overridevirtual

Initializes the component with player station and configuration.

This method demonstrates the standard VR-Engage component initialization pattern:

  • Calls base class initialize() first (required)
  • Registers message handlers for simulation state updates
  • Does NOT access attribute store yet (deferred to postInitialize)

Pattern Note: Attribute store access should be done in postInitialize() to ensure all components have been constructed and basic initialization is complete.

Parameters
playerThe player station instance this component belongs to
configConfiguration table containing role parameters (unused in this example)
Returns
true if initialization succeeds, false otherwise

Reimplemented from makVre::DtPlayerComponent.

References makVre::DtPlayerComponent::player().

◆ postInitialize()

virtual bool DtDriverQmlHudComponent::postInitialize ( )
overridevirtual

Completes initialization after all components are initialized.

This method demonstrates the proper phase for attribute store setup:

  • Creates the "vehicle-status" attribute hierarchy
  • Initializes "mobility-kill" and "firepower-kill" boolean attributes
  • Sets initial values (both false, indicating no damage)

Design Pattern: Use postInitialize() for cross-component dependencies and attribute store manipulation, as all components are guaranteed to exist at this point.

Returns
true if post-initialization succeeds, false otherwise

Reimplemented from makVre::DtPlayerComponent.

◆ tick()

virtual void DtDriverQmlHudComponent::tick ( double dt)
inlineoverridevirtual

Per-frame update callback.

Empty implementation - this component is purely message-driven and does not require per-frame updates. All state changes happen in response to SimulationStateMessage.

Parameters
dtElapsed time since last tick in seconds (unused)

Implements makVre::DtPlayerComponent.

◆ shutdown()

virtual void DtDriverQmlHudComponent::shutdown ( )
overridevirtual

Cleanup and resource release.

Unregisters message handlers to prevent callbacks after component destruction. This is critical for avoiding dangling pointers when the component is destroyed.

Reimplemented from makVre::DtPlayerComponent.

◆ type()

virtual const char * DtDriverQmlHudComponent::type ( ) const
overridevirtual

Returns the component type identifier string.

Used by the VR-Engage framework for component identification and factory registration.

Returns
The component type string matching DtDriverQmlHudComponentType

Implements makVre::DtPlayerComponent.

◆ handleSimState()

virtual makVre::DtVreMessageResult DtDriverQmlHudComponent::handleSimState ( makVre::DtVreMessage * msg)
virtual

Handles simulation state messages to update vehicle damage status.

This message handler demonstrates:

  • Filtering messages by entity ID to process only relevant entities
  • Extracting DIS appearance bits from simulation state
  • Using DtAppearance helper to interpret damage states
  • Updating attribute store values for QML consumption

Message Pattern: Uses the legacy delegate-based handler pattern. The handler is registered in initialize() and unregistered in shutdown().

Parameters
msgThe simulation state message containing entity appearance data
Returns
HANDLED to indicate successful processing

Member Data Documentation

◆ myVehicleDamageState

makVre::DtAttributeHandle DtDriverQmlHudComponent::myVehicleDamageState
protected

Handle to the vehicle damage state attribute hierarchy.

This attribute contains two boolean child attributes:

  • "mobility-kill": true when vehicle is immobilized
  • "firepower-kill": true when vehicle weapons are disabled

QML overlays bind to these attributes to reactively display damage state in the UI. The handle is obtained in postInitialize() and updated in handleSimState().


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