1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-28 15:57:42 +00:00
Funkin/source/funkin/ui/debug/MemoryCounter.hx
Eric 71947c581e
[PUBLIC PR] Fix a bug where the memory counter would overflow into the negatives (#662)
* get Float instead of Int in cpp (Float is 64-bit in so it works easier than Int64)

* use Math.fround instead of Math.round

---------

Co-authored-by: Karim Akra <144803230+KarimAkra@users.noreply.github.com>
2024-07-11 19:35:41 -04:00

46 lines
1 KiB
Haxe

package funkin.ui.debug;
import funkin.util.MemoryUtil;
import openfl.text.TextFormat;
import openfl.system.System;
import openfl.text.TextField;
class MemoryCounter extends TextField
{
var memPeak:Float = 0;
static final BYTES_PER_MEG:Float = 1024 * 1024;
static final ROUND_TO:Float = 1 / 100;
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
{
super();
this.x = x;
this.y = y;
this.width = 500;
this.selectable = false;
this.mouseEnabled = false;
defaultTextFormat = new TextFormat("_sans", 12, color);
text = "RAM: ";
#if flash
addEventListener(Event.ENTER_FRAME, function(e) {
var time = Lib.getTimer();
__enterFrame(time - currentTime);
});
#end
}
// Event Handlers
@:noCompletion
#if !flash override #end function __enterFrame(deltaTime:Float):Void
{
var mem:Float = Math.fround(MemoryUtil.getMemoryUsed() / BYTES_PER_MEG / ROUND_TO) * ROUND_TO;
if (mem > memPeak) memPeak = mem;
text = 'RAM: ${mem}mb / ${memPeak}mb';
}
}