|
VR-Engage
2.3
|
All log text is stored in a single contiguous ImGuiTextBuffer with a parallel offset table that records where each line starts, its length, and its severity level. This design uses one heap allocation for all text (the ImGuiTextBuffer grows geometrically), avoids per-line std::string overhead, and makes oldest-line eviction O(1) by advancing a head index rather than shifting memory.
Attach an instance to one or more DtOutputStream objects (DtFatal, DtWarn, DtInfo, DtVerbose, DtDebug). Every write() call appends text to the buffer. Call drawContents() from an ImGui rendering pass to display the captured log with text search, severity filtering, auto-scroll, and color-coded lines.
Thread safety: write() may be called from any thread. draw methods must be called from the ImGui (main) thread only.
#include <debugLogPrinter.h>
Classes | |
| struct | LineInfo |
Public Member Functions | |
| DtImGuiLogPrinter (int maxLines=10000) | |
| virtual | ~DtImGuiLogPrinter () |
| DtImGuiLogPrinter (const DtImGuiLogPrinter &)=delete | |
| DtImGuiLogPrinter & | operator= (const DtImGuiLogPrinter &)=delete |
| virtual void | write (const std::string &str, int notify_level, bool newLine) override |
| void | drawContents () |
| void | drawDetachedWindow () |
| void | clear () |
| void | connectToAllStreams () |
| void | disconnectFromAllStreams () |
| bool | isConnected () const |
| bool | isDetached () const |
| void | setDetached (bool detached) |
Private Member Functions | |
| void | drawToolbar () |
| void | drawLogRegion () |
| void | takeSnapshot () |
| void | commitPendingLine () |
| void | compactIfNeeded () |
Private Attributes | |
| std::mutex | myMutex |
| ImGuiTextBuffer | myBuf |
| std::vector< LineInfo > | myLines |
| int | myHead |
| int | myLineCount |
| std::string | myPendingLine |
| int | myPendingLevel |
| int | myMaxLines |
| ImGuiTextFilter | myFilter |
| bool | myLevelVisible [5] |
| bool | myAutoScroll |
| bool | myDetached |
| bool | myCopyMode |
| bool | myConnected |
| std::vector< LineInfo > | mySnapshot |
| std::string | mySnapshotText |
| std::string | myCopyText |
| bool | myCopyTextDirty |
|
explicit |
Constructs the log printer.
| maxLines | Maximum number of lines to retain before discarding the oldest. |
Referenced by DtImGuiLogPrinter(), and operator=().
|
virtual |
Virtual destructor.
|
delete |
References DtImGuiLogPrinter().
|
delete |
References DtImGuiLogPrinter().
|
overridevirtual |
DtPrinter override — called by every DtOutputStream this printer is connected to.
| str | The text to log. |
| notify_level | Severity (DtNlFatal … DtNlDebug). |
| newLine | True when str begins a new logical line. |
| void makVre::DtImGuiLogPrinter::drawContents | ( | ) |
Renders the log contents inside an existing ImGui window or tab.
Draws the toolbar (clear, auto-scroll, severity filters, copy-mode, detach button), search bar, and the scrollable log region.
| void makVre::DtImGuiLogPrinter::drawDetachedWindow | ( | ) |
Renders the log in its own detached ImGui window.
Call this from a draw path that is independent of the debug menu visibility so the detached window stays open even when the main debug menu is hidden. If the user closes the window, the log automatically re-attaches to the inline view.
| void makVre::DtImGuiLogPrinter::clear | ( | ) |
Discards all stored log lines.
| void makVre::DtImGuiLogPrinter::connectToAllStreams | ( | ) |
Connects this printer to all five global DtOutputStream instances.
| void makVre::DtImGuiLogPrinter::disconnectFromAllStreams | ( | ) |
Disconnects this printer from all five global DtOutputStream instances.
| bool makVre::DtImGuiLogPrinter::isConnected | ( | ) | const |
Returns true when the printer is attached to the output streams.
| bool makVre::DtImGuiLogPrinter::isDetached | ( | ) | const |
Returns true when the log is displayed in its own window.
| void makVre::DtImGuiLogPrinter::setDetached | ( | bool | detached | ) |
Sets whether the log is displayed in its own window.
|
private |
Builds the toolbar row (Clear, Auto-scroll, severity filters, Copy Mode, Detach).
|
private |
Builds the scrollable log region using the current snapshot.
|
private |
Takes a thread-safe snapshot of the line metadata and text into mySnapshot / mySnapshotText.
|
private |
Commits the pending partial line into the contiguous buffer.
|
private |
Compacts the buffer when the oldest lines have been evicted, reclaiming dead space at the front.
|
private |
Guards all mutable state accessed by write() and draw().
|
private |
Single contiguous text buffer holding all log line text. Lines are null-terminated within the buffer so that c_str()-style pointers can be handed directly to ImGui::TextUnformatted().
|
private |
Offset table describing each line stored in myBuf. Used as a circular array: valid lines are indices [myHead, myHead + lineCount).
|
private |
Index of the oldest valid line in myLines (circular).
|
private |
Total number of valid lines currently stored.
|
private |
Partial line being accumulated before the next newLine==true write.
|
private |
Notify level for the pending partial line.
|
private |
Maximum retained line count.
|
private |
ImGui text filter for search.
|
private |
Per-level visibility toggles (indexed by DtNotifyLevelType).
|
private |
Whether to auto-scroll to the bottom on new output.
|
private |
Whether the log is shown in its own detached ImGui window.
|
private |
Whether copy-mode is active (read-only InputTextMultiline for selection).
|
private |
Whether we are currently attached to the output streams.
|
private |
Frame-local snapshot of LineInfo, built by takeSnapshot().
|
private |
Frame-local snapshot of the text buffer, built by takeSnapshot().
|
private |
Cached flattened text for copy-mode InputTextMultiline.
|
private |
True when myCopyText needs rebuilding (filter/severity/line count changed).