From 574cc6049ff0e005b67319294b1cbd68336470bd Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 21 Sep 2022 23:01:58 +0100 Subject: [PATCH] NUMMAPS is dead Dynamically allocated mapheaderinfo. 1035 reserved slots in a google doc is a thing of the past --- src/deh_soc.c | 5 ----- src/doomdata.h | 2 -- src/doomstat.h | 4 ++-- src/g_game.c | 4 ++-- src/p_setup.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 3e9855256..030b7f644 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -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 diff --git a/src/doomdata.h b/src/doomdata.h index b891bc8a4..dbe7c1f84 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -218,8 +218,6 @@ typedef struct #define ZSHIFT 4 -#define NUMMAPS 1035 - /* slope thing types */ enum { diff --git a/src/doomstat.h b/src/doomstat.h index a9d82419b..807aec2d6 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -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. diff --git a/src/g_game.c b/src/g_game.c index 7a3e90676..21e30df41 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -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; diff --git a/src/p_setup.c b/src/p_setup.c index a74d9c137..ae3ca64b2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -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;