VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtPlayerStation Class Reference

Detailed Description

DtPlayerStation manages all aspects of a user's engagement with a simulation entity. It is responsible for handling user input, presenting the appropriate views, and controlling the entity according to the selected role.

Each instance is configured with a role definition that specifies:

  • Components that provide specific functionality
  • Connectors that handle communication with simulation protocols
  • Input mappings that translate user actions to simulation commands
  • Menu configurations for role-specific UI elements

The class maintains an attribute store for data sharing between components and manages the lifecycle of all component instances.

This class may be referred to as a Role, Station, or Player in different contexts.

Warning
Not thread safe. Used only in the display engine's main render thread.

#include <playerStation.h>

Public Types

using ComponentList = std::vector<DtPlayerComponent*>
 
using ConnectorNameList = std::vector<std::string>
 

Public Member Functions

 DtPlayerStation (DtPlayerStationApp *app, DtInitTable playerDefinition, DtEntityIdentifier attachTo, std::string stationName, std::string displayLayout)
 
virtual ~DtPlayerStation ()
 
virtual bool preInit ()
 
virtual bool initializeComponents ()
 
virtual bool postInitializeComponents ()
 
virtual bool initializeMenus ()
 
virtual bool finishInit ()
 
virtual void tick (double dt)
 
virtual void shutdown ()
 
virtual void takeVreControl (const std::string &stationNameOverride="")
 
virtual void releaseVreControl (const std::string &stationNameOverride="")
 
virtual void debugPlayer ()
 
virtual DtAttributeHandle & playerAttributeStore ()
 
virtual const DtAttributeHandle & playerAttributeStore () const
 
virtual const DtAttributeHandle & ownshipState () const
 
template<typename COMP_TYPE>
COMP_TYPE * findComponent (const std::string &name="")
 
template<typename COMP_TYPE>
std::vector< COMP_TYPE * > findComponents ()
 
virtual ConnectorNameList connectors (DtConnector::DtConnectorType connectionType)
 
virtual DtPlayerStationApp * app () const
 
virtual makVrv::DtDe * de () const
 
virtual makVrv::DtElementID elementId () const
 
virtual const DtEntityIdentifier & entityId () const
 
virtual const DtEntityType & entityType () const
 
virtual std::string stationName () const
 
virtual std::string displayLayout () const
 
virtual std::vector< std::string > roleTypes () const
 
virtual bool isActive () const
 
virtual bool isShuttingDown () const
 
virtual DtInitTable definition () const
 
virtual void tickUnreadyComponents (double dt)
 
virtual bool allComponentsReady () const
 
virtual bool anyComponentFailed () const
 

Protected Member Functions

virtual DtVreMessageResult handleSimulationStateMessage (makVre::DtVreMessage *msg)
 

Protected Attributes

DtPlayerStationApp * myApp
 
DtInitTable myPlayerDefinition
 
makVrv::DtElementID myElementId
 
DtEntityIdentifier myEntityId
 
DtEntityType myEntityType
 
DtForceType myForceType
 
std::vector< std::string > myRoleTypes
 
std::string myStationName
 
std::string myDisplayLayout
 
DtAttributeHandle myAttributeStore
 
const DtAttributeHandle myOwnshipState
 
ComponentList myComponents
 
ConnectorNameList myConnectorNames
 
bool myActive
 
bool myShuttingDown
 
makVrv::DtDe * myDe
 
bool myAnyComponentFailed = false
 
bool myAllComponentsReady = false
 
bool myFullyInitialized = false
 
std::map< size_t, bool[4]> myDebugAttributeTraceChecks
 

Member Typedef Documentation

◆ ComponentList

Type definition for a list of player components.

◆ ConnectorNameList

using makVre::DtPlayerStation::ConnectorNameList = std::vector<std::string>

Type definition for a list of connector names.

Constructor & Destructor Documentation

◆ DtPlayerStation()

