Adjusted the graphs.
This commit is contained in:
@@ -14,25 +14,30 @@ import openfl.text.TextFormat;
|
||||
*/
|
||||
class FunkinDebugDisplay extends Sprite
|
||||
{
|
||||
static final FPS_UPDATE_DELAY:Int = 200;
|
||||
static final UPDATE_DELAY:Int = 100;
|
||||
static final INNER_RECT_DIFF:Int = 3;
|
||||
static final OUTER_RECT_DIMENSIONS:Array<Int> = [215, 150];
|
||||
static final OUTER_RECT_DIMENSIONS:Array<Int> = [225, 200];
|
||||
static final OTHERS_OFFSET:Int = 8;
|
||||
|
||||
var currentFPS:Int;
|
||||
var deltaTimeout:Float;
|
||||
|
||||
var times:Array<Float>;
|
||||
|
||||
#if !html5
|
||||
var gcMem:Float;
|
||||
var gcMemPeak:Float;
|
||||
|
||||
var taskMem:Float;
|
||||
var taskMemPeak:Float;
|
||||
#end
|
||||
|
||||
var background:Shape;
|
||||
|
||||
var textDisplay:TextField;
|
||||
|
||||
var fpsGraph:FunkinStatsGraph;
|
||||
var gcMemGraph:FunkinStatsGraph;
|
||||
var taskMemGraph:FunkinStatsGraph;
|
||||
|
||||
var infoDisplay:TextField;
|
||||
|
||||
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
|
||||
{
|
||||
@@ -40,8 +45,11 @@ class FunkinDebugDisplay extends Sprite
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.currentFPS = 0;
|
||||
this.deltaTimeout = 0.0;
|
||||
this.gcMem = 0.0;
|
||||
this.gcMemPeak = 0.0;
|
||||
this.taskMem = 0.0;
|
||||
this.taskMemPeak = 0.0;
|
||||
this.times = [];
|
||||
|
||||
@@ -54,23 +62,51 @@ class FunkinDebugDisplay extends Sprite
|
||||
background.graphics.endFill();
|
||||
addChild(background);
|
||||
|
||||
textDisplay = new TextField();
|
||||
textDisplay.x += OTHERS_OFFSET;
|
||||
textDisplay.y += OTHERS_OFFSET;
|
||||
textDisplay.width = 500;
|
||||
textDisplay.selectable = false;
|
||||
textDisplay.mouseEnabled = false;
|
||||
textDisplay.defaultTextFormat = new TextFormat('Monsterrat', 12, color, JUSTIFY);
|
||||
textDisplay.antiAliasType = NORMAL;
|
||||
textDisplay.sharpness = 100;
|
||||
textDisplay.multiline = true;
|
||||
addChild(textDisplay);
|
||||
|
||||
fpsGraph = new FunkinStatsGraph(OTHERS_OFFSET, 110 + OTHERS_OFFSET, 100, 25, color, 'FPS Graph:');
|
||||
fpsGraph.maxValue = FlxG.drawFramerate;
|
||||
fpsGraph = new FunkinStatsGraph(OTHERS_OFFSET, OTHERS_OFFSET + 22, 100, 25, color);
|
||||
fpsGraph.minValue = 0;
|
||||
addChild(fpsGraph);
|
||||
|
||||
#if !html5
|
||||
gcMemGraph = new FunkinStatsGraph(OTHERS_OFFSET, Math.floor(OTHERS_OFFSET + (fpsGraph.y + fpsGraph.axisHeight) + 22), 100, 25, color);
|
||||
gcMemGraph.minValue = 0;
|
||||
addChild(gcMemGraph);
|
||||
|
||||
if (MemoryUtil.supportsTaskMem())
|
||||
{
|
||||
taskMemGraph = new FunkinStatsGraph(OTHERS_OFFSET, Math.floor(OTHERS_OFFSET + (gcMemGraph.y + gcMemGraph.axisHeight) + 22), 100, 25, color);
|
||||
taskMemGraph.minValue = 0;
|
||||
addChild(taskMemGraph);
|
||||
}
|
||||
#end
|
||||
|
||||
infoDisplay = new TextField();
|
||||
|
||||
infoDisplay.x = OTHERS_OFFSET;
|
||||
|
||||
if (taskMemGraph != null)
|
||||
{
|
||||
infoDisplay.y = taskMemGraph.y + taskMemGraph.axisHeight;
|
||||
}
|
||||
else if (gcMemGraph != null)
|
||||
{
|
||||
infoDisplay.y = gcMemGraph.y + gcMemGraph.axisHeight;
|
||||
}
|
||||
else
|
||||
infoDisplay.y = fpsGraph.y + fpsGraph.axisHeight;
|
||||
|
||||
infoDisplay.width = 500;
|
||||
infoDisplay.selectable = false;
|
||||
infoDisplay.mouseEnabled = false;
|
||||
infoDisplay.defaultTextFormat = new TextFormat('Monsterrat', 12, color, JUSTIFY);
|
||||
infoDisplay.antiAliasType = NORMAL;
|
||||
infoDisplay.sharpness = 100;
|
||||
infoDisplay.multiline = true;
|
||||
|
||||
addChild(infoDisplay);
|
||||
|
||||
updateFPSGraph();
|
||||
updateGcMemGraph();
|
||||
updateTaskMemGraph();
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
@@ -85,52 +121,73 @@ class FunkinDebugDisplay extends Sprite
|
||||
times.shift();
|
||||
}
|
||||
|
||||
if (deltaTimeout < FPS_UPDATE_DELAY)
|
||||
if (deltaTimeout < UPDATE_DELAY)
|
||||
{
|
||||
deltaTimeout += deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
fpsGraph.update(times.length);
|
||||
currentFPS = times.length;
|
||||
|
||||
updateDisplay(times.length, Math.floor(fpsGraph.average()), Math.floor(fpsGraph.lowest()));
|
||||
updateFPSGraph();
|
||||
updateGcMemGraph();
|
||||
updateTaskMemGraph();
|
||||
updateDisplay();
|
||||
|
||||
deltaTimeout = 0.0;
|
||||
}
|
||||
|
||||
function updateDisplay(?currentFPS:Int = 0, ?averageFPS:Int = 0, ?lowestFPS:Int = 0):Void
|
||||
function updateDisplay():Void
|
||||
{
|
||||
final info:Array<String> = [];
|
||||
|
||||
info.push('FPS: $currentFPS');
|
||||
|
||||
info.push('AVG FPS: $averageFPS');
|
||||
|
||||
info.push('1% LOW FPS: $lowestFPS');
|
||||
fpsGraph.textDisplay.text = 'FPS: $currentFPS';
|
||||
|
||||
#if !html5
|
||||
final gcMem:Float = MemoryUtil.getGCMemory();
|
||||
gcMemGraph.textDisplay.text = 'GC MEM: ${FlxStringUtil.formatBytes(gcMem).toLowerCase()} / ${FlxStringUtil.formatBytes(gcMemPeak).toLowerCase()}';
|
||||
|
||||
if (gcMem > gcMemPeak)
|
||||
if (taskMemGraph != null)
|
||||
{
|
||||
gcMemPeak = gcMem;
|
||||
}
|
||||
|
||||
info.push('GC MEM: ${FlxStringUtil.formatBytes(gcMem).toLowerCase()} / ${FlxStringUtil.formatBytes(gcMemPeak).toLowerCase()}');
|
||||
|
||||
if (MemoryUtil.supportsTaskMem())
|
||||
{
|
||||
final taskMem:Float = MemoryUtil.getTaskMemory();
|
||||
|
||||
if (taskMem > taskMemPeak)
|
||||
{
|
||||
taskMemPeak = taskMem;
|
||||
}
|
||||
|
||||
info.push('TASK MEM: ${FlxStringUtil.formatBytes(taskMem).toLowerCase()} / ${FlxStringUtil.formatBytes(taskMemPeak).toLowerCase()}');
|
||||
taskMemGraph.textDisplay.text = 'TASK MEM: ${FlxStringUtil.formatBytes(taskMem).toLowerCase()} / ${FlxStringUtil.formatBytes(taskMemPeak).toLowerCase()}';
|
||||
}
|
||||
#end
|
||||
|
||||
textDisplay.text = info.join('\n');
|
||||
final info:Array<String> = [];
|
||||
info.push('AVG FPS: ${Math.floor(fpsGraph.average())}');
|
||||
info.push('1% LOW FPS: ${Math.floor(fpsGraph.lowest())}');
|
||||
infoDisplay.text = info.join('\n');
|
||||
}
|
||||
|
||||
function updateFPSGraph(?currentFPS:Int = 0):Void
|
||||
{
|
||||
fpsGraph.maxValue = FlxG.drawFramerate;
|
||||
fpsGraph.update(times.length);
|
||||
}
|
||||
|
||||
#if !html5
|
||||
function updateGcMemGraph(?currentFPS:Int = 0):Void
|
||||
{
|
||||
gcMem = MemoryUtil.getGCMemory();
|
||||
|
||||
if (gcMem > gcMemPeak)
|
||||
{
|
||||
gcMemGraph.maxValue = gcMemPeak = gcMem;
|
||||
}
|
||||
|
||||
gcMemGraph.update(gcMem);
|
||||
}
|
||||
|
||||
function updateTaskMemGraph(?currentFPS:Int = 0):Void
|
||||
{
|
||||
if (taskMemGraph != null)
|
||||
{
|
||||
taskMem = MemoryUtil.getTaskMemory();
|
||||
|
||||
if (taskMem > taskMemPeak)
|
||||
{
|
||||
taskMemGraph.maxValue = taskMemPeak = taskMem;
|
||||
}
|
||||
|
||||
taskMemGraph.update(taskMem);
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package funkin.ui.debug.stats;
|
||||
|
||||
import openfl.display.Graphics;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.util.FlxColor;
|
||||
import openfl.display.Shape;
|
||||
import openfl.display.Sprite;
|
||||
import openfl.text.TextField;
|
||||
import openfl.text.TextFormat;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
|
||||
/**
|
||||
* This is a modified StatsGraph class for Funkin.
|
||||
*/
|
||||
class FunkinStatsGraph extends Sprite
|
||||
{
|
||||
static inline var AXIS_COLOR:FlxColor = 0xffffff;
|
||||
@@ -19,122 +14,145 @@ class FunkinStatsGraph extends Sprite
|
||||
static inline var HISTORY_MAX:Int = 100;
|
||||
|
||||
public var minValue:Float = FlxMath.MAX_VALUE_FLOAT;
|
||||
|
||||
public var maxValue:Float = FlxMath.MIN_VALUE_FLOAT;
|
||||
|
||||
public var graphColor:FlxColor;
|
||||
|
||||
public var history:Array<Float> = [];
|
||||
|
||||
var textDisplay:TextField;
|
||||
public var textDisplay:TextField;
|
||||
|
||||
var _axis:Shape;
|
||||
var _width:Int;
|
||||
var _height:Int;
|
||||
public var axis:Shape;
|
||||
|
||||
public function new(X:Int, Y:Int, Width:Int, Height:Int, GraphColor:FlxColor, name:String)
|
||||
public var axisWidth:Int;
|
||||
|
||||
public var axisHeight:Int;
|
||||
|
||||
public function new(x:Int, y:Int, width:Int, height:Int, graphColor:FlxColor):Void
|
||||
{
|
||||
super();
|
||||
x = X;
|
||||
y = Y;
|
||||
_width = Width;
|
||||
_height = Height;
|
||||
graphColor = GraphColor;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.graphColor = graphColor;
|
||||
this.axisWidth = width;
|
||||
this.axisHeight = height;
|
||||
|
||||
textDisplay = new TextField();
|
||||
textDisplay.y -= 22;
|
||||
textDisplay.width = 500;
|
||||
textDisplay.y -= 22;
|
||||
textDisplay.selectable = false;
|
||||
textDisplay.mouseEnabled = false;
|
||||
textDisplay.defaultTextFormat = new TextFormat('Monsterrat', 12, graphColor, JUSTIFY);
|
||||
textDisplay.antiAliasType = NORMAL;
|
||||
textDisplay.sharpness = 100;
|
||||
textDisplay.multiline = true;
|
||||
textDisplay.text = name;
|
||||
addChild(textDisplay);
|
||||
|
||||
_axis = new Shape();
|
||||
_axis.x += 4;
|
||||
|
||||
addChild(_axis);
|
||||
axis = new Shape();
|
||||
axis.x += 4;
|
||||
addChild(axis);
|
||||
|
||||
drawAxes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the axes of the graph.
|
||||
*/
|
||||
function drawAxes():Void
|
||||
{
|
||||
var gfx = _axis.graphics;
|
||||
gfx.clear();
|
||||
gfx.lineStyle(1, AXIS_COLOR, AXIS_ALPHA);
|
||||
axis.graphics.clear();
|
||||
axis.graphics.lineStyle(1, AXIS_COLOR, AXIS_ALPHA, false, null, null, MITER, 255);
|
||||
|
||||
// y-Axis
|
||||
gfx.moveTo(0, 0);
|
||||
gfx.lineTo(0, _height);
|
||||
axis.graphics.moveTo(0, 0);
|
||||
axis.graphics.lineTo(0, axisHeight);
|
||||
|
||||
// x-Axis
|
||||
gfx.moveTo(0, _height);
|
||||
gfx.lineTo(_width, _height);
|
||||
axis.graphics.moveTo(0, axisHeight);
|
||||
axis.graphics.lineTo(axisWidth, axisHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the graph based on the values stored in the history.
|
||||
*/
|
||||
function drawGraph():Void
|
||||
{
|
||||
var gfx:Graphics = graphics;
|
||||
gfx.clear();
|
||||
gfx.lineStyle(1, graphColor, 1);
|
||||
graphics.clear();
|
||||
graphics.lineStyle(1, graphColor, 1, false, null, null, MITER, 255);
|
||||
|
||||
var inc:Float = _width / (HISTORY_MAX - 1);
|
||||
if (history.length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var inc:Float = axisWidth / (HISTORY_MAX - 1);
|
||||
var range:Float = Math.max(maxValue - minValue, maxValue * 0.1);
|
||||
var graphX = _axis.x + 1;
|
||||
var scale:Float = axisHeight / range;
|
||||
|
||||
for (i in 0...history.length)
|
||||
{
|
||||
var value = (history[i] - minValue) / range;
|
||||
final pointY:Float = axisHeight - ((history[i] - minValue) * scale) - 1;
|
||||
|
||||
var pointY = (-value * _height - 1) + _height;
|
||||
if (i == 0) gfx.moveTo(graphX, _axis.y + pointY);
|
||||
gfx.lineTo(graphX + (i * inc), pointY);
|
||||
if (i == 0) graphics.moveTo(axis.x + 1, pointY);
|
||||
|
||||
graphics.lineTo(axis.x + 1 + (i * inc), pointY);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Value:Float):Void
|
||||
public function update(value:Float):Void
|
||||
{
|
||||
history.unshift(Value);
|
||||
if (history.length > HISTORY_MAX) history.pop();
|
||||
history.push(value);
|
||||
|
||||
// Update range
|
||||
maxValue = Math.max(maxValue, Value);
|
||||
minValue = Math.min(minValue, Value);
|
||||
if (history.length > HISTORY_MAX)
|
||||
{
|
||||
history.shift();
|
||||
}
|
||||
|
||||
maxValue = Math.max(maxValue, value);
|
||||
minValue = Math.min(minValue, value);
|
||||
|
||||
drawGraph();
|
||||
}
|
||||
|
||||
public function average():Float
|
||||
{
|
||||
if (history.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var sum:Float = 0;
|
||||
for (value in history)
|
||||
sum += value;
|
||||
|
||||
for (v in history)
|
||||
{
|
||||
sum += v;
|
||||
}
|
||||
|
||||
return sum / history.length;
|
||||
}
|
||||
|
||||
public function lowest():Float
|
||||
{
|
||||
var val:Float = history[0] ?? 0;
|
||||
for (value in history)
|
||||
if (history.length == 0)
|
||||
{
|
||||
if (value < val) val = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
var val:Float = history[0];
|
||||
|
||||
for (v in history)
|
||||
{
|
||||
if (v < val)
|
||||
{
|
||||
val = v;
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public function destroy():Void
|
||||
{
|
||||
_axis = FlxDestroyUtil.removeChild(this, _axis);
|
||||
textDisplay = FlxDestroyUtil.removeChild(this, textDisplay);
|
||||
if (axis != null)
|
||||
{
|
||||
removeChild(axis);
|
||||
axis = null;
|
||||
}
|
||||
|
||||
history = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user