mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-08 07:02:25 +02:00
Refining the plot widget to be able to represent negative values
This commit is contained in:
parent
3c0e284e98
commit
ed4dbaa4c7
4 changed files with 87 additions and 13 deletions
|
@ -72,6 +72,11 @@ void LODManager::autoAdjustLOD(float realTimeDelta) {
|
|||
// Note: we MUST clamp the blend to 1.0 for stability
|
||||
float blend = (realTimeDelta < LOD_ADJUST_RUNNING_AVG_TIMESCALE) ? realTimeDelta / LOD_ADJUST_RUNNING_AVG_TIMESCALE : 1.0f;
|
||||
_avgRenderTime = (1.0f - blend) * _avgRenderTime + blend * maxRenderTime; // msec
|
||||
|
||||
float smoothBlend = (realTimeDelta < LOD_ADJUST_RUNNING_AVG_TIMESCALE * _pidCoefs.w) ? realTimeDelta / (LOD_ADJUST_RUNNING_AVG_TIMESCALE * _pidCoefs.w) : 1.0f;
|
||||
_smoothRenderTime = (1.0f - smoothBlend) * _smoothRenderTime + smoothBlend * maxRenderTime; // msec
|
||||
|
||||
|
||||
// _avgRenderTime = maxRenderTime;
|
||||
if (!_automaticLODAdjust || _avgRenderTime == 0.0f) {
|
||||
// early exit
|
||||
|
@ -82,13 +87,17 @@ void LODManager::autoAdjustLOD(float realTimeDelta) {
|
|||
float oldSolidAngle = getLODAngleDeg();
|
||||
|
||||
float targetFPS = 0.5 * (getLODDecreaseFPS() + getLODIncreaseFPS());
|
||||
// float targetFPS = (getLODDecreaseFPS());
|
||||
float targetPeriod = 1.0f / targetFPS;
|
||||
|
||||
float currentFPS = (float)MSECS_PER_SECOND / _avgRenderTime;
|
||||
|
||||
static uint64_t lastTime = usecTimestampNow();
|
||||
|
||||
uint64_t now = usecTimestampNow();
|
||||
auto dt = (float) ((now - lastTime) / double(USECS_PER_MSEC));
|
||||
if (dt < targetPeriod * _pidCoefs.w) return;
|
||||
// if (dt < targetPeriod * _pidCoefs.w) return;
|
||||
dt = realTimeDelta;
|
||||
|
||||
lastTime = now;
|
||||
auto previous_error = _pidHistory.x;
|
||||
|
@ -96,7 +105,12 @@ void LODManager::autoAdjustLOD(float realTimeDelta) {
|
|||
|
||||
auto error = (targetFPS - currentFPS) / targetFPS;
|
||||
error = glm::clamp(error, -1.0f, 1.0f);
|
||||
if (error <= 0.0f) {
|
||||
// error = error * 2.0f;
|
||||
}
|
||||
auto integral = previous_integral + error * dt;
|
||||
glm::clamp(integral, -1.0f, 1.0f);
|
||||
|
||||
auto derivative = (error - previous_error) / dt;
|
||||
|
||||
_pidHistory.x = error;
|
||||
|
|
|
@ -61,8 +61,13 @@ class LODManager : public QObject, public Dependency {
|
|||
Q_PROPERTY(float engineRunTime READ getEngineRunTime)
|
||||
Q_PROPERTY(float batchTime READ getBatchTime)
|
||||
Q_PROPERTY(float gpuTime READ getGPUTime)
|
||||
|
||||
Q_PROPERTY(float avgRenderTime READ getAverageRenderTime)
|
||||
Q_PROPERTY(float fps READ getMaxTheoreticalFPS)
|
||||
|
||||
Q_PROPERTY(float smoothRenderTime READ getSmoothRenderTime)
|
||||
Q_PROPERTY(float smoothFPS READ getSmoothFPS)
|
||||
|
||||
Q_PROPERTY(float lodLevel READ getLODLevel WRITE setLODLevel NOTIFY LODChanged)
|
||||
Q_PROPERTY(float lodDecreaseFPS READ getLODDecreaseFPS)
|
||||
Q_PROPERTY(float lodIncreaseFPS READ getLODIncreaseFPS)
|
||||
|
@ -193,6 +198,10 @@ public:
|
|||
float getAverageRenderTime() const { return _avgRenderTime; };
|
||||
float getMaxTheoreticalFPS() const { return (float)MSECS_PER_SECOND / _avgRenderTime; };
|
||||
|
||||
float getSmoothRenderTime() const { return _smoothRenderTime; };
|
||||
float getSmoothFPS() const { return (float)MSECS_PER_SECOND / _smoothRenderTime; };
|
||||
|
||||
|
||||
float getLODLevel() const;
|
||||
void setLODLevel(float level);
|
||||
|
||||
|
@ -246,13 +255,14 @@ private:
|
|||
float _gpuTime { 0.0f }; // msec
|
||||
|
||||
float _avgRenderTime { 0.0f }; // msec
|
||||
float _smoothRenderTime{ 0.0f };
|
||||
float _desktopMaxRenderTime { DEFAULT_DESKTOP_MAX_RENDER_TIME };
|
||||
float _hmdMaxRenderTime { DEFAULT_HMD_MAX_RENDER_TIME };
|
||||
|
||||
float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE;
|
||||
int _boundaryLevelAdjust = 0;
|
||||
|
||||
glm::vec4 _pidCoefs{ 4.0f, 0.0000000f, 0.f, 4.0f };
|
||||
glm::vec4 _pidCoefs{ 1.0f, 0.0000000f, 0.f, 8.0f };
|
||||
glm::vec4 _pidHistory{ 0.0f };
|
||||
glm::vec4 _pidOutputs{ 0.0f };
|
||||
|
||||
|
|
|
@ -50,6 +50,10 @@ Item {
|
|||
property var valueMax : 1
|
||||
property var valueMin : 0
|
||||
|
||||
property var displayMinAt0 : true
|
||||
property var _displayMaxValue : 1
|
||||
property var _displayMinValue : 0
|
||||
|
||||
property var _values
|
||||
property var tick : 0
|
||||
|
||||
|
@ -72,7 +76,9 @@ Item {
|
|||
value: value,
|
||||
fromBinding: isBinding,
|
||||
valueMax: 1,
|
||||
valueMin: 0,
|
||||
numSamplesConstantMax: 0,
|
||||
numSamplesConstantMin: 0,
|
||||
valueHistory: new Array(),
|
||||
label: (plot["label"] !== undefined ? plot["label"] : ""),
|
||||
color: (plot["color"] !== undefined ? plot["color"] : "white"),
|
||||
|
@ -129,7 +135,7 @@ Item {
|
|||
_values[i].valueMax = currentVal;
|
||||
_values[i].numSamplesConstantMax = 0
|
||||
}
|
||||
if (_values[i].valueMin < currentVal) {
|
||||
if (_values[i].valueMin > currentVal) {
|
||||
_values[i].valueMin = currentVal;
|
||||
_values[i].numSamplesConstantMin = 0
|
||||
}
|
||||
|
@ -146,7 +152,7 @@ Item {
|
|||
if (currentValueMax < _values[i].valueMax) {
|
||||
currentValueMax = _values[i].valueMax
|
||||
}
|
||||
if (currentValueMin < _values[i].valueMin) {
|
||||
if (currentValueMin > _values[i].valueMin) {
|
||||
currentValueMin = _values[i].valueMin
|
||||
}
|
||||
}
|
||||
|
@ -154,9 +160,12 @@ Item {
|
|||
if ((valueMax < currentValueMax) || (tick % VALUE_HISTORY_SIZE == 0)) {
|
||||
valueMax = currentValueMax;
|
||||
}
|
||||
if ((valueMin < currentValueMin) || (tick % VALUE_HISTORY_SIZE == 0)) {
|
||||
if ((valueMin > currentValueMin) || (tick % VALUE_HISTORY_SIZE == 0)) {
|
||||
valueMin = currentValueMin;
|
||||
}
|
||||
_displayMaxValue = valueMax;
|
||||
_displayMinValue = ( displayMinAt0 ? 0 : valueMin )
|
||||
|
||||
mycanvas.requestPaint()
|
||||
}
|
||||
|
||||
|
@ -177,10 +186,10 @@ Item {
|
|||
}
|
||||
|
||||
function pixelFromVal(val, valScale) {
|
||||
return lineHeight + (height - lineHeight) * (1 - (0.9) * val / valueMax);
|
||||
return lineHeight + (height - lineHeight) * (1 - (0.9) * (val - _displayMinValue) / (_displayMaxValue - _displayMinValue));
|
||||
}
|
||||
function valueFromPixel(pixY) {
|
||||
return ((pixY - lineHeight) / (height - lineHeight) - 1) * valueMax / (-0.9);
|
||||
return _displayMinValue + (((pixY - lineHeight) / (height - lineHeight) - 1) * (_displayMaxValue - _displayMinValue) / (-0.9));
|
||||
}
|
||||
function plotValueHistory(ctx, valHistory, color) {
|
||||
var widthStep= width / (valHistory.length - 1);
|
||||
|
@ -208,8 +217,10 @@ Item {
|
|||
function displayTitle(ctx, text, maxVal) {
|
||||
ctx.fillStyle = "grey";
|
||||
ctx.textAlign = "right";
|
||||
ctx.fillText(displayValue(valueFromPixel(lineHeight), root.valueUnit), width, lineHeight);
|
||||
ctx.fillText("max" + displayValue(_displayMaxValue, root.valueUnit), width, pixelFromVal(_displayMaxValue));
|
||||
|
||||
ctx.fillText("min" + displayValue(_displayMinValue, root.valueUnit), width, pixelFromVal(_displayMinValue));
|
||||
|
||||
ctx.fillStyle = "white";
|
||||
ctx.textAlign = "left";
|
||||
ctx.fillText(text, 0, lineHeight);
|
||||
|
@ -218,15 +229,39 @@ Item {
|
|||
ctx.fillStyle = Qt.rgba(0, 0, 0, root.backgroundOpacity);
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
ctx.strokeStyle= "grey";
|
||||
/* ctx.strokeStyle= "grey";
|
||||
ctx.lineWidth="2";
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, lineHeight + 1);
|
||||
ctx.lineTo(width, lineHeight + 1);
|
||||
ctx.lineTo(width, lineHeight + 1);
|
||||
ctx.moveTo(0, height);
|
||||
ctx.lineTo(width, height);
|
||||
ctx.stroke();*/
|
||||
}
|
||||
|
||||
function displayMaxZeroMin(ctx) {
|
||||
var maxY = pixelFromVal(_displayMaxValue);
|
||||
|
||||
ctx.strokeStyle= "LightSlateGray";
|
||||
ctx.lineWidth="1";
|
||||
// ctx.strokeStyle= "grey";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, maxY);
|
||||
ctx.lineTo(width, maxY);
|
||||
ctx.stroke();
|
||||
|
||||
if (_displayMinValue != 0) {
|
||||
var zeroY = pixelFromVal(0);
|
||||
var minY = pixelFromVal(_displayMinValue);
|
||||
// ctx.strokeStyle= "DarkRed";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, zeroY);
|
||||
ctx.lineTo(width, zeroY);
|
||||
ctx.moveTo(0, minY);
|
||||
ctx.lineTo(width, minY);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
var ctx = getContext("2d");
|
||||
|
@ -240,7 +275,9 @@ Item {
|
|||
displayValueLegend(ctx, _values[i], i)
|
||||
}
|
||||
|
||||
displayTitle(ctx, title, valueMax)
|
||||
displayMaxZeroMin(ctx);
|
||||
|
||||
displayTitle(ctx, title, _displayMaxValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,6 +287,7 @@ Item {
|
|||
|
||||
onClicked: {
|
||||
resetMax();
|
||||
resetMin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ Item {
|
|||
label: "LOD PID Ki"
|
||||
valueVar: LODManager["pidKi"]
|
||||
valueVarSetter: (function (v) { LODManager["pidKi"] = v })
|
||||
max: 0.000005
|
||||
max: 0.1
|
||||
min: 0.0
|
||||
integral: false
|
||||
numDigits: 8
|
||||
|
@ -165,6 +165,11 @@ Item {
|
|||
label: "present",
|
||||
color: "#FFFF00"
|
||||
},
|
||||
{
|
||||
prop: "batchTime",
|
||||
label: "batch",
|
||||
color: "#00FF00"
|
||||
},
|
||||
{
|
||||
prop: "engineRunTime",
|
||||
label: "engineRun",
|
||||
|
@ -192,7 +197,12 @@ Item {
|
|||
{
|
||||
prop: "fps",
|
||||
label: "FPS",
|
||||
color: "#FFFFFF"
|
||||
color: "#FFFF55"
|
||||
},
|
||||
{
|
||||
prop: "smoothFPS",
|
||||
label: "Smooth FPS",
|
||||
color: "#9999FF"
|
||||
},
|
||||
{
|
||||
prop: "lodDecreaseFPS",
|
||||
|
@ -221,6 +231,8 @@ Item {
|
|||
object: LODManager
|
||||
valueScale: 1.0
|
||||
valueUnit: "deg"
|
||||
valueNumDigits: 1
|
||||
displayMinAt0: false
|
||||
plots: [
|
||||
{
|
||||
prop: "pidOp",
|
||||
|
|
Loading…
Reference in a new issue