From 68639f9772032f2859db00eef1a3012482807c5e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 23 Feb 2020 00:24:12 +1100 Subject: [PATCH] Make CustomParticle_Render slightly faster --- src/Particle.c | 5 ++--- src/Particle.h | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Particle.c b/src/Particle.c index 428d5b297..f1217acc3 100644 --- a/src/Particle.c +++ b/src/Particle.c @@ -322,9 +322,8 @@ static void CustomParticle_Render(struct CustomParticle* p, float t, VertexP3fT2 TextureRec rec = e->rec; int x, y, z; - float frame_time = p->totalLifespan / e->frameCount; - float inverted_lifetime = Math_AbsF(p->base.lifetime - p->totalLifespan); - int curFrame = Math_Floor(inverted_lifetime / frame_time); + float time_lived = p->totalLifespan - p->base.lifetime; + int curFrame = Math_Floor(e->frameCount * (time_lived / p->totalLifespan)); float shiftU = curFrame * (rec.U2 - rec.U1); rec.U1 += shiftU;// * 0.0078125f; diff --git a/src/Particle.h b/src/Particle.h index 1d5dad4e8..93e4fd6af 100644 --- a/src/Particle.h +++ b/src/Particle.h @@ -26,10 +26,10 @@ struct CustomParticleEffect { cc_bool fullBright; float size; float sizeVariation; - float spread; //how far from the spawnpoint their location can vary - float speed; //how fast they move away/towards the origin + float spread; /* how far from the spawnpoint their location can vary */ + float speed; /* how fast they move away/towards the origin */ float gravity; - float baseLifetime; //how long (in seconds) the particle lives for + float baseLifetime; /* how long (in seconds) the particle lives for */ float lifetimeVariation; };