载入中...
搜索中...
未找到
ConsolePanel.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4
5#include <cstdint>
6#include <deque>
7#include <mutex>
8#include <string>
9#include <vector>
10
11struct SQVM;
12typedef struct SQVM* HSQUIRRELVM;
13
14namespace eve::dev {
15
17 std::uint64_t seq = 0; // process-lifetime sequence number; never reused
18 std::string timestamp; // HH:MM:SS
19 std::string level; // debug | info | warn | error | print | cmd | result | engine
20 std::string text;
21};
22
33 std::vector<ConsoleLine> lines;
34 std::uint64_t firstSeq = 0; // oldest retained seq (nextSeq when empty)
35 std::uint64_t nextSeq = 0; // seq the next appended line will receive
36 std::uint64_t droppedThrough = 0; // highest seq no longer retained
38 std::uint64_t cursor = 0;
39 bool truncated = false; // cursor predates the retained window
40};
41
59public:
60 static ConsolePanel& instance();
61
62 ConsolePanel(const ConsolePanel&) = delete;
64
65 void setVisible(bool on);
66 bool isVisible() const;
67 void toggleVisible();
68
70 void addLog(std::string level, std::string text);
71 void addInfo(std::string text);
72 void addWarn(std::string text);
73 void addError(std::string text);
83 void addEngineLine(const std::string& text);
85 [[nodiscard]] bool isCapturingStderr() const;
86
87 void clear();
88 void setMaxEntries(size_t n);
89 std::vector<ConsoleLine> recent(size_t max = 128) const;
90 std::string format(size_t max = 128) const;
91
93 std::uint64_t nextSeq() const;
95 std::uint64_t droppedThrough() const;
104 [[nodiscard]] ConsoleSlice read(std::uint64_t afterSeq, size_t max = 64, const std::string& level = {}) const;
105
107 void attach(HSQUIRRELVM vm);
108 void detach();
109 bool isAttached() const { return vm_ != nullptr; }
110
115 std::string eval(const std::string& expression);
116
121 void drawImGui();
122
123 using ImGuiDrawer = void (*)(ConsolePanel& panel);
124 static void setImGuiDrawer(ImGuiDrawer fn);
125
126private:
127 // Immortal<ConsolePanel> constructs the singleton (devtools/Immortal.hpp).
128 template <typename>
129 friend struct Immortal;
130 ConsolePanel() = default;
131
132 static std::string nowStamp();
133
135 void appendLocked(std::string level, std::string text);
136
137 mutable std::mutex mu_;
138 bool visible_ = true;
139 size_t maxEntries_ = 500;
140 std::deque<ConsoleLine> log_;
141 HSQUIRRELVM vm_ = nullptr;
142 // Monotonic for the process lifetime: clear() drops lines but never rewinds
143 // these, so an existing reader cursor stays meaningful.
144 std::uint64_t nextSeq_ = 1;
145 std::uint64_t droppedThrough_ = 0;
146};
147
148} // namespace eve::dev
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:20
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
glm::vec3 n
Definition Grass.cpp:63
std::string text
int level
std::size_t cursor
In-engine runtime console / log ring buffer for DevTools.
void(*)(ConsolePanel &panel) ImGuiDrawer
ConsolePanel(const ConsolePanel &)=delete
ConsolePanel & operator=(const ConsolePanel &)=delete
SettlementPipeline::Stage fn
One bounded read of the console ring buffer together with its cursors.
std::vector< ConsoleLine > lines
Process-immortal singleton holder for DevTools objects.
Definition Immortal.hpp:19