History

Merge branch 'master' of github.com:highfidelity/hifi into tablet-ui

Seth Alves committed 9 years ago

Commit d072b152 parents 2ba8a53 86c0d7660 files · +1502 −427Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 60 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+6−28
@@ -911,19 +911,11 @@ void ScriptEngine::run() { · 910 unmodified lines
911911 break;
912912 }
913913
914− // determine how long before the next timer should fire, we'd ideally like to sleep just
915− // that long, so the next processEvents() will allow the timers to fire on time.
916− const std::chrono::microseconds minTimerTimeRemaining(USECS_PER_MSEC * getTimersRemainingTime());
917−
918− // However, if we haven't yet slept at least as long as our average timer per frame, then we will
919− // punish the timers to at least wait as long as the average run time of the timers.
920− auto untilTimer = std::max(minTimerTimeRemaining, averageTimerPerFrame);
921−
922− // choose the closest time point, our
923− auto remainingSleepUntil = std::chrono::duration_cast<std::chrono::microseconds>(sleepUntil - clock::now());
924− auto closestUntil = std::min(remainingSleepUntil, untilTimer);
925− auto thisSleepUntil = std::min(sleepUntil, clock::now() + closestUntil);
926− std::this_thread::sleep_until(thisSleepUntil);
914+ // We only want to sleep a small amount so that any pending events (like timers or invokeMethod events)
915+ // will be able to process quickly.
916+ static const int SMALL_SLEEP_AMOUNT = 100;
917+ auto smallSleepUntil = clock::now() + static_cast<std::chrono::microseconds>(SMALL_SLEEP_AMOUNT);
918+ std::this_thread::sleep_until(smallSleepUntil);
927919 }
928920
929921 #ifdef SCRIPT_DELAY_DEBUG
@@ -1013,21 +1005,6 @@ void ScriptEngine::run() { · 83 unmodified lines
10131005 emit doneRunning();
10141006 }
10151007
1016−quint64 ScriptEngine::getTimersRemainingTime() {
1017− quint64 minimumTime = USECS_PER_SECOND; // anything larger than this can be ignored
1018− QMutableHashIterator<QTimer*, CallbackData> i(_timerFunctionMap);
1019− while (i.hasNext()) {
1020− i.next();
1021− QTimer* timer = i.key();
1022− int remainingTime = timer->remainingTime();
1023− if (remainingTime >= 0) {
1024− minimumTime = std::min((quint64)remainingTime, minimumTime);
1025− }
1026− }
1027− return minimumTime;
1028−}
1029−
1030−
10311008 // NOTE: This is private because it must be called on the same thread that created the timers, which is why
10321009 // we want to only call it in our own run "shutdown" processing.
10331010 void ScriptEngine::stopAllTimers() {
@@ -1038,6 +1015,7 @@ void ScriptEngine::stopAllTimers() { · 4 unmodified lines
10381015 stopTimer(timer);
10391016 }
10401017 }
1018+
10411019 void ScriptEngine::stopAllTimersForEntityScript(const EntityItemID& entityID) {
10421020 // We could maintain a separate map of entityID => QTimer, but someone will have to prove to me that it's worth the complexity. -HRS
10431021 QVector<QTimer*> toDelete;