From 3c4429f2a8743b4331ebf02c9a7aeebfd1b96b88 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 31 Mar 2021 21:26:57 +0200 Subject: [PATCH] - fixed sector mesh generator to allow sectors with non-continuous wall loops. Blood has a few such sectors. --- source/core/sectorgeometry.cpp | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/source/core/sectorgeometry.cpp b/source/core/sectorgeometry.cpp index c9e471773..7099771ef 100644 --- a/source/core/sectorgeometry.cpp +++ b/source/core/sectorgeometry.cpp @@ -224,26 +224,39 @@ void SectorGeometry::MakeVertices(unsigned int secnum, int plane) polygon.resize(1); curPoly = &polygon.back(); + FixedBitArray done; int fz = sec->floorz, cz = sec->ceilingz; sec->floorz = sec->ceilingz = 0; - for (int i = 0; i < numvertices; i++) - { - auto wal = &wall[sec->wallptr + i]; + int vertstoadd = numvertices; - float X = WallStartX(wal); - float Y = WallStartY(wal); - if (fabs(X) > 32768. || fabs(Y) > 32768.) - { - // If we get here there's some fuckery going around with the coordinates. Let's better abort and wait for things to realign. - return; - } - curPoly->push_back(std::make_pair(X, Y)); - if (wal->point2 != sec->wallptr+i+1 && i < numvertices - 1) + done.Zero(); + while (vertstoadd > 0) + { + int start = 0; + while (done[start] && start < numvertices) start++; + int s = start; + if (start < numvertices) { + while (!done[start]) + { + auto wallp = &wall[sec->wallptr + start]; + float X = WallStartX(wallp); + float Y = WallStartY(wallp); + if (fabs(X) > 32768. || fabs(Y) > 32768.) + { + // If we get here there's some fuckery going around with the coordinates. Let's better abort and wait for things to realign. + return; + } + curPoly->push_back(std::make_pair(X, Y)); + done.Set(start); + vertstoadd--; + start = wallp->point2 - sec->wallptr; + } polygon.resize(polygon.size() + 1); curPoly = &polygon.back(); + assert(start == s); } } // Now make sure that the outer boundary is the first polygon by picking a point that's as much to the outside as possible.