Skip to content

Commit 926aa16

Browse files
committed
Disable frame pause if there are any coroutines or subscripts running
1 parent 6013971 commit 926aa16

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ui_main.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,23 @@ void ui_main_c::PCall(int narg, int nret)
150150
{
151151
sys->SetWorkDir(scriptWorkDir);
152152
inLua = true;
153+
hasActiveCoroutine = false;
153154
int err = lua_pcall(L, narg, nret, 1);
155+
lua_getglobal(L, "coroutine");
156+
lua_getfield(L, -1, "_list");
157+
lua_pcall(L, 0, 1, 0);
158+
159+
if (lua_istable(L, -1)) {
160+
lua_pushnil(L);
161+
while (lua_next(L, -2)) {
162+
lua_State* co = lua_tothread(L, -2);
163+
if (co && lua_status(co) == LUA_YIELD) {
164+
hasActiveCoroutine = true;
165+
}
166+
lua_pop(L, 1);
167+
}
168+
}
169+
lua_pop(L, 1);
154170
inLua = false;
155171
sys->SetWorkDir();
156172
if (err && !didExit) {
@@ -354,13 +370,23 @@ void ui_main_c::ScriptInit()
354370

355371
void ui_main_c::Frame()
356372
{
373+
// Check for any subscripts we need to run
374+
bool hasSubscript = false;
375+
for (dword i = 0; i < subScriptSize; i++) {
376+
if (subScriptList[i]) {
377+
hasSubscript = true;
378+
break;
379+
}
380+
}
381+
// Always runs 10 frames after finishing the boot process
357382
if (!sys->video->IsVisible() || sys->conWin->IsVisible() || restartFlag || didExit) {
358383
framesSinceWindowHidden = 0;
359384
}
360385
else if (framesSinceWindowHidden <= 10) {
361386
framesSinceWindowHidden++;
362387
}
363-
else if (!sys->video->IsActive() && !sys->video->IsCursorOverWindow()) {
388+
// Otherwise only runs frames if the mouse is on screen, there is an active coroutine, or there is an active subscript
389+
else if (!sys->video->IsActive() && !sys->video->IsCursorOverWindow() && !hasActiveCoroutine && !hasSubscript) {
364390
sys->Sleep(100);
365391
return;
366392
}

ui_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ui_main_c: public ui_IMain {
4949
int cursorY = 0;
5050
int framesSinceWindowHidden = 0;
5151
volatile bool inLua = false;
52+
bool hasActiveCoroutine = false;
5253
int ioOpenf = LUA_NOREF;
5354

5455
static int InitAPI(lua_State* L);

0 commit comments

Comments
 (0)