Created
July 4, 2013 10:54
-
-
Save ibilon/5926763 to your computer and use it in GitHub Desktop.
RAM used by the flashplayer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flash.events.Event; | |
import flash.display.Sprite; | |
import flash.system.System; | |
import flash.text.TextField; | |
import flash.text.TextFormat; | |
import flash.Lib; | |
class Main | |
{ | |
/** | |
* haxe -main Main -swf main.swf | |
*/ | |
public static function main () | |
{ | |
_sprite = new Sprite(); | |
_memReadText = new TextField(); | |
_fpsReadText = new TextField(); | |
_format = new TextFormat("default", 16, 0xFF00FF); | |
Lib.current.addEventListener(Event.ADDED_TO_STAGE, onStage); | |
} | |
public static function onStage (e:Event = null) | |
{ | |
Lib.current.removeEventListener(Event.ADDED_TO_STAGE, onStage); | |
Lib.current.addEventListener(Event.ENTER_FRAME, onEnterFrame); | |
Lib.current.stage.addChild(_sprite); | |
_sprite.addChild(_memReadText); | |
_memReadText.defaultTextFormat = _format; | |
_memReadText.width = 200; | |
_memReadText.height = 20; | |
_memReadText.x = 2; | |
_memReadText.y = 2; | |
_sprite.addChild(_fpsReadText); | |
_fpsReadText.defaultTextFormat = _format; | |
_fpsReadText.width = 200; | |
_fpsReadText.height = 20; | |
_fpsReadText.x = 2; | |
_fpsReadText.y = 30; | |
} | |
public static function onEnterFrame (e:Event = null) | |
{ | |
var t = Lib.getTimer(); | |
_frameListSum += (_frameList[_frameList.length] = Std.int(t - _frameLast)); | |
if (_frameList.length > 10) _frameListSum -= _frameList.shift(); | |
_frameLast = t; | |
_memReadText.text = "Mem: " + (System.totalMemory / 1024 / 1024) + "MB"; | |
_fpsReadText.text = "FPS: " + Std.int(1000 / (_frameListSum / _frameList.length)); | |
} | |
static var _fpsReadText : TextField; | |
static var _memReadText : TextField; | |
static var _sprite : Sprite; | |
static var _format : TextFormat; | |
static var _frameLast:Float; | |
static var _frameListSum:Int; | |
static var _frameList:Array<Int> = []; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment