VR-Engage  2.2
Loading...
Searching...
No Matches
driverQmlHudComponent.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file driverQmlHudComponent.h
7//! \brief Component demonstrating QML HUD overlay integration with vehicle damage state.
8
9
10#pragma once
11
13
14#include "vreUtil/attribute.h"
15
17
18//! Component type identifier for factory registration and role configuration.
19//!
20//! This string must match the componentGroup name used in role configuration XML files
21//! to instantiate this component as part of a player station role.
22constexpr auto DtDriverQmlHudComponentType = "DtDriverQmlHudComponent";
23
24//! \brief Example component demonstrating QML overlay integration with vehicle damage state.
25//!
26//! This component shows how to:
27//! - Create and manage player attribute store entries for QML data binding
28//! - Subscribe to simulation state messages to track entity appearance changes
29//! - Extract DIS appearance bits and interpret damage states (mobility-kill, firepower-kill)
30//! - Publish data to QML overlays through the VR-Engage attribute store system
31//!
32//! The component inherits from DtPlayerComponent and is registered with the player station's
33//! component factory for role-based instantiation. It works in conjunction with a QML overlay
34//! (configured separately) that displays the vehicle damage information.
35//!
36//! **Integration Pattern**: This component creates attribute store entries that QML files
37//! can bind to using the VR-Engage QML bridge. The QML overlay reads these attributes
38//! reactively and updates the UI when values change.
39//!
40//! **Message Handling**: Uses the legacy delegate-based message handling pattern. For new
41//! code, consider using the lambda-based subscription pattern shown in other examples.
42//!
43//! \see DtPlayerComponent for base class lifecycle methods
44//! \see DtPlayerAttributeStore for reactive data binding with QML
46{
47public:
48 //! \brief Constructs the driver QML HUD component.
49 //!
50 //! Default constructor. Actual initialization is deferred to the initialize() method
51 //! following the VR-Engage component lifecycle pattern.
53
54 //! \brief Destructor (compiler-generated).
55 virtual ~DtDriverQmlHudComponent() override = default;
56
57 //! \brief Initializes the component with player station and configuration.
58 //!
59 //! This method demonstrates the standard VR-Engage component initialization pattern:
60 //! - Calls base class initialize() first (required)
61 //! - Registers message handlers for simulation state updates
62 //! - Does NOT access attribute store yet (deferred to postInitialize)
63 //!
64 //! **Pattern Note**: Attribute store access should be done in postInitialize() to ensure
65 //! all components have been constructed and basic initialization is complete.
66 //!
67 //! \param player The player station instance this component belongs to
68 //! \param config Configuration table containing role parameters (unused in this example)
69 //! \return true if initialization succeeds, false otherwise
71
72 //! \brief Completes initialization after all components are initialized.
73 //!
74 //! This method demonstrates the proper phase for attribute store setup:
75 //! - Creates the "vehicle-status" attribute hierarchy
76 //! - Initializes "mobility-kill" and "firepower-kill" boolean attributes
77 //! - Sets initial values (both false, indicating no damage)
78 //!
79 //! **Design Pattern**: Use postInitialize() for cross-component dependencies and
80 //! attribute store manipulation, as all components are guaranteed to exist at this point.
81 //!
82 //! \return true if post-initialization succeeds, false otherwise
83 virtual bool postInitialize() override;
84
85 //! \brief Per-frame update callback.
86 //!
87 //! Empty implementation - this component is purely message-driven and does not require
88 //! per-frame updates. All state changes happen in response to SimulationStateMessage.
89 //!
90 //! \param dt Elapsed time since last tick in seconds (unused)
91 virtual void tick(double dt) override {};
92
93 //! \brief Cleanup and resource release.
94 //!
95 //! Unregisters message handlers to prevent callbacks after component destruction.
96 //! This is critical for avoiding dangling pointers when the component is destroyed.
97 virtual void shutdown() override;
98
99 //! \brief Returns the component type identifier string.
100 //!
101 //! Used by the VR-Engage framework for component identification and factory registration.
102 //!
103 //! \return The component type string matching DtDriverQmlHudComponentType
104 virtual const char* type() const override;
105
106 //! \brief Handles simulation state messages to update vehicle damage status.
107 //!
108 //! This message handler demonstrates:
109 //! - Filtering messages by entity ID to process only relevant entities
110 //! - Extracting DIS appearance bits from simulation state
111 //! - Using DtAppearance helper to interpret damage states
112 //! - Updating attribute store values for QML consumption
113 //!
114 //! **Message Pattern**: Uses the legacy delegate-based handler pattern. The handler
115 //! is registered in initialize() and unregistered in shutdown().
116 //!
117 //! \param msg The simulation state message containing entity appearance data
118 //! \return HANDLED to indicate successful processing
120
121protected:
122 //! Handle to the vehicle damage state attribute hierarchy.
123 //!
124 //! This attribute contains two boolean child attributes:
125 //! - "mobility-kill": true when vehicle is immobilized
126 //! - "firepower-kill": true when vehicle weapons are disabled
127 //!
128 //! QML overlays bind to these attributes to reactively display damage state in the UI.
129 //! The handle is obtained in postInitialize() and updated in handleSimState().
131};
Provides attribute handling system for hierarchical data storage and manipulation.
virtual const char * type() const override
Returns the component type identifier string.
virtual ~DtDriverQmlHudComponent() override=default
Destructor (compiler-generated).
virtual makVre::DtVreMessageResult handleSimState(makVre::DtVreMessage *msg)
Handles simulation state messages to update vehicle damage status.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with player station and configuration.
virtual bool postInitialize() override
Completes initialization after all components are initialized.
DtDriverQmlHudComponent()
Constructs the driver QML HUD component.
makVre::DtAttributeHandle myVehicleDamageState
Handle to the vehicle damage state attribute hierarchy.
Definition driverQmlHudComponent.h:130
virtual void shutdown() override
Cleanup and resource release.
virtual void tick(double dt) override
Per-frame update callback.
Definition driverQmlHudComponent.h:91
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
constexpr auto DtDriverQmlHudComponentType
Component type identifier for factory registration and role configuration.
Definition driverQmlHudComponent.h:22
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines the base class for all VREngage messages.