@@ -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
355371void 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 }
0 commit comments