VR-Engage  2.2
Loading...
Searching...
No Matches
artPartUpdater.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file artPartUpdater.h
7//! \brief Defines the DtArtPartUpdater component that monitors and reflects the state of articulated parts.
8//!
9//! This component monitors the state of articulated parts in the engaged entity and provides
10//! boolean state attributes that can be used by other components to react to part states.
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
17
19
20namespace makVre
21{
22
24{
25//! \ingroup RoleConfigParams
26//! \defgroup ArtPartUpdaterRoleParams Art Part Updater Role Parameters
27//! \roleInherits{PlayerComponentRoleParams}
28//! Configuration Options for art part updater role.
29//! @{
30
31//! \vreRoleParamRequired{artParts,table,artPartUpdater,{},Table of articulated part configurations defining which parts to monitor and their thresholds.}
32constexpr const char* artParts = "artParts";
33
34//! @}
35} // namespace ArtPartUpdaterConfig
36
37//! \brief Type identifier for DtArtPartUpdater component
38constexpr const char* DtArtPartUpdaterType = "DtArtPartUpdater";
39
40//! \brief Component for monitoring and reflecting the state of articulated parts
41//!
42//! The DtArtPartUpdater monitors specified articulated parts of the engaged entity.
43//! For each configured part, it provides two state attributes:
44//! - has[PartName]: Boolean indicating if the entity has the specified articulated part
45//! - [partName]State: Boolean indicating if the part's parameter value meets a configured threshold
46//!
47//! This component is particularly useful for quickly determining states such as
48//! whether doors are open/closed or other articulated parts are in specific positions.
49//!
50//! Example Lua configuration:
51//! \code
52//! ["artPartUpdater"] = {
53//! componentType = "DtArtPartUpdater";
54//! priority = 5;
55//! artParts = {
56//! {part = 3232, label = "slingLoadDoor", param = "theta", trueThreshold = 0};
57//! {part = 7648, label = "cargoDoor", param = "theta", trueThreshold = 0};
58//! {part = 7680, label = "slidingDoor", param = "y", trueThreshold = 0};
59//! };
60//! };
61//! \endcode
63{
64public:
65 //! \brief Constructor for DtArtPartUpdater
66 //!
67 //! Initializes the component with the name "DtArtPartUpdater".
69
70 //! \brief Virtual destructor for DtArtPartUpdater
71 virtual ~DtArtPartUpdater() override;
72
73 //! \brief Initializes the component with configuration from Lua
74 //!
75 //! Processes the provided configuration to set up monitoring for specified
76 //! articulated parts. Creates state attributes for each part and registers
77 //! handlers for simulation state and menu action messages.
78 //!
79 //! \param player Pointer to the player station this component belongs to
80 //! \param config Configuration table containing initialization parameters, especially the artParts table
81 //! \return True if initialization succeeds, false otherwise
83
84 //! \brief Updates the component state (empty implementation)
85 //!
86 //! This method is called each frame, but currently has no implementation for this component.
87 //!
88 //! \param dt Delta time in seconds since the last tick
89 virtual void tick(double dt) override;
90
91protected:
92 //! \brief Sets the has[PartName] attribute in the state repository
93 //!
94 //! Creates or updates a state attribute of the form "has[PartName]" with the provided boolean value.
95 //! The first character of the part label is capitalized in the attribute name.
96 //!
97 //! \param partLabel The label of the articulated part
98 //! \param value The boolean value to set for the attribute
99 virtual void setHasPartAttribute(std::string partLabel, bool value);
100
101 //! \brief Handles simulation state messages
102 //!
103 //! Processes simulation state messages to extract articulated part information and
104 //! updates corresponding state attributes based on the configured mappings.
105 //! For each configured part that exists, sets has[PartName]=true and updates
106 //! [partName]State based on the comparison with the threshold value.
107 //!
108 //! \param msg The simulation state message to process
109 //! \return HANDLED if the message was successfully processed
111
112 //! \brief Handles menu action messages
113 //!
114 //! Processes menu action messages specifically for the "cargoDoor" action.
115 //! Based on the current cargoDoorState, sends appropriate entity task messages
116 //! to open or close the cargo ramp.
117 //!
118 //! \param msg The menu action message to process
119 //! \return HANDLED if the message was handled, IGNORED otherwise
121
122 //! \brief Shuts down the component
123 //!
124 //! Removes the simulation state and menu action message handlers.
125 virtual void shutdown() override;
126
127 //! \brief Returns the component type identifier
128 //! \return The component type string
129 virtual const char* type() const override;
130
131 //! \brief Structure defining parameters for monitoring an articulated part
132 using partVars = struct
133 {
134 //! \brief Label for the articulated part used in attribute names
135 std::string label;
136
137 //! \brief Parameter to monitor for the articulated part (e.g., "x", "y", "z", "psi", "theta", "phi")
138 std::string param;
139
140 //! \brief Threshold value for the parameter that determines when the part's state is considered true
141 int trueThreshold;
142 };
143
144 //! \brief Map of art part IDs to their monitoring parameters
145 //!
146 //! The map keys are DIS articulated part type enumeration values,
147 //! and the values are partVars structures.
148 std::map<int, partVars> myParts;
149};
150} // namespace makVre
std::map< int, partVars > myParts
Map of art part IDs to their monitoring parameters.
Definition artPartUpdater.h:148
DtArtPartUpdater()
Constructor for DtArtPartUpdater.
virtual void shutdown() override
Shuts down the component.
virtual const char * type() const override
Returns the component type identifier.
virtual void tick(double dt) override
Updates the component state (empty implementation)
virtual makVre::DtVreMessageResult handleSimState(makVre::DtVreMessage *msg)
Handles simulation state messages.
struct { std::string label; std::string param; int trueThreshold; } partVars
Structure defining parameters for monitoring an articulated part.
Definition artPartUpdater.h:132
virtual void setHasPartAttribute(std::string partLabel, bool value)
Sets the has[PartName] attribute in the state repository.
virtual ~DtArtPartUpdater() override
Virtual destructor for DtArtPartUpdater.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with configuration from Lua.
virtual DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles menu action messages.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines the logic for controlling entities in VR-Engage.
constexpr const char * artParts
Definition artPartUpdater.h:32
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition artPartUpdater.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtArtPartUpdaterType
Type identifier for DtArtPartUpdater component.
Definition artPartUpdater.h:38