History

Merge branch 'master' of https://github.com/worklist/hifi

Philip Rosedale committed 12 years ago

Commit 7a2279b2 parents d5e106b bde71525 files · +58 −17Browse files

Showing the changes to interface/src/Menu.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Menu.cpp+28−5
@@ -56,6 +56,7 @@ Menu* Menu::getInstance() { · 55 unmodified lines
5656
5757 const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f};
5858 const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f;
59+const int FIVE_SECONDS_OF_FRAMES = 5 * 60;
5960
6061 Menu::Menu() :
6162 _actionHash(),
@@ -72,6 +73,7 @@ Menu::Menu() : · 10 unmodified lines
7273 _boundaryLevelAdjust(0),
7374 _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS),
7475 _lastAdjust(usecTimestampNow()),
76+ _fpsAverage(FIVE_SECONDS_OF_FRAMES),
7577 _loginAction(NULL)
7678 {
7779 Application *appInstance = Application::getInstance();
@@ -1104,22 +1106,43 @@ void Menu::voxelStatsDetailsClosed() { · 1026 unmodified lines
11041106 }
11051107
11061108 void Menu::autoAdjustLOD(float currentFPS) {
1109+ // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't
1110+ // really want to count them in our average, so we will ignore the real frame rates and stuff
1111+ // our moving average with simulated good data
1112+ const int IGNORE_THESE_SAMPLES = 100;
1113+ const float ASSUMED_FPS = 60.0f;
1114+ if (_fpsAverage.getSampleCount() < IGNORE_THESE_SAMPLES) {
1115+ currentFPS = ASSUMED_FPS;
1116+ }
1117+ _fpsAverage.updateAverage(currentFPS);
1118+
11071119 bool changed = false;
11081120 quint64 now = usecTimestampNow();
11091121 quint64 elapsed = now - _lastAdjust;
1110−
1111− if (elapsed > ADJUST_LOD_DOWN_DELAY && currentFPS < ADJUST_LOD_DOWN_FPS && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
1122+
1123+ if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS
1124+ && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
1125+
11121126 _voxelSizeScale *= ADJUST_LOD_DOWN_BY;
1127+ if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
1128+ _voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
1129+ }
11131130 changed = true;
11141131 _lastAdjust = now;
1115− qDebug() << "adjusting LOD down... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale;
1132+ qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
1133+ << "_voxelSizeScale=" << _voxelSizeScale;
11161134 }
11171135
1118− if (elapsed > ADJUST_LOD_UP_DELAY && currentFPS > ADJUST_LOD_UP_FPS && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
1136+ if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS
1137+ && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
11191138 _voxelSizeScale *= ADJUST_LOD_UP_BY;
1139+ if (_voxelSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
1140+ _voxelSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
1141+ }
11201142 changed = true;
11211143 _lastAdjust = now;
1122− qDebug() << "adjusting LOD up... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale;
1144+ qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
1145+ << "_voxelSizeScale=" << _voxelSizeScale;
11231146 }
11241147
11251148 if (changed) {