- merge old SectionLine and new Section2Wall into one type and use the same global array.

This commit is contained in:
Christoph Oelckers 2021-12-15 11:07:46 +01:00
parent d353787d31
commit 208ca4f783
3 changed files with 37 additions and 41 deletions

View file

@ -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<SectionLine> sectionLines;
inline SectionLine* SectionLine::partnerLine() const
{
return partner == -1 ? nullptr : &sectionLines[partner];
}
struct Section
{
@ -20,7 +32,6 @@ struct Section
TArray<int> lines;
};
extern TArray<SectionLine> sectionLines;
extern TArray<Section> Sections;
extern TArray<TArray<int>> sectionspersector; // reverse map, mainly for the automap

View file

@ -47,7 +47,6 @@ CVAR(Bool, hw_sectiondebug, false, 0)
TMap<int, bool> bugged;
static FMemArena sectionArena(102400);
TArray<Section2Wall*> section2walls;
TArray<Section2*> sections2;
TArrayView<TArrayView<Section2*>> sections2PerSector;
@ -528,17 +527,14 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
// count all sections and allocate the global buffers.
// Allocate all Section walls.
TArray<Section2Wall*> 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<sectionbuildsector>& 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<sectionbuildsector>& 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 = &sectionLines[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<loopcollect> 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 = &sectionLines[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]);
}

View file

@ -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<Section2Wall*> walls;
TArrayView<int> 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<Section2Wall*> walls;
TArrayView<int> walls;
TArrayView<Section2Loop> loops;
};
extern TArray<Section2*> sections2;
extern TArrayView<TArrayView<Section2*>> sections2PerSector;
extern TArray<Section2Wall*> section2walls;
void hw_CreateSections2();
using Outline = TArray<TArray<vec2_t>>;