- got rid of the MAX... constants and adjusted all places still using them.

This commit is contained in:
Christoph Oelckers 2021-12-06 20:54:21 +01:00
parent 1a3b9f8ac0
commit b8c4354691
15 changed files with 41 additions and 56 deletions

View file

@ -38,19 +38,15 @@ typedef int64_t coord_t;
enum
{
MAXSECTORS = 4096,
MAXWALLS = 16384,
MAXSPRITES = 16384,
MAXVOXMIPS = 5,
MAXWALLSB = ((MAXWALLS >> 2) + (MAXWALLS >> 3)),
MAXWALLSB = 6144,
MAXVOXELS = 1024,
MAXSTATUS = 1024,
// Maximum number of component tiles in a multi-psky:
MAXPSKYTILES = 16,
MAXSPRITESONSCREEN = MAXSPRITES >> 2,
MAXSPRITESONSCREEN = 4096,
MAXUNIQHUDID = 256, //Extra slots so HUD models can store animation state without messing game sprites
TSPR_TEMP = 99,
@ -274,6 +270,7 @@ void insertAllSprites(SpawnSpriteDef& sprites);
void allocateMapArrays(int numsprites);
void ValidateSprite(spritetype& spr, int secno, int index);
void fixSectors();
void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int *dacursectnum, SpawnSpriteDef& sprites);
void loadMapBackup(const char* filename);
void G_LoadMapHack(const char* filename, const unsigned char*, SpawnSpriteDef& sprites);

View file

@ -34,8 +34,6 @@ int32_t animateoffs(int tilenum, int fakevar);
inline int32_t bad_tspr(tspriteptr_t tspr)
{
// NOTE: tspr->owner >= MAXSPRITES (could be model) has to be handled by
// caller.
return (tspr->ownerActor == nullptr || (unsigned)tspr->picnum >= MAXTILES);
}

View file

@ -105,7 +105,7 @@ static int32_t LoadMapHack(const char *filename, SpawnSpriteDef& sprites)
if (sc.CheckNumber())
{
currentsprite = sc.Number;
if (currentsprite < 0 || currentsprite >= MAXSPRITES)
if ((unsigned)currentsprite >= sprites.sprites.Size())
{
sc.ScriptMessage("Invalid sprite number %d", currentsprite);
currentsprite = -1;

View file

@ -385,6 +385,22 @@ void allocateMapArrays(int numsprites)
ClearAutomap();
}
void fixSectors()
{
for(auto& sect : sectors())
{
// Fix maps which do not set their wallptr to the first wall of the sector. Lo Wang In Time's map 11 is such a case.
auto wp = sect.firstWall();
// Note: we do not have the 'sector' index initialized here, it would not be helpful anyway for this fix.
while (wp != wall.Data() && wp[-1].twoSided() && wp[-1].nextWall()->nextWall() == &wp[-1] && wp[-1].nextWall()->nextSector() == &sect)
{
sect.wallptr--;
sect.wallnum++;
wp--;
}
}
}
void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites)
{
inputState.ClearAllInput();
@ -411,7 +427,6 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang,
auto wallpos = fr.Tell();
fr.Seek((mapversion == 5 ? wallsize5 : mapversion == 6 ? wallsize6 : wallsize7)* numwalls, FileReader::SeekCur);
int numsprites = fr.ReadUInt16();
if ((unsigned)numsprites > MAXSPRITES) I_Error("%s: Invalid map, too many sprites", filename);
auto spritepos = fr.Tell();
// Now that we know the map's size, set up the globals.
@ -464,6 +479,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang,
artSetupMapArt(filename);
//Must be last.
fixSectors();
updatesector(pos->x, pos->y, cursectnum);
guniqhudid = 0;
fr.Seek(0, FileReader::SeekSet);

View file

@ -42,9 +42,9 @@
#include "hw_sections.h"
SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)];
TArray<SectionLine> sectionLines;
TArray<Section> Sections;
TArray<int> sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap
TArray<TArray<int>> sectionspersector; // reverse map, mainly for the automap
int numsectionlines;
void hw_SplitSector(int sector, int startpos, int endpos);
@ -55,16 +55,11 @@ TArray<int> splits;
void hw_BuildSections()
{
Sections.Resize(numsectors);
sectionspersector.Resize(numsectors);
sectionLines.Resize(numwalls * 5 / 4); // cannot reallocate, unfortunately.
numsectionlines = numwalls;
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.
int wp = sector[i].wallptr;
while (wp > 0 && wall[wp - 1].nextwall >= 0 && wall[wp - 1].nextWall()->nextsector == i)
{
sector[i].wallptr--;
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;

View file

@ -21,10 +21,9 @@ 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 TArray<SectionLine> sectionLines;
extern TArray<Section> Sections;
extern TArray<int> sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap
extern int numsectionlines;
extern TArray<TArray<int>> sectionspersector; // reverse map, mainly for the automap
void hw_BuildSections();

View file

@ -74,8 +74,8 @@ void BunchDrawer::Init(HWDrawInfo *_di, Clipper* c, vec2_t& view, binangle a1, b
// Precalculate the clip angles to avoid doing this repeatedly during level traversal.
wall[i].clipangle = clipper->PointToAngle(wall[i].pos);
}
memset(sectionstartang, -1, sizeof(sectionstartang));
memset(sectionendang, -1, sizeof(sectionendang));
memset(sectionstartang.Data(), -1, sectionstartang.Size() * sizeof(sectionstartang[0]));
memset(sectionendang.Data(), -1, sectionendang.Size() * sizeof(sectionendang[0]));
gotwall.Resize(numwalls);
blockwall.Resize(numwalls);
}
@ -94,8 +94,11 @@ void BunchDrawer::StartScene()
CompareData.Clear();
gotsector.Resize(numsectors);
gotsector.Zero();
gotsection2.Resize(Sections.Size());
gotsection2.Zero();
gotwall.Zero();
sectionstartang.Resize(Sections.Size());
sectionendang.Resize(Sections.Size());
blockwall.Zero();
}

