From 5bfe62d7b65b1002bcd4206a277601e56c847fa2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 Oct 2022 22:52:05 +0200 Subject: [PATCH] - move the clip object collection loop into its own function. --- source/build/src/clip.cpp | 38 +-------------------------- source/core/gamefuncs.cpp | 55 +++++++++++++++++++++++++++++++++++---- source/core/gamefuncs.h | 7 +---- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 4ae75b40c..deafd76e7 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -113,8 +113,6 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, int const initialsectnum = *sectnum; - int32_t const dasprclipmask = (cliptype >> 16); // CLIPMASK1 = 0x01000040 - vec2_t const move = { xvect, yvect }; vec2_t goal = { pos->X + (xvect >> 14), pos->Y + (yvect >> 14) }; vec2_t const cent = { (pos->X + goal.X) >> 1, (pos->Y + goal.Y) >> 1 }; @@ -139,41 +137,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, clip.center = (clip.pos.XY() + clip.dest) * 0.5; clip.movedist = clip.moveDelta.Length() + clip.walldist + 0.5 + MAXCLIPDIST * inttoworld; - while (auto sect = clip.search.GetNext()) - { - processClipWalls(clip, sect); - - if (dasprclipmask==0) - continue; - - TSectIterator it(sect); - while (auto actor = it.Next()) - { - int cstat = actor->spr.cstat; - - if (actor->spr.cstat2 & CSTAT2_SPRITE_NOFIND) continue; - if ((cstat & dasprclipmask) == 0) - continue; - - switch (cstat & (CSTAT_SPRITE_ALIGNMENT_MASK)) - { - case CSTAT_SPRITE_ALIGNMENT_FACING: - processClipFaceSprite(clip, actor); - break; - - case CSTAT_SPRITE_ALIGNMENT_WALL: - processClipWallSprite(clip, actor); - break; - - case CSTAT_SPRITE_ALIGNMENT_FLOOR: - processClipFloorSprite(clip, actor); - break; - - case CSTAT_SPRITE_ALIGNMENT_SLOPE: - processClipSlopeSprite(clip, actor); - } - } - } + collectClipObjects(clip, (cliptype >> 16)); int32_t hitwalls[4], hitwall; CollisionBase clipReturn{}; diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 233cd22f8..c9940433a 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -1330,7 +1330,7 @@ static void addWallToClipSet(MoveClipper& clip, walltype* wal) // //========================================================================== -void processClipWalls(MoveClipper& clip, sectortype* sec) +static void processClipWalls(MoveClipper& clip, sectortype* sec) { for(auto& wal : sec->walls) { @@ -1353,7 +1353,7 @@ void processClipWalls(MoveClipper& clip, sectortype* sec) // //========================================================================== -void processClipFaceSprite(MoveClipper& clip, DCoreActor* actor) +static void processClipFaceSprite(MoveClipper& clip, DCoreActor* actor) { auto spos = actor->spr.pos; if (!PointInRect(spos.XY(), clip.rect.min, clip.rect.max)) return; // are we outside this sprite's bounding box? @@ -1377,7 +1377,7 @@ void processClipFaceSprite(MoveClipper& clip, DCoreActor* actor) // //========================================================================== -void processClipWallSprite(MoveClipper& clip, DCoreActor* actor) +static void processClipWallSprite(MoveClipper& clip, DCoreActor* actor) { auto spos = actor->spr.pos; double height, z = spos.Z + actor->GetOffsetAndHeight(height); @@ -1424,7 +1424,7 @@ void processClipWallSprite(MoveClipper& clip, DCoreActor* actor) // //========================================================================== -bool processClipFloorSprite(MoveClipper& clip, DCoreActor* actor, DVector2* points, double* heights) +static bool processClipFloorSprite(MoveClipper& clip, DCoreActor* actor, DVector2* points, double* heights) { int heinum = spriteGetSlope(actor); double sprz = spriteGetZOfSlopef(&actor->spr, actor->spr.pos.XY(), heinum); @@ -1479,7 +1479,7 @@ bool processClipFloorSprite(MoveClipper& clip, DCoreActor* actor, DVector2* poin // //========================================================================== -void processClipSlopeSprite(MoveClipper& clip, DCoreActor* actor) +static void processClipSlopeSprite(MoveClipper& clip, DCoreActor* actor) { auto spos = actor->spr.pos; DVector2 points[4]; @@ -1528,6 +1528,51 @@ void processClipSlopeSprite(MoveClipper& clip, DCoreActor* actor) // //========================================================================== +void collectClipObjects(MoveClipper& clip, int spritemask) +{ + while (auto sect = clip.search.GetNext()) + { + processClipWalls(clip, sect); + + if (spritemask == 0) + continue; + + TSectIterator it(sect); + while (auto actor = it.Next()) + { + int cstat = actor->spr.cstat; + + if (actor->spr.cstat2 & CSTAT2_SPRITE_NOFIND) continue; + if ((cstat & spritemask) == 0) + continue; + + switch (cstat & (CSTAT_SPRITE_ALIGNMENT_MASK)) + { + case CSTAT_SPRITE_ALIGNMENT_FACING: + processClipFaceSprite(clip, actor); + break; + + case CSTAT_SPRITE_ALIGNMENT_WALL: + processClipWallSprite(clip, actor); + break; + + case CSTAT_SPRITE_ALIGNMENT_FLOOR: + processClipFloorSprite(clip, actor, nullptr, nullptr); + break; + + case CSTAT_SPRITE_ALIGNMENT_SLOPE: + processClipSlopeSprite(clip, actor); + } + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + int FindBestSector(const DVector3& pos) { int bestnum = -1; diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index c8aa4b6e8..adeee895a 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -275,15 +275,10 @@ struct MoveClipper MoveClipper(sectortype* start) : search(start) {} }; -void processClipWalls(MoveClipper& clip, sectortype* sec); +void collectClipObjects(MoveClipper& clip, int spritemask); -void processClipFaceSprite(MoveClipper& clip, DCoreActor* actor); -void processClipWallSprite(MoveClipper& clip, DCoreActor* actor); -bool processClipFloorSprite(MoveClipper& clip, DCoreActor* actor, DVector2* points = nullptr, double* heights = nullptr); -void processClipSlopeSprite(MoveClipper& clip, DCoreActor* actor); int FindBestSector(const DVector3& pos); - void setWallSectors(); void GetWallSpritePosition(const spritetypebase* spr, const DVector2& pos, DVector2* out, bool render = false); void GetFlatSpritePosition(DCoreActor* spr, const DVector2& pos, DVector2* out, double* outz = nullptr, bool render = false);