From 98258e0bb28055b86d860f2611359512d7b32f1e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 Jan 2022 16:34:04 +0100 Subject: [PATCH] - fix handling in the clipper for a new range that completely covers an existing one. The handling for this was from the first draft of the clipper that made very different assumptions than the final version. This cannot simply delete the old range - it has to explicitly alter it and recursively insert the outer sub-ranges separately. --- .../core/rendering/scene/hw_bunchdrawer.cpp | 4 +-- source/core/rendering/scene/hw_clipper.cpp | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index c1df5b81d..ecd3edef0 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -603,7 +603,7 @@ int BunchDrawer::FindClosestBunch() } } - //Printf("picked bunch starting at %d\n", Bunches[closest].startline); + //Printf("picked bunch starting at sector %d, wall %d\n", sections[sectionLines[Bunches[closest].startline].section].sector, Bunches[closest].startline); return closest; } @@ -680,7 +680,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal) if (section->lines[i] >= (int)wall.Size()) inbunch = false; if (!inbunch) { - //Printf("Starting bunch:\n\tWall %d\n", section->lines[i]); + //Printf("Starting bunch, Sector %d\n\tWall %d\n", section->sector, section->lines[i]); inbunch = StartBunch(sectnum, section->lines[i], walang1, walang2, portal); } else diff --git a/source/core/rendering/scene/hw_clipper.cpp b/source/core/rendering/scene/hw_clipper.cpp index edc27f11b..4fbb18dd5 100644 --- a/source/core/rendering/scene/hw_clipper.cpp +++ b/source/core/rendering/scene/hw_clipper.cpp @@ -201,10 +201,10 @@ void Clipper::Clear(binangle rangestart) if (visibleStart.asbam() != 0 || visibleEnd.asbam() != 0) { int vstart = int(visibleStart.asbam() - rangestart.asbam()); - if (vstart > 1) AddClipRange(0, vstart - 1); + if (vstart > 1) AddClipRange(0, vstart); int vend = int(visibleEnd.asbam() - rangestart.asbam()); - if (vend > 0 && vend < INT_MAX - 1) AddClipRange(vend + 1, INT_MAX); + if (vend > 0 && vend < INT_MAX) AddClipRange(vend, INT_MAX); } @@ -396,25 +396,27 @@ void Clipper::AddWindowRange(int start, int end, float topclip, float bottomclip if (node->start >= start && node->end <= end) { - if (node->topclip > node->bottomclip) // shortcut the common case where the old node is already closed. + int nodestart = node->start, nodeend = node->end; + if (node->topclip > node->bottomclip) // we only need to make adjustments to the old node if it is not closed. { float mtopclip = topclip, mbottomclip = bottomclip; mergeClip(node, mtopclip, mbottomclip, viewz); - // if old range is a window, make some adjustments. - if (mtopclip <= mbottomclip || (mtopclip <= node->topclip && mbottomclip >= node->bottomclip)) + // if the new window is closed, we must remove the old range and insert a closed one, so that it gets merged with its neighbours. + if (mtopclip <= mbottomclip) { - // if the new window is more narrow both on top and bottom, we can remove the old range. auto temp = node; node = node->next; RemoveRange(temp); - continue; + auto mynode = NewRange(nodestart, nodeend, 0, 0); + InsertRange(node->prev, mynode); + } + else + { + // in all other cases we must adjust the node's top and bottom + node->topclip = mtopclip; + node->bottomclip = mbottomclip; } - - // in all other cases we must adjust the node, and recursively process both sub-ranges. - node->topclip = mtopclip; - node->bottomclip = mbottomclip; } - int nodestart = node->start, nodeend = node->end; // At this point it is just easier to recursively add the sub-ranges because we'd have to run the full program on both anyway, // We must ensure the the new ranges' length are > 0. if (start < nodestart) AddWindowRange(start, nodestart, topclip, bottomclip, viewz);