From ec7fce9ff2a9545d1ced75070c08a0fa0c635158 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 27 Aug 2019 06:52:42 +0000 Subject: [PATCH] Ultra minor clipping stuff git-svn-id: https://svn.eduke32.com/eduke32@8048 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/build.h | 6 ++-- source/build/src/clip.cpp | 55 ++++++++++++++++++------------------ source/build/src/engine.cpp | 8 +++--- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 2f16d32c1..99faf95f0 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -525,8 +525,8 @@ static inline void inplace_vx_tweak_wall(walltypevx *vxwal, int32_t yaxp) #include "clip.h" -int32_t getwalldist(vec2_t const &in, int const wallnum); -int32_t getwalldist(vec2_t const &in, int const wallnum, vec2_t * const out); +int32_t getwalldist(vec2_t const in, int const wallnum); +int32_t getwalldist(vec2_t const in, int const wallnum, vec2_t * const out); #ifdef __cplusplus extern "C" { @@ -1190,7 +1190,7 @@ void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, in int findwallbetweensectors(int sect1, int sect2); static FORCE_INLINE bool sectoradjacent(int sect1, int sect2) { return findwallbetweensectors(sect1, sect2) != -1; } -int32_t getsectordist(vec2_t const &in, int const sectnum, vec2_t * const out = nullptr); +int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out = nullptr); extern const int16_t *chsecptr_onextwall; int32_t checksectorpointer(int16_t i, int16_t sectnum); diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 7cc28da67..6c03bb8ce 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -786,10 +786,13 @@ static FORCE_INLINE void clipmove_tweak_pos(const vec3_t *pos, int32_t gx, int32 } // Returns: should clip? -static bool cliptestsector(int const dasect, int const nextsect, int32_t const flordist, int32_t const ceildist, vec2_t const &pos, int32_t const posz) +static int cliptestsector(int const dasect, int const nextsect, int32_t const flordist, int32_t const ceildist, vec2_t const pos, int32_t const posz) { + Bassert((unsigned)dasect < numsectors && (unsigned)nextsect < numsectors); + auto const sec2 = (usectorptr_t)§or[nextsect]; - int32_t daz2 = sec2->floorz; + + int32_t daz2 = sec2->floorz; int32_t dacz2 = sec2->ceilingz; if ((sec2->floorstat|sec2->ceilingstat) & 2) @@ -799,7 +802,8 @@ static bool cliptestsector(int const dasect, int const nextsect, int32_t const f return 1; auto const sec = (usectorptr_t)§or[dasect]; - int32_t daz = sec->floorz; + + int32_t daz = sec->floorz; int32_t dacz = sec->ceilingz; if ((sec->floorstat|sec->ceilingstat) & 2) @@ -838,7 +842,7 @@ int32_t clipmovex(vec3_t *pos, int16_t *sectnum, // // raytrace (internal) // -static inline int32_t cliptrace(vec2_t const &pos, vec2_t * const goal) +static inline int32_t cliptrace(vec2_t const pos, vec2_t * const goal) { int32_t hitwall = -1; @@ -913,36 +917,35 @@ static inline void keepaway(int32_t *x, int32_t *y, int32_t w) while (1); } -static int32_t get_floorspr_clipyou(int32_t x1, int32_t x2, int32_t x3, int32_t x4, - int32_t y1, int32_t y2, int32_t y3, int32_t y4) +static int get_floorspr_clipyou(vec2_t const v1, vec2_t const v2, vec2_t const v3, vec2_t const v4) { - int32_t clipyou = 0; + int clipyou = 0; - if ((y1^y2) < 0) + if ((v1.y^v2.y) < 0) { - if ((x1^x2) < 0) clipyou ^= (x1*y2 < x2*y1)^(y1= 0) clipyou ^= 1; + if ((v1.x^v2.x) < 0) clipyou ^= (v1.x*v2.y < v2.x*v1.y)^(v1.y= 0) clipyou ^= 1; } - if ((y2^y3) < 0) + if ((v2.y^v3.y) < 0) { - if ((x2^x3) < 0) clipyou ^= (x2*y3 < x3*y2)^(y2= 0) clipyou ^= 1; + if ((v2.x^v3.x) < 0) clipyou ^= (v2.x*v3.y < v3.x*v2.y)^(v2.y= 0) clipyou ^= 1; } - if ((y3^y4) < 0) + if ((v3.y^v4.y) < 0) { - if ((x3^x4) < 0) clipyou ^= (x3*y4 < x4*y3)^(y3= 0) clipyou ^= 1; + if ((v3.x^v4.x) < 0) clipyou ^= (v3.x*v4.y < v4.x*v3.y)^(v3.y= 0) clipyou ^= 1; } - if ((y4^y1) < 0) + if ((v4.y^v1.y) < 0) { - if ((x4^x1) < 0) clipyou ^= (x4*y1 < x1*y4)^(y4= 0) clipyou ^= 1; + if ((v4.x^v1.x) < 0) clipyou ^= (v4.x*v1.y < v1.x*v4.y)^(v4.y= 0) clipyou ^= 1; } return clipyou; } -static void clipupdatesector(vec2_t const &pos, int16_t * const sectnum, int const walldist) +static void clipupdatesector(vec2_t const pos, int16_t * const sectnum, int const walldist) { if (inside_p(pos.x, pos.y, *sectnum)) return; @@ -1839,7 +1842,7 @@ restart_grand: v1.x += da.x; v2.x -= da.y; v3.x -= da.x; v4.x += da.y; v1.y += da.y; v2.y += da.x; v3.y -= da.y; v4.y -= da.x; - clipyou = get_floorspr_clipyou(v1.x, v2.x, v3.x, v4.x, v1.y, v2.y, v3.y, v4.y); + clipyou = get_floorspr_clipyou(v1, v2, v3, v4); break; } } @@ -2350,10 +2353,10 @@ restart_grand: case CSTAT_SPRITE_ALIGNMENT_FLOOR: { int32_t x3, y3, x4, y4, zz; - - if (vz == 0) continue; intz = z1; - if (((intz-sv->z)^vz) < 0) continue; + + if (vz == 0 || ((intz-sv->z)^vz) < 0) continue; + if ((cstat&64) != 0) if ((sv->z > intz) == ((cstat&8)==0)) continue; #if 1 @@ -2375,10 +2378,8 @@ restart_grand: get_floorspr_points((uspriteptr_t)spr, intx, inty, &x1, &x2, &x3, &x4, &y1, &y2, &y3, &y4); - if (get_floorspr_clipyou(x1, x2, x3, x4, y1, y2, y3, y4)) - { + if (get_floorspr_clipyou({x1, y1}, {x2, y2}, {x3, y3}, {x4, y4})) hit_set(hit, dasector, -1, z, intx, inty, intz); - } break; } diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index bdd46fc65..5e5ac99a6 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -208,7 +208,7 @@ int32_t(*getpalookup_replace)(int32_t davis, int32_t dashade) = NULL; int32_t bloodhack = 0; // adapted from build.c -static void getclosestpointonwall_internal(vec2_t const &p, int32_t const dawall, vec2_t *const closest) +static void getclosestpointonwall_internal(vec2_t const p, int32_t const dawall, vec2_t *const closest) { vec2_t const w = wall[dawall].pos; vec2_t const w2 = wall[wall[dawall].point2].pos; @@ -11412,21 +11412,21 @@ static inline bool inside_z_p(int32_t const x, int32_t const y, int32_t const z, return (z >= cz && z <= fz && inside_p(x, y, sectnum)); } -int32_t getwalldist(vec2_t const &in, int const wallnum) +int32_t getwalldist(vec2_t const in, int const wallnum) { vec2_t closest; getclosestpointonwall_internal(in, wallnum, &closest); return klabs(closest.x - in.x) + klabs(closest.y - in.y); } -int32_t getwalldist(vec2_t const &in, int const wallnum, vec2_t * const out) +int32_t getwalldist(vec2_t const in, int const wallnum, vec2_t * const out) { getclosestpointonwall_internal(in, wallnum, out); return klabs(out->x - in.x) + klabs(out->y - in.y); } -int32_t getsectordist(vec2_t const &in, int const sectnum, vec2_t * const out /*= nullptr*/) +int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*= nullptr*/) { if (inside_p(in.x, in.y, sectnum)) {