add engine pause mode
This commit is contained in:
@@ -168,6 +168,15 @@ bool DebuggingServer::performCommand(
|
||||
void DebuggingServer::onHitBreakpoint(dv::value&& stackTrace) {
|
||||
logger.info() << "hit breakpoint:\n"
|
||||
<< json::stringify(stackTrace, true, " ");
|
||||
if (connection == nullptr) {
|
||||
return;
|
||||
}
|
||||
connection->send(dv::object({
|
||||
{"type", std::string("hit-breakpoint")},
|
||||
{"stack", std::move(stackTrace)}
|
||||
}));
|
||||
|
||||
engine.startPauseLoop();
|
||||
}
|
||||
|
||||
void DebuggingServer::setClient(u64id_t client) {
|
||||
|
||||
@@ -309,6 +309,30 @@ void Engine::nextFrame() {
|
||||
input->pollEvents();
|
||||
}
|
||||
|
||||
void Engine::startPauseLoop() {
|
||||
bool initialCursorLocked = false;
|
||||
if (!isHeadless()) {
|
||||
initialCursorLocked = input->isCursorLocked();
|
||||
if (initialCursorLocked) {
|
||||
input->toggleCursor();
|
||||
}
|
||||
}
|
||||
while (!isQuitSignal()) {
|
||||
if (!debuggingServer->update()) {
|
||||
debuggingServer.reset();
|
||||
break;
|
||||
}
|
||||
if (isHeadless()) {
|
||||
platform::sleep(1.0 / params.tps * 1000);
|
||||
} else {
|
||||
nextFrame();
|
||||
}
|
||||
}
|
||||
if (initialCursorLocked) {
|
||||
input->toggleCursor();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::renderFrame() {
|
||||
screen->draw(time.getDelta());
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ public:
|
||||
void updateFrontend();
|
||||
void renderFrame();
|
||||
void nextFrame();
|
||||
void startPauseLoop();
|
||||
|
||||
/// @brief Set screen (scene).
|
||||
/// nullptr may be used to delete previous screen before creating new one,
|
||||
|
||||
@@ -164,30 +164,7 @@ static int l_math_normal_random(lua::State* L) {
|
||||
|
||||
constexpr inline int MAX_SHORT_STRING_LEN = 50;
|
||||
|
||||
static dv::value create_stack_trace(lua_State* L, int initFrame = 2) {
|
||||
auto entriesList = dv::list();
|
||||
|
||||
lua_Debug frame;
|
||||
int level = initFrame;
|
||||
|
||||
while (lua_getstack(L, level, &frame)) {
|
||||
auto entry = dv::object();
|
||||
if (lua_getinfo(L, "nSlf", &frame) == 0) {
|
||||
level++;
|
||||
entriesList.add(std::move(entry));
|
||||
continue;
|
||||
}
|
||||
if (frame.name) {
|
||||
entry["function"] = frame.name;
|
||||
}
|
||||
if (frame.source) {
|
||||
const char* src =
|
||||
(frame.source[0] == '@') ? frame.source + 1 : frame.source;
|
||||
entry["source"] = src;
|
||||
entry["line"] = frame.currentline;
|
||||
}
|
||||
entry["what"] = frame.what;
|
||||
|
||||
static dv::value collect_locals(lua::State* L, lua_Debug& frame) {
|
||||
auto locals = dv::object();
|
||||
|
||||
int localIndex = 1;
|
||||
@@ -262,7 +239,33 @@ static dv::value create_stack_trace(lua_State* L, int initFrame = 2) {
|
||||
locals[name] = std::move(local);
|
||||
lua::pop(L);
|
||||
}
|
||||
entry["locals"] = std::move(locals);
|
||||
return locals;
|
||||
}
|
||||
|
||||
static dv::value create_stack_trace(lua::State* L, int initFrame = 2) {
|
||||
auto entriesList = dv::list();
|
||||
|
||||
lua_Debug frame;
|
||||
int level = initFrame;
|
||||
|
||||
while (lua_getstack(L, level, &frame)) {
|
||||
auto entry = dv::object();
|
||||
if (lua_getinfo(L, "nSlf", &frame) == 0) {
|
||||
level++;
|
||||
entriesList.add(std::move(entry));
|
||||
continue;
|
||||
}
|
||||
if (frame.name) {
|
||||
entry["function"] = frame.name;
|
||||
}
|
||||
if (frame.source) {
|
||||
const char* src =
|
||||
(frame.source[0] == '@') ? frame.source + 1 : frame.source;
|
||||
entry["source"] = src;
|
||||
entry["line"] = frame.currentline;
|
||||
}
|
||||
entry["what"] = frame.what;
|
||||
entry["locals"] = collect_locals(L, frame);
|
||||
entriesList.add(std::move(entry));
|
||||
level++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user