Skip to content
Snippets Groups Projects
Commit 7d8f1088 authored by dg's avatar dg
Browse files

fix

git-svn-id: http://svn.net-core.org/repos/t-engine4@2062 51575b47-30f0-44d4-a5cc-537603b46e54
parent 8790386d
No related branches found
No related tags found
No related merge requests found
......@@ -957,19 +957,28 @@ function _M:displayParticles(nb_keyframes)
local del = {}
local e = next(self.particles)
while e do
local alive = true
for i = 1, nb_keyframes do alive = not e.update(e) end
-- Dont bother with obviously out of screen stuff
if alive and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
alive = e.ps:toScreen(self.display_x + (e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y), e.zoom * self.zoom, nb_keyframes)
end
if nb_keyframes == 0 then alive = true end
if nb_keyframes == 0 then
-- Just display it, not updating, no emiting
if e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
alive = e.ps:toScreen(self.display_x + (e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y), e.zoom * self.zoom)
end
else
-- Update more, if needed
for i = 1, nb_keyframes do
local alive = not e.update(e)
-- Only draw the first keyframe
if i == 1 and alive and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
alive = e.ps:toScreen(self.display_x + (e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y), e.zoom * self.zoom, nb_keyframes)
end
-- Update the particles enough times
e.ps:update()
if not alive then
del[#del+1] = e
e.dead = true
if i == 1 and not alive then
del[#del+1] = e
e.dead = true
end
end
end
e = next(self.particles, e)
......
......@@ -272,7 +272,6 @@ static int particles_to_screen(lua_State *L)
int y = luaL_checknumber(L, 3);
bool show = lua_toboolean(L, 4);
float zoom = luaL_checknumber(L, 5);
int keyframes = luaL_checknumber(L, 6);
int kf;
int w = 0;
int i, j;
......@@ -334,41 +333,64 @@ static int particles_to_screen(lua_State *L)
}
glEnd();
}
}
}
for (kf = 0; kf < keyframes; kf++)
{
if (p->life != PARTICLE_ETERNAL) p->life--;
// Restore normal display
glColor4f(1, 1, 1, 1);
p->ox = p->x;
p->oy = p->y;
lua_pushboolean(L, alive || ps->no_stop);
return 1;
}
p->x += p->xv;
p->y += p->yv;
static int particles_update(lua_State *L)
{
particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1);
int w = 0;
int i, j;
bool alive = FALSE;
if (p->vel)
{
p->x += cos(p->dir) * p->vel;
p->y += sin(p->dir) * p->vel;
}
glBindTexture(GL_TEXTURE_2D, ps->texture);
p->dir += p->dirv;
p->vel += p->velv;
p->r += p->rv;
p->g += p->gv;
p->b += p->bv;
p->a += p->av;
p->size += p->sizev;
p->xv += p->xa;
p->yv += p->ya;
p->dirv += p->dira;
p->velv += p->vela;
p->rv += p->ra;
p->gv += p->ga;
p->bv += p->ba;
p->av += p->aa;
p->sizev += p->sizea;
for (w = 0; w < ps->nb; w++)
{
particle_type *p = &ps->particles[w];
if (p->life > 0)
{
alive = TRUE;
if (p->life != PARTICLE_ETERNAL) p->life--;
p->ox = p->x;
p->oy = p->y;
p->x += p->xv;
p->y += p->yv;
if (p->vel)
{
p->x += cos(p->dir) * p->vel;
p->y += sin(p->dir) * p->vel;
}
p->dir += p->dirv;
p->vel += p->velv;
p->r += p->rv;
p->g += p->gv;
p->b += p->bv;
p->a += p->av;
p->size += p->sizev;
p->xv += p->xa;
p->yv += p->ya;
p->dirv += p->dira;
p->velv += p->vela;
p->rv += p->ra;
p->gv += p->ga;
p->bv += p->ba;
p->av += p->aa;
p->sizev += p->sizea;
}
}
......@@ -391,6 +413,7 @@ static const struct luaL_reg particles_reg[] =
{"close", particles_free},
{"emit", particles_emit},
{"toScreen", particles_to_screen},
{"update", particles_update},
{NULL, NULL},
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment