载入中...
搜索中...
未找到
DevTool.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
10
11#include <string>
12#include <unordered_map>
13#include <vector>
14#include <chrono>
15
16struct SQVM;
17typedef struct SQVM* HSQUIRRELVM;
18
19namespace ssq {
20class VM;
21}
22
23namespace eve {
24class Runtime;
25}
26
27namespace eve::dev {
28
29class McpServer;
30class AiPanel;
31class ConsolePanel;
32class FrameStatsPanel;
33
51public:
52 static DevTool& instance();
53
54 DevTool(const DevTool&) = delete;
55 DevTool& operator=(const DevTool&) = delete;
56
58 void attach(ssq::VM& vm, bool sampleLocals = true);
59 void attach(HSQUIRRELVM vm, bool sampleLocals = true);
67 void attach(eve::Runtime& runtime, bool sampleLocals = true);
69 void enableRenderTrace(bool on = true);
70 void detach();
71
73 void exposeScriptApi(ssq::VM& vm);
74
76 int startDap(uint16_t port);
77 void stopDap();
79 int startMcp(uint16_t port);
80 void stopMcp();
81 void poll();
82
84 void drawAiPanel();
86 void drawConsolePanel();
88 void drawFrameStatsPanel();
89
90 bool isAttached() const { return vm_ != nullptr; }
92 bool isRuntimeBound() const { return runtime_ != nullptr; }
93 bool renderTraceEnabled() const { return renderTraceEnabled_; }
94 bool sampleLocals() const { return sampleLocals_; }
95 void setSampleLocals(bool on) { sampleLocals_ = on; }
96
97 CallGraph& graph() { return graph_; }
98 const CallGraph& graph() const { return graph_; }
99 RenderFlow& renderFlow() { return renderFlow_; }
100 const RenderFlow& renderFlow() const { return renderFlow_; }
101 Debugger& debugger() { return Debugger::instance(); }
102 Snapshot& snapshot() { return Snapshot::instance(); }
103 ScenarioRecorder& scenario() { return ScenarioRecorder::instance(); }
104 DebugAdapter& dap() { return DebugAdapter::instance(); }
105 McpServer& mcp();
106 AiPanel& ai();
107 ConsolePanel& console();
108 FrameStatsPanel& frameStats();
109
110 SliceResult analyzeError(const std::string& errorMessage,
111 const std::vector<std::string>& hintVars = {}) const;
112
113 std::string formatError(const std::string& errorMessage,
114 const std::vector<std::string>& hintVars = {}) const;
115
120 void recordMcpSnippetError(std::string report);
121
122 const std::string& lastReport() const { return lastReport_; }
123 const std::string& lastError() const { return lastError_; }
125 const SliceResult& lastSlice() const { return lastSlice_; }
126
129 int calls = 0;
130 int lines = 0;
131 long long ns = 0;
132 };
133 const std::unordered_map<std::string, ProfileEntry>& profile() const { return profile_; }
135 profile_.clear();
136 profStack_.clear();
137 }
138 std::string formatProfileReport() const;
139
141 std::string notifyError(const std::string& errorMessage,
142 const std::vector<std::string>& hintVars = {});
143
144 void handleDebugEvent(HSQUIRRELVM vm, int type, const char* source, int line,
145 const char* funcname);
146
147private:
148 DevTool() = default;
149
150 void sampleFrameLocals(HSQUIRRELVM vm, const SourceLoc& loc);
151 void markErrorUses(const SourceLoc& loc, const std::vector<std::string>& hintVars);
152 void installRenderTracer();
153 void uninstallRenderTracer();
155 void pumpWhilePaused();
156 void handleDebugHotkey(const std::string& key);
157 void profileLine(const std::string& func);
158 void profileCall(const std::string& func);
159 void profileReturn();
160
161 HSQUIRRELVM vm_ = nullptr;
162 bool sampleLocals_ = true;
163 bool renderTraceEnabled_ = false;
165 eve::Runtime* runtime_ = nullptr;
166 CallGraph graph_;
167 RenderFlow renderFlow_;
168 std::string lastReport_;
169 std::string lastError_;
170 SliceResult lastSlice_;
171 std::unordered_map<std::string, ProfileEntry> profile_;
172 std::vector<std::pair<std::string, std::chrono::steady_clock::time_point>> profStack_;
173
174 std::unordered_map<int, std::unordered_map<std::string, std::string>> localSnap_;
175};
176
177} // namespace eve::dev
struct SQVM * HSQUIRRELVM
struct SQVM * HSQUIRRELVM
Definition DevTool.hpp:17
HSQUIRRELVM vm
Definition ECS.cpp:38
SQObjectPtr key
Definition ECS.cpp:155
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
unsigned line
std::string_view source
std::map< size_t, ScriptCallSyntax > calls
std::vector< std::string_view > lines
EVENGINE_API_FOUNDATION public API.
Definition Runtime.h:189
In-engine AI / MCP session surface for DevTools.
Definition AiPanel.hpp:27
Runtime call graph + dynamic data-flow tracer with backward slicing.
Definition CallGraph.hpp:81
In-engine runtime console / log ring buffer for DevTools.
Minimal Debug Adapter Protocol (DAP) server for VS Code.
Script + frame debugger: pause/step, breakpoints, watches.
Definition Debugger.hpp:86
Platform-level script + render debugger / dynamic slicer front-end.
Definition DevTool.hpp:50
const std::string & lastReport() const
Definition DevTool.hpp:122
bool renderTraceEnabled() const
Definition DevTool.hpp:93
Debugger & debugger()
Definition DevTool.hpp:101
RenderFlow & renderFlow()
Definition DevTool.hpp:99
const std::unordered_map< std::string, ProfileEntry > & profile() const
Definition DevTool.hpp:133
const std::string & lastError() const
Definition DevTool.hpp:123
Snapshot & snapshot()
Definition DevTool.hpp:102
CallGraph & graph()
Definition DevTool.hpp:97
bool sampleLocals() const
Definition DevTool.hpp:94
DevTool(const DevTool &)=delete
void setSampleLocals(bool on)
Definition DevTool.hpp:95
const CallGraph & graph() const
Definition DevTool.hpp:98
ScenarioRecorder & scenario()
Definition DevTool.hpp:103
bool isAttached() const
Definition DevTool.hpp:90
bool isRuntimeBound() const
True when errors also flow through Runtime::setErrorHandler.
Definition DevTool.hpp:92
DevTool & operator=(const DevTool &)=delete
const SliceResult & lastSlice() const
Script-side slice from the last notifyError (empty if none).
Definition DevTool.hpp:125
DebugAdapter & dap()
Definition DevTool.hpp:104
const RenderFlow & renderFlow() const
Definition DevTool.hpp:100
Lightweight FPS / frame-time overlay for DevTools (0.6 closeout).
Embedded Model Context Protocol (MCP) server for AI-assisted game development.
Definition McpServer.hpp:35
Render-pipeline flow tracer with a Weiser-style backward slice.
A state-driven bug scenario: baseline snapshot + ordered per-frame inputs.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
EVEngine ECS 集成层:底层实现使用 sunxfancy/ECS.hpp https://github.com/sunxfancy/ECS.hpp
Definition ECS.h:21
Per-function script profile (line-hook timing).
Definition DevTool.hpp:128