diff --git a/source/core/rendering/hw_sections2.cpp b/source/core/rendering/hw_sections2.cpp index 0f85bf670..4350171dc 100644 --- a/source/core/rendering/hw_sections2.cpp +++ b/source/core/rendering/hw_sections2.cpp @@ -47,6 +47,7 @@ CVAR(Bool, hw_sectiondebug, false, 0) TMap bugged; static FMemArena sectionArena(102400); +TArray section2walls; TArray sections2; TArrayView> sections2PerSector; @@ -534,9 +535,9 @@ static void ConstructSections(TArray& builders) } for (int i = 0; i < numwalls; i++) { - wallmap[i]->v1 = &wall[i].pos; - wallmap[i]->v2 = &wall[i].point2Wall()->pos; - wallmap[i]->wall = &wall[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; } @@ -593,14 +594,12 @@ static void ConstructSections(TArray& builders) { auto wal = wallmap[srcloop[w]]; section->walls[curwall++] = loop.walls[w] = wal; - wal->frontsection = section; + wal->section = section->index; // backsection will be filled in when everything is done. } } } } - for (auto& wal : wallmap) - if (wal->backside) wal->backsection = wal->backside->frontsection; } //========================================================================== @@ -636,12 +635,12 @@ void hw_CreateSections2() Printf(PRINT_LOG, "\t\tLoop, %d walls\n", loop.walls.Size()); for (auto& wall : loop.walls) { - Printf(PRINT_LOG, "\t\t\tWall %d, (%d, %d) -> (%d, %d)", ::wall.IndexOf(wall->wall), wall->v1->x / 16, wall->v1->y / -16, wall->v2->x / 16, wall->v2->y / -16); - if (wall->wall->nextwall == -1) Printf(PRINT_LOG, "one-sided\n"); + 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 { - Printf(PRINT_LOG, " next wall = %d, next sector = %d", wall->wall->nextwall, wall->wall->nextsector); - if (wall->wall->nextWall()->nextWall() != wall->wall) Printf(PRINT_LOG, " unreachable"); + Printf(PRINT_LOG, " next wall = %d, next sector = %d", wall->wallp()->nextwall, wall->wallp()->nextsector); + if (wall->wallp()->nextWall()->nextWall() != wall->wallp()) Printf(PRINT_LOG, " unreachable"); Printf(PRINT_LOG, "\n"); } } @@ -665,7 +664,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] = 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 ea11fcbd9..299a57067 100644 --- a/source/core/rendering/hw_sections2.h +++ b/source/core/rendering/hw_sections2.h @@ -10,15 +10,17 @@ enum ESEctionFlag struct Section2Wall { - // references to game data - vec2_t* v1; // points to start vertex in wall[] - vec2_t* v2; // points to end vertex in wall[] - walltype* wall; // points to the actual wall this belongs to - this is NOT necessarily the same as v1 and can be null. - - // references to section data - Section2Wall* backside; // points to this wall's back side - Section2* frontsection; - Section2* backsection; // if this is null the wall is one-sided + 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 @@ -40,6 +42,7 @@ struct Section2 extern TArray sections2; extern TArrayView> sections2PerSector; +extern TArray section2walls; void hw_CreateSections2(); using Outline = TArray>;