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

Detailed Description

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:

  • Subscribing to attribute changes via attribute callbacks
  • Accessing the player attribute store
  • Creating temporary overlay notifications with duration
  • Component lifecycle (initialize, tick, shutdown)
  • Proper callback cleanup during shutdown

This class inherits from DtPlayerComponent and is registered with the player station's component factory for role-based instantiation.

#include <notifyLogic.h>

Inheritance diagram for DtNotifyLogic:
[legend]

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 DtPlayerStationplayer ()
 
virtual DtAttributeHandleplayerAttributeStore ()
 
virtual const DtAttributeHandleplayerAttributeStore () 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
 
DtPlayerStationmyPlayer
 
makVrv::DtDe * myDe
 
DtEntityResolvermyResolver
 
DtAttributeCallbackManager myAttributeCallbacks
 

Constructor & Destructor Documentation

◆ DtNotifyLogic()

DtNotifyLogic::DtNotifyLogic ( )

Default constructor.

Initializes the notification logic component. The actual setup is performed in initialize() following the VR-Engage component lifecycle pattern.

◆ ~DtNotifyLogic()

virtual DtNotifyLogic::~DtNotifyLogic ( )
overridevirtual

Virtual destructor.

Cleanup is performed in shutdown() rather than the destructor to ensure proper framework ordering during component destruction.

Member Function Documentation

◆ initialize()

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

Initializes the component with player station and configuration.

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

  1. Call base class initialize() first
  2. Access player attribute store to find monitored attributes
  3. Register attribute callbacks for state change notifications
  4. Handle missing attributes gracefully with warnings

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.

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

Reimplemented from makVre::DtPlayerComponent.

References makVre::DtPlayerComponent::player().

◆ tick()

virtual void DtNotifyLogic::tick ( double dt)
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.

Parameters
dtDelta time in seconds since last update

Implements makVre::DtPlayerComponent.

◆ shutdown()

virtual void DtNotifyLogic::shutdown ( )
overridevirtual

Shutdown callback for cleanup.

Performs cleanup before component destruction. This method demonstrates the VR-Engage pattern for proper callback cleanup:

  1. Call base class shutdown() first
  2. Disconnect all attribute callbacks to prevent dangling pointers

The myAttributeCallbacks.disconnectAll() call ensures all registered callbacks are properly removed from the attribute store before the component is destroyed.

Reimplemented from makVre::DtPlayerComponent.

◆ type()

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

Returns the component type identifier.

This string is used by the component factory for instantiation and must match the registration in initPlayerStationModule().

Returns
The component type string "DtNotifyLogic"

Implements makVre::DtPlayerComponent.

◆ handleWeaponIndexChanged()

virtual void DtNotifyLogic::handleWeaponIndexChanged ( int index)
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.

Parameters
indexThe new weapon index value (0-based index into weapon list)

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