remainder->fmod!

This commit is contained in:
Howard Stearns 2015-11-20 09:49:14 -08:00
parent 431a8c9584
commit 0f6a37f0f7
4 changed files with 14 additions and 9 deletions

View file

@ -1112,7 +1112,8 @@ void Application::paintGL() {
// the key part (and not an exagerated part) of _lastPaintWait is accounted for.
const float targetPeriod = getTargetFramePeriod();
if (_lastPaintWait > EPSILON && actualPeriod > targetPeriod) {
deducedNonVSyncPeriod += remainder(actualPeriod, _lastPaintWait);
// Don't use C++ remainder(). It's authors are mathematically insane.
deducedNonVSyncPeriod += fmod(actualPeriod, _lastPaintWait);
}
_lastDeducedNonVSyncFps = 1.0f / deducedNonVSyncPeriod;
_lastInstantaneousFps = instantaneousFps;

View file

@ -93,16 +93,15 @@ void AvatarManager::init() {
const float target_fps = 1.0f / qApp->getTargetFramePeriod();
_renderDistanceController.setMeasuredValueSetpoint(target_fps);
const float TREE_SCALE = 32768.0f; // Not in shared library, alas.
const float SMALLEST_REASONABLE_HORIZON = 5.0f; // meters
_renderDistanceController.setControlledValueHighLimit(1.0f / SMALLEST_REASONABLE_HORIZON);
_renderDistanceController.setControlledValueLowLimit(1.0f / TREE_SCALE);
_renderDistanceController.setControlledValueLowLimit(1.0f / (float) TREE_SCALE);
// Advice for tuning parameters:
// See PIDController.h. There's a sectionon tuning in the reference.
// See PIDController.h. There's a section on tuning in the reference.
// Turn on logging with the following (or from js with AvatarList.setRenderDistanceControllerHistory("avatar render", 300))
//_renderDistanceController.setHistorySize("avatar render", target_fps * 4);
// Note that extra logging/hysteresis is turned off in Avatar.cpp when the above logging is on.
_renderDistanceController.setKP(0.0005f); // Usually about 0.6 of largest that doesn't oscillate when other constants 0.
_renderDistanceController.setKP(0.0005f); // Usually about 0.6 of largest that doesn't oscillate when other parameters 0.
_renderDistanceController.setKI(0.0004f); // Big enough to bring us to target with the above KP.
_renderDistanceController.setKD(0.00001f); // A touch of kd increases the speed by which we get there.
@ -136,6 +135,10 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
const float fps = qApp->getLastInstanteousFps();
const float paintWait = qApp->getLastPaintWait();
// The PID controller raises the controlled value when the measured value goes up.
// The measured value is frame rate. When the controlled value (1 / render cutoff distance)
// goes up, the render cutoff distance gets closer, the number of rendered avatars is less, and frame rate
// goes up.
const float deduced = qApp->getLastDeducedNonVSyncFps();
const float distance = 1.0f / _renderDistanceController.update(deduced, deltaTime, false, fps, paintWait);
_renderDistanceAverage.updateAverage(distance);

View file

@ -102,7 +102,7 @@ private:
QVector<AvatarManager::LocalLight> _localLights;
bool _shouldShowReceiveStats = false;
float _renderDistance { 40.0f };
float _renderDistance { (float) TREE_SCALE };
int _renderedAvatarCount {0};
PIDController _renderDistanceController {};
SimpleMovingAverage _renderDistanceAverage {10};

View file

@ -21,12 +21,12 @@
#include <limits>
#include <QVector>
// Although our coding standard shuns abbreviations, the control systems literature pretty uniformly uses p, i, d, and dt rather than
// Although our coding standard shuns abbreviations, the control systems literature uniformly uses p, i, d, and dt rather than
// proportionalTerm, integralTerm, derivativeTerm, and deltaTime. Here we will be consistent with the literature.
class PIDController {
public:
// These four the main interface:
// These are the main interfaces:
void setMeasuredValueSetpoint(float newValue) { _measuredValueSetpoint = newValue; }
float update(float measuredValue, float dt, bool resetAccumulator = false, float FIXME1 = 0.0f, float FIXME2 = 0.0f); // returns the new computedValue
void setHistorySize(QString label = QString(""), int size = 0) { _history.reserve(size); _history.resize(0); _label = label; } // non-empty does logging
@ -78,9 +78,10 @@ protected:
float _ki { 0.0f };
float _kd { 0.0f };
// Controller state
// Controller operating state
float _lastError{ 0.0f };
float _lastAccumulation{ 0.0f };
// reporting
QVector<Row> _history{};
QString _label{ "" };