- floatified getslopeval and all related code.

This commit is contained in:
Christoph Oelckers 2022-09-24 13:11:17 +02:00
parent ece8663f5e
commit 6a1ff029b7
5 changed files with 19 additions and 27 deletions

View file

@ -625,7 +625,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
int32_t const centery = ((span.Y >> 1) + adjofs.Y) * repeat.Y;
int32_t const rspanx = span.X * repeat.X;
int32_t const rspany = span.Y * repeat.Y;
int32_t const ratio = ksqrt(heinum * heinum + 4096 * 4096);
int32_t const ratio = ksqrt(heinum * heinum + SLOPEVAL_FACTOR * SLOPEVAL_FACTOR);
int32_t zz[3] = { pos->Z, pos->Z + flordist, pos->Z - ceildist };
for (int k = 0; k < 3; k++)
{

View file

@ -158,7 +158,7 @@ void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz,
double len = wal->Length();
if (len != 0)
{
float fac = (wal->delta().X * (ypos - wal->pos.Y) - wal->delta().Y * (xpos - wal->pos.X)) / len * (1 / 4096.);
float fac = (wal->delta().X * (ypos - wal->pos.Y) - wal->delta().Y * (xpos - wal->pos.X)) / len * (1. / SLOPEVAL_FACTOR);
if (pceilz && sec->ceilingstat & CSTAT_SECTOR_SLOPE) *pceilz += (sec->ceilingheinum * fac);
if (pflorz && sec->floorstat & CSTAT_SECTOR_SLOPE) *pflorz += (sec->floorheinum * fac);
}
@ -182,12 +182,12 @@ void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz)
//
//==========================================================================
int getslopeval(sectortype* sect, int x, int y, int z, int basez)
int getslopeval(sectortype* sect, const DVector3& pos, double basez)
{
auto wal = sect->firstWall();
auto delta = wal->int_delta();
int i = (y - wal->wall_int_pos().Y) * delta.X - (x - wal->wall_int_pos().X) * delta.Y;
return i == 0? 0 : Scale((z - basez) << 8, int(wal->Length() * worldtoint), i);
auto delta = wal->delta();
double i = (pos.Y - wal->pos.Y) * delta.X - (pos.X - wal->pos.X) * delta.Y;
return i == 0? 0 : SLOPEVAL_FACTOR * (pos.Z - basez) * wal->Length() / i;
}
//==========================================================================
@ -267,7 +267,7 @@ void TGetFlatSpritePosition(const spritetypebase* spr, const DVector2& pos, DVec
auto tex = tileGetTexture(spr->picnum);
double width, height, leftofs, topofs;
double sloperatio = sqrt(heinum * heinum + 4096 * 4096) * (1. / 4096.);
double sloperatio = sqrt(heinum * heinum + SLOPEVAL_FACTOR * SLOPEVAL_FACTOR) * (1. / SLOPEVAL_FACTOR);
double xrepeat = spr->xrepeat * REPEAT_SCALE;
double yrepeat = spr->yrepeat * REPEAT_SCALE;
@ -316,7 +316,7 @@ void TGetFlatSpritePosition(const spritetypebase* spr, const DVector2& pos, DVec
{
for (int i = 0; i < 4; i++)
{
outz[i] = (sinang * (out[i].Y - pos.Y) + cosang * (out[i].X - pos.X)) * heinum * (1. / 4096);
outz[i] = (sinang * (out[i].Y - pos.Y) + cosang * (out[i].X - pos.X)) * heinum * (1. / SLOPEVAL_FACTOR);
}
}
}

View file

@ -8,6 +8,8 @@
extern IntRect viewport3d;
constexpr int SLOPEVAL_FACTOR = 4096;
// breadth first search, this gets used multiple times throughout the engine, mainly for iterating over sectors.
// Only works on indices, this has no knowledge of the actual objects being looked at.
// All objects of this type operate on the same shared store. Interleaved use is not allowed, nested use is fine.
@ -258,7 +260,7 @@ extern double cameradist, cameraclock;
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);
bool calcChaseCamPos(DVector3& ppos, DCoreActor* pspr, sectortype** psectnum, DAngle ang, fixedhoriz horiz, double const interpfrac);
int getslopeval(sectortype* sect, int x, int y, int z, int planez);
int getslopeval(sectortype* sect, const DVector3& pos, double bazez);
@ -487,7 +489,7 @@ inline double spriteGetZOfSlopef(const spritetypebase* tspr, const DVector2& pos
if (heinum == 0) return tspr->pos.Z;
auto ang = tspr->angle;
double factor = -ang.Sin() * (pos.X - tspr->pos.Y) - ang.Cos() * (pos.X - tspr->pos.X);
return tspr->pos.Z + heinum * factor * (1./4096.);
return tspr->pos.Z + heinum * factor * (1./SLOPEVAL_FACTOR);
}
inline int inside(int x, int y, const sectortype* sect)
@ -582,24 +584,14 @@ inline double SquareDistToLine(double px, double py, double lx1, double ly1, dou
return SquareDist(px, py, xx, yy);
}
inline void alignceilslope(sectortype* sect, int x, int y, int z)
{
sect->setceilingslope(getslopeval(sect, x, y, z, sect->int_ceilingz()));
}
inline void alignflorslope(sectortype* sect, int x, int y, int z)
{
sect->setfloorslope(getslopeval(sect, x, y, z, sect->int_floorz()));
}
inline void alignceilslope(sectortype* sect, const DVector3& pos)
{
sect->setceilingslope(getslopeval(sect, pos.X * worldtoint, pos.Y * worldtoint, pos.Z * zworldtoint, sect->int_ceilingz()));
sect->setceilingslope(getslopeval(sect, pos, sect->ceilingz));
}
inline void alignflorslope(sectortype* sect, const DVector3& pos)
{
sect->setfloorslope(getslopeval(sect, pos.X * worldtoint, pos.Y * worldtoint, pos.Z * zworldtoint, sect->int_floorz()));
sect->setfloorslope(getslopeval(sect, pos, sect->floorz));
}
inline double BobVal(int val)

