VR-Engage  2.3
Loading...
Searching...
No Matches
debugManager.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6#pragma once
7
8//! \file debugManager.h
9//! \ingroup vreDebugManager
10//! \brief Contains the debug manager class declaration for the VREngage system.
11//!
12//! This file defines the DtVreDebugManager class which is the central interface for all
13//! debugging functionality in VREngage. It controls debug rendering, menu system, and
14//! debug message passing throughout the application.
15//!
16//! This file defines the DtVreDebugManager class, which is the primary interface
17//! for managing debug functionality in VR-Engage. It provides access to the debug renderer,
18//! debug menu configuration, and other debugging utilities.
19
22#include "vreUtil/delegate.h"
23#include "vreUtil/attribute.h"
24
25#include <list>
26
27//! \brief The DtVreDebugManager is the primary interface to and manager of all of the
28//! debug aspects of VR-Engage.
29//!
30//! The primary purpose of this class is to provide a singular interface for
31//! functions to access several aspects of debugging VR-Engage through IMGui.
32//! You can access the debug renderer, the state manager, etc. You register for a callback
33//! and then when the tab is live, the callback will be invoked.
34//!
35//! See the exampleDebugPlugin for implementation examples.
36//!
37//! \note Application developers will want to ensure that any additions or subtractions
38//! to the physical elements in the environment, at a structural level, are accounted
39//! for in this class's interface. For instance, if a new type of terrain element
40//! is added to the simulation, such as an implicit surface instead of a polygon,
41//! the queries of this class must be updated.
42
43class DtSimulationAddress;
44
45namespace makVrv
46{
47class DtDe;
48}
49
50namespace makVre
51{
52// Forward Declares
53class DtDebugRenderer;
56class DtInitializer;
58
59//! Defines the position where callbacks are registered in the callback list
61{
62 FRONT = 0, //!< Add callback to the front of the list (executed first)
63 BACK //!< Add callback to the back of the list (executed last)
64};
65
66// Typedefs
68using DebugMenuCallbackList = std::list<DtVreDebugMenuCallback>;
69using DebugConfigurationValue = std::pair<DtVreDebugMenuConfiguration, DebugMenuCallbackList>;
70using DebugMenuConfigurationMap = std::map<std::string, DebugConfigurationValue>;
71
73using DebugEnabledCallbackList = std::list<DtVreDebugEnabledCallback>;
74
75//! \brief Configuration structure for debug processes
76//!
77//! Contains the necessary information to configure and identify a debug process
78//! within the VREngage debug system.
80{
81 //! \brief Enumeration of process types that can be debugged
82 enum class Process
83 {
84 VRE_APP = 0, //!< VREngage application process
85 VRF_APP, //!< VRForces application process
86 VRE_SIM, //!< VREngage simulation process
87 VRF_SIM //!< VRForces simulation process
88 };
89
90 //! \brief Display name of the debug process
91 std::string displayName;
92 //! \brief Type identifier for the debug process
93 std::string debugType;
94 //! \brief Menu section where this process should appear
95 std::string menuSection;
96 //! \brief Type of process (VREngage or VRForces, app or sim)
98 //! \brief Simulation address for this debug process
99 DtSimulationAddress address;
100 //! \brief Whether the debug process is enabled
102 //! \brief Whether to show this process in the debug table
104 //! \brief Additional data associated with this debug process
106};
107
108//! \brief Configuration structure for debug menus
109//!
110//! Contains the necessary information to configure a debug menu section
111//! within the VREngage debug UI system.
113{
114 //! \brief Description of this debug menu section
115 std::string description;
116 //! \brief List of configurable debug processes in this menu section
117 std::vector<DtConfigurableDebugProcess> configurableOptions;
118
119 //! \brief Default constructor that initializes with empty values
125};
126
127//! \brief Main debug manager class for VREngage
128//!
129//! This singleton class provides the central interface for all debugging
130//! functionality in VREngage, including menu management, debug rendering,
131//! and debug message passing throughout the application.
133{
134public:
135 //! \brief Gets the singleton debug manager instance
136 //! \return Pointer to the singleton instance
138
139 //! \brief Installs the full debug system with rendering capabilities
140 //! \param de The graphics engine to attach the debug renderer to
141 static void installFull(makVrv::DtDe&);
142
143 //! \brief Installs a lightweight version of the debug system without rendering
144 //!
145 //! Use this when no graphics engine is available but debugging is still required
146 static void installLite();
147
148 //! \brief Cleans up and shuts down the debug system
149 //!
150 //! Releases all resources and destroys the singleton instance
151 static void shutdown();
152
153 //! \brief Registers a callback for a specific debug menu section
154 //!
155 //! The callback will be invoked when the specified debug menu section is active
156 //! \param sec The section name to register the callback for
157 //! \param cb The callback function to register
158 //! \param position Where to place the callback in the execution order
159 //! \return True if the callback was successfully registered
161 const std::string& sec, const DtVreDebugMenuCallback& cb, CallbackPosition position = CallbackPosition::BACK);
162 //! \brief Removes a previously registered debug menu callback
163 //! \param cb The callback to remove
164 //! \return True if the callback was found and removed
166
167 //! \brief Registers a callback that is triggered when debug rendering is enabled/disabled
168 //!
169 //! This callback will be invoked when the debug rendering enabled state changes
170 //! \param cb The callback function to register
171 //! \param position Where to place the callback in the execution order
172 //! \return True if the callback was successfully registered
175 //! \brief Removes a previously registered debug enabled callback
176 //! \param cb The callback to remove
177 //! \return True if the callback was found and removed
179
180 //! \brief Adds a new debug menu entry to the debug UI
181 //! \param name The name of the menu entry
182 //! \param conf The configuration for this menu entry
183 virtual void addDebugMenuEntry(const std::string& name, DtVreDebugMenuConfiguration conf);
184 //! \brief Removes a debug menu entry from the debug UI
185 //! \param name The name of the menu entry to remove
186 virtual void removeDebugMenuEntry(const std::string& name);
187
188 //! \brief Gets an iterator to a debug menu configuration by name
189 //! \param name The name of the menu configuration to find
190 //! \return Iterator to the debug menu configuration, or end() if not found
191 DebugMenuConfigurationMap::iterator getDebugMenuConfiguration(const std::string& name);
192 //! \brief Gets a debug process by type and simulation address
193 //! \param type The type of debug process to find
194 //! \param address The simulation address of the process
195 //! \param proc The found debug process configuration (output parameter)
196 //! \return True if the process was found, false otherwise
197 bool getDebugProcess(const std::string& type, DtSimulationAddress address, DtConfigurableDebugProcess& proc);
198
199 //! \brief Gets all debug processes matching a given type within a menu section
200 //! \param menuSection The menu section name to search (e.g. "Sim")
201 //! \param debugType The debug type to filter by (e.g. "sim.remoteDebugger")
202 //! \return Vector of pointers to matching configurable debug processes
203 std::vector<DtConfigurableDebugProcess*> getDebugProcessesByType(
204 const std::string& menuSection, const std::string& debugType);
205
206 //! \brief Draws the VREngage debug menu using ImGui
207 //!
208 //! This is the main drawing function that renders all registered debug UI elements.
209 //! It should be called from the application's ImGui rendering pass.
210 virtual void drawVrEngageDebugMenu();
211
212 //! \brief Checks if the debug window is currently visible
213 //! \return True if the debug window is visible
215 //! \brief Sets the visibility of the debug window
216 //! \param vis True to show the window, false to hide it
217 void setDebugWindowVisible(bool vis);
218
219 //! \brief Checks if debug messages are being sent
220 //! \return True if debug messages are enabled
222 //! \brief Enables or disables sending of debug messages
223 //! \param send True to enable debug messages, false to disable
224 void setSendDebugMessages(bool send);
225
226 //! \brief Checks if the debug system is running in lite mode
227 //! \return True if running in lite mode (without rendering)
228 bool isLiteMode() const;
229 //! \brief Checks if the debug system is running in full mode
230 //! \return True if running in full mode (with rendering)
231 bool isFullMode() const;
232
233 //! \brief Gets the debug initializer
234 //! \return Pointer to the debug initializer
236
237 //! \brief Gets the debug renderer instance
238 //! \return Pointer to the debug renderer
240
241 //! \brief Gets the ImGui log printer instance
242 //! \return Pointer to the log printer, or nullptr if not installed
244
245public:
246 //! \brief Pushes compact ImGui style settings
247 //!
248 //! Modifies ImGui style to use more compact layout for debug UI elements
249 static void PushStyleCompact();
250 //! \brief Pops compact ImGui style settings
251 //!
252 //! Restores the previous ImGui style settings after PushStyleCompact()
253 static void PopStyleCompact();
254 //! \brief Indents the ImGui content
255 //!
256 //! Adds indentation to subsequent ImGui elements
257 static void Indent();
258 //! \brief Unindents the ImGui content
259 //!
260 //! Removes indentation from subsequent ImGui elements
261 static void Unindent();
262 //! \brief Displays a help marker with description text
263 //! \param desc The description text to display in the help tooltip
264 static void HelpMarker(const std::string& desc);
265 //! \brief Checks if a debugger is attached to the process
266 //! \param recheck Force a recheck instead of using cached value
267 //! \return True if a debugger is attached
268 static bool IsDebuggerAttached(bool recheck = false);
269 //! \brief Creates a checkbox that displays different strings based on its state
270 //! \param enabledString Text to display when checkbox is checked
271 //! \param disabledString Text to display when checkbox is unchecked
272 //! \param val Pointer to the boolean value controlled by the checkbox
273 //! \return True if the checkbox value was changed
274 static bool ConditionalCheckbox(const std::string& enabledString, const std::string& disabledString, bool* val);
275
276protected:
277 //! \brief Constructor for DtVreDebugManager
278 //!
279 //! Protected since this is a singleton class
280 //! \param de Pointer to the graphics engine (can be null for lite mode)
281 explicit DtVreDebugManager(makVrv::DtDe*);
282
283 //! \brief Virtual destructor
284 //!
285 //! Handles cleanup of debug manager resources
287
288 //! \brief Copy constructor (deleted)
290 //! \brief Move constructor (deleted)
292 //! \brief Copy assignment operator (deleted)
294 //! \brief Move assignment operator (deleted)
296
297 //! \brief General callback for debug events
298 //!
299 //! Called when general debug events need to be processed
300 virtual void generalCallback();
301 //! \brief Simulation-specific callback for debug events
302 //!
303 //! Called when simulation-specific debug events need to be processed
304 virtual void simCallback();
305
306 //! \brief Log viewer callback for the General debug tab
307 //!
308 //! Draws the ImGui log panel showing captured application output.
309 //! When the log is detached, shows a re-attach button instead.
310 virtual void logCallback();
311
312 //! \brief Draws the detached log window independently of the debug menu.
313 //!
314 //! Connected to preTick so it renders even when the debug menu is hidden.
315 virtual void drawDetachedLog();
316
317 //! \brief Loads debug configuration settings
318 //!
319 //! Initializes the debug configuration from saved settings
321
322 //! \brief Installs default debug message handlers
323 //!
324 //! Sets up the standard debug message handlers for the system
326
327 //! \brief Draws the "Show VR-Engage Debug Menu" option
328 //!
329 //! Renders the toggle option for showing/hiding the debug menu
331
332 //! \brief Handles debug metadata messages
333 //! \param msg The message to process
334 //! \return Result of the message handling
336 //! \brief Handles debug meta enable/disable messages
337 //! \param msg The message to process
338 //! \return Result of the message handling
340 //! \brief Handles debug meta registration messages
341 //! \param msg The message to process
342 //! \return Result of the message handling
344
345 //! \brief Handles global debug enable/disable messages
346 //! \param msg The message to process
347 //! \return Result of the message handling
349
350 //! \brief Handles network connected message to request debug capabilities from backends
351 //! \param msg The message to process
352 //! \return Result of the message handling
354
355protected:
356 //! \brief Singleton instance of the debug manager
358 //! \brief Pointer to the graphics engine
359 makVrv::DtDe* myDe;
360
361 //! \brief Map of debug menu configurations and their callbacks
363
364 //! \brief List of callbacks to invoke when debug is enabled/disabled
366
367 //! \brief Debug renderer instance owned by the manager
368 std::unique_ptr<DtDebugRenderer> myDebugRenderer;
369
370 //! \brief ImGui log printer that captures DtOutputStream output
371 std::unique_ptr<DtImGuiLogPrinter> myLogPrinter;
372
373 //! \brief Debug initializer instance
374 std::unique_ptr<DtInitializer> myDebugInitializer;
375
376 //! \brief Flag indicating if the debug window should be drawn
378 //! \brief Width of indentation for ImGui elements
380
381 //! \brief Flag indicating if a debugger is attached to the process
383 //! \brief Flag indicating if debug messages should be sent
385 //! \brief Flag indicating if running in lite mode
387 //! \brief Flag indicating if the debug console is shown
389 //! \brief Whether the log section starts expanded in the General tab
391};
392} // namespace makVre
393
394// Callback for safely removing callbacks.
395#define DEBUG_MANAGER_REMOVE_MENU_CALLBACK(delegate) \
396 if (DtVreDebugManager::instance()) \
397 { \
398 DtVreDebugManager::instance()->removeDebugMenuCallback(delegate); \
399 }
400
401#define DEBUG_MANAGER_REMOVE_ENABLED_CALLBACK(delegate) \
402 if (DtVreDebugManager::instance()) \
403 { \
404 DtVreDebugManager::instance()->removeDebugEnabledCallback(delegate); \
405 }
Provides attribute handling system for hierarchical data storage and manipulation.
Use to add an entry to the VR-Engage debug menu.
Definition debugMetaRegister.h:35
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Debug renderer for 2D and 3D debug visuals.
Definition debugRenderer.h:128
Modern delegate class that can bind and invoke callables with any number of parameters.
Definition delegate.h:31
DtPrinter subclass that captures log output for ImGui display.
Definition debugLogPrinter.h:47
Configuration initializer for VREngage components.
Definition initializer.h:80
virtual void installDefaultDebugMessages()
Installs default debug message handlers.
float myIndentWidth
Width of indentation for ImGui elements.
Definition debugManager.h:379
makVrv::DtDe * myDe
Pointer to the graphics engine.
Definition debugManager.h:359
virtual void loadDebugConfiguration()
Loads debug configuration settings.
virtual void logCallback()
Log viewer callback for the General debug tab.
bool myDrawWindow
Flag indicating if the debug window should be drawn.
Definition debugManager.h:377
bool myLiteDebugManager
Flag indicating if running in lite mode.
Definition debugManager.h:386
DtVreDebugManager(makVrv::DtDe *)
Constructor for DtVreDebugManager.
DebugMenuConfigurationMap::iterator getDebugMenuConfiguration(const std::string &name)
Gets an iterator to a debug menu configuration by name.
static bool ConditionalCheckbox(const std::string &enabledString, const std::string &disabledString, bool *val)
Creates a checkbox that displays different strings based on its state.
static void Unindent()
Unindents the ImGui content.
virtual bool addDebugMenuCallback(const std::string &sec, const DtVreDebugMenuCallback &cb, CallbackPosition position=CallbackPosition::BACK)
Registers a callback for a specific debug menu section.
bool isDebugWindowVisible() const
Checks if the debug window is currently visible.
virtual ~DtVreDebugManager()
Virtual destructor.
static void Indent()
Indents the ImGui content.
DtVreDebugManager & operator=(DtVreDebugManager &)=delete
Copy assignment operator (deleted)
virtual void drawVrEngageDebugMenu()
Draws the VREngage debug menu using ImGui.
DtVreDebugManager(DtVreDebugManager &&)=delete
Move constructor (deleted)
virtual void addDebugMenuEntry(const std::string &name, DtVreDebugMenuConfiguration conf)
Adds a new debug menu entry to the debug UI.
std::unique_ptr< DtImGuiLogPrinter > myLogPrinter
ImGui log printer that captures DtOutputStream output.
Definition debugManager.h:371
static void installLite()
Installs a lightweight version of the debug system without rendering.
bool myDebuggerAttached
Flag indicating if a debugger is attached to the process.
Definition debugManager.h:382
virtual bool removeDebugMenuCallback(const DtVreDebugMenuCallback &cb)
Removes a previously registered debug menu callback.
static DtVreDebugManager * theDebugManager
Singleton instance of the debug manager.
Definition debugManager.h:357
static void PushStyleCompact()
Pushes compact ImGui style settings.
std::unique_ptr< DtDebugRenderer > myDebugRenderer
Debug renderer instance owned by the manager.
Definition debugManager.h:368
bool mySendingDebugMessages
Flag indicating if debug messages should be sent.
Definition debugManager.h:384
std::unique_ptr< DtInitializer > myDebugInitializer
Debug initializer instance.
Definition debugManager.h:374
bool isLiteMode() const
Checks if the debug system is running in lite mode.
void drawVrEngageDebugOption()
Draws the "Show VR-Engage Debug Menu" option.
static DtVreDebugManager * instance()
Gets the singleton debug manager instance.
DtDebugRenderer * debugRenderer()
Gets the debug renderer instance.
bool getDebugProcess(const std::string &type, DtSimulationAddress address, DtConfigurableDebugProcess &proc)
Gets a debug process by type and simulation address.
static void installFull(makVrv::DtDe &)
Installs the full debug system with rendering capabilities.
DtVreMessageResult handleDebugMetaEnable(DtVreMessage *msg)
Handles debug meta enable/disable messages.
bool myConsoleShown
Flag indicating if the debug console is shown.
Definition debugManager.h:388
DtVreDebugManager(DtVreDebugManager &)=delete
Copy constructor (deleted)
virtual void simCallback()
Simulation-specific callback for debug events.
std::vector< DtConfigurableDebugProcess * > getDebugProcessesByType(const std::string &menuSection, const std::string &debugType)
Gets all debug processes matching a given type within a menu section.
static void HelpMarker(const std::string &desc)
Displays a help marker with description text.
void setSendDebugMessages(bool send)
Enables or disables sending of debug messages.
static void PopStyleCompact()
Pops compact ImGui style settings.
static bool IsDebuggerAttached(bool recheck=false)
Checks if a debugger is attached to the process.
virtual void removeDebugMenuEntry(const std::string &name)
Removes a debug menu entry from the debug UI.
DtVreMessageResult handleDebugGlobalEnable(DtVreMessage *msg)
Handles global debug enable/disable messages.
DtVreMessageResult handleNetworkConnected(DtVreMessage *msg)
Handles network connected message to request debug capabilities from backends.
DtVreMessageResult handleDebugMetaData(DtVreMessage *msg)
Handles debug metadata messages.
virtual bool removeDebugEnabledCallback(const DtVreDebugEnabledCallback &cb)
Removes a previously registered debug enabled callback.
bool getSendDebugMessages() const
Checks if debug messages are being sent.
virtual void drawDetachedLog()
Draws the detached log window independently of the debug menu.
bool isFullMode() const
Checks if the debug system is running in full mode.
bool myLogOpenByDefault
Whether the log section starts expanded in the General tab.
Definition debugManager.h:390
virtual void generalCallback()
General callback for debug events.
DtVreMessageResult handleDebugMetaRegister(DtVreMessage *msg)
Handles debug meta registration messages.
void setDebugWindowVisible(bool vis)
Sets the visibility of the debug window.
virtual bool addDebugEnabledCallback(const DtVreDebugEnabledCallback &cb, CallbackPosition position=CallbackPosition::BACK)
Registers a callback that is triggered when debug rendering is enabled/disabled.
DebugEnabledCallbackList myDebugEnabledCallbackList
List of callbacks to invoke when debug is enabled/disabled.
Definition debugManager.h:365
DebugMenuConfigurationMap myDebugConfigurationMap
Map of debug menu configurations and their callbacks.
Definition debugManager.h:362
static void shutdown()
Cleans up and shuts down the debug system.
DtVreDebugManager & operator=(DtVreDebugManager &&)=delete
Move assignment operator (deleted)
DtInitializer * getDebugInitializer()
Gets the debug initializer.
DtImGuiLogPrinter * logPrinter()
Gets the ImGui log printer instance.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export macros for the VREngage Debug Manager library.
#define DEBUGMANAGER_DLL
Export/import macro for non-Windows platforms.
Definition export.h:40
!
Definition glsVreMessageUtil.h:50
DtDelegate< void, bool > DtVreDebugEnabledCallback
Definition debugManager.h:72
std::list< DtVreDebugMenuCallback > DebugMenuCallbackList
Definition debugManager.h:68
DtDelegate< void > DtVreDebugMenuCallback
Definition debugManager.h:67
CallbackPosition
Defines the position where callbacks are registered in the callback list.
Definition debugManager.h:61
@ BACK
Add callback to the back of the list (executed last)
Definition debugManager.h:63
@ FRONT
Add callback to the front of the list (executed first)
Definition debugManager.h:62
std::map< std::string, DebugConfigurationValue > DebugMenuConfigurationMap
Definition debugManager.h:70
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
std::list< DtVreDebugEnabledCallback > DebugEnabledCallbackList
Definition debugManager.h:73
std::pair< DtVreDebugMenuConfiguration, DebugMenuCallbackList > DebugConfigurationValue
Definition debugManager.h:69
Definition appLauncherComponent.h:28
Configuration structure for debug processes.
Definition debugManager.h:80
DtSimulationAddress address
Simulation address for this debug process.
Definition debugManager.h:99
std::string debugType
Type identifier for the debug process.
Definition debugManager.h:93
bool enabled
Whether the debug process is enabled.
Definition debugManager.h:101
Process
Enumeration of process types that can be debugged.
Definition debugManager.h:83
@ VRF_APP
VRForces application process.
Definition debugManager.h:85
@ VRE_APP
VREngage application process.
Definition debugManager.h:84
@ VRE_SIM
VREngage simulation process.
Definition debugManager.h:86
@ VRF_SIM
VRForces simulation process.
Definition debugManager.h:87
std::string displayName
Display name of the debug process.
Definition debugManager.h:91
std::string menuSection
Menu section where this process should appear.
Definition debugManager.h:95
DtAttributeHandle extraData
Additional data associated with this debug process.
Definition debugManager.h:105
bool showInTable
Whether to show this process in the debug table.
Definition debugManager.h:103
Process process
Type of process (VREngage or VRForces, app or sim)
Definition debugManager.h:97
Configuration structure for debug menus.
Definition debugManager.h:113
std::string description
Description of this debug menu section.
Definition debugManager.h:115
DtVreDebugMenuConfiguration()
Default constructor that initializes with empty values.
Definition debugManager.h:120
std::vector< DtConfigurableDebugProcess > configurableOptions
List of configurable debug processes in this menu section.
Definition debugManager.h:117
Defines the base class for all VREngage messages.