VR-Engage  2.2
Loading...
Searching...
No Matches
metaRoleControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file metaRoleControlLogic.h
7//! \brief Component for managing multiple sub-roles within a single player station
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
16
17#include <map>
18
19namespace makVre
20{
21class DtPlayerStation;
22
24{
25//! \ingroup RoleConfigParams
26//! \defgroup MetaRoleControlLogicRoleParams Meta Role Control Logic Role Parameters
27//! \roleInherits{PlayerComponentRoleParams}
28//! Configuration Options for meta role control logic role.
29//! @{
30
31//! \vreRoleParamRequired{inputConfigFile,string,metaRoleControlLogic,"input/metaRole.lua",Path to the input configuration file for meta role bindings.}
32constexpr const char* inputConfigFile = "inputConfigFile";
33
34//! \vreRoleParam{inputConfigGroup,string,"meta",metaRoleControlLogic,Input configuration group name within the input config file.}
35constexpr const char* inputConfigGroup = "inputConfigGroup";
36
37//! \vreRoleParam{nextSubRoleBinding,string,"next-sub-role",metaRoleControlLogic,Input action binding name for switching to the next sub-role.}
38constexpr const char* nextSubRoleBinding = "nextSubRoleBinding";
39
40//! \vreRoleParamRequired{subRoles,table,metaRoleControlLogic,{"role1","role2","role3"},Array of sub-role names that this meta role can switch between.}
41constexpr const char* subRoles = "subRoles";
42
43//! @}
44} // namespace MetaRoleControlLogicConfig
45
46//! \brief Type identifier for DtMetaRoleControlLogic component
47constexpr const char* DtMetaRoleControlLogicType = "DtMetaRoleControlLogic";
48
49//! \brief Player component that manages multiple sub-roles as a single unified role
50//!
51//! DtMetaRoleControlLogic instantiates and owns multiple sub-role PlayerStation instances,
52//! with input bindings to switch between them. This component creates a role that combines
53//! several role definitions into one group that behaves like a single role with multiple
54//! views or positions. For example, a tank crew member could switch between different
55//! stations within the vehicle.
57{
58public:
59 //! \brief Constructor for DtMetaRoleControlLogic
60 //!
61 //! Initializes component state with default values
63
64 //! \brief Virtual destructor for DtMetaRoleControlLogic
65 virtual ~DtMetaRoleControlLogic() override;
66
67 //! \brief Initializes the meta-role control component
68 //! \param player Pointer to the player station this component belongs to
69 //! \param config Configuration table containing meta-role settings
70 //! \return True if initialization succeeded, false otherwise
71 //!
72 //! Loads input configuration, creates sub-role player stations based on the
73 //! provided configurations, and prepares them for activation
74 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
75
76 //! \brief Performs post-initialization after all components are initialized
77 //! \return True if post-initialization succeeded, false otherwise
78 //!
79 //! Activates the first sub-role and checks that it initialized successfully
80 virtual bool postInitialize() override;
81
82 //! \brief Called every frame to update the meta-role and its sub-roles
83 //! \param dt Delta time since the last frame in seconds
84 //!
85 //! Updates all sub-role player stations, regardless of which one is active
86 virtual void tick(double dt) override;
87
88 //! \brief Shuts down the meta-role control component
89 //!
90 //! Shuts down all sub-role player stations and performs cleanup operations
91 virtual void shutdown() override;
92
93 //! \brief Returns the component type identifier
94 //! \return The component type string
95 virtual const char* type() const override;
96
97 //! \brief Activates a specific sub-role by name
98 //! \param station Name of the sub-role to activate
99 //!
100 //! Looks up the sub-role by name and activates it if found
101 virtual void activateSubRole(const std::string& station);
102
103 //! \brief Activates a specific sub-role by index
104 //! \param index Zero-based index of the sub-role to activate
105 //!
106 //! Shuts down the currently active sub-role and initializes the specified one
107 virtual void activateSubRole(int index);
108
109 //! \brief Input handler function to switch to the next sub-role
110 //! \param keyState Input value (> 0.5 to trigger the action)
111 //!
112 //! Cycles to the next sub-role in the list, wrapping around to the first
113 //! if the current role is the last one
114 virtual void nextSubRole(double keyState);
115
116 //! \brief Input handler function to switch to the previous sub-role
117 //! \param keyState Input value (> 0.5 to trigger the action)
118 //!
119 //! Cycles to the previous sub-role in the list, wrapping around to the last
120 //! if the current role is the first one
121 virtual void previousSubRole(double keyState);
122
123protected:
124 //! \brief Input logic that handles mapping of input actions to functions
126
127 //! \brief Collection of all sub-role player station instances
128 std::vector<DtPlayerStation*> mySubStations;
129
130 //! \brief Mapping from sub-role names to their indices in mySubStations
131 std::map<std::string, int> mySubStationIndex;
132
133 //! \brief Index of the currently active sub-role
135
137};
138
139} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:35
virtual const char * type() const override
Returns the component type identifier.
virtual void activateSubRole(const std::string &station)
Activates a specific sub-role by name.
virtual void activateSubRole(int index)
Activates a specific sub-role by index.
virtual void shutdown() override
Shuts down the meta-role control component.
DtMetaRoleControlLogic()
Constructor for DtMetaRoleControlLogic.
DtInputLogic myInputLogic
Input logic that handles mapping of input actions to functions.
Definition metaRoleControlLogic.h:125
int myCurrentSubStation
Index of the currently active sub-role.
Definition metaRoleControlLogic.h:134
virtual void previousSubRole(double keyState)
Input handler function to switch to the previous sub-role.
std::vector< DtPlayerStation * > mySubStations
Collection of all sub-role player station instances.
Definition metaRoleControlLogic.h:128
virtual void nextSubRole(double keyState)
Input handler function to switch to the next sub-role.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the meta-role control component.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
std::map< std::string, int > mySubStationIndex
Mapping from sub-role names to their indices in mySubStations.
Definition metaRoleControlLogic.h:131
virtual ~DtMetaRoleControlLogic() override
Virtual destructor for DtMetaRoleControlLogic.
double myActivateDelay
Definition metaRoleControlLogic.h:136
virtual void tick(double dt) override
Called every frame to update the meta-role and its sub-roles.
virtual DtPlayerStation & player()
Gets the player station.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
constexpr const char * subRoles
\vreRoleParamRequired{subRoles,table,metaRoleControlLogic,{"role1","role2","role3"}...
Definition metaRoleControlLogic.h:41
constexpr const char * inputConfigFile
Definition metaRoleControlLogic.h:32
constexpr const char * nextSubRoleBinding
Definition metaRoleControlLogic.h:38
constexpr const char * inputConfigGroup
Definition metaRoleControlLogic.h:35
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Defines the DtInputLogic class for handling input in VR-Engage.
Definition metaRoleControlLogic.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtMetaRoleControlLogicType
Type identifier for DtMetaRoleControlLogic component.
Definition metaRoleControlLogic.h:47
Defines the DtPlayerComponent base class for VR-Engage role components.