Skip to content

Commit

Permalink
Merge pull request #820 from ProjectJSE/fps_delay_fix
Browse files Browse the repository at this point in the history
Fix `FPSCounter` counting
  • Loading branch information
moxie-coder authored Dec 22, 2024
2 parents a9c95bc + e057881 commit d805b56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
6 changes: 3 additions & 3 deletions source/DiscordClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class DiscordClient

public static function initialize()
{
var discordHandlers:DiscordEventHandlers = DiscordEventHandlers.create();
final discordHandlers:DiscordEventHandlers = new DiscordEventHandlers();
discordHandlers.ready = Function.fromStaticFunction(onReady);
discordHandlers.disconnected = Function.fromStaticFunction(onDisconnected);
discordHandlers.errored = Function.fromStaticFunction(onError);
Discord.Initialize(clientID, cpp.RawPointer.addressOf(discordHandlers), 1, null);
Discord.Initialize(clientID, cpp.RawPointer.addressOf(discordHandlers), true, null);

if(!isInitialized) trace("Discord Client initialized");

Expand Down Expand Up @@ -171,7 +171,7 @@ final class DiscordPresence

function new()
{
__presence = DiscordRichPresence.create();
__presence = new DiscordRichPresence();
}

public function toString():String
Expand Down
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 = 500;
// 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}';
}
}
}
}

2 comments on commit d805b56

@system32unknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change timeoutDelay 500 to 50 because I set to 500 instead of 50 in wrong way

@moxie-coder
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change timeoutDelay 500 to 50 because I set to 500 instead of 50 in wrong way

okay

Please sign in to comment.