loading, checkRegister and texture creation order

beta.r3js.org
Theunis J. Botha 2017-06-19 12:42:15 +02:00
parent 5398cebcbe
commit 22e0e8828d
7 changed files with 87 additions and 78 deletions

View File

@ -172,7 +172,7 @@ GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture;
GameLib.D3.API.Texture.FromObject = function(objectTexture) {
return new GameLib.D3.API.Texture(
objectTexture.id,
objectTexture.textureType,
objectTexture.typeId,
objectTexture.name,
objectTexture.image,
objectTexture.wrapS,

View File

@ -78,23 +78,18 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
console.log('loading normal image');
loader = new THREE.XHRLoader();
loader = new THREE.ImageLoader();
loader.crossOrigin = true;
loader.path = data.baseUrl;
loader.responseType = 'blob';
loader.load(
this.path + '?ts=' + Date.now(),
function (blob) {
var image = document.createElement('img');
image.onload = function ( e ) { URL.revokeObjectURL( image.src ); };
image.src = URL.createObjectURL( blob );
function (image) {
this.instance = image;
this.publish(
GameLib.Event.IMAGE_LOADED,
{
@ -102,6 +97,7 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
imageInstance: this.instance
}
);
}.bind(this),
function(xhr) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded of ' + this.name);

View File

@ -458,7 +458,11 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
}
if (this.materials[0] === data.material) {
this.instance.material = data.material.instance;
if (this.instance.material !== data.material.instance) {
this.instance.material = data.material.instance;
}
this.instance.geometry.uvsNeedUpdate = true;
}
}

View File

@ -97,6 +97,7 @@ GameLib.D3.Scene = function (
function(apiTexture) {
if (apiTexture instanceof GameLib.D3.API.Texture) {
var texture = new GameLib.D3.Texture(
this.graphics,
apiTexture

View File

@ -210,35 +210,38 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
} else {
if (this.image instanceof GameLib.D3.Image) {
if (this.image.instance) {
var instance = new THREE.Texture(
this.image.instance
);
instance.name = this.name;
instance.flipY = this.flipY;
instance.encoding = this.encoding;
instance.offset.x = this.offset.x;
instance.offset.y = this.offset.y;
instance.repeat.x = this.repeat.x;
instance.repeat.y = this.repeat.y;
instance.mapping = this.mapping;
instance.format = this.format;
instance.wrapS = this.wrapS;
instance.wrapT = this.wrapT;
this.publish(
GameLib.Event.TEXTURE_LOADED,
{
texture : this
}
);
return instance;
}
}
// if (this.image instanceof GameLib.D3.Image) {
//
// if (this.image.instance) {
//
// var instance = new THREE.Texture(
// this.image.instance
// );
// instance.name = this.name;
// instance.flipY = this.flipY;
// instance.encoding = this.encoding;
// instance.offset.x = this.offset.x;
// instance.offset.y = this.offset.y;
// instance.repeat.x = this.repeat.x;
// instance.repeat.y = this.repeat.y;
// instance.mapping = this.mapping;
// instance.format = this.format;
// instance.wrapS = this.wrapS;
// instance.wrapT = this.wrapT;
//
// this.instance = instance;
//
// this.publish(
// GameLib.Event.TEXTURE_LOADED,
// {
// texture : this
// }
// );
//
// this.instance.needsUpdate = true;
// return instance;
// }
// }
this.subscribe(
GameLib.Event.IMAGE_LOADED,
@ -315,19 +318,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
instance = new THREE.Texture();
} else {
instance = new THREE.Texture(this.image.instance);
// instance.needsUpdate = true;
// instance.name = this.name;
// instance.flipY = this.flipY;
// instance.encoding = this.encoding;
// instance.offset.x = this.offset.x;
// instance.offset.y = this.offset.y;
// instance.repeat.x = this.repeat.x;
// instance.repeat.y = this.repeat.y;
// this.format = instance.format;
}
this.instance = instance;
this.publish(
GameLib.Event.TEXTURE_LOADED,
{
@ -335,6 +327,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
}
);
instance.needsUpdate = true;
this.instance = instance;
}
);

View File

@ -10,6 +10,18 @@ GameLib.EntityManager = function() {
this.entities = [];
this.loading = [];
this.dependencies = {};
this.subscriptions = [];
this.register = {};
this.checkRegister = [];
this.registerCallbacks();
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY_MANAGER,
@ -18,16 +30,6 @@ GameLib.EntityManager = function() {
},
null
);
this.loaded = [];
this.dependencies = {};
this.subscriptions = [];
this.register = {};
this.registerCallbacks();
};
GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype);
@ -203,24 +205,31 @@ GameLib.EntityManager.prototype.query = function(components) {
/**
* Returns all actual components of all entities that contain this component
* @param constructor
* @param constructors (array of constructor or just a single constructor)
*/
GameLib.EntityManager.prototype.queryComponents = function(constructor) {
GameLib.EntityManager.prototype.queryComponents = function(constructors) {
var entities = this.query([constructor]);
return this.checkRegister.reduce(
function(result, object) {
if (constructors instanceof Array) {
constructors.map(
function(constructor) {
if (object instanceof constructor) {
result.push(object);
}
}
);
} else {
if (object instanceof constructors) {
result.push(object);
}
}
var components = entities.reduce(
function(result, entity){
var ecs = entity.getComponents(constructor);
ecs.map(function(ec){
result.push(ec);
});
return result;
},
[]
);
return components;
};
/**
@ -405,7 +414,12 @@ GameLib.EntityManager.prototype.link = function(component, data) {
GameLib.EntityManager.prototype.componentCreated = function(data) {
console.log('component created : ' + data.component.name);
//console.log('component created : ' + data.component.name);
/**
* Register this component immediately
*/
this.checkRegister.push(data.component);
/**
* If we notify ourselves - ignore it
@ -417,7 +431,7 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
/**
* Store this component into our 'loaded' list
*/
this.loaded.push(data.component);
this.loading.push(data.component);
/**
* Store the dependencies too
@ -533,8 +547,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.loaded.length; i++) {
if (!this.loaded[i].loaded) {
for (var i = 0; i < this.loading.length; i++) {
if (!this.loading[i].loaded) {
loaded = false;
break
}
@ -544,10 +558,10 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
* All components loaded
*/
if (loaded) {
this.loaded.map(function(component){
this.loading.map(function(component){
component.instance = component.createInstance();
});
this.loaded = [];
this.loading = [];
}
};

View File

@ -878,7 +878,7 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en
/**
* Properties changed - rebuild the object list in the parent
*/
parentObject.buildIdToObject();
console.log('parentObject.buildIdToObject();');
/**
* Properties changed - rebuild GUI