render mode stable

beta.r3js.org
-=yb4f310 2018-01-12 14:57:15 +01:00
parent c428e635c4
commit 23a66225ef
14 changed files with 163 additions and 51 deletions

View File

@ -97,7 +97,7 @@ GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
GameLib.Event.CAST_SOURCE_CHANGED = 0x50; GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
// GameLib.Event.GET_SCENE = 0x53; GameLib.Event.DOM_ELEMENT_CHANGE = 0x53;
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54; GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55; GameLib.Event.LOAD_FONT = 0x55;
GameLib.Event.FONT_NOT_FOUND = 0x56; GameLib.Event.FONT_NOT_FOUND = 0x56;
@ -215,7 +215,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x50 : return 'cast_source_changed'; case 0x50 : return 'cast_source_changed';
case 0x51 : return 'animation_mesh_added'; case 0x51 : return 'animation_mesh_added';
case 0x52 : return 'animation_mesh_removed'; case 0x52 : return 'animation_mesh_removed';
case 0x53 : return 'unused';//return 'get_scene'; case 0x53 : return 'dom_element_change';
case 0x54 : return 'custom_code_window_resize'; case 0x54 : return 'custom_code_window_resize';
case 0x55 : return 'load_font'; case 0x55 : return 'load_font';
case 0x56 : return 'font_not_found'; case 0x56 : return 'font_not_found';

View File

@ -11,7 +11,30 @@ GameLib.API.Component = function(
this.componentType = componentType; this.componentType = componentType;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
if (this instanceof GameLib.EntityManager) {
parentEntity = this.defaultEntity;
} else {
parentEntity = GameLib.EntityManager.Instance.defaultEntity;
if (parentEntity) {
if (parentEntity.id === this.id) {
/**
* This is the default entity, it cannot be the parent entity of itself - so terminate here.
*/
console.log('terminating here');
parentEntity = null;
} else {
parentEntity.addComponent(this);
}
}
}
} }
this.parentEntity = parentEntity; this.parentEntity = parentEntity;
}; };

View File

@ -1151,13 +1151,9 @@ GameLib.Component.prototype.save = function(remote) {
}.bind(this) }.bind(this)
); );
for (var property in this.idToObject) { Object.keys(this.idToObject).map(
if ( function(componentId) {
this.idToObject.hasOwnProperty(property) && var apiObject = this.idToObject[componentId].toApiObject();
this.idToObject[property] instanceof GameLib.Component
) {
var apiObject = this.idToObject[property].toApiObject();
toSave.push(apiObject); toSave.push(apiObject);
@ -1166,10 +1162,17 @@ GameLib.Component.prototype.save = function(remote) {
{ {
apiObject: apiObject, apiObject: apiObject,
remote: remote remote: remote
},
function success(result) {
console.log(result);
},
function error(error) {
console.log(error);
} }
); );
}
} }.bind(this)
);
}; };
/** /**

View File

@ -4,12 +4,14 @@
* @param id * @param id
* @param name * @param name
* @param entities GameLib.API.Entity[] * @param entities GameLib.API.Entity[]
* @param defaultEntity
* @param parentEntity * @param parentEntity
*/ */
GameLib.API.EntityManager = function( GameLib.API.EntityManager = function(
id, id,
name, name,
entities, entities,
defaultEntity,
parentEntity parentEntity
) { ) {
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
@ -27,6 +29,11 @@ GameLib.API.EntityManager = function(
} }
this.entities = entities; this.entities = entities;
if (GameLib.Utils.UndefinedOrNull(defaultEntity)) {
defaultEntity = null;
}
this.defaultEntity = defaultEntity;
GameLib.API.Component.call( GameLib.API.Component.call(
this, this,
GameLib.Component.ENTITY_MANAGER, GameLib.Component.ENTITY_MANAGER,
@ -54,6 +61,7 @@ GameLib.API.EntityManager.FromObject = function(objectEntityManager) {
objectEntityManager.id, objectEntityManager.id,
objectEntityManager.name, objectEntityManager.name,
apiEntities, apiEntities,
objectEntityManager.defaultEntity,
objectEntityManager.parentEntity objectEntityManager.parentEntity
); );
}; };

