/** * Broadphase Runtime * @param physics GameLib.D3.Graphics * @param apiBroadphase GameLib.D3.API.Broadphase * @constructor */ GameLib.D3.Broadphase = function ( physics, apiBroadphase ) { this.physics = physics; this.physics.isNotCannonThrow(); if (GameLib.Utils.UndefinedOrNull(apiBroadphase)) { apiBroadphase = {}; } if (apiBroadphase instanceof GameLib.D3.Broadphase) { return apiBroadphase; } GameLib.D3.API.Broadphase.call( this, apiBroadphase.id, apiBroadphase.name, apiBroadphase.broadphaseType, apiBroadphase.parentEntity ); GameLib.Component.call( this, GameLib.Component.COMPONENT_BROADPHASE, { } ); }; GameLib.D3.Broadphase.prototype = Object.create(GameLib.D3.API.Broadphase.prototype); GameLib.D3.Broadphase.prototype.constructor = GameLib.D3.Broadphase; /** * * @returns {*} */ GameLib.D3.Broadphase.prototype.createInstance = function() { //todo 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.updateInstance = function() { //todo }; /** * GameLib.D3.Broadphase to GameLib.D3.API.Broadphase * @returns {GameLib.D3.API.Broadphase} */ GameLib.D3.Broadphase.prototype.toApiObject = function() { var apiBroadphase = new GameLib.D3.API.Broadphase( this.id, this.name, this.broadphaseType, GameLib.Utils.IdOrNull(this.parentEntity) ); return apiBroadphase; }; /** * GameLib.D3.Broadphase from Object Broadphase * @param graphics * @param objectComponent * @returns {GameLib.D3.Broadphase} * @constructor */ GameLib.D3.Broadphase.FromObject = function(graphics, objectComponent) { var apiBroadphase = GameLib.D3.API.Broadphase.FromObject(objectComponent); return new GameLib.D3.Broadphase( graphics, apiBroadphase ); }; /** * 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;