mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
don't allow punished scripts to slow stop or shutdown
This commit is contained in:
parent
17a5fa040d
commit
755989b8ff
1 changed files with 12 additions and 2 deletions
|
@ -845,14 +845,24 @@ void ScriptEngine::run() {
|
||||||
// it means our script is taking too long in it's updates, and we want to punish the
|
// it means our script is taking too long in it's updates, and we want to punish the
|
||||||
// script a little bit. So we will force the sleepUntil to be at least our averageUpdate
|
// script a little bit. So we will force the sleepUntil to be at least our averageUpdate
|
||||||
// time into the future.
|
// time into the future.
|
||||||
auto wouldSleep = (sleepUntil - clock::now());
|
auto wouldSleep = (sleepUntil - beforeSleep);
|
||||||
auto avgerageUpdate = totalUpdates / thisFrame;
|
auto avgerageUpdate = totalUpdates / thisFrame;
|
||||||
|
|
||||||
if (wouldSleep < avgerageUpdate) {
|
if (wouldSleep < avgerageUpdate) {
|
||||||
sleepUntil = beforeSleep + avgerageUpdate;
|
sleepUntil = beforeSleep + avgerageUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::sleep_until(sleepUntil);
|
// We don't want to actually sleep for too long, because it causes our scripts to hang
|
||||||
|
// on shutdown and stop... so we want to loop and sleep until we've spent our time in
|
||||||
|
// purgatory, constantly checking to see if our script was asked to end
|
||||||
|
while (!_isFinished && clock::now() < sleepUntil) {
|
||||||
|
auto wouldSleepSlice = (sleepUntil - clock::now());
|
||||||
|
auto thisSleepUntil = sleepUntil;
|
||||||
|
if (wouldSleepSlice > FRAME_DURATION) {
|
||||||
|
thisSleepUntil = clock::now() + FRAME_DURATION;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_until(thisSleepUntil);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SCRIPT_DELAY_DEBUG
|
#ifdef SCRIPT_DELAY_DEBUG
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue