VR-Engage  2.3
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
18
20
21#include <map>
22
23namespace makVre
24{
25class DtPlayerStation;
26
28{
29//! \ingroup RoleConfigParams
30//! \defgroup MetaRoleControlLogicRoleParams Meta Role Control Logic Role Parameters
31//! \roleInherits{PlayerComponentRoleParams}
32//! Configuration Options for meta role control logic role.
33//! @{
34
35//! \vreRoleParamRequired{inputConfigFile,string,metaRoleControlLogic,"input/metaRole.lua",Path to the input configuration file for meta role bindings.}
36constexpr const char* inputConfigFile = "inputConfigFile";
37
38//! \vreRoleParam{inputConfigGroup,string,"meta",metaRoleControlLogic,Input configuration group name within the input config file.}
39constexpr const char* inputConfigGroup = "inputConfigGroup";
40
41//! \vreRoleParam{nextSubRoleBinding,string,"next-sub-role",metaRoleControlLogic,Input and Menu action binding name for switching to the next sub-role.}
42constexpr const char* nextSubRoleBinding = "nextSubRoleBinding";
43
44//! \vreRoleParam{nextSubRoleInputAction,string,"next-sub-role",metaRoleControlLogic,Input action binding name for switching to the next sub-role.}
45constexpr const char* nextSubRoleInputAction = "nextSubRoleInputAction";
46
47//! \vreRoleParam{nextSubRoleMenuAction,string,"next-sub-role",metaRoleControlLogic,Menu action binding name for switching to the next sub-role.}
48constexpr const char* nextSubRoleMenuAction = "nextSubRoleMenuAction";
49
50//! \vreRoleParamRequired{subRoles,table,metaRoleControlLogic,{"role1","role2","role3"},Array of sub-role names that this meta role can switch between.}
51constexpr const char* subRoles = "subRoles";
52
53//! @}
54} // namespace MetaRoleControlLogicConfig
55
56//! \brief Type identifier for DtMetaRoleControlLogic component
57constexpr const char* DtMetaRoleControlLogicType = "DtMetaRoleControlLogic";
58
59//! \brief Player component that manages multiple sub-roles as a single unified role
60//!
61//! DtMetaRoleControlLogic instantiates and owns multiple sub-role PlayerStation instances,
62//! with input bindings to switch between them. This component creates a role that combines
63//! several role definitions into one group that behaves like a single role with multiple
64//! views or positions. For example, a tank crew member could switch between different
65//! stations within the vehicle.
67{
68public:
69 //! \brief Constructor for DtMetaRoleControlLogic
70 //!
71 //! Initializes component state with default values
73
74 //! \brief Virtual destructor for DtMetaRoleControlLogic
75 virtual ~DtMetaRoleControlLogic() override;
76
77 //! \brief Initializes the meta-role control component
78 //! \param player Pointer to the player station this component belongs to
79 //! \param config Configuration table containing meta-role settings
80 //! \return True if initialization succeeded, false otherwise
81 //!
82 //! Loads input configuration, creates sub-role player stations based on the
83 //! provided configurations, and prepares them for activation
84 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
85
86 //! \brief Performs post-initialization after all components are initialized
87 //! \return True if post-initialization succeeded, false otherwise
88 //!
89 //! Activates the first sub-role and checks that it initialized successfully
90 virtual bool postInitialize() override;
91
92 //! \brief Called every frame to update the meta-role and its sub-roles
93 //! \param dt Delta time since the last frame in seconds
94 //!
95 //! Updates all sub-role player stations, regardless of which one is active
96 virtual void tick(double dt) override;
97
98 //! \brief Shuts down the meta-role control component
99 //!
100 //! Shuts down all sub-role player stations and performs cleanup operations
101 virtual void shutdown() override;
102
103 //! \brief Returns the component type identifier
104 //! \return The component type string
105 virtual const char* type() const override;
106
107 //! \brief Activates a specific sub-role by name
108 //! \param station Name of the sub-role to activate
109 //!
110 //! Looks up the sub-role by name and activates it if found
111 virtual void activateSubRole(const std::string& station);
112
113 //! \brief Activates a specific sub-role by index
114 //! \param index Zero-based index of the sub-role to activate
115 //!
116 //! Shuts down the currently active sub-role and initializes the specified one
117 virtual void activateSubRole(int index);
118
119 //! \brief Input handler function to switch to the next sub-role
120 //! \param keyState Input value (> 0.5 to trigger the action)
121 //!
122 //! Cycles to the next sub-role in the list, wrapping around to the first
123 //! if the current role is the last one
124 virtual void nextSubRole(double keyState);
125
126 //! \brief Input handler function to switch to the previous sub-role
127 //! \param keyState Input value (> 0.5 to trigger the action)
128 //!
129 //! Cycles to the previous sub-role in the list, wrapping around to the last
130 //! if the current role is the first one
131 virtual void previousSubRole(double keyState);
132
133 //! \brief Returns the currently active sub-station, or nullptr if none.
135
136 //! \brief Handles menu messages related to sub-role switching
138
139protected:
141
142protected:
143 //! \brief Input logic that handles mapping of input actions to functions
145
146 //! \brief Owning collection of all sub-role player station instances.
147 //!
148 //! Clearing the collection destroys every sub-station, including ones created before a
149 //! sub-role initialization failure.
150 std::vector<std::unique_ptr<DtPlayerStation>> mySubStations;
151
152 //! \brief Mapping from sub-role names to their indices in mySubStations
153 std::map<std::string, int> mySubStationIndex;
154
155 //! \brief Index of the currently active sub-role
157
159
160 std::string myMenuAction;
161
163};
164
165} // namespace makVre
Definition functionQueue.h:26
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:39
DtPlayerStation * currentSubStation() const
Returns the currently active sub-station, or nullptr if none.
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.
std::vector< std::unique_ptr< DtPlayerStation > > mySubStations
Owning collection of all sub-role player station instances.
Definition metaRoleControlLogic.h:150
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:144
DtFunctionQueue myFunctionQueue
Definition metaRoleControlLogic.h:162
int myCurrentSubStation
Index of the currently active sub-role.
Definition metaRoleControlLogic.h:156
virtual void previousSubRole(double keyState)
Input handler function to switch to the previous sub-role.
virtual void nextSubRole(double keyState)
Input handler function to switch to the next sub-role.
virtual bool initializeStation(DtPlayerStation *ps)
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:153
virtual ~DtMetaRoleControlLogic() override
Virtual destructor for DtMetaRoleControlLogic.
double myActivateDelay
Definition metaRoleControlLogic.h:158
DtVreMessageResult handleMenuMessage(DtVreMessage *msg)
Handles menu messages related to sub-role switching.
std::string myMenuAction
Definition metaRoleControlLogic.h:160
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
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Deferred function queue.
constexpr const char * nextSubRoleInputAction
Definition metaRoleControlLogic.h:45
constexpr const char * subRoles
\vreRoleParamRequired{subRoles,table,metaRoleControlLogic,{"role1","role2","role3"}...
Definition metaRoleControlLogic.h:51
constexpr const char * inputConfigFile
Definition metaRoleControlLogic.h:36
constexpr const char * nextSubRoleBinding
Definition metaRoleControlLogic.h:42
constexpr const char * nextSubRoleMenuAction
Definition metaRoleControlLogic.h:48
constexpr const char * inputConfigGroup
Definition metaRoleControlLogic.h:39
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:28
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtMetaRoleControlLogicType
Type identifier for DtMetaRoleControlLogic component.
Definition metaRoleControlLogic.h:57
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines the base class for all VREngage messages.