Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Commit 85c5185

Browse files
authored
Update FPSCounter.hx
1 parent 733baa8 commit 85c5185

File tree

1 file changed

+65
-76
lines changed

1 file changed

+65
-76
lines changed

source/debug/FPSCounter.hx

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import backend.CoolSystemThingy;
1212

1313
import Main;
1414

15-
#if cpp
16-
import external.memory.Memory;
17-
#end
15+
import flixel.util.FlxColor;
1816

1917
/**
2018
The FPS class provides an easy-to-use monitor to display
@@ -31,7 +29,11 @@ class FPSCounter extends TextField
3129
The current memory usage (WARNING: this is NOT your total program memory usage, rather it shows the garbage collector memory)
3230
**/
3331
public var memoryMegas(get, never):Float;
34-
public var memoryLeakMegas(get, never):Float; // memory leak
32+
inline function get_memoryMegas():Float
33+
{
34+
return cpp.vm.Gc.memInfo64(cpp.vm.Gc.MEM_INFO_USAGE);
35+
}
36+
public var memoryPeaks(default, null):Float = 0; // memory leak
3537

3638
@:noCompletion private var cacheCount:Int;
3739
@:noCompletion private var currentTime:Float;
@@ -60,9 +62,11 @@ class FPSCounter extends TextField
6062
var deltaTimeout:Float = 0.0;
6163

6264
// All the colors: Red, Orange, Yellow, Green, Blue, Violet/Purple
63-
final rainbowColors:Array<Int> = [0xFFFF0000, 0xFFFFA500, 0xFFFFFF00, 0xFF00FF00, 0xFF0000FF, 0xFFFF00FF];
64-
var colorInterp:Float = 0;
65-
var currentColor:Int = 0;
65+
//final rainbowColors:Array<Int> = [0xFFFF0000, 0xFFFFA500, 0xFFFFFF00, 0xFF00FF00, 0xFF0000FF, 0xFFFF00FF];
66+
//var colorInterp:Float = 0;
67+
//var currentColor:Int = 0;
68+
var timeColor:Float = 0.0;
69+
var fpsMultiplier:Float = 1.0;
6670

6771
// Event Handlers
6872
@:noCompletion
@@ -76,12 +80,29 @@ class FPSCounter extends TextField
7680
times.shift();
7781
}
7882

79-
var currentCount = times.length;
80-
currentFPS = Math.round((currentCount + cacheCount) / 2);
81-
if (currentFPS > ClientPrefs.data.framerate) currentFPS = ClientPrefs.data.framerate;
82-
if (currentCount != cacheCount) {
83-
updateText(); // Psych Dev remove the 'if(currentCount != cacheCount)' so i back this
83+
if (Std.isOfType(FlxG.state, PlayState)) {
84+
try fpsMultiplier = PlayState.instance.playbackRate;
85+
catch (e:Dynamic) fpsMultiplier = 1.0;
8486
}
87+
//var currentCount = times.length;
88+
currentFPS = Math.min(FlxG.drawFramerate, times.length) / fpsMultiplier;
89+
//if (currentFPS > ClientPrefs.data.framerate) currentFPS = ClientPrefs.data.framerate;
90+
if (memoryMegas > memoryPeaks) memoryPeaks = memoryMegas;
91+
if (ClientPrefs.data.showRainbowFPS) {
92+
timeColor = (timeColor % 360.0) + 1.0;
93+
textColor = FlxColor.fromHSB(timeColor, 1, 1);
94+
} else {
95+
textColor = 0xFFFFFFFF;
96+
if (currentFPS <= ClientPrefs.data.framerate / 2 && currentFPS >= ClientPrefs.data.framerate / 3) {
97+
textColor = 0xFFFFFF00;
98+
} else if (currentFPS <= ClientPrefs.data.framerate / 3 && currentFPS >= ClientPrefs.data.framerate / 4) {
99+
textColor = 0xFFFF8000;
100+
} else if (currentFPS <= ClientPrefs.data.framerate / 4) {
101+
textColor = 0xFFFF0000;
102+
}
103+
}
104+
105+
updateText();
85106

86107
deltaTimeout += deltaTime;
87108
colorInterp += deltaTime / 330; // Division so that it doesn't give you a seizure on 60 FPS
@@ -90,18 +111,20 @@ class FPSCounter extends TextField
90111
}
91112

