socket system
parent
8e462a8c27
commit
050a7854b2
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
||||||
// COMPILE TIME DEFINITIONS (Generated via gulp)
|
// 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
|
// END COMPILE TIME DEFINITIONS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24818,6 +24818,7 @@ GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80;
|
||||||
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
|
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
|
||||||
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
|
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
|
||||||
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
|
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
|
||||||
|
GameLib.System.SYSTEM_TYPE_SOCKET = 0x800;
|
||||||
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
||||||
|
|
||||||
GameLib.System.prototype.createInstance = function() {
|
GameLib.System.prototype.createInstance = function() {
|
||||||
|
@ -30983,12 +30984,10 @@ GameLib.System.Render.prototype.start = function() {
|
||||||
GameLib.System.Render.prototype.instanceCreated = function(data) {
|
GameLib.System.Render.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.Renderer) {
|
if (data.component instanceof GameLib.D3.Renderer) {
|
||||||
console.log('new renderer');
|
|
||||||
this.renderers.push(data.component);
|
this.renderers.push(data.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Stats) {
|
if (data.component instanceof GameLib.Stats) {
|
||||||
console.log('new stats');
|
|
||||||
this.statistics.push(data.component);
|
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
|
* Storage System takes care loading and linking components and dependencies
|
||||||
* @param apiSystem GameLib.API.System
|
* @param apiSystem GameLib.API.System
|
||||||
|
|
|
@ -62,6 +62,7 @@ GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80;
|
||||||
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
|
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
|
||||||
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
|
GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200;
|
||||||
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
|
GameLib.System.SYSTEM_TYPE_AUDIO = 0x400;
|
||||||
|
GameLib.System.SYSTEM_TYPE_SOCKET = 0x800;
|
||||||
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
||||||
|
|
||||||
GameLib.System.prototype.createInstance = function() {
|
GameLib.System.prototype.createInstance = function() {
|
||||||
|
|
|
@ -54,12 +54,10 @@ GameLib.System.Render.prototype.start = function() {
|
||||||
GameLib.System.Render.prototype.instanceCreated = function(data) {
|
GameLib.System.Render.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.D3.Renderer) {
|
if (data.component instanceof GameLib.D3.Renderer) {
|
||||||
console.log('new renderer');
|
|
||||||
this.renderers.push(data.component);
|
this.renderers.push(data.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Stats) {
|
if (data.component instanceof GameLib.Stats) {
|
||||||
console.log('new stats');
|
|
||||||
this.statistics.push(data.component);
|
this.statistics.push(data.component);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue