VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
DebugConsole.hpp
1#pragma once
2#include "ErrorUtils.hpp"
3#include <vector>
4#include <string>
5#include <functional>
6#include <map>
7#include <mutex>
8
9#if DEBUG
10#include <imgui.h>
11#endif
12
13namespace vex {
14 class VEX_EXPORT DebugConsole {
15 public:
16 static DebugConsole& Get() {
17 static DebugConsole instance;
18 return instance;
19 }
20
21 #if DEBUG
23 static int TextEditCallbackStub(ImGuiInputTextCallbackData* data);
24
26 int TextEditCallback(ImGuiInputTextCallbackData* data);
27 #endif
28
30 void Init();
31
35 void Draw(bool* p_open, bool isEditorMode);
36
37 using CommandFunc = std::function<void(const std::vector<std::string>&)>;
38
42 void RegisterCommand(const std::string& name, CommandFunc cmd);
43
46 void Execute(const std::string& commandLine);
47
51 void AddLog(LogLevel level, const char* msg);
52
53 private:
54 DebugConsole() = default;
55
56 struct LogEntry {
57 std::string text;
58 LogLevel level;
59 };
60
61 std::vector<LogEntry> m_logs;
62 std::map<std::string, CommandFunc> m_commands;
63 std::vector<std::string> m_history;
64 int m_historyPos = -1; // -1: new line, 0..History.Size-1 browsing history
65
66 char m_inputBuf[256] = {0};
67 bool m_scrollToBottom = true;
68 std::mutex m_mutex;
69 };
70}
void RegisterCommand(const std::string &name, CommandFunc cmd)
Register a command with the debug console.
void Execute(const std::string &commandLine)
Execute a command with the given arguments.
void AddLog(LogLevel level, const char *msg)
API for the callback.
void Init()
Initialize the debug console.
void Draw(bool *p_open, bool isEditorMode)
Draw the debug console.
LogLevel
Enum class for log levels.