Fix FramerateCounter and VRAM Counter (#820)

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Update FramerateCounter.hx

* Optimize memory label update in MemoryCounter

* Optimize frame update logic in AssetTreeInfo and MemoryCounter

* Fixed VRAM display showing -2147483648B

* Update SystemInfo.hx

* VRAM: 6MB?
This commit is contained in:
HEIHUAa
2025-11-20 06:46:04 +07:00
committed by GitHub
parent 53aa9cc2e7
commit a8808be29e
4 changed files with 68 additions and 8 deletions
@@ -8,12 +8,20 @@ import funkin.backend.assets.IModsAssetLibrary;
import funkin.backend.assets.ScriptedAssetLibrary;
class AssetTreeInfo extends FramerateCategory {
private var lastUpdateTime:Float = 1;
public function new() {
super("Asset Libraries Tree Info");
}
public override function __enterFrame(t:Int) {
if (alpha <= 0.05) return;
if ((lastUpdateTime += FlxG.rawElapsed) < 1)
return;
lastUpdateTime = 0;
var text = 'Not initialized yet\n';
if (Paths.assetsTree != null){
text = "";
@@ -9,6 +9,13 @@ class FramerateCounter extends Sprite {
public var fpsLabel:TextField;
public var lastFPS:Float = 0;
private var frameCount:Int = 0;
private var accumulatedTime:Float = openfl.Lib.getTimer();
private final updateInterval:Float = 1 / 15;
private var lastUpdateTime:Float = 0;
public function new() {
super();
@@ -27,15 +34,40 @@ class FramerateCounter extends Sprite {
}
}
public function reload() {}
public function reload() {
lastUpdateTime = 0;
}
public override function __enterFrame(t:Int) {
if (alpha <= 0.05) return;
super.__enterFrame(t);
lastFPS = CoolUtil.fpsLerp(lastFPS, FlxG.rawElapsed == 0 ? 0 : (1 / FlxG.rawElapsed), 0.25);
fpsNum.text = Std.string(Math.floor(lastFPS));
frameCount++;
if ((lastUpdateTime += FlxG.rawElapsed) < updateInterval)
{
updateLabelPosition();
return;
}
final timer = openfl.Lib.getTimer();
final time = timer - accumulatedTime;
accumulatedTime = timer;
lastFPS = FlxMath.lerp(lastFPS, time <= 0 ? 0 : (1000 / time * frameCount), 1.0 - Math.pow(0.75, time * 0.06));
fpsNum.text = Std.string(Math.round(lastFPS));
lastUpdateTime = frameCount = 0;
updateLabelPosition();
}
private inline function updateLabelPosition():Void
{
fpsLabel.x = fpsNum.x + fpsNum.width;
fpsLabel.y = (fpsNum.y + fpsNum.height) - fpsLabel.height;
}
}
}
@@ -36,11 +36,21 @@ class MemoryCounter extends Sprite {
if (alpha <= 0.05) return;
super.__enterFrame(t);
memory = MemoryUtil.currentMemUsage();
final mem = MemoryUtil.currentMemUsage();
if (mem == memory) {
updateLabelPosition();
return;
}
memory = mem;
if (memoryPeak < memory) memoryPeak = memory;
memoryText.text = CoolUtil.getSizeString(memory);
memoryPeakText.text = ' / ${CoolUtil.getSizeString(memoryPeak)}';
memoryPeakText.x = memoryText.x + memoryText.width;
updateLabelPosition();
}
private inline function updateLabelPosition():Void
memoryPeakText.x = memoryText.x + memoryText.width;
}
@@ -115,8 +115,7 @@ class SystemInfo extends FramerateCategory {
if (vRAMBytes == 1000 || vRAMBytes == 1 || vRAMBytes <= 0)
Logs.trace('Unable to grab GPU VRAM', ERROR, RED);
else {
var vRAMBytesFloat:#if cpp Float64 #else Float #end = vRAMBytes*1024;
vRAM = CoolUtil.getSizeString64(vRAMBytesFloat);
vRAM = getSizeString(vRAMBytes / 1024);
}
}
} else
@@ -155,6 +154,17 @@ class SystemInfo extends FramerateCategory {
if (totalMem != "Unknown" && memType != "Unknown") __formattedSysText += '\nTotal MEM: $totalMem $memType';
}
static function getSizeString(size:Float):String {
if (size < 1024)
return Std.int(size) + " MB";
else if (size < 1024 * 1024)
return Std.int(size / 1024) + " GB";
else {
var tb = size / (1024 * 1024);
return Std.int(tb) + "." + CoolUtil.addZeros(Std.string(Std.int((tb % 1) * 100)), 2) + " TB";
}
}
public function new() {
super("System Info");
}