View file

@ -2612,7 +2612,7 @@ DVector4 actFloorBounceVector(DBloodActor* actor, double oldz, sectortype* pSect
DVector3 p(actor->vel.XY(), oldz);
DAngle angle = pSector->firstWall()->delta().Angle() + DAngle90;
auto t2 = pSector->floorheinum * (1. / 4096.);
auto t2 = pSector->floorheinum * (1. / SLOPEVAL_FACTOR);
auto t3 = DVector2(-1, t2).Length();
auto t4 = DVector3(angle.ToVector() * (t2 / t3), -1 / t3);
auto t8 = actor->vel.dot(t4);
@ -4140,7 +4140,7 @@ static void checkCeilHit(DBloodActor* actor)
if ((actor2->spr.statnum == kStatThing || actor2->spr.statnum == kStatDude) && (actor->vel.X != 0 || actor->vel.Y != 0 || actor->vel.Z != 0))
{
auto adelta = actor2->spr.pos - actor->spr.pos;
actor2->vel.XY() += adelta.XY() * (1. / 4096.);
actor2->vel.XY() += adelta.XY() * (1. / SLOPEVAL_FACTOR);
if (actor2->spr.statnum == kStatThing)
{
@ -4672,7 +4672,7 @@ static Collision MoveThing(DBloodActor* actor)
auto hitActor = coll.actor();
if ((hitActor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FACING)
{
actor->vel.XY() += (actor->spr.pos.XY() - hitActor->spr.pos.XY()) / 4096.;
actor->vel.XY() += (actor->spr.pos.XY() - hitActor->spr.pos.XY()) / SLOPEVAL_FACTOR;
lhit = actor->hit.hit;
}
}
@ -5150,7 +5150,7 @@ void MoveDude(DBloodActor* actor)
auto hitAct = floorColl.actor();
if ((hitAct->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FACING)
{
actor->vel.XY() += (actor->spr.pos - hitAct->spr.pos).XY() * (1. / 4096.);
actor->vel.XY() += (actor->spr.pos - hitAct->spr.pos).XY() * (1. / SLOPEVAL_FACTOR);
return;
}
}

View file

@ -8359,7 +8359,7 @@ bool SlopeBounce(DSWActor* actor, bool* hit_wall)
return false;
// if greater than a 45 degree angle
if (abs(slope) > 4096)
if (abs(slope) > SLOPEVAL_FACTOR)
*hit_wall = true;
else
*hit_wall = false;