From 926aa16e83490a7b2b3ffbd74948278db60504d0 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Wed, 5 Nov 2025 22:00:22 -0600 Subject: [PATCH 1/3] Disable frame pause if there are any coroutines or subscripts running --- ui_main.cpp | 28 +++++++++++++++++++++++++++- ui_main.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ui_main.cpp b/ui_main.cpp index 1c0281d..887de4f 100644 --- a/ui_main.cpp +++ b/ui_main.cpp @@ -150,7 +150,23 @@ void ui_main_c::PCall(int narg, int nret) { sys->SetWorkDir(scriptWorkDir); inLua = true; + hasActiveCoroutine = false; int err = lua_pcall(L, narg, nret, 1); + lua_getglobal(L, "coroutine"); + lua_getfield(L, -1, "_list"); + lua_pcall(L, 0, 1, 0); + + if (lua_istable(L, -1)) { + lua_pushnil(L); + while (lua_next(L, -2)) { + lua_State* co = lua_tothread(L, -2); + if (co && lua_status(co) == LUA_YIELD) { + hasActiveCoroutine = true; + } + lua_pop(L, 1); + } + } + lua_pop(L, 1); inLua = false; sys->SetWorkDir(); if (err && !didExit) { @@ -354,13 +370,23 @@ void ui_main_c::ScriptInit() void ui_main_c::Frame() { + // Check for any subscripts we need to run + bool hasSubscript = false; + for (dword i = 0; i < subScriptSize; i++) { + if (subScriptList[i]) { + hasSubscript = true; + break; + } + } + // Always runs 10 frames after finishing the boot process if (!sys->video->IsVisible() || sys->conWin->IsVisible() || restartFlag || didExit) { framesSinceWindowHidden = 0; } else if (framesSinceWindowHidden <= 10) { framesSinceWindowHidden++; } - else if (!sys->video->IsActive() && !sys->video->IsCursorOverWindow()) { + // Otherwise only runs frames if the mouse is on screen, there is an active coroutine, or there is an active subscript + else if (!sys->video->IsActive() && !sys->video->IsCursorOverWindow() && !hasActiveCoroutine && !hasSubscript) { sys->Sleep(100); return; } diff --git a/ui_main.h b/ui_main.h index 321513b..87bdb58 100644 --- a/ui_main.h +++ b/ui_main.h @@ -49,6 +49,7 @@ class ui_main_c: public ui_IMain { int cursorY = 0; int framesSinceWindowHidden = 0; volatile bool inLua = false; + bool hasActiveCoroutine = false; int ioOpenf = LUA_NOREF; static int InitAPI(lua_State* L); From 728851f1dbd3c867549e0da3730fcf5e9748df24 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Sat, 8 Nov 2025 13:53:24 -0600 Subject: [PATCH 2/3] Add background logic to another spot --- ui_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_main.cpp b/ui_main.cpp index 887de4f..c03c8bc 100644 --- a/ui_main.cpp +++ b/ui_main.cpp @@ -432,7 +432,7 @@ void ui_main_c::Frame() } //sys->con->Printf("Finishing up...\n"); - if ( !sys->video->IsActive() ) { + if ( !sys->video->IsActive() && !hasActiveCoroutine && !hasSubscript ) { sys->Sleep(100); } From 88b89bbbb84a8c5f247affdf8bf253c58125b597 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Tue, 18 Nov 2025 23:01:30 -0600 Subject: [PATCH 3/3] fix: improper stack pop causing error in updates --- ui_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_main.cpp b/ui_main.cpp index c03c8bc..09e59be 100644 --- a/ui_main.cpp +++ b/ui_main.cpp @@ -166,7 +166,7 @@ void ui_main_c::PCall(int narg, int nret) lua_pop(L, 1); } } - lua_pop(L, 1); + lua_pop(L, 2); inLua = false; sys->SetWorkDir(); if (err && !didExit) {