create instances immediately when dependencies are met
parent
e09cfed52a
commit
9408afba28
|
@ -65,7 +65,7 @@ GameLib.D3.API.Renderer = function (
|
||||||
this.domElement = domElement;
|
this.domElement = domElement;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
||||||
clearColor = new GameLib.API.Color(0.58, 0.58, 0.58);
|
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
|
||||||
}
|
}
|
||||||
this.clearColor = clearColor;
|
this.clearColor = clearColor;
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,6 @@ GameLib.EntityManager.prototype.toApiObject = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an EntityManager from an Object entity manager
|
* Returns an EntityManager from an Object entity manager
|
||||||
* @param graphics
|
|
||||||
* @param objectEntityManager Object
|
* @param objectEntityManager Object
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -405,9 +404,11 @@ GameLib.EntityManager.prototype.link = function(component, data) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.componentCreated = function(data) {
|
GameLib.EntityManager.prototype.componentCreated = function() {
|
||||||
|
|
||||||
//console.log('component created : ' + data.component.name);
|
var loading = [];
|
||||||
|
|
||||||
|
return function(data) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register this component immediately
|
* Register this component immediately
|
||||||
|
@ -424,25 +425,18 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
/**
|
/**
|
||||||
* Store this component into our 'loaded' list
|
* Store this component into our 'loaded' list
|
||||||
*/
|
*/
|
||||||
this.loading.push(data.component);
|
loading.push(data.component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the dependencies too
|
* Store the dependencies too
|
||||||
*/
|
*/
|
||||||
data.component.dependencies.map(function(id) {
|
data.component.dependencies.map(function (id) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
if (this.register.hasOwnProperty(id)) {
|
if (this.register.hasOwnProperty(id)) {
|
||||||
|
|
||||||
console.log('found a component here');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* First add this to the 'idToObject'
|
|
||||||
*/
|
|
||||||
// data.component.idToObject[id] = this.register[id];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove this dependency from the dependency list
|
* Remove this dependency from the dependency list
|
||||||
*/
|
*/
|
||||||
|
@ -455,7 +449,7 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
/**
|
/**
|
||||||
* Now link the component
|
* Now link the component
|
||||||
*/
|
*/
|
||||||
this.link(data.component, {component:this.register[id]});
|
this.link(data.component, {component: this.register[id]});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -483,18 +477,15 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
* has to load which has dependencies to this object
|
* has to load which has dependencies to this object
|
||||||
*/
|
*/
|
||||||
this.register[data.component.id] = data.component;
|
this.register[data.component.id] = data.component;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Otherwise, now - for each dependency - check if its loaded
|
* Otherwise, now - for each dependency - check if its loaded
|
||||||
*/
|
*/
|
||||||
this.dependencies[data.component.id] = this.dependencies[data.component.id].reduce(
|
this.dependencies[data.component.id] = this.dependencies[data.component.id].reduce(
|
||||||
function (result, component) {
|
|
||||||
|
|
||||||
/**
|
function (result, component) {
|
||||||
* Link the object to the component
|
|
||||||
*/
|
|
||||||
// component.idToObject[data.component.id] = data.component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the actual dependency
|
* Remove the actual dependency
|
||||||
|
@ -516,6 +507,9 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
*/
|
*/
|
||||||
if (component.dependencies.length === 0) {
|
if (component.dependencies.length === 0) {
|
||||||
component.loaded = true;
|
component.loaded = true;
|
||||||
|
component.instance = component.createInstance();
|
||||||
|
this.emitInstanceEvents(component);
|
||||||
|
delete component.dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -534,6 +528,8 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
*/
|
*/
|
||||||
if (data.component.dependencies.length === 0) {
|
if (data.component.dependencies.length === 0) {
|
||||||
data.component.loaded = true;
|
data.component.loaded = true;
|
||||||
|
data.component.instance = data.component.createInstance();
|
||||||
|
this.emitInstanceEvents(data.component);
|
||||||
delete data.component.dependencies;
|
delete data.component.dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,8 +537,8 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
* Now check if all components are loaded, i.e., no more dependencies - if so - create their instance objects
|
* Now check if all components are loaded, i.e., no more dependencies - if so - create their instance objects
|
||||||
*/
|
*/
|
||||||
var loaded = true;
|
var loaded = true;
|
||||||
for (var i = 0; i < this.loading.length; i++) {
|
for (var i = 0; i < loading.length; i++) {
|
||||||
if (!this.loading[i].loaded) {
|
if (!loading[i].loaded) {
|
||||||
loaded = false;
|
loaded = false;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -552,9 +548,12 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
* All components loaded
|
* All components loaded
|
||||||
*/
|
*/
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
this.loading.map(function(component) {
|
loading = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
component.instance = component.createInstance();
|
GameLib.EntityManager.prototype.emitInstanceEvents = function (component) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
component instanceof GameLib.D3.Mesh ||
|
component instanceof GameLib.D3.Mesh ||
|
||||||
|
@ -589,11 +588,6 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
this.loading = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -618,7 +612,7 @@ GameLib.EntityManager.prototype.registerCallbacks = function() {
|
||||||
this.subscriptions.push(
|
this.subscriptions.push(
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
GameLib.Event.COMPONENT_CREATED,
|
GameLib.Event.COMPONENT_CREATED,
|
||||||
this.componentCreated
|
this.componentCreated().bind(this)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue