111 lines
2.3 KiB
JavaScript
111 lines
2.3 KiB
JavaScript
|
/**
|
||
|
* Game Runtime
|
||
|
* @param graphics GameLib.D3.Graphics
|
||
|
* @param apiGame GameLib.D3.API.Game
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.Game = function (
|
||
|
graphics,
|
||
|
apiGame
|
||
|
) {
|
||
|
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
GameLib.D3.API.Game.call(
|
||
|
this,
|
||
|
apiGame.id,
|
||
|
apiGame.name,
|
||
|
apiGame.gameType,
|
||
|
apiGame.width,
|
||
|
apiGame.height,
|
||
|
apiGame.scenes,
|
||
|
apiGame.cameras,
|
||
|
apiGame.renderers,
|
||
|
apiGame.composers,
|
||
|
apiGame.systems,
|
||
|
apiGame.entityManager,
|
||
|
apiGame.mouse,
|
||
|
apiGame.raycaster,
|
||
|
apiGame.activeCameraIndex,
|
||
|
apiGame.activeRendererIndex,
|
||
|
apiGame.parentEntity
|
||
|
);
|
||
|
|
||
|
this.scenes = this.scenes.map(
|
||
|
function(apiScene) {
|
||
|
return GameLib.D3.Scene(
|
||
|
this.graphics,
|
||
|
apiScene
|
||
|
)
|
||
|
}.bind(this)
|
||
|
);
|
||
|
|
||
|
this.entityManager.entities.map(
|
||
|
function (entity) {
|
||
|
this.idToObject[entity.id] = entity;
|
||
|
entity.components.map(
|
||
|
function(component) {
|
||
|
if (component instanceof GameLib.Component) {
|
||
|
this.idToObject[component.id] = component;
|
||
|
}
|
||
|
}.bind(this)
|
||
|
)
|
||
|
}.bind(this)
|
||
|
);
|
||
|
|
||
|
this.entityManager.linkObjects(this.idToObject);
|
||
|
|
||
|
this.scenes = {};
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Game.GAME_TYPE_VR_PONG = 0x1;
|
||
|
GameLib.D3.Game.GAME_TYPE_VR_RACER = 0x2;
|
||
|
|
||
|
GameLib.D3.Game.prototype.addScene = function(
|
||
|
scene,
|
||
|
identifer
|
||
|
) {
|
||
|
this.scenes[identifer] = scene;
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Game.prototype.processPhysics = function (
|
||
|
dt
|
||
|
) {
|
||
|
for(var s in this.scenes) {
|
||
|
var scene = this.scenes[s];
|
||
|
|
||
|
for(var w in scene.worlds) {
|
||
|
var world = scene.worlds[w];
|
||
|
world.step(dt);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Game.prototype.render = function(
|
||
|
dt,
|
||
|
renderer
|
||
|
) {
|
||
|
for(var s in this.scenes) {
|
||
|
var scene = this.scenes[s];
|
||
|
scene.render(dt, renderer);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Game.prototype.update = function(
|
||
|
dt,
|
||
|
fixedDt
|
||
|
) {
|
||
|
for(var s in this.scenes) {
|
||
|
var scene = this.scenes[s];
|
||
|
|
||
|
for(var w in scene.worlds) {
|
||
|
var world = scene.worlds[w];
|
||
|
// NOTE: We are calling the step function with a variable timestep!
|
||
|
world.step(fixedDt, dt);
|
||
|
}
|
||
|
|
||
|
scene.update(dt);
|
||
|
scene.lateUpdate(dt);
|
||
|
}
|
||
|
};
|