Skip to content

Commit

Permalink
fix FPSCounter counting
Browse files Browse the repository at this point in the history
  • Loading branch information
system32unknown committed Dec 22, 2024
1 parent a9c95bc commit ac5c264
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions source/debug/FPSCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ class FPSCounter extends TextField
{
public var currentFPS(default, null):Float;

/*
inline function gay():Float
{
#if (cpp && windows)
return 0;
#elseif cpp
return cpp.vm.Gc.memInfo64(cpp.vm.Gc.MEM_INFO_USAGE);
#else
return cast(openfl.system.System.totalMemory, UInt);
#end
}
*/

/**
The current memory usage (WARNING: this is NOT your total program memory usage, rather it shows the garbage collector memory)
**/
Expand Down Expand Up @@ -56,17 +43,17 @@ class FPSCounter extends TextField

var fpsMultiplier:Float = 1.0;
var deltaTimeout:Float = 0.0;
public var timeoutDelay:Float = 1000;
// Event Handlers
override function __enterFrame(deltaTime:Float):Void
{
if (deltaTimeout > 1000) {
deltaTimeout = 0.0;
return;
}

final now:Float = haxe.Timer.stamp() * 1000;
times.push(now);
while (times[0] < now - 1000 / fpsMultiplier) times.shift();
if (deltaTimeout < timeoutDelay) {
deltaTimeout += deltaTime;
return;
}

if (Std.isOfType(FlxG.state, PlayState) && !PlayState.instance.trollingMode) {
try { fpsMultiplier = PlayState.instance.playbackRate; }
Expand All @@ -78,7 +65,6 @@ class FPSCounter extends TextField

currentFPS = Math.min(FlxG.drawFramerate, times.length) / fpsMultiplier;
updateText();
deltaTimeout += deltaTime;

if (ClientPrefs.rainbowFPS)
{
Expand All @@ -97,6 +83,7 @@ class FPSCounter extends TextField
if (currentFPS <= ClientPrefs.framerate / 4)
textColor = 0xFFFF0000;
}
deltaTimeout = 0.0;
}

public dynamic function updateText():Void { // so people can override it in hscript
Expand All @@ -113,4 +100,4 @@ class FPSCounter extends TextField
text += "\nSystem: " + '${System.platformLabel} ${System.platformVersion}';
}
}
}
}

0 comments on commit ac5c264

Please sign in to comment.