socket system

beta.r3js.org
-=yb4f310 2017-12-05 13:05:31 +01:00
parent 8e462a8c27
commit 050a7854b2
5 changed files with 214 additions and 11 deletions

12
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Tue Dec 05 2017 11:25:55 GMT+0100 (CET)";
var __DATE__ = "Tue Dec 05 2017 13:01:04 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS
/**
@ -24818,6 +24818,7 @@ GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80;
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
GameLib.System.SYSTEM_TYPE_SOCKET = 0x800;
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
GameLib.System.prototype.createInstance = function() {
@ -30983,12 +30984,10 @@ GameLib.System.Render.prototype.start = function() {
GameLib.System.Render.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Renderer) {
console.log('new renderer');
this.renderers.push(data.component);
}
if (data.component instanceof GameLib.Stats) {
console.log('new stats');
this.statistics.push(data.component);
}
};
@ -31116,6 +31115,109 @@ GameLib.System.Render.prototype.stop = function() {
};
/**
* System takes care of updating all the entities (based on their component data)
* @param apiSystem GameLib.API.System
* @constructor
*/
GameLib.System.Socket = function(
apiSystem
) {
GameLib.System.call(
this,
apiSystem
);
this.totalTime = 0;
this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null;
this.beforeRenderSubscription = null;
};
GameLib.System.Socket.prototype = Object.create(GameLib.System.prototype);
GameLib.System.Socket.prototype.constructor = GameLib.System.Socket;
/**
* Start this system (add all event listeners)
*/
GameLib.System.Socket.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.castComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAST);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
this.removeComponentSubscription = GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this)
);
this.beforeRenderSubscription = GameLib.Event.Subscribe(
GameLib.Event.BEFORE_RENDER,
this.beforeRender.bind(this)
);
};
/**
* From now on we want to track everything about a component, only from the systems that are active
* @param data
*/
GameLib.System.Socket.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.Cast) {
this.castComponents.push(data.component);
}
};
/**
* Removes a cast component from this system
* @param data
*/
GameLib.System.Socket.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.Cast) {
var index = this.castComponents.indexOf(data.component);
if (index !== -1) {
this.castComponents.splice(index, 1);
} else {
console.log('Socket System out of Component sync')
}
}
};
/**
* @param data
*/
GameLib.System.Socket.prototype.beforeRender = function(data) {
this.totalTime += data.delta;
};
/**
* Stop this system (remove all event listeners)
*/
GameLib.System.Socket.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.beforeRenderSubscription.remove();
};
/**
* Storage System takes care loading and linking components and dependencies
* @param apiSystem GameLib.API.System

View File

@ -62,6 +62,7 @@ GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80;
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
GameLib.System.SYSTEM_TYPE_SOCKET = 0x800;
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
GameLib.System.prototype.createInstance = function() {

View File

@ -54,12 +54,10 @@ GameLib.System.Render.prototype.start = function() {
GameLib.System.Render.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Renderer) {
console.log('new renderer');
this.renderers.push(data.component);
}
if (data.component instanceof GameLib.Stats) {
console.log('new stats');
this.statistics.push(data.component);
}
};

View File

@ -0,0 +1,102 @@
/**
* System takes care of updating all the entities (based on their component data)
* @param apiSystem GameLib.API.System
* @constructor
*/
GameLib.System.Socket = function(
apiSystem
) {
GameLib.System.call(
this,
apiSystem
);
this.totalTime = 0;
this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null;
this.beforeRenderSubscription = null;
};
GameLib.System.Socket.prototype = Object.create(GameLib.System.prototype);
GameLib.System.Socket.prototype.constructor = GameLib.System.Socket;
/**
* Start this system (add all event listeners)
*/
GameLib.System.Socket.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.castComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAST);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
this.removeComponentSubscription = GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this)
);
this.beforeRenderSubscription = GameLib.Event.Subscribe(
GameLib.Event.BEFORE_RENDER,
this.beforeRender.bind(this)
);
};
/**
* From now on we want to track everything about a component, only from the systems that are active
* @param data
*/
GameLib.System.Socket.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.Cast) {
this.castComponents.push(data.component);
}
};
/**
* Removes a cast component from this system
* @param data
*/
GameLib.System.Socket.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.Cast) {
var index = this.castComponents.indexOf(data.component);
if (index !== -1) {
this.castComponents.splice(index, 1);
} else {
console.log('Socket System out of Component sync')
}
}
};
/**
* @param data
*/
GameLib.System.Socket.prototype.beforeRender = function(data) {
this.totalTime += data.delta;
};
/**
* Stop this system (remove all event listeners)
*/
GameLib.System.Socket.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.beforeRenderSubscription.remove();
};