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

View file

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

View file

@ -57,17 +57,17 @@ struct particle_t
DVector3 Pos; DVector3 Pos;
DVector3 Vel; DVector3 Vel;
DVector3 Acc; DVector3 Acc;
BYTE ttl;
BYTE trans;
double size; double size;
double sizestep; double sizestep;
subsector_t * subsector;
short ttl;
BYTE bright; BYTE bright;
BYTE fade; bool notimefreeze;
float fadestep;
float alpha;
int color; int color;
WORD tnext; WORD tnext;
WORD snext; WORD snext;
subsector_t * subsector;
bool notimefreeze;
}; };
extern particle_t *Particles; 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->startfrac = 255 & (particle->color >>24);
vis->pic = NULL; vis->pic = NULL;
vis->bIsVoxel = false; vis->bIsVoxel = false;
vis->renderflags = particle->trans; vis->renderflags = short(particle->alpha * 255);
vis->FakeFlatStat = fakeside; vis->FakeFlatStat = fakeside;
vis->floorclip = 0; vis->floorclip = 0;
vis->ColormapNum = 0; vis->ColormapNum = 0;