From b9d0c9d6baa5b12f0bf99bf6a094d57612fb3429 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 17 Aug 2022 21:56:14 +0200 Subject: [PATCH] - simplified slope sprite code a bit and got rid of clipinsidebox overload. --- source/build/include/clip.h | 7 +---- source/build/src/clip.cpp | 38 +++++------------------- source/core/gamefuncs.h | 3 +- source/core/rendering/scene/hw_flats.cpp | 4 +-- source/games/duke/src/actors.cpp | 4 +-- source/games/exhumed/src/move.cpp | 2 +- 6 files changed, 15 insertions(+), 43 deletions(-) diff --git a/source/build/include/clip.h b/source/build/include/clip.h index 4c76995f9..092df4dde 100644 --- a/source/build/include/clip.h +++ b/source/build/include/clip.h @@ -21,12 +21,7 @@ typedef struct extern int clipsectorlist[MAXCLIPSECTORS]; -int clipinsidebox(vec2_t *vect, int wallnum, int walldist); -inline int clipinsidebox(int x, int y, int wall, int dist) -{ - vec2_t v = { x, y }; - return clipinsidebox(&v, wall, dist); -} +int clipinsidebox(const vec2_t &vect, int wallnum, int walldist); int clipinsideboxline(int x, int y, int x1, int y1, int x2, int y2, int walldist); struct CollisionBase; diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 529b39b24..d510b1b80 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -62,15 +62,15 @@ static inline void get_floorspr_points(DCoreActor *spr, int32_t px, int32_t py, // // clipinsidebox // -int clipinsidebox(vec2_t *vect, int wallnum, int walldist) +int clipinsidebox(const vec2_t &vect, int wallnum, int walldist) { int const r = walldist << 1; auto const wal1 = &wall[wallnum]; auto const wal2 = wal1->point2Wall(); - vec2_t const v1 = { wal1->wall_int_pos().X + walldist - vect->X, wal1->wall_int_pos().Y + walldist - vect->Y }; - vec2_t v2 = { wal2->wall_int_pos().X + walldist - vect->X, wal2->wall_int_pos().Y + walldist - vect->Y }; + vec2_t const v1 = { wal1->wall_int_pos().X + walldist - vect.X, wal1->wall_int_pos().Y + walldist - vect.Y }; + vec2_t v2 = { wal2->wall_int_pos().X + walldist - vect.X, wal2->wall_int_pos().Y + walldist - vect.Y }; if (((v1.X < 0) && (v2.X < 0)) || ((v1.Y < 0) && (v2.Y < 0)) || ((v1.X >= r) && (v2.X >= r)) || ((v1.Y >= r) && (v2.Y >= r))) return 0; @@ -89,17 +89,6 @@ int clipinsidebox(vec2_t *vect, int wallnum, int walldist) return (v2.X >= v2.Y) << 1; } -static int32_t spriteGetZOfSlope(DCoreActor* actor, int32_t dax, int32_t day) -{ - int16_t const heinum = spriteGetSlope(actor); - if (heinum == 0) - return actor->int_pos().Z; - - int const j = DMulScale(bsin(actor->int_ang() + 1024), day - actor->int_pos().Y, -bsin(actor->int_ang() + 512), dax - actor->int_pos().X, 4); - return actor->int_pos().Z + MulScale(heinum, j, 18); -} - - // // clipinsideboxline // @@ -621,18 +610,8 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, case CSTAT_SPRITE_ALIGNMENT_FLOOR: case CSTAT_SPRITE_ALIGNMENT_SLOPE: { - int heinum, sz; - - if ((cstat & (CSTAT_SPRITE_ALIGNMENT_MASK)) == CSTAT_SPRITE_ALIGNMENT_SLOPE) - { - heinum = spriteGetSlope(actor); - sz = spriteGetZOfSlope(actor, pos->X, pos->Y); - } - else - { - heinum = 0; - sz = actor->int_pos().Z; - } + int heinum = spriteGetSlope(actor); + int sz = spriteGetZOfSlope(&actor->spr, pos->X, pos->Y, heinum); if (pos->Z > sz - flordist && pos->Z < sz + ceildist) { @@ -917,7 +896,7 @@ int pushmove_(vec3_t *const vect, int *const sectnum, int i; for (i=startwall, wal=&wall[startwall]; i!=endwall; i+=dir, wal+=dir) - if (clipinsidebox(&vect->vec2, i, walldist-4) == 1) + if (clipinsidebox(vect->vec2, i, walldist-4) == 1) { int j = 0; if (wal->nextsector < 0 || wal->cstat & EWallFlags::FromInt(dawalclipmask)) j = 1; @@ -939,7 +918,7 @@ int pushmove_(vec3_t *const vect, int *const sectnum, { vect->X = (vect->X) + dx; vect->Y = (vect->Y) + dy; bad2--; if (bad2 == 0) break; - } while (clipinsidebox(&vect->vec2, i, walldist-4) != 0); + } while (clipinsidebox(vect->vec2, i, walldist-4) != 0); bad = -1; k--; if (k <= 0) return bad; clipupdatesector(vect->vec2, sectnum, walldist); @@ -1123,8 +1102,7 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas case CSTAT_SPRITE_ALIGNMENT_FLOOR: case CSTAT_SPRITE_ALIGNMENT_SLOPE: { - if ((cstat & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FLOOR) daz = actor->int_pos().Z; - else daz = spriteGetZOfSlope(actor, pos.X, pos.Y); + daz = spriteGetZOfSlope(&actor->spr, pos.X, pos.Y, spriteGetSlope(actor)); daz2 = daz; if ((cstat & CSTAT_SPRITE_ONE_SIDE) != 0 && (pos.Z > daz) == ((cstat & CSTAT_SPRITE_YFLIP)==0)) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index e92be6213..88483afbd 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -434,9 +434,8 @@ inline int tspriteGetSlope(const tspritetype* spr) return !(spr->clipdist & TSPR_SLOPESPRITE) ? 0 : uint8_t(spr->xoffset) + (int8_t(spr->yoffset) << 8); } -inline int32_t tspriteGetZOfSlope(const tspritetype* tspr, int dax, int day) +inline int32_t spriteGetZOfSlope(const spritetypebase* tspr, int dax, int day, int heinum) { - int heinum = tspriteGetSlope(tspr); if (heinum == 0) return tspr->int_pos().Z; int const j = DMulScale(bsin(tspr->int_ang() + 1024), day - tspr->int_pos().Y, -bsin(tspr->int_ang() + 512), dax - tspr->int_pos().X, 4); diff --git a/source/core/rendering/scene/hw_flats.cpp b/source/core/rendering/scene/hw_flats.cpp index ca3978e07..19f0c8cf5 100644 --- a/source/core/rendering/scene/hw_flats.cpp +++ b/source/core/rendering/scene/hw_flats.cpp @@ -139,7 +139,7 @@ void HWFlat::MakeVertices(HWDrawInfo* di) // Make adjustments for poorly aligned slope sprites on floors or ceilings constexpr float ONPLANE_THRESHOLD = 3.f; - if (tspriteGetZOfSlope(Sprite, posx, posy) < posz) + if (spriteGetZOfSlope(Sprite, posx, posy, tspriteGetSlope(Sprite)) < posz) { float maxofs = -FLT_MAX, minofs = FLT_MAX; for (int i = 0; i < 4; i++) @@ -436,7 +436,7 @@ void HWFlat::ProcessFlatSprite(HWDrawInfo* di, tspritetype* sprite, sectortype* if ((sprite->cstat & CSTAT_SPRITE_ONE_SIDE) != 0) { double myz = !(sprite->clipdist & TSPR_SLOPESPRITE) ? z : - tspriteGetZOfSlope(sprite, int(di->Viewpoint.Pos.X * 16), int(di->Viewpoint.Pos.Y * -16)) * -(1. / 256.); + spriteGetZOfSlope(sprite, int(di->Viewpoint.Pos.X * 16), int(di->Viewpoint.Pos.Y * -16), tspriteGetSlope(sprite)) * -(1. / 256.); if ((di->Viewpoint.Pos.Z < myz) == ((sprite->cstat & CSTAT_SPRITE_YFLIP) == 0)) return; } diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index c94c5f532..6134a0a34 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -3537,7 +3537,7 @@ void handle_se11(DDukeActor *actor) DukeStatIterator it(STAT_ACTOR); while (auto ac = it.Next()) { - if (ac->spr.extra > 0 && badguy(ac) && clipinsidebox(ac->int_pos().X, ac->int_pos().Y, wallnum(&wal), 256) == 1) + if (ac->spr.extra > 0 && badguy(ac) && clipinsidebox(ac->int_pos().vec2, wallnum(&wal), 256) == 1) return; } } @@ -3553,7 +3553,7 @@ void handle_se11(DDukeActor *actor) DukeStatIterator it(STAT_PLAYER); while (auto ac = it.Next()) { - if (ac->GetOwner() && clipinsidebox(ac->int_pos().X, ac->int_pos().Y, wallnum(&wal), 144) == 1) + if (ac->GetOwner() && clipinsidebox(ac->int_pos().vec2, wallnum(&wal), 144) == 1) { actor->temp_data[5] = 8; // Delay actor->temp_data[2] -= k; diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index 229fb591e..a0446752b 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -264,7 +264,7 @@ int BelowNear(DExhumedActor* pActor, int x, int y, int walldist) if (!search.Check(wal.nextSector())) { vec2_t pos = { x, y }; - if (clipinsidebox(&pos, wallnum(&wal), walldist)) + if (clipinsidebox(pos, wallnum(&wal), walldist)) { search.Add(wal.nextSector()); }