|
VR-Engage
2.2
|
Purpose: This example demonstrates how to monitor player state attributes and provide user feedback through VR-Engage's temporary notification system. It shows the pattern for registering callbacks on attribute changes and displaying timed notifications.
Observable Behavior: When running this example, you will see temporary notification messages appear when weapon selection changes. The notification displays "Weapon #N" where N is the weapon index, automatically dismisses after 3 seconds, and appears as an overlay in the VR-Engage UI.
Prerequisites: Understanding of Player Station Framework and familiarity with Player Attribute Store. Knowledge of callback/observer patterns is helpful.
Related Examples: The State Example demonstrates more complex state monitoring with custom UI.
This example demonstrates player component lifecycle implementation using DtPlayerComponent with proper initialization and shutdown. The implementation is a minimal component focused solely on notification logic. For complete details on component initialization, see Component Initialization.
The example also covers attribute store callbacks for registering change notifications on player state attributes. It uses DtAttributeCallbackCollection for automatic connection management and demonstrates type-safe attribute access with template-based callbacks.
Finally, the example shows how to create temporary notifications for timed overlay messages that provide user feedback. The implementation uses the DtPlayerStationTempNotification service and establishes a pattern for non-intrusive user notifications.
The plugin registers the notification component with VR-Engage's factory system:
The string "DtNotifyLogic" (defined as DtNotifyLogicType in the header) must match the componentType value in role configuration Lua files. Registration happens once at plugin load time, before any player stations are created.
The component monitors the weapon index attribute and displays notifications on change:
The DtAttributeCallbackCollection manages callback lifecycle automatically, disconnecting callbacks in shutdown() to prevent dangling references. The compiler ensures callback signatures match attribute types, and the code checks attribute existence before registration as a defensive measure.
When the weapon index changes, a temporary notification is displayed:
The notification duration (3.0 seconds) controls how long the message displays. The tempNotification() service provides non-blocking overlay display, and messages are automatically dismissed without user interaction. This pattern applies to any transient user feedback.
Build the example (see Environment Setup & Build Guide):
Install the plugin to the VR-Engage installation:
This copies the plugin to <VR-Engage-Install-Dir>\plugins64\vrEngage\release\exampleNotification.dll
Verify installation:
The toolkit installs an example simulation model set for this component at <VR-Engage-Install-Dir>\data\simulationModelSets\examples\notification.sms. This SMS includes a pre-configured Human role that demonstrates the notification component. To launch VR-Engage with this SMS as the default:
The example SMS provides roles/human.lua, which inherits from the standard humanBase.lua role and adds the DtNotifyLogic component:
This configuration demonstrates how to extend an existing role with additional components. The components table merges with the inherited components from humanBase.lua.
To add this component to your own role, add the following to your role configuration Lua file (e.g., <VR-Engage-Install-Dir>/data/simulationModelSets/<YourSMS>/roles/yourRole.lua):
The component monitors the standard weaponIndex attribute, which must be present in your role's attribute store. This attribute is typically populated by weapon system components in vehicle or human roles.
DtNotifyLogic component)Verification: Check the VR-Engage log file (the most recent *.log file in the MAK log directory, typically C:/MAK/logs or as configured via the MAK_LOG_DIR environment variable) for initialization messages. Successful initialization shows [NotifyLogic] Component initialized, while missing attributes produce [Example Notify] Failed to find state attribute "weaponIndex".
Plugin not loading: Verify the DLL is in <VR-Engage-Install-Dir>\plugins64\vrEngage\release\, check the VR-Engage log (most recent *.log file in the MAK log directory) for load errors, and ensure the role configuration includes the component group.
No notifications appear:
weaponIndex attribute not present in player attribute storeComponent not in role:
["notifyLogic"] component group with componentType = "DtNotifyLogic" to your role Lua file| Class | Base Class | Purpose | Header |
|---|---|---|---|
DtNotifyLogic | DtPlayerComponent | Monitors attributes and displays notifications | notifyLogic.h |
DtPlayerComponent::initialize() - Component lifecycle initializationDtPlayerAttributeStore::hasAttribute() - Check attribute existenceDtPlayerAttributeStore::operator[] - Access attribute by nameDtAttributeCallbackCollection::connect() - Register change callbackDtPlayerStationTempNotification::newNotification() - Display timed notificationDtPlayerStationApp::tempNotification() - Access notification serviceexampleNotification.dll (Windows)plugins64/vrEngage/release/Related Documentation: