send resolved

beta.r3js.org
Theunis J. Botha 2017-06-28 18:40:12 +02:00
parent 3ee447bf4d
commit 52ae5ae597
5 changed files with 60 additions and 255 deletions

View File

@ -43,6 +43,7 @@ GameLib.Event.LIGHT_INSTANCE_CREATED = 0x1b;
GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c; GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c;
GameLib.Event.DELETE_COMPONENT = 0x1d; GameLib.Event.DELETE_COMPONENT = 0x1d;
GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e; GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e;
GameLib.Event.COMPONENTS_LINKED = 0x1f;
/** /**
* Subscribe to some events * Subscribe to some events

View File

@ -628,4 +628,14 @@ GameLib.Utils.Difference = function (a, b) {
return c.indexOf(e) === i; return c.indexOf(e) === i;
} }
); );
};
/**
* Checks whether or not the object is empty
* @param obj
* @returns {boolean}
* @constructor
*/
GameLib.Utils.IsEmpty = function(obj) {
return (Object.keys(obj).length === 0 && obj.constructor === Object);
}; };

View File

@ -127,17 +127,22 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
if (event.code === 'Delete') { if (event.code === 'Delete') {
var meshes = entity.getComponents(GameLib.D3.Mesh); var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
var gui = entity.getFirstComponent(GameLib.GUI); var guis = GameLib.EntityManager.Instance.queryComponents([GameLib.GUI]);
meshes.map( meshes.map(
function(mesh) { function(mesh) {
if (mesh.selected) { if (mesh.selected) {
this.removeHelper(mesh, entity);
var parentEntity = mesh.parentEntity;
parentEntity.removeHelper(mesh, entity);
entity.removeComponent(mesh); entity.removeComponent(mesh);
entity.buildIdToObject(); entity.buildIdToObject();
gui.removeObject(mesh); guis.map(function(gui) {
gui.removeObject(mesh);
});
var scene = mesh.parentScene; var scene = mesh.parentScene;
scene.removeObject(mesh); scene.removeObject(mesh);
@ -148,7 +153,9 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
gui.build(entityManager); guis.map(function(gui) {
gui.build(entityManager);
});
} }
if (event.code === 'ControlLeft') { if (event.code === 'ControlLeft') {

View File

@ -28,6 +28,8 @@ GameLib.System.Linking = function(
*/ */
this.register = []; this.register = [];
this.resolved = [];
this.componentCreatedSubscription = null; this.componentCreatedSubscription = null;
this.parentSceneChangeSubscription = null; this.parentSceneChangeSubscription = null;
this.parentEntityChangeSubscription = null; this.parentEntityChangeSubscription = null;
@ -136,13 +138,17 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
} else { } else {
parentComponents.map( parentComponents.map(
function(parentComponent) { function (parentComponent) {
/** /**
* Link the parent component to this component * Link the parent component to this component
*/ */
this.link(parentComponent, {component: component}); this.link(parentComponent, {component: component});
if (this.resolved.indexOf(component) === -1) {
this.resolved.push(component);
}
/** /**
* Remove the actual dependency * Remove the actual dependency
*/ */
@ -164,6 +170,11 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
if (parentComponent.instance) { if (parentComponent.instance) {
parentComponent.loaded = true; parentComponent.loaded = true;
if (this.resolved.indexOf(parentComponent) === -1) {
this.resolved.push(parentComponent);
}
GameLib.Event.EmitInstanceEvents(parentComponent); GameLib.Event.EmitInstanceEvents(parentComponent);
} }
} }
@ -172,7 +183,24 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
); );
delete this.dependencies[component.id]; delete this.dependencies[component.id];
if (GameLib.Utils.IsEmpty(this.dependencies)) {
GameLib.Event.Emit(
GameLib.Event.COMPONENTS_LINKED,
{
components: this.resolved.map(
function(component) {
return component;
}
)
}
);
this.resolved = [];
}
} }
}; };
GameLib.System.Linking.prototype.registerDependencies = function(component) { GameLib.System.Linking.prototype.registerDependencies = function(component) {
@ -212,6 +240,10 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
*/ */
this.link(component, {component: processedComponent}); this.link(component, {component: processedComponent});
if (this.resolved.indexOf(processedComponent) === -1) {
this.resolved.push(processedComponent);
}
} else { } else {
/** /**
@ -314,34 +346,6 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
this.resolveDependencies(data.scene); this.resolveDependencies(data.scene);
// var scene = data.scene;
//
// scene.images.map(
// function(image){
// GameLib.Event.Emit(
// GameLib.Event.LOAD_IMAGE,
// {
// onLoaded : function(image) {
// if (this.onImageLoaded) {
// this.onImageLoaded(image);
// }
// },
// onProgress : function(image, progress) {
// if (this.onImageProgress) {
// this.onImageProgress(image, progress);
// }
// },
// onError : function(image, error) {
// if (this.onImageError) {
// this.onImageError(image, error);
// }
// },
// image : image
// }
// );
// }.bind(this)
// );
/** /**
* Add all meshes and lights * Add all meshes and lights
*/ */
@ -366,232 +370,15 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
}; };
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) { GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
this.resolveDependencies(data.image); this.resolveDependencies(data.image);
// var textures = this.queryRegister(GameLib.D3.Texture);
//
// textures.map(
//
// function(texture) {
// /**
// * Only work with images that belong to this texture
// */
// if (
// texture.image === data.image
// ) {
// /**
// * Update instance, if already an instance
// */
// if (texture.instance) {
// texture.updateInstance();
// GameLib.Event.Emit(
// GameLib.Event.TEXTURE_INSTANCE_UPDATED,
// {
// texture : texture
// }
// )
// } else {
// /**
// * Create a new instance
// */
// texture.instance = texture.createInstance();
// GameLib.Event.Emit(
// GameLib.Event.TEXTURE_INSTANCE_CREATED,
// {
// texture : texture
// }
// )
// }
// }
// }
// );
}; };
GameLib.System.Linking.prototype.textureInstanceCreated = function(data) { GameLib.System.Linking.prototype.textureInstanceCreated = function(data) {
this.resolveDependencies(data.texture); this.resolveDependencies(data.texture);
// var materials = this.queryRegister(GameLib.D3.Material);
//
// materials.map(
//
// function(material) {
//
// if (!material.loaded) {
// return;
// }
//
// if (!data.texture.loaded || !data.texture.instance) {
// console.warn('texture indicated it is loaded however it is not');
// return;
// }
//
// console.log('texture instance created');
// var modified = false;
// /**
// * We also need to check if the image of the texture is assigned -
// * if not we should disable the map
// */
// if (material.alphaMap === data.texture) {
// if (material.instance.alphaMap !== data.texture.instance) {
// material.instance.alphaMap = data.texture.instance;
// }
// modified = true;
// } else {
// if (material.instance.alphaMap)
// material.instance.alphaMap = null;
// }
//
// if (material.aoMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.aoMap = data.texture.instance;
// } else {
// material.instance.aoMap = null;
// }
// modified = true;
// }
// if (material.bumpMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.bumpMap = data.texture.instance;
// } else {
// material.instance.bumpMap = null;
// }
// modified = true;
// }
// if (material.diffuseMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.map = data.texture.instance;
// } else {
// material.instance.map = null;
// }
// modified = true;
// }
// if (material.displacementMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.displacementMap = data.texture.instance;
// } else {
// material.instance.displacementMap = null;
// }
// modified = true;
// }
// if (material.emissiveMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.emissiveMap = data.texture.instance;
// } else {
// material.instance.emissiveMap = null;
// }
// modified = true;
// }
// if (material.environmentMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.envMap = data.texture.instance;
// } else {
// material.instance.envMap = null;
// }
// modified = true;
// }
// if (material.lightMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.lightMap = data.texture.instance;
// } else {
// material.instance.lightMap = null;
// }
// modified = true;
// }
// if (material.metalnessMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.metalnessMap = data.texture.instance;
// } else {
// material.instance.metalnessMap = null;
// }
// modified = true;
// }
// if (material.normalMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.normalMap = data.texture.instance;
// } else {
// material.instance.normalMap = null;
// }
// modified = true;
// }
// if (material.roughnessMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.roughnessMap = data.texture.instance;
// } else {
// material.instance.roughnessMap = null;
// }
// modified = true;
// }
// if (material.specularMap === data.texture) {
//
// if (data.texture.image) {
// material.instance.specularMap = data.texture.instance;
// } else {
// material.instance.specularMap = null;
// }
// modified = true;
// }
//
// if (modified) {
// material.updateInstance();
// GameLib.Event.Emit(
// GameLib.Event.MATERIAL_INSTANCE_UPDATED,
// {
// material : material
// }
// )
// }
// }
// );
}; };
GameLib.System.Linking.prototype.materialInstanceCreated = function(data) { GameLib.System.Linking.prototype.materialInstanceCreated = function(data) {
this.resolveDependencies(data.material); this.resolveDependencies(data.material);
// var meshes = this.queryRegister(GameLib.D3.Mesh);
//
// meshes.map(function(mesh){
//
// if (!mesh.instance) {
// return;
// }
//
// /**
// * Only work with materials assigned to us
// */
// if (mesh.materials[0] !== data.material) {
// return;
// }
//
// if (mesh.instance.material === data.material.instance) {
// //mesh.instance.geometry.uvsNeedUpdate = true;
// return;
// }
//
// if (mesh.materials[0] === data.material) {
//
// if (mesh.instance.material !== data.material.instance) {
// mesh.instance.material = data.material.instance;
// }
//
// //mesh.instance.geometry.uvsNeedUpdate = true;
// }
// });
}; };
/** /**

View File

@ -263,7 +263,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
) )
} }
loaded.push(runtimeComponent.id); loaded.push(runtimeComponent);
if (includeDependencies) { if (includeDependencies) {
/** /**
@ -310,8 +310,8 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
function (result, dependency) { function (result, dependency) {
var found = loaded.reduce( var found = loaded.reduce(
function (result, id) { function (result, component) {
if (id === dependency) { if (component.id === dependency) {
result = true; result = true;
} }
return result; return result;
@ -365,7 +365,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
} }
); );
var toProcess = GameLib.Utils.Difference(loaded, loading); var toProcess = GameLib.Utils.Difference(loaded.map(function(component){return component.id}), loading);
if (toProcess.length === 0) { if (toProcess.length === 0) {
GameLib.Event.Emit( GameLib.Event.Emit(