From 9397eb6a194a39ede022831331696b0c93982e7e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 8 Dec 2021 21:12:21 +0100 Subject: [PATCH] - automatically handle one specific case of bad wall loops. Both RRRA E3L1.map and SW $yamato.map have this: Wall x and Wall x+1 have identical properties and both reference Wall x+2 as point2. The duplicate in this case can be safely deleted to make the sector well formed. --- source/core/rendering/hw_sections2.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/source/core/rendering/hw_sections2.cpp b/source/core/rendering/hw_sections2.cpp index 3008aa686..fe5e8cc03 100644 --- a/source/core/rendering/hw_sections2.cpp +++ b/source/core/rendering/hw_sections2.cpp @@ -60,6 +60,7 @@ void CollectLoops(TArray& sectors) if (visited[w]) continue; thisloop.Clear(); thisloop.Push(w); + visited.Set(w); for (int ww = wall[w].point2; ww != w; ww = wall[ww].point2) { @@ -71,15 +72,31 @@ void CollectLoops(TArray& sectors) } if (visited[ww]) { - Printf("Wall %d's point2 links to already visited wall %d\n", w, ww); + // quick check for the only known cause of this in proper maps: + // RRRA E1L3 and SW $yamato have a wall duplicate where the duplicate's index is the original's + 1. These can just be deleted here and be ignored. + if (ww > 1 && wall[ww-1].x == wall[ww-2].x && wall[ww-1].y == wall[ww-2].y && wall[ww-1].point2 == wall[ww-2].point2 && wall[ww - 1].point2 == ww) + { + thisloop.Clear(); + break; + } + Printf("found already visited wall %d\nLinked by:", ww); + for (int i = 0; i < numwalls; i++) + { + if (wall[i].point2 == ww) + Printf(" %d,", i); + } + Printf("\n"); sectors.Last().bugged = true; break; } thisloop.Push(ww); visited.Set(ww); } - count ++; - sectors.Last().loops.Push(std::move(thisloop)); + if (thisloop.Size() > 0) + { + count++; + sectors.Last().loops.Push(std::move(thisloop)); + } } } Printf("Created %d loops from %d sectors, %d walls\n", count, numsectors, numwalls);