View File

@ -56,7 +56,17 @@ GameLib.Controls.prototype.createInstance = function() {
/** /**
* Updates the mesh instance * Updates the mesh instance
*/ */
GameLib.Controls.prototype.updateInstance = function() { GameLib.Controls.prototype.updateInstance = function(property) {
if (property === 'domElement') {
GameLib.Event.Emit(
GameLib.Event.DOM_ELEMENT_CHANGE,
{
component: this
}
);
}
console.log('default controls update instance'); console.log('default controls update instance');
}; };

View File

@ -46,8 +46,8 @@ GameLib.Controls.Mouse.prototype.createInstance = function() {
/** /**
* Update Instance * Update Instance
*/ */
GameLib.Controls.Mouse.prototype.updateInstance = function() { GameLib.Controls.Mouse.prototype.updateInstance = function(property) {
GameLib.Controls.prototype.updateInstance.call(this); GameLib.Controls.prototype.updateInstance.call(this, property);
}; };
/** /**

View File

@ -115,7 +115,7 @@ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){
objectMesh.heightMapScale, objectMesh.heightMapScale,
objectMesh.isHeightMap, objectMesh.isHeightMap,
objectMesh.isDotMap, objectMesh.isDotMap,
GameLib.Utils.IdOrNull(objectMesh.dotObject) objectMesh.dotObject
); );
}; };

View File

@ -122,7 +122,7 @@ GameLib.D3.API.Renderer = function (
this.renderMode = renderMode; this.renderMode = renderMode;
if (GameLib.Utils.UndefinedOrNull(lastRenderMode)) { if (GameLib.Utils.UndefinedOrNull(lastRenderMode)) {
lastRenderMode = this.renderMode; lastRenderMode = GameLib.D3.API.Renderer.MODE_CANVAS;
} }
this.lastRenderMode = lastRenderMode; this.lastRenderMode = lastRenderMode;

View File

@ -142,7 +142,7 @@ GameLib.D3.Mesh = function (
linkedObjects.font = GameLib.D3.Font; linkedObjects.font = GameLib.D3.Font;
} }
/** /**
* Runtime meshes have helpers too * Runtime meshes have helpers too
* @type {null} * @type {null}
*/ */

View File

@ -118,7 +118,18 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
property === 'isDotMap' || property === 'isDotMap' ||
property === 'dotObject' property === 'dotObject'
) { ) {
this.generateDotMap(); this.dots.map(
function(dot){
this.parentScene.instance.remove(dot);
dot.geometry.dispose();
dot.material.dispose();
}.bind(this)
);
if (this.isDotMap) {
this.generateDotMap();
}
} }
GameLib.D3.Mesh.prototype.updateInstance.call(this, property); GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
@ -139,7 +150,7 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
this.heightMapScale, this.heightMapScale,
this.isHeightMap, this.isHeightMap,
this.isDotMap, this.isDotMap,
this.dotObject GameLib.Utils.IdOrNull(this.dotObject)
); );
return apiMeshPlane; return apiMeshPlane;
@ -215,13 +226,6 @@ GameLib.D3.Mesh.Plane.prototype.getHeightData = function() {
GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() { GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
this.dots.map(
function(dot){
// this.parentScene.instance.remove(dot);
// dot.geometry.dispose();
}.bind(this)
);
this.dots = []; this.dots = [];
var data = this.getHeightData(); var data = this.getHeightData();
@ -232,11 +236,18 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
for (var x = 0; x < width; x++) { for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++ ) { for (var y = 0; y < height; y++ ) {
var geometry = new THREE.BoxBufferGeometry(0.5,0.5,0.5); var geometry;
var material;
var materialInstance = this.materials[0].instance; if (this.dotObject) {
geometry = this.dotObject.instance.geometry.clone();
material = this.dotObject.materials[0].instance;
} else {
geometry = new THREE.BoxBufferGeometry(0.5, 0.5, 0.5);
material = this.materials[0].instance;
}
var dot = new THREE.Mesh(geometry, materialInstance); var dot = new THREE.Mesh(geometry, material);
dot.position.x = x; dot.position.x = x;
dot.position.y = y; dot.position.y = y;
dot.position.z = data[(y * width) + x]; dot.position.z = data[(y * width) + x];

View File

@ -13,6 +13,7 @@ GameLib.EntityManager = function(apiEntityManager) {
apiEntityManager.id, apiEntityManager.id,
apiEntityManager.name, apiEntityManager.name,
apiEntityManager.entities, apiEntityManager.entities,
apiEntityManager.defaultEntity,
apiEntityManager.parentEntity apiEntityManager.parentEntity
); );
@ -40,10 +41,17 @@ GameLib.EntityManager = function(apiEntityManager) {
this.removeComponent.bind(this) this.removeComponent.bind(this)
); );
GameLib.Event.Subscribe(
GameLib.Event.ENTITY_LOADED,
this.entityLoaded.bind(this)
);
GameLib.Component.call( GameLib.Component.call(
this, this,
{ {
'entities' : [GameLib.Entity] 'entities' : [GameLib.Entity],
'defaultEntity' : GameLib.Entity
} }
); );
}; };
@ -62,6 +70,10 @@ GameLib.EntityManager.prototype.instanceCreated = function(data) {
} }
}; };
GameLib.EntityManager.prototype.entityLoaded = function(data) {
this.defaultEntity = data.entity;
};
GameLib.EntityManager.prototype.registerComponent = function(data) { GameLib.EntityManager.prototype.registerComponent = function(data) {
var updated = false; var updated = false;
@ -380,6 +392,7 @@ GameLib.EntityManager.prototype.toApiObject = function() {
this.id, this.id,
this.name, this.name,
apiEntities, apiEntities,
this.defaultEntity,
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );

View File

@ -46,20 +46,23 @@ GameLib.Entity.prototype.createInstance = function() {
*/ */
GameLib.Entity.prototype.addComponent = function(component) { GameLib.Entity.prototype.addComponent = function(component) {
GameLib.Utils.PushUnique(this.components, component);
if (component instanceof GameLib.D3.Mesh) {
/** // if (component instanceof GameLib.D3.Mesh) {
* For meshes, simply get the children components //
* @type {Array} // /**
*/ // * For meshes, simply get the children components
component.getChildrenComponents().map(function(childComponent){ // * @type {Array}
GameLib.Utils.PushUnique(this.components, childComponent); // */
childComponent.parentEntity = this; // component.getChildrenComponents().map(function(childComponent){
}.bind(this)) // GameLib.Utils.PushUnique(this.components, childComponent);
// childComponent.parentEntity = this;
// }.bind(this))
//
// } else {
if (component instanceof GameLib.Component) {
} else {
/** /**
* Here we will dig into this component - find all its 'parentEntity' members - and update them accordingly * Here we will dig into this component - find all its 'parentEntity' members - and update them accordingly
*/ */
@ -68,16 +71,16 @@ GameLib.Entity.prototype.addComponent = function(component) {
/** /**
* Also add the child components of this component as components of this entity * Also add the child components of this component as components of this entity
*/ */
for (var property in component.idToObject) { Object.keys(component.idToObject).map(
if (component.idToObject.hasOwnProperty(property) && function(componentId) {
component.idToObject[property] !== component && GameLib.Utils.PushUnique(this.components, component.idToObject[componentId]);
component.idToObject[property] instanceof GameLib.Component component.idToObject[componentId].parentEntity = this;
) { }.bind(this)
GameLib.Utils.PushUnique(this.components, component.idToObject[property]); );
component.idToObject[property].parentEntity = this;
} GameLib.Utils.PushUnique(this.components, component);
}
} }
// }
/** /**

View File

@ -62,6 +62,7 @@ GameLib.System.Input = function(
this.delayedInstanceEncounteredSubscription = null; this.delayedInstanceEncounteredSubscription = null;
this.instanceCreatedSubscription = null; this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null; this.removeComponentSubscription = null;
this.domElementChangeSubscription = null;
this.mouse = new GameLib.Mouse(); this.mouse = new GameLib.Mouse();
}; };
@ -91,6 +92,11 @@ GameLib.System.Input.prototype.start = function() {
this.delayedInstanceEncountered.bind(this) this.delayedInstanceEncountered.bind(this)
); );
this.domElementChangeSubscription = GameLib.Event.Subscribe(
GameLib.Event.DOM_ELEMENT_CHANGE,
this.domElementChange.bind(this)
);
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR); this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR);
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH); this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH);
@ -141,6 +147,8 @@ GameLib.System.Input.prototype.stop = function() {
this.delayedInstanceEncounteredSubscription.remove(); this.delayedInstanceEncounteredSubscription.remove();
this.domElementChangeSubscription.remove();
this.touchControls.map( this.touchControls.map(
function(touchControl){ function(touchControl){
this.deRegisterTouchControls(touchControl); this.deRegisterTouchControls(touchControl);
@ -175,6 +183,16 @@ GameLib.System.Input.prototype.stop = function() {
}; };
/**
*
* @param data
*/
GameLib.System.Input.prototype.domElementChange = function(data) {
if (data.component instanceof GameLib.Controls) {
console.log('todo: implement dom element change');
}
};
/** /**
* From now on we want to track everything about a component, only from the systems that are active * From now on we want to track everything about a component, only from the systems that are active
* @param data * @param data
@ -312,6 +330,11 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) {
GameLib.System.Input.prototype.registerTouchControls = function(touchControl) { GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
if (!touchControl.domElement || !touchControl.domElement.instance) {
console.warn('no domElement at time of registration of touch controls - this part will be skipped');
return;
}
touchControl.domElement.instance.addEventListener( touchControl.domElement.instance.addEventListener(
'touchstart', 'touchstart',
this.touchStart, this.touchStart,
@ -337,6 +360,11 @@ GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) { GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) {
if (!keyboardControl.domElement || !keyboardControl.domElement.instance) {
console.warn('no domElement at time of registration of keyboard controls - this part will be skipped');
return;
}
keyboardControl.domElement.instance.addEventListener( keyboardControl.domElement.instance.addEventListener(
'keyup', 'keyup',
this.keyboardKeyUp, this.keyboardKeyUp,
@ -352,6 +380,11 @@ GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardContr
GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) { GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
if (!mouseControl.domElement || !mouseControl.domElement.instance) {
console.warn('no domElement at time of registration of mouse controls - this part will be skipped');
return;
}
mouseControl.domElement.instance.addEventListener( mouseControl.domElement.instance.addEventListener(
'mousedown', 'mousedown',
this.mouseDown, this.mouseDown,
@ -401,6 +434,11 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl)
// }.bind(this) // }.bind(this)
// ); // );
if (!editorControl.domElement || !editorControl.domElement.instance) {
console.warn('no domElement at time of registration of editor controls - are you sure you know what you are doing?');
return;
}
editorControl.domElement.instance.addEventListener( editorControl.domElement.instance.addEventListener(
'mousedown', 'mousedown',
this.mouseDownEdit, this.mouseDownEdit,

View File

@ -287,6 +287,9 @@ GameLib.System.Storage.prototype.save = function(data) {
component : data.apiObject, component : data.apiObject,
session : this.token session : this.token
})); }));
},
function error(error){
console.log(error);
} }
); );