From ce2bac455889913d37ad74681bb229186e76a253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Mon, 26 Feb 2024 00:46:13 -0300 Subject: [PATCH] start rewrite of particle multithreading --- src/playsim/p_effect.cpp | 62 +++++++++++++++++++++------------------- src/playsim/p_effect.h | 3 -- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index 197a5e1da55..1be461d3d47 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -34,12 +34,6 @@ ** more useful. */ -#if __has_include() && !( __linux__ || __APPLE__ ) - - #include - -#endif - #include "doomtype.h" #include "doomstat.h" @@ -212,6 +206,7 @@ void P_ReInitParticles (FLevelLocals *Level, int num) Level->ParticleIndices.Resize(MaxParticles); Level->Particles.Resize(MaxParticles); + for(int i = 0; i < MaxParticles; i++) { Level->ParticleIndices[i] = i; @@ -277,11 +272,9 @@ void P_FindParticleSubsectors (FLevelLocals *Level) return; } - particle_t * pp = Level->Particles.Data(); - for(uint32_t i = 0; i < Level->NumParticles; i++) { - particle_t * p = pp + Level->ParticleIndices[i]; + particle_t * p = Level->Particles.Data(Level->ParticleIndices[i]); assert(p->subsector); p->subsector->particles.Push(p); } @@ -403,32 +396,39 @@ void P_UpdateReplacedParticles(FLevelLocals *Level) P_FindParticleSubsectors(Level); } + + void P_ThinkParticles(FLevelLocals *Level) { uint64_t startNs = I_nsTime(); - uint32_t * newEnd; ParticleCount = Level->NumParticles; - particle_t * p = Level->Particles.Data(); - - auto proc = [Level, p](uint32_t i) + if(ParticleCount > 0) { - return P_ThinkParticle(Level, *(p + i)); - }; + particle_t * particles = Level->Particles.Data(); -#if __has_include() && !( __linux__ || __APPLE__ ) - if(r_particles_multithreaded) - { - newEnd = std::remove_if(std::execution::par_unseq, Level->ParticleIndices.Data(), Level->ParticleIndices.Data(Level->NumParticles), proc); - } - else -#endif - { - newEnd = std::remove_if(Level->ParticleIndices.Data(), Level->ParticleIndices.Data(Level->NumParticles), proc); - } + uint32_t * start = Level->ParticleIndices.Data(); + uint32_t * newEnd = Level->ParticleIndices.Data(Level->NumParticles - 1); - Level->NumParticles = reinterpret_cast(newEnd) - reinterpret_cast(Level->ParticleIndices.Data()); + if(r_particles_multithreaded) + { + //TODO + } + //else + { + for(uint32_t * i = newEnd; i >= start; i--) + { + if(P_ThinkParticle(Level, *(particles + *i))) + { + std::swap(*newEnd, *i); + newEnd--; + } + } + } + + Level->NumParticles = (newEnd + 1) - Level->ParticleIndices.Data(); + } ParticleThinkMsAvg[ticAvgPos] = ParticleThinkMs; ParticleReplaceCountAvg[ticAvgPos] = ParticleReplaceCount; @@ -476,10 +476,7 @@ void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &v // // Creates a particle with "jitter" // -particle_t *JitterParticle (FLevelLocals *Level, int ttl) -{ - return JitterParticle (Level, ttl, 1.0); -} + // [XA] Added "drift speed" multiplier setting for enhanced railgun stuffs. particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift) { @@ -504,6 +501,11 @@ particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift) return particle; } +particle_t *JitterParticle (FLevelLocals *Level, int ttl) +{ + return JitterParticle (Level, ttl, 1.0); +} + static void MakeFountain (AActor *actor, int color1, int color2) { particle_t *particle; diff --git a/src/playsim/p_effect.h b/src/playsim/p_effect.h index ee4e0c208a6..67e064e607a 100644 --- a/src/playsim/p_effect.h +++ b/src/playsim/p_effect.h @@ -102,9 +102,6 @@ void P_FindParticleSubsectors (FLevelLocals *Level); class AActor; -particle_t *JitterParticle (FLevelLocals *Level, int ttl); -particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift); - void P_UpdateReplacedParticles(FLevelLocals *Level); void P_ThinkParticles(FLevelLocals *Level);