2023-11-07 04:04:22 -05:00
|
|
|
package funkin.ui.debug;
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2024-02-21 17:10:18 -05:00
|
|
|
import funkin.util.MemoryUtil;
|
2022-01-27 22:20:38 -05:00
|
|
|
import openfl.text.TextFormat;
|
|
|
|
import openfl.system.System;
|
|
|
|
import openfl.text.TextField;
|
|
|
|
|
|
|
|
class MemoryCounter extends TextField
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
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
|
2023-06-08 16:30:45 -04:00
|
|
|
addEventListener(Event.ENTER_FRAME, function(e) {
|
2023-01-22 22:25:45 -05:00
|
|
|
var time = Lib.getTimer();
|
|
|
|
__enterFrame(time - currentTime);
|
|
|
|
});
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event Handlers
|
|
|
|
@:noCompletion
|
|
|
|
#if !flash override #end function __enterFrame(deltaTime:Float):Void
|
|
|
|
{
|
2024-07-11 19:35:41 -04:00
|
|
|
var mem:Float = Math.fround(MemoryUtil.getMemoryUsed() / BYTES_PER_MEG / ROUND_TO) * ROUND_TO;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
if (mem > memPeak) memPeak = mem;
|
|
|
|
|
|
|
|
text = 'RAM: ${mem}mb / ${memPeak}mb';
|
|
|
|
}
|
2022-01-27 22:20:38 -05:00
|
|
|
}
|