@@ -20,6 +20,8 @@ Phaser.FrameDebugger = function (game) {
2020
2121 this . on = false ;
2222
23+ this . skipNext = false ;
24+
2325 // Single frame
2426 this . frame = [ ] ;
2527
@@ -37,6 +39,9 @@ Phaser.FrameDebugger = function (game) {
3739 this . CANVAS_MASK_PUSH = 4 ;
3840 this . CANVAS_MASK_POP = 5 ;
3941 this . CANVAS_RENDER_SPRITE = 6 ;
42+ this . CANVAS_RENDER_TEXT = 7 ;
43+ this . CANVAS_RENDER_BITMAPTEXT = 8 ;
44+ this . UPDATE_TEXT = 9 ;
4045
4146} ;
4247
@@ -72,14 +77,39 @@ Phaser.FrameDebugger.prototype = {
7277
7378 } ,
7479
80+ tu : function ( ) {
81+
82+ this . frame . push ( { type : this . UPDATE_TEXT , time : Date . now ( ) } ) ;
83+
84+ } ,
85+
7586 cb : function ( mode ) {
7687
7788 this . frame . push ( { type : this . CANVAS_BLENDMODE , mode : mode } ) ;
7889
7990 } ,
8091
92+ ct : function ( texture , width , height , res ) {
93+
94+ this . frame . push ( {
95+ type : this . CANVAS_RENDER_TEXT ,
96+ texture : texture ,
97+ width : width , height : height ,
98+ resolution : res
99+ } ) ;
100+
101+ this . skipNext = true ;
102+
103+ } ,
104+
81105 cs : function ( texture , width , height , res ) {
82106
107+ if ( this . skipNext )
108+ {
109+ this . skipNext = false ;
110+ return ;
111+ }
112+
83113 this . frame . push ( {
84114 type : this . CANVAS_RENDER_SPRITE ,
85115 texture : texture ,
@@ -110,7 +140,8 @@ Phaser.FrameDebugger.prototype = {
110140
111141 this . on = true ;
112142
113- this . max = max ;
143+ // this.max = max;
144+ this . max = 1 ;
114145
115146 } ,
116147
@@ -142,13 +173,11 @@ Phaser.FrameDebugger.prototype = {
142173 + ' font-size: 12px;'
143174 + '}'
144175 + 'h2 {'
145- + ' border-top: 1px dashed white;'
146176 + ' margin-top: 32px;'
147177 + '}'
148- + '.xstrip {'
178+ + '.strip {'
149179 + ' background: #4a4a4a;'
150- + ' display: flex;'
151- + ' flex-flow: row nowrap;'
180+ + ' padding: 16px 0px 16px 48px;'
152181 + '}'
153182 + '</style>'
154183 + '</head>'
@@ -164,37 +193,82 @@ Phaser.FrameDebugger.prototype = {
164193
165194 for ( var f = 0 ; f < this . log . length ; f ++ )
166195 {
196+ var pixels = 0 ;
167197 var frame = this . log [ f ] ;
198+ var textures = { } ;
168199
169200 this . addTag ( body , 'h2' , 'Frame ' + f ) ;
201+
202+ this . addTag ( body , 'p' , 'Frame Start @ ' + frame [ 0 ] . time ) ;
170203
171204 var box = this . addTag ( body , 'ol' , null , 'strip' ) ;
172205
173- for ( var i = 0 ; i < frame . length ; i ++ )
206+ // Count sprite batch changes
207+ // Add in TilingSprite, Graphics, etc
208+
209+ for ( var i = 1 ; i < frame . length - 1 ; i ++ )
174210 {
175211 var t = frame [ i ] ;
176212
177213 switch ( t . type )
178214 {
179- case this . START :
180- this . addTag ( box , 'li' , 'Frame Start @ ' + t . time ) ;
215+ case this . UPDATE_TEXT :
216+ this . addTag ( box , 'li' , 'Text.updateText @ ' + t . time ) ;
181217 break ;
182218
183219 case this . CANVAS_RENDER_SPRITE :
184220 this . addTag ( box , 'li' , 'Sprite (' + t . width + ' x ' + t . height + ')' ) ;
221+ pixels += this . addTexture ( t , textures ) ;
185222 break ;
186223
187- case this . STOP :
188- var duration = t . time - frame [ 0 ] . time ;
189- this . addTag ( box , 'li' , 'Frame Stop @ ' + t . time ) ;
190- this . addTag ( box , 'li' , 'Frame Duration ' + duration + 'ms' ) ;
224+ case this . CANVAS_RENDER_TEXT :
225+ this . addTag ( box , 'li' , 'Text (' + t . width + ' x ' + t . height + ')' ) ;
226+ pixels += this . addTexture ( t , textures ) ;
191227 break ;
192228 }
193229 }
230+
231+ var t = frame [ frame . length - 1 ] ;
232+ var duration = t . time - frame [ 0 ] . time ;
233+ this . addTag ( body , 'p' , 'Frame Stop @ ' + t . time ) ;
234+ this . addTag ( body , 'p' , 'Frame Duration: ' + duration + 'ms' ) ;
235+ this . addTag ( body , 'p' , 'Total pixels rendered: ' + pixels ) ;
236+ this . addTag ( body , 'p' , 'Unique Textures:' ) ;
237+
238+ var textureList = this . addTag ( body , 'ol' ) ;
239+
240+ for ( var single in textures )
241+ {
242+ this . addTag ( textureList , 'li' , single + ' - Times Used: ' + textures [ single ] ) ;
243+ }
244+
194245 }
195246
196247 } ,
197248
249+ addTexture : function ( t , textures ) {
250+
251+ var txt = t . texture . baseTexture . source . src ;
252+
253+ if ( txt === undefined )
254+ {
255+ // It's a canvas
256+ txt = t . texture . baseTexture . source . _pixiId ;
257+ }
258+
259+ if ( textures . hasOwnProperty ( txt ) )
260+ {
261+ textures [ txt ] ++ ;
262+ }
263+ else
264+ {
265+ textures [ txt ] = 1 ;
266+ }
267+
268+ return t . width * t . height ;
269+
270+ } ,
271+
198272 addImg : function ( parent , img ) {
199273
200274 parent . appendChild ( img . cloneNode ( true ) ) ;
0 commit comments