VR-Engage  2.3
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 Sets up attribute callback.
58 //!
59 //! This method demonstrates the VR-Engage pattern for component initialization:
60 //! 1. Call base class post 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 //! \return true if post initialization succeeds, false otherwise
71 virtual bool postInitialize() override;
72
73 //! \brief Per-frame update callback.
74 //!
75 //! Called every frame by the player station framework. This example does not
76 //! require per-frame processing, as it uses event-driven callbacks instead.
77 //! The empty implementation demonstrates that tick() is optional for
78 //! components that only respond to events.
79 //!
80 //! \param dt Delta time in seconds since last update
81 virtual void tick(double dt) override;
82
83 //! \brief Shutdown callback for cleanup.
84 //!
85 //! Performs cleanup before component destruction. This method demonstrates
86 //! the VR-Engage pattern for proper callback cleanup:
87 //! 1. Call base class shutdown() first
88 //! 2. Disconnect all attribute callbacks to prevent dangling pointers
89 //!
90 //! The myAttributeCallbacks.disconnectAll() call ensures all registered
91 //! callbacks are properly removed from the attribute store before the
92 //! component is destroyed.
93 virtual void shutdown() override;
94
95 //! \brief Returns the component type identifier.
96 //!
97 //! This string is used by the component factory for instantiation and
98 //! must match the registration in initPlayerStationModule().
99 //!
100 //! \return The component type string "DtNotifyLogic"
101 virtual const char* type() const override;
102
103protected:
104 //! \brief Callback invoked when the weaponIndex attribute changes.
105 //!
106 //! This method demonstrates the VR-Engage pattern for attribute change callbacks.
107 //! It is automatically called by the attribute store when the "weaponIndex"
108 //! value changes, allowing the component to respond to state changes without
109 //! polling.
110 //!
111 //! The callback creates a temporary notification message that displays for
112 //! 3 seconds as an overlay in the VR-Engage UI. This is accessed via the
113 //! player station app's tempNotification() service.
114 //!
115 //! PATTERN: Attribute callbacks provide an event-driven alternative to polling
116 //! state in tick(). This is the recommended approach for responding to state
117 //! changes as it's more efficient and maintains clear separation of concerns.
118 //!
119 //! \param index The new weapon index value (0-based index into weapon list)
120 virtual void handleWeaponIndexChanged(int index);
121};
Provides attribute handling system for hierarchical data storage and manipulation.
virtual void handleWeaponIndexChanged(int index)
Callback invoked when the weaponIndex attribute changes.
virtual bool postInitialize() override
Sets up attribute callback.
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.
Base class for all role components in VR-Engage.
Definition playerComponent.h:102
constexpr auto DtNotifyLogicType
Type identifier string for DtNotifyLogic component registration.
Definition notifyLogic.h:24
Defines the DtPlayerComponent base class for VR-Engage role components.