From 19b71892692a6754571ea7ee5653a9c14008267a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 27 Feb 2014 18:00:58 -0800 Subject: [PATCH] switch AUTO LOD to use moving avarage of FPS, and also tweak the min and max behavior --- interface/src/Menu.cpp | 33 ++++++++++++++++++++++++++++----- interface/src/Menu.h | 3 ++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 830ac17ebd..a33b4ee5d5 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -56,6 +56,7 @@ Menu* Menu::getInstance() { const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f}; const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f; +const int FIVE_SECONDS_OF_FRAMES = 5 * 60; Menu::Menu() : _actionHash(), @@ -72,6 +73,7 @@ Menu::Menu() : _boundaryLevelAdjust(0), _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), _lastAdjust(usecTimestampNow()), + _fpsAverage(FIVE_SECONDS_OF_FRAMES), _loginAction(NULL) { Application *appInstance = Application::getInstance(); @@ -1105,22 +1107,43 @@ void Menu::voxelStatsDetailsClosed() { } void Menu::autoAdjustLOD(float currentFPS) { + // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't + // really want to count them in our average, so we will ignore the real frame rates and stuff + // our moving average with simulated good data + const int IGNORE_THESE_SAMPLES = 100; + const float ASSUMED_FPS = 60.0f; + if (_fpsAverage.getSampleCount() < IGNORE_THESE_SAMPLES) { + currentFPS = ASSUMED_FPS; + } + _fpsAverage.updateAverage(currentFPS); + bool changed = false; quint64 now = usecTimestampNow(); quint64 elapsed = now - _lastAdjust; - - if (elapsed > ADJUST_LOD_DOWN_DELAY && currentFPS < ADJUST_LOD_DOWN_FPS && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { + + if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS + && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { + _voxelSizeScale *= ADJUST_LOD_DOWN_BY; + if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { + _voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; + } changed = true; _lastAdjust = now; - qDebug() << "adjusting LOD down... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale; + qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() + << "_voxelSizeScale=" << _voxelSizeScale; } - if (elapsed > ADJUST_LOD_UP_DELAY && currentFPS > ADJUST_LOD_UP_FPS && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { + if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS + && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { _voxelSizeScale *= ADJUST_LOD_UP_BY; + if (_voxelSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) { + _voxelSizeScale = ADJUST_LOD_MAX_SIZE_SCALE; + } changed = true; _lastAdjust = now; - qDebug() << "adjusting LOD up... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale; + qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() + << "_voxelSizeScale=" << _voxelSizeScale; } if (changed) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 84a5eef481..3d8aa24cbd 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -27,7 +27,7 @@ const quint64 ADJUST_LOD_UP_DELAY = ADJUST_LOD_DOWN_DELAY * 2; const float ADJUST_LOD_DOWN_BY = 0.9f; const float ADJUST_LOD_UP_BY = 1.1f; -const float ADJUST_LOD_MIN_SIZE_SCALE = TREE_SCALE * 1.0f; +const float ADJUST_LOD_MIN_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE * 0.25f; const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE; enum FrustumDrawMode { @@ -193,6 +193,7 @@ private: QMenu* _activeScriptsMenu; QString replaceLastOccurrence(QChar search, QChar replace, QString string); quint64 _lastAdjust; + SimpleMovingAverage _fpsAverage; QAction* _loginAction; };