VR-Engage  2.2
Loading...
Searching...
No Matches
vreRtdGlobal.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreRtdGlobal.h
7//! \ingroup vreVrfRtd
8//! \brief Global singleton manager for VREngage RTD components
9//!
10//! This file defines the DtVreRtdGlobal class, which provides global state management
11//! and coordination for the VREngage Real-Time Dynamics (RTD) system. It manages the
12//! RTD world, event callbacks, terrain queries, and message logging.
13
14#pragma once
15
16#include <RTD/World.h>
18
19class DtCgf;
20class DtScenario;
21
22namespace vreRtd
23{
24
25//! \brief Message forwarding listener from RTD to VRF Sim
26//!
27//! This class is responsible for forwarding messages from the RTD system
28//! to the VRF simulation environment, ensuring proper logging and message
29//! display in the user interface.
30class RTD_VRF_BACKEND_PLUGIN_EXPORT DtVreRtdPrinterListener : public smPrinter::Listener
31{
32public:
33 //! \brief Default constructor
35
36 //! \brief Default destructor
38
39 //! \brief Converts MAK notification level to RTD notification level
40 //! \param nl The MAK notification level to convert
41 //! \return The equivalent RTD notification level
42 //!
43 //! Translates between the MAK notification levels and the RTD notification
44 //! levels to ensure consistent severity mapping in log messages.
45 static smPrinter::NotifyLevel makNotifyLevelToRTD(int nl);
46
47 //! \brief Prints a message to the RTD logging system
48 //! \param msg The message to print
49 //!
50 //! Forwards a message to the RTD logging system with default severity.
51 virtual void print(const std::string& msg) override;
52
53 //! \brief Prints a message to the RTD logging system
54 //! \param msg The message to print
55 //!
56 //! Forwards a message to the RTD logging system with default severity.
57 virtual void print(const char* msg) override;
58
59 //! \brief Prints a message to the RTD logging system with specified severity
60 //! \param notLevel The notification level (severity) of the message
61 //! \param msg The message to print
62 //!
63 //! Forwards a message to the RTD logging system with the specified severity level.
64 virtual void print(smPrinter::NotifyLevel notLevel, const std::string& msg) override;
65
66 //! \brief Prints a message to the RTD logging system with specified severity
67 //! \param notLevel The notification level (severity) of the message
68 //! \param msg The message to print
69 //!
70 //! Forwards a message to the RTD logging system with the specified severity level.
71 virtual void print(smPrinter::NotifyLevel notLevel, const char* msg) override;
72};
73
74//! \brief Global singleton manager for VREngage RTD components
75//!
76//! This singleton class provides global state management and coordination for
77//! the VREngage Real-Time Dynamics (RTD) system. It manages the RTD world object,
78//! scenario event callbacks, configuration settings, and message logging.
79class RTD_VRF_BACKEND_PLUGIN_EXPORT DtVreRtdGlobal
80{
81public:
82 //! \brief Initializes the RTD plugin library
83 //!
84 //! Performs one-time initialization of the RTD plugin library, setting up
85 //! global resources and configurations. This should be called once during
86 //! application startup before using any RTD functionality.
87 static void pluginLibInit();
88
89 //! \brief Gets the singleton instance of the global RTD manager
90 //! \return Pointer to the singleton instance
91 //!
92 //! Returns the singleton instance of the global RTD manager, creating it
93 //! if it doesn't already exist. This is the proper way to access the global RTD state.
95
96 //! \brief Constructor
97 //!
98 //! Initializes a new instance of the global RTD manager. Normally this should
99 //! not be called directly - use getInstance() instead to access the singleton instance.
101
102 //! \brief Resets the global RTD state
103 //!
104 //! Resets the global RTD state to its initial configuration, clearing any
105 //! existing world state but preserving the RTD world object itself.
106 void reset();
107
108 //! \brief Destroys the global RTD manager
109 //!
110 //! Completely destroys the global RTD manager and all its resources,
111 //! including the RTD world object. This should be called during
112 //! application shutdown to ensure proper cleanup.
113 void destroy();
114
115 //! \brief Resets the RTD world
116 //!
117 //! Resets just the RTD world to its initial state, clearing all simulation
118 //! objects but preserving the world configuration.
120
121 //! \brief Destroys the RTD world
122 //!
123 //! Completely destroys the RTD world and all its resources. This is more
124 //! thorough than resetRTDWorld() and requires the world to be recreated
125 //! before it can be used again.
127
128 //! \brief Initializes the scenario event callbacks
129 //!
130 //! Sets up the callback functions that link the VRF scenario lifecycle events
131 //! (load, run, reset) to the appropriate RTD system responses.
133
134 //! \brief Static callback for scenario rollback events
135 //! \param data User data passed by the callback system
136 //!
137 //! Static callback function invoked before a scenario is rolled back.
138 //! Routes the callback to the processPreScenarioRollbackCallback method.
139 static void preScenarioRollbackCallback(void* data);
140
141 //! \brief Processes a scenario rollback event
142 //!
143 //! Handles the pre-scenario rollback event, preparing the RTD system
144 //! for the scenario to be rolled back to a previous state.
146
147 //! \brief Static callback for scenario load events
148 //! \param scenario The scenario being loaded
149 //! \param data User data passed by the callback system
150 //!
151 //! Static callback function invoked before a scenario is loaded.
152 //! Routes the callback to the processPreLoadScenario method.
153 static void preLoadScenarioCallback(DtScenario& scenario, void* data);
154
155 //! \brief Processes a scenario load event
156 //!
157 //! Handles the pre-load scenario event, preparing the RTD system
158 //! for a new scenario to be loaded.
160
161 //! \brief Static callback after scenario load completes
162 //! \param scenario The scenario that was loaded
163 //! \param data User data passed by the callback system
164 //!
165 //! Static callback function invoked after a scenario is loaded.
166 //! Routes the callback to the processPostLoadScenario method.
167 static void postLoadScenarioCallback(const DtScenario& scenario, void* data);
168
169 //! \brief Processes post-scenario load event
170 //!
171 //! Handles the post-load scenario event, finalizing RTD setup
172 //! after a new scenario has been loaded.
174
175 //! \brief Static callback for scenario run events
176 //! \param data User data passed by the callback system
177 //!
178 //! Static callback function invoked when a scenario starts running.
179 //! Routes the callback to the processScenarioRunCallback method.
180 static void scenarioRunCallback(void* data);
181
182 //! \brief Processes a scenario run event
183 //!
184 //! Handles the scenario run event, preparing the RTD system
185 //! to begin active simulation.
187
188 //! \brief Gets the RTD world object
189 //! \return Pointer to the RTD world
190 //!
191 //! Returns the current RTD world object being used for simulation.
192 RTD::World* rtdWorld() { return myRtdWorld; }
193
194 //! \brief Gets the RTD world object (const version)
195 //! \return Const pointer to the RTD world
196 //!
197 //! Returns the current RTD world object being used for simulation.
198 RTD::World* rtdWorld() const { return myRtdWorld; }
199
200 //! \brief Sets the RTD world object
201 //! \param val The new RTD world object
202 //!
203 //! Sets the RTD world object to be used for simulation.
204 void setRtdWorld(RTD::World* val) { myRtdWorld = val; }
205
206 //! \brief Gets the CGF object (const version)
207 //! \return Const pointer to the CGF object
208 //!
209 //! Returns the current CGF (Computer Generated Forces) object.
210 DtCgf* cgf() const { return myCgf; }
211
212 //! \brief Gets the CGF object
213 //! \return Pointer to the CGF object
214 //!
215 //! Returns the current CGF (Computer Generated Forces) object.
216 DtCgf* cgf() { return myCgf; }
217
218 //! \brief Sets the CGF object
219 //! \param val The new CGF object
220 //!
221 //! Sets the CGF (Computer Generated Forces) object to be used.
222 void setCgf(DtCgf* val) { myCgf = val; }
223
224 //! \brief Gets the default RTD fixed delta time (const version)
225 //! \return The default fixed delta time value
226 //!
227 //! Returns the default fixed delta time (in seconds) used for RTD simulation steps.
229
230 //! \brief Gets the default RTD fixed delta time
231 //! \return The default fixed delta time value
232 //!
233 //! Returns the default fixed delta time (in seconds) used for RTD simulation steps.
235
236 //! \brief Sets the default RTD fixed delta time
237 //! \param val The new default fixed delta time value
238 //!
239 //! Sets the default fixed delta time (in seconds) used for RTD simulation steps.
241
242 //! \brief Checks if terrain queries are blocking (const version)
243 //! \return True if terrain queries are blocking, false otherwise
244 //!
245 //! Returns whether terrain queries are set to block until completed.
247
248 //! \brief Checks if terrain queries are blocking
249 //! \return True if terrain queries are blocking, false otherwise
250 //!
251 //! Returns whether terrain queries are set to block until completed.
253
254 //! \brief Sets whether terrain queries are blocking
255 //! \param val True to make terrain queries blocking, false for non-blocking
256 //!
257 //! Sets whether terrain queries should block until completed or
258 //! operate asynchronously.
260
261 //! \brief Gets the printer listener (const version)
262 //! \return Const pointer to the printer listener
263 //!
264 //! Returns the current printer listener used for message forwarding.
266
267 //! \brief Gets the printer listener
268 //! \return Pointer to the printer listener
269 //!
270 //! Returns the current printer listener used for message forwarding.
272
273 //! \brief Sets the printer listener
274 //! \param val The new printer listener
275 //!
276 //! Sets the printer listener to be used for message forwarding.
278
279protected:
280 //! \brief Singleton instance of the global RTD manager
282
283 //! \brief The RTD world object
284 RTD::World* myRtdWorld;
285
286 //! \brief Flag indicating whether terrain queries are blocking
288
289 //! \brief Pointer to the CGF object
290 DtCgf* myCgf;
291
292 //! \brief Default fixed delta time for RTD simulation steps
294
295 //! \brief Printer listener for message forwarding
297};
298
299} // namespace vreRtd
static DtVreRtdGlobal * getInstance()
Gets the singleton instance of the global RTD manager.
DtCgf * cgf() const
Gets the CGF object (const version)
Definition vreRtdGlobal.h:210
void initializeCallbacks()
Initializes the scenario event callbacks.
void setCgf(DtCgf *val)
Sets the CGF object.
Definition vreRtdGlobal.h:222
RTD::World * rtdWorld()
Gets the RTD world object.
Definition vreRtdGlobal.h:192
bool myTerrainQueryBlocking
Flag indicating whether terrain queries are blocking.
Definition vreRtdGlobal.h:287
static void pluginLibInit()
Initializes the RTD plugin library.
DtVreRtdPrinterListener * myListener
Printer listener for message forwarding.
Definition vreRtdGlobal.h:296
static void postLoadScenarioCallback(const DtScenario &scenario, void *data)
Static callback after scenario load completes.
void destroy()
Destroys the global RTD manager.
static void scenarioRunCallback(void *data)
Static callback for scenario run events.
DtCgf * cgf()
Gets the CGF object.
Definition vreRtdGlobal.h:216
void setDefaultRtdFixedDeltaTime(smDouble val)
Sets the default RTD fixed delta time.
Definition vreRtdGlobal.h:240
vreRtd::DtVreRtdPrinterListener * printerListener()
Gets the printer listener.
Definition vreRtdGlobal.h:271
DtVreRtdGlobal()
Constructor.
smDouble defaultRtdFixedDeltaTime() const
Gets the default RTD fixed delta time (const version)
Definition vreRtdGlobal.h:228
bool isTerrainQueryBlocking() const
Checks if terrain queries are blocking (const version)
Definition vreRtdGlobal.h:246
void setTerrainQueryBlocking(bool val)
Sets whether terrain queries are blocking.
Definition vreRtdGlobal.h:259
void reset()
Resets the global RTD state.
vreRtd::DtVreRtdPrinterListener * printerListener() const
Gets the printer listener (const version)
Definition vreRtdGlobal.h:265
void destroyRTDWorld()
Destroys the RTD world.
DtCgf * myCgf
Pointer to the CGF object.
Definition vreRtdGlobal.h:290
static void preScenarioRollbackCallback(void *data)
Static callback for scenario rollback events.
void setRtdWorld(RTD::World *val)
Sets the RTD world object.
Definition vreRtdGlobal.h:204
bool isTerrainQueryBlocking()
Checks if terrain queries are blocking.
Definition vreRtdGlobal.h:252
static void preLoadScenarioCallback(DtScenario &scenario, void *data)
Static callback for scenario load events.
virtual void processPreLoadScenario()
Processes a scenario load event.
void resetRTDWorld()
Resets the RTD world.
void setPrinterListener(vreRtd::DtVreRtdPrinterListener *val)
Sets the printer listener.
Definition vreRtdGlobal.h:277
smDouble myDefaultRtdFixedDeltaTime
Default fixed delta time for RTD simulation steps.
Definition vreRtdGlobal.h:293
RTD::World * rtdWorld() const
Gets the RTD world object (const version)
Definition vreRtdGlobal.h:198
virtual void processScenarioRunCallback()
Processes a scenario run event.
static DtVreRtdGlobal * theRtdGlobalInstance
Singleton instance of the global RTD manager.
Definition vreRtdGlobal.h:281
virtual void processPreScenarioRollbackCallback()
Processes a scenario rollback event.
smDouble defaultRtdFixedDeltaTime()
Gets the default RTD fixed delta time.
Definition vreRtdGlobal.h:234
virtual void processPostLoadScenario()
Processes post-scenario load event.
RTD::World * myRtdWorld
The RTD world object.
Definition vreRtdGlobal.h:284
Message forwarding listener from RTD to VRF Sim.
Definition vreRtdGlobal.h:31
virtual void print(const std::string &msg) override
Prints a message to the RTD logging system.
virtual void print(smPrinter::NotifyLevel notLevel, const std::string &msg) override
Prints a message to the RTD logging system with specified severity.
~DtVreRtdPrinterListener()=default
Default destructor.
virtual void print(const char *msg) override
Prints a message to the RTD logging system.
DtVreRtdPrinterListener()=default
Default constructor.
static smPrinter::NotifyLevel makNotifyLevelToRTD(int nl)
Converts MAK notification level to RTD notification level.
virtual void print(smPrinter::NotifyLevel notLevel, const char *msg) override
Prints a message to the RTD logging system with specified severity.
Definition vreRtdConfigFileReader.h:18
Common definitions for the RTD backend library.