105 lines
2.1 KiB
JavaScript
105 lines
2.1 KiB
JavaScript
/**
|
|
* Creates a camera object
|
|
* @param implementation
|
|
* @param apiClock GameLib.API.Clock
|
|
* @constructor
|
|
*/
|
|
GameLib.Clock = function(
|
|
implementation,
|
|
apiClock
|
|
) {
|
|
|
|
this.implementation = implementation;
|
|
this.implementation.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiClock)) {
|
|
apiClock = {};
|
|
}
|
|
|
|
if (apiClock instanceof GameLib.Clock) {
|
|
return apiClock;
|
|
}
|
|
|
|
GameLib.API.Clock.call(
|
|
this,
|
|
apiClock.id,
|
|
apiClock.name,
|
|
apiClock.parentEntity
|
|
);
|
|
|
|
GameLib.Component.call(
|
|
this,
|
|
GameLib.Component.COMPONENT_CLOCK
|
|
);
|
|
|
|
} ;
|
|
|
|
GameLib.Clock.prototype = Object.create(GameLib.API.Clock.prototype);
|
|
GameLib.Clock.prototype.constructor = GameLib.Clock;
|
|
|
|
/**
|
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
|
* @returns {THREE.Clock}
|
|
*/
|
|
GameLib.Clock.prototype.createInstance = function() {
|
|
|
|
this.instance = new THREE.Clock();
|
|
|
|
GameLib.Component.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
GameLib.Clock.prototype.updateInstance = function() {
|
|
|
|
};
|
|
|
|
GameLib.Clock.prototype.getDelta = function() {
|
|
|
|
var delta = this.instance.getDelta();
|
|
|
|
/**
|
|
* clamp the delta to 1/60
|
|
*/
|
|
|
|
if (delta > (1 / 30.0)) {
|
|
// console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time');
|
|
delta = (1 / 30.0);
|
|
}
|
|
|
|
return delta;
|
|
};
|
|
|
|
/**
|
|
* Converts a GameLib.Clock to a new GameLib.API.Clock
|
|
* @returns {GameLib.API.Clock}
|
|
*/
|
|
GameLib.Clock.prototype.toApiObject = function() {
|
|
|
|
return new GameLib.API.Clock(
|
|
this.id,
|
|
this.name,
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
);
|
|
|
|
};
|
|
|
|
/**
|
|
* Converts from an Object camera to a GameLib.Clock
|
|
* @param graphics GameLib.Graphics
|
|
* @param objectClock Object
|
|
* @returns {GameLib.Clock}
|
|
* @constructor
|
|
*/
|
|
GameLib.Clock.FromObject = function(graphics, objectClock) {
|
|
|
|
var apiClock = GameLib.API.Clock.FromObject(objectClock);
|
|
|
|
return new GameLib.Clock(
|
|
graphics,
|
|
apiClock
|
|
);
|
|
|
|
};
|