From a483ad20be3ac83403ccfb68a121c79bb70e122a Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sun, 13 Nov 2022 13:50:33 -0600 Subject: [PATCH] Replaced memset for particles as recommended by dpJudas --- src/playsim/p_effect.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index ee1be6a02d1..697d608ab90 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -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; } @@ -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; } @@ -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