PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/flixel-2.35/org/flixel/data/FlxConsole.as

https://github.com/dcgw/ld18
ActionScript | 204 lines | 132 code | 14 blank | 58 comment | 12 complexity | 363b3faaaede10f436178d5134121ed7 MD5 | raw file
  1. package org.flixel.data
  2. {
  3. import flash.display.Bitmap;
  4. import flash.display.BitmapData;
  5. import flash.display.Sprite;
  6. import flash.text.AntiAliasType;
  7. import flash.text.GridFitType;
  8. import flash.text.TextField;
  9. import flash.text.TextFormat;
  10. import org.flixel.FlxG;
  11. import org.flixel.FlxMonitor;
  12. /**
  13. * Contains all the logic for the developer console.
  14. * This class is automatically created by FlxGame.
  15. */
  16. public class FlxConsole extends Sprite
  17. {
  18. public var mtrUpdate:FlxMonitor;
  19. public var mtrRender:FlxMonitor;
  20. public var mtrTotal:FlxMonitor;
  21. /**
  22. * @private
  23. */
  24. protected const MAX_CONSOLE_LINES:uint = 256;
  25. /**
  26. * @private
  27. */
  28. protected var _console:Sprite;
  29. /**
  30. * @private
  31. */
  32. protected var _text:TextField;
  33. /**
  34. * @private
  35. */
  36. protected var _fpsDisplay:TextField;
  37. /**
  38. * @private
  39. */
  40. protected var _extraDisplay:TextField;
  41. /**
  42. * @private
  43. */
  44. protected var _curFPS:uint;
  45. /**
  46. * @private
  47. */
  48. protected var _lines:Array;
  49. /**
  50. * @private
  51. */
  52. protected var _Y:Number;
  53. /**
  54. * @private
  55. */
  56. protected var _YT:Number;
  57. /**
  58. * @private
  59. */
  60. protected var _bx:int;
  61. /**
  62. * @private
  63. */
  64. protected var _by:int;
  65. /**
  66. * @private
  67. */
  68. protected var _byt:int;
  69. /**
  70. * Constructor
  71. *
  72. * @param X X position of the console
  73. * @param Y Y position of the console
  74. * @param Zoom The game's zoom level
  75. */
  76. public function FlxConsole(X:uint,Y:uint,Zoom:uint)
  77. {
  78. super();
  79. visible = false;
  80. x = X*Zoom;
  81. _by = Y*Zoom;
  82. _byt = _by - FlxG.height*Zoom;
  83. _YT = _Y = y = _byt;
  84. var tmp:Bitmap = new Bitmap(new BitmapData(FlxG.width*Zoom,FlxG.height*Zoom,true,0x7F000000));
  85. addChild(tmp);
  86. mtrUpdate = new FlxMonitor(8);
  87. mtrRender = new FlxMonitor(8);
  88. mtrTotal = new FlxMonitor(8);
  89. _text = new TextField();
  90. _text.width = tmp.width;
  91. _text.height = tmp.height;
  92. _text.multiline = true;
  93. _text.wordWrap = true;
  94. _text.embedFonts = true;
  95. _text.selectable = false;
  96. _text.antiAliasType = AntiAliasType.NORMAL;
  97. _text.gridFitType = GridFitType.PIXEL;
  98. _text.defaultTextFormat = new TextFormat("system",8,0xffffff);
  99. addChild(_text);
  100. _fpsDisplay = new TextField();
  101. _fpsDisplay.width = 100;
  102. _fpsDisplay.x = tmp.width-100;
  103. _fpsDisplay.height = 20;
  104. _fpsDisplay.multiline = true;
  105. _fpsDisplay.wordWrap = true;
  106. _fpsDisplay.embedFonts = true;
  107. _fpsDisplay.selectable = false;
  108. _fpsDisplay.antiAliasType = AntiAliasType.NORMAL;
  109. _fpsDisplay.gridFitType = GridFitType.PIXEL;
  110. _fpsDisplay.defaultTextFormat = new TextFormat("system",16,0xffffff,true,null,null,null,null,"right");
  111. addChild(_fpsDisplay);
  112. _extraDisplay = new TextField();
  113. _extraDisplay.width = 100;
  114. _extraDisplay.x = tmp.width-100;
  115. _extraDisplay.height = 64;
  116. _extraDisplay.y = 20;
  117. _extraDisplay.alpha = 0.5;
  118. _extraDisplay.multiline = true;
  119. _extraDisplay.wordWrap = true;
  120. _extraDisplay.embedFonts = true;
  121. _extraDisplay.selectable = false;
  122. _extraDisplay.antiAliasType = AntiAliasType.NORMAL;
  123. _extraDisplay.gridFitType = GridFitType.PIXEL;
  124. _extraDisplay.defaultTextFormat = new TextFormat("system",8,0xffffff,true,null,null,null,null,"right");
  125. addChild(_extraDisplay);
  126. _lines = new Array();
  127. }
  128. /**
  129. * Logs data to the developer console
  130. *
  131. * @param Text The text that you wanted to write to the console
  132. */
  133. public function log(Text:String):void
  134. {
  135. if(Text == null)
  136. Text = "NULL";
  137. trace(Text);
  138. _lines.push(Text);
  139. if(_lines.length > MAX_CONSOLE_LINES)
  140. {
  141. _lines.shift();
  142. var newText:String = "";
  143. for(var i:uint = 0; i < _lines.length; i++)
  144. newText += _lines[i]+"\n";
  145. _text.text = newText;
  146. }
  147. else
  148. _text.appendText(Text+"\n");
  149. _text.scrollV = _text.height;
  150. }
  151. /**
  152. * Shows/hides the console.
  153. */
  154. public function toggle():void
  155. {
  156. if(_YT == _by)
  157. _YT = _byt;
  158. else
  159. {
  160. _YT = _by;
  161. visible = true;
  162. }
  163. }
  164. /**
  165. * Updates and/or animates the dev console.
  166. */
  167. public function update():void
  168. {
  169. var total:Number = mtrTotal.average();
  170. _fpsDisplay.text = uint(1000/total) + " fps";
  171. var up:uint = mtrUpdate.average();
  172. var rn:uint = mtrRender.average();
  173. var fx:uint = up+rn;
  174. var tt:uint = uint(total);
  175. _extraDisplay.text = up + "ms update\n" + rn + "ms render\n" + fx + "ms flixel\n" + (tt-fx) + "ms flash\n" + tt + "ms total";
  176. if(_Y < _YT)
  177. _Y += FlxG.height*10*FlxG.elapsed;
  178. else if(_Y > _YT)
  179. _Y -= FlxG.height*10*FlxG.elapsed;
  180. if(_Y > _by)
  181. _Y = _by;
  182. else if(_Y < _byt)
  183. {
  184. _Y = _byt;
  185. visible = false;
  186. }
  187. y = Math.floor(_Y);
  188. }
  189. }
  190. }