diff --git a/v3/src/gameobjects/index.js b/v3/src/gameobjects/index.js index cdccbbe62..73c41c71b 100644 --- a/v3/src/gameobjects/index.js +++ b/v3/src/gameobjects/index.js @@ -12,7 +12,6 @@ var GameObjects = { Graphics: require('./graphics/Graphics.js'), Group: require('./group/Group'), Image: require('./image/Image'), - ObjectPool: require('./pool/ObjectPool.js'), Particles: require('./particles/ParticleEmitterManager'), PathFollower: require('./pathfollower/PathFollower'), Sprite3D: require('./sprite3d/Sprite3D'), diff --git a/v3/src/gameobjects/pool/ObjectPool.js b/v3/src/gameobjects/pool/ObjectPool.js deleted file mode 100644 index dca14c3f1..000000000 --- a/v3/src/gameobjects/pool/ObjectPool.js +++ /dev/null @@ -1,231 +0,0 @@ -// Phaser.GameObjects.ObjectPool - -var Class = require('../../utils/Class'); - -// An Object Pool - -var ObjectPool = new Class({ - - initialize: - - function ObjectPool (manager, classType, maxSize, createCallback, callbackScope) - { - if (maxSize === undefined) { maxSize = -1; } - if (createCallback === undefined) { createCallback = this.makeGameObject; } - if (callbackScope === undefined) { callbackScope = this; } - - this.manager = manager; - this.scene = manager.scene; - - this.displayList = this.scene.sys.displayList; - this.updateList = this.scene.sys.updateList; - - this.createCallback = createCallback; - this.callbackScope = callbackScope; - - this.maxSize = maxSize; - - this.classType = classType; - - this._list = []; - }, - - makeGameObject: function () - { - var gameObject = new this.classType(this.scene); - - this.displayList.add(gameObject); - - gameObject.setActive(false); - gameObject.setVisible(false); - - return gameObject; - }, - - // Add an existing GameObject, or Array or Group of GameObjects into this Pool - add: function (child) - { - var children; - - if (Array.isArray(child)) - { - children = child; - } - else if (child.hasOwnProperty('children')) - { - children = child.children.getArray(); - } - else - { - children = [ child ]; - } - - var len = children.length; - - if (this.maxSize > -1) - { - var free = this.maxSize - this._list.length; - - if (len > free) - { - len = free; - } - } - - for (var i = 0; i < len; i++) - { - this._list.push(children[i]); - } - - return this; - }, - - // Create X new GameObjects in this Pool if there is capacity to do so - create: function (quantity) - { - for (var i = 0; i < quantity; i++) - { - if (!this.isFull()) - { - this._list.push(this.createCallback.call(this.callbackScope)); - } - } - - return this; - }, - - // Proxy method for sub-classes to override - get: function () - { - return this.getFreeGameObject(); - }, - - getFreeGameObject: function () - { - var gameObject; - - for (var i = 0; i < this._list.length; i++) - { - gameObject = this._list[i]; - - if (!gameObject.active) - { - gameObject.setActive(true); - gameObject.setVisible(true); - - return gameObject; - } - } - - if (!this.isFull()) - { - gameObject = this.createCallback.call(this.callbackScope); - - gameObject.setActive(true); - gameObject.setVisible(true); - - this._list.push(gameObject); - - return gameObject; - } - - return null; - }, - - kill: function (gameObject) - { - if (this._list.indexOf(gameObject) > -1) - { - gameObject.setActive(false); - } - }, - - killAndHide: function (gameObject) - { - if (this._list.indexOf(gameObject) > -1) - { - gameObject.setActive(false); - gameObject.setVisible(false); - } - }, - - purge: function (destroyChildren) - { - if (destroyChildren === undefined) { destroyChildren = true; } - - if (destroyChildren) - { - for (var i = 0; i < this._list.length; i++) - { - this._list[i].destroy(); - } - } - - this._list.length = 0; - }, - - isFull: function () - { - if (this.maxSize === -1) - { - return false; - } - else - { - return (this._list.length === this.maxSize); - } - }, - - update: function (time, delta) - { - for (var i = 0; i < this._list.length; i++) - { - var gameObject = this._list[i]; - - if (gameObject.active) - { - gameObject.update(time, delta); - } - } - }, - - getTotalUsed: function () - { - var total = 0; - - for (var i = 0; i < this._list.length; i++) - { - if (this._list[i].active) - { - total++; - } - } - - return total; - }, - - getTotalFree: function () - { - var used = this.getTotalUsed(); - var capacity = (this.maxSize === -1) ? 999999999999 : this.maxSize; - - return (capacity - used); - }, - - destroy: function () - { - this.manager = undefined; - this.scene = undefined; - - this.displayList = undefined; - this.updateList = undefined; - - this.createCallback = undefined; - this.callbackScope = undefined; - - this._list.length = 0; - } - -}); - -module.exports = ObjectPool; diff --git a/v3/src/gameobjects/pool/SpritePool.js b/v3/src/gameobjects/pool/SpritePool.js deleted file mode 100644 index e62e1d0e7..000000000 --- a/v3/src/gameobjects/pool/SpritePool.js +++ /dev/null @@ -1,48 +0,0 @@ -// Phaser.GameObjects.SpritePool - -var Class = require('../../utils/Class'); -var Sprite = require('../sprite/Sprite'); -var ObjectPool = require('./ObjectPool'); - -// An Object Pool - -var SpritePool = new Class({ - - Extends: ObjectPool, - - initialize: - - function SpritePool (manager, maxSize, quantity, key, frame) - { - ObjectPool.call(this, manager, Sprite, maxSize, this.makeSprite, this); - - this.defaultKey = key; - - this.defaultFrame = frame; - }, - - makeSprite: function () - { - var gameObject = new this.classType(this.scene, 0, 0, this.defaultKey, this.defaultFrame); - - this.displayList.add(gameObject); - this.updateList.add(gameObject); - - gameObject.setActive(false); - gameObject.setVisible(false); - - return gameObject; - }, - - get: function (x, y) - { - var gameObject = this.getFreeGameObject(); - - gameObject.setPosition(x, y); - - return gameObject; - } - -}); - -module.exports = SpritePool; diff --git a/v3/src/scene/local/InjectionMap.js b/v3/src/scene/local/InjectionMap.js index d26888cad..fb5bbece2 100644 --- a/v3/src/scene/local/InjectionMap.js +++ b/v3/src/scene/local/InjectionMap.js @@ -20,7 +20,6 @@ var InjectionMap = { load: 'load', make: 'make', physicsManager: 'physics', - pool: 'pool', sceneManager: 'scene', time: 'time', tweens: 'tweens' diff --git a/v3/src/scene/local/Systems.js b/v3/src/scene/local/Systems.js index a6301162e..8064d0b7a 100644 --- a/v3/src/scene/local/Systems.js +++ b/v3/src/scene/local/Systems.js @@ -10,7 +10,6 @@ var GameObjectFactory = require('../plugins/GameObjectFactory'); var InputManager = require('../plugins/InputManager'); var Loader = require('../plugins/Loader'); var PhysicsManager = require('../plugins/PhysicsManager'); -var PoolManager = require('../plugins/PoolManager'); var SceneManager = require('../plugins/SceneManager'); var Settings = require('./Settings'); var StableSort = require('../../utils/array/StableSort'); @@ -54,7 +53,6 @@ var Systems = new Class({ this.load; this.make; this.physicsManager; - this.pool; this.sceneManager; this.time; this.tweens; @@ -86,7 +84,6 @@ var Systems = new Class({ this.load = new Loader(scene); this.make = new GameObjectCreator(scene); this.physicsManager = new PhysicsManager(scene); - this.pool = new PoolManager(scene); this.sceneManager = new SceneManager(scene); this.time = new Clock(scene); this.tweens = new TweenManager(scene); @@ -128,7 +125,6 @@ var Systems = new Class({ // Move these into local arrays, so you can control which systems are registered here and their // execution order - this.pool.begin(time); this.updateList.begin(time); this.time.begin(time); this.tweens.begin(time); @@ -136,7 +132,6 @@ var Systems = new Class({ this.physicsManager.update(time, delta); - this.pool.update(time, delta); this.updateList.update(time, delta); this.time.update(time, delta); this.tweens.update(time, delta); @@ -250,7 +245,6 @@ var Systems = new Class({ this.settings.active = false; this.settings.visible = false; - this.pool.shutdown(); this.displayList.shutdown(); this.updateList.shutdown(); this.time.shutdown(); @@ -268,7 +262,6 @@ var Systems = new Class({ // TODO this.add.destroy(); - this.pool.destroy(); this.time.destroy(); this.tweens.destroy(); diff --git a/v3/src/scene/plugins/PoolManager.js b/v3/src/scene/plugins/PoolManager.js deleted file mode 100644 index 5da83a807..000000000 --- a/v3/src/scene/plugins/PoolManager.js +++ /dev/null @@ -1,140 +0,0 @@ -var Class = require('../../utils/Class'); -var ObjectPool = require('../../gameobjects/pool/ObjectPool'); -var SpritePool = require('../../gameobjects/pool/SpritePool'); - -var PoolManager = new Class({ - - initialize: - - function PoolManager (scene) - { - this.scene = scene; - - this._active = []; - this._pendingInsertion = []; - this._pendingRemoval = []; - - this.processing = false; - }, - - add: function (pool) - { - if (this.processing) - { - this._pendingInsertion.push(pool); - } - else - { - this._active.push(pool); - } - - return this; - }, - - createSpritePool: function (maxSize, key, frame) - { - var pool = new SpritePool(this, maxSize, key, frame); - - this.add(pool); - - return pool; - }, - - createObjectPool: function (classType, maxSize) - { - if (maxSize === undefined) { maxSize = -1; } - - var pool = new ObjectPool(this, classType, maxSize); - - this.add(pool); - - return pool; - }, - - begin: function () - { - var toRemove = this._pendingRemoval.length; - var toInsert = this._pendingInsertion.length; - - if (toRemove === 0 && toInsert === 0) - { - // Quick bail - return; - } - - var i; - var pool; - - // Delete old pools - for (i = 0; i < toRemove; i++) - { - pool = this._pendingRemoval[i]; - - var index = this._active.indexOf(pool); - - if (index > -1) - { - this._active.splice(index, 1); - } - - pool.destroy(); - } - - // Move pending to active - this._active = this._active.concat(this._pendingInsertion.splice(0)); - - // Clear the lists - this._pendingRemoval.length = 0; - this._pendingInsertion.length = 0; - }, - - update: function (time, delta) - { - this.processing = true; - - for (var i = 0; i < this._active.length; i++) - { - var pool = this._active[i]; - - pool.update.call(pool, time, delta); - } - - this.processing = false; - }, - - // Scene that owns this Pool is shutting down - shutdown: function () - { - var i; - - for (i = 0; i < this._pendingInsertion.length; i++) - { - this._pendingInsertion[i].destroy(); - } - - for (i = 0; i < this._active.length; i++) - { - this._active[i].destroy(); - } - - for (i = 0; i < this._pendingRemoval.length; i++) - { - this._pendingRemoval[i].destroy(); - } - - this._active.length = 0; - this._pendingRemoval.length = 0; - this._pendingInsertion.length = 0; - }, - - // Game level nuke - destroy: function () - { - this.shutdown(); - - this.scene = undefined; - } - -}); - -module.exports = PoolManager;