LODManager uses new settings

This commit is contained in:
Atlante45 2015-01-19 21:27:21 -08:00
parent d0d16e088e
commit 23bab601c5
2 changed files with 66 additions and 51 deletions

View file

@ -16,6 +16,29 @@
#include "LODManager.h" #include "LODManager.h"
namespace SettingsKey {
const SettingHandle<int> boundaryLevelAdjust("boundaryLevelAdjust", 0);
const SettingHandle<float> octreeSizeScale("octreeSizeScale", DEFAULT_OCTREE_SIZE_SCALE);
}
float LODManager::getOctreeSizeScale() const {
return SettingsKey::octreeSizeScale.get();
}
void LODManager::setOctreeSizeScale(float sizeScale) {
SettingsKey::octreeSizeScale.set(sizeScale);
_shouldRenderTableNeedsRebuilding = true;
}
int LODManager::getBoundaryLevelAdjust() const {
return SettingsKey::boundaryLevelAdjust.get();
}
void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
SettingsKey::boundaryLevelAdjust.set(boundaryLevelAdjust);
_shouldRenderTableNeedsRebuilding = true;
}
void LODManager::autoAdjustLOD(float currentFPS) { void LODManager::autoAdjustLOD(float currentFPS) {
// NOTE: our first ~100 samples at app startup are completely all over the place, and we don't // 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 // really want to count them in our average, so we will ignore the real frame rates and stuff
@ -31,54 +54,63 @@ void LODManager::autoAdjustLOD(float currentFPS) {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000; const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000;
if (_automaticAvatarLOD) { bool automaticAvatarLOD = SettingHandles::automaticAvatarLOD.get();
if (_fastFPSAverage.getAverage() < _avatarLODDecreaseFPS) { if (automaticAvatarLOD) {
float avatarLODIncreaseFPS = SettingHandles::avatarLODIncreaseFPS.get();
float avatarLODDecreaseFPS = SettingHandles::avatarLODDecreaseFPS.get();
float avatarLODDistanceMultiplier = SettingHandles::avatarLODDistanceMultiplier.get();
if (_fastFPSAverage.getAverage() < avatarLODDecreaseFPS) {
if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) { if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) {
// attempt to lower the detail in proportion to the fps difference // attempt to lower the detail in proportion to the fps difference
float targetFps = (_avatarLODDecreaseFPS + _avatarLODIncreaseFPS) * 0.5f; float targetFps = (avatarLODDecreaseFPS + avatarLODIncreaseFPS) * 0.5f;
float averageFps = _fastFPSAverage.getAverage(); float averageFps = _fastFPSAverage.getAverage();
const float MAXIMUM_MULTIPLIER_SCALE = 2.0f; const float MAXIMUM_MULTIPLIER_SCALE = 2.0f;
_avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, _avatarLODDistanceMultiplier * avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER,
(averageFps < EPSILON ? MAXIMUM_MULTIPLIER_SCALE : avatarLODDistanceMultiplier * (averageFps < EPSILON ?
qMin(MAXIMUM_MULTIPLIER_SCALE, targetFps / averageFps))); MAXIMUM_MULTIPLIER_SCALE :
qMin(MAXIMUM_MULTIPLIER_SCALE,
targetFps / averageFps)));
_lastAvatarDetailDrop = now; _lastAvatarDetailDrop = now;
} }
} else if (_fastFPSAverage.getAverage() > _avatarLODIncreaseFPS) { } else if (_fastFPSAverage.getAverage() > avatarLODIncreaseFPS) {
// let the detail level creep slowly upwards // let the detail level creep slowly upwards
const float DISTANCE_DECREASE_RATE = 0.05f; const float DISTANCE_DECREASE_RATE = 0.05f;
_avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER,
_avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE); avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE);
} }
SettingHandles::avatarLODDistanceMultiplier.set(avatarLODDistanceMultiplier);
} }
bool changed = false; bool changed = false;
quint64 elapsed = now - _lastAdjust; quint64 elapsed = now - _lastAdjust;
float octreeSizeScale = getOctreeSizeScale();
if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS
&& _octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { && octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
_octreeSizeScale *= ADJUST_LOD_DOWN_BY; octreeSizeScale *= ADJUST_LOD_DOWN_BY;
if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { if (octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
_octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
} }
changed = true; changed = true;
_lastAdjust = now; _lastAdjust = now;
qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_octreeSizeScale=" << _octreeSizeScale; << "_octreeSizeScale=" << octreeSizeScale;
} }
if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS
&& _octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { && octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
_octreeSizeScale *= ADJUST_LOD_UP_BY; octreeSizeScale *= ADJUST_LOD_UP_BY;
if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) { if (octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
_octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE; octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
} }
changed = true; changed = true;
_lastAdjust = now; _lastAdjust = now;
qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_octreeSizeScale=" << _octreeSizeScale; << "_octreeSizeScale=" << octreeSizeScale;
} }
setOctreeSizeScale(octreeSizeScale);
if (changed) { if (changed) {
_shouldRenderTableNeedsRebuilding = true; _shouldRenderTableNeedsRebuilding = true;
@ -129,16 +161,6 @@ QString LODManager::getLODFeedbackText() {
return result; return result;
} }
void LODManager::setOctreeSizeScale(float sizeScale) {
_octreeSizeScale = sizeScale;
_shouldRenderTableNeedsRebuilding = true;
}
void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
_boundaryLevelAdjust = boundaryLevelAdjust;
_shouldRenderTableNeedsRebuilding = true;
}
// TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells // TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells
// I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. // I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it.
bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) { bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) {

View file

@ -14,6 +14,7 @@
#include <DependencyManager.h> #include <DependencyManager.h>
#include <OctreeConstants.h> #include <OctreeConstants.h>
#include <Settings.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <SimpleMovingAverage.h> #include <SimpleMovingAverage.h>
@ -37,26 +38,26 @@ const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f;
const int ONE_SECOND_OF_FRAMES = 60; const int ONE_SECOND_OF_FRAMES = 60;
const int FIVE_SECONDS_OF_FRAMES = 5 * ONE_SECOND_OF_FRAMES; const int FIVE_SECONDS_OF_FRAMES = 5 * ONE_SECOND_OF_FRAMES;
namespace SettingHandles {
const SettingHandle<bool> automaticAvatarLOD("automaticAvatarLOD", true);
const SettingHandle<float> avatarLODDecreaseFPS("avatarLODDecreaseFPS", DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS);
const SettingHandle<float> avatarLODIncreaseFPS("avatarLODIncreaseFPS", ADJUST_LOD_UP_FPS);
const SettingHandle<float> avatarLODDistanceMultiplier("avatarLODDistanceMultiplier",
DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER);
}
class LODManager : public Dependency { class LODManager : public Dependency {
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
void setAutomaticAvatarLOD(bool automaticAvatarLOD) { _automaticAvatarLOD = automaticAvatarLOD; } // TODO: Once the SettingWatcher is implemented, replace them with normal SettingHandles.
bool getAutomaticAvatarLOD() const { return _automaticAvatarLOD; } float getOctreeSizeScale() const;
void setAvatarLODDecreaseFPS(float avatarLODDecreaseFPS) { _avatarLODDecreaseFPS = avatarLODDecreaseFPS; } void setOctreeSizeScale(float sizeScale);
float getAvatarLODDecreaseFPS() const { return _avatarLODDecreaseFPS; } int getBoundaryLevelAdjust() const;
void setAvatarLODIncreaseFPS(float avatarLODIncreaseFPS) { _avatarLODIncreaseFPS = avatarLODIncreaseFPS; } void setBoundaryLevelAdjust(int boundaryLevelAdjust);
float getAvatarLODIncreaseFPS() const { return _avatarLODIncreaseFPS; }
void setAvatarLODDistanceMultiplier(float multiplier) { _avatarLODDistanceMultiplier = multiplier; }
float getAvatarLODDistanceMultiplier() const { return _avatarLODDistanceMultiplier; }
// User Tweakable LOD Items // User Tweakable LOD Items
QString getLODFeedbackText(); QString getLODFeedbackText();
void setOctreeSizeScale(float sizeScale);
float getOctreeSizeScale() const { return _octreeSizeScale; }
void setBoundaryLevelAdjust(int boundaryLevelAdjust);
int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; }
void autoAdjustLOD(float currentFPS); void autoAdjustLOD(float currentFPS);
void resetLODAdjust(); void resetLODAdjust();
@ -66,14 +67,6 @@ public:
private: private:
LODManager() {} LODManager() {}
bool _automaticAvatarLOD = true;
float _avatarLODDecreaseFPS = DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS;
float _avatarLODIncreaseFPS = ADJUST_LOD_UP_FPS;
float _avatarLODDistanceMultiplier = DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER;
float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE;
int _boundaryLevelAdjust = 0;
quint64 _lastAdjust = 0; quint64 _lastAdjust = 0;
quint64 _lastAvatarDetailDrop = 0; quint64 _lastAvatarDetailDrop = 0;
SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES; SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES;