particle component, input and render system updates

beta.r3js.org
-=yb4f310 2017-11-06 13:57:57 +01:00
parent ee72894565
commit abc78b2993
9 changed files with 1023 additions and 724 deletions

View File

@ -128,7 +128,7 @@ GameLib.Component.prototype.performInstanceCreation = function() {
GameLib.Component.prototype.createInstance = function() {
// console.log('create instance : '+ this.name);
// console.log('create instance : '+ this.name);
/**
* When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller
@ -282,6 +282,7 @@ GameLib.Component.COMPONENT_FOG = 0x50;
GameLib.Component.COMPONENT_MESH_LINE = 0x51;
GameLib.Component.COMPONENT_PARTICLE_ENGINE = 0x52;
GameLib.Component.COMPONENT_SYSTEM_PARTICLE = 0x53;
GameLib.Component.COMPONENT_PARTICLE = 0x54;
/**
* Returns string name for component number
@ -368,6 +369,7 @@ GameLib.Component.GetComponentName = function(number) {
case 0x51 : return 'GameLib.D3.Mesh.Line';
case 0x52 : return 'GameLib.D3.ParticleEngine';
case 0x53 : return 'GameLib.D3.System.Particle';
case 0x54 : return 'GameLib.D3.Particle';
break;
}

View File

@ -2,49 +2,30 @@
* Raw ParticleEngine API object - should always correspond with the ParticleEngine Schema
* @param id
* @param name
* @param meshes
* @param materials
* @param position
* @param rotation
* @param direction
* @param lookAt
* @param scale
* @param enabled
* @param templateParticle
* @param particles
* @param particlesPerSecond
* @param frequency
* @param elapsed
* @param distanceType
* @param minDistance
* @param maxDistance
* @param scaleType
* @param minScale
* @param maxScale
* @param rotationType
* @param minRotation
* @param maxRotation
* @param parentEntity
* @constructor
*/
GameLib.D3.API.ParticleEngine = function(
id,
name,
meshes,
materials,
position,
rotation,
scale,
direction,
lookAt,
enabled,
templateParticle,
particles,
particlesPerSecond,
frequency,
elapsed,
distanceType,
minDistance,
maxDistance,
scaleType,
minScale,
maxScale,
rotationType,
minRotation,
maxRotation,
parentEntity
) {
@ -58,16 +39,6 @@ GameLib.D3.API.ParticleEngine = function(
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(meshes)) {
meshes = [];
}
this.meshes = meshes;
if (GameLib.Utils.UndefinedOrNull(materials)) {
materials = [];
}
this.materials = materials;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0, 0, 0);
}
@ -83,15 +54,20 @@ GameLib.D3.API.ParticleEngine = function(
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(direction)) {
direction = new GameLib.API.Vector3(0, 0, 1);
if (GameLib.Utils.UndefinedOrNull(enabled)) {
enabled = false;
}
this.direction = direction;
this.enabled = enabled;
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
lookAt = new GameLib.API.Vector3(0, 0, -1);
if (GameLib.Utils.UndefinedOrNull(templateParticle)) {
templateParticle = null;
}
this.lookAt = lookAt;
this.templateParticle = templateParticle;
if (GameLib.Utils.UndefinedOrNull(particles)) {
particles = [];
}
this.particles = particles;
if (GameLib.Utils.UndefinedOrNull(particlesPerSecond)) {
particlesPerSecond = 1;
@ -99,7 +75,7 @@ GameLib.D3.API.ParticleEngine = function(
this.particlesPerSecond = particlesPerSecond;
if (GameLib.Utils.UndefinedOrNull(frequency)) {
frequency = Number(1 / Number(particlesPerSecond));
frequency = Number(1 / Number(this.particlesPerSecond));
}
this.frequency = frequency;
@ -108,51 +84,6 @@ GameLib.D3.API.ParticleEngine = function(
}
this.elapsed = elapsed;
if (GameLib.Utils.UndefinedOrNull(distanceType)) {
distanceType = GameLib.D3.ParticleEngine.DISTANCE_TYPE_CONSTANT;
}
this.distanceType = distanceType;
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
minDistance = 0;
}
this.minDistance = minDistance;
if (GameLib.Utils.UndefinedOrNull(maxDistance)) {
maxDistance = 1;
}
this.maxDistance = maxDistance;
if (GameLib.Utils.UndefinedOrNull(scaleType)) {
scaleType = GameLib.D3.ParticleEngine.SCALE_TYPE_CONSTANT;
}
this.scaleType = scaleType;
if (GameLib.Utils.UndefinedOrNull(minScale)) {
minScale = null;
}
this.minScale = minScale;
if (GameLib.Utils.UndefinedOrNull(maxScale)) {
maxScale = null;
}
this.maxScale = maxScale;
if (GameLib.Utils.UndefinedOrNull(rotationType)) {
rotationType = GameLib.D3.ParticleEngine.ROTATION_TYPE_CONSTANT;
}
this.rotationType = rotationType;
if (GameLib.Utils.UndefinedOrNull(minRotation)) {
minRotation = 0;
}
this.minRotation = minRotation;
if (GameLib.Utils.UndefinedOrNull(maxRotation)) {
maxRotation = 0;
}
this.maxRotation = maxRotation;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
@ -170,55 +101,43 @@ GameLib.D3.API.ParticleEngine.prototype.constructor = GameLib.D3.API.ParticleEng
*/
GameLib.D3.API.ParticleEngine.FromObject = function(objectParticleEngine) {
var apiMeshes = [];
if (objectParticleEngine.meshes) {
apiMeshes = objectParticleEngine.meshes.map(
function (objectMesh) {
if (objectMesh instanceof Object) {
return GameLib.D3.API.Mesh.FromObject(objectMesh);
var apiParticles = [];
if (objectParticleEngine.particles) {
apiParticles = objectParticleEngine.particles.map(
function (objectParticle) {
if (objectParticle instanceof Object) {
return GameLib.D3.API.Particle.FromObject(objectParticle);
} else {
return objectMesh
return objectParticle
}
}
)
}
var apiMaterials = [];
if (objectParticleEngine.materials) {
apiMaterials = objectParticleEngine.materials.map(
function (objectMaterial) {
if (objectMaterial instanceof Object) {
return GameLib.D3.API.Material.FromObject(objectMaterial);
} else {
return objectMaterial
}
}
)
var apiTemplateParticle = null;
if (objectParticleEngine.templateParticle) {
if (objectParticleEngine.templateParticle instanceof Object) {
apiTemplateParticle = GameLib.D3.API.Material.FromObject(objectParticleEngine.templateParticle);
} else {
apiTemplateParticle = objectParticleEngine.templateParticle;
}
}
return new GameLib.D3.API.ParticleEngine(
objectParticleEngine.id,
objectParticleEngine.name,
apiMeshes,
apiMaterials,
GameLib.API.Vector3.FromObject(objectParticleEngine.position),
GameLib.API.Vector3.FromObject(objectParticleEngine.rotation),
GameLib.API.Vector3.FromObject(objectParticleEngine.scale),
GameLib.API.Vector3.FromObject(objectParticleEngine.direction),
GameLib.API.Vector3.FromObject(objectParticleEngine.lookAt),
objectParticleEngine.enabled,
apiTemplateParticle,
apiParticles,
objectParticleEngine.particlesPerSecond,
objectParticleEngine.frequency,
objectParticleEngine.elapsed,
objectParticleEngine.distanceType,
objectParticleEngine.minDistance,
objectParticleEngine.maxDistance,
objectParticleEngine.scaleType,
objectParticleEngine.minScale,
objectParticleEngine.maxScale,
objectParticleEngine.rotationType,
objectParticleEngine.minRotation,
objectParticleEngine.maxRotation,
objectParticleEngine.parentEntity
);
};

View File

@ -0,0 +1,183 @@
/**
* Raw Particle API object - should always correspond with the Particle Schema
* @param id
* @param name
* @param lifeTime
* @param elapsed
* @param mesh
* @param positionOffsetType
* @param positionOffset
* @param positionOffsetFn
* @param directionType
* @param rotation
* @param scale
* @param direction
* @param directionFn
* @param scaleFn
* @param scaleType
* @param rotationType
* @param rotationFn
* @param parentEngine
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Particle = function(
id,
name,
lifeTime,
elapsed,
mesh,
positionOffsetType,
positionOffset,
positionOffsetFn,
directionType,
direction,
directionFn,
scaleType,
scale,
scaleFn,
rotationType,
rotation,
rotationFn,
parentEngine,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Particle (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(lifeTime)) {
lifeTime = 10;
}
this.lifeTime = lifeTime;
if (GameLib.Utils.UndefinedOrNull(elapsed)) {
elapsed = 0;
}
this.elapsed = elapsed;
if (GameLib.Utils.UndefinedOrNull(mesh)) {
mesh = null;
}
this.mesh = mesh;
if (GameLib.Utils.UndefinedOrNull(positionOffsetType)) {
positionOffsetType = GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT;
}
this.positionOffsetType = positionOffsetType;
if (GameLib.Utils.UndefinedOrNull(positionOffset)) {
positionOffset = new GameLib.API.Vector3(0, 0, 0);
}
this.positionOffset = positionOffset;
if (GameLib.Utils.UndefinedOrNull(positionOffsetFn)) {
positionOffsetFn = '//@ sourceURL=positionOffsetFn.js';
}
this.positionOffsetFn = positionOffsetFn;
if (GameLib.Utils.UndefinedOrNull(directionType)) {
directionType = GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT;
}
this.directionType = directionType;
if (GameLib.Utils.UndefinedOrNull(direction)) {
direction = new GameLib.API.Vector3(0, 1, 0);
}
this.direction = direction;
if (GameLib.Utils.UndefinedOrNull(directionFn)) {
directionFn = '//@ sourceURL=directionFn.js';
}
this.directionFn = directionFn;
if (GameLib.Utils.UndefinedOrNull(scaleType)) {
scaleType = GameLib.D3.Particle.SCALE_TYPE_CONSTANT;
}
this.scaleType = scaleType;
if (GameLib.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.API.Vector3(1, 1, 1);
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(scaleFn)) {
scaleFn = '//@ sourceURL=scaleFn.js';
}
this.scaleFn = scaleFn;
if (GameLib.Utils.UndefinedOrNull(rotationType)) {
rotationType = GameLib.D3.Particle.ROTATION_TYPE_CONSTANT;
}
this.rotationType = rotationType;
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = new GameLib.API.Vector3(0, 0, 0);
}
this.rotation = rotation;
if (GameLib.Utils.UndefinedOrNull(rotationFn)) {
rotationFn = '//@ sourceURL=rotationFn.js';
}
this.rotationFn = rotationFn;
if (GameLib.Utils.UndefinedOrNull(parentEngine)) {
parentEngine = null;
}
this.parentEngine = parentEngine;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Particle.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Particle.prototype.constructor = GameLib.D3.API.Particle;
/**
* Creates an API Particle from an Object Particle
* @param objectParticle
* @constructor
*/
GameLib.D3.API.Particle.FromObject = function(objectParticle) {
var apiMesh = null;
if (objectParticle.mesh) {
if (objectParticle.mesh instanceof Object) {
apiMesh = GameLib.D3.API.Mesh.FromObject(objectParticle.mesh);
} else {
apiMesh = objectParticle.mesh;
}
}
return new GameLib.D3.API.Particle(
objectParticle.id,
objectParticle.name,
objectParticle.lifeTime,
objectParticle.elapsed,
apiMesh,
objectParticle.positionOffsetType,
GameLib.API.Vector3.FromObject(objectParticle.positionOffset),
objectParticle.positionOffsetFn,
objectParticle.directionType,
GameLib.API.Vector3.FromObject(objectParticle.direction),
objectParticle.directionFn,
objectParticle.scaleType,
GameLib.API.Vector3.FromObject(objectParticle.scale),
objectParticle.scaleFn,
objectParticle.rotationType,
GameLib.API.Vector3.FromObject(objectParticle.rotation),
objectParticle.rotationFn,
objectParticle.parentEngine,
objectParticle.parentEntity
);
};

View File

@ -22,50 +22,18 @@ GameLib.D3.ParticleEngine = function(
GameLib.D3.API.ParticleEngine.call(
this,
apiParticleEngine.id,
apiParticleEngine.name,
apiParticleEngine.meshes,
apiParticleEngine.materials,
apiParticleEngine.position,
apiParticleEngine.rotation,
apiParticleEngine.scale,
apiParticleEngine.direction,
apiParticleEngine.lookAt,
apiParticleEngine.particlesPerSecond,
apiParticleEngine.frequency,
apiParticleEngine.elapsed,
apiParticleEngine.distanceType,
apiParticleEngine.minDistance,
apiParticleEngine.maxDistance,
apiParticleEngine.scaleType,
apiParticleEngine.minScale,
apiParticleEngine.maxScale,
apiParticleEngine.rotationType,
apiParticleEngine.minRotation,
apiParticleEngine.maxRotation,
apiParticleEngine.parentEntity
);
this.meshes = this.meshes.map(
function(mesh) {
if (mesh instanceof GameLib.D3.API.Mesh) {
return new GameLib.D3.Mesh(
graphics,
mesh
)
}
}
);
this.materials = this.materials.map(
function(material) {
if (material instanceof GameLib.D3.API.Material) {
return new GameLib.D3.Material(
graphics,
material
)
}
}
apiParticleEngine.id,
apiParticleEngine.name,
apiParticleEngine.position,
apiParticleEngine.rotation,
apiParticleEngine.scale,
apiParticleEngine.enabled,
apiParticleEngine.templateParticle,
apiParticleEngine.particles,
apiParticleEngine.particlesPerSecond,
apiParticleEngine.frequency,
apiParticleEngine.elapsed,
apiParticleEngine.parentEntity
);
if (this.position instanceof GameLib.API.Vector3) {
@ -90,7 +58,6 @@ GameLib.D3.ParticleEngine = function(
throw new Error('rotation not instance of API.Vector3');
}
if (this.scale instanceof GameLib.API.Vector3) {
this.scale = new GameLib.Vector3(
graphics,
@ -102,42 +69,30 @@ GameLib.D3.ParticleEngine = function(
throw new Error('scale not instance of API.Vector3');
}
if (this.direction instanceof GameLib.API.Vector3) {
this.direction = new GameLib.Vector3(
if (this.templateParticle instanceof GameLib.D3.API.Particle) {
this.templateParticle = new GameLib.D3.Particle(
graphics,
this.direction,
this
);
} else {
console.warn('direction not instance of API.Vector3');
throw new Error('direction not instance of API.Vector3');
material
)
}
if (this.lookAt instanceof GameLib.API.Vector3) {
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
} else {
console.warn('lookAt not instance of API.Vector3');
throw new Error('lookAt not instance of API.Vector3');
}
/**
* This is just a reference to the first mesh in the array
* @type {null}
*/
this.parentMesh = null;
this.particles = this.particles.map(
function(particle) {
if (particle instanceof GameLib.D3.API.Particle) {
return new GameLib.D3.Particle(
graphics,
particle
)
}
}
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PARTICLE_ENGINE,
{
parentMesh : GameLib.D3.Mesh,
meshes : [GameLib.D3.Mesh],
materials : [GameLib.D3.Material]
templateParticle : GameLib.D3.Particle,
particles : [GameLib.D3.Particle]
}
);
@ -146,180 +101,56 @@ GameLib.D3.ParticleEngine = function(
GameLib.D3.ParticleEngine.prototype = Object.create(GameLib.D3.API.ParticleEngine.prototype);
GameLib.D3.ParticleEngine.prototype.constructor = GameLib.D3.ParticleEngine;
GameLib.D3.ParticleEngine.DISTANCE_TYPE_CONSTANT = 0x1;
GameLib.D3.ParticleEngine.SCALE_TYPE_CONSTANT = 0x1;
GameLib.D3.ParticleEngine.ROTATION_TYPE_CONSTANT = 0x1;
/**
* We don't use a 3rd party particle engine right now
* @returns true
*/
GameLib.D3.ParticleEngine.prototype.createInstance = function() {
this.frequency = Number(1 / this.particlesPerSecond);
var apiMesh = new GameLib.D3.API.Mesh(
null,
GameLib.D3.Mesh.MESH_TYPE_PLANE,
'Particle Mesh',
null,
null,
this.materials,
null
);
this.parentMesh = new GameLib.D3.Mesh.Plane(
this.graphics,
apiMesh,
1,
1,
1,
1
);
// for (var i = 0; i < this.particlesPerSecond; i++) {
//
// if (i === 0) {
//
//
//
//
// this.parentMesh.useQuaternion = false;
//
// this.parentMesh.position.setFrom(this.position);
// this.parentMesh.rotation.setFrom(this.rotation);
// this.parentMesh.scale.setFrom(this.scale);
//
// this.parentMesh.instance.lookAt(this.lookAt.instance);
//
// this.meshes.push(this.parentMesh);
//
// } else {
//
// var mesh = this.parentMesh.clone();
//
// mesh.parentMesh = this.parentMesh;
//
// mesh.updateInstance();
//
// this.meshes.push(mesh);
// }
//
// }
// this.updateDistances();
this.instance = true;/* {
parentMesh : this.parentMesh.instance,
position : this.position.instance,
direction : this.direction.instance,
lookAt : this.lookAt.instance,
meshes : this.meshes.map(
function(mesh) {
return mesh.instance
}
),
materials : this.materials.map(
function(material) {
return material.instance
}
)
};*/
this.instance = true;
GameLib.Component.prototype.createInstance.call(this);
};
// GameLib.D3.ParticleEngine.prototype.updateDistances = function() {
//
// var distanceGrain = 1;
//
// if (this.particlesPerSecond > 1) {
// distanceGrain = Number(1 / (this.particlesPerSecond - 1));
// }
//
// var minDistance = this.direction.clone().multiply(this.minDistance, true);
// minDistance.parentObject = null;
// minDistance.updateInstance();
//
// var maxDistance = this.direction.clone().multiply(this.maxDistance, true);
// maxDistance.parentObject = null;
// maxDistance.updateInstance();
//
// this.meshes.map(
// function(mesh, index) {
//
// if (index === 0) {
// return;
// }
//
// var distance = minDistance.instance.lerp(maxDistance.instance, (index * distanceGrain));
//
// mesh.position.x = this.direction.x * (distance.x);
// mesh.position.y = this.direction.y * (distance.y);
// mesh.position.z = this.direction.z * (distance.z);
//
// mesh.updateInstancePosition();
//
// }.bind(this)
// );
//
// };
/**
* Updates the instance with the current state
*/
GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
console.log('property : ' + property);
if (property === 'position') {
this.parentMesh.position.setFrom(this.position);
this.parentMesh.updateInstancePosition();
}
if (property === 'rotation') {
this.parentMesh.rotation.setFrom(this.rotation);
this.parentMesh.updateInstanceRotation();
}
if (property === 'scale') {
this.parentMesh.scale.setFrom(this.scale);
this.parentMesh.updateInstanceScale();
}
if (property === 'particlesPerSecond') {
this.frequency = Number(1 / this.particlesPerSecond);
}
console.log('particles per second or max distance');
if (property === 'frequency') {
this.particlesPerSecond = Math.round(1 / this.frequency);
}
this.meshes.map(
function(mesh) {
};
GameLib.D3.ParticleEngine.prototype.processParticles = function(delta) {
this.particles.map(
function(particle){
particle.mesh.position.x += particle.direction.x * delta;
particle.mesh.position.y += particle.direction.y * delta;
particle.mesh.position.z += particle.direction.z * delta;
particle.mesh.updateInstancePosition();
particle.elapsed += delta;
if (particle.elapsed > particle.lifeTime) {
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component : mesh
component: particle
}
)
}
);
}
);
};
this.meshes = [];
GameLib.D3.ParticleEngine.prototype.createNewParticle = function(delta) {
this.createInstance();
}
if (property === 'minDistance' || property === 'maxDistance') {
// this.updateDistances();
}
if (property === 'lookAt') {
this.lookAt.instance.x = this.lookAt.x;
this.lookAt.instance.y = this.lookAt.y;
this.lookAt.instance.z = this.lookAt.z;
this.parentMesh.instance.lookAt(this.lookAt.instance);
}
//GameLib.Event.Emit(GameLib.Event.PARTICLE_INSTANCE_UPDATED, {component:this});
};
/**
@ -329,36 +160,21 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
GameLib.D3.ParticleEngine.prototype.toApiObject = function() {
return new GameLib.D3.API.ParticleEngine(
this.id,
this.name,
this.meshes.map(
function(mesh){
return GameLib.Utils.IdOrNull(mesh);
}
),
this.materials.map(
function(material){
return GameLib.Utils.IdOrNull(material);
}
),
this.position.toApiObject(),
this.rotation.toApiObject(),
this.scale.toApiObject(),
this.direction.toApiObject(),
this.lookAt.toApiObject(),
this.enabled,
GameLib.Utils.IdOrNull(this.templateParticle),
this.particles.map(
function(particle) {
return GameLib.Utils.IdOrNull(particle);
}
),
this.particlesPerSecond,
this.frequency,
this.elapsed,
this.distanceType,
this.minDistance,
this.maxDistance,
this.scaleType,
this.minScale,
this.maxScale,
this.rotationType,
this.minRotation,
this.maxRotation,
GameLib.Utils.IdOrNull(this.parentEntity)
);

197
src/game-lib-d3-particle.js Normal file
View File

@ -0,0 +1,197 @@
/**
* Creates a Particle object
* @param graphics GameLib.D3.Graphics
* @param apiParticle GameLib.D3.API.Particle
* @constructor
*/
GameLib.D3.Particle = function(
graphics,
apiParticle
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiParticle)) {
apiParticle = {};
}
if (apiParticle instanceof GameLib.D3.Particle) {
return apiParticle;
}
GameLib.D3.API.Particle.call(
this,
apiParticle.id,
apiParticle.name,
apiParticle.lifeTime,
apiParticle.elapsed,
apiParticle.mesh,
apiParticle.positionOffsetType,
apiParticle.positionOffset,
apiParticle.positionOffsetFn,
apiParticle.directionType,
apiParticle.direction,
apiParticle.directionFn,
apiParticle.scaleType,
apiParticle.scale,
apiParticle.scaleFn,
apiParticle.rotationType,
apiParticle.rotation,
apiParticle.rotationFn,
apiParticle.parentEngine,
apiParticle.parentEntity
);
if (this.mesh instanceof GameLib.D3.API.Mesh) {
this.mesh = new GameLib.D3.Mesh(
graphics,
this.mesh
)
}
if (this.positionOffset instanceof GameLib.API.Vector3) {
this.positionOffset = new GameLib.Vector3(
graphics,
this.positionOffset,
this
);
} else {
console.warn('positionOffset not instance of API.Vector3');
throw new Error('positionOffset not instance of API.Vector3');
}
if (this.direction instanceof GameLib.API.Vector3) {
this.direction = new GameLib.Vector3(
graphics,
this.direction,
this
);
} else {
console.warn('direction not instance of API.Vector3');
throw new Error('direction not instance of API.Vector3');
}
if (this.scale instanceof GameLib.API.Vector3) {
this.scale = new GameLib.Vector3(
graphics,
this.scale,
this
);
} else {
console.warn('scale not instance of API.Vector3');
throw new Error('scale not instance of API.Vector3');
}
if (this.rotation instanceof GameLib.API.Vector3) {
this.rotation = new GameLib.Vector3(
graphics,
this.rotation,
this
);
} else {
console.warn('rotation not instance of API.Vector3');
throw new Error('rotation not instance of API.Vector3');
}
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_PARTICLE,
{
mesh : GameLib.D3.Mesh,
parentEngine : GameLib.D3.ParticleEngine
}
);
};
GameLib.D3.Particle.prototype = Object.create(GameLib.D3.API.Particle.prototype);
GameLib.D3.Particle.prototype.constructor = GameLib.D3.Particle;
GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT = 0x1;
GameLib.D3.Particle.POSITION_OFFSET_TYPE_RANDOM = 0x2;
GameLib.D3.Particle.POSITION_OFFSET_TYPE_FUNCTION = 0x3;
GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT = 0x1;
GameLib.D3.Particle.DIRECTION_TYPE_RANDOM = 0x2;
GameLib.D3.Particle.DIRECTION_TYPE_FUNCTION = 0x3;
GameLib.D3.Particle.SCALE_TYPE_CONSTANT = 0x1;
GameLib.D3.Particle.SCALE_TYPE_LINEAR = 0x2;
GameLib.D3.Particle.SCALE_TYPE_EXPONENTIAL = 0x3;
GameLib.D3.Particle.SCALE_TYPE_RANDOM = 0x4;
GameLib.D3.Particle.SCALE_TYPE_FUNCTION = 0x5;
GameLib.D3.Particle.ROTATION_TYPE_CONSTANT = 0x1;
GameLib.D3.Particle.ROTATION_TYPE_RANDOM = 0x2;
GameLib.D3.Particle.ROTATION_TYPE_FUNCTION = 0x3;
/**
* Particle create instance
*/
GameLib.D3.Particle.prototype.createInstance = function() {
if (!this.mesh) {
console.warn('no mesh to clone from - failed dependency check?');
return
}
this.instance = true;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Particle.prototype.updateInstance = function(property) {
console.log('Update Particle Property : ' + property);
};
/**
* Converts a GameLib.D3.Particle to a new GameLib.D3.API.Particle
* @returns {GameLib.D3.API.Particle}
*/
GameLib.D3.Particle.prototype.toApiObject = function() {
return new GameLib.D3.API.Particle(
this.id,
this.name,
this.lifeTime,
this.elapsed,
GameLib.Utils.IdOrNull(this.mesh),
this.positionOffsetType,
this.positionOffset.toApiObject(),
this.positionOffsetFn,
this.directionType,
this.direction.toApiObject(),
this.directionFn,
this.scaleType,
this.scale.toApiObject(),
this.scaleFn,
this.rotationType,
this.rotation.toApiObject(),
this.rotationFn,
GameLib.Utils.IdOrNull(this.parentEngine),
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts from an Object Particle to a GameLib.D3.Particle
* @param graphics GameLib.D3.Graphics
* @param objectParticle Object
* @returns {GameLib.D3.Particle}
* @constructor
*/
GameLib.D3.Particle.FromObject = function(graphics, objectParticle) {
var apiParticle = GameLib.D3.API.Particle.FromObject(objectParticle);
return new GameLib.D3.Particle(
graphics,
apiParticle
);
};

View File

@ -214,11 +214,14 @@ GameLib.D3.Scene.prototype.createInstance = function() {
};
GameLib.D3.Scene.prototype.updateInstance = function() {
GameLib.D3.Scene.prototype.updateInstance = function(property) {
this.instance.name = this.name;
if (property === 'name') {
this.instance.name = this.name;
return;
}
if (this.instance.fog !== this.fog.instance) {
if (this.fog && this.fog.instance !== this.instance.fog) {
this.instance.fog = this.fog.instance;
}

View File

@ -16,48 +16,56 @@ GameLib.System.Input = function(
this.graphics = graphics;
this.graphics.isNotThreeThrow();
/**
* We need new function pointers with scope bound to this so we can remove the
* window event handlers when we need to
* @type {function()}
*/
this.keyDown = null;
this.selectAll = false;
this.controlLeft = false;
this.sensitivityCounter = 0;
this.renderers = [];
this.editorControls = [];
this.touchControls = [];
this.keyboardControls = [];
this.mouseControls = [];
this.touchStart = this.onTouchStart.bind(this);
this.touchMove = this.onTouchMove.bind(this);
this.touchEnd = this.onTouchEnd.bind(this);
this.touchCancel = this.onTouchCancel.bind(this);
/**
* Touch Controls
* @type {null}
*/
this.touchStart = null;
this.touchMove = null;
this.touchEnd = null;
this.touchCancel = null;
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
/**
* Keyboard Controls
* @type {null}
*/
this.keyboardKeyUp = null;
this.keyboardKeyDown = null;
/**
* Mouse Controls
* @type {null}
*/
this.mouseDown = null;
this.mouseMove = null;
this.mouseWheel = null;
this.mouseUp = null;
/**
* Editor Controls
* @type {null}
*/
this.keyDown = null;
this.keyUp = null;
this.mouseDownEdit = null;
this.mouseMoveEdit = null;
this.mouseWheelEdit = null;
this.mouseUpEdit = null;
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
this.delayedInstanceEncounteredSubscription = null;
this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null;
this.mouse = new GameLib.Mouse(
graphics
@ -73,7 +81,7 @@ GameLib.System.Input.prototype.constructor = GameLib.System.Input;
GameLib.System.Input.prototype.start = function() {
GameLib.System.prototype.start.call(this);
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch);
@ -82,203 +90,470 @@ GameLib.System.Input.prototype.start = function() {
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
this.removeComponentSubscription = GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this)
);
this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe(
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
function() {
if (this.editorControls) {
this.editorControls.map(
function(editorControl) {
if (editorControl.linked && !editorControl.loaded) {
editorControl.createInstance();
this.entityCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.ENTITY_LOADED,
function(data){
if (data.entity === editorControl.parentEntity) {
editorControl.dispose();
this.entityCreatedSubscription.remove();
this.restart();
}
}.bind(this)
)
}
}.bind(this)
)
}
//this.restart();
}.bind(this)
this.delayedInstanceEncountered.bind(this)
);
/**
* If we have touch controls - inject them first so we can override editor controls if necessary
*/
if (this.touchControls.length > 0) {
this.registerTouchControls();
this.sensitivityCounter = 0;
this.registerKeyboardControls();
this.registerMouseControls();
if (this.touchControls.length > 1) {
console.warn('too many touch controls - will use ' + this.touchControls[0].name)
this.registerEditorControls();
};
/**
*
*/
GameLib.System.Input.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.delayedInstanceEncounteredSubscription.remove();
this.deRegisterEditorControls();
this.deRegisterTouchControls();
this.deRegisterKeyboardControls();
this.deRegisterMouseControls();
this.editorControls = [];
this.touchControls = [];
this.keyboardControls = [];
this.mouseControls = [];
};
/**
* From now on we want to track everything about a component, only from the systems that are active
* @param data
*/
GameLib.System.Input.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Controls.Editor) {
if (this.editorControls.length > 0) {
console.log('ignoring multiple editor controls')
} else {
this.editorControls.push(data.component);
this.registerEditorControls();
}
}
if (data.component instanceof GameLib.D3.Controls.Touch) {
if (this.touchControls.length > 0) {
console.log('ignoring multiple touch controls')
} else {
this.touchControls.push(data.component);
this.registerTouchControls();
}
}
if (data.component instanceof GameLib.D3.Controls.Keyboard) {
if (this.keyboardControls.length > 0) {
console.log('ignoring multiple keyboard controls')
} else {
this.keyboardControls.push(data.component);
this.registerKeyboardControls();
}
}
if (data.component instanceof GameLib.D3.Controls.Mouse) {
if (this.mouseControls.length > 0) {
console.log('ignoring multiple mouse controls')
} else {
this.mouseControls.push(data.component);
this.registerMouseControls();
}
}
};
/**
* Removes a particle engine from this system
* @param data
*/
GameLib.System.Input.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.D3.Controls.Editor) {
var index = this.editorControls.indexOf(data.component);
if (index !== -1) {
console.log('removing editor controls from system');
this.deRegisterEditorControls();
this.editorControls.splice(index, 1);
} else {
console.log('failed to find the editor controls in the system - probably it was ignored - ' + data.component.name);
}
var touchControl = this.touchControls[0];
this.touchSensitivity = touchControl.sensitivity;
touchControl.domElement.instance.addEventListener(
'touchstart',
this.touchStart,
false
);
touchControl.domElement.instance.addEventListener(
'touchmove',
this.touchMove,
false
);
touchControl.domElement.instance.addEventListener(
'touchend',
this.touchEnd,
false
);
touchControl.domElement.instance.addEventListener(
'touchcancel',
this.touchCancel,
false
);
}
};
/**
* Delayed Instance - we need to check if editControls will block the loading process (since only one will be created)
* @param data
*/
GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) {
if (data.component instanceof GameLib.D3.Controls.Editor) {
if (this.editorControls.length === 0) {
/**
* We need to register these controls so instance creation can continue
*/
this.editorControls.push(data.component);
this.registerEditorControls();
} else {
/**
* There are already another editor controls, these ones will never get created, we need to
* notify our linking system of this problem so loading can continue
*/
data.component.createInstance();
}
}
};
GameLib.System.Input.prototype.registerTouchControls = function() {
if (this.touchControls.length !== 1) {
return;
}
var touchControl = this.touchControls[0];
this.touchSensitivity = touchControl.sensitivity;
this.touchStart = this.onTouchStart.bind(this);
this.touchMove = this.onTouchMove.bind(this);
this.touchEnd = this.onTouchEnd.bind(this);
this.touchCancel = this.onTouchCancel.bind(this);
touchControl.domElement.instance.addEventListener(
'touchstart',
this.touchStart,
false
);
touchControl.domElement.instance.addEventListener(
'touchmove',
this.touchMove,
false
);
touchControl.domElement.instance.addEventListener(
'touchend',
this.touchEnd,
false
);
touchControl.domElement.instance.addEventListener(
'touchcancel',
this.touchCancel,
false
);
};
GameLib.System.Input.prototype.registerKeyboardControls = function() {
if (this.keyboardControls.length !== 1) {
return;
}
var keyboardControl = this.keyboardControls[0];
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
keyboardControl.domElement.instance.addEventListener(
'keyup',
this.keyboardKeyUp,
false
);
keyboardControl.domElement.instance.addEventListener(
'keydown',
this.keyboardKeyDown,
false
);
};
GameLib.System.Input.prototype.registerMouseControls = function() {
if (this.mouseControls.length !== 1) {
return;
}
var mouseControl = this.mouseControls[0];
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
mouseControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
false
);
mouseControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheel,
false
);
mouseControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUp,
false
);
};
GameLib.System.Input.prototype.registerEditorControls = function() {
if (this.editorControls.length !== 1) {
return;
}
var editorControl = this.editorControls[0];
/**
* Same for keyboard controls
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
*/
if (this.keyboardControls.length > 0) {
this.keyboardControls.map(
function(keyboardControl) {
keyboardControl.domElement.instance.addEventListener(
'keyup',
this.keyboardKeyUp,
false
);
keyboardControl.domElement.instance.addEventListener(
'keydown',
this.keyboardKeyDown,
false
);
}.bind(this)
)
}
if (this.mouseControls.length > 0) {
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
/**
* Do Nothing
*/
this.mouseControls.map(
function(mouseControl) {
mouseControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
false
);
} else {
mouseControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheel,
false
);
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
editorControl.domElement.instance.addEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.addEventListener(
'keyup',
this.keyUp,
false
);
mouseControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUp,
false
);
}.bind(this)
)
}
if (this.editorControls.length > 0) {
this.editorControls.map(
function(editorControl) {
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
// if (this.mouseControls.length < 1) {
editorControl.createInstance();
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
// }
editorControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUpEdit,
false
);
};
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
*/
if (this.keyboardControls.length > 0) {
/**
* Do Nothing
*/
} else {
GameLib.System.Input.prototype.deRegisterEditorControls = function() {
editorControl.domElement.instance.addEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.addEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.createInstance();
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
// if (this.mouseControls.length < 1) {
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUpEdit,
false
);
// }
}.bind(this)
)
if (this.editorControls.length !== 1) {
return;
}
var editorControl = this.editorControls[0];
editorControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
if (this.keyboardControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.instance.dispose();
editorControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUpEdit,
false
);
};
GameLib.System.Input.prototype.deRegisterTouchControls = function() {
if (this.touchControls.length !== 1) {
return;
}
var touchControl = this.touchControls[0];
touchControl.domElement.instance.removeEventListener(
'touchstart',
this.touchStart,
false
);
touchControl.domElement.instance.removeEventListener(
'touchmove',
this.touchMove,
false
);
touchControl.domElement.instance.removeEventListener(
'touchend',
this.touchEnd,
false
);
touchControl.domElement.instance.removeEventListener(
'touchcancel',
this.touchCancel,
false
);
};
GameLib.System.Input.prototype.deRegisterKeyboardControls = function() {
if (this.keyboardControls.length !== 1) {
return;
}
var keyboardControl = this.keyboardControls[0];
keyboardControl.domElement.instance.removeEventListener(
'keydown',
this.keyboardKeyDown,
false
);
keyboardControl.domElement.instance.removeEventListener(
'keyup',
this.keyboardKeyUp,
false
);
};
GameLib.System.Input.prototype.deRegisterMouseControls = function() {
if (this.mouseControls.length !== 1) {
return;
}
var mouseControl = this.mouseControls[0];
mouseControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDown,
false
);
mouseControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheel,
false
);
mouseControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUp,
false
);
};
GameLib.System.Input.prototype.onKeyboardKeyUp = function(event) {
@ -720,152 +995,7 @@ GameLib.System.Input.prototype.deSelectMesh = function(mesh) {
);
};
/**
*
*/
GameLib.System.Input.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.delayedInstanceEncounteredSubscription.remove();
if (this.editorControls.length > 0) {
/**
* Now remove all input capabilities
*/
this.editorControls.map(
function(editorControl) {
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
// }
if (this.keyboardControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.instance.dispose();
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUpEdit,
false
);
// }
}.bind(this)
)
}
if (this.touchControls.length > 0) {
this.touchControls.map(
function(touchControl) {
touchControl.domElement.instance.removeEventListener(
'touchstart',
this.touchStart,
false
);
touchControl.domElement.instance.removeEventListener(
'touchmove',
this.touchMove,
false
);
touchControl.domElement.instance.removeEventListener(
'touchend',
this.touchEnd,
false
);
touchControl.domElement.instance.removeEventListener(
'touchcancel',
this.touchCancel,
false
);
}.bind(this)
)
}
if (this.keyboardControls.length > 0) {
this.keyboardControls.map(
function(keyboardControl) {
keyboardControl.domElement.instance.removeEventListener(
'keydown',
this.keyboardKeyDown,
false
);
keyboardControl.domElement.instance.removeEventListener(
'keyup',
this.keyboardKeyUp,
false
);
}.bind(this)
)
}
if (this.mouseControls.length > 0) {
this.mouseControls.map(
function(mouseControl) {
mouseControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDown,
false
);
mouseControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheel,
false
);
mouseControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUp,
false
);
}.bind(this)
)
}
};

View File

@ -51,10 +51,10 @@ GameLib.System.Particle.prototype.start = function() {
this.instanceCreated.bind(this)
);
this.instanceUpdatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.PARTICLE_INSTANCE_UPDATED,
this.instanceUpdated.bind(this)
);
// this.instanceUpdatedSubscription = GameLib.Event.Subscribe(
// GameLib.Event.PARTICLE_INSTANCE_UPDATED,
// this.instanceUpdated.bind(this)
// );
this.removeComponentSubscription = GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
@ -82,17 +82,7 @@ GameLib.System.Particle.prototype.instanceCreated = function(data) {
};
GameLib.System.Particle.prototype.instanceUpdated = function(data) {
//if (data.component instanceof GameLib.D3.ParticleEngine) {
console.log('particle engine updated : ' + data.component.name);
//this.particleEngines.push(data.component);
//this.initialize(data.component);
//}
// console.log('particle engine updated : ' + data.component.name);
};
/**
@ -128,7 +118,16 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
this.particleEngines.map(
function(particleEngine) {
particleEngine.elapsed += data.delta;
if (particleEngine.enabled) {
particleEngine.elapsed += data.delta;
particleEngine.processParticles(data.delta);
if (particleEngine.elapsed > particleEngine.frequency) {
particleEngine.elapsed = 0;
particleEngine.createNewParticle();
}
}
// var position = this.camera.position.instance.clone();
// var lookAt = this.camera.lookAt.instance.clone();
@ -158,7 +157,7 @@ GameLib.System.Particle.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.instanceCreatedSubscription.remove();
this.instanceUpdatedSubscription.remove();
// this.instanceUpdatedSubscription.remove();
this.removeComponentSubscription.remove();
this.beforeRenderSubscription.remove();

View File

@ -30,6 +30,16 @@ GameLib.System.Render.prototype.start = function() {
this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Stats);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
this.removeComponentSubscription = GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this)
);
this.renderSubscription = this.subscribe(
GameLib.Event.RENDER,
this.render
@ -37,6 +47,41 @@ GameLib.System.Render.prototype.start = function() {
};
/**
* From now on we want to track everything about a component, only from the systems that are active
* @param data
*/
GameLib.System.Render.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Renderer) {
console.log('new renderer');
this.renderers.push(data.component);
}
};
/**
* Removes a particle engine from this system
* @param data
*/
GameLib.System.Render.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.D3.Renderer) {
var index = this.renderers.indexOf(data.component);
if (index !== -1) {
console.log('removing renderer from system');
this.renderers.splice(index, 1);
} else {
console.log('failed to find the renderer in the system : ' + data.component.name);
}
}
};
/**
* Render subscription script
*/
@ -118,17 +163,22 @@ GameLib.System.Render.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.renderers.map(
function(renderer) {
if (renderer.statistics) {
renderer.statistics.resize();
renderer.domElement.instance.parentElement.removeChild(renderer.statistics.instance.dom);
}
}
);
this.instanceCreatedSubscription.remove();
this.renderers = [];
this.removeComponentSubscription.remove();
this.renderSubscription.remove();
this.renderers.map(
function(renderer) {
if (renderer.statistics) {
renderer.statistics.resize();
renderer.domElement.instance.parentElement.removeChild(renderer.statistics.instance.dom);
}
}
);
this.renderers = [];
this.renderSubscription.remove();
};