From 1a3b9f8ac08f25d7df94e00a14df05ff7a37caaf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 6 Dec 2021 20:08:32 +0100 Subject: [PATCH] - made several arrays holding sector related data dynamic. --- source/build/include/build.h | 2 +- source/build/src/clip.cpp | 29 +++++++------- source/core/maploader.cpp | 6 ++- source/core/rendering/hw_sections.cpp | 39 +++++++++---------- source/core/rendering/hw_sections.h | 3 +- .../core/rendering/scene/hw_bunchdrawer.cpp | 5 ++- source/core/rendering/scene/hw_bunchdrawer.h | 4 +- source/core/rendering/scene/hw_drawinfo.cpp | 2 +- source/core/savegamehelp.cpp | 2 +- source/core/sectorgeometry.cpp | 6 +-- source/games/blood/src/db.cpp | 2 +- 11 files changed, 50 insertions(+), 50 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index eef0be4a6..ba100d816 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -235,7 +235,7 @@ extern int16_t pskybits_override; EXTERN int16_t tailspritefree; EXTERN uint8_t gotpic[(MAXTILES+7)>>3]; -extern FixedBitArray gotsector; +extern BitArray gotsector; extern uint32_t drawlinepat; diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 70f09fb14..e07cecaea 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -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)) || diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 86fd1137c..f981c622a 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -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; diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index 227b37023..e04f8d06b 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -43,9 +43,8 @@ SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)]; -Section sections[MAXSECTORS + (MAXSECTORS >> 2)]; +TArray
Sections; TArray 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 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 = §ions[firstsection]; - Section* sect2 = §ions[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; diff --git a/source/core/rendering/hw_sections.h b/source/core/rendering/hw_sections.h index 307009b36..428893ef4 100644 --- a/source/core/rendering/hw_sections.h +++ b/source/core/rendering/hw_sections.h @@ -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
Sections; extern TArray sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap -extern int numsections; extern int numsectionlines; diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 03027697d..2a8271497 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -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 = §ions[sectionnum]; + auto section = &Sections[sectionnum]; for (unsigned i = 0; i < section->lines.Size(); i++) { auto thisline = §ionLines[section->lines[i]]; diff --git a/source/core/rendering/scene/hw_bunchdrawer.h b/source/core/rendering/scene/hw_bunchdrawer.h index d6622a017..ed8bd1d06 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.h +++ b/source/core/rendering/scene/hw_bunchdrawer.h @@ -27,7 +27,7 @@ class BunchDrawer double viewx, viewy; vec2_t iview; float gcosang, gsinang; - FixedBitArray gotsector; + BitArray gotsector; FixedBitArray 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& GotSector() const { return gotsector; } + const BitArray& GotSector() const { return gotsector; } }; diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index c3d8464cc..a483cf5bf 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -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 gotsector; +BitArray gotsector; //========================================================================== // diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index fd96961dd..4de7b92d5 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -705,7 +705,7 @@ void SerializeMap(FSerializer& arc) { setWallSectors(); hw_BuildSections(); - sectorGeometry.SetSize(numsections); + sectorGeometry.SetSize(Sections.Size()); } } diff --git a/source/core/sectorgeometry.cpp b/source/core/sectorgeometry.cpp index 80ef2d94a..d8b384fff 100644 --- a/source/core/sectorgeometry.cpp +++ b/source/core/sectorgeometry.cpp @@ -218,7 +218,7 @@ public: bool SectorGeometry::MakeVertices(unsigned int secnum, int plane, const FVector2& offset) { - auto sec = §ions[secnum]; + auto sec = &Sections[secnum]; auto sectorp = §or[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 = §ions[secnum]; + auto sec = &Sections[secnum]; auto sectorp = §or[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 = §or[sections[secnum].sector]; + auto sec = §or[Sections[secnum].sector]; auto compare = &data[secnum].compare[plane]; if (plane == 0) diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 5616f86e4..df5370b15 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -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; }