r3-legacy/bak/game-lib-d3-broadphase.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-10-14 12:32:53 +02:00
/**
* Physics Broadphase Superset
* @param id
2016-10-14 13:08:22 +02:00
* @param name String
* @param broadphaseType Number
* @param engine GameLib.D3.Engine
2016-10-14 12:32:53 +02:00
* @constructor
*/
2016-11-21 16:08:39 +01:00
GameLib.D3.Broadphase = function Broadphase(
2016-10-14 12:32:53 +02:00
id,
name,
2016-10-14 13:08:22 +02:00
broadphaseType,
2016-10-31 09:30:03 +01:00
engine
2016-10-14 12:32:53 +02:00
) {
this.id = id;
if (typeof name == 'undefined') {
name = 'broadphase-' + broadphaseType;
}
this.name = name;
if (typeof broadphaseType == 'undefined') {
2016-10-14 13:08:22 +02:00
broadphaseType = GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE;
2016-10-14 12:32:53 +02:00
}
this.broadphaseType = broadphaseType;
2016-10-14 13:08:22 +02:00
this.engine = engine;
2016-10-31 09:30:03 +01:00
this.engine.isNotCannonThrow();
2016-10-14 13:08:22 +02:00
2016-10-31 09:30:03 +01:00
this.instance = this.createInstance();
2016-10-14 13:08:22 +02:00
};
/**
* 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) {
2016-10-31 09:30:03 +01:00
instance = new this.engine.instance.SAPBroadphase();
2016-10-14 13:08:22 +02:00
} else {
console.warn('Unsupported broadphase type: ' + this.broadphaseType);
throw new Error('Unsupported broadphase type: ' + this.broadphaseType);
}
return instance;
2016-10-14 12:32:53 +02:00
};
2016-12-09 20:32:09 +01:00
GameLib.D3.Broadphase.prototype.toApiBroadphase = function() {
return null;
};
2016-10-14 12:32:53 +02:00
/**
* 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;