NUMMAPS is dead

Dynamically allocated mapheaderinfo. 1035 reserved slots in a google doc is a thing of the past
This commit is contained in:
toaster 2022-09-21 23:01:58 +01:00
parent a12a29e1e5
commit 574cc6049f
5 changed files with 38 additions and 11 deletions

View file

@ -1095,11 +1095,6 @@ void readlevelheader(MYFILE *f, char * name)
const INT32 num = G_MapNumber(name);
if (num >= NUMMAPS)
{
I_Error("Too many maps!");
}
if (f->wad > mainwads && num < nummapheaders)
{
// only mark as a major mod if it replaces an already-existing mapheaderinfo

View file

@ -218,8 +218,6 @@ typedef struct
#define ZSHIFT 4
#define NUMMAPS 1035
/* slope thing types */
enum
{

View file

@ -440,8 +440,8 @@ typedef struct
#define LF2_NOTIMEATTACK (1<<2) ///< Hide this map in Time Attack modes
#define LF2_VISITNEEDED (1<<3) ///< Not available in Time Attack modes until you visit the level
extern mapheader_t* mapheaderinfo[NUMMAPS];
extern INT32 nummapheaders;
extern mapheader_t** mapheaderinfo;
extern INT32 nummapheaders, mapallocsize;
// This could support more, but is that a good idea?
// Keep in mind that it may encourage people making overly long cups just because they "can", and would be a waste of memory.

View file

@ -192,8 +192,8 @@ mapthing_t *bflagpoint;
struct quake quake;
// Map Header Information
mapheader_t* mapheaderinfo[NUMMAPS] = {NULL};
INT32 nummapheaders;
mapheader_t** mapheaderinfo = {NULL};
INT32 nummapheaders, mapallocsize = 0;
// Kart cup definitions
cupheader_t *kartcupheaders = NULL;

View file

@ -422,9 +422,43 @@ static void P_ClearSingleMapHeaderInfo(INT16 i)
*/
void P_AllocMapHeader(INT16 i)
{
if (i > nummapheaders)
I_Error("P_AllocMapHeader: Called on %d, should be %d", i, nummapheaders);
if (i >= NEXTMAP_SPECIAL)
{
I_Error("P_AllocMapHeader: Too many maps!");
}
if (i >= mapallocsize)
{
if (!mapallocsize)
{
mapallocsize = 16;
}
else
{
mapallocsize *= 2;
}
mapheaderinfo = Z_ReallocAlign(
(void*) mapheaderinfo,
sizeof(mapheader_t*) * mapallocsize,
PU_STATIC,
NULL,
sizeof(mapheader_t*) * 8
);
if (!mapheaderinfo)
I_Error("P_AllocMapHeader: Not enough memory to realloc mapheaderinfo (size %d)", mapallocsize);
}
if (!mapheaderinfo[i])
{
mapheaderinfo[i] = Z_Malloc(sizeof(mapheader_t), PU_STATIC, NULL);
if (!mapheaderinfo[i])
I_Error("P_AllocMapHeader: Not enough memory to allocate new mapheader");
mapheaderinfo[i]->lumpnum = LUMPERROR;
mapheaderinfo[i]->lumpname = NULL;
mapheaderinfo[i]->thumbnailPic = NULL;