- floatified calcSlope and cleaned up the get*slope interface

This commit is contained in:
Christoph Oelckers 2022-09-17 21:18:04 +02:00
parent 930a78f7b2
commit ece8663f5e
6 changed files with 108 additions and 81 deletions

View file

@ -138,90 +138,42 @@ bool calcChaseCamPos(DVector3& ppos, DCoreActor* act, sectortype** psect, DAngle
//
//==========================================================================
void calcSlope(const sectortype* sec, float xpos, float ypos, float* pceilz, float* pflorz)
void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz, double* pflorz)
{
int bits = 0;
if (pceilz)
{
bits |= sec->ceilingstat;
*pceilz = float(sec->int_ceilingz());
*pceilz = sec->ceilingz;
}
if (pflorz)
{
bits |= sec->floorstat;
*pflorz = float(sec->int_floorz());
*pflorz = sec->floorz;
}
if ((bits & CSTAT_SECTOR_SLOPE) == CSTAT_SECTOR_SLOPE)
{
auto wal = sec->firstWall();
int len = wal->Length();
double len = wal->Length();
if (len != 0)
{
float fac = (wal->int_delta().X * (float(ypos - wal->wall_int_pos().Y)) - wal->int_delta().Y * (float(xpos - wal->wall_int_pos().X))) * (1.f / 256.f) / len;
float fac = (wal->delta().X * (ypos - wal->pos.Y) - wal->delta().Y * (xpos - wal->pos.X)) / len * (1 / 4096.);
if (pceilz && sec->ceilingstat & CSTAT_SECTOR_SLOPE) *pceilz += (sec->ceilingheinum * fac);
if (pflorz && sec->floorstat & CSTAT_SECTOR_SLOPE) *pflorz += (sec->floorheinum * fac);
}
}
}
//==========================================================================
//
// for the renderer
//
//==========================================================================
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pceilz, float* pflorz)
{
calcSlope(sec, dax * worldtoint, day * worldtoint, pceilz, pflorz);
if (pceilz) *pceilz *= -(1 / 256.f);
if (pflorz) *pflorz *= -(1 / 256.f);
}
//==========================================================================
//
// for the games (these are not inlined so that they can inline calcSlope)
//
//==========================================================================
int getceilzofslopeptr(const sectortype* sec, int dax, int day)
{
float z;
calcSlope(sec, dax, day, &z, nullptr);
return int(z);
}
int getflorzofslopeptr(const sectortype* sec, int dax, int day)
{
float z;
calcSlope(sec, dax, day, nullptr, &z);
return int(z);
}
void getzsofslopeptr(const sectortype* sec, int dax, int day, int* ceilz, int* florz)
{
float c, f;
calcSlope(sec, dax, day, &c, &f);
*ceilz = int(c);
*florz = int(f);
}
void getzsofslopeptr(const sectortype* sec, double dax, double day, double* ceilz, double* florz)
{
float c, f;
calcSlope(sec, dax * worldtoint, day * worldtoint, &c, &f);
*ceilz = c * zinttoworld;
*florz = f * zinttoworld;
}
// only used by clipmove et.al.
void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz)
{
DVector2 closestv;
SquareDistToSector(dax * inttoworld, day * inttoworld, &sector[sectnum], &closestv);
float ffloorz, fceilz;
calcSlope(&sector[sectnum], closestv.X * worldtoint, closestv.Y * worldtoint, &fceilz, &ffloorz);
if (ceilz) *ceilz = int(fceilz);
if (florz) *florz = int(ffloorz);
double ffloorz, fceilz;
calcSlope(&sector[sectnum], closestv.X, closestv.Y, &fceilz, &ffloorz);
if (ceilz) *ceilz = int(fceilz * zworldtoint);
if (florz) *florz = int(ffloorz * zworldtoint);
}
//==========================================================================
@ -235,7 +187,7 @@ int getslopeval(sectortype* sect, int x, int y, int z, int 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, wal->Length(), i);
return i == 0? 0 : Scale((z - basez) << 8, int(wal->Length() * worldtoint), i);
}
//==========================================================================

View file

