mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 22:48:34 +00:00
Added in destroy methods for all managers and invoked them from Game
This commit is contained in:
parent
f1a25921c7
commit
a802914243
22 changed files with 200 additions and 38 deletions
|
@ -84,6 +84,8 @@ var AnimationManager = new Class({
|
|||
boot: function ()
|
||||
{
|
||||
this.textureManager = this.game.textures;
|
||||
|
||||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -551,7 +553,11 @@ var AnimationManager = new Class({
|
|||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
// TODO
|
||||
this.anims.clear();
|
||||
|
||||
this.textureManager = null;
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
var AddToDOM = require('../dom/AddToDOM');
|
||||
var AnimationManager = require('../animations/AnimationManager');
|
||||
var CacheManager = require('../cache/CacheManager');
|
||||
var CanvasPool = require('../display/canvas/CanvasPool');
|
||||
var Class = require('../utils/Class');
|
||||
var Config = require('./Config');
|
||||
var CreateRenderer = require('./CreateRenderer');
|
||||
var Data = require('../data/DataManager');
|
||||
var DataManager = require('../data/DataManager');
|
||||
var DebugHeader = require('./DebugHeader');
|
||||
var Device = require('../device');
|
||||
var DOMContentLoaded = require('../dom/DOMContentLoaded');
|
||||
|
@ -133,10 +134,10 @@ var Game = new Class({
|
|||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Data} registry
|
||||
* @property {Phaser.Data.DataManager} registry
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.registry = new Data(this);
|
||||
this.registry = new DataManager(this);
|
||||
|
||||
/**
|
||||
* An instance of the Input Manager.
|
||||
|
@ -212,9 +213,6 @@ var Game = new Class({
|
|||
|
||||
// Wait for the DOM Ready event, then call boot.
|
||||
DOMContentLoaded(this.boot.bind(this));
|
||||
|
||||
// For debugging only
|
||||
window.game = this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -425,9 +423,24 @@ var Game = new Class({
|
|||
* @method Phaser.Game#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
destroy: function (removeCanvas)
|
||||
{
|
||||
// TODO
|
||||
this.loop.destroy();
|
||||
|
||||
this.scene.destroy();
|
||||
|
||||
this.renderer.destroy();
|
||||
|
||||
this.events.emit('destroy');
|
||||
|
||||
this.events.removeAllListeners();
|
||||
|
||||
this.onStepCallback = null;
|
||||
|
||||
if (removeCanvas)
|
||||
{
|
||||
CanvasPool.remove(this.canvas);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -598,7 +598,8 @@ var TimeStep = new Class({
|
|||
{
|
||||
this.stop();
|
||||
|
||||
this.callback = null;
|
||||
this.callback = NOOP;
|
||||
|
||||
this.raf = null;
|
||||
this.game = null;
|
||||
}
|
||||
|
|
2
src/cache/CacheManager.js
vendored
2
src/cache/CacheManager.js
vendored
|
@ -131,6 +131,8 @@ var CacheManager = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.custom = {};
|
||||
|
||||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,8 @@ var DataManager = new Class({
|
|||
this.blockSet = false;
|
||||
|
||||
this._frozen = false;
|
||||
|
||||
this.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
// Retrieves the value for the given key, or undefined if it doesn't exist.
|
||||
|
|
|
@ -1,39 +1,26 @@
|
|||
var OS = require('../device/OS');
|
||||
|
||||
var isBooted = false;
|
||||
|
||||
/**
|
||||
* Inspects the readyState of the document. If the document is already complete then it invokes the given callback.
|
||||
* If not complete it sets up several event listeners such as `deviceready`, and once those fire, it invokes the callback.
|
||||
* Called automatically by the Phaser.Game instance. Should not usually be access directly.
|
||||
* Called automatically by the Phaser.Game instance. Should not usually be accessed directly.
|
||||
*
|
||||
* @function Phaser.Dom.DOMContentLoaded
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {function} callback - The callback to be invoked when the device is ready and the DOM content is loaded.
|
||||
*
|
||||
* @return {boolean} Returns `false` if the document is already loaded, otherwise `true` if the callback is pending.
|
||||
*/
|
||||
var DOMContentLoaded = function (callback)
|
||||
{
|
||||
if (isBooted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
||||
{
|
||||
isBooted = true;
|
||||
|
||||
callback();
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
var check = function ()
|
||||
{
|
||||
isBooted = true;
|
||||
|
||||
document.removeEventListener('deviceready', check, true);
|
||||
document.removeEventListener('DOMContentLoaded', check, true);
|
||||
window.removeEventListener('load', check, true);
|
||||
|
@ -55,8 +42,6 @@ var DOMContentLoaded = function (callback)
|
|||
document.addEventListener('DOMContentLoaded', check, true);
|
||||
window.addEventListener('load', check, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = DOMContentLoaded;
|
||||
|
|
|
@ -193,6 +193,8 @@ var InputManager = new Class({
|
|||
this.mouse.boot();
|
||||
this.touch.boot();
|
||||
this.gamepad.boot();
|
||||
|
||||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -500,6 +502,28 @@ var InputManager = new Class({
|
|||
getScaleY: function ()
|
||||
{
|
||||
return this.game.config.height / this.bounds.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.events.removeAllListeners();
|
||||
|
||||
this.keyboard.destroy();
|
||||
this.mouse.destroy();
|
||||
this.touch.destroy();
|
||||
this.gamepad.destroy();
|
||||
|
||||
this.activePointer.destroy();
|
||||
|
||||
this.queue = [];
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -584,6 +584,19 @@ var Pointer = new Class({
|
|||
forwardButtonDown: function ()
|
||||
{
|
||||
return (this.buttons & 16);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Pointer#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.camera = null;
|
||||
this.manager = null;
|
||||
this.position = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -339,6 +339,20 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.stopListeners();
|
||||
this.disconnectAll();
|
||||
|
||||
this.gamepads = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* The total number of connected game pads.
|
||||
*
|
||||
|
|
|
@ -402,6 +402,8 @@ var KeyboardManager = new Class({
|
|||
this.captures = [];
|
||||
this.queue = [];
|
||||
this.handler = undefined;
|
||||
|
||||
this.manager = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -267,6 +267,19 @@ var MouseManager = new Class({
|
|||
document.removeEventListener('mozpointerlockchange', this.pointerLockChange, true);
|
||||
document.removeEventListener('webkitpointerlockchange', this.pointerLockChange, true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Mouse.MouseManager#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.stopListeners();
|
||||
|
||||
this.manager = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -159,6 +159,19 @@ var TouchManager = new Class({
|
|||
target.removeEventListener('touchstart', this.handler);
|
||||
target.removeEventListener('touchmove', this.handler);
|
||||
target.removeEventListener('touchend', this.handler);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Touch.TouchManager#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.stopListeners();
|
||||
|
||||
this.manager = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ var PluginManager = new Class({
|
|||
|
||||
boot: function ()
|
||||
{
|
||||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
installGlobal: function (sys, globalPlugins)
|
||||
|
@ -88,7 +89,7 @@ var PluginManager = new Class({
|
|||
|
||||
destroy: function ()
|
||||
{
|
||||
plugins = {};
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -104,7 +104,6 @@ var CanvasRenderer = new Class({
|
|||
{
|
||||
},
|
||||
|
||||
|
||||
resetTransform: function ()
|
||||
{
|
||||
this.currentContext.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
@ -284,17 +283,14 @@ var CanvasRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Removes everything from the renderer and optionally removes the Canvas DOM element.
|
||||
*
|
||||
* @method destroy
|
||||
* @param [removegameCanvas=true] {boolean} Removes the Canvas element from the DOM.
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
// CanvasPool
|
||||
|
||||
this.gameCanvas = null;
|
||||
this.gameContext = null;
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -882,6 +882,14 @@ var WebGLRenderer = new Class({
|
|||
this.setProgram(program);
|
||||
this.gl.uniformMatrix4fv(this.gl.getUniformLocation(program, name), transpose, matrix);
|
||||
return this;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
// Clear-up anything that should be cleared :)
|
||||
this.contextLost = true;
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1070,7 +1070,20 @@ var SceneManager = new Class({
|
|||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
// TODO
|
||||
for (var i = this.scenes.length - 1; i >= 0; i--)
|
||||
{
|
||||
var sys = this.scenes[i].sys;
|
||||
|
||||
sys.destroy();
|
||||
}
|
||||
|
||||
this.scenes = [];
|
||||
|
||||
this._pending = [];
|
||||
this._start = [];
|
||||
this._queue = [];
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -219,6 +219,9 @@ var Systems = new Class({
|
|||
{
|
||||
this.settings.status = CONST.DESTROYED;
|
||||
|
||||
this.settings.active = false;
|
||||
this.settings.visible = false;
|
||||
|
||||
this.events.emit('destroy', this);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,8 @@ var BaseSoundManager = new Class({
|
|||
}
|
||||
}, this);
|
||||
|
||||
game.events.once('destroy', this.destroy, this);
|
||||
|
||||
/**
|
||||
* Property that actually holds the value of global playback rate.
|
||||
*
|
||||
|
@ -409,14 +411,17 @@ var BaseSoundManager = new Class({
|
|||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.game = null;
|
||||
this.removeAllListeners();
|
||||
|
||||
this.forEachActiveSound(function (sound)
|
||||
{
|
||||
sound.destroy();
|
||||
});
|
||||
|
||||
this.sounds.length = 0;
|
||||
this.sounds = null;
|
||||
|
||||
this.game = null;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -302,6 +302,9 @@ var Frame = new Class({
|
|||
|
||||
destroy: function ()
|
||||
{
|
||||
this.texture = null;
|
||||
|
||||
this.source = null;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -191,12 +191,14 @@ var Texture = new Class({
|
|||
|
||||
setFilter: function (filterMode)
|
||||
{
|
||||
for (var i = 0; i < this.source.length; i++)
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.source.length; i++)
|
||||
{
|
||||
this.source[i].setFilter(filterMode);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.dataSource.length; i++)
|
||||
for (i = 0; i < this.dataSource.length; i++)
|
||||
{
|
||||
this.dataSource[i].setFilter(filterMode);
|
||||
}
|
||||
|
@ -204,6 +206,28 @@ var Texture = new Class({
|
|||
|
||||
destroy: function ()
|
||||
{
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.source.length; i++)
|
||||
{
|
||||
this.source[i].destroy();
|
||||
}
|
||||
|
||||
for (i = 0; i < this.dataSource.length; i++)
|
||||
{
|
||||
this.dataSource[i].destroy();
|
||||
}
|
||||
|
||||
for (var frameName in this.frames)
|
||||
{
|
||||
var frame = this.frames[frameName];
|
||||
|
||||
frame.destroy();
|
||||
}
|
||||
|
||||
this.source = [];
|
||||
this.dataSource = [];
|
||||
this.frames = {};
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -48,6 +48,8 @@ var TextureManager = new Class({
|
|||
|
||||
this.addBase64('__DEFAULT', this.game.config.defaultImage);
|
||||
this.addBase64('__MISSING', this.game.config.missingImage);
|
||||
|
||||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
updatePending: function ()
|
||||
|
@ -410,6 +412,18 @@ var TextureManager = new Class({
|
|||
|
||||
callback.apply(thisArg, args);
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
for (var texture in this.list)
|
||||
{
|
||||
this.list[texture].destroy();
|
||||
}
|
||||
|
||||
this.list = {};
|
||||
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -55,6 +55,13 @@ var TextureSource = new Class({
|
|||
{
|
||||
game.renderer.setTextureFilter(this.glTexture, filterMode);
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.texture = null;
|
||||
|
||||
this.image = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue