From 2ba68df27fb2c066feba9965044b5a0ba90b03f9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 27 Sep 2022 21:21:20 +0200 Subject: [PATCH] - eliminate int_floorz / int_ceilingz in the backend. --- source/build/include/clip.h | 2 +- source/build/src/clip.cpp | 27 +++++++++++++++------------ source/core/gamefuncs.cpp | 6 +++--- source/core/gamefuncs.h | 2 +- source/core/maptypes.h | 4 ---- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/source/build/include/clip.h b/source/build/include/clip.h index c5271ce25..2fffa3c9f 100644 --- a/source/build/include/clip.h +++ b/source/build/include/clip.h @@ -13,7 +13,7 @@ #define MAXCLIPSECTORS 512 #define MAXCLIPNUM 2048 -#define CLIPCURBHEIGHT (1<<8) +#define CLIPCURBHEIGHT (1) typedef struct { int32_t x1, y1, x2, y2; diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index f66dd862e..4fe02ce3e 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -144,8 +144,8 @@ static int cliptestsector(int const dasect, int const nextsect, int32_t const fl } } - int32_t daz2 = sec2->int_floorz(); - int32_t dacz2 = sec2->int_ceilingz(); + double daz2 = sec2->floorz; + double dacz2 = sec2->ceilingz; if ((sec2->floorstat|sec2->ceilingstat) & CSTAT_SECTOR_SLOPE) getcorrectzsofslope(nextsect, pos.X, pos.Y, &dacz2, &daz2); @@ -155,23 +155,26 @@ static int cliptestsector(int const dasect, int const nextsect, int32_t const fl auto const sec = §or[dasect]; - int32_t daz = sec->int_floorz(); - int32_t dacz = sec->int_ceilingz(); + double daz = sec->floorz; + double dacz = sec->ceilingz; if ((sec->floorstat|sec->ceilingstat) & CSTAT_SECTOR_SLOPE) getcorrectzsofslope(dasect, pos.X, pos.Y, &dacz, &daz); - int32_t const sec2height = abs(daz2-dacz2); + double const sec2height = abs(daz2-dacz2); + double fposz = posz * zinttoworld; + double fceildist = ceildist * zinttoworld; + double fflordist = flordist * zinttoworld; return ((abs(daz-dacz) > sec2height && // clip if the current sector is taller and the next is too small - sec2height < (ceildist+(CLIPCURBHEIGHT<<1))) || + sec2height < (fceildist + (CLIPCURBHEIGHT * 2))) || ((sec2->floorstat & CSTAT_SECTOR_SKY) == 0 && // parallaxed floor curbs don't clip - posz >= daz2-(flordist-1) && // also account for desired z distance tolerance + fposz >= daz2-(fflordist-1) && // also account for desired z distance tolerance daz2 < daz-CLIPCURBHEIGHT) || // curbs less tall than 256 z units don't clip ((sec2->ceilingstat & CSTAT_SECTOR_SKY) == 0 && - posz <= dacz2+(ceildist-1) && + fposz <= dacz2+(fceildist-1) && dacz2 > dacz+CLIPCURBHEIGHT)); // ceilings check the same conditions ^^^^^ } @@ -756,7 +759,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, if (enginecompatibility_mode != ENGINECOMPATIBILITY_19950829 && (sect->ceilingstat & CSTAT_SECTOR_SLOPE)) tempint2 = int_getceilzofslopeptr(sect, pos->X, pos->Y) - pos->Z; else - tempint2 = sect->int_ceilingz() - pos->Z; + tempint2 = int(sect->ceilingz * zworldtoint) - pos->Z; if (tempint2 > 0) { @@ -771,7 +774,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, if (enginecompatibility_mode != ENGINECOMPATIBILITY_19950829 && (sect->ceilingstat & CSTAT_SECTOR_SLOPE)) tempint2 = pos->Z - int_getflorzofslopeptr(sect, pos->X, pos->Y); else - tempint2 = pos->Z - sect->int_floorz(); + tempint2 = pos->Z - int(sect->floorz * zworldtoint); if (tempint2 <= 0) { @@ -953,8 +956,8 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas if (wal.cstat & EWallFlags::FromInt(dawalclipmask)) continue; // XXX? - if (((nextsect->ceilingstat & CSTAT_SECTOR_SKY) == 0) && (pos.Z <= nextsect->int_ceilingz()+(3<<8))) continue; - if (((nextsect->floorstat & CSTAT_SECTOR_SKY) == 0) && (pos.Z >= nextsect->int_floorz()-(3<<8))) continue; + if (((nextsect->ceilingstat & CSTAT_SECTOR_SKY) == 0) && (pos.Z <= int(nextsect->ceilingz * zworldtoint)+(3<<8))) continue; + if (((nextsect->floorstat & CSTAT_SECTOR_SKY) == 0) && (pos.Z >= int(nextsect->floorz * zworldtoint)-(3<<8))) continue; int nextsectno = ::sectnum(nextsect); if (!clipsectormap[nextsectno]) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 1030093b7..8045d562d 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -148,14 +148,14 @@ void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz, } // only used by clipmove et.al. -void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz) +void getcorrectzsofslope(int sectnum, int dax, int day, double* ceilz, double* florz) { DVector2 closestv; SquareDistToSector(dax * inttoworld, day * inttoworld, §or[sectnum], &closestv); double ffloorz, fceilz; calcSlope(§or[sectnum], closestv.X, closestv.Y, &fceilz, &ffloorz); - if (ceilz) *ceilz = int(fceilz * zworldtoint); - if (florz) *florz = int(ffloorz * zworldtoint); + if (ceilz) *ceilz = fceilz; + if (florz) *florz = ffloorz; } //========================================================================== diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 5ba0b1e5e..a450d4024 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -335,7 +335,7 @@ inline void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pc // only used by clipmove et.al. -void getcorrectzsofslope(int sectnum, int dax, int day, int* ceilz, int* florz); +void getcorrectzsofslope(int sectnum, int dax, int day, double* ceilz, double* florz); //========================================================================== // diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 77b7444b3..4ce0ebba4 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -249,10 +249,6 @@ struct sectortype #endif - int int_ceilingz() const { return ceilingz * zworldtoint; } - int int_floorz() const { return floorz * zworldtoint; } - - // panning byte fields were promoted to full floats to enable panning interpolation. float ceilingxpan_; float ceilingypan_;