diff --git a/src/deh_soc.c b/src/deh_soc.c index 150d954dd..0352fc710 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -1079,11 +1079,6 @@ void readlevelheader(MYFILE *f, char * name) const INT32 num = G_MapNumber(name); - if (num >= NUMMAPS) - { - I_Error("Too many maps!"); - } - if (num >= nummapheaders) { P_AllocMapHeader((INT16)(num)); diff --git a/src/doomdata.h b/src/doomdata.h index a8a0e387e..f08e61e6a 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -289,8 +289,6 @@ struct mapthing_t #define ZSHIFT 4 -#define NUMMAPS 1035 - /* slope thing types */ enum { diff --git a/src/doomstat.h b/src/doomstat.h index b43acf77b..ad12065b1 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -453,8 +453,8 @@ struct mapheader_t #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,basenummapheaders; +extern mapheader_t** mapheaderinfo; +extern INT32 nummapheaders, basenummapheaders, mapallocsize; #define MAXMAPLUMPNAME 64 // includes \0, for cleaner savedata diff --git a/src/g_game.c b/src/g_game.c index 05ed3af40..b7f1e7613 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -182,8 +182,8 @@ UINT8 skipstats; struct quake quake; // Map Header Information -mapheader_t* mapheaderinfo[NUMMAPS] = {NULL}; -INT32 nummapheaders = 0; +mapheader_t** mapheaderinfo = {NULL}; +INT32 nummapheaders, mapallocsize = 0; INT32 basenummapheaders = 0; // Kart cup definitions diff --git a/src/p_setup.c b/src/p_setup.c index bdfc513d5..348ceb675 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -462,9 +462,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;