Skip to content

Commit

Permalink
Added pc.Application#destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalpias committed Jun 4, 2015
1 parent 01d4754 commit 413f0ae
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/core_fullscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
Element.prototype.requestFullscreen = Element.prototype.requestFullscreen ||
Element.prototype.webkitRequestFullscreen ||
Element.prototype.msRequestFullscreen ||
function () {};
function () {};
}
document.exitFullscreen = document.exitFullscreen ||
document.webkitExitFullscreen ||
document.mozCancelFullScreen ||
document.msExitFullscreen;
if (!document.fullscreenElement) {
if (!document.hasOwnProperty('fullscreenElement')) {
Object.defineProperty(document, 'fullscreenElement', {
enumerable: true,
configurable: false,
enumerable: true,
configurable: false,
get: function () {
return document.webkitCurrentFullScreenElement ||
document.webkitFullscreenElement ||
Expand All @@ -53,7 +53,7 @@
});
}

if (!document.fullscreenEnabled) {
if (!document.hasOwnProperty('fullscreenEnabled')) {
Object.defineProperty(document, 'fullscreenEnabled', {
enumerable: true,
configurable: false,
Expand Down
10 changes: 10 additions & 0 deletions src/framework/components/component_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,21 @@ pc.extend(pc, function () {
component.onEnable();
}
}

};

// Add event support
pc.events.attach(ComponentSystem);

ComponentSystem.destroy = function () {
ComponentSystem.off('initialize');
ComponentSystem.off('postInitialize');
ComponentSystem.off('toolsUpdate');
ComponentSystem.off('update');
ComponentSystem.off('fixedUpdate');
ComponentSystem.off('postUpdate');
};

return {
ComponentSystem: ComponentSystem
};
Expand Down
68 changes: 68 additions & 0 deletions src/framework/framework_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ pc.extend(pc, function () {
* the next tick. Override this if you have a custom Application.
*/
tick: function () {
if (!this.graphicsDevice) {
return;
}

Application._currentApplication = this;

// Submit a request to queue up a new animation frame immediately
Expand Down Expand Up @@ -776,6 +780,70 @@ pc.extend(pc, function () {
} else {
self.scene.setSkybox(null);
}
},

/**
* @function
* @name pc.Application#destroy
* @description Destroys application and removes all event listeners
*/
destroy: function () {
Application._applications[this.graphicsDevice.canvas.id] = null;

this.off('librariesloaded');
document.removeEventListener('visibilitychange');
document.removeEventListener('mozvisibilitychange');
document.removeEventListener('msvisibilitychange');
document.removeEventListener('webkitvisibilitychange');

if (this.mouse) {
this.mouse.off('mouseup');
this.mouse.off('mousedown');
this.mouse.off('mousewheel');
this.mouse.off('mousemove');

this.mouse = null;
}

if (this.keyboard) {
this.keyboard.off("keydown");
this.keyboard.off("keyup");
this.keyboard.off("keypress");

this.keyboard = null;
}

if (this.touch) {
this.touch.off('touchstart');
this.touch.off('touchend');
this.touch.off('touchmove');
this.touch.off('touchcancel');

this.touch = null;
}

if (this.controller) {
this.controller = null;
}

this.root.destroy();

pc.ComponentSystem.destroy();

this.loader.destroy();
this.loader = null;

this.scene = null;

this.systems = [];
this.context = null;

this.graphicsDevice = null;

this.renderer = null;
this._audioManager = null;

pc.net.http = new pc.net.Http();
}
};

Expand Down
11 changes: 11 additions & 0 deletions src/resources/resources_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ pc.extend(pc, function () {
if (this._cache[url + type]) {
return this._cache[url + type];
}
},

/**
* @function
* @name pc.ResourceLoader#destroy
* @description Destroys resource loader
*/
destroy: function () {
this._handlers = {};
this._requests = {};
this._cache = {};
}
};

Expand Down

0 comments on commit 413f0ae

Please sign in to comment.