TOON: Ensure minimum delay in worst case of render() loop to allow thread scheduling.

This should ensure that CPU usage is not pegged at 100%.

svn-id: r55790
This commit is contained in:
David Turner 2011-02-05 21:58:44 +00:00
parent e990453a4d
commit 36b6d961c2

View File

@ -419,13 +419,13 @@ void ToonEngine::render() {
copyToVirtualScreen(true);
}
// add a little sleep here if needed.
// add a little sleep here
int32 newMillis = (int32)_system->getMillis();
if (newMillis - _lastRenderTime < _tickLength) {
int32 sleepMs = _tickLength - (newMillis - _lastRenderTime);
assert(sleepMs >= 0);
_system->delayMillis(sleepMs);
}
int32 sleepMs = 1; // Minimum delay to allow thread scheduling
if ((newMillis - _lastRenderTime) < _tickLength)
sleepMs = _tickLength - (newMillis - _lastRenderTime);
assert(sleepMs >= 0);
_system->delayMillis(sleepMs);
_lastRenderTime = _system->getMillis();
}