linking and loading done
parent
1a0878a094
commit
943a81916f
|
@ -10,6 +10,11 @@ GameLib.EntityManager = function() {
|
||||||
|
|
||||||
this.entities = [];
|
this.entities = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 'register' array is a register of each component currently loaded - when the linking
|
||||||
|
* system starts it also loads all the current components from the entity manager
|
||||||
|
* @type {Array}
|
||||||
|
*/
|
||||||
this.register = [];
|
this.register = [];
|
||||||
|
|
||||||
GameLib.Event.Subscribe(
|
GameLib.Event.Subscribe(
|
||||||
|
@ -35,6 +40,12 @@ GameLib.EntityManager.prototype.createInstance = function() {
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.registerComponent = function(data) {
|
GameLib.EntityManager.prototype.registerComponent = function(data) {
|
||||||
this.register.push(data.component);
|
this.register.push(data.component);
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.REGISTER_UPDATE,
|
||||||
|
{
|
||||||
|
register : this.register
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,6 +98,18 @@ GameLib.EntityManager.prototype.findEntityById = function(id) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.EntityManager.prototype.findComponentById = function(id) {
|
||||||
|
return this.register.reduce(
|
||||||
|
function(result, component){
|
||||||
|
if (component.id === id){
|
||||||
|
result = component;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.findHelperByObject = function(object) {
|
GameLib.EntityManager.prototype.findHelperByObject = function(object) {
|
||||||
|
|
||||||
return this.entities.reduce(
|
return this.entities.reduce(
|
||||||
|
|
|
@ -21,12 +21,6 @@ GameLib.System.Linking = function(
|
||||||
*/
|
*/
|
||||||
this.dependencies = {};
|
this.dependencies = {};
|
||||||
|
|
||||||
/**
|
|
||||||
* The 'register' array is a register of each component currently loaded - when the linking
|
|
||||||
* system starts it also loads all the current components from the entity manager
|
|
||||||
* @type {Array}
|
|
||||||
*/
|
|
||||||
this.register = [];
|
|
||||||
|
|
||||||
this.resolved = [];
|
this.resolved = [];
|
||||||
|
|
||||||
|
@ -46,15 +40,6 @@ GameLib.System.Linking.prototype.constructor = GameLib.System.Linking;
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.start = function() {
|
GameLib.System.Linking.prototype.start = function() {
|
||||||
|
|
||||||
this.register = GameLib.EntityManager.Instance.queryComponents([GameLib.Component]);
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.REGISTER_UPDATE,
|
|
||||||
{
|
|
||||||
register : this.register
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.componentCreatedSubscription = this.subscribe(
|
this.componentCreatedSubscription = this.subscribe(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CREATED,
|
||||||
this.componentCreated.bind(this)
|
this.componentCreated.bind(this)
|
||||||
|
@ -219,18 +204,6 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Register this component immediately
|
|
||||||
*/
|
|
||||||
this.register.push(component);
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.REGISTER_UPDATE,
|
|
||||||
{
|
|
||||||
register : this.register
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We only care about components with unloaded dependencies -
|
* We only care about components with unloaded dependencies -
|
||||||
* other components will have already had their instance objects created
|
* other components will have already had their instance objects created
|
||||||
|
@ -244,15 +217,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
||||||
/**
|
/**
|
||||||
* Check if we already processed a component on which this component is dependent
|
* Check if we already processed a component on which this component is dependent
|
||||||
*/
|
*/
|
||||||
var processedComponent = this.register.reduce(
|
var processedComponent = GameLib.EntityManager.Instance.findComponentById(id);
|
||||||
function(result, component){
|
|
||||||
if (component.id === id){
|
|
||||||
result = component;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
if (processedComponent) {
|
if (processedComponent) {
|
||||||
|
|
||||||
|
@ -450,13 +415,6 @@ GameLib.System.Linking.prototype.onParentEntityChange = function(data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.stop = function() {
|
GameLib.System.Linking.prototype.stop = function() {
|
||||||
this.register = [];
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.REGISTER_UPDATE,
|
|
||||||
{
|
|
||||||
register : this.register
|
|
||||||
}
|
|
||||||
);
|
|
||||||
this.componentCreatedSubscription.remove();
|
this.componentCreatedSubscription.remove();
|
||||||
this.parentSceneChangeSubscription.remove();
|
this.parentSceneChangeSubscription.remove();
|
||||||
this.parentEntityChangeSubscription.remove();
|
this.parentEntityChangeSubscription.remove();
|
||||||
|
|
|
@ -275,24 +275,19 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
|
||||||
/**
|
/**
|
||||||
* Now - we should systematically check if we have the dependency already
|
* Now - we should systematically check if we have the dependency already
|
||||||
* loaded (in our runtime environment) - if we have - we just ignore loading this dependency (for now)
|
* loaded (in our runtime environment) - if we have - we just ignore loading this dependency (for now)
|
||||||
* TODO: decide what to do with runtime versions of 'stale' dependencies
|
*
|
||||||
|
* We don't override runtime versions of the same component in the database because the user
|
||||||
|
* could be working with it and it should be the latest version.
|
||||||
*/
|
*/
|
||||||
var components = GameLib.EntityManager.Instance.queryComponents(componentClass);
|
|
||||||
|
|
||||||
dependencies = dependencies.reduce(
|
dependencies = dependencies.reduce(
|
||||||
function (result, dependency) {
|
function (result, dependency) {
|
||||||
|
|
||||||
var found = components.reduce(
|
if (GameLib.EntityManager.Instance.findComponentById(dependency)) {
|
||||||
function (result, component) {
|
/**
|
||||||
if (component.id === dependency) {
|
* Don't add the dependency
|
||||||
found = true;
|
*/
|
||||||
}
|
} else {
|
||||||
return result;
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
result.push(dependency);
|
result.push(dependency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue