|
VR-Engage
2.2
|
This component shows how to use the VR-Engage player attribute store callback system to monitor state changes and display temporary overlay notifications to the user. It specifically monitors the "weaponIndex" attribute and displays a notification when the player's active weapon changes.
Key VR-Engage patterns demonstrated:
This class inherits from DtPlayerComponent and is registered with the player station's component factory for role-based instantiation.
#include <notifyLogic.h>
Public Member Functions | |
| DtNotifyLogic () | |
| virtual | ~DtNotifyLogic () override |
| virtual bool | initialize (makVre::DtPlayerStation *player, makVre::DtInitTable &config) override |
| virtual void | tick (double dt) override |
| virtual void | shutdown () override |
| virtual const char * | type () const override |
Public Member Functions inherited from makVre::DtPlayerComponent | |
| DtPlayerComponent () | |
| virtual | ~DtPlayerComponent () |
| virtual bool | postInitialize () |
| virtual void | setName (const std::string &name) |
| virtual const std::string & | name () |
| virtual DtPlayerStation & | player () |
| virtual DtAttributeHandle & | playerAttributeStore () |
| virtual const DtAttributeHandle & | playerAttributeStore () const |
Protected Member Functions | |
| virtual void | handleWeaponIndexChanged (int index) |
Protected Member Functions inherited from makVre::DtPlayerComponent | |
| virtual void | initializeStateAttributes () |
Additional Inherited Members | |
Protected Attributes inherited from makVre::DtPlayerComponent | |
| std::string | myName |
| DtInitTable | myConfig |
| DtPlayerStation * | myPlayer |
| makVrv::DtDe * | myDe |
| DtEntityResolver * | myResolver |
| DtAttributeCallbackManager | myAttributeCallbacks |
| DtNotifyLogic::DtNotifyLogic | ( | ) |
Default constructor.
Initializes the notification logic component. The actual setup is performed in initialize() following the VR-Engage component lifecycle pattern.
|
overridevirtual |
Virtual destructor.
Cleanup is performed in shutdown() rather than the destructor to ensure proper framework ordering during component destruction.
|
overridevirtual |
Initializes the component with player station and configuration.
This method demonstrates the VR-Engage pattern for component initialization:
The "weaponIndex" attribute is accessed from the player attribute store, which is a centralized repository for player-specific state. Callbacks are registered using the myAttributeCallbacks connection manager for automatic lifetime management.
| player | The player station instance this component belongs to |
| config | Configuration table containing role parameters (not used in this example) |
Reimplemented from makVre::DtPlayerComponent.
References makVre::DtPlayerComponent::player().
|
overridevirtual |
Per-frame update callback.
Called every frame by the player station framework. This example does not require per-frame processing, as it uses event-driven callbacks instead. The empty implementation demonstrates that tick() is optional for components that only respond to events.
| dt | Delta time in seconds since last update |
Implements makVre::DtPlayerComponent.
|
overridevirtual |
Shutdown callback for cleanup.
Performs cleanup before component destruction. This method demonstrates the VR-Engage pattern for proper callback cleanup:
The myAttributeCallbacks.disconnectAll() call ensures all registered callbacks are properly removed from the attribute store before the component is destroyed.
Reimplemented from makVre::DtPlayerComponent.
|
overridevirtual |
Returns the component type identifier.
This string is used by the component factory for instantiation and must match the registration in initPlayerStationModule().
Implements makVre::DtPlayerComponent.
|
protectedvirtual |
Callback invoked when the weaponIndex attribute changes.
This method demonstrates the VR-Engage pattern for attribute change callbacks. It is automatically called by the attribute store when the "weaponIndex" value changes, allowing the component to respond to state changes without polling.
The callback creates a temporary notification message that displays for 3 seconds as an overlay in the VR-Engage UI. This is accessed via the player station app's tempNotification() service.
PATTERN: Attribute callbacks provide an event-driven alternative to polling state in tick(). This is the recommended approach for responding to state changes as it's more efficient and maintains clear separation of concerns.
| index | The new weapon index value (0-based index into weapon list) |