VR-Engage  2.2
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;
55class DtInitializer;
57
58//! Defines the position where callbacks are registered in the callback list
60{
61 FRONT = 0, //!< Add callback to the front of the list (executed first)
62 BACK //!< Add callback to the back of the list (executed last)
63};
64
65// Typedefs
67using DebugMenuCallbackList = std::list<DtVreDebugMenuCallback>;
68using DebugConfigurationValue = std::pair<DtVreDebugMenuConfiguration, DebugMenuCallbackList>;
69using DebugMenuConfigurationMap = std::map<std::string, DebugConfigurationValue>;
70
72using DebugEnabledCallbackList = std::list<DtVreDebugEnabledCallback>;
73
74//! \brief Configuration structure for debug processes
75//!
76//! Contains the necessary information to configure and identify a debug process
77//! within the VREngage debug system.
79{
80 //! \brief Enumeration of process types that can be debugged
81 enum class Process
82 {
83 VRE_APP = 0, //!< VREngage application process
84 VRF_APP, //!< VRForces application process
85 VRE_SIM, //!< VREngage simulation process
86 VRF_SIM //!< VRForces simulation process
87 };
88
89 //! \brief Display name of the debug process
90 std::string displayName;
91 //! \brief Type identifier for the debug process
92 std::string debugType;
93 //! \brief Menu section where this process should appear
94 std::string menuSection;
95 //! \brief Type of process (VREngage or VRForces, app or sim)
97 //! \brief Simulation address for this debug process
98 DtSimulationAddress address;
99 //! \brief Whether the debug process is enabled
101 //! \brief Whether to show this process in the debug table
103 //! \brief Additional data associated with this debug process
105};
106
107//! \brief Configuration structure for debug menus
108//!
109//! Contains the necessary information to configure a debug menu section
110//! within the VREngage debug UI system.
112{
113 //! \brief Description of this debug menu section
114 std::string description;
115 //! \brief List of configurable debug processes in this menu section
116 std::vector<DtConfigurableDebugProcess> configurableOptions;
117
118 //! \brief Default constructor that initializes with empty values
124};
125
126//! \brief Main debug manager class for VREngage
127//!
128//! This singleton class provides the central interface for all debugging
129//! functionality in VREngage, including menu management, debug rendering,
130//! and debug message passing throughout the application.
132{
133public:
134 //! \brief Gets the singleton debug manager instance
135 //! \return Pointer to the singleton instance
137
138 //! \brief Installs the full debug system with rendering capabilities
139 //! \param de The graphics engine to attach the debug renderer to
140 static void installFull(makVrv::DtDe&);
141
142 //! \brief Installs a lightweight version of the debug system without rendering
143 //!
144 //! Use this when no graphics engine is available but debugging is still required
145 static void installLite();
146
147 //! \brief Cleans up and shuts down the debug system
148 //!
149 //! Releases all resources and destroys the singleton instance
150 static void shutdown();
151
152 //! \brief Registers a callback for a specific debug menu section
153 //!
154 //! The callback will be invoked when the specified debug menu section is active
155 //! \param sec The section name to register the callback for
156 //! \param cb The callback function to register
157 //! \param position Where to place the callback in the execution order
158 //! \return True if the callback was successfully registered
160 const std::string& sec, const DtVreDebugMenuCallback& cb, CallbackPosition position = CallbackPosition::BACK);
161 //! \brief Removes a previously registered debug menu callback
162 //! \param cb The callback to remove
163 //! \return True if the callback was found and removed
165
166 //! \brief Registers a callback that is triggered when debug rendering is enabled/disabled
167 //!
168 //! This callback will be invoked when the debug rendering enabled state changes
169 //! \param cb The callback function to register
170 //! \param position Where to place the callback in the execution order
171 //! \return True if the callback was successfully registered
174 //! \brief Removes a previously registered debug enabled callback
175 //! \param cb The callback to remove
176 //! \return True if the callback was found and removed
178
179 //! \brief Adds a new debug menu entry to the debug UI
180 //! \param name The name of the menu entry
181 //! \param conf The configuration for this menu entry
182 virtual void addDebugMenuEntry(const std::string& name, DtVreDebugMenuConfiguration conf);
183 //! \brief Removes a debug menu entry from the debug UI
184 //! \param name The name of the menu entry to remove
185 virtual void removeDebugMenuEntry(const std::string& name);
186
187 //! \brief Gets an iterator to a debug menu configuration by name
188 //! \param name The name of the menu configuration to find
189 //! \return Iterator to the debug menu configuration, or end() if not found
190 DebugMenuConfigurationMap::iterator getDebugMenuConfiguration(const std::string& name);
191 //! \brief Gets a debug process by type and simulation address
192 //! \param type The type of debug process to find
193 //! \param address The simulation address of the process
194 //! \param proc The found debug process configuration (output parameter)
195 //! \return True if the process was found, false otherwise
196 bool getDebugProcess(const std::string& type, DtSimulationAddress address, DtConfigurableDebugProcess& proc);
197
198 //! \brief Draws the VREngage debug menu using ImGui
199 //!
200 //! This is the main drawing function that renders all registered debug UI elements.
201 //! It should be called from the application's ImGui rendering pass.
202 virtual void drawVrEngageDebugMenu();
203
204 //! \brief Checks if the debug window is currently visible
205 //! \return True if the debug window is visible
207 //! \brief Sets the visibility of the debug window
208 //! \param vis True to show the window, false to hide it
209 void setDebugWindowVisible(bool vis);
210
211 //! \brief Checks if debug messages are being sent
212 //! \return True if debug messages are enabled
214 //! \brief Enables or disables sending of debug messages
215 //! \param send True to enable debug messages, false to disable
216 void setSendDebugMessages(bool send);
217
218 //! \brief Checks if the debug system is running in lite mode
219 //! \return True if running in lite mode (without rendering)
220 bool isLiteMode() const;
221 //! \brief Checks if the debug system is running in full mode
222 //! \return True if running in full mode (with rendering)
223 bool isFullMode() const;
224
225 //! \brief Gets the debug initializer
226 //! \return Pointer to the debug initializer
228
229 //! \brief Gets the debug renderer instance
230 //! \return Pointer to the debug renderer
232
233public:
234 //! \brief Pushes compact ImGui style settings
235 //!
236 //! Modifies ImGui style to use more compact layout for debug UI elements
237 static void PushStyleCompact();
238 //! \brief Pops compact ImGui style settings
239 //!
240 //! Restores the previous ImGui style settings after PushStyleCompact()
241 static void PopStyleCompact();
242 //! \brief Indents the ImGui content
243 //!
244 //! Adds indentation to subsequent ImGui elements
245 static void Indent();
246 //! \brief Unindents the ImGui content
247 //!
248 //! Removes indentation from subsequent ImGui elements
249 static void Unindent();
250 //! \brief Displays a help marker with description text
251 //! \param desc The description text to display in the help tooltip
252 static void HelpMarker(const std::string& desc);
253 //! \brief Checks if a debugger is attached to the process
254 //! \param recheck Force a recheck instead of using cached value
255 //! \return True if a debugger is attached
256 static bool IsDebuggerAttached(bool recheck = false);
257 //! \brief Creates a checkbox that displays different strings based on its state
258 //! \param enabledString Text to display when checkbox is checked
259 //! \param disabledString Text to display when checkbox is unchecked
260 //! \param val Pointer to the boolean value controlled by the checkbox
261 //! \return True if the checkbox value was changed
262 static bool ConditionalCheckbox(const std::string& enabledString, const std::string& disabledString, bool* val);
263
264protected:
265 //! \brief Constructor for DtVreDebugManager
266 //!
267 //! Protected since this is a singleton class
268 //! \param de Pointer to the graphics engine (can be null for lite mode)
269 explicit DtVreDebugManager(makVrv::DtDe*);
270
271 //! \brief Virtual destructor
272 //!
273 //! Handles cleanup of debug manager resources
275
276 //! \brief Copy constructor (deleted)
278 //! \brief Move constructor (deleted)
280 //! \brief Copy assignment operator (deleted)
282 //! \brief Move assignment operator (deleted)
284
285 //! \brief General callback for debug events
286 //!
287 //! Called when general debug events need to be processed
288 virtual void generalCallback();
289 //! \brief Simulation-specific callback for debug events
290 //!
291 //! Called when simulation-specific debug events need to be processed
292 virtual void simCallback();
293
294 //! \brief Loads debug configuration settings
295 //!
296 //! Initializes the debug configuration from saved settings
298
299 //! \brief Installs default debug message handlers
300 //!
301 //! Sets up the standard debug message handlers for the system
303
304 //! \brief Draws the "Show VR-Engage Debug Menu" option
305 //!
306 //! Renders the toggle option for showing/hiding the debug menu
308
309 //! \brief Handles debug metadata messages
310 //! \param msg The message to process
311 //! \return Result of the message handling
313 //! \brief Handles debug meta enable/disable messages
314 //! \param msg The message to process
315 //! \return Result of the message handling
317 //! \brief Handles debug meta registration messages
318 //! \param msg The message to process
319 //! \return Result of the message handling
321 //! \brief Handles global debug enable/disable messages
322 //! \param msg The message to process
323 //! \return Result of the message handling
325
326protected:
327 //! \brief Singleton instance of the debug manager
329 //! \brief Pointer to the graphics engine
330 makVrv::DtDe* myDe;
331
332 //! \brief Map of debug menu configurations and their callbacks
334
335 //! \brief List of callbacks to invoke when debug is enabled/disabled
337
338 //! \brief Debug renderer instance owned by the manager
339 std::unique_ptr<DtDebugRenderer> myDebugRenderer;
340
341 //! \brief Debug initializer instance
342 std::unique_ptr<DtInitializer> myDebugInitializer;
343
344 //! \brief Flag indicating if the debug window should be drawn
346 //! \brief Width of indentation for ImGui elements
348
349 //! \brief Flag indicating if a debugger is attached to the process
351 //! \brief Flag indicating if debug messages should be sent
353 //! \brief Flag indicating if running in lite mode
355 //! \brief Flag indicating if the debug console is shown
357};
358} // namespace makVre
359
360// Callback for safely removing callbacks.
361#define DEBUG_MANAGER_REMOVE_MENU_CALLBACK(delegate) \
362 if (DtVreDebugManager::instance()) \
363 { \
364 DtVreDebugManager::instance()->removeDebugMenuCallback(delegate); \
365 }
366
367#define DEBUG_MANAGER_REMOVE_ENABLED_CALLBACK(delegate) \
368 if (DtVreDebugManager::instance()) \
369 { \
370 DtVreDebugManager::instance()->removeDebugEnabledCallback(delegate); \
371 }
Provides attribute handling system for hierarchical data storage and manipulation.
Definition debugMetaRegister.h:31
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
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:347
makVrv::DtDe * myDe
Pointer to the graphics engine.
Definition debugManager.h:330
virtual void loadDebugConfiguration()
Loads debug configuration settings.
bool myDrawWindow
Flag indicating if the debug window should be drawn.
Definition debugManager.h:345
bool myLiteDebugManager
Flag indicating if running in lite mode.
Definition debugManager.h:354
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.
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:350
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:328
static void PushStyleCompact()
Pushes compact ImGui style settings.
std::unique_ptr< DtDebugRenderer > myDebugRenderer
Debug renderer instance owned by the manager.
Definition debugManager.h:339
bool mySendingDebugMessages
Flag indicating if debug messages should be sent.
Definition debugManager.h:352
std::unique_ptr< DtInitializer > myDebugInitializer
Debug initializer instance.
Definition debugManager.h:342
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:356
DtVreDebugManager(DtVreDebugManager &)=delete
Copy constructor (deleted)
virtual void simCallback()
Simulation-specific callback for debug events.
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 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.
bool isFullMode() const
Checks if the debug system is running in full mode.
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:336
DebugMenuConfigurationMap myDebugConfigurationMap
Map of debug menu configurations and their callbacks.
Definition debugManager.h:333
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.
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
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtDelegate< void, bool > DtVreDebugEnabledCallback
Definition debugManager.h:71
std::list< DtVreDebugMenuCallback > DebugMenuCallbackList
Definition debugManager.h:67
DtDelegate< void > DtVreDebugMenuCallback
Definition debugManager.h:66
CallbackPosition
Defines the position where callbacks are registered in the callback list.
Definition debugManager.h:60
@ BACK
Add callback to the back of the list (executed last)
Definition debugManager.h:62
@ FRONT
Add callback to the front of the list (executed first)
Definition debugManager.h:61
std::map< std::string, DebugConfigurationValue > DebugMenuConfigurationMap
Definition debugManager.h:69
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
std::list< DtVreDebugEnabledCallback > DebugEnabledCallbackList
Definition debugManager.h:72
std::pair< DtVreDebugMenuConfiguration, DebugMenuCallbackList > DebugConfigurationValue
Definition debugManager.h:68
Definition appLauncherComponent.h:28
Configuration structure for debug processes.
Definition debugManager.h:79
DtSimulationAddress address
Simulation address for this debug process.
Definition debugManager.h:98
std::string debugType
Type identifier for the debug process.
Definition debugManager.h:92
bool enabled
Whether the debug process is enabled.
Definition debugManager.h:100
Process
Enumeration of process types that can be debugged.
Definition debugManager.h:82
@ VRF_APP
VRForces application process.
Definition debugManager.h:84
@ VRE_APP
VREngage application process.
Definition debugManager.h:83
@ VRE_SIM
VREngage simulation process.
Definition debugManager.h:85
@ VRF_SIM
VRForces simulation process.
Definition debugManager.h:86
std::string displayName
Display name of the debug process.
Definition debugManager.h:90
std::string menuSection
Menu section where this process should appear.
Definition debugManager.h:94
DtAttributeHandle extraData
Additional data associated with this debug process.
Definition debugManager.h:104
bool showInTable
Whether to show this process in the debug table.
Definition debugManager.h:102
Process process
Type of process (VREngage or VRForces, app or sim)
Definition debugManager.h:96
Configuration structure for debug menus.
Definition debugManager.h:112
std::string description
Description of this debug menu section.
Definition debugManager.h:114
DtVreDebugMenuConfiguration()
Default constructor that initializes with empty values.
Definition debugManager.h:119
std::vector< DtConfigurableDebugProcess > configurableOptions
List of configurable debug processes in this menu section.
Definition debugManager.h:116
Defines the base class for all VREngage messages.