cocos2d / cocos2d-js__old__

cocos2d in JavaScript central repository
14 stars 9 forks source link

About Cocos2d-html5 code maintainability and performance in multi rendering mode #85

Open linshun opened 11 years ago

linshun commented 11 years ago

Because cc.Sprite, cc.Node, cc.LabelTTF has 2 sets of render mode, our current approach is defining a render specific class.

Pros and Cons: Code is harder to maintain, but performance is better.

What we want is to find an approach that is both maintainable, and performs good as well.

Current design: https://github.com/dingpinglv/cocos2d-html5/tree/Iss2072_JSPerformanceImprovement

There is an new approach: https://github.com/dingpinglv/cocos2d-html5/tree/Test_MemberFunctionRedefine

Member function redefine:

cc.Sprite = cc.Node.extend({ _canvasDraw:function(){ …………...// implement }, _webglDraw: function(){ ……………..// implement }, draw: function(){ ………..// empty },

ctor:function(webgl){ cc.Sprite.prototype.draw = webgl?cc.Sprite.prototype.drawWebGL : cc.Sprite.prototype.drawCanvas; } })


Pros: easier to maintain than the current approach, API documentation works Cons: a tiny bit of overhead in object creation

We have tested these two approaches in samples/tests/performance tests/PerformanceSpriteTest "F(1) actions". The test result is: screen shot 2013-06-05 at 6 09 23

The performance on Firefox is almost not different. However, the new approach is lower performance than current design on Chrome.

Riq, could you please help me to forward this issue to the javascript experts?

Thanks.