- use index fields in Section2Wall.

There's little benefit of using pointers here - it inflates a critical render struct, does not make any code more readable and requires quite deep refactoring of hw_bunchdrawer.
Now, with all fields having the same tyoe and name a lot less code needs to be changed.
This commit is contained in:
Christoph Oelckers 2021-12-15 00:44:10 +01:00
parent a407e86ff6
commit f8f6c345fc
2 changed files with 22 additions and 20 deletions

View file

@ -47,6 +47,7 @@ CVAR(Bool, hw_sectiondebug, false, 0)
TMap<int, bool> bugged; TMap<int, bool> bugged;
static FMemArena sectionArena(102400); static FMemArena sectionArena(102400);
TArray<Section2Wall*> section2walls;
TArray<Section2*> sections2; TArray<Section2*> sections2;
TArrayView<TArrayView<Section2*>> sections2PerSector; TArrayView<TArrayView<Section2*>> sections2PerSector;
@ -534,9 +535,9 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
} }
for (int i = 0; i < numwalls; i++) for (int i = 0; i < numwalls; i++)
{ {
wallmap[i]->v1 = &wall[i].pos; wallmap[i]->startpoint = i;
wallmap[i]->v2 = &wall[i].point2Wall()->pos; wallmap[i]->endpoint = wall[i].point2;
wallmap[i]->wall = &wall[i]; wallmap[i]->wall = i;
wallmap[i]->backside = validWallIndex(wall[i].nextwall)? wallmap[wall[i].nextwall] : nullptr; wallmap[i]->backside = validWallIndex(wall[i].nextwall)? wallmap[wall[i].nextwall] : nullptr;
} }
@ -593,14 +594,12 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
{ {
auto wal = wallmap[srcloop[w]]; auto wal = wallmap[srcloop[w]];
section->walls[curwall++] = loop.walls[w] = wal; section->walls[curwall++] = loop.walls[w] = wal;
wal->frontsection = section; wal->section = section->index;
// backsection will be filled in when everything is done. // 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()); Printf(PRINT_LOG, "\t\tLoop, %d walls\n", loop.walls.Size());
for (auto& wall : loop.walls) 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); 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->wall->nextwall == -1) Printf(PRINT_LOG, "one-sided\n"); if (wall->wallp()->nextwall == -1) Printf(PRINT_LOG, "one-sided\n");
else else
{ {
Printf(PRINT_LOG, " next wall = %d, next sector = %d", wall->wall->nextwall, wall->wall->nextsector); Printf(PRINT_LOG, " next wall = %d, next sector = %d", wall->wallp()->nextwall, wall->wallp()->nextsector);
if (wall->wall->nextWall()->nextWall() != wall->wall) Printf(PRINT_LOG, " unreachable"); if (wall->wallp()->nextWall()->nextWall() != wall->wallp()) Printf(PRINT_LOG, " unreachable");
Printf(PRINT_LOG, "\n"); Printf(PRINT_LOG, "\n");
} }
} }
@ -665,7 +664,7 @@ Outline BuildOutline(Section2* section)
output[i].Resize(section->loops[i].walls.Size()); output[i].Resize(section->loops[i].walls.Size());
for (unsigned j = 0; j < section->loops[i].walls.Size(); j++) 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]); StripLoop(output[i]);
} }

View file

@ -10,15 +10,17 @@ enum ESEctionFlag
struct Section2Wall struct Section2Wall
{ {
// references to game data int index;
vec2_t* v1; // points to start vertex in wall[] int section;
vec2_t* v2; // points to end vertex in wall[] int startpoint;
walltype* wall; // points to the actual wall this belongs to - this is NOT necessarily the same as v1 and can be null. 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]; }
// 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
}; };
struct Section2Loop struct Section2Loop
@ -40,6 +42,7 @@ struct Section2
extern TArray<Section2*> sections2; extern TArray<Section2*> sections2;
extern TArrayView<TArrayView<Section2*>> sections2PerSector; extern TArrayView<TArrayView<Section2*>> sections2PerSector;
extern TArray<Section2Wall*> section2walls;
void hw_CreateSections2(); void hw_CreateSections2();
using Outline = TArray<TArray<vec2_t>>; using Outline = TArray<TArray<vec2_t>>;