- replaced most of numsectors, too.

This commit is contained in:
Christoph Oelckers 2021-12-21 10:51:41 +01:00
parent f1c0298825
commit df0c577cf4
20 changed files with 68 additions and 72 deletions

View file

@ -398,7 +398,7 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist
}
{
BFSSearch search(numsectors, *sectnum);
BFSSearch search(sector.Size(), *sectnum);
for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;)
{
@ -417,7 +417,7 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist
}
{
BFSSearch search(numsectors, *sectnum);
BFSSearch search(sector.Size(), *sectnum);
for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;)
{
@ -784,7 +784,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
int32_t tempint2, tempint1 = INT32_MAX;
*sectnum = -1;
for (int j = numsectors - 1; j >= 0; j--)
for (int j = (int)sector.Size() - 1; j >= 0; j--)
{
auto sect = &sector[j];
if (inside(pos->x, pos->y, sect) == 1)

View file

@ -615,7 +615,7 @@ void neartag(const vec3_t& sv, sectortype* sect, int ange, HitInfoBase& result,
//
void dragpoint(int w, int32_t dax, int32_t day)
{
BFSSearch walbitmap(numwalls);
BFSSearch walbitmap(wall.Size());
int clockwise = 0;
const int tmpstartwall = w;
int cnt = 16384; // limit the number of iterations.
@ -735,7 +735,7 @@ void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, in
if (checker(x, y, z, initialsectnum))
return;
BFSSearch search(numsectors, *sectnum);
BFSSearch search(sector.Size(), *sectnum);
int iter = 0;
for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;)
@ -777,7 +777,7 @@ void updatesector(int32_t const x, int32_t const y, int * const sectnum)
// we need to support passing in a sectnum of -1, unfortunately
for (int i = numsectors - 1; i >= 0; --i)
for (int i = (int)sector.Size() - 1; i >= 0; --i)
if (inside_p(x, y, i))
SET_AND_RETURN(*sectnum, i);
@ -795,7 +795,7 @@ void updatesectorz(int32_t const x, int32_t const y, int32_t const z, int* const
// we need to support passing in a sectnum of -1, unfortunately
for (int i = numsectors - 1; i >= 0; --i)
for (int i = (int)sector.Size() - 1; i >= 0; --i)
if (inside_z_p(x, y, z, i))
SET_AND_RETURN(*sectnum, i);

View file

@ -416,7 +416,7 @@ void drawredlines(int cposx, int cposy, int czoom, int cang)
int width = screen->GetWidth();
int height = screen->GetHeight();
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
if (!gFullMap && !show2dsector[i]) continue;
@ -464,7 +464,7 @@ static void drawwhitelines(int cposx, int cposy, int czoom, int cang)
int width = screen->GetWidth();
int height = screen->GetHeight();
for (int i = numsectors - 1; i >= 0; i--)
for (int i = (int)sector.Size() - 1; i >= 0; i--)
{
if (!gFullMap && !show2dsector[i] && !isSWALL()) continue;
@ -556,7 +556,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang)
TArray<spritetype*> floorsprites;
for (int i = numsectors - 1; i >= 0; i--)
for (int i = (int)sector.Size() - 1; i >= 0; i--)
{
auto sect = &sector[i];
if (!gFullMap && !show2dsector[i]) continue;

View file

@ -86,7 +86,7 @@ class BFSSectorSearch : public BFSSearch
{
public:
BFSSectorSearch(const sectortype* startnode) : BFSSearch(numsectors, sector.IndexOf(startnode))
BFSSectorSearch(const sectortype* startnode) : BFSSearch(sector.Size(), sector.IndexOf(startnode))
{
}

View file

@ -244,7 +244,7 @@ static void ReadWallV5(FileReader& fr, walltype& wall)
static void SetWallPalV5()
{
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
int startwall = sector[i].wallptr;
int endwall = startwall + sector[i].wallnum;
@ -380,20 +380,20 @@ static void ReadSpriteV5(FileReader& fr, spritetype& spr, int& secno)
// allocates global map storage. Blood will also call this.
void allocateMapArrays(int numsprites)
void allocateMapArrays(int numwall, int numsector, int numsprites)
{
ClearInterpolations();
show2dsector.Resize(numsectors);
show2dwall.Resize(numwalls);
gotsector.Resize(numsectors);
clipsectormap.Resize(numsectors);
show2dsector.Resize(numsector);
show2dwall.Resize(numwall);
gotsector.Resize(numsector);
clipsectormap.Resize(numsector);
mapDataArena.FreeAll();
sector.Resize(numsectors);
memset(sector.Data(), 0, sizeof(sectortype) * numsectors);
wall.Resize(numwalls);
sector.Resize(numsector);
memset(sector.Data(), 0, sizeof(sectortype) * numsector);
wall.Resize(numwall);
memset(wall.Data(), 0, sizeof(walltype) * wall.Size());
ClearAutomap();
@ -444,13 +444,13 @@ void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cu
auto spritepos = fr.Tell();
// Now that we know the map's size, set up the globals.
allocateMapArrays(numsprites);
allocateMapArrays(numwalls, numsectors, numsprites);
sprites.sprites.Resize(numsprites);
memset(sprites.sprites.Data(), 0, numsprites * sizeof(spritetype));
// Now load the actual data.
fr.Seek(sectorpos, FileReader::SeekSet);
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
switch (mapversion)
{
@ -542,7 +542,7 @@ void setWallSectors()
wal.lengthflags = 3;
}
for (int i = 0; i < numsectors - 1; i++)
for (unsigned i = 0; i < sector.Size() - 1; i++)
{
auto sect = &sector[i];
auto nextsect = &sector[i + 1];

View file

@ -700,7 +700,7 @@ inline int walltype::Length()
//=============================================================================
struct SpawnSpriteDef;
void allocateMapArrays(int numsprites);
void allocateMapArrays(int numwall, int numsector, int numsprites);
void validateSprite(spritetype& spr, int secno, int index);
void fixSectors();
void loadMap(const char *filename, int flags, vec3_t *pos, int16_t *ang, int *cursectnum, SpawnSpriteDef& sprites);

View file

@ -211,13 +211,13 @@ int GetWindingOrder(TArray<int>& poly)
static void CollectLoops(TArray<loopcollect>& sectors)
{
BitArray visited;
visited.Resize(numwalls);
visited.Resize(wall.Size());
visited.Zero();
TArray<int> thisloop;
int count = 0;
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
int first = sector[i].wallptr;
int last = first + sector[i].wallnum;
@ -251,7 +251,7 @@ static void CollectLoops(TArray<loopcollect>& sectors)
}
Printf("found already visited wall %d\nLinked by:", ww);
bugged.Insert(i, true);
for (int i = 0; i < numwalls; i++)
for (unsigned i = 0; i < wall.Size(); i++)
{
if (wall[i].point2 == ww)
Printf(" %d,", i);
@ -347,13 +347,8 @@ static int insideLoop(TArray<int>& check, TArray<int>& loop)
static void GroupData(TArray<loopcollect>& collect, TArray<sectionbuildsector>& builders)
{
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
if (i == 250)
{
int a = 0;
}
auto& builder = builders[i];
builder.sectnum = i;
auto& sectloops = collect[i].loops;
@ -585,37 +580,37 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
TArray<int> splitwalls;
// Allocate all Section walls.
sectionLines.Resize(numwalls + splits.Size() * 2 / 3);
sectionLines.Resize(wall.Size() + splits.Size() * 2 / 3);
for (unsigned i = 0; i < splits.Size(); i++)
{
if (i % 3) splitwalls.Push(splits[i]);
}
int nextwall = numwalls;
for (int i = 0; i < numwalls; i++)
unsigned nextwall = wall.Size();
for (unsigned i = 0; i < wall.Size(); i++)
{
sectionLines[i].startpoint = i;
sectionLines[i].endpoint = wall[i].point2;
sectionLines[i].wall = i;
sectionLines[i].partner = wall[i].nextwall;
}
for (int i = numwalls; i < (int)sectionLines.Size(); i++)
for (unsigned i = wall.Size(); i < sectionLines.Size(); i++)
{
int pair = (i - numwalls);
unsigned pair = (i - wall.Size());
sectionLines[i].startpoint = splitwalls[pair];
sectionLines[i].endpoint = splitwalls[pair ^ 1];
sectionLines[i].wall = -1;
sectionLines[i].partner = numwalls + (pair ^ 1);
sectionLines[i].partner = wall.Size() + (pair ^ 1);
}
unsigned count = 0;
// allocate as much as possible from the arena here.
size_t size = sizeof(*sectionsPerSector.Data()) * numsectors;
size_t size = sizeof(*sectionsPerSector.Data()) * sector.Size();
auto data = sectionArena.Calloc(size);
sectionsPerSector.Set(static_cast<decltype(sectionsPerSector.Data())>(data), numsectors);
sectionsPerSector.Set(static_cast<decltype(sectionsPerSector.Data())>(data), sector.Size());
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
auto& builder = builders[i];
count += builder.sections.Size();
@ -630,7 +625,7 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
// now fill in the data
int cursection = 0;
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
auto& builder = builders[i];
for (unsigned j = 0; j < builder.sections.Size(); j++)
@ -668,7 +663,7 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
}
else
{
wall_i = numwalls + splitwalls.Find(-wall_i);
wall_i = (int)wall.Size() + splitwalls.Find(-wall_i);
auto wal = &sectionLines[wall_i];
section->lines[curwall++] = loop.walls[w] = wall_i;
wal->section = section->index;
@ -701,7 +696,7 @@ void hw_CreateSections()
TArray<loopcollect> collect;
CollectLoops(collect);
TArray<sectionbuildsector> builders(numsectors, true);
TArray<sectionbuildsector> builders(sector.Size(), true);
GroupData(collect, builders);
SplitLoops(builders);

View file

@ -62,10 +62,10 @@ inline void mergePortals()
pt1.targets.Append(pt2.targets);
pt2.targets.Reset();
pt2.type = -1;
for (int n = 0; n < numsectors; n++)
for (auto& s : sector)
{
//Printf("Merged %d and %d\n", i, j);
if (sector[n].portalnum == (int)j) sector[n].portalnum = i;
if (s.portalnum == (int)j) s.portalnum = i;
}
didsomething = true;
break;

View file

@ -68,16 +68,16 @@ void BunchDrawer::Init(HWDrawInfo *_di, Clipper* c, vec2_t& view, binangle a1, b
gcosang = bamang(di->Viewpoint.RotAngle).fcos();
gsinang = bamang(di->Viewpoint.RotAngle).fsin();
for (int i = 0; i < numwalls; i++)
for (auto& w : wall)
{
// Precalculate the clip angles to avoid doing this repeatedly during level traversal.
auto vv = wall[i].pos - view;
wall[i].clipangle = bvectangbam(vv.x, vv.y);
auto vv = w.pos - view;
w.clipangle = bvectangbam(vv.x, vv.y);
}
memset(sectionstartang.Data(), -1, sectionstartang.Size() * sizeof(sectionstartang[0]));
memset(sectionendang.Data(), -1, sectionendang.Size() * sizeof(sectionendang[0]));
gotwall.Resize(numwalls);
//blockwall.Resize(numwalls);
gotwall.Resize(wall.Size());
//blockwall.Resize(wall.Size());
}
//==========================================================================
@ -93,7 +93,7 @@ void BunchDrawer::StartScene()
StartTime = I_msTime();
Bunches.Clear();
CompareData.Clear();
gotsector.Resize(numsectors);
gotsector.Resize(sector.Size());
gotsector.Zero();
gotsection2.Resize(numsections);
gotsection2.Zero();
@ -652,7 +652,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal)
{
if (walang1.asbam() >= angrange.asbam()) { walang1 = bamang(0); inbunch = false; }
if (walang2.asbam() >= angrange.asbam()) walang2 = angrange;
if (section->lines[i] >= numwalls) inbunch = false;
if (section->lines[i] >= (int)wall.Size()) inbunch = false;
if (!inbunch)
{
//Printf("Starting bunch:\n\tWall %d\n", section->lines[i]);

View file

@ -297,6 +297,7 @@ public:
struct HWLineToSpritePortal : public HWLinePortal
{
walltype clipline = {};
walltype* origin;
spritetype* camera;
protected:
@ -309,7 +310,7 @@ protected:
public:
HWLineToSpritePortal(FPortalSceneState* state, walltype* from, spritetype* to)
: HWLinePortal(state, &wall[numwalls]), origin(from), camera(to)
: HWLinePortal(state, &clipline), origin(from), camera(to)
{
}
};

View file

@ -165,7 +165,7 @@ void PropagateMarkerReferences(void)
case kMarkerWarpDest:
{
int nOwner = actor->s().owner;
if (nOwner >= 0 && nOwner < numsectors)
if (validSectorIndex(nOwner))
{
if (sector[nOwner].hasX())
{
@ -178,7 +178,7 @@ void PropagateMarkerReferences(void)
case kMarkerOn:
{
int nOwner = actor->s().owner;
if (nOwner >= 0 && nOwner < numsectors)
if (validSectorIndex(nOwner))
{
if (sector[nOwner].hasX())
{

View file

@ -263,7 +263,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
gMapRev = mapHeader.revision;
numsectors = mapHeader.numsectors;
numwalls = mapHeader.numwalls;
allocateMapArrays(mapHeader.numsprites);
allocateMapArrays(mapHeader.numwalls, mapHeader.numsectors, mapHeader.numsprites);
#if 1 // bad, bad hack, just for making Polymost happy...
PolymostAllocFakeSector();
#endif
@ -297,7 +297,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
pSky->tileofs[i] = LittleShort(tpskyoff[i]);
}
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
sectortype* pSector = &sector[i];
sectortypedisk load;

View file

@ -690,7 +690,7 @@ BitArray GetClosestSpriteSectors(sectortype* pSector, int x, int y, int nDist, T
// E1M2: throwing TNT at the double doors while standing on the train platform
// by setting newSectCheckMethod to true these issues will be resolved
BitArray sectorMap(numsectors); // this gets returned to the caller.
BitArray sectorMap(sector.Size()); // this gets returned to the caller.
sectorMap.Zero();
sectorMap.Set(sectnum(pSector));
double nDist4sq = 256. * nDist * nDist; // (nDist * 16)^2 - * 16 to account for Build's 28.4 fixed point format.

View file

@ -48,7 +48,7 @@ void InitMirrors(void)
{
tileDelete(4080 + i);
}
for (int i = numwalls - 1; i >= 0; i--)
for (int i = (int)wall.Size() - 1; i >= 0; i--)
{
auto pWalli = &wall[i];
if (mirrorcnt == 16)
@ -105,7 +105,7 @@ void InitMirrors(void)
continue;
}
}
for (int i = numsectors - 1; i >= 0; i--)
for (int i = (int)sector.Size() - 1; i >= 0; i--)
{
if (mirrorcnt >= 15)
break;

View file

@ -8314,7 +8314,7 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
}
else if (chan->SourceType == SOURCE_Unattached)
{
if (chan->UserData < 0 || chan->UserData >= numsectors) return false; // not a vaild sector sound.
if (chan->UserData < 0 || !validSectorIndex(chan->UserData)) return false; // not a vaild sector sound.
sndx = int(chan->Point[0] * 16);
sndy = int(chan->Point[1] * -16);
searchsect = &sector[chan->UserData];

View file

@ -398,7 +398,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
//Draw sprites
auto pactor = ps[screenpeek].GetActor();
for (i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
if (!gFullMap || !show2dsector[i]) continue;
DukeSectIterator it(i);

View file

@ -951,7 +951,7 @@ void DoWall(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, i
{
auto lValue = GetGameVarID(lVar2, sActor, sPlayer).safeValue();
auto vWall = GetGameVarID(lVar1, sActor, sPlayer);
iWall = vWall.safeValue();
auto iWall = vWall.safeValue();
if (iWall < 0 || iWall >= (int)wall.Size() || vWall.isActor())
{
@ -1050,7 +1050,7 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
iSector = vv.safeValue();
}
if (iSector < 0 || iSector >= numsectors || no)
if (iSector < 0 || iSector >= (int)sector.Size() || no)
{
if (!bSet) SetGameVarID(lVar2, 0, sActor, sPlayer);
return;

View file

@ -881,7 +881,7 @@ static void SpawnPortals()
}
// Unfortunately the above still isn't enough. We got to do one more check to add stuff to the portals.
// There is one map where a sector neighboring a portal is not marked as part of the portal itself.
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
auto sectp = &sector[i];
if (sectp->floorpicnum == FOF && sectp->portalflags != PORTAL_SECTOR_FLOOR)

View file

@ -1680,7 +1680,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
// Draw sprites
auto peekActor = Player[screenpeek].Actor();
for (i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
SWSectIterator it(i);
while (auto actor = it.Next())

View file

@ -917,17 +917,17 @@ void CollectPortals()
testnewrenderer = true;
TArray<PortalGroup> floorportals;
TArray<PortalGroup> ceilingportals;
BitArray floordone(numsectors), ceilingdone(numsectors);
BitArray floordone(sector.Size()), ceilingdone(sector.Size());
for (int i = 0; i < numsectors; i++)
for (auto& sec : sector)
{
sector[i].portalflags = sector[i].portalnum = 0;
sec.portalflags = sec.portalnum = 0;
}
floordone.Zero();
ceilingdone.Zero();
portalClear();
for (int i = 0; i < numsectors; i++)
for (unsigned i = 0; i < sector.Size(); i++)
{
if (sector[i].floorpicnum == FAF_MIRROR_PIC && !floordone[i])
{