View file

@ -28,12 +28,12 @@ class BunchDrawer
vec2_t iview;
float gcosang, gsinang;
BitArray gotsector;
FixedBitArray<MAXSECTORS*5/4> gotsection2;
BitArray gotsection2;
BitArray gotwall;
BitArray blockwall;
binangle ang1, ang2, angrange;
int sectionstartang[MAXSECTORS*5/4], sectionendang[MAXSECTORS*5/4];
TArray<int> sectionstartang, sectionendang;
private:

View file

@ -67,7 +67,7 @@ void eelBiteSeqCallback(int, DBloodActor* actor)
/*
* workaround for
* pXSprite->target >= 0 && pXSprite->target < kMaxSprites in file NBlood/source/blood/src/aiboneel.cpp at line 86
* pXSprite->target >= 0 in file NBlood/source/blood/src/aiboneel.cpp at line 86
* The value of pXSprite->target is -1.
* copied from lines 177:181
* resolves this case, but may cause other issues?

View file

@ -111,12 +111,12 @@ public:
void SetSpecialOwner() // nnext hackery
{
ownerActor = nullptr;
s().owner = kMaxSprites - 1;
s().owner = kMagicOwner;
}
bool GetSpecialOwner()
{
return ownerActor == nullptr && (s().owner == kMaxSprites - 1);
return ownerActor == nullptr && (s().owner == kMagicOwner);
}
bool IsPlayerActor()

View file

@ -36,7 +36,7 @@ void QuitGame(void);
enum
{
kMaxSprites = MAXSPRITES,
kMagicOwner = 16383,
kMaxTiles = MAXTILES,
kMaxStatus = MAXSTATUS,

View file

@ -645,6 +645,8 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
#endif
}
}
fixSectors();
unsigned int nCRC = fr.ReadUInt32();
fr.Seek(0, FileReader::SeekSet);

View file

@ -100,21 +100,6 @@ struct BloodSpawnSpriteDef : public SpawnSpriteDef
TArray<XSPRITE> xspr;
};
#ifdef POLYMER
#pragma pack(push, 1)
struct PolymerLight_t {
int16_t lightId, lightmaxrange;
_prlight* lightptr;
uint8_t lightcount;
};
#pragma pack(pop)
extern PolymerLight_t gPolymerLight[kMaxSprites];
void DeleteLight(int32_t s);
#endif
DBloodActor* InsertSprite(sectortype* pSector, int nStat);
int DeleteSprite(DBloodActor* actor);

View file

@ -25,7 +25,6 @@ BEGIN_PS_NS
enum
{
kStatIgnited = 404,
kMaxSprites = 4096,
kMaxVoxels = 4096,
kMaxPalookups = 256,
kMaxStatus = 1024,

View file

@ -58,7 +58,6 @@ ParentalStruct aVoxelArray[MAXTILES];
static char* script_p, * scriptend_p;
static char token[MAXTOKEN];
static int grabbed;
static int scriptline;
static bool endofscript;
static bool tokenready; // only true if UnGetToken was just called
@ -196,13 +195,9 @@ void LoadKVXFromScript(const char* filename)
int lNumber = 0, lTile = 0; // lNumber is the voxel no. and lTile is the editart tile being
// replaced.
int grabbed = 0; // Number of lines parsed
// zero out the array memory with -1's for pics not being voxelized
memset(&aVoxelArray[0], -1, sizeof(struct TILE_INFO_TYPE) * MAXTILES);
grabbed = 0;
// Load the file
auto buffer = LoadScriptFile(filename);
if (!buffer.Size())
@ -235,10 +230,6 @@ void LoadKVXFromScript(const char* filename)
if (lNumber >= nextvoxid) // JBF: so voxels in the def file append to the list
nextvoxid = lNumber + 1;
grabbed++;
ASSERT(grabbed < MAXSPRITES);
}
while (script_p < scriptend_p);