makVre::DtPlayerStation::DtPlayerStation ( DtPlayerStationApp * app,
DtInitTable playerDefinition,
DtEntityIdentifier attachTo,
std::string stationName,
std::string displayLayout )

Constructor for a player station.

Parameters
appPointer to the player station application
playerDefinitionTable containing the role definition
attachToID of the entity this station will control
stationNameName of the chosen role
displayLayoutName of the display layout to use

Creates a new player station instance when a role is engaged. This happens when:

  • A user clicks Engage from the Choose Role menu
  • The station is configured to auto-engage at startup
  • A secondary role is created when an entity embarks in a host slot

The playerDefinition parameter contains the complete role configuration, which is assembled by merging the role definition from the .lua file, overrides from the .entity file, and display layout-specific settings. The stationName parameter identifies the chosen role from those available for the entity type. Available roles are defined in the .entity file, with each role specifying a .lua file containing its definition.

Role configuration files are located in the vre-roles-dir folder as defined in the .sms file (default: "data/simulationModelSets/VR-Engage/roles").

The displayLayout parameter specifies which layout to use with the chosen role. Roles can support multiple layouts that arrange views differently. Some roles only support a single layout, often called "default".

Warning
DtPlayerStation instances should only be created using DtPlayerStationApp::createPlayerStation and destroyed using DtPlayerStationApp::destroyPlayerStation.
See also
DtPlayerStationApp::createPlayerStation

References app(), displayLayout(), and stationName().

◆ ~DtPlayerStation()

virtual makVre::DtPlayerStation::~DtPlayerStation ( )
virtual

Destructor for a player station.

If this instance was created as a secondary role as a result of the primary ownship embarking in a role slot, then this secondary instance is destroyed when the primary ownship leaves that slot. If this instance is a primary role, then this instance is destroyed either when the VR-Engage app is closed, or when the user returns to the Choose Role panel.

Member Function Documentation

◆ preInit()

virtual bool makVre::DtPlayerStation::preInit ( )
virtual

Pre-initialization: validation, attribute setup, and state flags.

Returns
True if validation passed, false on fatal error

Validates the entity, element, type, and role definition. Sets up initial attributes in the attribute store and resets internal state flags. Must be called before initializeComponents().

◆ initializeComponents()

virtual bool makVre::DtPlayerStation::initializeComponents ( )
virtual

Instantiates all components in the role definition and calls initialize() on each.

Returns
True if all components initialized successfully

Called after preInit(). Creates component instances via the component factory and invokes initialize() with the per-component config table.

◆ postInitializeComponents()

virtual bool makVre::DtPlayerStation::postInitializeComponents ( )
virtual

Calls postInitialize() on all components.

Returns
True if all components return true from postInitialize()

Called after initializeComponents(). Gives each component a chance to perform setup that depends on peer components being initialized.

◆ initializeMenus()

virtual bool makVre::DtPlayerStation::initializeMenus ( )
virtual

Initializes menus via the DtActionMenuUpdater component.

Returns
True if menu initialization succeeded (or no menu component)

Called after postInitializeComponents(). Passes the menuConfig table from the role definition to the action menu updater component.

◆ finishInit()

virtual bool makVre::DtPlayerStation::finishInit ( )
virtual

Post-pipeline finalization: connectors, PlayerCreatedMessage.

Returns
True always (currently cannot fail)

Sets up connectors, sends the PlayerCreatedMessage, and performs any remaining post-menu-init work. Must be called after initializeMenus().

◆ tick()

virtual void makVre::DtPlayerStation::tick ( double dt)
virtual

Updates the player station.

Parameters
dtSeconds elapsed since the previous tick

Called once per display engine frame to update the player station. Updates all components and processes any pending operations.

◆ shutdown()

virtual void makVre::DtPlayerStation::shutdown ( )
virtual

Shuts down the player station.

Performs teardown of all setup done during initialization:

  • Destroys all components
  • Requests connectors to be stopped
  • Unregisters message handlers

