From c87b4a581bb71dc551e259cef9a6772a0f847e7f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Sep 2022 19:37:22 +0200 Subject: [PATCH] - got rid of the WallStart/End macros They never got much use and the places where they were used work just as well without them --- source/core/gamefuncs.h | 57 +------------------ .../core/rendering/scene/hw_bunchdrawer.cpp | 16 +++--- source/core/rendering/scene/hw_portal.cpp | 23 ++++---- source/core/rendering/scene/hw_walls.cpp | 4 +- source/core/sectorgeometry.cpp | 4 +- 5 files changed, 26 insertions(+), 78 deletions(-) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 9a6482472..b701dc4dd 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -354,61 +354,6 @@ sectortype* nextsectorneighborzptr(sectortype* sectp, double startz, int flags); bool isAwayFromWall(DCoreActor* ac, double delta); -inline double WallStartX(int wallnum) -{ - return wall[wallnum].pos.X; -} - -inline double WallStartY(int wallnum) -{ - return -wall[wallnum].pos.Y; -} - -inline double WallEndX(int wallnum) -{ - return wall[wallnum].point2Wall()->pos.X; -} - -inline double WallEndY(int wallnum) -{ - return -wall[wallnum].point2Wall()->pos.Y; -} - -inline double WallStartX(const walltype* wallnum) -{ - return wallnum->pos.X; -} - -inline double WallStartY(const walltype* wallnum) -{ - return -wallnum->pos.Y; -} - -inline DVector2 WallStart(const walltype* wallnum) -{ - return { WallStartX(wallnum), WallStartY(wallnum) }; -} - -inline double WallEndX(const walltype* wallnum) -{ - return wallnum->point2Wall()->pos.X; -} - -inline double WallEndY(const walltype* wallnum) -{ - return -wallnum->point2Wall()->pos.Y; -} - -inline DVector2 WallEnd(const walltype* wallnum) -{ - return { WallEndX(wallnum), WallEndY(wallnum) }; -} - -inline DVector2 WallDelta(const walltype* wallnum) -{ - return WallEnd(wallnum) - WallStart(wallnum); -} - inline double PointOnLineSide(double x, double y, double linex, double liney, double deltax, double deltay) { return (x - linex) * deltay - (y - liney) * deltax; @@ -416,7 +361,7 @@ inline double PointOnLineSide(double x, double y, double linex, double liney, do inline double PointOnLineSide(const DVector2 &pos, const walltype *line) { - return (pos.X - WallStartX(line)) * WallDelta(line).Y - (pos.Y - WallStartY(line)) * WallDelta(line).X; + return (pos.X - line->pos.X) * line->delta().Y - (pos.Y - line->pos.Y) * line->delta().X; } template diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index c1e563c19..23ae5ef9c 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -383,14 +383,14 @@ int BunchDrawer::WallInFront(int line1, int line2) int wall2s = sectionLines[line2].startpoint; int wall2e = sectionLines[line2].endpoint; - double x1s = WallStartX(wall1s); - double y1s = WallStartY(wall1s); - double x1e = WallStartX(wall1e); - double y1e = WallStartY(wall1e); - double x2s = WallStartX(wall2s); - double y2s = WallStartY(wall2s); - double x2e = WallStartX(wall2e); - double y2e = WallStartY(wall2e); + double x1s = wall[wall1s].pos.X; + double y1s = -wall[wall1s].pos.Y; + double x1e = wall[wall1e].pos.X; + double y1e = -wall[wall1e].pos.Y; + double x2s = wall[wall2s].pos.X; + double y2s = -wall[wall2s].pos.Y; + double x2e = wall[wall2e].pos.X; + double y2e = -wall[wall2e].pos.Y; retry: double dx1 = x1e - x1s; diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index 68b78d5e0..b4483d664 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -428,15 +428,14 @@ void HWScenePortalBase::ClearClipper(HWDrawInfo *di, Clipper *clipper) inline int P_GetLineSide(const DVector2& pos, const walltype* line) { - auto delta = WallDelta(line); - double v = (pos.Y - WallStartY(line) * delta.X + WallStartX(line) - pos.X) * delta.Y; + auto v = PointOnLineSide(pos, line); return v < -1. / 65536. ? -1 : v > 1. / 65536 ? 1 : 0; } bool P_ClipLineToPortal(walltype* line, walltype* portal, DVector2 view) { - int behind1 = P_GetLineSide(WallStart(line), portal); - int behind2 = P_GetLineSide(WallEnd(line), portal); + int behind1 = P_GetLineSide(line->pos, portal); + int behind2 = P_GetLineSide(line->point2Wall()->pos, portal); if (behind1 == 0 && behind2 == 0) { @@ -461,8 +460,8 @@ bool P_ClipLineToPortal(walltype* line, walltype* portal, DVector2 view) { // The line intersects with the portal straight, so we need to do another check to see how both ends of the portal lie in relation to the viewer. int viewside = P_GetLineSide(view, line); - int p1side = P_GetLineSide(WallStart(portal), line); - int p2side = P_GetLineSide(WallEnd(portal), line); + int p1side = P_GetLineSide(portal->pos, line); + int p2side = P_GetLineSide(portal->point2Wall()->pos, line); // Do the same handling of points on the portal straight as above. if (p1side == 0) p1side = p2side; else if (p2side == 0) p2side = p1side; @@ -481,7 +480,7 @@ int HWLinePortal::ClipSector(sectortype *sub) // this seg is completely behind the mirror for (int i = 0; iwallnum; i++) { - if (PointOnLineSide(WallStart(sub->firstWall()), line) == 0) return PClip_Inside; + if (PointOnLineSide(sub->firstWall()->pos, line) == 0) return PClip_Inside; } return PClip_InFront; } @@ -603,8 +602,11 @@ bool HWLineToLinePortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *cl auto &vp = di->Viewpoint; di->mClipPortal = this; - auto srccenter = (WallStart(origin) + WallEnd(origin)) / 2; - auto destcenter = (WallStart(line) + WallEnd(line)) / 2; + auto srccenter = origin->center(); + srccenter.Y = -srccenter.Y; + auto destcenter = line->center(); + destcenter.Y = -destcenter.Y; + DVector2 npos = vp.Pos - srccenter + destcenter; #if 0 // Blood does not rotate these. Needs map checking to make sure it can be added. @@ -669,7 +671,8 @@ bool HWLineToSpritePortal::Setup(HWDrawInfo* di, FRenderState& rstate, Clipper* auto& vp = di->Viewpoint; di->mClipPortal = this; - auto srccenter = (WallStart(origin) + WallEnd(origin)) / 2; + auto srccenter = origin->center(); + srccenter.Y = -srccenter.Y; DVector2 destcenter = { camera->spr.pos.X, -camera->spr.pos.Y }; DVector2 npos = vp.Pos - srccenter + destcenter; diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index 8ad0e7844..d70dd02d7 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -914,8 +914,8 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec float fch2; float ffh2; - FVector2 v1(WallStartX(wal), WallStartY(wal)); - FVector2 v2(WallEndX(wal), WallEndY(wal)); + FVector2 v1(wal->pos.X, -wal->pos.Y); + FVector2 v2(p2wall->pos.X, -p2wall->pos.Y); PlanesAtPoint(frontsector, wal->pos.X, wal->pos.Y, &fch1, &ffh1); PlanesAtPoint(frontsector, p2wall->pos.X, p2wall->pos.Y, &fch2, &ffh2); diff --git a/source/core/sectorgeometry.cpp b/source/core/sectorgeometry.cpp index a53a23488..6f26d0bbb 100644 --- a/source/core/sectorgeometry.cpp +++ b/source/core/sectorgeometry.cpp @@ -61,8 +61,8 @@ static FVector3 CalcNormal(sectortype* sector, int plane) auto wal = sector->firstWall(); auto wal2 = wal->point2Wall(); - pt[0] = { (float)WallStartX(wal), 0.f, (float)WallStartY(wal)}; - pt[1] = { (float)WallStartX(wal2), 0.f, (float)WallStartY(wal2)}; + pt[0] = { (float)wal->pos.X, 0.f, -(float)wal->pos.Y}; + pt[1] = { (float)wal2->pos.X, 0.f, -(float)wal2->pos.Y}; PlanesAtPoint(sector, wal->pos.X, wal->pos.Y, plane ? &pt[0].Z : nullptr, plane? nullptr : &pt[0].Y); PlanesAtPoint(sector, wal2->pos.X, wal2->pos.Y, plane ? &pt[1].Z : nullptr, plane ? nullptr : &pt[1].Y);