create instances immediately when dependencies are met

beta.r3js.org
-=yb4f310 2017-06-21 16:36:19 +02:00
parent e09cfed52a
commit 9408afba28
2 changed files with 157 additions and 163 deletions

View File

@ -65,7 +65,7 @@ GameLib.D3.API.Renderer = function (
this.domElement = domElement;
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;

View File

@ -256,7 +256,6 @@ GameLib.EntityManager.prototype.toApiObject = function() {
/**
* Returns an EntityManager from an Object entity manager
* @param graphics
* @param objectEntityManager Object
* @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
@ -424,25 +425,18 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
/**
* Store this component into our 'loaded' list
*/
this.loading.push(data.component);
loading.push(data.component);
/**
* 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
*/
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
*/
@ -455,7 +449,7 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
/**
* Now link the component
*/
this.link(data.component, {component:this.register[id]});
this.link(data.component, {component: this.register[id]});
} else {
@ -483,18 +477,15 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
* has to load which has dependencies to this object
*/
this.register[data.component.id] = data.component;
} else {
/**
* Otherwise, now - for each dependency - check if its loaded
*/
this.dependencies[data.component.id] = this.dependencies[data.component.id].reduce(
function (result, component) {
/**
* Link the object to the component
*/
// component.idToObject[data.component.id] = data.component;
function (result, component) {
/**
* Remove the actual dependency
@ -516,6 +507,9 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
*/
if (component.dependencies.length === 0) {
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) {
data.component.loaded = true;
data.component.instance = data.component.createInstance();
this.emitInstanceEvents(data.component);
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
*/
var loaded = true;
for (var i = 0; i < this.loading.length; i++) {
if (!this.loading[i].loaded) {
for (var i = 0; i < loading.length; i++) {
if (!loading[i].loaded) {
loaded = false;
break
}
@ -552,9 +548,12 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
* All components loaded
*/
if (loaded) {
this.loading.map(function(component) {
loading = [];
}
};
};
component.instance = component.createInstance();
GameLib.EntityManager.prototype.emitInstanceEvents = function (component) {
if (
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.subscribe(
GameLib.Event.COMPONENT_CREATED,
this.componentCreated
this.componentCreated().bind(this)
)
);
};