remove particle engine slowly - todo: notify clones of being clones
parent
0d900614df
commit
e552963f30
|
@ -32,7 +32,7 @@ GameLib.Event.COMPONENT_CREATED = 0xe;
|
|||
GameLib.Event.COMPONENT_CLONED = 0xf;
|
||||
GameLib.Event.TEXTURE_ANIMATED_CHANGE = 0x10;
|
||||
GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
|
||||
//GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x12;
|
||||
GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12;
|
||||
//GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x13;
|
||||
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
|
||||
//GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x15;
|
||||
|
@ -139,7 +139,7 @@ GameLib.Event.GetEventName = function(number) {
|
|||
case 0xf : return 'component_cloned';
|
||||
case 0x10 : return 'texture_animated_change';
|
||||
case 0x11 : return 'animate_texture_instance';
|
||||
case 0x12 : return 'unused';//'rigid_body_instance_created';
|
||||
case 0x12 : return 'remove_particle_engine';
|
||||
case 0x13 : return 'unused';//'texture_instance_created';
|
||||
case 0x14 : return 'texture_instance_updated';
|
||||
case 0x15 : return 'unused';//'material_instance_created';
|
||||
|
|
|
@ -85,6 +85,8 @@ GameLib.D3.ParticleEngine = function(
|
|||
|
||||
this.particles = [];
|
||||
|
||||
this.disabledForRemoval = false;
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_PARTICLE_ENGINE,
|
||||
|
@ -116,6 +118,10 @@ GameLib.D3.ParticleEngine.prototype.createInstance = function() {
|
|||
this.templateParticle.direction.x = this.direction.x;
|
||||
this.templateParticle.direction.y = this.direction.y;
|
||||
this.templateParticle.direction.z = this.direction.z;
|
||||
|
||||
this.templateParticle.scale.x = this.scale.x;
|
||||
this.templateParticle.scale.y = this.scale.y;
|
||||
this.templateParticle.scale.z = this.scale.z;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
@ -162,6 +168,66 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
|
|||
this.templateParticle.direction.y = this.direction.y;
|
||||
this.templateParticle.direction.z = this.direction.z;
|
||||
}
|
||||
|
||||
if (property === 'scale') {
|
||||
|
||||
this.scale.updateInstance('direction', true);
|
||||
|
||||
this.templateParticle.scale.x = this.scale.x;
|
||||
this.templateParticle.scale.y = this.scale.y;
|
||||
this.templateParticle.scale.z = this.scale.z;
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.ParticleEngine.prototype.remove = function() {
|
||||
|
||||
GameLib.Event.Subscribe(
|
||||
GameLib.Event.REMOVE_PARTICLE_ENGINE,
|
||||
function(data){
|
||||
if (data.component === this) {
|
||||
/**
|
||||
* We only remove the things we cloned, the mesh, particle, and this
|
||||
*/
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REMOVE_COMPONENT,
|
||||
{
|
||||
component : this.templateParticle.mesh
|
||||
}
|
||||
);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REMOVE_COMPONENT,
|
||||
{
|
||||
component : this.templateParticle
|
||||
}
|
||||
);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REMOVE_COMPONENT,
|
||||
{
|
||||
component : this
|
||||
}
|
||||
)
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
/**
|
||||
* Below signals the particle system to continue processing the particles, but don't create more, and
|
||||
* we wait for the system to signal REMOVE_PARTICLE_ENGINE so we can destroy ourselves
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.disabledForRemoval = true;
|
||||
};
|
||||
|
||||
GameLib.D3.ParticleEngine.prototype.clone = function() {
|
||||
var mesh = this.templateParticle.mesh.clone();
|
||||
var templateParticle = this.templateParticle.clone();
|
||||
templateParticle.mesh = mesh;
|
||||
templateParticle.instance = mesh.instance;
|
||||
var engine = GameLib.Component.prototype.clone.call(this);
|
||||
engine.templateParticle = templateParticle;
|
||||
return engine;
|
||||
};
|
||||
|
||||
GameLib.D3.ParticleEngine.prototype.processParticles = function(delta) {
|
||||
|
|
|
@ -286,7 +286,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component
|
|||
affected.map(function(component){
|
||||
component.useQuaternion = true;
|
||||
component[property]['axis'].x = Number(value);
|
||||
component.updateInstance();
|
||||
component.updateInstance('x');
|
||||
})
|
||||
}
|
||||
);
|
||||
|
@ -302,7 +302,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component
|
|||
affected.map(function(component){
|
||||
component.useQuaternion = true;
|
||||
component[property]['axis'].y = Number(value);
|
||||
component.updateInstance();
|
||||
component.updateInstance('y');
|
||||
})
|
||||
}
|
||||
);
|
||||
|
@ -318,7 +318,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component
|
|||
affected.map(function(component){
|
||||
component.useQuaternion = true;
|
||||
component[property]['axis'].z = Number(value);
|
||||
component.updateInstance();
|
||||
component.updateInstance('z');
|
||||
})
|
||||
}
|
||||
);
|
||||
|
@ -654,7 +654,7 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
|
|||
componentTemplate.affected.map(
|
||||
function(component) {
|
||||
component[property] = newComponent;
|
||||
component.updateInstance();
|
||||
component.updateInstance(property);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -112,11 +112,11 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
|
|||
this.particleEngines.map(
|
||||
function(particleEngine) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(particleEngine.camera)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene) ||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(particleEngine.camera) ||
|
||||
GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle) ||
|
||||
GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh) ||
|
||||
GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene) ||
|
||||
GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene.instance)) {
|
||||
return;
|
||||
}
|
||||
|
@ -162,7 +162,16 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
|
|||
[]
|
||||
);
|
||||
|
||||
if (particleEngine.enabled) {
|
||||
if (particleEngine.disabledForRemoval && particleEngine.particles.length === 0) {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REMOVE_PARTICLE_ENGINE,
|
||||
{
|
||||
component : particleEngine
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (particleEngine.enabled && !particleEngine.disabledForRemoval) {
|
||||
|
||||
if (particleEngine.elapsed > particleEngine.frequency) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue