VR-Engage  2.3
Loading...
Searching...
No Matches
vreVrvExtensions.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6//! \file vreVrvExtensions.h
7//! \brief Provides VREngage-specific extensions to the VR-Vantage runtime system
8//!
9//! This file contains declarations of classes needed to override the type of
10//! reflected entity list created in a DtVrlinkConnection. By default, VR-Vantage
11//! creates reflected entity list derived from DtReflectedEntityList. However, VR-Engage
12//! creates a DtVrfRemoteController that requires a DtReflectedExtEntityList. Therefore
13//! the reflected entity list created by VR-Vantage must be a DtReflectedExtEntityList,
14//! enabling a single list to be used and shared by multiple classes in the VR-Engage
15//! front-end. Overriding this requires replacing the DtReflectedEntityList and
16//! DtEntityStateRepository with corresponding DtReflectedExtEntityList and
17//! DtExtEntityStateRepository types.
18//!
19//! DtVreEntityReflectedListCreator and DtVreEntityStateInterceptorCreator instances
20//! are registered in DtConnectorAccessory::slot_onSimCreated(), ensuring that our
21//! derived reflected list and derived state repository classes get created by VR-Vantage.
22
23#pragma once
24
26
27#include <vrvVrl/DtVrlinkConnection.h>
28#include <vrvVrl/DtEntityStateInterceptorCreator.h>
29#include <vrvVrl/DtCustomReflectedEntityList.h>
30#include <vrvVrl/DtVrlinkReflectedAerodromeList.h>
31#include <vrfExtObjects/extEntityStateRepository.h>
32
34#include <vrfobjparam/smsLoader.h>
35
36#include <atomic>
37#include <mutex>
38
39class DtReflectedExtEntityList;
40class DtReflectedExtEntity;
41class DtExtEntityStateRepository;
42
43
44namespace makVre
45{
46//! \brief Type of derived reflected entity list to create in VR-Vantage's DtVrlinkConnection
47//!
48//! This type alias defines a custom reflected entity list based on DtReflectedExtEntityList,
49//! DtReflectedExtEntity, and DtExtEntityStateRepository classes
50using DtVreBaseCustomReflectedEntityList = makVrv::DT_PROTOCOL_NAMESPACE::DtCustomReflectedEntityList<
51 DtReflectedExtEntityList, DtReflectedExtEntity, DtExtEntityStateRepository>;
52
53//! \brief VREngage-specific implementation of the reflected entity list
54//!
55//! Extends the base custom reflected entity list to provide VREngage-specific functionality,
56//! including parameter database handling and interaction with simulation model sets.
57#pragma warning(push)
58#pragma warning(disable: 4661) // template explicit instantiation: no definition for entityUpdatedCallback/entityUpdated/processDiGuyPdu in base template TU
60{
61public:
62 //! \brief Constructor for non-HLA protocols
63 //! \param listener Reference to the entity element processor that will receive entity events
64 DtVreCustomReflectedEntityList(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor& listener)
66 {
67 }
68
69#if defined(DtHLA)
70 //! \brief Constructor for HLA protocol
71 //! \param listener Reference to the entity element processor that will receive entity events
72 //! \param regionsToUse Reference to the DDM regions to use for this entity list
74 makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor& listener, const DtDDMRegionSet& regionsToUse)
75 : DtVreBaseCustomReflectedEntityList(listener, regionsToUse)
76 {
77 }
78#endif
79
80 //! \brief Virtual destructor
81 //!
82 //! Removes message handlers registered during initialization
84
85 //! \brief Initializes the reflected entity list
86 //!
87 //! Registers parameter factories, the SMS message handler, and debug controls.
88 //! Called during reflected-list creation, after the connector's
89 //! signal_exerciseConnectionCreated callback registers the network dispatch thread.
90 virtual void initialize();
91
92 //! \brief Determines whether a reflected object is ready to join the list.
93 //! \param obj Pointer to the reflected object to check.
94 //! \return True when the object is ready to be added.
95 //!
96 //! Initializes the state-property schema and applies retained extended
97 //! attributes before the object is announced to list consumers.
98 virtual bool readyToAdd(DtReflectedObject* obj) override;
99
100 //! \brief Handles removal of a reflected entity.
101 //! \param ent Pointer to the entity being removed
102 //!
103 //! Removes cached initialization state before the entity pointer can be
104 //! reused for a subsequently reflected entity.
105 virtual void entityRemoved(DtReflectedEntity* ent) override;
106
107 //! \brief Handles entity updates
108 //! \param ent Pointer to the entity that was updated
109 //!
110 //! Overridden function to process entity updates
111 virtual void entityUpdated(DtReflectedEntity* ent) override;
112
113 //! \brief Gets the parameter database associated with this entity list
114 //! \return Non-owning pointer to the parameter database, or nullptr before loading.
115 //!
116 //! Returns the SMS loader's database. A non-null pointer alone does not indicate
117 //! that the most recent load succeeded.
118 DtVrfParameterDb* parameterDatabase();
119
120protected:
121 //! \brief Rebuilds reflected EESR state-property schemas after an SMS reload.
122 //!
123 //! Clears cached entity-type initialization state, then reinitializes each
124 //! reflected EESR from the current SMS parameter database. EESR initialization
125 //! replays retained extended attributes into the rebuilt schema.
126 //! Checks that the database and extended repositories are available.
128
129 //! \brief Discovers and initializes an entity with parameter data
130 //! \param obj Pointer to the reflected object to discover
131 //! \param entSR Pointer to the entity state repository
132 //!
133 //! Defers discovery until the SMS database and entity type are available.
134 //! Initializes from matching SMS parameters and checks the resulting initialized
135 //! flag and state/parameter property counts. Missing parameter types are logged once
136 //! per SMS refresh.
137 virtual void discoverEntityIfNecessary(DtReflectedObject* obj, DtExtEntityStateRepository* entSR);
138
139 //! \brief Handles simulation model set list messages
140 //! \param msg Pointer to the message containing the SMS list
141 //! \return Message result indicating how the message was handled
142 //!
143 //! Logs SMS receipt and load outcomes, and refreshes entity schemas after a
144 //! successful reload. Checks database availability for an unchanged cached list.
145 //! \note The completion acknowledgment is sent even if loading fails.
147
148 //! \brief Draws the state-property reception trace controls in the debug menu.
149 //!
150 //! Runs on the render thread as a DtVreDebugManager menu callback. All ImGui
151 //! calls are confined to this method because ImGui is not thread safe. The
152 //! controls only exchange data with the network thread through
153 //! myStatePropertyTraceEnabled and the mutex-guarded myTracedPropertyName.
155
156 //! \brief Logs extended-attribute (state property) reception for a reflected entity.
157 //! \param entSR Pointer to the entity state repository to inspect.
158 //!
159 //! Runs on the network-processing thread from entityUpdated() before the base
160 //! class consumes pending attribute updates; all reads are non-destructive
161 //! (markAsRead=false). Logs the traced property's value when it changes and
162 //! dumps the attribute inventory when its size changes. Does nothing unless
163 //! enabled from the debug menu.
164 virtual void traceStatePropertyReception(DtExtEntityStateRepository* entSR);
165
166protected:
167 //! \brief Loader for simulation model sets
168 DtSmsLoader mySmsLoader;
169
170 //! \brief Simulation model set filenames from the most recent successful load.
171 std::vector<std::string> mySms;
172
173 //! \brief Type alias for mapping reflected objects to entity types
174 using InitializedTypeMap = std::map<DtReflectedObject*, DtEntityType>;
175
176 //! \brief Map of reflected objects to their entity types
177 //!
178 //! Tracks which entities have been initialized with which entity types
180
181 //! \brief Type alias for the set of missing entity types
182 using MissingTypeSet = std::set<DtEntityType>;
183
184 //! \brief Set of entity types we know aren't in the parameter database
185 //!
186 //! This prevents entities with unknown parameter types from searching
187 //! the parameter database every time there's a network update
189
190 //! \brief Whether state-property reception tracing is enabled
191 //!
192 //! Written by the debug menu on the render thread and read by
193 //! traceStatePropertyReception() on the network thread.
194 std::atomic<bool> myStatePropertyTraceEnabled{false};
195
196 //! \brief Guards myTracedPropertyName, which is shared between threads
198
199 //! \brief Name of the state property whose value changes are traced
200 //!
201 //! Empty means only attribute-inventory changes are logged. Guarded by
202 //! myTracedPropertyMutex.
204
205 //! \brief ImGui edit buffer for the traced property name
206 //!
207 //! Only touched on the render thread inside drawStatePropertyTraceMenu().
209
210 //! \brief Last logged (attribute count, traced value) per state repository
211 //!
212 //! Used for change detection so the trace only logs transitions. Only
213 //! touched on the network thread.
214 std::map<const void*, std::pair<size_t, std::string>> myTraceLastLogged;
215};
216#pragma warning(pop)
217
218//! \brief Creator class for DtVreCustomReflectedEntityList instances
219//!
220//! This class overrides the default entity reflected list creator to produce
221//! VREngage-specific reflected entity lists
222class VRL_DLL DtVreEntityReflectedListCreator : public makVrv::DT_PROTOCOL_NAMESPACE::DtVrvEntityReflectedListCreator
223{
224public:
225 //! \brief Gets or creates the singleton instance for a specific connection
226 //! \param sim Reference to the VR-Link connection to associate with this creator
227 //! \return Reference to the singleton instance
228 static DtVrvEntityReflectedListCreator& instance(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection& sim);
229
230 //! \brief Creates a new reflected entity list
231 //! \param listener Reference to the entity element processor that will receive entity events
232 //! \return Pointer to the newly created reflected entity list
233 //!
234 //! Creates a DtVreCustomReflectedEntityList instance and initializes it
235 virtual DtReflectedEntityList* create(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor& listener) override;
236
237#if defined(DtHLA)
238 //! \brief Creates a new reflected entity list with DDM regions (HLA-specific)
239 //! \param l Reference to the entity element processor that will receive entity events
240 //! \param r Reference to the DDM regions to use
241 //! \return Pointer to the newly created reflected entity list
242 virtual DtReflectedEntityList* create(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor& l,
243 const DtDDMRegionSet& r) override;
244#endif
245
246protected:
247 //! \brief Constructor
248 //! \param sim Reference to the VR-Link connection to associate with this creator
249 DtVreEntityReflectedListCreator(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection& sim);
250};
251
252//! \brief Creator class for the DtEntityStateRepository derived from DtExtEntityStateRepository
253//!
254//! This class overrides the default entity state interceptor creator to produce
255//! VREngage-specific entity state repositories
256class VRL_DLL DtVreEntityStateInterceptorCreator : public makVrv::DT_PROTOCOL_NAMESPACE::DtEntityStateInterceptorCreator
257{
258public:
259 //! \brief Gets or creates the singleton instance for a specific connection
260 //! \param sim Reference to the VR-Link connection to associate with this creator
261 //! \return Reference to the singleton instance
262 static DtEntityStateInterceptorCreator& instance(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection& sim);
263
264 //! \brief Default constructor
266
267 //! \brief Virtual destructor
269
270 //! \brief Creates a new entity state repository
271 //! \param listener Pointer to the entity state listener that will receive entity state events
272 //! \return Pointer to the newly created entity state repository
273 //!
274 //! Creates an entity state interceptor using DtExtEntityStateRepository
275 virtual DtEntityStateRepository* create(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkEntityStateListener* listener) override;
276};
277
278//! \brief Creator class for aerodrome reflected lists
279//!
280//! This class overrides the default aerodrome reflected list creator to produce
281//! VREngage-specific aerodrome reflected lists based on DtReflectedExtAerodromeList
283 : public makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkReflectedAerodromeListCreator
284{
285public:
286 //! \brief Gets or creates the singleton instance for a specific connection
287 //! \param sim Reference to the VR-Link connection to associate with this creator
288 //! \return Reference to the singleton instance
289 static makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkReflectedAerodromeListCreator& instance(
290 makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection& sim);
291
292 //! \brief Creates a new aerodrome reflected list
293 //! \param l Reference to the aerodrome existence listener
294 //! \return Pointer to the newly created aerodrome reflected list
295 virtual DtReflectedAerodromeList* create(makVrv::DT_PROTOCOL_NAMESPACE::DtAerodromeExistenceListener& l) override;
296#if defined(DtHLA)
297 //! \brief Creates a new aerodrome reflected list with DDM regions (HLA-specific)
298 //! \param l Reference to the aerodrome existence listener
299 //! \param s Pointer to the DDM regions to use
300 //! \return Pointer to the newly created aerodrome reflected list
301 virtual DtReflectedAerodromeList* create(
302 makVrv::DT_PROTOCOL_NAMESPACE::DtAerodromeExistenceListener& l, const DtDDMRegionSet* s) override;
303#endif
304
305protected:
306 //! \brief Constructor
307 //! \param sim Reference to the VR-Link connection to associate with this creator
308 DtVreAerodromeReflectedListCreator(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection& sim);
309};
310
311} // namespace makVre
virtual DtReflectedAerodromeList * create(makVrv::DT_PROTOCOL_NAMESPACE::DtAerodromeExistenceListener &l, const DtDDMRegionSet *s) override
Creates a new aerodrome reflected list with DDM regions (HLA-specific)
virtual DtReflectedAerodromeList * create(makVrv::DT_PROTOCOL_NAMESPACE::DtAerodromeExistenceListener &l) override
Creates a new aerodrome reflected list.
static makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkReflectedAerodromeListCreator & instance(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &sim)
Gets or creates the singleton instance for a specific connection.
DtVreAerodromeReflectedListCreator(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &sim)
Constructor.
std::atomic< bool > myStatePropertyTraceEnabled
Whether state-property reception tracing is enabled.
Definition vreVrvExtensions.h:194
MissingTypeSet myMissingTypes
Set of entity types we know aren't in the parameter database.
Definition vreVrvExtensions.h:188
std::set< DtEntityType > MissingTypeSet
Type alias for the set of missing entity types.
Definition vreVrvExtensions.h:182
virtual ~DtVreCustomReflectedEntityList() override
Virtual destructor.
std::mutex myTracedPropertyMutex
Guards myTracedPropertyName, which is shared between threads.
Definition vreVrvExtensions.h:197
virtual void initialize()
Initializes the reflected entity list.
std::vector< std::string > mySms
Simulation model set filenames from the most recent successful load.
Definition vreVrvExtensions.h:171
DtSmsLoader mySmsLoader
Loader for simulation model sets.
Definition vreVrvExtensions.h:168
virtual void traceStatePropertyReception(DtExtEntityStateRepository *entSR)
Logs extended-attribute (state property) reception for a reflected entity.
virtual void entityRemoved(DtReflectedEntity *ent) override
Handles removal of a reflected entity.
std::string myTracedPropertyName
Name of the state property whose value changes are traced.
Definition vreVrvExtensions.h:203
std::map< DtReflectedObject *, DtEntityType > InitializedTypeMap
Type alias for mapping reflected objects to entity types.
Definition vreVrvExtensions.h:174
virtual void refreshReflectedEntityProperties()
Rebuilds reflected EESR state-property schemas after an SMS reload.
InitializedTypeMap myInitializedWithType
Map of reflected objects to their entity types.
Definition vreVrvExtensions.h:179
virtual void discoverEntityIfNecessary(DtReflectedObject *obj, DtExtEntityStateRepository *entSR)
Discovers and initializes an entity with parameter data.
virtual void drawStatePropertyTraceMenu()
Draws the state-property reception trace controls in the debug menu.
virtual bool readyToAdd(DtReflectedObject *obj) override
Determines whether a reflected object is ready to join the list.
DtVreCustomReflectedEntityList(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor &listener)
Constructor for non-HLA protocols.
Definition vreVrvExtensions.h:64
virtual void entityUpdated(DtReflectedEntity *ent) override
Handles entity updates.
DtVrfParameterDb * parameterDatabase()
Gets the parameter database associated with this entity list.
virtual DtVreMessageResult handleSessionSmsList(DtVreMessage *msg)
Handles simulation model set list messages.
char myTracedPropertyInputBuffer[64]
ImGui edit buffer for the traced property name.
Definition vreVrvExtensions.h:208
std::map< const void *, std::pair< size_t, std::string > > myTraceLastLogged
Last logged (attribute count, traced value) per state repository.
Definition vreVrvExtensions.h:214
DtVreCustomReflectedEntityList(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor &listener, const DtDDMRegionSet &regionsToUse)
Constructor for HLA protocol.
Definition vreVrvExtensions.h:73
virtual DtReflectedEntityList * create(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor &l, const DtDDMRegionSet &r) override
Creates a new reflected entity list with DDM regions (HLA-specific)
static DtVrvEntityReflectedListCreator & instance(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &sim)
Gets or creates the singleton instance for a specific connection.
DtVreEntityReflectedListCreator(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &sim)
Constructor.
virtual DtReflectedEntityList * create(makVrv::DT_PROTOCOL_NAMESPACE::DtEntityElementProcessor &listener) override
Creates a new reflected entity list.
virtual ~DtVreEntityStateInterceptorCreator() override
Virtual destructor.
DtVreEntityStateInterceptorCreator()
Default constructor.
static DtEntityStateInterceptorCreator & instance(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &sim)
Gets or creates the singleton instance for a specific connection.
virtual DtEntityStateRepository * create(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkEntityStateListener *listener) override
Creates a new entity state repository.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export macros and protocol namespace for vrePlayerStationConnector.
#define VRL_DLL
Empty definition for non-Windows platforms.
Definition export.h:52
!
Definition glsVreMessageUtil.h:50
makVrv::DT_PROTOCOL_NAMESPACE::DtCustomReflectedEntityList< DtReflectedExtEntityList, DtReflectedExtEntity, DtExtEntityStateRepository > DtVreBaseCustomReflectedEntityList
Type of derived reflected entity list to create in VR-Vantage's DtVrlinkConnection.
Definition vreVrvExtensions.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.