Skip to content

Commit 7f9e68a

Browse files
author
pandamicro
committed
Improve RenderCmd construction performance
1 parent 41b1026 commit 7f9e68a

File tree

46 files changed

+140
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+140
-123
lines changed

cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ cc.Node.RenderCmd.prototype._originSyncStatus = cc.Node.RenderCmd.prototype._syn
542542
(function () {
543543
//The cc.Node's render command for Canvas
544544
cc.Node.CanvasRenderCmd = function (renderable) {
545-
cc.Node.RenderCmd.call(this, renderable);
545+
this._node = renderable;
546+
this._anchorPointInPoints = {x: 0, y: 0};
547+
this._displayedColor = cc.color(255, 255, 255, 255);
546548
this._cachedParent = null;
547549
this._cacheDirty = false;
548550
this._currentRegion = new cc.Region();
@@ -559,6 +561,7 @@ cc.Node.RenderCmd.prototype._originSyncStatus = cc.Node.RenderCmd.prototype._syn
559561

560562
var proto = cc.Node.CanvasRenderCmd.prototype = Object.create(cc.Node.RenderCmd.prototype);
561563
proto.constructor = cc.Node.CanvasRenderCmd;
564+
proto._rootCtor = cc.Node.CanvasRenderCmd;
562565

563566
proto._notifyRegionStatus = function (status) {
564567
if (this._needDraw && this._regionFlag < status) {

cocos2d/core/base-nodes/CCNodeWebGLRenderCmd.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
// ------------------------------ The cc.Node's render command for WebGL ----------------------------------
2525
(function() {
2626
cc.Node.WebGLRenderCmd = function (renderable) {
27-
cc.Node.RenderCmd.call(this, renderable);
27+
this._node = renderable;
28+
this._anchorPointInPoints = {x: 0, y: 0};
29+
this._displayedColor = cc.color(255, 255, 255, 255);
2830
this._shaderProgram = null;
2931
};
3032

3133
var proto = cc.Node.WebGLRenderCmd.prototype = Object.create(cc.Node.RenderCmd.prototype);
3234
proto.constructor = cc.Node.WebGLRenderCmd;
35+
proto._rootCtor = cc.Node.WebGLRenderCmd;
3336

3437
proto._updateColor = function () {
3538
};

cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
5252
};
5353
var proto = cc.LabelTTF.RenderCmd.prototype;
5454
proto.constructor = cc.LabelTTF.RenderCmd;
55+
proto._labelCmdCtor = cc.LabelTTF.RenderCmd;
5556

5657
proto._setFontStyle = function (fontNameOrFontDef, fontSize, fontStyle, fontWeight) {
5758
if (fontNameOrFontDef instanceof cc.FontDefinition) {
@@ -371,9 +372,9 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
371372
};
372373
})();
373374

374-
(function(){
375-
cc.LabelTTF.CacheRenderCmd = function (renderable) {
376-
cc.LabelTTF.RenderCmd.call(this,renderable);
375+
(function () {
376+
cc.LabelTTF.CacheRenderCmd = function () {
377+
this._labelCmdCtor();
377378
var locCanvas = this._labelCanvas = document.createElement("canvas");
378379
locCanvas.width = 1;
379380
locCanvas.height = 1;
@@ -385,6 +386,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
385386

386387
var proto = cc.LabelTTF.CacheRenderCmd.prototype;
387388
proto.constructor = cc.LabelTTF.CacheRenderCmd;
389+
proto._cacheCmdCtor = cc.LabelTTF.CacheRenderCmd;
388390

389391
proto._updateTexture = function () {
390392
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
@@ -433,21 +435,21 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
433435

434436
})();
435437

436-
(function(){
438+
(function () {
437439
cc.LabelTTF.CacheCanvasRenderCmd = function (renderable) {
438-
cc.Sprite.CanvasRenderCmd.call(this, renderable);
439-
cc.LabelTTF.CacheRenderCmd.call(this);
440+
this._spriteCmdCtor(renderable);
441+
this._cacheCmdCtor();
440442
};
441443

442444
var proto = cc.LabelTTF.CacheCanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);
443445
cc.inject(cc.LabelTTF.CacheRenderCmd.prototype, proto);
444446
proto.constructor = cc.LabelTTF.CacheCanvasRenderCmd;
445447
})();
446448

447-
(function(){
449+
(function () {
448450
cc.LabelTTF.CanvasRenderCmd = function (renderable) {
449-
cc.Sprite.CanvasRenderCmd.call(this, renderable);
450-
cc.LabelTTF.RenderCmd.call(this);
451+
this._spriteCmdCtor(renderable);
452+
this._labelCmdCtor();
451453
};
452454

453455
cc.LabelTTF.CanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);

cocos2d/core/labelttf/CCLabelTTFWebGLRenderCmd.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
// ----------------------------------- LabelTTF WebGL render cmd ----------------------------
2626
(function () {
2727
cc.LabelTTF.WebGLRenderCmd = function (renderable) {
28-
cc.Sprite.WebGLRenderCmd.call(this, renderable);
29-
cc.LabelTTF.CacheRenderCmd.call(this);
28+
this._spriteCmdCtor(renderable);
29+
this._cacheCmdCtor();
3030
};
3131
var proto = cc.LabelTTF.WebGLRenderCmd.prototype = Object.create(cc.Sprite.WebGLRenderCmd.prototype);
3232

cocos2d/core/layers/CCLayerCanvasRenderCmd.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
*/
3434
(function () {
3535
//Layer's canvas render command
36-
cc.Layer.CanvasRenderCmd = function(renderable){
37-
cc.Node.CanvasRenderCmd.call(this, renderable);
36+
cc.Layer.CanvasRenderCmd = function (renderable) {
37+
this._rootCtor(renderable);
3838
this._isBaked = false;
3939
this._bakeSprite = null;
4040
this._canUseDirtyRegion = true;
@@ -43,6 +43,7 @@
4343

4444
var proto = cc.Layer.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
4545
proto.constructor = cc.Layer.CanvasRenderCmd;
46+
proto._layerCmdCtor = cc.Layer.CanvasRenderCmd;
4647

4748
proto._setCacheDirty = function (child) {
4849
if (child && this._updateCache === 0)
@@ -215,8 +216,8 @@
215216
*/
216217
(function () {
217218
//LayerColor's canvas render command
218-
cc.LayerColor.CanvasRenderCmd = function(renderable){
219-
cc.Layer.CanvasRenderCmd.call(this, renderable);
219+
cc.LayerColor.CanvasRenderCmd = function (renderable) {
220+
this._layerCmdCtor(renderable);
220221
this._needDraw = true;
221222
this._blendFuncStr = "source-over";
222223
this._bakeRenderCmd = new cc.CustomRenderCmd(this, this._bakeRendering);

cocos2d/core/layers/CCLayerWebGLRenderCmd.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
/**
3232
* cc.Layer's rendering objects of WebGL
3333
*/
34-
(function(){
35-
cc.Layer.WebGLRenderCmd = function(renderable){
36-
cc.Node.WebGLRenderCmd.call(this, renderable);
34+
(function () {
35+
cc.Layer.WebGLRenderCmd = function (renderable) {
36+
this._rootCtor(renderable);
37+
this._isBaked = false;
3738
};
3839

3940
var proto = cc.Layer.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
4041
proto.constructor = cc.Layer.WebGLRenderCmd;
42+
proto._layerCmdCtor = cc.Layer.WebGLRenderCmd;
4143

4244
proto.bake = function () {
4345
};
@@ -52,9 +54,9 @@
5254
/**
5355
* cc.LayerColor's rendering objects of WebGL
5456
*/
55-
(function(){
56-
cc.LayerColor.WebGLRenderCmd = function(renderable){
57-
cc.Layer.WebGLRenderCmd.call(this, renderable);
57+
(function () {
58+
cc.LayerColor.WebGLRenderCmd = function (renderable) {
59+
this._layerCmdCtor(renderable);
5860
this._needDraw = true;
5961

6062
this._matrix = new cc.math.Matrix4();

cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
(function () {
2626
cc.Sprite.CanvasRenderCmd = function (renderable) {
27-
cc.Node.CanvasRenderCmd.call(this, renderable);
27+
this._rootCtor(renderable);
2828
this._needDraw = true;
2929
this._textureCoord = {
3030
renderX: 0, //the x of texture coordinate for render, when texture tinted, its value doesn't equal x.
@@ -43,6 +43,7 @@
4343

4444
var proto = cc.Sprite.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
4545
proto.constructor = cc.Sprite.CanvasRenderCmd;
46+
proto._spriteCmdCtor = cc.Sprite.CanvasRenderCmd;
4647

4748
proto.setDirtyRecursively = function (value) {
4849
};

cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(function () {
2727

2828
cc.Sprite.WebGLRenderCmd = function (renderable) {
29-
cc.Node.WebGLRenderCmd.call(this, renderable);
29+
this._rootCtor(renderable);
3030
this._needDraw = true;
3131

3232
this._vertices = [
@@ -44,6 +44,7 @@
4444

4545
var proto = cc.Sprite.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
4646
proto.constructor = cc.Sprite.WebGLRenderCmd;
47+
proto._spriteCmdCtor = cc.Sprite.WebGLRenderCmd;
4748

4849
proto.updateBlendFunc = function (blendFunc) {
4950
};

cocos2d/labels/CCLabelBMFontCanvasRenderCmd.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
3131
****************************************************************************/
3232

33-
(function(){
34-
cc.LabelBMFont.CanvasRenderCmd = function(renderableObject){
35-
cc.Node.CanvasRenderCmd.call(this, renderableObject);
33+
(function () {
34+
cc.LabelBMFont.CanvasRenderCmd = function (renderableObject) {
35+
this._rootCtor(renderableObject);
3636
};
3737

3838
var proto = cc.LabelBMFont.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);

cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
3131
****************************************************************************/
3232

33-
(function(){
34-
cc.LabelBMFont.WebGLRenderCmd = function(renderableObject){
35-
cc.Node.WebGLRenderCmd.call(this, renderableObject);
33+
(function () {
34+
cc.LabelBMFont.WebGLRenderCmd = function (renderableObject) {
35+
this._rootCtor(renderableObject);
3636
};
3737

3838
var proto = cc.LabelBMFont.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);

0 commit comments

Comments
 (0)