Phaser.FrameDebugger = function (game){ this.game = game; this.on = false ; this.skipNext = false ; this.frame = [] ; this.log = [] ; this.count = 0; this.max = 1; this.START = 0; this.STOP = 1; this.CANVAS_CLEAR = 2; this.CANVAS_BLENDMODE = 3; this.CANVAS_MASK_PUSH = 4; this.CANVAS_MASK_POP = 5; this.CANVAS_RENDER_SPRITE = 6; this.CANVAS_RENDER_TEXT = 7; this.CANVAS_RENDER_BITMAPTEXT = 8; this.UPDATE_TEXT = 9; this.CANVAS_DOC_START = 10; this.CANVAS_DOC_STOP = 11; this.CANVAS_SPRITE_BATCH_START = 12; this.CANVAS_SPRITE_BATCH_RENDER_FAST = 13; this.CANVAS_SPRITE_BATCH_RENDER_SLOW = 14; this.CANVAS_SPRITE_BATCH_STOP = 15; this.CANVAS_RENDER_TILING_SPRITE = 16; this.GENERATE_TILING_TEXTURE = 17; this.GRAPHICS_GENERATE_CACHED_SPRITE_SLOW = 18; this.GRAPHICS_GENERATE_CACHED_SPRITE_FAST = 19; this.CANVAS_RENDER_GRAPHICS = 20; this.CANVAS_RENDER_GRAPHICS_CACHED = 21; this.CANVAS_GRAPHICS_START = 22; this.CANVAS_GRAPHICS_STOP = 23; this.CANVAS_GRAPHICS_POLY = 24; this.CANVAS_GRAPHICS_RECT = 25; this.CANVAS_GRAPHICS_CIRCLE = 26; this.CANVAS_GRAPHICS_ELIPSE = 27; this.CANVAS_GRAPHICS_ROUNDED_RECT = 28; } ; Phaser.FrameDebugger.prototype = { start: function (){ this.frame = [{ type: this.START, time: Date.now()} ] ; } , stop: function (){ this.frame.push({ type: this.STOP, time: Date.now()} ); this.log.push(this.frame); this.count++ ; if (this.count === this.max) { this.finish(); } } , cr: function (){ this.frame.push({ type: this.CANVAS_CLEAR} ); } , tu: function (){ this.frame.push({ type: this.UPDATE_TEXT, time: Date.now()} ); } , cts: function (texture, width, height){ this.frame.push({ type: this.CANVAS_RENDER_TILING_SPRITE, texture: texture, width: width, height: height} ); } , gtt: function (texture, width, height){ this.frame.push({ type: this.GENERATE_TILING_TEXTURE, texture: texture, width: width, height: height, time: Date.now()} ); } , cgc: function (){ this.frame.push({ type: this.CANVAS_RENDER_GRAPHICS_CACHED} ); } , cg: function (){ this.frame.push({ type: this.CANVAS_RENDER_GRAPHICS} ); } , rgs: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_START, time: Date.now()} ); } , rgp: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_STOP, time: Date.now()} ); } , cgpoly: function (points){ this.frame.push({ type: this.CANVAS_GRAPHICS_POLY, time: Date.now(), points: points} ); } , cgrect: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_RECT, time: Date.now()} ); } , cgcirc: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_CIRCLE, time: Date.now()} ); } , cgrrect: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_ROUNDED_RECT, time: Date.now()} ); } , cgelip: function (){ this.frame.push({ type: this.CANVAS_GRAPHICS_ELIPSE, time: Date.now()} ); } , cgcs1: function (texture, width, height){ this.frame.push({ type: this.GRAPHICS_GENERATE_CACHED_SPRITE_SLOW, texture: texture, width: width, height: height, time: Date.now()} ); } , cgcs2: function (texture, width, height){ this.frame.push({ type: this.GRAPHICS_GENERATE_CACHED_SPRITE_FAST, texture: texture, width: width, height: height, time: Date.now()} ); } , cb: function (mode){ this.frame.push({ type: this.CANVAS_BLENDMODE, mode: mode} ); } , cdcs: function (){ this.frame.push({ type: this.CANVAS_DOC_START, time: Date.now()} ); } , cdcp: function (){ this.frame.push({ type: this.CANVAS_DOC_STOP, time: Date.now()} ); } , csbs: function (){ this.frame.push({ type: this.CANVAS_SPRITE_BATCH_START, time: Date.now()} ); } , csb1: function (texture, width, height, res){ this.frame.push({ type: this.CANVAS_SPRITE_BATCH_RENDER_FAST, texture: texture, width: width, height: height, resolution: res} ); } , csb2: function (texture, width, height, res){ this.frame.push({ type: this.CANVAS_SPRITE_BATCH_RENDER_SLOW, texture: texture, width: width, height: height, resolution: res} ); } , csbp: function (){ this.frame.push({ type: this.CANVAS_SPRITE_BATCH_STOP, time: Date.now()} ); } , ct: function (texture, width, height, res){ this.frame.push({ type: this.CANVAS_RENDER_TEXT, texture: texture, width: width, height: height, resolution: res} ); this.skipNext = true ; } , cs: function (texture, width, height, res){ if (this.skipNext) { this.skipNext = false ; return ; } this.frame.push({ type: this.CANVAS_RENDER_SPRITE, texture: texture, width: width, height: height, resolution: res} ); } , cm: function (mask){ this.frame.push({ type: this.CANVAS_MASK_PUSH, mask: mask} ); } , cmo: function (){ this.frame.push({ type: this.CANVAS_MASK_POP} ); } , record: function (max){ if (max === undefined) { max = 1; } if (this.on) { return ; } this.reset(); this.on = true ; this.max = 1; } , reset: function (){ this.frame = [] ; this.log = [] ; this.count = 0; this.max = 1; } , finish: function (){ console.log(this.log); this.on = false ; this.win = _AN_Call_open('open', window, 'about:blank', 'FrameDebugger'); var content = '' + 'Display List Debugger Output' + '' + '' + '' + '

Display List Debugger

' + ''; _AN_Call_open('open', this.win.document, 'text/html', 'replace'); _AN_Call_write('write', this.win.document, content); this.win.document.close(); var body = this.win.document.body; for (var f = 0; f < _AN_Read_length('length', this.log); f++ ){ var pixels = 0; var frame = this.log[f]; var textures = { } ; var total = 0; var primitives = 0; this.addTag(body, 'h2', 'Frame ' + f); this.addTag(body, 'p', 'Frame Start @ ' + frame[0].time); var root = this.addTag(body, 'ol', null , 'strip'); var current = root; var stack = [root] ; for (var i = 1; i < _AN_Read_length('length', frame) - 1; i++ ){ var t = frame[i]; switch (t.type){ case this.UPDATE_TEXT: this.addTag(current, 'li', 'Text.updateText @ ' + t.time); break ; case this.GENERATE_TILING_TEXTURE: this.addTag(current, 'li', 'Generate Tiling Texture @ ' + t.time); break ; case this.CANVAS_BLENDMODE: this.addTag(current, 'li', 'Set Blend Mode: ' + t.mode); break ; case this.GRAPHICS_GENERATE_CACHED_SPRITE_FAST: this.addTag(current, 'li', 'Graphics.Generate Cached Sprite (Fast) @ ' + t.time + '(' + t.width + ' x ' + t.height + ')'); break ; case this.GRAPHICS_GENERATE_CACHED_SPRITE_SLOW: this.addTag(current, 'li', 'Graphics.Generate Cached Sprite (Slow) @ ' + t.time + '(' + t.width + ' x ' + t.height + ')'); break ; case this.CANVAS_DOC_START: this.addTag(current, 'li', 'DisplayObjectContainer Start @ ' + t.time); var current = this.addTag(current, 'ol'); stack.push(current); break ; case this.CANVAS_DOC_STOP: stack.pop(); current = stack[_AN_Read_length('length', stack) - 1]; this.addTag(current, 'li', 'DisplayObjectContainer Stop @ ' + t.time); break ; case this.CANVAS_SPRITE_BATCH_START: this.addTag(current, 'li', 'SpriteBatch Start @ ' + t.time); var current = this.addTag(current, 'ol'); stack.push(current); break ; case this.CANVAS_SPRITE_BATCH_RENDER_FAST: this.addTag(current, 'li', 'Child (FastPath) (' + t.width + ' x ' + t.height + ')'); pixels += this.addTexture(t, textures); total++ ; break ; case this.CANVAS_SPRITE_BATCH_RENDER_SLOW: this.addTag(current, 'li', 'Child (SlowPath) (' + t.width + ' x ' + t.height + ')'); pixels += this.addTexture(t, textures); total++ ; break ; case this.CANVAS_SPRITE_BATCH_STOP: stack.pop(); current = stack[_AN_Read_length('length', stack) - 1]; this.addTag(current, 'li', 'SpriteBatch Stop @ ' + t.time); break ; case this.CANVAS_RENDER_SPRITE: this.addTag(current, 'li', 'Sprite (' + t.width + ' x ' + t.height + ')'); pixels += this.addTexture(t, textures); total++ ; break ; case this.CANVAS_RENDER_TEXT: this.addTag(current, 'li', 'Text (' + t.width + ' x ' + t.height + ')'); pixels += this.addTexture(t, textures); total++ ; break ; case this.CANVAS_RENDER_TILING_SPRITE: this.addTag(current, 'li', 'Tiling Sprite (' + t.width + ' x ' + t.height + ')'); pixels += this.addTexture(t, textures); total++ ; break ; case this.CANVAS_RENDER_GRAPHICS: this.addTag(current, 'li', 'Graphics (Dynamic)'); break ; case this.CANVAS_RENDER_GRAPHICS_CACHED: this.addTag(current, 'li', 'Graphics (Cached)'); break ; case this.CANVAS_GRAPHICS_START: this.addTag(current, 'li', 'Render Graphics Start @ ' + t.time); var current = this.addTag(current, 'ol'); stack.push(current); break ; case this.CANVAS_GRAPHICS_POLY: this.addTag(current, 'li', 'Polygon (' + t.points + ' points)'); primitives++ ; break ; case this.CANVAS_GRAPHICS_RECT: this.addTag(current, 'li', 'Rectangle'); primitives++ ; break ; case this.CANVAS_GRAPHICS_CIRCLE: this.addTag(current, 'li', 'Circle'); primitives++ ; break ; case this.CANVAS_GRAPHICS_ROUNDED_RECT: this.addTag(current, 'li', 'Rounded Rectangle'); primitives++ ; break ; case this.CANVAS_GRAPHICS_ELIPSE: this.addTag(current, 'li', 'Elipse'); primitives++ ; break ; case this.CANVAS_GRAPHICS_STOP: stack.pop(); current = stack[_AN_Read_length('length', stack) - 1]; this.addTag(current, 'li', 'Render Graphics Stop @ ' + t.time); break ; } } var t = frame[_AN_Read_length('length', frame) - 1]; var duration = t.time - frame[0].time; this.addTag(body, 'p', 'Frame Stop @ ' + t.time); this.addTag(body, 'p', 'Frame Duration: ' + duration + 'ms'); this.addTag(body, 'p', 'Total Objects Rendered: ' + total + ' (' + pixels + ' pixels)'); this.addTag(body, 'p', 'Canvas Primitives Rendered: ' + primitives); this.addTag(body, 'p', 'Unique Textures:'); var textureList = this.addTag(body, 'ol'); for (var single in textures){ this.addTag(textureList, 'li', single + ' - Times Used: ' + textures[single]); } } } , addTexture: function (t, textures){ var txt = _AN_Read_src('src', t.texture.baseTexture.source); if (txt === undefined) { txt = t.texture.baseTexture.source._pixiId; } if (textures.hasOwnProperty(txt)) { textures[txt]++ ; } else { textures[txt] = 1; } return t.width * t.height; } , addImg: function (parent, img){ _AN_Call_appendchild('appendChild', parent, img.cloneNode(true )); } , addTag: function (parent, tag, content, className, style){ var e = _AN_Call_createelement('createElement', this.win.document, tag); if (content) { e.textContent = content; } if (className) { e.className = className; } if (style) { e.style = style; } _AN_Call_appendchild('appendChild', parent, e); return e; } } ;