VR-Engage  2.2
Loading...
Searching...
No Matches
playerComponent.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file playerComponent.h
7//! \brief Defines the DtPlayerComponent base class for VR-Engage role components
8//!
9//! This file contains the base class that all role components in VR-Engage must
10//! inherit from. Components provide specific functionality for roles, such as
11//! movement, weapons, sensors, and user interface elements. The component system
12//! allows roles to be composed from reusable building blocks.
13
14#pragma once
15
17
18#include "vreUtil/attribute.h"
19
20#include "vreUtil/initializer.h"
21#include <vrvUtil/DtProfiler.h>
22
23#include <string>
24
25namespace makVrv
26{
27class DtDe;
28}
29
30namespace makVre
31{
32//! \brief Forward declaration of the initialization table class
33class DtInitTable;
34
35//! \brief Forward declaration of the player station class
36class DtPlayerStation;
37
38//! \brief Forward declaration of the entity resolver class
40
42{
43//! \defgroup RoleConfigParams Role Configuration Parameters
44//! \brief Parameters used to configure player station role components.
45//!
46//! Role configuration parameters control the behavior of components within a player role.
47//! Each component type defines its own set of parameters that can be specified in role
48//! configuration files to customize component behavior.
49//! @hidegroupgraph
50//! \ingroup RoleConfigParams
51//! \defgroup PlayerComponentRoleParams Player Component Role Parameters
52//! \brief Base configuration options inherited by all player components.
53//!
54//! These parameters are available to all component types that inherit from DtPlayerComponent.
55//! They provide common configuration options for component identification and initialization.
56//! Component-specific parameters are documented in each component's own parameter group.
57//! @{
58
59//! \vreRoleParam{initAttributes,string,"",playerComponent,Table of initial attribute values to set during component initialization.}
60constexpr const char* initAttributes = "initAttributes";
61
62//! \vreRoleParam{name,string,"",playerComponent,Name to assign to this component instance for identification purposes.}
63constexpr const char* name = "name";
64
65//! @}
66} // namespace PlayerComponentConfig
67
68//! \brief Base class for all role components in VR-Engage
69//!
70//! DtPlayerComponent serves as the foundation for all components that can be
71//! added to player roles. Components encapsulate specific functionality, such as
72//! movement control, weapons systems, sensor management, and user interface elements.
73//!
74//! Components are instantiated by the player station during initialization based on
75//! the role definition. They have access to the player attribute store for sharing
76//! data with other components, and they receive tick calls for regular updates.
78{
79public:
80 //! \brief Constructor
81 //!
82 //! Creates a component
83 //! Called from DtPlayerStation::initializeComponents during player station initialization.
84 //! Each component has a unique type that identifies its functionality.
86
87 //! \brief Virtual destructor
88 //!
89 //! Ensures proper cleanup of derived component classes.
91
92 //! \brief Initializes the component
93 //! \param player Pointer to the player station that owns this component
94 //! \param config Configuration table with component settings
95 //! \return True if initialization was successful, false otherwise
96 //!
97 //! Called when the component is first created during player station initialization.
98 //! This method performs initial setup and calls initializeStateAttributes().
99 //! Components should override this method to perform type-specific initialization,
100 //! but must call the base class implementation first.
102
103 //! \brief Performs post-initialization setup
104 //! \return True if post-initialization was successful, false otherwise
105 //!
106 //! Called after all components have been created and initialized. This is when
107 //! required but not owned state attributes can be looked up in the state, or
108 //! dependent components can be located. Components can use this phase to establish
109 //! connections with other components in the player station.
110 virtual bool postInitialize();
111
112 //! \brief Updates the component
113 //! \param dt Time in seconds since the last tick
114 //!
115 //! Called once per frame to update the component's state.
116 //! All concrete component classes must implement this method.
117 virtual void tick(double dt) = 0;
118
119 //! \brief Shuts down the component
120 //!
121 //! Called when the player station is shutting down. Components should
122 //! override this method to release resources and perform cleanup operations.
123 virtual void shutdown();
124
125 //! \brief Gets the component type identifier
126 //! \return Reference to the component type string
127 //!
128 //! Returns the unique type identifier for this component class. The type string
129 //! is used by the component system to identify and instantiate components based
130 //! on role configuration. Each component class should return a consistent,
131 //! descriptive type name (e.g., "DtDriverControlLogic", "DtObserverUpdater").
132 //!
133 //! \note This is a pure virtual method that must be implemented by all derived classes.
134 virtual const char* type() const = 0;
135
136 //! \brief Sets the component name
137 //! \param name The name to assign to this component
138 //!
139 //! Sets a name for this component instance, which can be used to distinguish
140 //! between multiple components of the same type in a player station.
141 virtual void setName(const std::string& name);
142
143 //! \brief Gets the component name
144 //! \return Reference to the component name string
145 //!
146 //! Returns the name of this component instance, which may be empty if
147 //! no name was explicitly assigned.
148 virtual const std::string& name();
149
150 //! \brief Gets the player station
151 //! \return Reference to the player station that owns this component
152 //!
153 //! Provides access to the player station that this component belongs to.
155
156 //! \brief Gets the player attribute store
157 //! \return Reference to the attribute store
158 //!
159 //! Provides access to the attribute store of the player station, which
160 //! contains shared data that can be accessed by all components.
162
163 //! \brief Gets the player attribute store (const version)
164 //! \return Const reference to the attribute store
166
167protected:
168 //! \brief Initializes component state attributes
169 //!
170 //! Creates and initializes any player state attributes required by this component.
171 //! Derived component classes should override this method if they need to add
172 //! custom state attributes to the player attribute store.
174
175 //! \brief Component instance name
176 std::string myName;
177
178 //! \brief Component configuration table
180
181 //! \brief Pointer to the owning player station
183
184 //! \brief Pointer to the display engine (common to all components)
185 makVrv::DtDe* myDe;
186
187 //! \brief Pointer to the entity resolver (common to all components)
189
190 //! \brief Member-scope instance of Attribute callback manager
191 //!
192 //! Used to manage Attribute change callback connections and ensure that all
193 //! callbacks are unregistered when this class instance is destroyed.
195};
196
197} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Definition attributeCallback.h:166
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Entity resolution and mapping system.
Definition entityResolver.h:52
Table-based access to Lua state for configuration data.
Definition initializer.h:38
DtInitTable myConfig
Component configuration table.
Definition playerComponent.h:179
virtual void setName(const std::string &name)
Sets the component name.
virtual const char * type() const =0
Gets the component type identifier.
virtual DtAttributeHandle & playerAttributeStore()
Gets the player attribute store.
virtual const DtAttributeHandle & playerAttributeStore() const
Gets the player attribute store (const version)
virtual bool postInitialize()
Performs post-initialization setup.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config)
Initializes the component.
virtual void shutdown()
Shuts down the component.
virtual DtPlayerStation & player()
Gets the player station.
std::string myName
Component instance name.
Definition playerComponent.h:176
virtual ~DtPlayerComponent()
Virtual destructor.
virtual void tick(double dt)=0
Updates the component.
virtual void initializeStateAttributes()
Initializes component state attributes.
DtPlayerStation * myPlayer
Pointer to the owning player station.
Definition playerComponent.h:182
DtEntityResolver * myResolver
Pointer to the entity resolver (common to all components)
Definition playerComponent.h:188
DtAttributeCallbackManager myAttributeCallbacks
Member-scope instance of Attribute callback manager.
Definition playerComponent.h:194
makVrv::DtDe * myDe
Pointer to the display engine (common to all components)
Definition playerComponent.h:185
virtual const std::string & name()
Gets the component name.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
constexpr const char * initAttributes
Definition playerComponent.h:60
constexpr const char * name
Definition playerComponent.h:63
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Provides configuration initialization for VREngage components.
Definition playerComponent.h:42
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition appLauncherComponent.h:28