/** * System takes care of updating all the entities (based on their component data) * @param implementation * @param apiSystem GameLib.API.System * @constructor */ GameLib.System = function( apiSystem ) { if (GameLib.Utils.UndefinedOrNull(apiSystem)) { apiSystem = {}; } if (apiSystem instanceof GameLib.System) { return apiSystem; } GameLib.API.System.call( this, apiSystem.id, apiSystem.name, apiSystem.systemType, apiSystem.parentEntity ); GameLib.Component.call( this, GameLib.Component.COMPONENT_SYSTEM ); }; GameLib.System.prototype = Object.create(GameLib.API.System.prototype); GameLib.System.prototype.constructor = GameLib.System; GameLib.System.SYSTEM_TYPE_NONE = 0x0; GameLib.System.SYSTEM_TYPE_RENDER = 0x1; GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2; GameLib.System.SYSTEM_TYPE_INPUT = 0x4; GameLib.System.SYSTEM_TYPE_STORAGE = 0x8; GameLib.System.SYSTEM_TYPE_GUI = 0x10; GameLib.System.SYSTEM_TYPE_PHYSICS = 0x20; GameLib.System.SYSTEM_TYPE_LINKING = 0x40; GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80; GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100; GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF; GameLib.System.prototype.createInstance = function() { //console.log('GameLib.System.prototype.createInstance();'); }; /** * @callback * @override */ GameLib.System.prototype.start = function() { if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { // 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]); } this.update(); }; /** * @callback * @override */ GameLib.System.prototype.update = function(deltaTime) { if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { 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(); } ); } }; /** * @callback * @override */ GameLib.System.prototype.stop = function() { if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { // this.pathFollowingObjects = []; // this.followObjects = []; // this.meshObjects = []; // this.lookAtObjects = []; // this.cameraObjects = []; // this.lightObjects = []; } }; /** * Converts runtime vector to API Vector * @returns {GameLib.API.System} */ GameLib.System.prototype.toApiObject = function() { return new GameLib.API.System( this.id, this.name, this.systemType, GameLib.Utils.IdOrNull(this.parentEntity) ); }; GameLib.System.prototype.restart = function() { this.stop(); this.start(); };