kopia lustrzana https://github.com/robhawkes/vizicities
Improve memory cleanup
rodzic
42708a7610
commit
2a899feaa7
|
@ -341,7 +341,21 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
// Remove layer and perform clean up operations
|
||||
}, {
|
||||
key: 'removeLayer',
|
||||
value: function removeLayer(layer) {}
|
||||
value: function removeLayer(layer) {
|
||||
var layerIndex = this._layers.indexOf(layer);
|
||||
|
||||
if (layerIndex > -1) {
|
||||
// Remove from this._layers
|
||||
this._layers.splice(layerIndex, 1);
|
||||
};
|
||||
|
||||
this._engine._scene.remove(layer._layer);
|
||||
|
||||
layer.destroy();
|
||||
|
||||
this.emit('layerRemoved');
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: 'addControls',
|
||||
value: function addControls(controls) {
|
||||
|
@ -4598,6 +4612,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
this._onAdd(world);
|
||||
this.emit('added');
|
||||
}
|
||||
|
||||
// Destroys the layer and removes it from the scene and memory
|
||||
}, {
|
||||
key: 'destroy',
|
||||
value: function destroy() {
|
||||
this._world = null;
|
||||
this._layer = null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Layer;
|
||||
|
@ -4750,10 +4772,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
// Run LOD calculations based on render calls
|
||||
//
|
||||
// Throttled to 1 LOD calculation per 100ms
|
||||
this._throttledWorldUpdate = (0, _lodashThrottle2['default'])(this._onWorldUpdate, 100).bind(this);
|
||||
this._throttledWorldUpdate = (0, _lodashThrottle2['default'])(this._onWorldUpdate, 100);
|
||||
|
||||
this._world.on('preUpdate', this._throttledWorldUpdate);
|
||||
this._world.on('move', this._onWorldMove.bind(this));
|
||||
this._world.on('preUpdate', this._throttledWorldUpdate, this);
|
||||
this._world.on('move', this._onWorldMove, this);
|
||||
}
|
||||
}, {
|
||||
key: '_onWorldUpdate',
|
||||
|
@ -4964,6 +4986,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
this._world.off('preUpdate', this._throttledWorldUpdate);
|
||||
this._world.off('move', this._onWorldMove);
|
||||
|
||||
this._throttledWorldUpdate = null;
|
||||
|
||||
for (var i = this._layer.children.length - 1; i >= 0; i--) {
|
||||
this._layer.remove(this._layer.children[i]);
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
16
src/World.js
16
src/World.js
|
@ -170,7 +170,21 @@ class World extends EventEmitter {
|
|||
}
|
||||
|
||||
// Remove layer and perform clean up operations
|
||||
removeLayer(layer) {}
|
||||
removeLayer(layer) {
|
||||
var layerIndex = this._layers.indexOf(layer);
|
||||
|
||||
if (layerIndex > -1) {
|
||||
// Remove from this._layers
|
||||
this._layers.splice(layerIndex, 1);
|
||||
};
|
||||
|
||||
this._engine._scene.remove(layer._layer);
|
||||
|
||||
layer.destroy();
|
||||
|
||||
this.emit('layerRemoved');
|
||||
return this;
|
||||
}
|
||||
|
||||
addControls(controls) {
|
||||
controls._addToWorld(this);
|
||||
|
|
|
@ -21,6 +21,12 @@ class Layer extends EventEmitter {
|
|||
this._onAdd(world);
|
||||
this.emit('added');
|
||||
}
|
||||
|
||||
// Destroys the layer and removes it from the scene and memory
|
||||
destroy() {
|
||||
this._world = null;
|
||||
this._layer = null;
|
||||
}
|
||||
}
|
||||
|
||||
export default Layer;
|
||||
|
|
|
@ -97,10 +97,10 @@ class GridLayer extends Layer {
|
|||
// Run LOD calculations based on render calls
|
||||
//
|
||||
// Throttled to 1 LOD calculation per 100ms
|
||||
this._throttledWorldUpdate = throttle(this._onWorldUpdate, 100).bind(this);
|
||||
this._throttledWorldUpdate = throttle(this._onWorldUpdate, 100);
|
||||
|
||||
this._world.on('preUpdate', this._throttledWorldUpdate);
|
||||
this._world.on('move', this._onWorldMove.bind(this));
|
||||
this._world.on('preUpdate', this._throttledWorldUpdate, this);
|
||||
this._world.on('move', this._onWorldMove, this);
|
||||
}
|
||||
|
||||
_onWorldUpdate() {
|
||||
|
@ -297,6 +297,8 @@ class GridLayer extends Layer {
|
|||
this._world.off('preUpdate', this._throttledWorldUpdate);
|
||||
this._world.off('move', this._onWorldMove);
|
||||
|
||||
this._throttledWorldUpdate = null;
|
||||
|
||||
for (var i = this._layer.children.length - 1; i >= 0; i--) {
|
||||
this._layer.remove(this._layer.children[i]);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue