Skip to content

Commit

Permalink
fix the game freezing
Browse files Browse the repository at this point in the history
this is more of an band-aid fix, also I formatted it since, GitHub is dumb :octocat:
  • Loading branch information
moxie-coder committed Dec 22, 2024
1 parent fce8420 commit 0fac1c1
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions source/debug/FPSCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class FPSCounter extends TextField
/**
The current memory usage (WARNING: this is NOT your total program memory usage, rather it shows the garbage collector memory)
**/
public var memory(get, never):Float;
public var memory(get, never):Float;
inline function get_memory():Float
return Memory.gay();

var mempeak:Float = 0;
var mempeak:Float = 0;

@:noCompletion private var times:Array<Float>;

Expand All @@ -39,32 +39,34 @@ class FPSCounter extends TextField
times = [];
}

var timeColor:Float = 0.0;
var timeColor:Float = 0.0;

var fpsMultiplier:Float = 1.0;
var deltaTimeout:Float = 0.0;
var deltaTimeout:Float = 0.0;
public var timeoutDelay:Float = 50;
// Event Handlers
override function __enterFrame(deltaTime:Float):Void
{
final now:Float = haxe.Timer.stamp() * 1000;
times.push(now);
while (times[0] < now - 1000 / fpsMultiplier) times.shift();
if (deltaTimeout < timeoutDelay) {
if (deltaTimeout <= timeoutDelay)
{
deltaTimeout += deltaTime;
return;
}

if (Std.isOfType(FlxG.state, PlayState) && !PlayState.instance.trollingMode) {
if (Std.isOfType(FlxG.state, PlayState) && !PlayState.instance.trollingMode)
{
try { fpsMultiplier = PlayState.instance.playbackRate; }
catch (e:Dynamic) { fpsMultiplier = 1.0; }
}
else fpsMultiplier = 1.0;

if (memory > mempeak) mempeak = memory;
currentFPS = Math.min(FlxG.drawFramerate, times.length) / fpsMultiplier;
updateText();
if (memory > mempeak) mempeak = memory;

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

if (ClientPrefs.rainbowFPS)
{
Expand All @@ -79,21 +81,24 @@ class FPSCounter extends TextField

if (currentFPS <= ClientPrefs.framerate / 3 && currentFPS >= ClientPrefs.framerate / 4)
textColor = 0xFFFF8000;

if (currentFPS <= ClientPrefs.framerate / 4)
textColor = 0xFFFF0000;
}
deltaTimeout = 0.0;
}

public dynamic function updateText():Void { // so people can override it in hscript
public dynamic function updateText():Void // so people can override it in hscript
{
text = (ClientPrefs.showFPS ? "FPS: " + (ClientPrefs.ffmpegMode ? ClientPrefs.targetFPS : Math.round(currentFPS)) : "");
if (ClientPrefs.ffmpegMode) {
if (ClientPrefs.ffmpegMode)
{
text += " (Rendering Mode)";
}

if (ClientPrefs.showRamUsage) text += "\nRAM: " + FlxStringUtil.formatBytes(memory) + (ClientPrefs.showMaxRamUsage ? " / " + FlxStringUtil.formatBytes(mempeak) : "");
if (ClientPrefs.debugInfo) {
if (ClientPrefs.debugInfo)
{
text += '\nState: ${Type.getClassName(Type.getClass(FlxG.state))}';
if (FlxG.state.subState != null)
text += '\nSubstate: ${Type.getClassName(Type.getClass(FlxG.state.subState))}';
Expand Down

3 comments on commit 0fac1c1

@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.

btw I did manage to confirm that inputs are being dropped as a matter of fact, ever since the new input system was implemented, so now that has to been fixed aswell

@StinkTheStinker
Copy link

Choose a reason for hiding this comment

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

is this talking about the freeze when you come back on the tab after a bit

@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.

is this talking about the freeze when you come back on the tab after a bit

no

Please sign in to comment.