/** * Physics Broadphase Superset * @param id * @param name String * @param broadphaseType Number * @param engine GameLib.D3.Engine * @constructor */ GameLib.D3.Broadphase = function Broadphase( id, name, broadphaseType, engine ) { this.id = id; if (typeof name == 'undefined') { name = 'broadphase-' + broadphaseType; } this.name = name; if (typeof broadphaseType == 'undefined') { broadphaseType = GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE; } this.broadphaseType = broadphaseType; this.engine = engine; this.engine.isNotCannonThrow(); this.instance = this.createInstance(); }; /** * Creates a custom Broadphase instance based on the engine type */ GameLib.D3.Broadphase.prototype.createInstance = function() { var instance = null; if (this.broadphaseType == GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) { instance = new this.engine.instance.NaiveBroadphase(); } else if (this.broadphaseType == GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID) { instance = new this.engine.instance.GridBroadphase(); } else if (this.broadphaseType == GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP) { instance = new this.engine.instance.SAPBroadphase(); } else { console.warn('Unsupported broadphase type: ' + this.broadphaseType); throw new Error('Unsupported broadphase type: ' + this.broadphaseType); } return instance; }; GameLib.D3.Broadphase.prototype.toApiBroadphase = function() { return null; }; /** * Broadphase Types * @type {number} */ GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE = 0x1; GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID = 0x2; GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP = 0x3;