- floatified the particles.

This is the last bit of play code that needed to be altered, what's left is the underlying data representations of vertices, linedefs and sectors.

# Conflicts:
#	src/p_setup.cpp
#	src/r_things.cpp
This commit is contained in:
Christoph Oelckers 2016-04-02 13:28:43 +02:00
parent 931774ab38
commit 60e25b32a8
4 changed files with 93 additions and 126 deletions

View file

@ -149,15 +149,16 @@ CUSTOM_CVAR( Int, r_maxparticles, 4000, CVAR_ARCHIVE )
void P_InitParticles () void P_InitParticles ()
{ {
const char *i; const char *i;
int num;
if ((i = Args->CheckValue ("-numparticles"))) if ((i = Args->CheckValue ("-numparticles")))
NumParticles = atoi (i); num = atoi (i);
// [BC] Use r_maxparticles now. // [BC] Use r_maxparticles now.
else else
NumParticles = r_maxparticles; num = r_maxparticles;
// This should be good, but eh... // This should be good, but eh...
NumParticles = clamp<WORD>(NumParticles, 100, 65535); NumParticles = (WORD)clamp<int>(num, 100, 65535);
P_DeinitParticles(); P_DeinitParticles();
Particles = new particle_t[NumParticles]; Particles = new particle_t[NumParticles];
@ -206,7 +207,7 @@ void P_FindParticleSubsectors ()
for (WORD i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext) for (WORD i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext)
{ {
// Try to reuse the subsector from the last portal check, if still valid. // 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].x, Particles[i].y); if (Particles[i].subsector == NULL) Particles[i].subsector = R_PointInSubsector(Particles[i].Pos);
int ssnum = int(Particles[i].subsector - subsectors); int ssnum = int(Particles[i].subsector - subsectors);
Particles[i].snext = ParticlesInSubsec[ssnum]; Particles[i].snext = ParticlesInSubsec[ssnum];
ParticlesInSubsec[ssnum] = i; ParticlesInSubsec[ssnum] = i;
@ -279,33 +280,29 @@ void P_ThinkParticles ()
continue; continue;
} }
DVector2 newxy = P_GetOffsetPosition(FIXED2DBL(particle->x), FIXED2DBL(particle->y), FIXED2DBL(particle->vel.x), FIXED2DBL(particle->vel.y)); // Handle crossing a line portal
particle->x = FLOAT2FIXED(newxy.X); DVector2 newxy = P_GetOffsetPosition(particle->Pos.X, particle->Pos.Y, particle->Vel.X, particle->Vel.Y);
particle->y = FLOAT2FIXED(newxy.Y); particle->Pos.X = newxy.X;
//particle->x += particle->vel.x; particle->Pos.Y = newxy.Y;
//particle->y += particle->vel.y; particle->Pos.Z += particle->Vel.Z;
particle->z += particle->vel.z; particle->Vel += particle->Acc;
particle->vel.x += particle->accx; particle->subsector = R_PointInSubsector(particle->Pos);
particle->vel.y += particle->accy; // Handle crossing a sector portal.
particle->vel.z += particle->accz;
particle->subsector = R_PointInSubsector(particle->x, particle->y);
if (!particle->subsector->sector->PortalBlocksMovement(sector_t::ceiling)) if (!particle->subsector->sector->PortalBlocksMovement(sector_t::ceiling))
{ {
AActor *skybox = particle->subsector->sector->SkyBoxes[sector_t::ceiling]; AActor *skybox = particle->subsector->sector->SkyBoxes[sector_t::ceiling];
if (particle->z > FLOAT2FIXED(skybox->specialf1)) if (particle->Pos.Z > skybox->specialf1)
{ {
particle->x += FLOAT2FIXED(skybox->Scale.X); particle->Pos += skybox->Scale;
particle->y += FLOAT2FIXED(skybox->Scale.Y);
particle->subsector = NULL; particle->subsector = NULL;
} }
} }
else if (!particle->subsector->sector->PortalBlocksMovement(sector_t::floor)) else if (!particle->subsector->sector->PortalBlocksMovement(sector_t::floor))
{ {
AActor *skybox = particle->subsector->sector->SkyBoxes[sector_t::floor]; AActor *skybox = particle->subsector->sector->SkyBoxes[sector_t::floor];
if (particle->z < FLOAT2FIXED(skybox->specialf1)) if (particle->Pos.Z < skybox->specialf1)
{ {
particle->x += FLOAT2FIXED(skybox->Scale.X); particle->Pos += skybox->Scale;
particle->y += FLOAT2FIXED(skybox->Scale.Y);
particle->subsector = NULL; particle->subsector = NULL;
} }
} }
@ -320,20 +317,14 @@ void P_SpawnParticle(const DVector3 &pos, const DVector3 &vel, const DVector3 &a
if (particle) if (particle)
{ {
particle->x = FLOAT2FIXED(pos.X); particle->Pos = pos;
particle->y = FLOAT2FIXED(pos.Y); particle->Vel = vel;
particle->z = FLOAT2FIXED(pos.Z); particle->Acc = accel;
particle->vel.x = FLOAT2FIXED(vel.X);
particle->vel.y = FLOAT2FIXED(vel.Y);
particle->vel.z = FLOAT2FIXED(vel.Z);
particle->color = ParticleColor(color); particle->color = ParticleColor(color);
particle->trans = BYTE(startalpha*255); particle->trans = BYTE(startalpha*255);
if (fadestep < 0) particle->fade = FADEFROMTTL(lifetime); if (fadestep < 0) particle->fade = FADEFROMTTL(lifetime);
else particle->fade = int(fadestep * 255); else particle->fade = int(fadestep * 255);
particle->ttl = lifetime; particle->ttl = lifetime;
particle->accx = FLOAT2FIXED(accel.X);
particle->accy = FLOAT2FIXED(accel.Y);
particle->accz = FLOAT2FIXED(accel.Z);
particle->bright = fullbright; particle->bright = fullbright;
particle->size = (WORD)size; particle->size = (WORD)size;
} }
@ -380,15 +371,14 @@ particle_t *JitterParticle (int ttl, double drift)
particle_t *particle = NewParticle (); particle_t *particle = NewParticle ();
if (particle) { if (particle) {
fixed_t *val = &particle->vel.x;
int i; int i;
// Set initial velocities // Set initial velocities
for (i = 3; i; i--, val++) for (i = 3; i; i--)
*val = (int)((FRACUNIT/4096) * (M_Random () - 128) * drift); particle->Vel[i] = ((1./4096) * (M_Random () - 128) * drift);
// Set initial accelerations // Set initial accelerations
for (i = 3; i; i--, val++) for (i = 3; i; i--)
*val = (int)((FRACUNIT/16384) * (M_Random () - 128) * drift); particle->Acc[i] = ((1./16384) * (M_Random () - 128) * drift);
particle->trans = 255; // fully opaque particle->trans = 255; // fully opaque
particle->ttl = ttl; particle->ttl = ttl;
@ -411,15 +401,12 @@ static void MakeFountain (AActor *actor, int color1, int color2)
DAngle an = M_Random() * (360. / 256); DAngle an = M_Random() * (360. / 256);
double out = actor->radius * M_Random() / 256.; double out = actor->radius * M_Random() / 256.;
DVector3 pos = actor->Vec3Angle(out, an, actor->Height + 1); particle->Pos = actor->Vec3Angle(out, an, actor->Height + 1);
particle->x = FLOAT2FIXED(pos.X);
particle->y = FLOAT2FIXED(pos.Y);
particle->z = FLOAT2FIXED(pos.Z);
if (out < actor->radius/8) if (out < actor->radius/8)
particle->vel.z += FRACUNIT*10/3; particle->Vel.Z += 10./3;
else else
particle->vel.z += FRACUNIT*3; particle->Vel.Z += 3;
particle->accz -= FRACUNIT/11; particle->Acc.Z -= 1./11;
if (M_Random() < 30) { if (M_Random() < 30) {
particle->size = 4; particle->size = 4;
particle->color = color2; particle->color = color2;
@ -445,7 +432,7 @@ void P_RunEffect (AActor *actor, int effects)
double backz = actor->Height * ((2. / 3) - actor->Vel.Z / 8); double backz = actor->Height * ((2. / 3) - actor->Vel.Z / 8);
DAngle an = moveangle + 90.; DAngle an = moveangle + 90.;
int speed; double speed;
particle = JitterParticle (3 + (M_Random() & 31)); particle = JitterParticle (3 + (M_Random() & 31));
if (particle) { if (particle) {
@ -454,14 +441,12 @@ void P_RunEffect (AActor *actor, int effects)
backx - actor->Vel.X * pathdist, backx - actor->Vel.X * pathdist,
backy - actor->Vel.Y * pathdist, backy - actor->Vel.Y * pathdist,
backz - actor->Vel.Z * pathdist); backz - actor->Vel.Z * pathdist);
particle->x = FLOAT2FIXED(pos.X); particle->Pos = pos;
particle->y = FLOAT2FIXED(pos.Y); speed = (M_Random () - 128) * (1./200);
particle->z = FLOAT2FIXED(pos.Z); particle->Vel.X += speed * an.Cos();
speed = (M_Random () - 128) * (FRACUNIT/200); particle->Vel.Y += speed * an.Sin();
particle->vel.x += fixed_t(speed * an.Cos()); particle->Vel.Z -= 1./36;
particle->vel.y += fixed_t(speed * an.Sin()); particle->Acc.Z -= 1./20;
particle->vel.z -= FRACUNIT/36;
particle->accz -= FRACUNIT/20;
particle->color = yellow; particle->color = yellow;
particle->size = 2; particle->size = 2;
} }
@ -473,15 +458,13 @@ void P_RunEffect (AActor *actor, int effects)
backx - actor->Vel.X * pathdist, backx - actor->Vel.X * pathdist,
backy - actor->Vel.Y * pathdist, backy - actor->Vel.Y * pathdist,
backz - actor->Vel.Z * pathdist + (M_Random() / 64.)); backz - actor->Vel.Z * pathdist + (M_Random() / 64.));
particle->x = FLOAT2FIXED(pos.X); particle->Pos = pos;
particle->y = FLOAT2FIXED(pos.Y);
particle->z = FLOAT2FIXED(pos.Z);
speed = (M_Random () - 128) * (FRACUNIT/200); speed = (M_Random () - 128) * (1./200);
particle->vel.x += fixed_t(speed * an.Cos()); particle->Vel.X += speed * an.Cos();
particle->vel.y += fixed_t(speed * an.Sin()); particle->Vel.Y += speed * an.Sin();
particle->vel.z += FRACUNIT/80; particle->Vel.Z -= 1. / 80;
particle->accz += FRACUNIT/40; particle->Acc.Z -= 1. / 40;
if (M_Random () & 7) if (M_Random () & 7)
particle->color = grey2; particle->color = grey2;
else else
@ -529,18 +512,16 @@ void P_RunEffect (AActor *actor, int effects)
{ {
DAngle ang = M_Random() * (360 / 256.); DAngle ang = M_Random() * (360 / 256.);
DVector3 pos = actor->Vec3Angle(actor->radius, ang, 0); DVector3 pos = actor->Vec3Angle(actor->radius, ang, 0);
particle->x = FLOAT2FIXED(pos.X); particle->Pos = pos;
particle->y = FLOAT2FIXED(pos.Y);
particle->z = FLOAT2FIXED(pos.Z);
particle->color = *protectColors[M_Random() & 1]; particle->color = *protectColors[M_Random() & 1];
particle->vel.z = FRACUNIT; particle->Vel.Z = 1;
particle->accz = M_Random () << 7; particle->Acc.Z = M_Random () / 512.;
particle->size = 1; particle->size = 1;
if (M_Random () < 128) if (M_Random () < 128)
{ // make particle fall from top of actor { // make particle fall from top of actor
particle->z += FLOAT2FIXED(actor->Height); particle->Pos.Z += actor->Height;
particle->vel.z = -particle->vel.z; particle->Vel.Z = -particle->Vel.Z;
particle->accz = -particle->accz; particle->Acc.Z = -particle->Acc.Z;
} }
} }
} }
@ -570,20 +551,21 @@ void P_DrawSplash (int count, const DVector3 &pos, DAngle angle, int kind)
p->size = 2; p->size = 2;
p->color = M_Random() & 0x80 ? color1 : color2; p->color = M_Random() & 0x80 ? color1 : color2;
p->vel.z -= M_Random () * 512; p->Vel.Z -= M_Random () / 128.;
p->accz -= FRACUNIT/8; p->Acc.Z -= 1./8;
p->accx += (M_Random () - 128) * 8; p->Acc.X += (M_Random () - 128) / 8192.;
p->accy += (M_Random () - 128) * 8; p->Acc.Y += (M_Random () - 128) / 8192.;
p->z = FLOAT2FIXED(pos.Z) - M_Random () * 1024; p->Pos.Z = pos.Z - M_Random () / 64.;
angle += M_Random() * (45./256); angle += M_Random() * (45./256);
p->x = FLOAT2FIXED(pos.X + (M_Random() & 15)*angle.Cos()); p->Pos.X = pos.X + (M_Random() & 15)*angle.Cos();
p->y = FLOAT2FIXED(pos.Y + (M_Random() & 15)*angle.Sin()); p->Pos.Y = pos.Y + (M_Random() & 15)*angle.Sin();
} }
} }
void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, int kind) void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, int kind)
{ {
int color1, color2, zvel, zspread, zadd; int color1, color2, zadd;
double zvel, zspread;
switch (kind) switch (kind)
{ {
@ -605,14 +587,14 @@ void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, in
break; break;
} }
zvel = -128; zvel = -0.5;
zspread = updown ? -6000 : 6000; zspread = updown ? -6000 / 65536. : 6000 / 65536.;
zadd = (updown == 2) ? -128 : 0; zadd = (updown == 2) ? 128 : 0;
for (; count; count--) for (; count; count--)
{ {
particle_t *p = NewParticle (); particle_t *p = NewParticle ();
angle_t an; DAngle an;
if (!p) if (!p)
break; break;
@ -622,19 +604,20 @@ void P_DrawSplash2 (int count, const DVector3 &pos, DAngle angle, int updown, in
p->trans = 255; p->trans = 255;
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;
p->accz = -FRACUNIT/22; p->Acc.Z = -1 / 22.;
if (kind) { if (kind)
an = (angle.BAMs() + ((M_Random() - 128) << 23)) >> ANGLETOFINESHIFT; {
p->vel.x = (M_Random () * finecosine[an]) >> 11; an = angle + ((M_Random() - 128) * (180 / 256.));
p->vel.y = (M_Random () * finesine[an]) >> 11; p->Vel.X = M_Random() * an.Cos() / 2048.;
p->accx = p->vel.x >> 4; p->Vel.Y = M_Random() * an.Sin() / 2048.;
p->accy = p->vel.y >> 4; p->Acc.X = p->Vel.X / 16.;
p->Acc.Y = p->Vel.Y / 16.;
} }
p->z = FLOAT2FIXED(pos.Z) + (M_Random () + zadd - 128) * zspread; an = angle + ((M_Random() - 128) * (90 / 256.));
an = (angle.BAMs() + ((M_Random() - 128) << 22)) >> ANGLETOFINESHIFT; p->Pos.X = pos.X + ((M_Random() & 31) - 15) * an.Cos();
p->x = FLOAT2FIXED(pos.X) + ((M_Random () & 31)-15)*finecosine[an]; p->Pos.Y = pos.Y + ((M_Random() & 31) - 15) * an.Sin();
p->y = FLOAT2FIXED(pos.X) + ((M_Random () & 31)-15)*finesine[an]; p->Pos.Z = pos.Z + (M_Random() + zadd - 128) * zspread;
} }
} }
@ -749,13 +732,8 @@ void P_DrawRailTrail(AActor *source, const DVector3 &start, const DVector3 &end,
p->bright = fullbright; p->bright = fullbright;
tempvec = DMatrix3x3(dir, deg) * extend; tempvec = DMatrix3x3(dir, deg) * extend;
p->vel.x = FLOAT2FIXED(tempvec.X * drift)>>4; p->Vel = tempvec * drift / 16.;
p->vel.y = FLOAT2FIXED(tempvec.Y * drift)>>4; p->Pos = tempvec + pos;
p->vel.z = FLOAT2FIXED(tempvec.Z * drift)>>4;
tempvec += pos;
p->x = FLOAT2FIXED(tempvec.X);
p->y = FLOAT2FIXED(tempvec.Y);
p->z = FLOAT2FIXED(tempvec.Z);
pos += spiral_step; pos += spiral_step;
deg += double(r_rail_spiralsparsity * 14); deg += double(r_rail_spiralsparsity * 14);
@ -812,11 +790,9 @@ void P_DrawRailTrail(AActor *source, const DVector3 &start, const DVector3 &end,
DVector3 postmp = pos + diff; DVector3 postmp = pos + diff;
p->size = 2; p->size = 2;
p->x = FLOAT2FIXED(postmp.X); p->Pos = postmp;
p->y = FLOAT2FIXED(postmp.Y);
p->z = FLOAT2FIXED(postmp.Z);
if (color1 != -1) if (color1 != -1)
p->accz -= FRACUNIT/4096; p->Acc.Z -= 1./4096;
pos += trail_step; pos += trail_step;
p->bright = fullbright; p->bright = fullbright;
@ -888,10 +864,8 @@ void P_DisconnectEffect (AActor *actor)
double zo = M_Random()*actor->Height / 256; double zo = M_Random()*actor->Height / 256;
DVector3 pos = actor->Vec3Offset(xo, yo, zo); DVector3 pos = actor->Vec3Offset(xo, yo, zo);
p->x = FLOAT2FIXED(pos.X); p->Pos = pos;
p->y = FLOAT2FIXED(pos.Y); p->Acc.Z -= 1./4096;
p->z = FLOAT2FIXED(pos.Z);
p->accz -= FRACUNIT/4096;
p->color = M_Random() < 128 ? maroon1 : maroon2; p->color = M_Random() < 128 ? maroon1 : maroon2;
p->size = 4; p->size = 4;
} }

View file

@ -52,21 +52,16 @@
struct subsector_t; struct subsector_t;
// [RH] Particle details // [RH] Particle details
struct fixedvec3
{
fixed_t x, y, z;
};
struct particle_t struct particle_t
{ {
fixed_t x,y,z; DVector3 Pos;
fixedvec3 vel; DVector3 Vel;
fixed_t accx,accy,accz; DVector3 Acc;
BYTE ttl; BYTE ttl;
BYTE trans; BYTE trans;
WORD size; WORD size;
BYTE bright:1; BYTE bright;
BYTE fade; BYTE fade;
int color; int color;
WORD tnext; WORD tnext;

View file

@ -1222,8 +1222,6 @@ void P_LoadSegs (MapData * map)
line_t* line; // phares 10/4/98 line_t* line; // phares 10/4/98
int ptp_angle; // phares 10/4/98 int ptp_angle; // phares 10/4/98
int delta_angle; // phares 10/4/98 int delta_angle; // phares 10/4/98
int dis; // phares 10/4/98
int dx,dy; // phares 10/4/98
int vnum1,vnum2; // phares 10/4/98 int vnum1,vnum2; // phares 10/4/98
int lumplen = map->Size(ML_SEGS); int lumplen = map->Size(ML_SEGS);

View file

@ -2423,12 +2423,12 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
BYTE* map; BYTE* map;
// [ZZ] Particle not visible through the portal plane // [ZZ] Particle not visible through the portal plane
if (CurrentPortal && !!P_PointOnLineSide(particle->x, particle->y, CurrentPortal->dst)) if (CurrentPortal && !!P_PointOnLineSide(particle->Pos, CurrentPortal->dst))
return; return;
// transform the origin point // transform the origin point
tr_x = particle->x - viewx; tr_x = FLOAT2FIXED(particle->Pos.X - ViewPos.X);
tr_y = particle->y - viewy; tr_y = FLOAT2FIXED(particle->Pos.Y - ViewPos.Y);
tz = DMulScale20 (tr_x, viewtancos, tr_y, viewtansin); tz = DMulScale20 (tr_x, viewtancos, tr_y, viewtansin);
@ -2460,8 +2460,8 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
if (x1 >= x2) if (x1 >= x2)
return; return;
yscale = MulScale16 (yaspectmul, xscale); yscale = MulScale16(yaspectmul, xscale);
ty = particle->z - viewz; ty = FLOAT2FIXED(particle->Pos.Z - ViewPos.Z);
psize <<= 4; psize <<= 4;
y1 = (centeryfrac - FixedMul (ty+psize, yscale)) >> FRACBITS; y1 = (centeryfrac - FixedMul (ty+psize, yscale)) >> FRACBITS;
y2 = (centeryfrac - FixedMul (ty-psize, yscale)) >> FRACBITS; y2 = (centeryfrac - FixedMul (ty-psize, yscale)) >> FRACBITS;
@ -2522,9 +2522,9 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
map = sector->ColorMap->Maps; map = sector->ColorMap->Maps;
} }
if (botpic != skyflatnum && particle->z < botplane->ZatPoint (particle->x, particle->y)) if (botpic != skyflatnum && particle->Pos.Z < botplane->ZatPoint (particle->Pos))
return; return;
if (toppic != skyflatnum && particle->z >= topplane->ZatPoint (particle->x, particle->y)) if (toppic != skyflatnum && particle->Pos.Z >= topplane->ZatPoint (particle->Pos))
return; return;
// store information in a vissprite // store information in a vissprite
@ -2536,9 +2536,9 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
vis->yscale = xscale; vis->yscale = xscale;
vis->depth = tz; vis->depth = tz;
vis->idepth = (DWORD)DivScale32 (1, tz) >> 1; vis->idepth = (DWORD)DivScale32 (1, tz) >> 1;
vis->gx = particle->x; vis->gx = FLOAT2FIXED(particle->Pos.X);
vis->gy = particle->y; vis->gy = FLOAT2FIXED(particle->Pos.Y);
vis->gz = particle->z; // kg3D vis->gz = FLOAT2FIXED(particle->Pos.Z);
vis->gzb = y1; vis->gzb = y1;
vis->gzt = y2; vis->gzt = y2;
vis->x1 = x1; vis->x1 = x1;