Skip to content

Commit

Permalink
Use SwitchToThread (...) when Unity engine tries to call Sleep (0)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Dec 15, 2024
1 parent d215007 commit 0b4fb23
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,36 +1077,42 @@ SleepEx_Detour (DWORD dwMilliseconds, BOOL bAlertable)
static const auto game_id =
SK_GetCurrentGameID ();

// TODO: Move into actual plug-in
if (game_id == SK_GAME_ID::ChronoCross)
if (dwMilliseconds == 0)
{
if (dwMilliseconds == 0)
// TODO: Move into actual plug-in
switch (game_id)
{
return
SwitchToThread ();
}
}
case SK_GAME_ID::ChronoCross:
case SK_GAME_ID::Starfield:
{
return
SwitchToThread ();
} break;

else if (game_id == SK_GAME_ID::Starfield)
{
if (dwMilliseconds == 0)
{
return
SwitchToThread ();
}
}
default:
{
if (! SK_GetCurrentRenderBackend ().windows.unity)
{
return
SK_SleepEx (dwMilliseconds, bAlertable);
}

if (dwMilliseconds == 0)
{
return
SK_SleepEx (dwMilliseconds, bAlertable);
else
{
return
SwitchToThread ();
}
} break;
}
}

#if 0
// Early-out for fmod, it uses SleepEx (...) instead of signaled waits,
// and it's for audio mixing, so we don't want to touch it.
if (auto early_out = SleepEx_EarlyOutForModule (dwMilliseconds, bAlertable, hModFmodStudio, L"fmodstudio.dll", _ReturnAddress ());
early_out != (DWORD)-1)
return early_out;
#endif

SK_TLS* pTLS = nullptr;
SK_MMCS_ApplyPendingTaskPriority (&pTLS);
Expand Down

0 comments on commit 0b4fb23

Please sign in to comment.