first loading seems ok
parent
68a8eef4bb
commit
8e5c3d1d04
|
@ -93,7 +93,7 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
|
|||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
|
||||
} else if (typeof object == 'string') {
|
||||
} else if (typeof object === 'string') {
|
||||
console.warn('Linked object found:' + object);
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
|
@ -124,7 +124,7 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
|||
} else {
|
||||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
} else if (typeof object == 'string') {
|
||||
} else if (typeof object === 'string') {
|
||||
console.warn('Linked object found:' + object);
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
|
@ -133,10 +133,16 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
|||
return idToObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Undefined or null check
|
||||
* @param variable
|
||||
* @returns {boolean}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Utils.UndefinedOrNull = function (
|
||||
variable
|
||||
) {
|
||||
return typeof variable == 'undefined' || variable == null;
|
||||
return typeof variable === 'undefined' || variable === null;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -199,15 +205,6 @@ GameLib.Utils.Link = function(propertyString, idToObject, parentObject, id) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.Utils.Raycast = function (
|
||||
from,
|
||||
to,
|
||||
options,
|
||||
world
|
||||
) {
|
||||
console.log("not implemented yet");
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a random ID
|
||||
* @returns {string}
|
||||
|
|
|
@ -57,6 +57,15 @@ GameLib.Component.prototype.getDependencies = function() {
|
|||
var dependencies = [];
|
||||
|
||||
for (var property in this.linkedObjects) {
|
||||
|
||||
// if (
|
||||
// property === 'parentMesh' ||
|
||||
// property === 'parentScene' ||
|
||||
// property === 'parentEntity'
|
||||
// ) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
//TODO array linked objects
|
||||
if (this.linkedObjects.hasOwnProperty(property)){
|
||||
if (this.hasOwnProperty(property)) {
|
||||
|
|
|
@ -30,6 +30,7 @@ GameLib.D3.Image = function(
|
|||
this,
|
||||
GameLib.Component.COMPONENT_IMAGE
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Image.prototype = Object.create(GameLib.D3.API.Image.prototype);
|
||||
|
|
|
@ -147,13 +147,13 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
|||
if (mesh.selected) {
|
||||
this.removeHelper(mesh, entity);
|
||||
entity.removeComponent(mesh);
|
||||
entity.buildIdToObject();
|
||||
console.log('entity.buildIdToObject()');
|
||||
|
||||
gui.removeObject(mesh);
|
||||
|
||||
var scene = mesh.parentScene;
|
||||
scene.removeObject(mesh);
|
||||
scene.buildIdToObject();
|
||||
console.log('scene.buildIdToObject()');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
|
|
@ -208,13 +208,29 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
|||
|
||||
instance.quaternion = this.quaternion.instance;
|
||||
|
||||
for (var im = 0; im < this.meshes.length; im++) {
|
||||
instance.add(this.meshes[im].instance);
|
||||
this.meshes.map(function(mesh){
|
||||
if (mesh instanceof GameLib.D3.Mesh) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh.instance)){
|
||||
console.warn('No mesh instance');
|
||||
throw new Error('No mesh instance');
|
||||
}
|
||||
instance.add(mesh.instance);
|
||||
} else {
|
||||
console.log('Unable to add mesh which should be loaded at this point');
|
||||
}
|
||||
});
|
||||
|
||||
for (var l = 0; l < this.lights.length; l++) {
|
||||
instance.add(this.lights[l].instance);
|
||||
this.lights.map(function(light){
|
||||
if (light instanceof GameLib.D3.Light) {
|
||||
if (GameLib.Utils.UndefinedOrNull(light.instance)){
|
||||
console.warn('No light instance');
|
||||
throw new Error('No light instance');
|
||||
}
|
||||
instance.add(light.instance)
|
||||
} else {
|
||||
console.log('Unable to add light which should be loaded at this point');
|
||||
}
|
||||
});
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
@ -327,6 +343,8 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
|
|||
|
||||
if (this.instance) {
|
||||
this.instance.add(object.instance);
|
||||
} else {
|
||||
console.warn('no scene instance');
|
||||
}
|
||||
|
||||
|
||||
|
@ -360,6 +378,8 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
|
|||
|
||||
if (this.instance) {
|
||||
this.instance.remove(object.instance);
|
||||
} else {
|
||||
console.warn('no scene instance');
|
||||
}
|
||||
|
||||
if (object.parentScene === this) {
|
||||
|
|
|
@ -25,6 +25,8 @@ GameLib.EntityManager = function() {
|
|||
|
||||
this.subscriptions = [];
|
||||
|
||||
this.register = {};
|
||||
|
||||
this.registerCallbacks();
|
||||
};
|
||||
|
||||
|
@ -378,6 +380,29 @@ GameLib.EntityManager.prototype.onParentEntityChange = function(data) {
|
|||
|
||||
};
|
||||
|
||||
|
||||
GameLib.EntityManager.prototype.link = function(component, data) {
|
||||
for (var property in component.linkedObjects) {
|
||||
if (component.linkedObjects.hasOwnProperty(property)) {
|
||||
if (component.linkedObjects[property] instanceof Array) {
|
||||
component[property] = component[property].map(function (entry) {
|
||||
if (entry === data.component.id) {
|
||||
return data.component;
|
||||
} else {
|
||||
return entry;
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
if (component[property] &&
|
||||
component[property] === data.component.id) {
|
||||
component[property] = data.component;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||
|
||||
console.log('component created : ' + data.component.name);
|
||||
|
@ -399,59 +424,131 @@ GameLib.EntityManager.prototype.componentCreated = function(data) {
|
|||
*/
|
||||
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
|
||||
*/
|
||||
var index = data.component.dependencies.indexOf(id);
|
||||
if (index === -1) {
|
||||
console.log('failed to locate dependency which should exist');
|
||||
}
|
||||
data.component.dependencies.splice(index, 1);
|
||||
|
||||
/**
|
||||
* Now link the component
|
||||
*/
|
||||
this.link(data.component, {component:this.register[id]});
|
||||
|
||||
} else {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.dependencies[id])) {
|
||||
this.dependencies[id] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't store duplicate dependencies
|
||||
*/
|
||||
if (this.dependencies[id].indexOf(data.component === -1)) {
|
||||
this.dependencies[id].push(data.component);
|
||||
}
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
|
||||
/**
|
||||
* Now find all the dependencies of this component
|
||||
* Now find all the components which depend on this component
|
||||
*/
|
||||
var dependencies = this.dependencies[data.component.id];
|
||||
if (GameLib.Utils.UndefinedOrNull(dependencies)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(this.dependencies[data.component.id])) {
|
||||
|
||||
/**
|
||||
* We have no dependencies, so mark our component as loaded and create an instance
|
||||
* We don't know about any dependencies on this object - but maybe a component still
|
||||
* has to load which has dependencies to this object
|
||||
*/
|
||||
data.component.loaded = true;
|
||||
data.component.instance = data.component.createInstance();
|
||||
|
||||
/**
|
||||
* If we have none, we are done and can exit
|
||||
*/
|
||||
return;
|
||||
}
|
||||
this.register[data.component.id] = data.component;
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Otherwise, now - for each dependency - update 'idToObject' and check if its loaded
|
||||
*/
|
||||
dependencies.map(function(component){
|
||||
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;
|
||||
|
||||
var loaded = true;
|
||||
|
||||
for (var property in component.idToObject) {
|
||||
if (
|
||||
component.idToObject.hasOwnProperty(property) &&
|
||||
component.idToObject[property] === null
|
||||
) {
|
||||
loaded = false
|
||||
}
|
||||
}
|
||||
|
||||
component.loaded = loaded;
|
||||
|
||||
if (component.loaded) {
|
||||
/**
|
||||
* Our component is fully loaded, time to create an instance of it
|
||||
* Remove the actual dependency
|
||||
*/
|
||||
component.instance = component.createInstance();
|
||||
var index = component.dependencies.indexOf(data.component.id);
|
||||
if (index === -1) {
|
||||
console.warn('dependency mismatch');
|
||||
} else {
|
||||
component.dependencies.splice(index, 1);
|
||||
}
|
||||
|
||||
})
|
||||
/**
|
||||
* Find the actual place where this object should be linked - and link them
|
||||
*/
|
||||
this.link(component, data);
|
||||
|
||||
/**
|
||||
* If we now managed to link the objects, and this object has no more dependencies
|
||||
*/
|
||||
if (component.dependencies.length === 0) {
|
||||
component.loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Also remove this from the current dependency list
|
||||
*/
|
||||
return result;
|
||||
}.bind(this),
|
||||
[]
|
||||
);
|
||||
|
||||
delete this.dependencies[data.component.id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Now if this new component has no dependencies, load it
|
||||
*/
|
||||
if (data.component.dependencies.length === 0) {
|
||||
data.component.loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
loaded = false;
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All components loaded
|
||||
*/
|
||||
if (loaded) {
|
||||
this.loaded.map(function(component){
|
||||
component.instance = component.createInstance();
|
||||
});
|
||||
this.loaded = [];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -245,13 +245,20 @@ GameLib.System.prototype.update = function(deltaTime) {
|
|||
function(renderEntity) {
|
||||
|
||||
var stats = renderEntity.getFirstComponent(GameLib.D3.Stats);
|
||||
stats.instance.begin();
|
||||
|
||||
if (!stats.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
var renderer = renderEntity.getFirstComponent(GameLib.D3.Renderer);
|
||||
var camera = renderEntity.getFirstComponent(GameLib.D3.Camera);
|
||||
var viewports = renderEntity.getComponents(GameLib.D3.Viewport);
|
||||
var scenes = renderEntity.getComponents(GameLib.D3.Scene);
|
||||
|
||||
if (!renderer.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (viewports.length > 1) {
|
||||
renderer.instance.autoClear = false;
|
||||
}
|
||||
|
@ -273,12 +280,27 @@ GameLib.System.prototype.update = function(deltaTime) {
|
|||
);
|
||||
|
||||
function renderScene(scene) {
|
||||
|
||||
if (!scene.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (scene.activeCamera) {
|
||||
|
||||
if (!scene.activeCamera.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.instance.render(
|
||||
scene.instance,
|
||||
scene.activeCamera.instance
|
||||
);
|
||||
} else {
|
||||
|
||||
if (!camera.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.instance.render(
|
||||
scene.instance,
|
||||
camera.instance
|
||||
|
|
Loading…
Reference in New Issue