Called when disengaging from this role, or when suspending this role temporarily when embarking into a different role slot.

◆ takeVreControl()

virtual void makVre::DtPlayerStation::takeVreControl ( const std::string & stationNameOverride = "")
virtual

Acquires VR-Engage role control for this station.

Queues a VrfSetVreControlledMessage that marks this station's role types as controlled. Does not queue a request for spectators, stations without role types, or meta roles. The optional override lets a sub-role report control using its owning station's name.

Parameters
stationNameOverrideStation name to include in the control request. Uses stationName() when empty.

DtLoadingPlayerState calls this method when initialization reaches its Complete phase. Override this method when a specialized station needs a different role-acquisition operation.

◆ releaseVreControl()

virtual void makVre::DtPlayerStation::releaseVreControl ( const std::string & stationNameOverride = "")
virtual

Releases VR-Engage role control for this station.

Called by DtPlayerStationApp immediately before permanently deleting a station. Shutdown preserves role occupancy so a suspended station remains engaged while another station is active. Does not queue a request for stations without role types or meta roles. The optional override lets a sub-role release control using its owning station's name.

Parameters
stationNameOverrideStation name to include in the release request. Uses stationName() when empty.

Override this method when a specialized station needs a different role-release operation.

◆ debugPlayer()

virtual void makVre::DtPlayerStation::debugPlayer ( )
virtual

Provides debugging information.

Invoked from the ImGui debug menu system to populate the Player tab of the Shift-F4 debug menu. Displays component status, attribute values, and other diagnostic information about the player station.

◆ playerAttributeStore() [1/2]

virtual DtAttributeHandle & makVre::DtPlayerStation::playerAttributeStore ( )
virtual

Gets the player attribute store.

Returns
Reference to the attribute store

The attribute store contains player/role data shared between components.

◆ playerAttributeStore() [2/2]

virtual const DtAttributeHandle & makVre::DtPlayerStation::playerAttributeStore ( ) const
virtual

Gets the player attribute store (const version)

Returns
Const reference to the attribute store

◆ ownshipState()

virtual const DtAttributeHandle & makVre::DtPlayerStation::ownshipState ( ) const
virtual

Gets the ownship state attribute handle.

Returns
Const reference to the ownship state attribute handle

References findComponent(), and findComponents().

◆ findComponent()

template<typename COMP_TYPE>
COMP_TYPE * makVre::DtPlayerStation::findComponent ( const std::string & name = "")

Finds a component by type and optional name.

Template Parameters
COMP_TYPEThe component type to find
Parameters
nameOptional name to match (empty to match by type only)
Returns
Pointer to the found component, or NULL if not found

Returns the first component that matches the template type. If a name is provided, both the type and name must match to find the component.

References myComponents.

Referenced by ownshipState().

◆ findComponents()

template<typename COMP_TYPE>
std::vector< COMP_TYPE * > makVre::DtPlayerStation::findComponents ( )

Finds all components of a specific type.

Template Parameters
COMP_TYPEThe component type to find
Returns
Vector of pointers to matching components

Returns a list of all components that match the specified template type.

References myComponents.

Referenced by ownshipState().

◆ connectors()

virtual ConnectorNameList makVre::DtPlayerStation::connectors ( DtConnector::DtConnectorType connectionType)
virtual

Gets the list of connectors by type.

Parameters
connectionTypeThe type of connectors to retrieve
Returns
List of connector names for the specified type

Returns a list of connectors belonging to this role with the ConnectorType protocol suffix appended to each name.

◆ app()

virtual DtPlayerStationApp * makVre::DtPlayerStation::app ( ) const
virtual

Gets the player station application.

Returns
Pointer to the application

Returns a pointer to the VR-Engage DtPlayerStationApp singleton. This pointer is provided in the constructor and saved for convenience. It should never be null and should remain valid for the life of this class.

