From caa8efd3d53b1a71b9d5d7162ec17e27581c1325 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 7 Apr 2021 16:09:25 +0200 Subject: [PATCH] - fixed renderer to avoid bunches of walls that wrap around behind the camera's back. --- .../core/rendering/scene/hw_bunchdrawer.cpp | 21 ++++++++++++------- source/core/rendering/scene/hw_bunchdrawer.h | 6 +++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 95a520f36..955aa7f3d 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -94,15 +94,16 @@ void BunchDrawer::StartScene() // //========================================================================== -void BunchDrawer::StartBunch(int sectnum, int linenum, binangle startan, binangle endan, bool portal) +bool BunchDrawer::StartBunch(int sectnum, int linenum, binangle startan, binangle endan, bool portal) { FBunch* bunch = &Bunches[LastBunch = Bunches.Reserve(1)]; bunch->sectnum = sectnum; bunch->startline = bunch->endline = linenum; - bunch->startangle = startan; - bunch->endangle = endan; + bunch->startangle = (startan.asbam() - ang1.asbam()) > ANGLE_180? ang1 :startan; + bunch->endangle = (endan.asbam() - ang2.asbam()) < ANGLE_180 ? ang2 : endan; bunch->portal = portal; + return bunch->endangle != ang2; } //========================================================================== @@ -111,10 +112,11 @@ void BunchDrawer::StartBunch(int sectnum, int linenum, binangle startan, binangl // //========================================================================== -void BunchDrawer::AddLineToBunch(int line, binangle newan) +bool BunchDrawer::AddLineToBunch(int line, binangle newan) { Bunches[LastBunch].endline++; - Bunches[LastBunch].endangle = newan; + Bunches[LastBunch].endangle = (newan.asbam() - ang2.asbam()) < ANGLE_180 ? ang2 : newan; + return Bunches[LastBunch].endangle != ang2; } //========================================================================== @@ -421,6 +423,7 @@ int BunchDrawer::FindClosestBunch() } } + //Printf("picked bunch starting at %d\n", Bunches[closest].startline); return closest; } @@ -497,12 +500,13 @@ void BunchDrawer::ProcessSector(int sectnum, bool portal) else if (!inbunch) { startangle = walang1; - StartBunch(sectnum, sect->wallptr + i, walang1, walang2, portal); - inbunch = true; + //Printf("Starting bunch:\n\tWall %d\n", sect->wallptr + i); + inbunch = StartBunch(sectnum, sect->wallptr + i, walang1, walang2, portal); } else { - AddLineToBunch(sect->wallptr + i, walang2); + //Printf("\tWall %d\n", sect->wallptr + i); + inbunch = AddLineToBunch(sect->wallptr + i, walang2); } if (thiswall->point2 != sect->wallptr + i + 1) inbunch = false; } @@ -516,6 +520,7 @@ void BunchDrawer::ProcessSector(int sectnum, bool portal) void BunchDrawer::RenderScene(const int* viewsectors, unsigned sectcount, bool portal) { + //Printf("----------------------------------------- \n"); auto process = [&]() { for (unsigned i = 0; i < sectcount; i++) diff --git a/source/core/rendering/scene/hw_bunchdrawer.h b/source/core/rendering/scene/hw_bunchdrawer.h index d72454cd5..9182ef76a 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.h +++ b/source/core/rendering/scene/hw_bunchdrawer.h @@ -12,7 +12,7 @@ struct FBunch int startline; int endline; bool portal; - binangle startangle; // in pseudo angles for the clipper + binangle startangle; binangle endangle; }; @@ -41,8 +41,8 @@ private: }; void StartScene(); - void StartBunch(int sectnum, int linenum, binangle startan, binangle endan, bool portal); - void AddLineToBunch(int line, binangle newan); + bool StartBunch(int sectnum, int linenum, binangle startan, binangle endan, bool portal); + bool AddLineToBunch(int line, binangle newan); void DeleteBunch(int index); bool CheckClip(walltype* wal); int ClipLine(int line, bool portal);