particle emitters store and reuse particles
This commit is contained in:
parent
9d51858266
commit
531cc1b43e
|
@ -46,7 +46,18 @@ emitter.die_hook = std_die;
|
|||
emitter.spawn = function(t)
|
||||
{
|
||||
t ??= this.transform;
|
||||
var par = {
|
||||
|
||||
var par = this.dead.shift();
|
||||
if (par) {
|
||||
par.body.pos = t.pos;
|
||||
par.transform.scale = [this.scale,this.scale,this.scale];
|
||||
this.particles[par.id] = par;
|
||||
par.time = 0;
|
||||
this.spawn_hook(par);
|
||||
return;
|
||||
}
|
||||
|
||||
par = {
|
||||
transform: os.make_transform(),
|
||||
life: this.life,
|
||||
time: 0,
|
||||
|
@ -83,6 +94,7 @@ emitter.step = function(dt)
|
|||
|
||||
if (p.time >= p.life) {
|
||||
this.die_hook(p);
|
||||
this.dead.push(this.particles[p.id]);
|
||||
delete this.particles[p.id];
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +110,7 @@ var make_emitter = function()
|
|||
e.ssbo = render.make_textssbo();
|
||||
e.shape = shape.quad;
|
||||
e.shader = render.make_shader("shaders/baseparticle.cg");
|
||||
e.dead = [];
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue