- made several arrays holding sector related data dynamic.

This commit is contained in:
Christoph Oelckers 2021-12-06 20:08:32 +01:00
parent 2a07159c8d
commit 1a3b9f8ac0
11 changed files with 50 additions and 50 deletions

View file

@ -235,7 +235,7 @@ extern int16_t pskybits_override;
EXTERN int16_t tailspritefree;
EXTERN uint8_t gotpic[(MAXTILES+7)>>3];
extern FixedBitArray<MAXSECTORS> gotsector;
extern BitArray gotsector;
extern uint32_t drawlinepat;

View file

@ -20,15 +20,11 @@ static linetype clipit[MAXCLIPNUM];
static int32_t clipsectnum, origclipsectnum, clipspritenum;
int clipsectorlist[MAXCLIPSECTORS];
static int origclipsectorlist[MAXCLIPSECTORS];
static uint8_t clipsectormap[(MAXSECTORS+7)>>3];
static uint8_t origclipsectormap[(MAXSECTORS+7)>>3];
static CollisionBase clipobjectval[MAXCLIPNUM];
static uint8_t clipignore[(MAXCLIPNUM+7)>>3];
static int32_t rxi[8], ryi[8];
inline void bitmap_set(uint8_t* const ptr, int const n) { ptr[n >> 3] |= 1 << (n & 7); }
inline char bitmap_test(uint8_t const* const ptr, int const n) { return ptr[n >> 3] & (1 << (n & 7)); }
BitArray clipsectormap;
int32_t quickloadboard=0;
@ -36,6 +32,7 @@ vec2_t hitscangoal = { (1<<29)-1, (1<<29)-1 };
int32_t hitallsprites = 0;
////////// CLIPMOVE //////////
inline char bitmap_test(uint8_t const* const ptr, int const n) { return ptr[n >> 3] & (1 << (n & 7)); }
// x1, y1: in/out
@ -175,7 +172,7 @@ static inline void addclipsect(int const sectnum)
{
if (clipsectnum < MAXCLIPSECTORS)
{
bitmap_set(clipsectormap, sectnum);
clipsectormap.Set(sectnum);
clipsectorlist[clipsectnum++] = sectnum;
}
else
@ -413,7 +410,7 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist
for (auto& wal : wallsofsector(listsectnum))
{
if (wal.nextsector >= 0 && bitmap_test(clipsectormap, wal.nextsector))
if (wal.nextsector >= 0 && clipsectormap[wal.nextsector])
search.Add(wal.nextsector);
}
}
@ -478,8 +475,8 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
clipmove_warned = 0;
memset(clipsectormap, 0, (numsectors+7)>>3);
bitmap_set(clipsectormap, *sectnum);
clipsectormap.Zero();
clipsectormap.Set(*sectnum);
do
{
@ -563,7 +560,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
}
else if (wal->nextsector>=0)
{
if (bitmap_test(clipsectormap, wal->nextsector) == 0)
if (!clipsectormap[wal->nextsector])
addclipsect(wal->nextsector);
}
}
@ -858,8 +855,8 @@ int pushmove_(vec3_t *const vect, int *const sectnum,
clipsectorlist[0] = *sectnum;
clipsectnum = 1;
memset(clipsectormap, 0, (numsectors + 7) >> 3);
bitmap_set(clipsectormap, *sectnum);
clipsectormap.Zero();
clipsectormap.Set(*sectnum);
}
do
@ -926,7 +923,7 @@ int pushmove_(vec3_t *const vect, int *const sectnum,
clipupdatesector(vect->vec2, sectnum, walldist);
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE && *sectnum < 0) return -1;
}
else if (bitmap_test(clipsectormap, wal->nextsector) == 0)
else if (!clipsectormap[wal->nextsector])
addclipsect(wal->nextsector);
}
@ -975,8 +972,8 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas
clipsectorlist[0] = sectnum;
clipsectnum = 1;
clipspritenum = 0;
memset(clipsectormap, 0, (numsectors+7)>>3);
bitmap_set(clipsectormap, sectnum);
clipsectormap.Zero();
clipsectormap.Set(sectnum);
do //Collect sectors inside your square first
{
@ -1011,7 +1008,7 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas
if (((nextsect->floorstat&1) == 0) && (pos.z >= nextsect->floorz-(3<<8))) continue;
int nextsectno = ::sectnum(nextsect);
if (bitmap_test(clipsectormap, nextsectno) == 0)
if (!clipsectormap[nextsectno])
addclipsect(nextsectno);
if (((v1.x < xmin + MAXCLIPDIST) && (v2.x < xmin + MAXCLIPDIST)) ||

View file

@ -49,6 +49,8 @@
#include "interpolate.h"
#include "games/blood/src/mapstructs.h"
extern BitArray clipsectormap;
// needed for skipping over to get the map size first.
enum
{
@ -371,6 +373,8 @@ void allocateMapArrays(int numsprites)
show2dsector.Resize(numsectors);
show2dwall.Resize(numwalls);
gotsector.Resize(numsectors);
clipsectormap.Resize(numsectors);
mapDataArena.FreeAll();
sector.Resize(numsectors);
@ -469,7 +473,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang,
G_LoadMapHack(filename, md4, sprites);
setWallSectors();
hw_BuildSections();
sectorGeometry.SetSize(numsections);
sectorGeometry.SetSize(Sections.Size());
wallbackup = wall;

View file

@ -43,9 +43,8 @@
SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)];
Section sections[MAXSECTORS + (MAXSECTORS >> 2)];
TArray<Section> Sections;
TArray<int> sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap
int numsections;
int numsectionlines;
void hw_SplitSector(int sector, int startpos, int endpos);
@ -55,6 +54,7 @@ TArray<int> splits;
void hw_BuildSections()
{
Sections.Resize(numsectors);
for (int i = 0; i < numsectors; i++)
{
// Fix maps which do not set their wallptr to the first wall. Lo Wang In Time's map 11 is such a case.
@ -65,16 +65,15 @@ void hw_BuildSections()
sector[i].wallnum++;
wp--;
}
sections[i].sector = i;
sections[i].lines.Resize(sector[i].wallnum);
for (int j = 0; j < sector[i].wallnum; j++) sections[i].lines[j] = sector[i].wallptr + j;
Sections[i].sector = i;
Sections[i].lines.Resize(sector[i].wallnum);
for (int j = 0; j < sector[i].wallnum; j++) Sections[i].lines[j] = sector[i].wallptr + j;
sectionspersector[i].Resize(1);
sectionspersector[i][0] = i;
}
// Initial setup just creates a 1:1 mapping of walls to section lines and sectors to sections.
numsectionlines = numwalls;
numsections = numsectors;
for (int i = 0; i < numwalls; i++)
{
auto& wal = wall[i];
@ -95,12 +94,12 @@ static void SplitSection(int section, int start, int end)
{
// note: to do this, the sector's lines must be well ordered and there must only be one outline and no holes.
// This also can only apply a single split to a given sector.
int firstsection = numsections++;
int secondsection = numsections++;
int firstsection = Sections.Reserve(2);
int secondsection = firstsection+1;
auto& sect = sections[section];
Section* sect1 = &sections[firstsection];
Section* sect2 = &sections[secondsection];
auto& sect = Sections[section];
Section* sect1 = &Sections[firstsection];
Section* sect2 = &Sections[secondsection];
sect1->sector = sect.sector;
sect2->sector = sect.sector;
sect1->lines.Clear();
@ -135,7 +134,7 @@ static void SplitSection(int section, int start, int end)
{
SectionLine& newline = sectionLines[thisline];
newline = sectionLines[sline];
newline.section = int(sect1 - sections);
newline.section = Sections.IndexOf(sect1);
if (i != sect1->lines.Size() - 1) newline.point2index = thisline + 1 - firstnewline;
else newline.point2index = 0;
assert(newline.point2index >= 0);
@ -153,8 +152,8 @@ static void SplitSection(int section, int start, int end)
{
splitline1 = thisline++;
sectionLines[splitline1].wall = -1;
sectionLines[splitline1].section = int(sect1 - sections);
sectionLines[splitline1].partnersection = int(sect2 - sections);
sectionLines[splitline1].section = Sections.IndexOf(sect1);
sectionLines[splitline1].partnersection = Sections.IndexOf(sect2);
sectionLines[splitline1].startpoint = start;
sectionLines[splitline1].endpoint = end;
sectionLines[splitline1].point2index = splitline1 + 1 - firstnewline;
@ -170,7 +169,7 @@ static void SplitSection(int section, int start, int end)
{
SectionLine& newline = sectionLines[thisline];
newline = sectionLines[sline];
newline.section = int(sect2 - sections);
newline.section = Sections.IndexOf(sect1);
if (i != sect2->lines.Size() - 1) newline.point2index = thisline + 1 - firstnewline;
else newline.point2index = 0;
assert(newline.point2index >= 0);
@ -188,8 +187,8 @@ static void SplitSection(int section, int start, int end)
{
splitline2 = thisline++;
sectionLines[splitline2].wall = -1;
sectionLines[splitline2].section = int(sect2 - sections);
sectionLines[splitline2].partnersection = int(sect1 - sections);
sectionLines[splitline2].section = Sections.IndexOf(sect2);
sectionLines[splitline2].partnersection = Sections.IndexOf(sect1);
sectionLines[splitline2].startpoint = end;
sectionLines[splitline2].endpoint = start;
sectionLines[splitline2].point2index = splitline2 + 1 - firstnewline;
@ -199,8 +198,8 @@ static void SplitSection(int section, int start, int end)
sectionLines[splitline2].partner = splitline1;
sectionspersector[sect.sector].Resize(2);
sectionspersector[sect.sector][0] = int(sect1 - sections);
sectionspersector[sect.sector][1] = int(sect2 - sections);
sectionspersector[sect.sector][0] = Sections.IndexOf(sect1);
sectionspersector[sect.sector][1] = Sections.IndexOf(sect2);
}
void hw_SplitSector(int sectnum, int start, int end)
@ -213,7 +212,7 @@ void hw_SplitSector(int sectnum, int start, int end)
{
int sect = sectionspersector[sectnum][i];
bool foundstart = false, foundend = false;
for (int aline : sections[sect].lines)
for (int aline : Sections[sect].lines)
{
int line = sectionLines[aline].wall;
if (line == start) foundstart = true;

View file

@ -22,9 +22,8 @@ struct Section
// giving 25% more may be a bit high as normally this should be small numbers only.
extern SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)];
extern Section sections[MAXSECTORS + (MAXSECTORS >> 2)];
extern TArray<Section> Sections;
extern TArray<int> sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap
extern int numsections;
extern int numsectionlines;

View file

@ -92,6 +92,7 @@ void BunchDrawer::StartScene()
StartTime = I_msTime();
Bunches.Clear();
CompareData.Clear();
gotsector.Resize(numsectors);
gotsector.Zero();
gotsection2.Zero();
gotwall.Zero();
@ -560,7 +561,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal)
SetupSprite.Clock();
int sectnum = sections[sectionnum].sector;
int sectnum = Sections[sectionnum].sector;
if (!gotsector[sectnum])
{
gotsector.Set(sectnum);
@ -598,7 +599,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal)
//Todo: process subsectors
inbunch = false;
auto section = &sections[sectionnum];
auto section = &Sections[sectionnum];
for (unsigned i = 0; i < section->lines.Size(); i++)
{
auto thisline = &sectionLines[section->lines[i]];

View file

@ -27,7 +27,7 @@ class BunchDrawer
double viewx, viewy;
vec2_t iview;
float gcosang, gsinang;
FixedBitArray<MAXSECTORS> gotsector;
BitArray gotsector;
FixedBitArray<MAXSECTORS*5/4> gotsection2;
BitArray gotwall;
BitArray blockwall;
@ -61,5 +61,5 @@ private:
public:
void Init(HWDrawInfo* _di, Clipper* c, vec2_t& view, binangle a1, binangle a2);
void RenderScene(const int* viewsectors, unsigned sectcount, bool portal);
const FixedBitArray<MAXSECTORS>& GotSector() const { return gotsector; }
const BitArray& GotSector() const { return gotsector; }
};

View file

@ -51,7 +51,7 @@ CVAR(Bool, gl_texture, true, 0)
CVAR(Float, gl_mask_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_sprite_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
FixedBitArray<MAXSECTORS> gotsector;
BitArray gotsector;
//==========================================================================
//

View file

@ -705,7 +705,7 @@ void SerializeMap(FSerializer& arc)
{
setWallSectors();
hw_BuildSections();
sectorGeometry.SetSize(numsections);
sectorGeometry.SetSize(Sections.Size());
}
}

View file

@ -218,7 +218,7 @@ public:
bool SectorGeometry::MakeVertices(unsigned int secnum, int plane, const FVector2& offset)
{
auto sec = &sections[secnum];
auto sec = &Sections[secnum];
auto sectorp = &sector[sec->sector];
int numvertices = sec->lines.Size();
@ -333,7 +333,7 @@ bool SectorGeometry::MakeVertices(unsigned int secnum, int plane, const FVector2
bool SectorGeometry::MakeVertices2(unsigned int secnum, int plane, const FVector2& offset)
{
auto sec = &sections[secnum];
auto sec = &Sections[secnum];
auto sectorp = &sector[sec->sector];
int numvertices = sec->lines.Size();
@ -544,7 +544,7 @@ nexti:;
void SectorGeometry::ValidateSector(unsigned int secnum, int plane, const FVector2& offset)
{
auto sec = &sector[sections[secnum].sector];
auto sec = &sector[Sections[secnum].sector];
auto compare = &data[secnum].compare[plane];
if (plane == 0)

View file

@ -726,7 +726,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
setWallSectors();
hw_BuildSections();
sectorGeometry.SetSize(numsections);
sectorGeometry.SetSize(Sections.Size());
wallbackup = wall;
sectorbackup = sector;
}