dynamic lifetimes for particle systems

This commit is contained in:
James B. Pollack 2015-12-30 11:46:16 -08:00
parent a5c19c04e5
commit b7d0a75f25

View file

@ -56,7 +56,6 @@ var LINE_ENTITY_DIMENSIONS = {
var LINE_LENGTH = 500;
var PICK_MAX_DISTANCE = 500; // max length of pick-ray
//
// near grabbing
//
@ -129,6 +128,7 @@ var USE_PARTICLE_BEAM_FOR_SEARCHING = true;
var USE_ENTITY_LINES_FOR_MOVING = false;
var USE_OVERLAY_LINES_FOR_MOVING = false;
var USE_PARTICLE_BEAM_FOR_MOVING = true;
var TEMPORARY_PARTICLE_BEAM_LIFETIME = 30;
var USE_SPOTLIGHT = false;
var USE_POINTLIGHT = false;
@ -549,6 +549,14 @@ function MyController(hand) {
};
this.renewParticleBeamLifetime = function(){
var props = Entities.getEntityProperties(this.particleBeam,"age");
Entities.editEntity(this.particleBeam,{
lifetime: TEMPORARY_PARTICLE_BEAM_LIFETIME + props.age // renew lifetime
})
var lifetime = Entities.getEntityProperties(this.particleBeam,"lfietime").lifetime;
}
this.evalLightWorldTransform = function(modelPos, modelRot) {
var MODEL_LIGHT_POSITION = {
@ -1803,4 +1811,26 @@ function cleanup() {
}
Script.scriptEnding.connect(cleanup);
Script.update.connect(update);
Script.update.connect(update);
// particle systems can end up hanging around if a user crashes or something else causes controller cleanup not to get called.
// we can't create the search system on-demand since it takes some time for the particles to reach their entire length.
// thus the system cannot have a fixed lifetime. this loop updates the lifetimes and will stop updating if a user crashes.
if(USE_PARTICLE_BEAM_FOR_SEARCHING===true || USE_PARTICLE_BEAM_FOR_SEARCHING ===true){
Script.update.connect(renewParticleBeamLifetimes)
}
var sinceLastParticleLifetimeUpdate = 0;
function renewParticleBeamLifetimes(deltaTime) {
//debounce this call since we don't want it 60x a second
sinceLastParticleLifetimeUpdate = sinceLastParticleLifetimeUpdate + deltaTime;
if (sinceLastParticleLifetimeUpdate > TEMPORARY_PARTICLE_BEAM_LIFETIME - 10) {
sinceLastParticleLifetimeUpdate = 0;
} else {
return;
}
rightController.renewParticleBeamLifetime();
leftController.renewParticleBeamLifetime();
}