diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 0165e5f69..c27682af7 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -45,7 +45,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "v_draw.h" #include "sectorgeometry.h" #include "gamefuncs.h" -#include "hw_sections.h" +#include "hw_sections2.h" #include "coreactor.h" CVAR(Bool, am_followplayer, true, CVAR_ARCHIVE) CVAR(Bool, am_rotate, true, CVAR_ARCHIVE) @@ -581,12 +581,14 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang) int picnum = sect->floorpicnum; if ((unsigned)picnum >= (unsigned)MAXTILES) continue; - for (auto ii : sectionspersector[i]) + for (auto sect : sections2PerSector[i]) { - auto mesh = sectorGeometry.get(ii, 0, { 0.f,0.f }); - vertices.Resize(mesh->vertices.Size()); - for (unsigned j = 0; j < mesh->vertices.Size(); j++) + TArray* indices; + auto mesh = sectionGeometry.get(sect, 0, { 0.f, 0.f }, &indices); + vertices.Resize(indices->Size()); + for (unsigned jj = 0; jj < indices->Size(); jj++) { + int j = (*indices)[jj]; int ox = int(mesh->vertices[j].X * 16.f) - cposx; int oy = int(mesh->vertices[j].Y * -16.f) - cposy; int x1 = DMulScale(ox, xvect, -oy, yvect, 16) + (width << 11); diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index c3fdeb4e5..aaa47774d 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -492,6 +492,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, hw_BuildSections(); hw_CreateSections2(); sectorGeometry.SetSize(Sections.Size()); + sectionGeometry.SetSize(sections2.Size()); wallbackup = wall; diff --git a/source/core/rendering/hw_sections2.cpp b/source/core/rendering/hw_sections2.cpp index 97e49505a..0f85bf670 100644 --- a/source/core/rendering/hw_sections2.cpp +++ b/source/core/rendering/hw_sections2.cpp @@ -568,8 +568,10 @@ static void ConstructSections(TArray& builders) { auto section = (Section2*)sectionArena.Calloc(sizeof(Section2)); auto& srcsect = builder.sections[j]; - sections2[cursection++] = section; + sections2[cursection] = section; sections2PerSector[i][j] = section; + section->sector = §or[i]; + section->index = cursection++; int sectwalls = srcsect.wallcount; auto walls = (Section2Wall**)sectionArena.Calloc(sectwalls * sizeof(Section2Wall*)); @@ -620,11 +622,11 @@ void hw_CreateSections2() ConstructSections(builders); - //if (hw_sectiondebug) + if (hw_sectiondebug) { for (int i = 0; i < numsectors; i++) { - if (sections2PerSector[i][0]->flags == 0 && !bugged.CheckKey(i)) continue; + //if (sections2PerSector[i][0]->flags == 0 && !bugged.CheckKey(i)) continue; Printf(PRINT_LOG, "Sector %d, %d walls, %d sections\n", i, sector[i].wallnum, sections2PerSector[i].Size()); for (auto& section : sections2PerSector[i]) { diff --git a/source/core/sectorgeometry.cpp b/source/core/sectorgeometry.cpp index 0a19b04c3..169d9ef19 100644 --- a/source/core/sectorgeometry.cpp +++ b/source/core/sectorgeometry.cpp @@ -257,7 +257,7 @@ ETriangulateResult TriangulateOutlineEarcut(const FOutline& polygon, int count, // Sections are already validated so we can assume that the data is well defined here. auto indices = mapbox::earcut(polygon); - if (indices.size() < 3 * count) + if (indices.size() < 3 * (count + polygon.size() * 2 - 2)) { // this means that full triangulation failed. return ETriangulateResult::Failed; @@ -271,7 +271,7 @@ ETriangulateResult TriangulateOutlineEarcut(const FOutline& polygon, int count, points[p++] = { pt.first, pt.second }; } } - indicesOut.Resize(count * 3); + indicesOut.Resize((unsigned)indices.size()); for (unsigned i = 0; i < indices.size(); i++) { indicesOut[i] = indices[i]; @@ -313,7 +313,7 @@ ETriangulateResult TriangulateOutlineLibtess(const FOutline& polygon, int count, // Add contours. for (auto& loop : polygon) - tessAddContour(tess, 2, &loop.data()->first, (int)sizeof(*loop.data()), loop.size()); + tessAddContour(tess, 2, &loop.data()->first, (int)sizeof(*loop.data()), (int)loop.size()); int result = tessTesselate(tess, TESS_WINDING_POSITIVE, TESS_POLYGONS, 3, 2, 0); if (!result) @@ -556,7 +556,7 @@ SectionGeometryPlane* SectionGeometry::get(Section2* section, int plane, const F if (!section || section->index >= data.Size()) return nullptr; auto sectp = section->sector; if (sectp->dirty) MarkDirty(sectp); - if (section->flags & EDirty::GeometryDirty) + if (data[section->index].dirty & EDirty::GeometryDirty) { bool res = CreateMesh(section); if (!res) diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 1c7a06284..2fcc503c4 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -731,6 +731,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect hw_BuildSections(); hw_CreateSections2(); sectorGeometry.SetSize(Sections.Size()); + sectionGeometry.SetSize(sections2.Size()); wallbackup = wall; sectorbackup = sector; }