r3-legacy/src/r3-system-0.js

104 lines
2.5 KiB
JavaScript

/**
* System takes care of updating all the entities (based on their component data)
* @param apiSystem R3.API.System
* @constructor
*/
R3.System = function(
apiSystem
) {
if (R3.Utils.UndefinedOrNull(apiSystem)) {
apiSystem = {};
}
R3.API.System.call(
this,
apiSystem.id,
apiSystem.name,
apiSystem.systemType,
apiSystem.parentEntity
);
this.started = false;
this.paused = false;
var linkedObjects = {};
if (apiSystem.systemType === R3.System.SYSTEM_TYPE_INPUT) {
linkedObjects.mouseControls = [R3.Controls.Mouse];
linkedObjects.keyboardControls = [R3.Controls.Keyboard];
linkedObjects.touchControls = [R3.Controls.Touch];
linkedObjects.editorControls = [R3.Controls.D3.Editor];
}
if (apiSystem.systemType === R3.System.SYSTEM_TYPE_AUDIO) {
linkedObjects.audioComponents = [R3.D3.Audio];
}
R3.Component.call(
this,
linkedObjects
);
};
R3.System.prototype = Object.create(R3.Component.prototype);
R3.System.prototype.constructor = R3.System;
R3.System.SYSTEM_TYPE_NONE = 0x0;
R3.System.SYSTEM_TYPE_RENDER = 0x1;
R3.System.SYSTEM_TYPE_ANIMATION = 0x2;
R3.System.SYSTEM_TYPE_INPUT = 0x4;
R3.System.SYSTEM_TYPE_STORAGE = 0x8;
R3.System.SYSTEM_TYPE_GUI = 0x10;
R3.System.SYSTEM_TYPE_PHYSICS = 0x20;
R3.System.SYSTEM_TYPE_LINKING = 0x40;
R3.System.SYSTEM_TYPE_CUSTOM = 0x80;
R3.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
R3.System.SYSTEM_TYPE_PARTICLE = 0x200;
R3.System.SYSTEM_TYPE_AUDIO = 0x400;
R3.System.SYSTEM_TYPE_SOCKET = 0x800;
R3.System.SYSTEM_TYPE_ALL = 0xFFFF;
R3.System.prototype.createInstance = function() {
this.instance = true;
R3.Component.prototype.createInstance.call(this);
};
/**
* @callback
* @override
*/
R3.System.prototype.start = function() {
this.started = true;
// console.log('starting ' + this.name);
};
/**
* @callback
* @override
*/
R3.System.prototype.stop = function() {
this.started = false;
// console.log('stopping ' + this.name);
};
/**
* Converts runtime vector to API Vector
* @returns {R3.API.System}
*/
R3.System.prototype.toApiObject = function() {
return new R3.API.System(
this.id,
this.name,
this.systemType,
R3.Utils.IdOrNull(this.parentEntity)
);
};
R3.System.prototype.restart = function() {
console.log('restarting system : ' + this.name);
this.stop();
this.start();
};