Skip to content

Commit

Permalink
ram counter
Browse files Browse the repository at this point in the history
  • Loading branch information
x8c8r committed Sep 9, 2024
1 parent 53c0731 commit cb3652e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package;
import flixel.FlxG;
import flixel.FlxGame;
import flixel.FlxState;
import openfl.Assets;
import openfl.Lib;
import openfl.display.FPS;
import openfl.display.Sprite;
Expand Down Expand Up @@ -85,10 +84,12 @@ class Main extends Sprite

#if !mobile
addChild(new FPS(10, 3, 0xFFFFFF));
addChild(new RAM(10, 18));
#end

Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash);
}

function onCrash(e:UncaughtErrorEvent):Void
{
var errMsg:String = "";
Expand Down
37 changes: 37 additions & 0 deletions source/RAM.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import openfl.text.TextFormat;
import openfl.system.System;
import haxe.Timer;
import openfl.events.Event;
import openfl.text.TextField;

class RAM extends TextField {
public var curRAM:Float;
private var times:Array<Float>;

public function new(x:Float, y:Float) {
super();
this.x = x;
this.y = y;

defaultTextFormat = new TextFormat("_sans", 12, 0xFFFFFF);
selectable = false;
mouseEnabled = false;
autoSize = LEFT;

times = [];

addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(_) {
var now = Timer.stamp();
times.push(now);

while(times[0] < now - 1)
times.shift();

var mem:Float = Math.round(System.totalMemory / 1024 / 1024 * 100)/100;

if (visible)
text = "Memory: " + mem + "MB";
}
}

0 comments on commit cb3652e

Please sign in to comment.