Skip to content

Commit

Permalink
Replaced memset for particles as recommended by dpJudas
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorCooke authored and coelckers committed Nov 13, 2022
1 parent f044695 commit a483ad2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/playsim/p_effect.cpp
Expand Up @@ -130,9 +130,10 @@ inline particle_t *NewParticle (FLevelLocals *Level, bool replace = false)
particle_t* ntop = &Level->Particles[result->tnext];
ntop->tprev = Level->ActiveParticles;
}
// [MC] Future proof this by resetting everything when replacing a particle.
auto tnext = result->tnext;
auto tprev = result->tprev;
memset(result, 0, sizeof(particle_t));
*result = {};
result->tnext = tnext;
result->tprev = tprev;
}
Expand Down Expand Up @@ -185,12 +186,12 @@ void P_InitParticles (FLevelLocals *Level)
void P_ClearParticles (FLevelLocals *Level)
{
int i = 0;
memset (Level->Particles.Data(), 0, Level->Particles.Size() * sizeof(particle_t));
Level->OldestParticle = NO_PARTICLE;
Level->ActiveParticles = NO_PARTICLE;
Level->InactiveParticles = 0;
for (auto &p : Level->Particles)
{
p = {};
p.tprev = i - 1;
p.tnext = ++i;
}
Expand Down Expand Up @@ -281,7 +282,7 @@ void P_ThinkParticles (FLevelLocals *Level)
particle->size += particle->sizestep;
if (particle->alpha <= 0 || oldtrans < particle->alpha || --particle->ttl <= 0 || (particle->size <= 0))
{ // The particle has expired, so free it
memset (particle, 0, sizeof(particle_t));
*particle = {};
if (prev)
prev->tnext = i;
else
Expand Down

0 comments on commit a483ad2

Please sign in to comment.