diff --git a/source/core/rendering/hw_sections.h b/source/core/rendering/hw_sections.h index 6c864a2be..e451de59d 100644 --- a/source/core/rendering/hw_sections.h +++ b/source/core/rendering/hw_sections.h @@ -11,7 +11,19 @@ struct SectionLine int wall; int partner; int point2index; + + vec2_t v1() const { return ::wall[startpoint].pos; } + vec2_t v2() const { return ::wall[endpoint].pos; } + walltype* wallp() const { return &::wall[wall]; } + SectionLine* partnerLine() const; + }; +extern TArray sectionLines; + +inline SectionLine* SectionLine::partnerLine() const +{ + return partner == -1 ? nullptr : §ionLines[partner]; +} struct Section { @@ -20,7 +32,6 @@ struct Section TArray lines; }; -extern TArray sectionLines; extern TArray
Sections; extern TArray> sectionspersector; // reverse map, mainly for the automap diff --git a/source/core/rendering/hw_sections2.cpp b/source/core/rendering/hw_sections2.cpp index 86b43d31e..2c342cfa1 100644 --- a/source/core/rendering/hw_sections2.cpp +++ b/source/core/rendering/hw_sections2.cpp @@ -47,7 +47,6 @@ CVAR(Bool, hw_sectiondebug, false, 0) TMap bugged; static FMemArena sectionArena(102400); -TArray section2walls; TArray sections2; TArrayView> sections2PerSector; @@ -528,17 +527,14 @@ static void ConstructSections(TArray& builders) // count all sections and allocate the global buffers. // Allocate all Section walls. - TArray wallmap(numwalls, true); + sectionLines.Resize(numwalls); + for (int i = 0; i < numwalls; i++) { - wallmap[i] = (Section2Wall*)sectionArena.Calloc(sizeof(Section2Wall)); - } - for (int i = 0; i < numwalls; i++) - { - wallmap[i]->startpoint = i; - wallmap[i]->endpoint = wall[i].point2; - wallmap[i]->wall = i; - wallmap[i]->backside = validWallIndex(wall[i].nextwall)? wallmap[wall[i].nextwall] : nullptr; + sectionLines[i].startpoint = i; + sectionLines[i].endpoint = wall[i].point2; + sectionLines[i].wall = i; + sectionLines[i].partner = wall[i].nextwall; } unsigned count = 0; @@ -575,7 +571,7 @@ static void ConstructSections(TArray& builders) section->index = cursection++; int sectwalls = srcsect.wallcount; - auto walls = (Section2Wall**)sectionArena.Calloc(sectwalls * sizeof(Section2Wall*)); + auto walls = (int*)sectionArena.Calloc(sectwalls * sizeof(int)); section->walls.Set(walls, sectwalls); unsigned srcloops = srcsect.loops.Size(); @@ -588,20 +584,24 @@ static void ConstructSections(TArray& builders) auto& srcloop = srcsect.loops[i]; auto& loop = section->loops[i]; unsigned numwalls = srcloop.Size() - 1; - auto walls = (Section2Wall**)sectionArena.Calloc(numwalls * sizeof(Section2Wall*)); + auto walls = (int*)sectionArena.Calloc(numwalls * sizeof(int)); loop.walls.Set(walls, numwalls); for (unsigned w = 0; w < numwalls; w++) { - auto wal = wallmap[srcloop[w]]; - section->walls[curwall++] = loop.walls[w] = wal; + int wall_i = srcloop[w]; + auto wal = §ionLines[wall_i]; + section->walls[curwall++] = loop.walls[w] = wall_i; wal->section = section->index; - wal->index = section2walls.Size(); - section2walls.Push(wal); } } } } - section2walls.ShrinkToFit(); + // Can only do this after completing everything else. + for (auto& line : sectionLines) + { + line.partnersection = line.partner == -1 ? -1 : sectionLines[line.partner].section; + } + sectionLines.ShrinkToFit(); sections2.ShrinkToFit(); } @@ -615,8 +615,8 @@ void hw_CreateSections2() { bugged.Clear(); sectionArena.FreeAll(); - sections2.Reset(); - section2walls.Clear(); + sections2.Clear(); + sectionLines.Clear(); TArray collect; CollectLoops(collect); @@ -637,8 +637,9 @@ void hw_CreateSections2() for (auto& loop : section->loops) { Printf(PRINT_LOG, "\t\tLoop, %d walls\n", loop.walls.Size()); - for (auto& wall : loop.walls) + for (auto& wall_i : loop.walls) { + auto wall = §ionLines[wall_i]; Printf(PRINT_LOG, "\t\t\tWall %d, (%d, %d) -> (%d, %d)", wall->wall, wall->v1().x / 16, wall->v1().y / -16, wall->v2().x / 16, wall->v2().y / -16); if (wall->wallp()->nextwall == -1) Printf(PRINT_LOG, "one-sided\n"); else @@ -668,7 +669,7 @@ Outline BuildOutline(Section2* section) output[i].Resize(section->loops[i].walls.Size()); for (unsigned j = 0; j < section->loops[i].walls.Size(); j++) { - output[i][j] = section->loops[i].walls[j]->v1(); + output[i][j] = sectionLines[section->loops[i].walls[j]].v1(); } StripLoop(output[i]); } diff --git a/source/core/rendering/hw_sections2.h b/source/core/rendering/hw_sections2.h index 299a57067..6737696cb 100644 --- a/source/core/rendering/hw_sections2.h +++ b/source/core/rendering/hw_sections2.h @@ -1,4 +1,4 @@ - +#include "hw_sections.h" struct Section2; enum ESEctionFlag @@ -8,24 +8,9 @@ enum ESEctionFlag BadWinding = 4, }; -struct Section2Wall -{ - int index; - int section; - int startpoint; - int endpoint; - int wall; // points to the actual wall this belongs to - this is NOT necessarily the same as startpoint and can be -1. - Section2Wall* backside; // this is better kept as pointer because of reindexing when splitting a section. - - vec2_t v1() const { return ::wall[startpoint].pos; } - vec2_t v2() const { return ::wall[endpoint].pos; } - walltype* wallp() const { return &::wall[wall]; } - -}; - struct Section2Loop { - TArrayView walls; + TArrayView walls; }; struct Section2 @@ -36,13 +21,12 @@ struct Section2 unsigned index; sectortype* sector; // this uses a memory arena for storage, so use TArrayView instead of TArray - TArrayView walls; + TArrayView walls; TArrayView loops; }; extern TArray sections2; extern TArrayView> sections2PerSector; -extern TArray section2walls; void hw_CreateSections2(); using Outline = TArray>;