diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 256489f..035440c 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,6 +1,7 @@ var math = require('../math'), EventEmitter = require('eventemitter3'), - Transform = require('./Transform'), + Transform = require('./TransformStatic'), + // Transform = require('./Transform'), _tempDisplayObjectParent = new DisplayObject(); diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 256489f..035440c 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,6 +1,7 @@ var math = require('../math'), EventEmitter = require('eventemitter3'), - Transform = require('./Transform'), + Transform = require('./TransformStatic'), + // Transform = require('./Transform'), _tempDisplayObjectParent = new DisplayObject(); diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 2d1e90f..21dd156 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -60,6 +60,8 @@ this._dirty = false; this.updated = true; + + this._worldID = 0; } Transform.prototype.constructor = Transform; @@ -105,6 +107,8 @@ wt.d = lt.c * pt.b + lt.d * pt.d; wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._worldID ++; }; Transform.prototype.updateChildTransform = function (childTransform) diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 256489f..035440c 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,6 +1,7 @@ var math = require('../math'), EventEmitter = require('eventemitter3'), - Transform = require('./Transform'), + Transform = require('./TransformStatic'), + // Transform = require('./Transform'), _tempDisplayObjectParent = new DisplayObject(); diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 2d1e90f..21dd156 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -60,6 +60,8 @@ this._dirty = false; this.updated = true; + + this._worldID = 0; } Transform.prototype.constructor = Transform; @@ -105,6 +107,8 @@ wt.d = lt.c * pt.b + lt.d * pt.d; wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._worldID ++; }; Transform.prototype.updateChildTransform = function (childTransform) diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index fcab61b..cddd68e 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -24,40 +24,56 @@ * * @member {PIXI.ObservablePoint} */ - this.position = new ObservablePoint(this,0.0); + this.position = new ObservablePoint(this.onChange, this,0.0); /** * The scale factor of the object. * * @member {PIXI.ObservablePoint} */ - this.scale = new ObservablePoint(this,1,1); + this.scale = new ObservablePoint(this.onChange, this,1,1); /** * The pivot point of the displayObject that it rotates around * * @member {PIXI.ObservablePoint} */ - this.pivot = new ObservablePoint(this,0.0); + this.pivot = new ObservablePoint(this.onChange, this,0.0); /** * The skew amount, on the x and y axis. * * @member {PIXI.ObservablePoint} */ - this.skew = new ObservablePoint(this,0.0); + this.skew = new ObservablePoint(this.updateSkew, this,0.0); this._rotation = 0; this._sr = Math.sin(0); this._cr = Math.cos(0); - this._dirtyLocal = 0; - this._versionLocal = 0; - this._versionGlobal = 0; + this._localID = 0; + this._currentLocalID = 0; + this._parentID = 0; + this._worldID = 0; } TransformStatic.prototype.constructor = TransformStatic; +TransformStatic.prototype.onChange = function () +{ + this._localID ++; +}; + +TransformStatic.prototype.updateSkew = function () +{ + this._cy = Math.cos(this.skew.y); + this._sy = Math.sin(this.skew.y); + this._nsx = Math.sin(this.skew.x); + this._cx = Math.cos(this.skew.x); + + this._localID ++; +}; + /** * Updates the values of the object and applies the parent's transform. * @param parentTransform {PIXI.Transform} The transform of the parent of this object @@ -69,7 +85,7 @@ var wt = this.worldTransform; var lt = this.localTransform; - if(this._dirtyLocal !== this._versionLocal) + if(this._localID !== this._currentLocalID) { // get the matrix values of the displayobject based on its transform properties.. lt.a = this._cr * this.scale._x; @@ -78,18 +94,27 @@ lt.d = this._cr * this.scale._y; lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c); lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d); - this._dirtyLocal = this._versionLocal; - } - // concat the parent matrix with the objects transform. - wt.a = lt.a * pt.a + lt.b * pt.c; - wt.b = lt.a * pt.b + lt.b * pt.d; - wt.c = lt.c * pt.a + lt.d * pt.c; - wt.d = lt.c * pt.b + lt.d * pt.d; - wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; - wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + this._currentLocalID = this._localID; - this._versionGlobal++; - this.updated = true; + // force an update.. + this._parentID = -1; + } + + if(this._parentID !== parentTransform._worldID) + { + // concat the parent matrix with the objects transform. + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._parentID = parentTransform._worldID; + + // update the id of the transform.. + this._worldID ++; + } }; TransformStatic.prototype.updateChildTransform = function (childTransform) @@ -112,6 +137,7 @@ this._rotation = value; this._sr = Math.sin(value); this._cr = Math.cos(value); + this._localID ++; } } }); diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 256489f..035440c 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,6 +1,7 @@ var math = require('../math'), EventEmitter = require('eventemitter3'), - Transform = require('./Transform'), + Transform = require('./TransformStatic'), + // Transform = require('./Transform'), _tempDisplayObjectParent = new DisplayObject(); diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 2d1e90f..21dd156 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -60,6 +60,8 @@ this._dirty = false; this.updated = true; + + this._worldID = 0; } Transform.prototype.constructor = Transform; @@ -105,6 +107,8 @@ wt.d = lt.c * pt.b + lt.d * pt.d; wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._worldID ++; }; Transform.prototype.updateChildTransform = function (childTransform) diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index fcab61b..cddd68e 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -24,40 +24,56 @@ * * @member {PIXI.ObservablePoint} */ - this.position = new ObservablePoint(this,0.0); + this.position = new ObservablePoint(this.onChange, this,0.0); /** * The scale factor of the object. * * @member {PIXI.ObservablePoint} */ - this.scale = new ObservablePoint(this,1,1); + this.scale = new ObservablePoint(this.onChange, this,1,1); /** * The pivot point of the displayObject that it rotates around * * @member {PIXI.ObservablePoint} */ - this.pivot = new ObservablePoint(this,0.0); + this.pivot = new ObservablePoint(this.onChange, this,0.0); /** * The skew amount, on the x and y axis. * * @member {PIXI.ObservablePoint} */ - this.skew = new ObservablePoint(this,0.0); + this.skew = new ObservablePoint(this.updateSkew, this,0.0); this._rotation = 0; this._sr = Math.sin(0); this._cr = Math.cos(0); - this._dirtyLocal = 0; - this._versionLocal = 0; - this._versionGlobal = 0; + this._localID = 0; + this._currentLocalID = 0; + this._parentID = 0; + this._worldID = 0; } TransformStatic.prototype.constructor = TransformStatic; +TransformStatic.prototype.onChange = function () +{ + this._localID ++; +}; + +TransformStatic.prototype.updateSkew = function () +{ + this._cy = Math.cos(this.skew.y); + this._sy = Math.sin(this.skew.y); + this._nsx = Math.sin(this.skew.x); + this._cx = Math.cos(this.skew.x); + + this._localID ++; +}; + /** * Updates the values of the object and applies the parent's transform. * @param parentTransform {PIXI.Transform} The transform of the parent of this object @@ -69,7 +85,7 @@ var wt = this.worldTransform; var lt = this.localTransform; - if(this._dirtyLocal !== this._versionLocal) + if(this._localID !== this._currentLocalID) { // get the matrix values of the displayobject based on its transform properties.. lt.a = this._cr * this.scale._x; @@ -78,18 +94,27 @@ lt.d = this._cr * this.scale._y; lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c); lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d); - this._dirtyLocal = this._versionLocal; - } - // concat the parent matrix with the objects transform. - wt.a = lt.a * pt.a + lt.b * pt.c; - wt.b = lt.a * pt.b + lt.b * pt.d; - wt.c = lt.c * pt.a + lt.d * pt.c; - wt.d = lt.c * pt.b + lt.d * pt.d; - wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; - wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + this._currentLocalID = this._localID; - this._versionGlobal++; - this.updated = true; + // force an update.. + this._parentID = -1; + } + + if(this._parentID !== parentTransform._worldID) + { + // concat the parent matrix with the objects transform. + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._parentID = parentTransform._worldID; + + // update the id of the transform.. + this._worldID ++; + } }; TransformStatic.prototype.updateChildTransform = function (childTransform) @@ -112,6 +137,7 @@ this._rotation = value; this._sr = Math.sin(value); this._cr = Math.cos(value); + this._localID ++; } } }); diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 62296d9..5fdf224 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,6 +93,7 @@ this.texture = texture || Texture.EMPTY; this.textureDirty = true; this.vertexData = new Float32Array(8); + this._transformID = -1; } // constructor @@ -201,6 +202,16 @@ Sprite.prototype.calculateVertices = function () { + if(this._transformID === this.transform._worldID && !this.textureDirty) + { + return; + } + + this._transformID = this.transform._worldID; + this.textureDirty = false; + + // set the vertex data + var texture = this._texture, wt = this.transform.worldTransform, a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, @@ -254,12 +265,7 @@ */ Sprite.prototype._renderWebGL = function (renderer) { - if(this.transform.updated || this.textureDirty) - { - this.textureDirty = false; - // set the vertex data - this.calculateVertices(); - } + this.calculateVertices(); renderer.setObjectRenderer(renderer.plugins.sprite); renderer.plugins.sprite.render(this); @@ -287,14 +293,8 @@ //TODO lookinto caching.. if(!this._currentBounds) { - // if(this.vertexDirty) - { - this.vertexDirty = false; - - // set the vertex data - this.calculateVertices(); - - } + // set the vertex data + this.calculateVertices(); var minX, maxX, minY, maxY, w0, w1, h0, h1,