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)
|
console.warn('Object with no ID passed: ' + object)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (typeof object == 'string') {
|
} else if (typeof object === 'string') {
|
||||||
console.warn('Linked object found:' + object);
|
console.warn('Linked object found:' + object);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Unhandled type of object: ', object);
|
console.warn('Unhandled type of object: ', object);
|
||||||
|
@ -124,7 +124,7 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
||||||
} else {
|
} else {
|
||||||
console.warn('Object with no ID passed: ' + object)
|
console.warn('Object with no ID passed: ' + object)
|
||||||
}
|
}
|
||||||
} else if (typeof object == 'string') {
|
} else if (typeof object === 'string') {
|
||||||
console.warn('Linked object found:' + object);
|
console.warn('Linked object found:' + object);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Unhandled type of object: ', object);
|
console.warn('Unhandled type of object: ', object);
|
||||||
|
@ -133,10 +133,16 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
||||||
return idToObject;
|
return idToObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undefined or null check
|
||||||
|
* @param variable
|
||||||
|
* @returns {boolean}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
GameLib.Utils.UndefinedOrNull = function (
|
GameLib.Utils.UndefinedOrNull = function (
|
||||||
variable
|
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
|
* Generates a random ID
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
|
|
@ -57,6 +57,15 @@ GameLib.Component.prototype.getDependencies = function() {
|
||||||
var dependencies = [];
|
var dependencies = [];
|
||||||
|
|
||||||
for (var property in this.linkedObjects) {
|
for (var property in this.linkedObjects) {
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// property === 'parentMesh' ||
|
||||||
|
// property === 'parentScene' ||
|
||||||
|
// property === 'parentEntity'
|
||||||
|
// ) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
//TODO array linked objects
|
//TODO array linked objects
|
||||||
if (this.linkedObjects.hasOwnProperty(property)){
|
if (this.linkedObjects.hasOwnProperty(property)){
|
||||||
if (this.hasOwnProperty(property)) {
|
if (this.hasOwnProperty(property)) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ GameLib.D3.Image = function(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_IMAGE
|
GameLib.Component.COMPONENT_IMAGE
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Image.prototype = Object.create(GameLib.D3.API.Image.prototype);
|
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) {
|
if (mesh.selected) {
|
||||||
this.removeHelper(mesh, entity);
|
this.removeHelper(mesh, entity);
|
||||||
entity.removeComponent(mesh);
|
entity.removeComponent(mesh);
|
||||||
entity.buildIdToObject();
|
console.log('entity.buildIdToObject()');
|
||||||
|
|
||||||
gui.removeObject(mesh);
|
gui.removeObject(mesh);
|
||||||
|
|
||||||
var scene = mesh.parentScene;
|
var scene = mesh.parentScene;
|
||||||
scene.removeObject(mesh);
|
scene.removeObject(mesh);
|
||||||
scene.buildIdToObject();
|
console.log('scene.buildIdToObject()');
|
||||||
}
|
}
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
|
@ -208,13 +208,29 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
||||||
|
|
||||||
instance.quaternion = this.quaternion.instance;
|
instance.quaternion = this.quaternion.instance;
|
||||||
|
|
||||||
for (var im = 0; im < this.meshes.length; im++) {
|
this.meshes.map(function(mesh){
|
||||||
instance.add(this.meshes[im].instance);
|
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++) {
|
this.lights.map(function(light){
|
||||||
instance.add(this.lights[l].instance);
|
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;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -327,6 +343,8 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
|
||||||
|
|
||||||
if (this.instance) {
|
if (this.instance) {
|
||||||
this.instance.add(object.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) {
|
if (this.instance) {
|
||||||
this.instance.remove(object.instance);
|
this.instance.remove(object.instance);
|
||||||
|
} else {
|
||||||
|
console.warn('no scene instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.parentScene === this) {
|
if (object.parentScene === this) {
|
||||||
|
|
|
@ -25,6 +25,8 @@ GameLib.EntityManager = function() {
|
||||||
|
|
||||||
this.subscriptions = [];
|
this.subscriptions = [];
|
||||||
|
|
||||||
|
this.register = {};
|
||||||
|
|
||||||
this.registerCallbacks();
|
this.registerCallbacks();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,80 +380,175 @@ 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) {
|
GameLib.EntityManager.prototype.componentCreated = function(data) {
|
||||||
|
|
||||||
console.log('component created : ' + data.component.name);
|
console.log('component created : ' + data.component.name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we notify ourselves - ignore it
|
* If we notify ourselves - ignore it
|
||||||
*/
|
*/
|
||||||
if (data.component === this) {
|
if (data.component === this) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store this component into our 'loaded' list
|
* Store this component into our 'loaded' list
|
||||||
*/
|
*/
|
||||||
this.loaded.push(data.component);
|
this.loaded.push(data.component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the dependencies too
|
* Store the dependencies too
|
||||||
*/
|
*/
|
||||||
data.component.dependencies.map(function(id) {
|
data.component.dependencies.map(function(id) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.dependencies[id])) {
|
/**
|
||||||
this.dependencies[id] = [];
|
* Check if we already processed a component on which this component is dependent
|
||||||
}
|
*/
|
||||||
|
if (this.register.hasOwnProperty(id)) {
|
||||||
|
|
||||||
this.dependencies[id].push(data.component);
|
console.log('found a component here');
|
||||||
|
|
||||||
}.bind(this));
|
/**
|
||||||
|
* First add this to the 'idToObject'
|
||||||
|
*/
|
||||||
|
data.component.idToObject[id] = this.register[id];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now find all the dependencies of this component
|
* Remove this dependency from the dependency list
|
||||||
*/
|
*/
|
||||||
var dependencies = this.dependencies[data.component.id];
|
var index = data.component.dependencies.indexOf(id);
|
||||||
if (GameLib.Utils.UndefinedOrNull(dependencies)) {
|
if (index === -1) {
|
||||||
|
console.log('failed to locate dependency which should exist');
|
||||||
|
}
|
||||||
|
data.component.dependencies.splice(index, 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We have no dependencies, so mark our component as loaded and create an instance
|
* Now link the component
|
||||||
*/
|
*/
|
||||||
data.component.loaded = true;
|
this.link(data.component, {component:this.register[id]});
|
||||||
data.component.instance = data.component.createInstance();
|
|
||||||
|
|
||||||
/**
|
} else {
|
||||||
* If we have none, we are done and can exit
|
|
||||||
*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (GameLib.Utils.UndefinedOrNull(this.dependencies[id])) {
|
||||||
* Otherwise, now - for each dependency - update 'idToObject' and check if its loaded
|
this.dependencies[id] = [];
|
||||||
*/
|
}
|
||||||
dependencies.map(function(component){
|
|
||||||
component.idToObject[data.component.id] = data.component;
|
|
||||||
|
|
||||||
var loaded = true;
|
/**
|
||||||
|
* Don't store duplicate dependencies
|
||||||
|
*/
|
||||||
|
if (this.dependencies[id].indexOf(data.component === -1)) {
|
||||||
|
this.dependencies[id].push(data.component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var property in component.idToObject) {
|
}.bind(this));
|
||||||
if (
|
|
||||||
component.idToObject.hasOwnProperty(property) &&
|
|
||||||
component.idToObject[property] === null
|
|
||||||
) {
|
|
||||||
loaded = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
component.loaded = loaded;
|
/**
|
||||||
|
* Now find all the components which depend on this component
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.dependencies[data.component.id])) {
|
||||||
|
|
||||||
if (component.loaded) {
|
/**
|
||||||
/**
|
* We don't know about any dependencies on this object - but maybe a component still
|
||||||
* Our component is fully loaded, time to create an instance of it
|
* has to load which has dependencies to this object
|
||||||
*/
|
*/
|
||||||
component.instance = component.createInstance();
|
this.register[data.component.id] = data.component;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
})
|
/**
|
||||||
|
* Otherwise, now - for each dependency - update 'idToObject' and 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the actual dependency
|
||||||
|
*/
|
||||||
|
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
|
* Properties changed - rebuild the object list in the parent
|
||||||
*/
|
*/
|
||||||
parentObject.buildIdToObject();
|
console.log('parentObject.buildIdToObject();');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties changed - rebuild GUI
|
* Properties changed - rebuild GUI
|
||||||
|
|
|
@ -245,13 +245,20 @@ GameLib.System.prototype.update = function(deltaTime) {
|
||||||
function(renderEntity) {
|
function(renderEntity) {
|
||||||
|
|
||||||
var stats = renderEntity.getFirstComponent(GameLib.D3.Stats);
|
var stats = renderEntity.getFirstComponent(GameLib.D3.Stats);
|
||||||
stats.instance.begin();
|
|
||||||
|
if (!stats.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var renderer = renderEntity.getFirstComponent(GameLib.D3.Renderer);
|
var renderer = renderEntity.getFirstComponent(GameLib.D3.Renderer);
|
||||||
var camera = renderEntity.getFirstComponent(GameLib.D3.Camera);
|
var camera = renderEntity.getFirstComponent(GameLib.D3.Camera);
|
||||||
var viewports = renderEntity.getComponents(GameLib.D3.Viewport);
|
var viewports = renderEntity.getComponents(GameLib.D3.Viewport);
|
||||||
var scenes = renderEntity.getComponents(GameLib.D3.Scene);
|
var scenes = renderEntity.getComponents(GameLib.D3.Scene);
|
||||||
|
|
||||||
|
if (!renderer.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (viewports.length > 1) {
|
if (viewports.length > 1) {
|
||||||
renderer.instance.autoClear = false;
|
renderer.instance.autoClear = false;
|
||||||
}
|
}
|
||||||
|
@ -273,12 +280,27 @@ GameLib.System.prototype.update = function(deltaTime) {
|
||||||
);
|
);
|
||||||
|
|
||||||
function renderScene(scene) {
|
function renderScene(scene) {
|
||||||
|
|
||||||
|
if (!scene.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (scene.activeCamera) {
|
if (scene.activeCamera) {
|
||||||
|
|
||||||
|
if (!scene.activeCamera.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
renderer.instance.render(
|
renderer.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
scene.activeCamera.instance
|
scene.activeCamera.instance
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if (!camera.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
renderer.instance.render(
|
renderer.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
camera.instance
|
camera.instance
|
||||||
|
|
Loading…
Reference in New Issue