clock, linking system updates, physics updates, animation system started

beta.r3js.org
-=yb4f310 2017-09-14 05:42:38 +02:00
parent 01b36238f9
commit 74ef87c6aa
22 changed files with 381 additions and 47 deletions

View File

@ -81,6 +81,7 @@ GameLib.Event.FETCH_COMPONENTS = 0x3f;
GameLib.Event.GET_API_URL = 0x40; GameLib.Event.GET_API_URL = 0x40;
GameLib.Event.GET_PHYSICS_ENGINE = 0x41; GameLib.Event.GET_PHYSICS_ENGINE = 0x41;
GameLib.Event.PARENT_WORLD_CHANGE = 0x42; GameLib.Event.PARENT_WORLD_CHANGE = 0x42;
GameLib.Event.ANIMATE = 0x43;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -157,6 +158,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x40 : return 'get_api_url'; case 0x40 : return 'get_api_url';
case 0x41 : return 'get_physics_engine'; case 0x41 : return 'get_physics_engine';
case 0x42 : return 'parent_world_change'; case 0x42 : return 'parent_world_change';
case 0x43 : return 'animate';
break; break;
} }
@ -378,6 +380,13 @@ GameLib.Event.Emit = function(
} }
) )
} else { } else {
if (clientCallback) {
/**
* We execute the client callback immediately since there are no subscriptions to this event
*/
clientCallback();
}
if (clientErrorCallback) { if (clientErrorCallback) {
clientErrorCallback({ clientErrorCallback({
message : 'No subscriptions for event ' + eventName message : 'No subscriptions for event ' + eventName

View File

@ -150,6 +150,7 @@ GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33;
GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34; GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34;
GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35; GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35;
GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36; GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36;
GameLib.Component.COMPONENT_CLOCK = 0x37;
/** /**
* Returns string name for component number * Returns string name for component number
@ -213,6 +214,7 @@ GameLib.Component.GetComponentName = function(number) {
case 0x34 : return 'GameLib.D3.FrictionContactMaterial'; case 0x34 : return 'GameLib.D3.FrictionContactMaterial';
case 0x35 : return 'GameLib.D3.RaycastVehicle'; case 0x35 : return 'GameLib.D3.RaycastVehicle';
case 0x36 : return 'GameLib.D3.RaycastWheel'; case 0x36 : return 'GameLib.D3.RaycastWheel';
case 0x37 : return 'GameLib.Clock';
break; break;
} }

46
src/game-lib-api-clock.js Normal file
View File

@ -0,0 +1,46 @@
/**
* Raw Clock API object - should always correspond with the Clock Schema
* @constructor
* @param id
* @param name
* @param parentEntity
*/
GameLib.API.Clock = function(
id,
name,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Clock (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.API.Clock.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.Clock.prototype.constructor = GameLib.API.Clock;
/**
* Creates an API camera from an Object camera
* @param objectClock
* @constructor
*/
GameLib.API.Clock.FromObject = function(objectClock) {
return new GameLib.API.Clock(
objectClock.id,
objectClock.name,
objectClock.parentEntity
);
};

104
src/game-lib-clock.js Normal file
View File

@ -0,0 +1,104 @@
/**
* Creates a camera object
* @param implementation
* @param apiClock GameLib.API.Clock
* @constructor
*/
GameLib.Clock = function(
implementation,
apiClock
) {
this.implementation = implementation;
this.implementation.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiClock)) {
apiClock = {};
}
if (apiClock instanceof GameLib.Clock) {
return apiClock;
}
GameLib.API.Clock.call(
this,
apiClock.id,
apiClock.name,
apiClock.parentEntity
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CLOCK
);
} ;
GameLib.Clock.prototype = Object.create(GameLib.API.Clock.prototype);
GameLib.Clock.prototype.constructor = GameLib.Clock;
/**
* Creates a camera instance of 'graphics' type (only THREE for now)
* @returns {THREE.Clock}
*/
GameLib.Clock.prototype.createInstance = function() {
var instance = new THREE.Clock();
return instance;
};
/**
* Updates the instance with the current state
*/
GameLib.Clock.prototype.updateInstance = function() {
};
GameLib.Clock.prototype.getDelta = function() {
var delta = this.instance.getDelta();
/**
* clamp the delta to 1/60
*/
if (delta > (1 / 30.0)) {
console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time');
delta = (1 / 30.0);
}
return delta;
};
/**
* Converts a GameLib.Clock to a new GameLib.API.Clock
* @returns {GameLib.API.Clock}
*/
GameLib.Clock.prototype.toApiObject = function() {
return new GameLib.API.Clock(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts from an Object camera to a GameLib.Clock
* @param graphics GameLib.Graphics
* @param objectClock Object
* @returns {GameLib.Clock}
* @constructor
*/
GameLib.Clock.FromObject = function(graphics, objectClock) {
var apiClock = GameLib.API.Clock.FromObject(objectClock);
return new GameLib.Clock(
graphics,
apiClock
);
};

View File

@ -16,8 +16,7 @@
GameLib.D3.API.FrictionContactMaterial = function( GameLib.D3.API.FrictionContactMaterial = function(
id, id,
name, name,
material1, materials,
material2,
friction, friction,
restitution, restitution,
contactEquationStiffness, contactEquationStiffness,
@ -37,15 +36,10 @@ GameLib.D3.API.FrictionContactMaterial = function(
} }
this.name = name; this.name = name;
if (GameLib.Utils.UndefinedOrNull(material1)) { if (GameLib.Utils.UndefinedOrNull(materials)) {
material1 = null; materials = [];
} }
this.material1 = material1; this.materials = materials;
if (GameLib.Utils.UndefinedOrNull(material2)) {
material2 = null;
}
this.material2 = material2;
if (GameLib.Utils.UndefinedOrNull(friction)) { if (GameLib.Utils.UndefinedOrNull(friction)) {
friction = 0.3; friction = 0.3;
@ -95,8 +89,7 @@ GameLib.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionConta
return new GameLib.D3.API.FrictionContactMaterial( return new GameLib.D3.API.FrictionContactMaterial(
objectFrictionContactMaterial.id, objectFrictionContactMaterial.id,
objectFrictionContactMaterial.name, objectFrictionContactMaterial.name,
objectFrictionContactMaterial.material1, objectFrictionContactMaterial.materials,
objectFrictionContactMaterial.material2,
objectFrictionContactMaterial.friction, objectFrictionContactMaterial.friction,
objectFrictionContactMaterial.restitution, objectFrictionContactMaterial.restitution,
objectFrictionContactMaterial.contactEquationStiffness, objectFrictionContactMaterial.contactEquationStiffness,

View File

@ -98,7 +98,7 @@ GameLib.D3.API.Mesh = function(
} }
this.skinWeights = skinWeights; this.skinWeights = skinWeights;
if (GameLib.Utils.UndefinedOrNull(materials)) { if (GameLib.Utils.UndefinedOrNull(materials) || (materials instanceof Array && materials.length === 0)) {
materials = [new GameLib.D3.API.Material(null, GameLib.D3.Material.MATERIAL_TYPE_STANDARD, 'Material (' + this.name + ')')]; materials = [new GameLib.D3.API.Material(null, GameLib.D3.Material.MATERIAL_TYPE_STANDARD, 'Material (' + this.name + ')')];
} }
this.materials = materials; this.materials = materials;

View File

@ -7,6 +7,7 @@
* @param solver * @param solver
* @param rigidBodies * @param rigidBodies
* @param contactMaterials * @param contactMaterials
* @param allowSleep
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
@ -18,6 +19,8 @@ GameLib.D3.API.PhysicsWorld = function(
solver, solver,
rigidBodies, rigidBodies,
contactMaterials, contactMaterials,
allowSleep,
defaultContactMaterial,
parentEntity parentEntity
) { ) {
@ -62,6 +65,19 @@ GameLib.D3.API.PhysicsWorld = function(
} }
this.contactMaterials = contactMaterials; this.contactMaterials = contactMaterials;
if (GameLib.Utils.UndefinedOrNull(allowSleep)) {
allowSleep = true;
}
this.allowSleep = allowSleep;
if (GameLib.Utils.UndefinedOrNull(defaultContactMaterial)) {
defaultContactMaterial = new GameLib.D3.API.FrictionContactMaterial(
null,
'Default Contact Material (Physics World ' + this.id + ')'
);
}
this.defaultContactMaterial = defaultContactMaterial;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null; parentEntity = null;
} }
@ -85,6 +101,8 @@ GameLib.D3.API.PhysicsWorld.FromObject = function(objectWorld) {
objectWorld.solver, objectWorld.solver,
objectWorld.rigidBodies, objectWorld.rigidBodies,
objectWorld.contactMaterials, objectWorld.contactMaterials,
objectWorld.allowSleep,
objectWorld.defaultContactMaterial,
objectWorld.parentEntity objectWorld.parentEntity
); );
}; };

View File

@ -24,8 +24,7 @@ GameLib.D3.FrictionContactMaterial = function (
this, this,
apiFrictionContactMaterial.id, apiFrictionContactMaterial.id,
apiFrictionContactMaterial.name, apiFrictionContactMaterial.name,
apiFrictionContactMaterial.material1, apiFrictionContactMaterial.materials,
apiFrictionContactMaterial.material2,
apiFrictionContactMaterial.friction, apiFrictionContactMaterial.friction,
apiFrictionContactMaterial.restitution, apiFrictionContactMaterial.restitution,
apiFrictionContactMaterial.contactEquationStiffness, apiFrictionContactMaterial.contactEquationStiffness,
@ -39,8 +38,7 @@ GameLib.D3.FrictionContactMaterial = function (
this, this,
GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL, GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL,
{ {
material1 : GameLib.D3.FrictionMaterial, materials : [GameLib.D3.FrictionMaterial]
material2 : GameLib.D3.FrictionMaterial
} }
); );
}; };
@ -55,14 +53,21 @@ GameLib.D3.FrictionContactMaterial.prototype.constructor = GameLib.D3.FrictionCo
GameLib.D3.FrictionContactMaterial.prototype.createInstance = function() { GameLib.D3.FrictionContactMaterial.prototype.createInstance = function() {
var instance = new CANNON.ContactMaterial( var instance = new CANNON.ContactMaterial(
this.material1.instance, null,
this.material2.instance, null,
{ {
friction: this.friction, friction: this.friction,
restitution: this.restitution, restitution: this.restitution,
contactEquationStiffness: this.contactEquationStiffness contactEquationStiffness: this.contactEquationStiffness
} }
); );
instance.materials = this.materials.map(
function(material){
return material.instance;
}
);
return instance; return instance;
}; };
@ -71,8 +76,11 @@ GameLib.D3.FrictionContactMaterial.prototype.createInstance = function() {
*/ */
GameLib.D3.FrictionContactMaterial.prototype.updateInstance = function() { GameLib.D3.FrictionContactMaterial.prototype.updateInstance = function() {
this.instance.material1 = this.material1.instance; this.instance.materials = this.materials.map(
this.instance.material2 = this.material2.instance; function(material) {
return material.instance;
}
);
this.instance.friction = this.friction; this.instance.friction = this.friction;
this.instance.restitution = this.restitution; this.instance.restitution = this.restitution;
@ -92,8 +100,11 @@ GameLib.D3.FrictionContactMaterial.prototype.toApiObject = function() {
var apiFrictionContactMaterial = new GameLib.D3.API.FrictionContactMaterial( var apiFrictionContactMaterial = new GameLib.D3.API.FrictionContactMaterial(
this.id, this.id,
this.name, this.name,
GameLib.Utils.IdOrNull(this.material1), this.materials.map(
GameLib.Utils.IdOrNull(this.material2), function(material) {
return GameLib.Utils.IdOrNull(material);
}
),
this.friction, this.friction,
this.restitution, this.restitution,
this.contactEquationStiffness, this.contactEquationStiffness,

View File

@ -1046,6 +1046,10 @@ GameLib.D3.Mesh.prototype.applyLocalPositionRotationScale = function() {
this.scale.y = 1; this.scale.y = 1;
this.scale.z = 1; this.scale.z = 1;
this.localPosition.x = 0;
this.localPosition.y = 0;
this.localPosition.z = 0;
this.quaternion.axis.x = 0; this.quaternion.axis.x = 0;
this.quaternion.axis.y = 0; this.quaternion.axis.y = 0;
this.quaternion.axis.z = 0; this.quaternion.axis.z = 0;
@ -1221,6 +1225,14 @@ GameLib.D3.Mesh.prototype.createHelper = function() {
}; };
GameLib.D3.Mesh.prototype.addMaterial = function(material) {
if (this.materials.length === 1) {
this.instance.material = material.instance;
} else {
this.instance.material.push(material.instance);
}
};
/** /**
* Convenience function for removing a helper for this Mesh - should be called from Systems only * Convenience function for removing a helper for this Mesh - should be called from Systems only
*/ */

View File

@ -29,6 +29,8 @@ GameLib.D3.PhysicsWorld = function(
apiWorld.solver, apiWorld.solver,
apiWorld.rigidBodies, apiWorld.rigidBodies,
apiWorld.contactMaterials, apiWorld.contactMaterials,
apiWorld.allowSleep,
apiWorld.defaultContactMaterial,
apiWorld.parentEntity apiWorld.parentEntity
); );
@ -78,6 +80,13 @@ GameLib.D3.PhysicsWorld = function(
}.bind(this) }.bind(this)
); );
if (this.defaultContactMaterial instanceof GameLib.D3.API.FrictionContactMaterial) {
this.defaultContactMaterial = new GameLib.D3.FrictionContactMaterial(
this.physics,
this.defaultContactMaterial
)
}
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_PHYSICS_WORLD, GameLib.Component.COMPONENT_PHYSICS_WORLD,
@ -85,7 +94,8 @@ GameLib.D3.PhysicsWorld = function(
'broadphase' : GameLib.D3.Broadphase, 'broadphase' : GameLib.D3.Broadphase,
'solver' : GameLib.D3.Solver, 'solver' : GameLib.D3.Solver,
'rigidBodies' : [GameLib.D3.RigidBody], 'rigidBodies' : [GameLib.D3.RigidBody],
'contactMaterials' : [GameLib.D3.FrictionContactMaterial] 'contactMaterials' : [GameLib.D3.FrictionContactMaterial],
'defaultContactMaterial' : GameLib.D3.FrictionContactMaterial
} }
); );
}; };
@ -106,6 +116,7 @@ GameLib.D3.PhysicsWorld.prototype.createInstance = function() {
instance.broadphase = this.broadphase.instance; instance.broadphase = this.broadphase.instance;
instance.solver = this.solver.instance; instance.solver = this.solver.instance;
instance.gravity = this.gravity.instance; instance.gravity = this.gravity.instance;
instance.allowSleep = this.allowSleep;
this.contactMaterials.map( this.contactMaterials.map(
function(contactMaterial) { function(contactMaterial) {
@ -135,6 +146,13 @@ GameLib.D3.PhysicsWorld.prototype.createInstance = function() {
} }
); );
instance.defaultContactMaterial.friction = this.defaultContactMaterial.friction;
instance.defaultContactMaterial.restitution = this.defaultContactMaterial.restitution;
instance.defaultContactMaterial.contactEquationStiffness = this.defaultContactMaterial.contactEquationStiffness;
instance.defaultContactMaterial.contactEquationRelaxation = this.defaultContactMaterial.contactEquationRelaxation;
instance.defaultContactMaterial.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
return instance; return instance;
} else { } else {
@ -225,8 +243,15 @@ GameLib.D3.PhysicsWorld.prototype.updateInstance = function() {
this.instance.broadphase = this.broadphase.instance; this.instance.broadphase = this.broadphase.instance;
this.instance.solver = this.solver.instance; this.instance.solver = this.solver.instance;
this.instance.gravity = this.gravity.instance; this.instance.gravity = this.gravity.instance;
this.instance.allowSleep = this.allowSleep;
this.instance.defaultContactMaterial.friction = this.defaultContactMaterial.friction;
this.instance.defaultContactMaterial.restitution = this.defaultContactMaterial.restitution;
this.instance.defaultContactMaterial.contactEquationStiffness = this.defaultContactMaterial.contactEquationStiffness;
this.instance.defaultContactMaterial.contactEquationRelaxation = this.defaultContactMaterial.contactEquationRelaxation;
this.instance.defaultContactMaterial.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
this.instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
//TODO add contact materials and rigidbodies ? - this functionality is actually part of the physics system..
}; };
/** /**
@ -247,6 +272,8 @@ GameLib.D3.PhysicsWorld.prototype.toApiObject = function() {
this.contactMaterials.map(function(contactMaterial){ this.contactMaterials.map(function(contactMaterial){
return GameLib.Utils.IdOrNull(contactMaterial); return GameLib.Utils.IdOrNull(contactMaterial);
}), }),
this.allowSleep,
GameLib.Utils.IdOrNull(this.defaultContactMaterial),
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );

View File

@ -69,6 +69,14 @@ GameLib.D3.RigidBody = function (
this this
); );
this.force = new GameLib.Vector3(
this.physics
);
this.forcePoint = new GameLib.Vector3(
this.physics
);
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_RIGID_BODY, GameLib.Component.COMPONENT_RIGID_BODY,
@ -109,6 +117,18 @@ GameLib.D3.RigidBody.prototype.createInstance = function() {
} }
); );
instance.addEventListener("sleepy",function(event){
console.log(this.name + " is feeling sleepy...");
}.bind(this));
instance.addEventListener("sleep",function(event){
console.log(this.name + " fell asleep!");
}.bind(this));
instance.addEventListener("wakeup",function(event){
console.log(this.name + " woke up!");
}.bind(this));
this.shapes.map(function(shape){ this.shapes.map(function(shape){
if (shape.loaded) { if (shape.loaded) {
@ -237,3 +257,18 @@ GameLib.D3.RigidBody.FromObject = function(physics, objectComponent) {
apiRigidBody apiRigidBody
); );
}; };
GameLib.D3.RigidBody.prototype.applyForce = function() {
this.instance.applyForce(
this.force.instance,
this.forcePoint.instance
)
};
GameLib.D3.RigidBody.prototype.applyLocalForce = function() {
this.instance.applyLocalForce(
this.force.instance,
this.forcePoint.instance
)
};

View File

@ -24,6 +24,8 @@ GameLib.System = function(
apiSystem.parentEntity apiSystem.parentEntity
); );
this.started = false;
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_SYSTEM GameLib.Component.COMPONENT_SYSTEM
@ -56,17 +58,19 @@ GameLib.System.prototype.createInstance = function() {
*/ */
GameLib.System.prototype.start = function() { GameLib.System.prototype.start = function() {
this.started = true;
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
// this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
// this.meshObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Mesh]);
// this.lookAtObjects = GameLib.EntityManager.Instance.query([GameLib.D3.LookAt]);
// this.cameraObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Camera]);
// this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
}
this.update(); // if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
// // this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
// // this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
// // this.meshObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Mesh]);
// // this.lookAtObjects = GameLib.EntityManager.Instance.query([GameLib.D3.LookAt]);
// // this.cameraObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Camera]);
// // this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
// }
//
// this.update();
}; };
@ -126,14 +130,17 @@ GameLib.System.prototype.update = function(deltaTime) {
*/ */
GameLib.System.prototype.stop = function() { GameLib.System.prototype.stop = function() {
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { this.started = false;
// this.pathFollowingObjects = [];
// this.followObjects = []; //
// this.meshObjects = []; // if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
// this.lookAtObjects = []; // // this.pathFollowingObjects = [];
// this.cameraObjects = []; // // this.followObjects = [];
// this.lightObjects = []; // // this.meshObjects = [];
} // // this.lookAtObjects = [];
// // this.cameraObjects = [];
// // this.lightObjects = [];
// }
}; };
/** /**

View File

@ -16,11 +16,33 @@ GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype);
GameLib.System.Animation.prototype.constructor = GameLib.System.Animation; GameLib.System.Animation.prototype.constructor = GameLib.System.Animation;
GameLib.System.Animation.prototype.start = function() { GameLib.System.Animation.prototype.start = function() {
console.log('todo: animation system start');
GameLib.System.prototype.start.call(this);
this.animateSubscription = GameLib.Event.Subscribe(
GameLib.Event.ANIMATE,
this.animate
);
}; };
GameLib.System.Animation.prototype.animate = function(data, clientCallback) {
this.renderSubscription = GameLib.Event.Subscribe(
GameLib.Event.BEFORE_RENDER,
function(data) {
if (clientCallback(data)) {
this.renderSubscription.remove();
}
}.bind(this)
)
};
GameLib.System.Animation.prototype.stop = function() { GameLib.System.Animation.prototype.stop = function() {
console.log('todo: animation system stop');
GameLib.System.prototype.stop.call(this);
this.animateSubscription.remove();
}; };

View File

@ -26,6 +26,8 @@ GameLib.System.CustomCode.prototype.constructor = GameLib.System.CustomCode;
*/ */
GameLib.System.CustomCode.prototype.start = function() { GameLib.System.CustomCode.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.customCodeComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.CustomCode); this.customCodeComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.CustomCode);
this.customCodeComponents.map(function(customCodeComponent){ this.customCodeComponents.map(function(customCodeComponent){
@ -46,6 +48,8 @@ GameLib.System.CustomCode.prototype.start = function() {
*/ */
GameLib.System.CustomCode.prototype.stop = function() { GameLib.System.CustomCode.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.subscriptions.map(function(subscription){ this.subscriptions.map(function(subscription){
subscription.remove(); subscription.remove();
}); });

View File

@ -43,6 +43,8 @@ GameLib.System.GUI.prototype.constructor = GameLib.System.GUI;
GameLib.System.GUI.prototype.start = function() { GameLib.System.GUI.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
/** /**
@ -188,8 +190,17 @@ GameLib.System.GUI.prototype.start = function() {
GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected) { GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected) {
return function(value) { return function(value) {
affected.map(function(component){ affected.map(function(component){
component[property][subProperty] = value;
component.updateInstance(); component[property][subProperty] = value;
if (typeof component[property].updateInstance === 'function') {
component[property].updateInstance();
} else if (typeof component[property][subProperty].updateInstance === 'function') {
component[property][subProperty].updateInstance();
} else {
component.updateInstance();
}
}); });
} }
}; };
@ -1679,6 +1690,8 @@ GameLib.System.GUI.prototype.newEntity = function(data) {
GameLib.System.GUI.prototype.stop = function() { GameLib.System.GUI.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.guis.map(function(gui){ this.guis.map(function(gui){
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
}); });

View File

@ -43,6 +43,8 @@ GameLib.System.Input.prototype.constructor = GameLib.System.Input;
*/ */
GameLib.System.Input.prototype.start = function() { GameLib.System.Input.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer);
this.renderers.map( this.renderers.map(
@ -374,6 +376,8 @@ GameLib.System.Input.prototype.deSelectMesh = function(mesh) {
*/ */
GameLib.System.Input.prototype.stop = function() { GameLib.System.Input.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
/** /**
* Now remove all input capabilities * Now remove all input capabilities
*/ */

View File

@ -50,6 +50,8 @@ GameLib.System.Linking.prototype.constructor = GameLib.System.Linking;
GameLib.System.Linking.prototype.start = function() { GameLib.System.Linking.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.componentCreatedSubscription = this.subscribe( this.componentCreatedSubscription = this.subscribe(
GameLib.Event.COMPONENT_CREATED, GameLib.Event.COMPONENT_CREATED,
this.componentCreated.bind(this) this.componentCreated.bind(this)
@ -700,6 +702,12 @@ GameLib.System.Linking.prototype.arrayItemAdded = function(data) {
) { ) {
data.component.addRigidBody(data.item); data.component.addRigidBody(data.item);
} }
if (data.component instanceof GameLib.D3.Mesh &&
data.item instanceof GameLib.D3.Material
) {
data.component.addMaterial(data.item);
}
}; };
GameLib.System.Linking.prototype.instanceCreated = function(data) { GameLib.System.Linking.prototype.instanceCreated = function(data) {
@ -999,6 +1007,7 @@ GameLib.System.Linking.prototype.meshDeleted = function(data) {
}; };
GameLib.System.Linking.prototype.stop = function() { GameLib.System.Linking.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.imageNotFoundSubscription.remove(); this.imageNotFoundSubscription.remove();
this.componentCreatedSubscription.remove(); this.componentCreatedSubscription.remove();
this.parentSceneChangeSubscription.remove(); this.parentSceneChangeSubscription.remove();

View File

@ -32,6 +32,8 @@ GameLib.System.Physics.prototype.constructor = GameLib.System.Physics;
GameLib.System.Physics.prototype.start = function() { GameLib.System.Physics.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld); this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld);
// this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody); // this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody);
// this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastWheel); // this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastWheel);
@ -130,6 +132,8 @@ GameLib.System.Physics.prototype.beforeRender = function(data) {
GameLib.System.Physics.prototype.stop = function() { GameLib.System.Physics.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.worlds = []; this.worlds = [];
this.rigidBodies = []; this.rigidBodies = [];
this.wheels = []; this.wheels = [];

View File

@ -24,6 +24,8 @@ GameLib.System.Render.prototype.constructor = GameLib.System.Render;
*/ */
GameLib.System.Render.prototype.start = function() { GameLib.System.Render.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer);
this.renderers.map( this.renderers.map(
@ -69,6 +71,8 @@ GameLib.System.Render.prototype.render = function(data) {
*/ */
GameLib.System.Render.prototype.stop = function() { GameLib.System.Render.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.renderers.map( this.renderers.map(
function(renderer) { function(renderer) {
if (renderer.statistics) { if (renderer.statistics) {

View File

@ -99,6 +99,8 @@ GameLib.System.Storage.prototype.constructor = GameLib.System.Storage;
GameLib.System.Storage.prototype.start = function() { GameLib.System.Storage.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.loginSubscription = this.subscribe( this.loginSubscription = this.subscribe(
GameLib.Event.LOGGED_IN, GameLib.Event.LOGGED_IN,
function(data) { function(data) {
@ -998,6 +1000,9 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
}; };
GameLib.System.Storage.prototype.stop = function() { GameLib.System.Storage.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.loginSubscription.remove(); this.loginSubscription.remove();
this.loadSubscription.remove(); this.loadSubscription.remove();
this.saveSubscription.remove(); this.saveSubscription.remove();

View File

@ -34,6 +34,8 @@ GameLib.System.Visualization.prototype.constructor = GameLib.System.Visualizatio
GameLib.System.Visualization.prototype.start = function() { GameLib.System.Visualization.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.visualizationSubscription = this.subscribe( this.visualizationSubscription = this.subscribe(
GameLib.Event.VISUALIZE, GameLib.Event.VISUALIZE,
this.visualize this.visualize
@ -110,6 +112,8 @@ GameLib.System.Visualization.prototype.stopVisualize = function(data) {
GameLib.System.Visualization.prototype.stop = function() { GameLib.System.Visualization.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
if (this.visualizationSubscription) { if (this.visualizationSubscription) {
this.visualizationSubscription.remove(); this.visualizationSubscription.remove();
} }

View File

@ -43,7 +43,7 @@ GameLib.Vector3 = function (
); );
if (GameLib.Utils.UndefinedOrNull(parentObject)) { if (GameLib.Utils.UndefinedOrNull(parentObject)) {
parentObject = null; parentObject = this;
} }
this.parentObject = parentObject; this.parentObject = parentObject;
@ -93,6 +93,7 @@ GameLib.Vector3.prototype.updateInstance = function() {
this.instance.z = this.z; this.instance.z = this.z;
if (this.parentObject && if (this.parentObject &&
this.parentObject !== this &&
this.parentObject.updateInstance) { this.parentObject.updateInstance) {
this.parentObject.updateInstance(); this.parentObject.updateInstance();
} }