Skip to content

Commit

Permalink
add stat particles
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Oct 7, 2023
1 parent 29368f0 commit 10fe8f6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/playsim/p_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "vm.h"
#include "actorinlines.h"
#include "g_game.h"
#include "i_time.h"

CVAR (Int, cl_rockettrails, 1, CVAR_ARCHIVE);
CVAR (Bool, r_rail_smartspiral, false, CVAR_ARCHIVE);
Expand Down Expand Up @@ -99,11 +100,33 @@ static const struct ColorList {
{NULL, 0, 0, 0 }
};

static int ParticleCount;
static float ParticleThinkMs;
static float ParticleThinkMsAvg[5];
static uint64_t ParticleCreateNs;
static float ParticleCreateMsAvg[5];
static int ticAvgPos = 0;

ADD_STAT(particles)
{
FString str;
float ParticleCreateMs = ParticleCreateNs / 1000000.0f;
str.Format(
"Particle Count: %d, Particle Think Time: %.2f ms, Particle Create Time: %.2f ms\n"
"Average Particle Think Time (6tic): %.2f ms, Average Particle Create Time (6tic): %.2f ms\n"
, ParticleCount, ParticleThinkMs, ParticleCreateMs,
((ParticleThinkMsAvg[0] + ParticleThinkMsAvg[1] + ParticleThinkMsAvg[2] + ParticleThinkMsAvg[3] + ParticleThinkMsAvg[4] + ParticleThinkMs) / 6.0f),
((ParticleCreateMsAvg[0] + ParticleCreateMsAvg[1] + ParticleCreateMsAvg[2] + ParticleCreateMsAvg[3] + ParticleCreateMsAvg[4] + ParticleCreateMs) / 6.0f)
);
return str;
}

inline particle_t *NewParticle (FLevelLocals *Level, bool replace = false)
{
particle_t *result = nullptr;
// [MC] Thanks to RaveYard and randi for helping me with this addition.
// Array's filled up
uint64_t startNs = I_nsTime();
if (Level->InactiveParticles == NO_PARTICLE)
{
if (replace)
Expand Down Expand Up @@ -137,6 +160,7 @@ inline particle_t *NewParticle (FLevelLocals *Level, bool replace = false)
result->tnext = tnext;
result->tprev = tprev;
}
ParticleCreateNs += (I_nsTime() - startNs);
return result;
}

Expand All @@ -157,6 +181,7 @@ inline particle_t *NewParticle (FLevelLocals *Level, bool replace = false)
{
Level->OldestParticle = Level->ActiveParticles;
}
ParticleCreateNs += (I_nsTime() - startNs);
return result;
}

Expand Down Expand Up @@ -265,10 +290,13 @@ void P_InitEffects ()

void P_ThinkParticles (FLevelLocals *Level)
{
uint64_t startNs = I_nsTime();
ParticleCount = 0;
int i = Level->ActiveParticles;
particle_t *particle = nullptr, *prev = nullptr;
while (i != NO_PARTICLE)
{
ParticleCount++;
particle = &Level->Particles[i];
i = particle->tnext;
if (Level->isFrozen() && !(particle->flags &PT_NOTIMEFREEZE))
Expand Down Expand Up @@ -332,6 +360,13 @@ void P_ThinkParticles (FLevelLocals *Level)
}
prev = particle;
}
ParticleThinkMsAvg[ticAvgPos] = ParticleThinkMs;
ParticleCreateMsAvg[ticAvgPos] = ParticleCreateNs / 1000000.0f;

ticAvgPos = (ticAvgPos + 1) % 5;

ParticleCreateNs = 0;
ParticleThinkMs = ( I_nsTime() - startNs) / 1000000.0f;
}

enum PSFlag
Expand Down

0 comments on commit 10fe8f6

Please sign in to comment.