From 68e730af454938854d4220c92de521c53b399a18 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 25 Mar 2015 15:48:50 -0700 Subject: [PATCH] handle throttle render case and clean up code logic to be more obvious --- interface/src/LODManager.cpp | 46 ++++++++++++++++++++---------------- interface/src/LODManager.h | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 751bea8c23..e1a82372d2 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -50,6 +50,7 @@ void LODManager::autoAdjustLOD(float currentFPS) { currentFPS = ASSUMED_FPS; _lastUpShift = _lastDownShift = usecTimestampNow(); } + _fpsAverageStartWindow.updateAverage(currentFPS); _fpsAverageDownWindow.updateAverage(currentFPS); _fpsAverageUpWindow.updateAverage(currentFPS); @@ -64,12 +65,17 @@ void LODManager::autoAdjustLOD(float currentFPS) { if (_automaticLODAdjust) { // LOD Downward adjustment - // If our last adjust was an upshift, then we don't want to consider any downshifts until we've delayed at least - // our START_DELAY_WINDOW_IN_SECS - bool doDownShift = _lastAdjustWasUpShift - ? (elapsedSinceUpShift > START_SHIFT_ELPASED && _fpsAverageStartWindow.getAverage() < getLODDecreaseFPS()) - : (elapsedSinceDownShift > DOWN_SHIFT_ELPASED && _fpsAverageDownWindow.getAverage() < getLODDecreaseFPS()); + // If we've been downshifting, we watch a shorter downshift window so that we will quickly move toward our + // target frame rate. But if we haven't just done a downshift (either because our last shift was an upshift, + // or because we've just started out) then we look at a much longer window to consider whether or not to start + // downshifting. + bool doDownShift = false; + if (_isDownshifting) { + doDownShift = (elapsedSinceDownShift > DOWN_SHIFT_ELPASED && _fpsAverageDownWindow.getAverage() < getLODDecreaseFPS()); + } else { + doDownShift = (elapsedSinceUpShift > START_SHIFT_ELPASED && _fpsAverageStartWindow.getAverage() < getLODDecreaseFPS()); + } if (doDownShift) { @@ -83,24 +89,26 @@ void LODManager::autoAdjustLOD(float currentFPS) { } if (changed) { - if (_lastAdjustWasUpShift) { - qDebug() << "adjusting LOD DOWN after initial delay..." - << "average fps for last "<< START_DELAY_WINDOW_IN_SECS <<"seconds was " - << _fpsAverageStartWindow.getAverage() - << "minimum is:" << getLODDecreaseFPS() - << "elapsedSinceUpShift:" << elapsedSinceUpShift - << " NEW _octreeSizeScale=" << _octreeSizeScale; - } else { + if (_isDownshifting) { + // subsequent downshift qDebug() << "adjusting LOD DOWN..." << "average fps for last "<< DOWN_SHIFT_WINDOW_IN_SECS <<"seconds was " << _fpsAverageDownWindow.getAverage() << "minimum is:" << getLODDecreaseFPS() << "elapsedSinceDownShift:" << elapsedSinceDownShift << " NEW _octreeSizeScale=" << _octreeSizeScale; + } else { + // first downshift + qDebug() << "adjusting LOD DOWN after initial delay..." + << "average fps for last "<< START_DELAY_WINDOW_IN_SECS <<"seconds was " + << _fpsAverageStartWindow.getAverage() + << "minimum is:" << getLODDecreaseFPS() + << "elapsedSinceUpShift:" << elapsedSinceUpShift + << " NEW _octreeSizeScale=" << _octreeSizeScale; } _lastDownShift = now; - _lastAdjustWasUpShift = false; + _isDownshifting = true; emit LODDecreased(); } @@ -130,7 +138,7 @@ void LODManager::autoAdjustLOD(float currentFPS) { << " NEW _octreeSizeScale=" << _octreeSizeScale; _lastUpShift = now; - _lastAdjustWasUpShift = true; + _isDownshifting = false; emit LODIncreased(); } @@ -149,13 +157,11 @@ void LODManager::autoAdjustLOD(float currentFPS) { } void LODManager::resetLODAdjust() { - - // TODO: Do we need this??? - /* + _fpsAverageStartWindow.reset(); _fpsAverageDownWindow.reset(); _fpsAverageUpWindow.reset(); - _lastAdjust = usecTimestampNow(); - */ + _lastUpShift = _lastDownShift = usecTimestampNow(); + _isDownshifting = false; } QString LODManager::getLODFeedbackText() { diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 3f9d2046c1..d3765c164a 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -107,7 +107,7 @@ private: quint64 _lastDownShift = 0; quint64 _lastUpShift = 0; - bool _lastAdjustWasUpShift = true; // start out as if we've just upshifted + bool _isDownshifting = false; // start out as if we're not downshifting SimpleMovingAverage _fpsAverageStartWindow = START_DELAY_SAMPLES_OF_FRAMES; SimpleMovingAverage _fpsAverageDownWindow = DOWN_SHIFT_SAMPLES_OF_FRAMES;