Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Recording node references to speed up node retrieval by id in the Nod…
Browse files Browse the repository at this point in the history
…eMap component.
  • Loading branch information
probityrules committed Oct 20, 2015
1 parent 2648fda commit 91e47c0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 30 deletions.
97 changes: 83 additions & 14 deletions lib/platypus.combined.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ this.platypus = this.platypus || {};
* @type String
* @static
**/
platypus.buildDate = /*=date*/"Mon, 19 Oct 2015 21:14:39 GMT"; // injected by build process
platypus.buildDate = /*=date*/"Tue, 20 Oct 2015 18:50:23 GMT"; // injected by build process

})();

Expand Down Expand Up @@ -2823,6 +2823,10 @@ platypus.Entity = (function () {
* @readonly
*/
this.playing = false;

this._visible = true;

this._updating = false;

// Set up initial playthrough.
if (textures.length < 2) {
Expand All @@ -2838,6 +2842,22 @@ platypus.Entity = (function () {

Object.defineProperties(prototype, {
/**
* The visibility of the sprite.
*
* @property visible
* @memberof PIXI.DisplayObject#
*/
visible: {
get: function () {
return this._visible;
},
set: function (value) {
this._visible = value;
this._syncUpdate();
}
},

/**
* The PIXIAnimations current frame index
*
* @member {number}
Expand All @@ -2863,7 +2883,7 @@ platypus.Entity = (function () {
}

this.playing = false;
PIXI.ticker.shared.remove(this.update, this);
this._syncUpdate();
};

/**
Expand All @@ -2876,7 +2896,21 @@ platypus.Entity = (function () {
}

this.playing = true;
PIXI.ticker.shared.add(this.update, this);
this._syncUpdate();
};

prototype._syncUpdate = function () {
var update = this.playing && this._visible;

if (update !== this._updating) {
this._updating = update;

if (update) {
PIXI.ticker.shared.add(this.update, this);
} else {
PIXI.ticker.shared.remove(this.update, this);
}
}
};

/**
Expand Down Expand Up @@ -15014,12 +15048,13 @@ This component sets up a NodeMap to be used by the [[NodeResident]] component on
var i = 0;

this.owner.map = this.map = [];
this.nodes = {};

this.residentsAwaitingNode = [];

if (definition.map) {
for (i = 0; i < definition.map.length; i++) {
this.map.push(new Node(definition.map[i], this));
this.addNode(new Node(definition.map[i], this));
}
}
},
Expand All @@ -15036,8 +15071,8 @@ This component sets up a NodeMap to be used by the [[NodeResident]] component on
} else {
node = new Node(nodeDefinition, this);
}

this.map.push(node);
this.addNode(node);

for (i = this.residentsAwaitingNode.length - 1; i >= 0; i--) {
entity = this.residentsAwaitingNode[i];
Expand All @@ -15063,6 +15098,11 @@ This component sets up a NodeMap to be used by the [[NodeResident]] component on
},

publicMethods: {
addNode: function (node) {
this.map.push(node);
this.nodes[node.id] = node;
},

getNode: function () {
var i = 0,
id = '',
Expand All @@ -15081,12 +15121,8 @@ This component sets up a NodeMap to be used by the [[NodeResident]] component on
id += divider + args[i];
divider = '|';
}
for (i = 0; i < this.map.length; i++) {
if (this.map[i].id === id) {
return this.map[i];
}
}
return null;

return this.nodes[id] || null;
},

/**
Expand Down Expand Up @@ -17932,6 +17968,7 @@ This component will destroy the entity once an animation has finished. This is u
"cache": function () {
this.updateSprite(false);
this.owner.cacheRender = this.container;
this.cache = true;
if (this.owner.parent && this.owner.parent.triggerEventOnChildren) {
/**
* On receiving a "cache" event, this component triggers "cache-sprite" to cache its rendering into the background. This is an optimization for static images to reduce render calls.
Expand Down Expand Up @@ -18627,6 +18664,9 @@ This component will destroy the entity once an animation has finished. This is u
}
this.removePins();
this.followThroughs = null;
if (!this.cache) {
this.sprite.destroy();
}
this.sprite = null;
}
}
Expand Down Expand Up @@ -18656,6 +18696,7 @@ This component will destroy the entity once an animation has finished. This is u
var AABB = include('platypus.AABB'),
Animation = include('platypus.PIXIAnimation'),
Application = include('springroll.Application'),
CanvasRenderer = include('PIXI.CanvasRenderer'),
Container = include('PIXI.Container'),
Graphics = include('PIXI.Graphics'),
ParticleContainer = include('PIXI.ParticleContainer'),
Expand Down Expand Up @@ -18703,7 +18744,8 @@ This component will destroy the entity once an animation has finished. This is u
tile.template = this; // backwards reference for clearing index later.
},
nullTemplate = {
getNext: doNothing
getNext: doNothing,
destroy: doNothing
},
prototype = Template.prototype;

Expand All @@ -18729,6 +18771,16 @@ This component will destroy the entity once an animation has finished. This is u
prototype.clear = function () {
this.index = 0;
};

prototype.destroy = function () {
var i = 0;

for (i = 0; i < this.instances.length; i++) {
this.instances[i].destroy();
}

this.instances.length = 0;
};

return platypus.createComponentClass({

Expand Down Expand Up @@ -18840,6 +18892,7 @@ This component will destroy the entity once an animation has finished. This is u
var imgMap = this.imageMap;

this.doMap = null; //list of display objects that should overlay tile map.
this.cachedDisplayObjects = null;
this.populate = this.populateTiles;

this.tiles = {};
Expand All @@ -18858,7 +18911,7 @@ This component will destroy the entity once an animation has finished. This is u
this.cachePixels = new AABB();

// Set up containers
this.tileContainer = (this.spriteSheet.images.length > 1) ? new Container() : new ParticleContainer(15000, {position: true, rotation: true, scale: true});
this.tileContainer = ((this.spriteSheet.images.length > 1) || (this.renderer instanceof CanvasRenderer)) ? new Container() : new ParticleContainer(15000, {position: true, rotation: true, scale: true});
this.mapContainer = new Container();
this.mapContainer.addChild(this.tileContainer);

Expand Down Expand Up @@ -19156,8 +19209,10 @@ This component will destroy the entity once an animation has finished. This is u
if (this.entityCache && object) { //TODO: currently only handles a single display object on the cached entity.
if (!this.doMap) {
this.doMap = [];
this.cachedDisplayObjects = [];
this.populate = this.populateTilesAndEntities;
}
this.cachedDisplayObjects.push(object);

// Determine range:
bounds = object.getBounds(object.transformMatrix);
Expand Down Expand Up @@ -19422,6 +19477,7 @@ This component will destroy the entity once an animation has finished. This is u
destroy: function () {
var x = 0,
y = 0,
key = '',
grid = this.cacheGrid;

if (grid) {
Expand All @@ -19442,9 +19498,22 @@ This component will destroy the entity once an animation has finished. This is u
this.parentContainer.removeChild(this.mapContainer);
}
this.imageMap.length = 0;

for (key in this.tiles) {
if (this.tiles.hasOwnProperty(key)) {
this.tiles[key].destroy();
}
}
this.tiles = null;
this.parentContainer = null;
this.tilesSprite = null;

if (this.cachedDisplayObjects) {
for (x = 0; x < this.cachedDisplayObjects.length; x++) {
this.cachedDisplayObjects[x].destroy();
}
this.cachedDisplayObjects.length = 0;
}
}
}
});
Expand Down
Loading

0 comments on commit 91e47c0

Please sign in to comment.