2017-01-12 04:44:01 +01:00
|
|
|
/**
|
|
|
|
* System takes care of updating all the entities (based on their component data)
|
2017-06-24 18:09:44 +02:00
|
|
|
* @param implementation
|
2017-01-12 04:44:01 +01:00
|
|
|
* @param apiSystem GameLib.API.System
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.System = function(
|
2017-01-20 13:40:27 +01:00
|
|
|
apiSystem
|
2017-01-12 04:44:01 +01:00
|
|
|
) {
|
|
|
|
|
2017-01-20 13:40:27 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiSystem)) {
|
|
|
|
apiSystem = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiSystem instanceof GameLib.System) {
|
|
|
|
return apiSystem;
|
|
|
|
}
|
|
|
|
|
2017-01-20 13:40:27 +01:00
|
|
|
GameLib.API.System.call(
|
2017-01-12 04:44:01 +01:00
|
|
|
this,
|
|
|
|
apiSystem.id,
|
|
|
|
apiSystem.name,
|
|
|
|
apiSystem.systemType,
|
|
|
|
apiSystem.parentEntity
|
|
|
|
);
|
|
|
|
|
2017-06-16 15:49:53 +02:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_SYSTEM
|
|
|
|
);
|
|
|
|
|
2017-01-12 04:44:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.prototype = Object.create(GameLib.API.System.prototype);
|
|
|
|
GameLib.System.prototype.constructor = GameLib.System;
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
GameLib.System.SYSTEM_TYPE_NONE = 0x0;
|
2017-01-12 17:40:17 +01:00
|
|
|
GameLib.System.SYSTEM_TYPE_RENDER = 0x1;
|
|
|
|
GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
|
|
|
|
GameLib.System.SYSTEM_TYPE_INPUT = 0x4;
|
2017-05-16 11:50:06 +02:00
|
|
|
GameLib.System.SYSTEM_TYPE_STORAGE = 0x8;
|
2017-05-22 11:34:18 +02:00
|
|
|
GameLib.System.SYSTEM_TYPE_GUI = 0x10;
|
2017-06-24 18:09:44 +02:00
|
|
|
GameLib.System.SYSTEM_TYPE_PHYSICS = 0x20;
|
2017-05-16 11:50:06 +02:00
|
|
|
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
2017-01-12 04:44:01 +01:00
|
|
|
|
2017-06-16 15:49:53 +02:00
|
|
|
GameLib.System.prototype.createInstance = function() {
|
|
|
|
console.log('GameLib.System.prototype.createInstance();');
|
|
|
|
};
|
|
|
|
|
2017-01-12 04:44:01 +01:00
|
|
|
/**
|
|
|
|
* @callback
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
GameLib.System.prototype.start = function() {
|
|
|
|
|
2017-05-22 11:34:18 +02:00
|
|
|
|
2017-05-10 15:56:27 +02:00
|
|
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
2017-06-16 15:49:53 +02:00
|
|
|
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
|
|
|
|
// this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
|
|
|
|
// this.meshObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Mesh]);
|
|
|
|
// this.lookAtObjects = GameLib.EntityManager.Instance.query([GameLib.D3.LookAt]);
|
|
|
|
// this.cameraObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Camera]);
|
|
|
|
// this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
|
2017-01-12 04:44:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-13 14:09:18 +02:00
|
|
|
this.update();
|
2017-05-11 13:30:20 +02:00
|
|
|
|
2017-01-12 04:44:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @callback
|
|
|
|
* @override
|
|
|
|
*/
|
2017-01-13 16:19:51 +01:00
|
|
|
GameLib.System.prototype.update = function(deltaTime) {
|
2017-01-12 04:44:01 +01:00
|
|
|
|
|
|
|
|
2017-05-10 15:56:27 +02:00
|
|
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
|
|
|
|
2017-01-12 04:44:01 +01:00
|
|
|
this.pathFollowingObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.update(deltaTime);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.followObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.update(deltaTime);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.lookAtObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.update(deltaTime);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.meshObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.updateInstance();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.cameraObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.updateInstance();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.lightObjects.forEach(
|
|
|
|
function(object) {
|
|
|
|
object.updateInstance();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-11 13:30:20 +02:00
|
|
|
|
2017-01-13 16:19:51 +01:00
|
|
|
|
2017-01-12 04:44:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @callback
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
GameLib.System.prototype.stop = function() {
|
|
|
|
|
2017-05-10 15:56:27 +02:00
|
|
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
2017-05-11 13:30:20 +02:00
|
|
|
// this.pathFollowingObjects = [];
|
|
|
|
// this.followObjects = [];
|
|
|
|
// this.meshObjects = [];
|
|
|
|
// this.lookAtObjects = [];
|
|
|
|
// this.cameraObjects = [];
|
|
|
|
// this.lightObjects = [];
|
2017-01-12 04:44:01 +01:00
|
|
|
}
|
|
|
|
};
|
2017-01-20 13:40:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts runtime vector to API Vector
|
2017-05-10 15:56:27 +02:00
|
|
|
* @returns {GameLib.API.System}
|
2017-01-20 13:40:27 +01:00
|
|
|
*/
|
2017-05-16 14:51:57 +02:00
|
|
|
GameLib.System.prototype.toApiObject = function() {
|
2017-01-20 13:40:27 +01:00
|
|
|
return new GameLib.API.System(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.systemType,
|
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
|
|
);
|
|
|
|
};
|