@ -258,9 +258,6 @@ 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);
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz);
int getslopeval(sectortype* sect, int x, int y, int z, int planez);
@ -285,50 +282,129 @@ bool sectorsConnected(int sect1, int sect2);
void dragpoint(walltype* wal, const DVector2& pos);
int32_t inside(double x, double y, const sectortype* sect);
int insidePoly(double x, double y, const DVector2* points, int count);
void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz);
int getceilzofslopeptr(const sectortype* sec, int dax, int day);
int getflorzofslopeptr(const sectortype* sec, int dax, int day);
void getzsofslopeptr(const sectortype* sec, int dax, int day, int* ceilz, int* florz);
void getzsofslopeptr(const sectortype* sec, double dax, double day, double* ceilz, double* florz);
//==========================================================================
//
// slope stuff (many wrappers, one worker only)
//
//==========================================================================
void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz, double* pflorz);
//==========================================================================
//
// for the renderer
//
//==========================================================================
inline void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pceilz, float* pflorz)
{
double f, c;
calcSlope(sec, dax, day, &c, &f);
if (pceilz) *pceilz = -float(c);
if (pflorz) *pflorz = -float(f);
}
//==========================================================================
//
// old deprecated integer versions
//
//==========================================================================
[[deprecated]]
inline int getceilzofslopeptr(const sectortype* sec, int dax, int day)
{
double z;
calcSlope(sec, dax * inttoworld, day * inttoworld, &z, nullptr);
return int(z * zworldtoint);
}
[[deprecated]]
inline int getflorzofslopeptr(const sectortype* sec, int dax, int day)
{
double z;
calcSlope(sec, dax * inttoworld, day * inttoworld, nullptr, &z);
return int(z * zworldtoint);
}
[[deprecated]]
inline void getzsofslopeptr(const sectortype* sec, int dax, int day, int* ceilz, int* florz)
{
double c, f;
calcSlope(sec, dax * inttoworld, day * inttoworld, &c, &f);
*ceilz = int(c * zworldtoint);
*florz = int(f * zworldtoint);
}
template<class Vector>
[[deprecated]]
inline int getceilzofslopeptr(const sectortype* sec, const Vector& pos)
{
return getceilzofslopeptr(sec, pos.X * worldtoint, pos.Y * worldtoint);
}
template<class Vector>
[[deprecated]]
inline int getflorzofslopeptr(const sectortype* sec, const Vector& pos)
{
return getflorzofslopeptr(sec, pos.X * worldtoint, pos.Y * worldtoint);
}
template<class Vector>
[[deprecated]]
inline void getzsofslopeptr(const sectortype* sec, const Vector& pos, int* ceilz, int* florz)
{
getzsofslopeptr(sec, int(pos.X * worldtoint), int(pos.Y * worldtoint), ceilz, florz);
}
// only used by clipmove et.al.
void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz);
//==========================================================================
//
// floating point interface
//
//==========================================================================
inline void getzsofslopeptr(const sectortype* sec, double dax, double day, double* ceilz, double* florz)
{
calcSlope(sec, dax, day, ceilz, florz);
}
template<class Vector>
inline void getzsofslopeptr(const sectortype* sec, const Vector& pos, double* ceilz, double* florz)
{
getzsofslopeptr(sec, pos.X, pos.Y, ceilz, florz);
calcSlope(sec, pos.X, pos.Y, ceilz, florz);
}
inline double getceilzofslopeptrf(const sectortype* sec, double dax, double day)
{
return getceilzofslopeptr(sec, dax * worldtoint, day * worldtoint) * zinttoworld;
double c;
calcSlope(sec, dax, day, &c, nullptr);
return c;
}
inline double getflorzofslopeptrf(const sectortype* sec, double dax, double day)
{
return getflorzofslopeptr(sec, dax * worldtoint, day * worldtoint) * zinttoworld;
double f;
calcSlope(sec, dax, day, nullptr, &f);
return f;
}
inline double getceilzofslopeptrf(const sectortype* sec, const DVector2& pos)
template<class Vector>
inline double getceilzofslopeptrf(const sectortype* sec, const Vector& pos)
{
return getceilzofslopeptr(sec, pos.X * worldtoint, pos.Y * worldtoint) * zinttoworld;
return getceilzofslopeptrf(sec, pos.X, pos.Y);
}
inline double getflorzofslopeptrf(const sectortype* sec, const DVector2& pos)
template<class Vector>
inline double getflorzofslopeptrf(const sectortype* sec, const Vector& pos)
{
return getflorzofslopeptr(sec, pos.X * worldtoint, pos.Y * worldtoint) * zinttoworld;
return getflorzofslopeptrf(sec, pos.X, pos.Y);
}
//==========================================================================
//
// end of slopes
//
//==========================================================================
inline DVector2 rotatepoint(const DVector2& pivot, const DVector2& point, DAngle angle)
{
return (point - pivot).Rotated(angle) + pivot;

View file

@ -62,8 +62,7 @@ void walltype::calcLength()
{
lengthflags &= ~1;
point2Wall()->lengthflags &= ~2;
auto d = int_delta();
length = (int)sqrt(d.X * d.X + d.Y * d.Y);
length = delta().Length();
}
// needed for skipping over to get the map size first.

View file

@ -403,7 +403,7 @@ struct walltype
// extensions not from the binary map format.
angle_t clipangle;
int length; // cached value to avoid calling sqrt repeatedly.
double length; // cached value to avoid calling sqrt repeatedly.
uint16_t portalnum;
uint8_t portalflags;
@ -427,7 +427,7 @@ struct walltype
DVector2 delta() const { return point2Wall()->pos - pos; }
DVector2 center() const { return(point2Wall()->pos + pos) / 2; }
bool twoSided() const { return nextsector >= 0; }
int Length();
double Length();
void calcLength(); // this is deliberately not inlined and stored in a file where it can't be found at compile time.
void movexy(int newx, int newy);
void move(const DVector2& vec)
@ -640,7 +640,7 @@ inline void walltype::movexy(int newx, int newy)
sectorp()->dirty = EDirty::AllDirty;
}
inline int walltype::Length()
inline double walltype::Length()
{
if ((lengthflags & 1) || (point2Wall()->lengthflags & 2))
{

View file

@ -476,7 +476,7 @@ double wall_length(walltype* wal)
return wal->Length();
}
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, length, wall_point2wall)
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, length, wall_length)
{
PARAM_SELF_STRUCT_PROLOGUE(walltype);
ACTION_RETURN_FLOAT(self->Length());

View file

@ -201,7 +201,7 @@ TArray<DBloodActor*> getSpritesNearWalls(sectortype* pSrcSect, int nDist)
auto qpos = spos - wpos;
double num = qpos.dot(wlen);
double den = wlen.Length();
double den = wal.Length();
if (num > 0 && num < den)
{