fresh start
parent
0ff071bb6b
commit
dba92a70ba
File diff suppressed because one or more lines are too long
|
@ -166,6 +166,49 @@ GameLib.D3.Color = function(r, g, b, a) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.a = a;
|
this.a = a;
|
||||||
};
|
};
|
||||||
|
GameLib.D3.ComponentInterface = function(
|
||||||
|
componentId
|
||||||
|
) {
|
||||||
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
|
|
||||||
|
// this will maybe not used
|
||||||
|
this.parentEntity = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// will be not used
|
||||||
|
GameLib.D3.ComponentInterface.prototype.setParentEntity = function(
|
||||||
|
entity
|
||||||
|
) {
|
||||||
|
this.parentEntity = entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onUpdate = function(
|
||||||
|
deltaTime,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
//this.parentEntity.mesh.material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onLateUpdate = function(
|
||||||
|
deltaTime,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onRegistered = function(
|
||||||
|
parentScene
|
||||||
|
) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onSetParentEntity = function(
|
||||||
|
parentScene,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
//parentEntity.mesh.material = new THREE.MeshBasicMaterial();
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Engine Superset
|
* Engine Superset
|
||||||
* @param engineType
|
* @param engineType
|
||||||
|
@ -232,6 +275,58 @@ GameLib.D3.Entity = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
this.componentIds = componentIds;
|
this.componentIds = componentIds;
|
||||||
|
|
||||||
|
this.parentScene = null;
|
||||||
|
this.mesh = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var c in this.componentIds) {
|
||||||
|
var componentId = this.componentIds[c];
|
||||||
|
if(this.parentScene.componentIdToComponent[componentId]) {
|
||||||
|
this.parentScene.componentIdToComponent[componentId].onUpdate(deltaTime, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onLateUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var c in this.componentIds) {
|
||||||
|
var componentId = this.componentIds[c];
|
||||||
|
if(this.parentScene.componentIdToComponent[componentId]) {
|
||||||
|
this.parentScene.componentIdToComponent[componentId].onLateUpdate(deltaTime, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onRegistered = function(
|
||||||
|
parentScene
|
||||||
|
) {
|
||||||
|
this.parentScene = parentScene;
|
||||||
|
|
||||||
|
if(this.meshId != null && parentScene.meshIdToMesh[this.meshId]) {
|
||||||
|
parentScene.threeScene.add(parentScene.meshIdToMesh[this.meshId]);
|
||||||
|
this.mesh = parentScene.meshIdToMesh[this.meshId];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.addComponentId = function(
|
||||||
|
componentId
|
||||||
|
) {
|
||||||
|
this.componentIds.push(componentId);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.addComponent = function(
|
||||||
|
component
|
||||||
|
) {
|
||||||
|
this.parentScene.registerComponent(component);
|
||||||
|
|
||||||
|
this.componentIds.push(component.componentId);
|
||||||
|
component.setParentEntity(this);
|
||||||
|
component.onSetParentEntity(this.parentScene, this);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Fly Controls
|
* Fly Controls
|
||||||
|
@ -3000,6 +3095,16 @@ GameLib.D3.Scene = function(
|
||||||
entities = [];
|
entities = [];
|
||||||
}
|
}
|
||||||
this.entities = entities;
|
this.entities = entities;
|
||||||
|
|
||||||
|
// changes
|
||||||
|
this.threeScene = new THREE.Scene();
|
||||||
|
this.threeScene.render = true;
|
||||||
|
|
||||||
|
// assoc array
|
||||||
|
this.meshIdToMesh = {};
|
||||||
|
|
||||||
|
// assoc array
|
||||||
|
this.componentIdToComponent = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3547,6 +3652,85 @@ GameLib.D3.Scene.loadScene = function(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - RUNTIME FUNCTIONS - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.update = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var e in this.entities) {
|
||||||
|
this.entities[e].onUpdate(deltaTime);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.lateUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var e in this.entities) {
|
||||||
|
this.entities[e].onLateUpdate(deltaTime);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renders the scene
|
||||||
|
* @param deltaTime
|
||||||
|
* @param renderer
|
||||||
|
* @param camera
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.render = function(
|
||||||
|
deltaTime,
|
||||||
|
renderer,
|
||||||
|
camera
|
||||||
|
) {
|
||||||
|
renderer.render(this.threeScene, camera);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.registerEntity = function(
|
||||||
|
entity
|
||||||
|
) {
|
||||||
|
this.entities.push(entity);
|
||||||
|
entity.onRegistered(this);
|
||||||
|
|
||||||
|
// link components to entity
|
||||||
|
for(var c in entity.componentIds) {
|
||||||
|
var componentId = entity.componentIds[c];
|
||||||
|
|
||||||
|
var component = this.componentIdToComponent[componentId];
|
||||||
|
if(component) {
|
||||||
|
component.setParentEntity(entity);
|
||||||
|
component.onSetParentEntity(this, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Scene.prototype.registerComponent = function(
|
||||||
|
component
|
||||||
|
) {
|
||||||
|
this.componentIdToComponent[component.componentId] = component;
|
||||||
|
if(component.onRegistered && typeof component.onRegistered == 'function') {
|
||||||
|
component.onRegistered(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Scene.prototype.registerLight = function(
|
||||||
|
light
|
||||||
|
) {
|
||||||
|
this.threeScene.add(light);
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Physics Shape Superset
|
* Physics Shape Superset
|
||||||
* @param engine GameLib.D3.Engine
|
* @param engine GameLib.D3.Engine
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
GameLib.D3.ComponentInterface = function(
|
||||||
|
componentId
|
||||||
|
) {
|
||||||
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
|
|
||||||
|
// this will maybe not used
|
||||||
|
this.parentEntity = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// will be not used
|
||||||
|
GameLib.D3.ComponentInterface.prototype.setParentEntity = function(
|
||||||
|
entity
|
||||||
|
) {
|
||||||
|
this.parentEntity = entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onUpdate = function(
|
||||||
|
deltaTime,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
//this.parentEntity.mesh.material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onLateUpdate = function(
|
||||||
|
deltaTime,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onRegistered = function(
|
||||||
|
parentScene
|
||||||
|
) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameLib.D3.ComponentInterface.prototype.onSetParentEntity = function(
|
||||||
|
parentScene,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
//parentEntity.mesh.material = new THREE.MeshBasicMaterial();
|
||||||
|
};
|
|
@ -9,4 +9,56 @@ GameLib.D3.Entity = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
this.componentIds = componentIds;
|
this.componentIds = componentIds;
|
||||||
|
|
||||||
|
this.parentScene = null;
|
||||||
|
this.mesh = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var c in this.componentIds) {
|
||||||
|
var componentId = this.componentIds[c];
|
||||||
|
if(this.parentScene.componentIdToComponent[componentId]) {
|
||||||
|
this.parentScene.componentIdToComponent[componentId].onUpdate(deltaTime, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onLateUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var c in this.componentIds) {
|
||||||
|
var componentId = this.componentIds[c];
|
||||||
|
if(this.parentScene.componentIdToComponent[componentId]) {
|
||||||
|
this.parentScene.componentIdToComponent[componentId].onLateUpdate(deltaTime, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.onRegistered = function(
|
||||||
|
parentScene
|
||||||
|
) {
|
||||||
|
this.parentScene = parentScene;
|
||||||
|
|
||||||
|
if(this.meshId != null && parentScene.meshIdToMesh[this.meshId]) {
|
||||||
|
parentScene.threeScene.add(parentScene.meshIdToMesh[this.meshId]);
|
||||||
|
this.mesh = parentScene.meshIdToMesh[this.meshId];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.addComponentId = function(
|
||||||
|
componentId
|
||||||
|
) {
|
||||||
|
this.componentIds.push(componentId);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Entity.prototype.addComponent = function(
|
||||||
|
component
|
||||||
|
) {
|
||||||
|
this.parentScene.registerComponent(component);
|
||||||
|
|
||||||
|
this.componentIds.push(component.componentId);
|
||||||
|
component.setParentEntity(this);
|
||||||
|
component.onSetParentEntity(this.parentScene, this);
|
||||||
};
|
};
|
|
@ -80,6 +80,16 @@ GameLib.D3.Scene = function(
|
||||||
entities = [];
|
entities = [];
|
||||||
}
|
}
|
||||||
this.entities = entities;
|
this.entities = entities;
|
||||||
|
|
||||||
|
// changes
|
||||||
|
this.threeScene = new THREE.Scene();
|
||||||
|
this.threeScene.render = true;
|
||||||
|
|
||||||
|
// assoc array
|
||||||
|
this.meshIdToMesh = {};
|
||||||
|
|
||||||
|
// assoc array
|
||||||
|
this.componentIdToComponent = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -626,4 +636,83 @@ GameLib.D3.Scene.loadScene = function(
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - RUNTIME FUNCTIONS - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.update = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var e in this.entities) {
|
||||||
|
this.entities[e].onUpdate(deltaTime);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.lateUpdate = function(
|
||||||
|
deltaTime
|
||||||
|
) {
|
||||||
|
for(var e in this.entities) {
|
||||||
|
this.entities[e].onLateUpdate(deltaTime);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renders the scene
|
||||||
|
* @param deltaTime
|
||||||
|
* @param renderer
|
||||||
|
* @param camera
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.render = function(
|
||||||
|
deltaTime,
|
||||||
|
renderer,
|
||||||
|
camera
|
||||||
|
) {
|
||||||
|
renderer.render(this.threeScene, camera);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the scene
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.registerEntity = function(
|
||||||
|
entity
|
||||||
|
) {
|
||||||
|
this.entities.push(entity);
|
||||||
|
entity.onRegistered(this);
|
||||||
|
|
||||||
|
// link components to entity
|
||||||
|
for(var c in entity.componentIds) {
|
||||||
|
var componentId = entity.componentIds[c];
|
||||||
|
|
||||||
|
var component = this.componentIdToComponent[componentId];
|
||||||
|
if(component) {
|
||||||
|
component.setParentEntity(entity);
|
||||||
|
component.onSetParentEntity(this, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Scene.prototype.registerComponent = function(
|
||||||
|
component
|
||||||
|
) {
|
||||||
|
this.componentIdToComponent[component.componentId] = component;
|
||||||
|
if(component.onRegistered && typeof component.onRegistered == 'function') {
|
||||||
|
component.onRegistered(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Scene.prototype.registerLight = function(
|
||||||
|
light
|
||||||
|
) {
|
||||||
|
this.threeScene.add(light);
|
||||||
};
|
};
|
Loading…
Reference in New Issue