VR-Engage  2.2
Loading...
Searching...
No Matches
notifyLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file notifyLogic.h
7//! \brief Example component demonstrating attribute monitoring and temporary notifications in VR-Engage
8//!
9//! This header defines the DtNotifyLogic component which shows how to monitor player
10//! attribute store changes and display temporary overlay notifications. It demonstrates
11//! the attribute callback system and temporary notification API.
12
13#pragma once
14
16
17#include "vreUtil/attribute.h"
18
19
20//! \brief Type identifier string for DtNotifyLogic component registration.
21//!
22//! This string is used when registering the component with the component factory
23//! and must match the componentType value used in role configuration files.
24constexpr auto DtNotifyLogicType = "DtNotifyLogic";
25
26//! \brief Example component demonstrating player attribute monitoring and temporary notifications.
27//!
28//! This component shows how to use the VR-Engage player attribute store callback system
29//! to monitor state changes and display temporary overlay notifications to the user.
30//! It specifically monitors the "weaponIndex" attribute and displays a notification
31//! when the player's active weapon changes.
32//!
33//! Key VR-Engage patterns demonstrated:
34//! - Subscribing to attribute changes via attribute callbacks
35//! - Accessing the player attribute store
36//! - Creating temporary overlay notifications with duration
37//! - Component lifecycle (initialize, tick, shutdown)
38//! - Proper callback cleanup during shutdown
39//!
40//! This class inherits from DtPlayerComponent and is registered with the player
41//! station's component factory for role-based instantiation.
43{
44public:
45 //! \brief Default constructor.
46 //!
47 //! Initializes the notification logic component. The actual setup is performed
48 //! in initialize() following the VR-Engage component lifecycle pattern.
50
51 //! \brief Virtual destructor.
52 //!
53 //! Cleanup is performed in shutdown() rather than the destructor to ensure
54 //! proper framework ordering during component destruction.
55 virtual ~DtNotifyLogic() override;
56
57 //! \brief Initializes the component with player station and configuration.
58 //!
59 //! This method demonstrates the VR-Engage pattern for component initialization:
60 //! 1. Call base class initialize() first
61 //! 2. Access player attribute store to find monitored attributes
62 //! 3. Register attribute callbacks for state change notifications
63 //! 4. Handle missing attributes gracefully with warnings
64 //!
65 //! The "weaponIndex" attribute is accessed from the player attribute store,
66 //! which is a centralized repository for player-specific state. Callbacks
67 //! are registered using the myAttributeCallbacks connection manager for
68 //! automatic lifetime management.
69 //!
70 //! \param player The player station instance this component belongs to
71 //! \param config Configuration table containing role parameters (not used in this example)
72 //! \return true if initialization succeeds, false otherwise
74
75 //! \brief Per-frame update callback.
76 //!
77 //! Called every frame by the player station framework. This example does not
78 //! require per-frame processing, as it uses event-driven callbacks instead.
79 //! The empty implementation demonstrates that tick() is optional for
80 //! components that only respond to events.
81 //!
82 //! \param dt Delta time in seconds since last update
83 virtual void tick(double dt) override;
84
85 //! \brief Shutdown callback for cleanup.
86 //!
87 //! Performs cleanup before component destruction. This method demonstrates
88 //! the VR-Engage pattern for proper callback cleanup:
89 //! 1. Call base class shutdown() first
90 //! 2. Disconnect all attribute callbacks to prevent dangling pointers
91 //!
92 //! The myAttributeCallbacks.disconnectAll() call ensures all registered
93 //! callbacks are properly removed from the attribute store before the
94 //! component is destroyed.
95 virtual void shutdown() override;
96
97 //! \brief Returns the component type identifier.
98 //!
99 //! This string is used by the component factory for instantiation and
100 //! must match the registration in initPlayerStationModule().
101 //!
102 //! \return The component type string "DtNotifyLogic"
103 virtual const char* type() const override;
104
105protected:
106 //! \brief Callback invoked when the weaponIndex attribute changes.
107 //!
108 //! This method demonstrates the VR-Engage pattern for attribute change callbacks.
109 //! It is automatically called by the attribute store when the "weaponIndex"
110 //! value changes, allowing the component to respond to state changes without
111 //! polling.
112 //!
113 //! The callback creates a temporary notification message that displays for
114 //! 3 seconds as an overlay in the VR-Engage UI. This is accessed via the
115 //! player station app's tempNotification() service.
116 //!
117 //! PATTERN: Attribute callbacks provide an event-driven alternative to polling
118 //! state in tick(). This is the recommended approach for responding to state
119 //! changes as it's more efficient and maintains clear separation of concerns.
120 //!
121 //! \param index The new weapon index value (0-based index into weapon list)
122 virtual void handleWeaponIndexChanged(int index);
123};
Provides attribute handling system for hierarchical data storage and manipulation.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with player station and configuration.
virtual void handleWeaponIndexChanged(int index)
Callback invoked when the weaponIndex attribute changes.
DtNotifyLogic()
Default constructor.
virtual void shutdown() override
Shutdown callback for cleanup.
virtual ~DtNotifyLogic() override
Virtual destructor.
virtual void tick(double dt) override
Per-frame update callback.
virtual const char * type() const override
Returns the component type identifier.
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
constexpr auto DtNotifyLogicType
Type identifier string for DtNotifyLogic component registration.
Definition notifyLogic.h:24
Defines the DtPlayerComponent base class for VR-Engage role components.