- moved particle storage into FLevelLocals.

- moved parts of the render setup out of the separate render functions.

Things like particle and polyobject linking were duplicated several times for rendering different things in different renderers.
These things only need to be set up once before the renderer is started so it makes a lot more sense to consolidate them into one place outside the actual rendering code.
This commit is contained in:
Christoph Oelckers 2019-01-29 01:09:02 +01:00
commit 68667e5eaa
22 changed files with 139 additions and 128 deletions

View file

@ -59,12 +59,6 @@ FRandom pr_railtrail("RailTrail");
#define FADEFROMTTL(a) (1.f/(a))
// [RH] particle globals
uint32_t ActiveParticles;
uint32_t InactiveParticles;
TArray<particle_t> Particles;
TArray<uint16_t> ParticlesInSubsec;
static int grey1, grey2, grey3, grey4, red, green, blue, yellow, black,
red1, green1, blue1, yellow1, purple, purple1, white,
rblue1, rblue2, rblue3, rblue4, orange, yorange, dred, grey5,
@ -103,15 +97,15 @@ static const struct ColorList {
{NULL, 0, 0, 0 }
};
inline particle_t *NewParticle (void)
inline particle_t *NewParticle (FLevelLocals *Level)
{
particle_t *result = nullptr;
if (InactiveParticles != NO_PARTICLE)
if (Level->InactiveParticles != NO_PARTICLE)
{
result = &Particles[InactiveParticles];
InactiveParticles = result->tnext;
result->tnext = ActiveParticles;
ActiveParticles = uint32_t(result - Particles.Data());
result = &Level->Particles[Level->InactiveParticles];
Level->InactiveParticles = result->tnext;
result->tnext = Level->ActiveParticles;
Level->ActiveParticles = uint32_t(result - Level->Particles.Data());
}
return result;
}
@ -119,7 +113,7 @@ inline particle_t *NewParticle (void)
//
// [RH] Particle functions
//
void P_InitParticles ();
void P_InitParticles (FLevelLocals *);
// [BC] Allow the maximum number of particles to be specified by a cvar (so people
// with lots of nice hardware can have lots of particles!).
@ -134,11 +128,14 @@ CUSTOM_CVAR( Int, r_maxparticles, 4000, CVAR_ARCHIVE )
if ( gamestate != GS_STARTUP )
{
P_InitParticles( );
for (auto Level : AllLevels())
{
P_InitParticles(Level);
}
}
}
void P_InitParticles ()
void P_InitParticles (FLevelLocals *Level)
{
const char *i;
int num;
@ -152,45 +149,45 @@ void P_InitParticles ()
// This should be good, but eh...
int NumParticles = clamp<int>(num, 100, 65535);
Particles.Resize(NumParticles);
P_ClearParticles ();
Level->Particles.Resize(NumParticles);
P_ClearParticles (Level);
}
void P_ClearParticles ()
void P_ClearParticles (FLevelLocals *Level)
{
int i = 0;
memset (Particles.Data(), 0, Particles.Size() * sizeof(particle_t));
ActiveParticles = NO_PARTICLE;
InactiveParticles = 0;
for (auto &p : Particles)
memset (Level->Particles.Data(), 0, Level->Particles.Size() * sizeof(particle_t));
Level->ActiveParticles = NO_PARTICLE;
Level->InactiveParticles = 0;
for (auto &p : Level->Particles)
p.tnext = ++i;
Particles.Last().tnext = NO_PARTICLE;
Level->Particles.Last().tnext = NO_PARTICLE;
}
// Group particles by subsectors. Because particles are always
// in motion, there is little benefit to caching this information
// from one frame to the next.
void P_FindParticleSubsectors ()
void P_FindParticleSubsectors (FLevelLocals *Level)
{
if (ParticlesInSubsec.Size() < level.subsectors.Size())
if (Level->ParticlesInSubsec.Size() < level.subsectors.Size())
{
ParticlesInSubsec.Reserve (level.subsectors.Size() - ParticlesInSubsec.Size());
Level->ParticlesInSubsec.Reserve (level.subsectors.Size() - Level->ParticlesInSubsec.Size());
}
fillshort (&ParticlesInSubsec[0], level.subsectors.Size(), NO_PARTICLE);
fillshort (&Level->ParticlesInSubsec[0], level.subsectors.Size(), NO_PARTICLE);
if (!r_particles)
{
return;
}
for (uint16_t i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext)
for (uint16_t i = Level->ActiveParticles; i != NO_PARTICLE; i = Level->Particles[i].tnext)
{
// Try to reuse the subsector from the last portal check, if still valid.
if (Particles[i].subsector == NULL) Particles[i].subsector = R_PointInSubsector(Particles[i].Pos);
int ssnum = Particles[i].subsector->Index();
Particles[i].snext = ParticlesInSubsec[ssnum];
ParticlesInSubsec[ssnum] = i;
if (Level->Particles[i].subsector == nullptr) Level->Particles[i].subsector = R_PointInSubsector(Level->Particles[i].Pos);
int ssnum = Level->Particles[i].subsector->Index();
Level->Particles[i].snext = Level->ParticlesInSubsec[ssnum];
Level->ParticlesInSubsec[ssnum] = i;
}
}
@ -220,7 +217,6 @@ void P_InitEffects ()
{
const struct ColorList *color = Colors;
P_InitParticles();
while (color->color)
{
*(color->color) = ParticleColor(color->r, color->g, color->b);
@ -232,16 +228,16 @@ void P_InitEffects ()
blood2 = ParticleColor(RPART(kind)/3, GPART(kind)/3, BPART(kind)/3);
}
void P_ThinkParticles ()
void P_ThinkParticles (FLevelLocals *Level)
{
int i;
particle_t *particle, *prev;
i = ActiveParticles;
i = Level->ActiveParticles;
prev = NULL;
while (i != NO_PARTICLE)
{
particle = &Particles[i];
particle = &Level->Particles[i];
i = particle->tnext;
if (!particle->notimefreeze && level.isFrozen())
{
@ -258,9 +254,9 @@ void P_ThinkParticles ()
if (prev)
prev->tnext = i;
else
ActiveParticles = i;
particle->tnext = InactiveParticles;
InactiveParticles = (int)(particle - Particles.Data());
Level->ActiveParticles = i;
particle->tnext = Level->InactiveParticles;
Level->InactiveParticles = (int)(particle - Level->Particles.Data());
continue;
}
@ -299,10 +295,10 @@ enum PSFlag
PS_NOTIMEFREEZE = 1 << 5,
};
void P_SpawnParticle(const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size,
void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size,
double fadestep, double sizestep, int flags)
{
particle_t *particle = NewParticle();
particle_t *particle = NewParticle(Level);
if (particle)
{
@ -326,7 +322,7 @@ void P_SpawnParticle(const DVector3 &pos, const DVector3 &vel, const DVector3 &a
//
// Run effects on all actors in the world
//
void P_RunEffects ()
void P_RunEffects (FLevelLocals *Level)
{
if (players[consoleplayer].camera == NULL) return;
@ -339,10 +335,7 @@ void P_RunEffects ()
{
if (actor->effects || actor->fountaincolor)
{
// Only run the effect if the actor is potentially visible
int rnum = pnum + actor->Sector->Index();
if (level.rejectmatrix.Size() == 0 || !(level.rejectmatrix[rnum>>3] & (1 << (rnum & 7))))
P_RunEffect (actor, actor->effects);
P_RunEffect (actor, actor->effects);
}
}
}
@ -352,14 +345,14 @@ void P_RunEffects ()
//
// Creates a particle with "jitter"
//
particle_t *JitterParticle (int ttl)
particle_t *JitterParticle (FLevelLocals *Level, int ttl)
{
return JitterParticle (ttl, 1.0);
return JitterParticle (Level, ttl, 1.0);
}
// [XA] Added "drift speed" multiplier setting for enhanced railgun stuffs.
particle_t *JitterParticle (int ttl, double drift)
particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift)
{
particle_t *particle = NewParticle ();
particle_t *particle = NewParticle (Level);
if (particle) {
int i;
@ -385,7 +378,7 @@ static void MakeFountain (AActor *actor, int color1, int color2)
if (!(level.time & 1))
return;
particle = JitterParticle (51);
particle = JitterParticle (actor->Level, 51);
if (particle)
{
@ -425,7 +418,7 @@ void P_RunEffect (AActor *actor, int effects)
DAngle an = moveangle + 90.;
double speed;
particle = JitterParticle (3 + (M_Random() & 31));
particle = JitterParticle (actor->Level, 3 + (M_Random() & 31));
if (particle) {
double pathdist = M_Random() / 256.;
DVector3 pos = actor->Vec3Offset(
@ -442,7 +435,7 @@ void P_RunEffect (AActor *actor, int effects)
particle->size = 2;
}
for (i = 6; i; i--) {
particle_t *particle = JitterParticle (3 + (M_Random() & 31));
particle_t *particle = JitterParticle (actor->Level, 3 + (M_Random() & 31));
if (particle) {
double pathdist = M_Random() / 256.;
DVector3 pos = actor->Vec3Offset(
@ -471,7 +464,7 @@ void P_RunEffect (AActor *actor, int effects)
DVector3 pos = actor->Vec3Angle(-actor->radius * 2, moveangle, -actor->Height * actor->Vel.Z / 8 + actor->Height * (2. / 3));
P_DrawSplash2 (6, pos, moveangle + 180, 2, 2);
P_DrawSplash2 (actor->Level, 6, pos, moveangle + 180, 2, 2);
}
if (actor->fountaincolor)
{
@ -498,7 +491,7 @@ void P_RunEffect (AActor *actor, int effects)
for (i = 3; i > 0; i--)
{
particle = JitterParticle (16);
particle = JitterParticle (actor->Level, 16);
if (particle != NULL)
{
DAngle ang = M_Random() * (360 / 256.);
@ -519,7 +512,7 @@ void P_RunEffect (AActor *actor, int effects)
}
}
void P_DrawSplash (int count, const DVector3 &pos, DAngle angle, int kind)
void P_DrawSplash (FLevelLocals *Level, int count, const DVector3 &pos, DAngle angle, int kind)
{
int color1, color2;
@ -535,7 +528,7 @@ void P_DrawSplash (int count, const DVector3 &pos, DAngle angle, int kind)
for (; count; count--)
{
particle_t *p = JitterParticle (10);
particle_t *p = JitterParticle (Level, 10);
if (!p)
break;
@ -553,7 +546,7 @@ void P_DrawSplash (int count, const DVector3 &pos, DAngle angle, int kind)
}
}
void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, int kind)
void P_DrawSplash2 (FLevelLocals *Level, int count, const DVector3 &pos, DAngle angle, int updown, int kind)
{
int color1, color2, zadd;
double zvel, zspread;
@ -584,7 +577,7 @@ void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, in
for (; count; count--)
{
particle_t *p = NewParticle ();
particle_t *p = NewParticle (Level);
DAngle an;
if (!p)
@ -724,7 +717,7 @@ void P_DrawRailTrail(AActor *source, TArray<SPortalHit> &portalhits, int color1,
deg = (double)SpiralOffset;
for (i = spiral_steps; i; i--)
{
particle_t *p = NewParticle ();
particle_t *p = NewParticle (source->Level);
DVector3 tempvec;
if (!p)
@ -795,7 +788,7 @@ void P_DrawRailTrail(AActor *source, TArray<SPortalHit> &portalhits, int color1,
{
// [XA] inner trail uses a different default duration (33).
int innerduration = (duration == 0) ? 33 : duration;
particle_t *p = JitterParticle (innerduration, (float)drift);
particle_t *p = JitterParticle (source->Level, innerduration, (float)drift);
if (!p)
return;
@ -915,7 +908,7 @@ void P_DisconnectEffect (AActor *actor)
for (i = 64; i; i--)
{
particle_t *p = JitterParticle (TICRATE*2);
particle_t *p = JitterParticle (actor->Level, TICRATE*2);
if (!p)
break;