Permalink
Browse files

HTML5: Improved performance!

  • Loading branch information...
1 parent 875bd4d commit e58c8f2ea81dbe8a7505b448b87dfa4b11195005 @splhack splhack committed Feb 27, 2014
@@ -19,4 +19,5 @@ extern class BitmapClip
public var y:Float;
public function setMatrix(matrix:Matrix):Void;
+ public function detachFromParent():Void;
}
@@ -7,6 +7,8 @@ typedef StageSize = {
typedef EventListener = Movie->Button->Void;
+typedef ExecListener = LWF->Void;
+
@:native("LWF.LWF")
extern class LWF
{
@@ -46,6 +48,8 @@ extern class LWF
public function addEventListener(event:String, listener:EventListener):Void;
+ public function addExecListener(listener:ExecListener):Void;
+
public function addMovieEventListener(instanceName:String, listeners:{}):Void;
public function clearAllowButton():Void;
@@ -56,6 +60,8 @@ extern class LWF
public function clearEventListener(event:String):Void;
+ public function clearExecListener():Void;
+
public function clearMovieEventListener(instanceName:String, ?type:String):Void;
public function denyAllButtons():Void;
@@ -98,6 +104,8 @@ extern class LWF
public function removeEventListener(event:String, listener:EventListener):Void;
+ public function removeExecListener(listener:ExecListener):Void;
+
public function removeMovieEventListener(instanceName:String, listeners:{}):Void;
public function render():Void;
@@ -120,6 +128,8 @@ extern class LWF
public function setEventListener(event:String, listener:EventListener):Void;
+ public function setExecListener(listener:ExecListener):Void;
+
public function setFastForward(fastForward:Bool):Void;
public function setFastForwardTimeout(fastForwardTimeout:Int):Void;
@@ -84,7 +84,7 @@ class CanvasBitmapRenderer
@matrix = new Matrix(0, 0, 0, 0, 0, 0)
@matrixForAtlas = new Matrix() if fragment.rotated or
@context.x isnt 0 or @context.y isnt 0 or @context.scale isnt 1
- @cmd = {}
+ @cmd = new CanvasRenderCommand()
destruct: ->
@@ -18,6 +18,21 @@
# 3. This notice may not be removed or altered from any source distribution.
#
+class CanvasRenderCommand
+ constructor: ->
+ @renderCount = 0
+ @renderingIndex = 0
+ @alpha = 0
+ @blendMode = 0
+ @maskMode = 0
+ @matrix = null
+ @image = null
+ @pattern = null
+ @u = 0
+ @v = 0
+ @w = 0
+ @h = 0
+
class CanvasRendererFactory extends WebkitCSSRendererFactory
constructor:(data, @resourceCache, \
@cache, @stage, @textInSubpixel, @needsClear, @quirkyClearRect) ->
@@ -172,11 +187,16 @@ class CanvasRendererFactory extends WebkitCSSRendererFactory
@renderBlendMode = "normal"
@renderMaskMode = "normal"
@renderMasked = false
- for rIndex in @commandsKeys
+ renderCount = lwf.renderCount
+ for rIndex in [0...@commands.length]
cmd = @commands[rIndex]
- if cmd.subCommandsKeys?
- for srIndex in cmd.subCommandsKeys
+ continue if !cmd? or cmd.renderingIndex isnt rIndex or
+ cmd.renderCount isnt renderCount
+ if cmd.subCommands?
+ for srIndex in [0...cmd.subCommands.length]
scmd = cmd.subCommands[srIndex]
+ continue if !scmd? or scmd.renderingIndex isnt srIndex or
+ scmd.renderCount isnt renderCount
ctx = @render(ctx, scmd)
ctx = @render(ctx, cmd)
@@ -35,12 +35,13 @@ class CanvasResourceCache extends WebkitCSSResourceCache
canvas = document.createElement('canvas')
canvas.width = w
canvas.height = h
+ canvas.name = @getCanvasName()
ctx = canvas.getContext('2d')
canvas.withPadding = true
ctx.drawImage(image,
0, 0, image.width, image.height,
1, 1, image.width, image.height)
imageCache[texture.filename] = canvas
- super
+ super(settings, imageCache, texture, image)
return
@@ -24,12 +24,12 @@ class CanvasTextRenderer extends HTML5TextRenderer
constructor: ->
super
- @cmd = {}
+ @cmd = new CanvasRenderCommand()
render:(m, c, renderingIndex, renderingCount, visible) ->
return if !visible or c.multi.alpha is 0
- super
+ super(m, c, renderingIndex, renderingCount, visible)
cmd = @cmd
cmd.alpha = c.multi.alpha
@@ -83,7 +83,6 @@ class Cocos2dResourceCache extends WebkitCSSResourceCache
return
loadImages:(settings, data) ->
- lwfUrl = settings["lwf"]
prefix = settings["imagePrefix"] ? settings["prefix"] ? ""
suffix = settings["imageSuffix"] ? ""
imageCache = {}
@@ -102,7 +101,7 @@ class Cocos2dResourceCache extends WebkitCSSResourceCache
return
unloadLWF:(lwf) ->
- super
+ super(lwf)
unless @cache[lwf.url]?
for name, url of lwf.renderFactory.cache
if url.match(/\.(png|jpg)$/i)
Oops, something went wrong.

0 comments on commit e58c8f2

Please sign in to comment.