diff --git a/EndGate/EndGate.Core.JS/Collision/CollisionManager.js b/EndGate/EndGate.Core.JS/Collision/CollisionManager.js index c52b91e6..9f656005 100644 --- a/EndGate/EndGate.Core.JS/Collision/CollisionManager.js +++ b/EndGate/EndGate.Core.JS/Collision/CollisionManager.js @@ -1,6 +1,7 @@ var EndGate; (function (EndGate) { /// + /// /// /// /// @@ -22,6 +23,7 @@ var EndGate; this._nonStaticCollidables = []; this._quadTree = new Collision.Assets._.QuadTree(configuration); this._enabled = false; + this._disposed = false; this._onCollision = new EndGate.EventHandler2(); } Object.defineProperty(CollisionManager.prototype, "OnCollision", { @@ -120,6 +122,25 @@ var EndGate; } }; + /** + * Destroys removes all monitored collidables and destroys the collision manager. + */ + CollisionManager.prototype.Dispose = function () { + if (!this._disposed) { + this._disposed = true; + + for (var i = 0; i < this._collidables.length; i++) { + this.Unmonitor(this._collidables[i].Collidable); + } + + this._collidables = []; + this._nonStaticCollidables = []; + this._quadTree = null; + } else { + throw new Error("CollisionManager cannot be disposed more than once"); + } + }; + CollisionManager.prototype.HashIds = function (c1, c2) { return Math.min(c1._id, c2._id).toString() + Math.max(c2._id, c1._id).toString(); }; diff --git a/EndGate/EndGate.Core.JS/Collision/CollisionManager.ts b/EndGate/EndGate.Core.JS/Collision/CollisionManager.ts index a39a3add..412f265a 100644 --- a/EndGate/EndGate.Core.JS/Collision/CollisionManager.ts +++ b/EndGate/EndGate.Core.JS/Collision/CollisionManager.ts @@ -1,4 +1,5 @@ /// +/// /// /// /// @@ -17,13 +18,14 @@ module EndGate.Collision { /** * Defines a manager that will check for collisions between objects that it is monitoring. */ - export class CollisionManager implements IUpdateable, EndGate._.ITyped { + export class CollisionManager implements IUpdateable, IDisposable, EndGate._.ITyped { public _type: string = "CollisionManager"; private _collidables: ICollidableMappings[]; private _nonStaticCollidables: Collidable[]; public _quadTree: Assets._.QuadTree; private _onCollision: EventHandler2; private _enabled: boolean; + private _disposed: boolean; /** * Creates a new instance of CollisionManager. @@ -33,6 +35,7 @@ module EndGate.Collision { this._nonStaticCollidables = []; this._quadTree = new Assets._.QuadTree(configuration); this._enabled = false; + this._disposed = false; this._onCollision = new EventHandler2(); } @@ -147,6 +150,26 @@ module EndGate.Collision { } } + /** + * Destroys removes all monitored collidables and destroys the collision manager. + */ + public Dispose(): void { + if (!this._disposed) { + this._disposed = true; + + for (var i = 0; i < this._collidables.length; i++) { + this.Unmonitor(this._collidables[i].Collidable); + } + + this._collidables = []; + this._nonStaticCollidables = []; + this._quadTree = null; + } + else { + throw new Error("CollisionManager cannot be disposed more than once"); + } + } + private HashIds(c1: Collidable, c2: Collidable): string { return Math.min(c1._id, c2._id).toString() + Math.max(c2._id, c1._id).toString(); } diff --git a/EndGate/EndGate.Core.JS/Game.js b/EndGate/EndGate.Core.JS/Game.js index ff6188bf..8185c90a 100644 --- a/EndGate/EndGate.Core.JS/Game.js +++ b/EndGate/EndGate.Core.JS/Game.js @@ -82,6 +82,7 @@ var EndGate; Game.prototype.Dispose = function () { this.Scene.Dispose(); this.Map.Dispose(); + this.CollisionManager.Dispose(); GameRunnerInstance.Unregister(this); }; Game._gameIds = 0; diff --git a/EndGate/EndGate.Core.JS/Game.ts b/EndGate/EndGate.Core.JS/Game.ts index ed9d9aea..dd29304d 100644 --- a/EndGate/EndGate.Core.JS/Game.ts +++ b/EndGate/EndGate.Core.JS/Game.ts @@ -126,6 +126,7 @@ module EndGate { public Dispose(): void { this.Scene.Dispose(); this.Map.Dispose(); + this.CollisionManager.Dispose(); GameRunnerInstance.Unregister(this); } }