Referenced by DtPlayerStation().

◆ de()

virtual makVrv::DtDe * makVre::DtPlayerStation::de ( ) const
virtual

Gets the display engine.

Returns
Pointer to the display engine

Returns a pointer to the VR-Vantage DtDe singleton. This pointer is obtained from app() during construction and saved for convenience. It should never be null and should remain valid for the life of this class.

◆ elementId()

virtual makVrv::DtElementID makVre::DtPlayerStation::elementId ( ) const
virtual

Gets the element ID for the controlled entity.

Returns
Element ID of the controlled entity

Returns the DtElementID associated with the entity that this player station controls in the display engine.

◆ entityId()

virtual const DtEntityIdentifier & makVre::DtPlayerStation::entityId ( ) const
virtual

Gets the entity ID for the controlled entity.

Returns
Reference to the entity identifier

Returns the DtEntityIdentifier of the entity that this player station controls.

◆ entityType()

virtual const DtEntityType & makVre::DtPlayerStation::entityType ( ) const
virtual

Gets the entity type for the controlled entity.

Returns
Reference to the entity type

Returns the DtEntityType of the entity that this player station controls.

◆ stationName()

virtual std::string makVre::DtPlayerStation::stationName ( ) const
virtual

Gets the name of the role.

Returns
String containing the station name

Returns the name of the role that this player station represents. This name is provided in the constructor and saved for reference. It should not change during the life of the player station.

Referenced by DtPlayerStation().

◆ displayLayout()

virtual std::string makVre::DtPlayerStation::displayLayout ( ) const
virtual

Gets the display layout name.

Returns
String containing the display layout name

Returns the name of the display layout chosen when the role was engaged. This is provided in the constructor and saved for reference. It should not change during the life of the player station.

Referenced by DtPlayerStation().

◆ roleTypes()

virtual std::vector< std::string > makVre::DtPlayerStation::roleTypes ( ) const
virtual

Gets the list of joystick function groups.

Returns
List of joystick function groups

Returns a list of joystick function groups that this station will control. Used internally with the VR-Forces Remote Control joystick API. This list is defined by the "roleTypes" table in the Role definition. Note that these strings do not correspond to "Roles" as the term is generally used elsewhere, meaning a PlayerStation definition or instance.

◆ isActive()

virtual bool makVre::DtPlayerStation::isActive ( ) const
virtual
Returns
true unless the Role has been suspended in the case of an emplicit engagement of an embarked Role. If the player embarks in a role slot, the active primary PlayerStation is supsneded and a new secondary PlayerStation instance is created for the embarked Role.

◆ isShuttingDown()

virtual bool makVre::DtPlayerStation::isShuttingDown ( ) const
virtual
Returns
True after shutdown has been called and remains True until the PlayerStation instance is either destroyed or re-initialized by calling init again.

◆ definition()

virtual DtInitTable makVre::DtPlayerStation::definition ( ) const
virtual
Returns
the lua config table defining the Connector, Component, and Menu configuration for this Role. This is the final configuration for this Role, after filtering and merging the associated Display Layout configuration. This table is built when the user engages a role and before the DtPlayerStation instance is created. It should not change thereafter.

◆ tickUnreadyComponents()

virtual void makVre::DtPlayerStation::tickUnreadyComponents ( double dt)
virtual

Calls finalizeInitTick(dt) on every component where componentReady() is false.

For each unready component, calls finalizeInitTick(dt). The component itself is responsible for setting myComponentReady = true when returning Ready. If finalizeInitTick() returns Failed, records the failure (queryable via anyComponentFailed()).

Called by LOADING_PLAYER_STATE during its ComponentReadiness phase.

Parameters
dtTime in seconds since the last tick

◆ allComponentsReady()

virtual bool makVre::DtPlayerStation::allComponentsReady ( ) const
virtual

Returns true when every component reports componentReady() == true.

Used by LOADING_PLAYER_STATE to determine when to advance from the ComponentReadiness phase to Complete.

◆ anyComponentFailed()

virtual bool makVre::DtPlayerStation::anyComponentFailed ( ) const
virtual

Returns true if any component's most recent finalizeInitTick() returned Failed.

Used by LOADING_PLAYER_STATE to detect unrecoverable initialization failures and abort back to CHOOSE_ROLE_STATE.

◆ handleSimulationStateMessage()

virtual DtVreMessageResult makVre::DtPlayerStation::handleSimulationStateMessage ( makVre::DtVreMessage * msg)
protectedvirtual

Handler for the SimulationStateMessage for this station's ownship entity. This function is used only to cache initial state values of the ownship entity from the first message receied after engagement. This handler is then unregistered. The initial state values are saved in the AttributeStore as: <DtEntityType> "entityType" <DtVector> "InitialPosition" <DtTaitBryan> "InitialOrientation" <DtEntityIdentifier> "InitialParent".

Member Data Documentation

◆ myApp

DtPlayerStationApp* makVre::DtPlayerStation::myApp
protected

Writes name, type, and value of each attribute in Attribute Store to a human-readable string. Returns vector of these strings, one per attribute. Used by debugPlayer to write the data in the Attribute Store to the F4 menu or log file.

Pointer to DtPlayerStationApp singleton that created and owns this DtPlayerStation instance. This should never be null.

◆ myPlayerDefinition

DtInitTable makVre::DtPlayerStation::myPlayerDefinition
protected

◆ myElementId

makVrv::DtElementID makVre::DtPlayerStation::myElementId
protected

◆ myEntityId

DtEntityIdentifier makVre::DtPlayerStation::myEntityId
protected

◆ myEntityType

DtEntityType makVre::DtPlayerStation::myEntityType
protected

◆ myForceType

DtForceType makVre::DtPlayerStation::myForceType
protected

◆ myRoleTypes

std::vector<std::string> makVre::DtPlayerStation::myRoleTypes
protected

◆ myStationName

std::string makVre::DtPlayerStation::myStationName
protected

◆ myDisplayLayout

std::string makVre::DtPlayerStation::myDisplayLayout
protected

◆ myAttributeStore

DtAttributeHandle makVre::DtPlayerStation::myAttributeStore
protected

◆ myOwnshipState

const DtAttributeHandle makVre::DtPlayerStation::myOwnshipState
protected

◆ myComponents

ComponentList makVre::DtPlayerStation::myComponents
protected

Referenced by findComponent(), and findComponents().

◆ myConnectorNames

ConnectorNameList makVre::DtPlayerStation::myConnectorNames
protected

◆ myActive

bool makVre::DtPlayerStation::myActive
protected

◆ myShuttingDown

bool makVre::DtPlayerStation::myShuttingDown
protected

◆ myDe

makVrv::DtDe* makVre::DtPlayerStation::myDe
protected

◆ myAnyComponentFailed

bool makVre::DtPlayerStation::myAnyComponentFailed = false
protected

Set to true if any component's finalizeInitTick() returns Failed.

Reset in preInit(). Checked by LOADING_PLAYER_STATE via anyComponentFailed().

◆ myAllComponentsReady

bool makVre::DtPlayerStation::myAllComponentsReady = false
mutableprotected

Cached result of allComponentsReady().

Once all components report ready, this is set to true so subsequent calls avoid iterating the entire component list every tick. Reset in preInit(). Mutable because allComponentsReady() is const and this is a pure cache of the iteration result.

◆ myFullyInitialized

bool makVre::DtPlayerStation::myFullyInitialized = false
protected

True once the full init pipeline (preInit through finishInit) has completed. Prevents tick() from running on a partially built station.

Reset in preInit(), set in finishInit().

◆ myDebugAttributeTraceChecks

std::map<size_t, bool[4]> makVre::DtPlayerStation::myDebugAttributeTraceChecks
protected

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