mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-09 06:39:30 +02:00
Merge pull request #7962 from zzmp/fix/throttle
fix throttling when Interface is not in focus
This commit is contained in:
commit
f16a3ce6bb
2 changed files with 26 additions and 22 deletions
|
@ -174,7 +174,6 @@ static const QString FBX_EXTENSION = ".fbx";
|
||||||
static const QString OBJ_EXTENSION = ".obj";
|
static const QString OBJ_EXTENSION = ".obj";
|
||||||
static const QString AVA_JSON_EXTENSION = ".ava.json";
|
static const QString AVA_JSON_EXTENSION = ".ava.json";
|
||||||
|
|
||||||
static const int MSECS_PER_SEC = 1000;
|
|
||||||
static const int MIRROR_VIEW_TOP_PADDING = 5;
|
static const int MIRROR_VIEW_TOP_PADDING = 5;
|
||||||
static const int MIRROR_VIEW_LEFT_PADDING = 10;
|
static const int MIRROR_VIEW_LEFT_PADDING = 10;
|
||||||
static const int MIRROR_VIEW_WIDTH = 265;
|
static const int MIRROR_VIEW_WIDTH = 265;
|
||||||
|
@ -633,7 +632,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
|
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
|
||||||
|
|
||||||
// update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
|
// update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
|
||||||
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SEC;
|
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND;
|
||||||
|
|
||||||
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
|
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
|
||||||
connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
|
connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
|
||||||
|
@ -1828,9 +1827,9 @@ bool Application::event(QEvent* event) {
|
||||||
|
|
||||||
// Presentation/painting logic
|
// Presentation/painting logic
|
||||||
// TODO: Decouple presentation and painting loops
|
// TODO: Decouple presentation and painting loops
|
||||||
static bool isPainting = false;
|
static bool isPaintingThrottled = false;
|
||||||
if ((int)event->type() == (int)Present) {
|
if ((int)event->type() == (int)Present) {
|
||||||
if (isPainting) {
|
if (isPaintingThrottled) {
|
||||||
// If painting (triggered by presentation) is hogging the main thread,
|
// If painting (triggered by presentation) is hogging the main thread,
|
||||||
// repost as low priority to avoid hanging the GUI.
|
// repost as low priority to avoid hanging the GUI.
|
||||||
// This has the effect of allowing presentation to exceed the paint budget by X times and
|
// This has the effect of allowing presentation to exceed the paint budget by X times and
|
||||||
|
@ -1838,14 +1837,17 @@ bool Application::event(QEvent* event) {
|
||||||
// (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
|
// (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
|
||||||
removePostedEvents(this, Present);
|
removePostedEvents(this, Present);
|
||||||
postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
|
postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
|
||||||
isPainting = false;
|
isPaintingThrottled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
idle();
|
float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
|
||||||
|
if (shouldPaint(nsecsElapsed)) {
|
||||||
|
_lastTimeUpdated.start();
|
||||||
|
idle(nsecsElapsed);
|
||||||
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
|
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
|
||||||
isPainting = true;
|
}
|
||||||
|
isPaintingThrottled = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if ((int)event->type() == (int)Paint) {
|
} else if ((int)event->type() == (int)Paint) {
|
||||||
|
@ -1855,7 +1857,7 @@ bool Application::event(QEvent* event) {
|
||||||
|
|
||||||
paintGL();
|
paintGL();
|
||||||
|
|
||||||
isPainting = false;
|
isPaintingThrottled = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2639,10 +2641,9 @@ bool Application::acceptSnapshot(const QString& urlString) {
|
||||||
|
|
||||||
static uint32_t _renderedFrameIndex { INVALID_FRAME };
|
static uint32_t _renderedFrameIndex { INVALID_FRAME };
|
||||||
|
|
||||||
void Application::idle() {
|
bool Application::shouldPaint(float nsecsElapsed) {
|
||||||
// idle is called on a queued connection, so make sure we should be here.
|
if (_aboutToQuit) {
|
||||||
if (_inPaint || _aboutToQuit) {
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto displayPlugin = getActiveDisplayPlugin();
|
auto displayPlugin = getActiveDisplayPlugin();
|
||||||
|
@ -2661,16 +2662,21 @@ void Application::idle() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float msecondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC / USECS_PER_MSEC;
|
float msecondsSinceLastUpdate = nsecsElapsed / NSECS_PER_USEC / USECS_PER_MSEC;
|
||||||
|
|
||||||
// Throttle if requested
|
// Throttle if requested
|
||||||
if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
|
if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync up the _renderedFrameIndex
|
// Sync up the _renderedFrameIndex
|
||||||
_renderedFrameIndex = displayPlugin->presentCount();
|
_renderedFrameIndex = displayPlugin->presentCount();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::idle(float nsecsElapsed) {
|
||||||
|
|
||||||
// Update the deadlock watchdog
|
// Update the deadlock watchdog
|
||||||
updateHeartbeat();
|
updateHeartbeat();
|
||||||
|
|
||||||
|
@ -2687,7 +2693,7 @@ void Application::idle() {
|
||||||
|
|
||||||
PROFILE_RANGE(__FUNCTION__);
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
|
|
||||||
float secondsSinceLastUpdate = msecondsSinceLastUpdate / MSECS_PER_SECOND;
|
float secondsSinceLastUpdate = nsecsElapsed / NSECS_PER_MSEC / MSECS_PER_SECOND;
|
||||||
|
|
||||||
// If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
|
// If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
|
||||||
if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
|
if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
|
||||||
|
@ -2697,9 +2703,6 @@ void Application::idle() {
|
||||||
_keyboardDeviceHasFocus = true;
|
_keyboardDeviceHasFocus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're going to execute idle processing, so restart the last idle timer
|
|
||||||
_lastTimeUpdated.start();
|
|
||||||
|
|
||||||
checkChangeCursor();
|
checkChangeCursor();
|
||||||
|
|
||||||
Stats::getInstance()->updateStats();
|
Stats::getInstance()->updateStats();
|
||||||
|
@ -2926,7 +2929,7 @@ void Application::loadSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::saveSettings() const {
|
void Application::saveSettings() const {
|
||||||
sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SEC);
|
sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SECOND);
|
||||||
DependencyManager::get<AudioClient>()->saveSettings();
|
DependencyManager::get<AudioClient>()->saveSettings();
|
||||||
DependencyManager::get<LODManager>()->saveSettings();
|
DependencyManager::get<LODManager>()->saveSettings();
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,8 @@ private:
|
||||||
|
|
||||||
void cleanupBeforeQuit();
|
void cleanupBeforeQuit();
|
||||||
|
|
||||||
void idle();
|
bool shouldPaint(float nsecsElapsed);
|
||||||
|
void idle(float nsecsElapsed);
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
|
|
||||||
// Various helper functions called during update()
|
// Various helper functions called during update()
|
||||||
|
|
Loading…
Reference in a new issue