- floatified the translucency values in particle_t to elimintate the gross inaccuracies with fadeout time.

- widened ttl variable in particle_t to short to allow longer living particles than 6 seconds.
- reordered fields in particle_t to reduce struct size a bit.
This commit is contained in:
Christoph Oelckers 2017-01-07 13:13:16 +01:00
parent 8b001956ad
commit 362551e58d
4 changed files with 21 additions and 22 deletions

View file

@ -1060,7 +1060,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
player_t *player=&players[consoleplayer];
if (particle->trans==0) return;
if (particle->alpha==0) return;
lightlevel = gl_ClampLight(sector->GetTexture(sector_t::ceiling) == skyflatnum ?
sector->GetCeilingLight() : sector->GetFloorLight());
@ -1100,7 +1100,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
Colormap.ClearColor();
}
trans=particle->trans/255.0f;
trans=particle->alpha;
RenderStyle = STYLE_Translucent;
OverrideShader = 0;

View file

@ -62,7 +62,7 @@ CVAR (Bool, r_particles, true, 0);
FRandom pr_railtrail("RailTrail");
#define FADEFROMTTL(a) (255/(a))
#define FADEFROMTTL(a) (1.f/(a))
// [RH] particle globals
WORD NumParticles;
@ -269,11 +269,10 @@ void P_ThinkParticles ()
continue;
}
BYTE oldtrans;
oldtrans = particle->trans;
particle->trans -= particle->fade;
auto oldtrans = particle->alpha;
particle->alpha -= particle->fadestep;
particle->size += particle->sizestep;
if (oldtrans < particle->trans || --particle->ttl <= 0 || (particle->size <= 0))
if (oldtrans < particle->alpha || --particle->ttl <= 0 || (particle->size <= 0))
{ // The particle has expired, so free it
memset (particle, 0, sizeof(particle_t));
if (prev)
@ -331,9 +330,9 @@ void P_SpawnParticle(const DVector3 &pos, const DVector3 &vel, const DVector3 &a
particle->Vel = vel;
particle->Acc = accel;
particle->color = ParticleColor(color);
particle->trans = BYTE(startalpha*255);
if (fadestep < 0) particle->fade = FADEFROMTTL(lifetime);
else particle->fade = int(fadestep * 255);
particle->alpha = float(startalpha);
if (fadestep < 0) particle->fadestep = FADEFROMTTL(lifetime);
else particle->fadestep = float(fadestep);
particle->ttl = lifetime;
particle->bright = !!(flags & PS_FULLBRIGHT);
particle->size = size;
@ -392,9 +391,9 @@ particle_t *JitterParticle (int ttl, double drift)
for (i = 3; i; i--)
particle->Acc[i] = ((1./16384) * (M_Random () - 128) * drift);
particle->trans = 255; // fully opaque
particle->alpha = 1.f; // fully opaque
particle->ttl = ttl;
particle->fade = FADEFROMTTL(ttl);
particle->fadestep = FADEFROMTTL(ttl);
}
return particle;
}
@ -622,8 +621,8 @@ void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, in
break;
p->ttl = 12;
p->fade = FADEFROMTTL(12);
p->trans = 255;
p->fadestep = FADEFROMTTL(12);
p->alpha = 1.f;
p->size = 4;
p->color = M_Random() & 0x80 ? color1 : color2;
p->Vel.Z = M_Random() * zvel;
@ -763,9 +762,9 @@ void P_DrawRailTrail(AActor *source, TArray<SPortalHit> &portalhits, int color1,
int spiralduration = (duration == 0) ? 35 : duration;
p->trans = 255;
p->alpha = 1.f;
p->ttl = duration;
p->fade = FADEFROMTTL(spiralduration);
p->fadestep = FADEFROMTTL(spiralduration);
p->size = 3;
p->bright = fullbright;

View file

@ -57,17 +57,17 @@ struct particle_t
DVector3 Pos;
DVector3 Vel;
DVector3 Acc;
BYTE ttl;
BYTE trans;
double size;
double sizestep;
subsector_t * subsector;
short ttl;
BYTE bright;
BYTE fade;
bool notimefreeze;
float fadestep;
float alpha;
int color;
WORD tnext;
WORD snext;
subsector_t * subsector;
bool notimefreeze;
};
extern particle_t *Particles;

View file

@ -2593,7 +2593,7 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
vis->startfrac = 255 & (particle->color >>24);
vis->pic = NULL;
vis->bIsVoxel = false;
vis->renderflags = particle->trans;
vis->renderflags = short(particle->alpha * 255);
vis->FakeFlatStat = fakeside;
vis->floorclip = 0;
vis->ColormapNum = 0;