VR-Engage  2.2
Loading...
Searching...
No Matches
vreSimComponent.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreSimComponent.h
7//! \ingroup vreVrfmodel
8//! \brief Base template class for VR-Engage simulation components
9//!
10//! This file defines the DtVreSimComponent template class which serves as the
11//! base class for VR-Engage simulation components. It extends VR-Forces base
12//! components with VR-Engage specific functionality such as player control detection
13//! and entity system name retrieval.
14
15#pragma once
16
17#include "vreVrfmodel/export.h"
18
19#pragma warning(push)
20#pragma warning(disable : 4100) // unused parameter
21#pragma warning(disable : 4244) // type conversion, possible loss of data
22
23#include <vrfobjcore/vrfObjectStateRepository.h>
24#include <vlutil/vlString.h>
25
26#pragma warning(pop)
27
28class DtSimulationServices;
29class DtComponentDescriptor;
30class DtReaderWriterRegistry;
31
32namespace makVre
33{
34//! \brief Base template class for VR-Engage simulation components
35//! \tparam ComponentBase The base component class to extend with VR-Engage functionality
36//!
37//! DtVreSimComponent is a template class that serves as the base for VR-Engage
38//! simulation components. It extends VR-Forces base component classes with VR-Engage
39//! specific functionality such as player control detection and entity system name
40//! retrieval. All VR-Engage components should derive from this template class.
41template <typename ComponentBase>
42class VREVRFMODEL_DLL DtVreSimComponent : public ComponentBase
43{
44public:
45 //! \brief Constructor
46 //! \param name The name of this component
47 //! \param owner The local object that owns this component
48 //! \param simManager The simulation services manager
49 //! \param desc Component descriptor with configuration parameters
50 //! \param parentRegistry Optional parent registry for reader/writer functionality
51 //!
52 //! Creates a new VR-Engage simulation component with the specified parameters.
53 //! Forwards all parameters to the base component class constructor.
54 DtVreSimComponent(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
55 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0)
56 : ComponentBase(name, owner, simManager, desc, parentRegistry)
57 {
58 }
59
60 //! \brief Virtual destructor
61 //!
62 //! Cleans up resources used by the VR-Engage simulation component.
63 //! Base component resources are cleaned up by the base class destructor.
64 virtual ~DtVreSimComponent() {}
65
66 //! \brief Checks if the entity is player controlled
67 //! \param role Optional role name to check for (empty string to check for any role)
68 //! \return True if the entity has the specified role or any role if no specific role is provided
69 //!
70 //! Determines whether the entity is under player control by checking for role assignments
71 //! in the entity's extended data. If a specific role is provided, checks only for that role.
72 //! If no role is specified, checks for any role assignment.
73 //!
74 //! In VR-Engage, player control is indicated by the presence of role assignments
75 //! stored as extended data entries with keys beginning with "role-".
76 bool isPlayerControlled(const std::string& role = "") const
77 {
78 if (!role.empty())
79 {
80 // return true if the specific role entry is not empty
81 const makVrf::DtVrfStateComponent* component =
82 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>();
83 const DtVrfObjectStateRepository::ExtendedData& extendedDataMap = component->extendedData();
84 std::string key = "role-" + role;
85 DtVrfObjectStateRepository::ExtendedData::const_iterator valueIter = extendedDataMap.find(key.c_str());
86 if (valueIter != extendedDataMap.end())
87 {
88 return true;
89 }
90 }
91 else
92 {
93 // No specific role given, search map for any entries with a key starting with "role-"
94 const DtVrfObjectStateRepository::ExtendedData& extendedDataMap =
95 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>()->extendedData();
96 DtVrfObjectStateRepository::ExtendedData::const_iterator iter = extendedDataMap.begin();
97 DtVrfObjectStateRepository::ExtendedData::const_iterator end = extendedDataMap.end();
98 for (; iter != end; ++iter)
99 {
100 // return true if we find any role entry that is not empty
101 if (iter->first.findString("role-") == 0 && !iter->second.isEmpty())
102 {
103 return true;
104 }
105 }
106 }
107 return false;
108 }
109
110 //! \brief Gets the entity's top-level system name
111 //! \return String containing the top-level system name from the entity definition
112 //!
113 //! Retrieves the name of the top-level system (direct child of base-system)
114 //! defined in the entity file. This is extracted from the full parent system name
115 //! by removing the "base-system." prefix and any suffixes after the first period.
116 //!
117 //! \note This implementation uses string manipulation since DtComponentSystem
118 //! does not provide a direct accessor for the top-level system name.
119 DtString entitySystemName() const
120 {
121 DtString name = this->parentSystem()->fullName();
122 if (name.findString("base-system") == 0)
123 {
124 name.snipFront('.');
125 }
126 name.snipBackToFirst('.');
127 return name;
128 }
129
130private:
131 //! \brief Default constructor (not implemented)
132 //!
133 //! Default constructor is private and not implemented to prevent
134 //! creation of instances without proper initialization.
136
137 //! \brief Copy constructor (not implemented)
138 //!
139 //! Copy constructor is private and not implemented to prevent
140 //! copy construction.
142
143 //! \brief Assignment operator (not implemented)
144 //! \return Reference to this object
145 //!
146 //! Assignment operator is private and not implemented to prevent assignment.
148};
149} // namespace makVre
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
Definition vreSimComponent.h:54
DtVreSimComponent()
Default constructor (not implemented)
DtVreSimComponent(const DtVreSimComponent &other)
Copy constructor (not implemented)
virtual ~DtVreSimComponent()
Virtual destructor.
Definition vreSimComponent.h:64
DtString entitySystemName() const
Gets the entity's top-level system name.
Definition vreSimComponent.h:119
bool isPlayerControlled(const std::string &role="") const
Checks if the entity is player controlled.
Definition vreSimComponent.h:76
DtVreSimComponent & operator=(const DtVreSimComponent &other)
Assignment operator (not implemented)
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49