92113
public dynamic function updateText():Void { // so people can override it in hscript, here: Main.fpsVar.updateText = function() { ... }
93-
if (ClientPrefs.data.showFPS)
94-
text = 'FPS: ${currentFPS}' + (ClientPrefs.data.ffmpegMode ? ' (Rendering Mode)' : '');
114+
//if (ClientPrefs.data.showFPS)
115+
text = 'FPS: ${currentFPS}' + (ClientPrefs.data.ffmpegMode ? ' (Rendering Mode)' : '');
95116

96-
if (ClientPrefs.data.showMemory) {
117+
if (ClientPrefs.data.showMemory)
118+
{
97119
text += '\nMemory: ${FlxStringUtil.formatBytes(memoryMegas)}'
98120
+ (ClientPrefs.data.showMemoryLeak ? ' / ${FlxStringUtil.formatBytes(memoryLeakMegas)}' : '');
99121
}
100122

101123
if (ClientPrefs.data.showEngineVersion)
102124
text += '\nMiu Engine ${MainMenuState.miuEngineVersion} (Modified PE ${MainMenuState.psychEngineVersion})'; // Inspired by SB Engine by Stefan2008 (https://github.com/Stefan2008Git)
103125

104-
if (ClientPrefs.data.showDebugInfo) {
126+
if (ClientPrefs.data.showDebugInfo)
127+
{
105128
text += '\nOS: ${System.platformLabel} ${System.platformVersion}';
106129
text += '\nState: ' + Type.getClassName(Type.getClass(FlxG.state));
107130
if (FlxG.state.subState != null)
@@ -111,67 +134,33 @@ class FPSCounter extends TextField
111134
text += '\nLime ' + CoolSystemThingy.getLimeVer;
112135
text += FlxG.VERSION;
113136
}
114-
115-
if (ClientPrefs.data.showRainbowFPS) {
116-
var colorIndex1:Int = Math.floor(colorInterp);
117-
var colorIndex2:Int = (colorIndex1 + 1) % rainbowColors.length;
118-
var startColor:Int = rainbowColors[colorIndex1];
119-
var endColor:Int = rainbowColors[colorIndex2];
120-
var segmentInterp:Float = colorInterp - colorIndex1;
121-
var interpolatedColor:Int = interpolateColor(startColor, endColor, segmentInterp);
122-
123-
textColor = interpolatedColor;
124-
125-
// Check if the current color segment interpolation is complete
126-
if (colorInterp >= rainbowColors.length) {
127-
// Reset colorInterp to start the interpolation cycle again
128-
textColor = rainbowColors[0];
129-
colorInterp = 0;
130-
}
131-
} else {
132-
textColor = 0xFFFFFFFF;
133-
if (currentFPS <= ClientPrefs.data.framerate / 2 && currentFPS >= ClientPrefs.data.framerate / 3) {
134-
textColor = 0xFFFFFF00;
135-
} else if (currentFPS <= ClientPrefs.data.framerate / 3 && currentFPS >= ClientPrefs.data.framerate / 4) {
136-
textColor = 0xFFFF8000;
137-
} else if (currentFPS <= ClientPrefs.data.framerate / 4) {
138-
textColor = 0xFFFF0000;
139-
}
140-
}
141137
}
142138

143-
private function interpolateColor(startColor:Int, endColor:Int, t:Float):Int {
144-
// Extract color components (RGBA) from startColor
145-
var startR:Int = (startColor >> 16) & 0xFF;
146-
var startG:Int = (startColor >> 8) & 0xFF;
147-
var startB:Int = startColor & 0xFF;
148-
var startA:Int = (startColor >> 24) & 0xFF;
149-
150-
// Extract color components (RGBA) from endColor
151-
var endR:Int = (endColor >> 16) & 0xFF;
152-
var endG:Int = (endColor >> 8) & 0xFF;
153-
var endB:Int = endColor & 0xFF;
154-
var endA:Int = (endColor >> 24) & 0xFF;
155-
156-
// Perform linear interpolation for each color component
157-
var interpolatedR:Int = Math.round(startR + t * (endR - startR));
158-
var interpolatedG:Int = Math.round(startG + t * (endG - startG));
159-
var interpolatedB:Int = Math.round(startB + t * (endB - startB));
160-
var interpolatedA:Int = Math.round(startA + t * (endA - startA));
161-
162-
// Combine interpolated color components into a single color value
163-
var interpolatedColor:Int = (interpolatedA << 24) | (interpolatedR << 16) | (interpolatedG << 8) | interpolatedB;
164-
165-
return interpolatedColor;
166-
}
167-
168-
inline function get_memoryMegas():Float
169-
return Memory.getCurrentUsage();
170-
171-
inline function get_memoryLeakMegas():Float
172-
return Memory.getPeakUsage();
173-
174-
139+
/*private function interpolateColor(startColor:Int, endColor:Int, t:Float):Int {
140+
// Extract color components (RGBA) from startColor
141+
var startR:Int = (startColor >> 16) & 0xFF;
142+
var startG:Int = (startColor >> 8) & 0xFF;
143+
var startB:Int = startColor & 0xFF;
144+
var startA:Int = (startColor >> 24) & 0xFF;
145+
146+
// Extract color components (RGBA) from endColor
147+
var endR:Int = (endColor >> 16) & 0xFF;
148+
var endG:Int = (endColor >> 8) & 0xFF;
149+
var endB:Int = endColor & 0xFF;
150+
var endA:Int = (endColor >> 24) & 0xFF;
151+
152+
// Perform linear interpolation for each color component
153+
var interpolatedR:Int = Math.round(startR + t * (endR - startR));
154+
var interpolatedG:Int = Math.round(startG + t * (endG - startG));
155+
var interpolatedB:Int = Math.round(startB + t * (endB - startB));
156+
var interpolatedA:Int = Math.round(startA + t * (endA - startA));
157+
158+
// Combine interpolated color components into a single color value
159+
var interpolatedColor:Int = (interpolatedA << 24) | (interpolatedR << 16) | (interpolatedG << 8) | interpolatedB;
160+
161+
return interpolatedColor;
162+
}*/
163+
175164
public function getText():String // Main.fpsVar.getText();
176165
return text;
177-
}
166+
}

0 commit comments

Comments
 (0)