Tidied up existing destroy methods and added new one to world

master
Robin Hawkes 2016-02-29 09:17:22 +00:00
rodzic 3d6e7a3b6f
commit f343b64f0f
8 zmienionych plików z 304 dodań i 68 usunięć

183
dist/vizicities.js vendored
Wyświetl plik

@ -189,6 +189,8 @@ return /******/ (function(modules) { // webpackBootstrap
this._initEnvironment();
this._initEvents();
this._pause = false;
// Kick off the update and render loop
this._update();
}
@ -265,6 +267,10 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_update',
value: function _update() {
if (this._pause) {
return;
}
var delta = this._engine.clock.getDelta();
// Once _update is called it will run forever, for now
@ -398,7 +404,7 @@ return /******/ (function(modules) { // webpackBootstrap
return this;
}
// Remove layer and perform clean up operations
// Remove layer from world and scene but don't destroy it entirely
}, {
key: 'removeLayer',
value: function removeLayer(layer) {
@ -411,8 +417,6 @@ return /******/ (function(modules) { // webpackBootstrap
this._engine._scene.remove(layer._layer);
layer.destroy();
this.emit('layerRemoved');
return this;
}
@ -426,9 +430,67 @@ return /******/ (function(modules) { // webpackBootstrap
this.emit('controlsAdded', controls);
return this;
}
// Remove controls from world but don't destroy them entirely
}, {
key: 'removeControls',
value: function removeControls(controls) {}
value: function removeControls(controls) {
var controlsIndex = this._controls.indexOf(controlsIndex);
if (controlsIndex > -1) {
this._controls.splice(controlsIndex, 1);
};
this.emit('controlsRemoved', controls);
return this;
}
}, {
key: 'stop',
value: function stop() {
this._pause = true;
}
}, {
key: 'start',
value: function start() {
this._pause = false;
this._update();
}
// Destroys the world(!) and removes it from the scene and memory
}, {
key: 'destroy',
value: function destroy() {
this.stop();
// Remove listeners
this.off('controlsMoveEnd', this._onControlsMoveEnd);
var i;
// Remove all controls
var controls;
for (i = this._controls.length - 1; i >= 0; i--) {
controls = this._controls[0];
this.removeControls(controls);
controls.destroy();
};
// Remove all layers
var layer;
for (i = this._layers.length - 1; i >= 0; i--) {
layer = this._layers[0];
this.removeLayer(layer);
layer.destroy();
};
// Environment layer is removed with the other layers
this._environment = null;
this._engine = null;
// TODO: Probably should clean the container too / remove the canvas
this._container = null;
}
}]);
return World;
@ -3088,6 +3150,43 @@ return /******/ (function(modules) { // webpackBootstrap
this._renderer.render(this._scene, this._camera);
this.emit('postRender');
}
}, {
key: 'destroy',
value: function destroy() {
// Remove any remaining objects from scene
var child;
for (i = this._scene.children.length - 1; i >= 0; i--) {
child = this._scene.children[i];
if (!child) {
continue;
}
this._scene.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
}
child.material.dispose();
child.material = null;
}
};
this._scene = null;
this._renderer = null;
this._camera = null;
this._clock = null;
this._frustum = null;
}
}]);
return Engine;
@ -3400,6 +3499,18 @@ return /******/ (function(modules) { // webpackBootstrap
this.emit('added');
}
// Destroys the controls and removes them from memory
}, {
key: 'destroy',
value: function destroy() {
// TODO: Remove event listeners
this._controls.dispose();
this._world = null;
this._controls = null;
}
}]);
return Orbit;
@ -7408,31 +7519,33 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'destroy',
value: function destroy() {
// Remove everything else in the layer
var child;
for (i = this._layer.children.length - 1; i >= 0; i--) {
child = this._layer.children[i];
if (this._layer.children) {
// Remove everything else in the layer
var child;
for (var i = this._layer.children.length - 1; i >= 0; i--) {
child = this._layer.children[i];
if (!child) {
continue;
}
this.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
if (!child) {
continue;
}
child.material.dispose();
child.material = null;
this.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
}
child.material.dispose();
child.material = null;
}
}
}
@ -8540,6 +8653,10 @@ return /******/ (function(modules) { // webpackBootstrap
value: function _outputTiles() {
var _this2 = this;
if (!this._tiles) {
return;
}
// Remove all tiles from layer
this._removeTiles();
@ -8719,6 +8836,10 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_removeTiles',
value: function _removeTiles() {
if (!this._tiles || !this._tiles.children) {
return;
}
for (var i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
}
@ -8762,11 +8883,11 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'destroy',
value: function destroy() {
var i;
// Remove all tiles
for (i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
if (this._tiles.children) {
// Remove all tiles
for (var i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
}
}
this._tileCache.destroy();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -23,6 +23,42 @@ class Engine extends EventEmitter {
this._renderer.render(this._scene, this._camera);
this.emit('postRender');
}
destroy() {
// Remove any remaining objects from scene
var child;
for (i = this._scene.children.length - 1; i >= 0; i--) {
child = this._scene.children[i];
if (!child) {
continue;
}
this._scene.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
}
child.material.dispose();
child.material = null;
}
};
this._scene = null;
this._renderer = null;
this._camera = null;
this._clock = null;
this._frustum = null;
}
}
// Initialise without requiring new keyword

Wyświetl plik

@ -29,6 +29,8 @@ class World extends EventEmitter {
this._initEnvironment();
this._initEvents();
this._pause = false;
// Kick off the update and render loop
this._update();
}
@ -90,6 +92,10 @@ class World extends EventEmitter {
}
_update() {
if (this._pause) {
return;
}
var delta = this._engine.clock.getDelta();
// Once _update is called it will run forever, for now
@ -202,7 +208,7 @@ class World extends EventEmitter {
return this;
}
// Remove layer and perform clean up operations
// Remove layer from world and scene but don't destroy it entirely
removeLayer(layer) {
var layerIndex = this._layers.indexOf(layer);
@ -213,8 +219,6 @@ class World extends EventEmitter {
this._engine._scene.remove(layer._layer);
layer.destroy();
this.emit('layerRemoved');
return this;
}
@ -228,7 +232,62 @@ class World extends EventEmitter {
return this;
}
removeControls(controls) {}
// Remove controls from world but don't destroy them entirely
removeControls(controls) {
var controlsIndex = this._controls.indexOf(controlsIndex);
if (controlsIndex > -1) {
this._controls.splice(controlsIndex, 1);
};
this.emit('controlsRemoved', controls);
return this;
}
stop() {
this._pause = true;
}
start() {
this._pause = false;
this._update();
}
// Destroys the world(!) and removes it from the scene and memory
//
// TODO: World out why so much three.js stuff is left in the heap after this
destroy() {
this.stop();
// Remove listeners
this.off('controlsMoveEnd', this._onControlsMoveEnd);
var i;
// Remove all controls
var controls;
for (i = this._controls.length - 1; i >= 0; i--) {
controls = this._controls[0];
this.removeControls(controls);
controls.destroy();
};
// Remove all layers
var layer;
for (i = this._layers.length - 1; i >= 0; i--) {
layer = this._layers[0];
this.removeLayer(layer);
layer.destroy();
};
// Environment layer is removed with the other layers
this._environment = null;
this._engine = null;
// TODO: Probably should clean the container too / remove the canvas
this._container = null;
}
}
// Initialise without requiring new keyword

Wyświetl plik

@ -86,6 +86,16 @@ class Orbit extends EventEmitter {
this.emit('added');
}
// Destroys the controls and removes them from memory
destroy() {
// TODO: Remove event listeners
this._controls.dispose();
this._world = null;
this._controls = null;
}
}
// Initialise without requiring new keyword

Wyświetl plik

@ -36,31 +36,33 @@ class Layer extends EventEmitter {
// Destroys the layer and removes it from the scene and memory
destroy() {
// Remove everything else in the layer
var child;
for (i = this._layer.children.length - 1; i >= 0; i--) {
child = this._layer.children[i];
if (this._layer.children) {
// Remove everything else in the layer
var child;
for (var i = this._layer.children.length - 1; i >= 0; i--) {
child = this._layer.children[i];
if (!child) {
continue;
}
this.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
if (!child) {
continue;
}
child.material.dispose();
child.material = null;
this.remove(child);
if (child.geometry) {
// Dispose of mesh and materials
child.geometry.dispose();
child.geometry = null;
}
if (child.material) {
if (child.material.map) {
child.material.map.dispose();
child.material.map = null;
}
child.material.dispose();
child.material = null;
}
}
}

Wyświetl plik

@ -91,6 +91,10 @@ class TileLayer extends Layer {
// Update and output tiles from the previous LOD checklist
_outputTiles() {
if (!this._tiles) {
return;
}
// Remove all tiles from layer
this._removeTiles();
@ -263,6 +267,10 @@ class TileLayer extends Layer {
}
_removeTiles() {
if (!this._tiles || !this._tiles.children) {
return;
}
for (var i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
}
@ -299,11 +307,11 @@ class TileLayer extends Layer {
// Destroys the layer and removes it from the scene and memory
destroy() {
var i;
// Remove all tiles
for (i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
if (this._tiles.children) {
// Remove all tiles
for (var i = this._tiles.children.length - 1; i >= 0; i--) {
this._tiles.remove(this._tiles.children[i]);
}
}
this._tileCache.destroy();