From fdefb1829b4fce24cebf7601864935c0ce6f2ab4 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 2 Oct 2024 12:41:34 +0200 Subject: [PATCH] Revert "pre alloc MapName on mapload and unarchive" This reverts commit 1b027e169aafe1f5d5ae2dc08ed555d1e607d2cc. --- src/d_clisrv.c | 4 ++-- src/d_netcmd.c | 10 +++++----- src/discord.c | 2 +- src/doomstat.h | 1 - src/g_game.c | 21 +++++++-------------- src/g_game.h | 2 -- src/lua_hudlib.c | 6 +++--- src/m_cheat.c | 2 +- src/m_misc.c | 6 +++--- src/p_saveg.c | 6 +----- src/p_setup.c | 14 +++++++------- src/p_spec.c | 2 +- src/sdl/i_system.c | 2 +- src/y_inter.c | 2 +- 14 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 832b8659e..f91b15f58 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1454,7 +1454,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) CopyCaretColors(netbuffer->u.serverinfo.servername, cv_servername.string, MAXSERVERNAME); - strncpy(netbuffer->u.serverinfo.mapname, globalmapname, 7); + strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16); @@ -1839,7 +1839,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) { if (!reloading) { - CON_LogMessage(va(M_GetText("Map is now \"%s"), globalmapname)); + CON_LogMessage(va(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap))); if (strlen(mapheaderinfo[gamemap-1]->lvlttl) > 0) { CON_LogMessage(va(": %s", mapheaderinfo[gamemap-1]->lvlttl)); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 256cf5a85..96de8ed95 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5010,16 +5010,16 @@ static void Command_Showmap_f(void) if (mapheaderinfo[gamemap-1]->zonttl[0] && !(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) { if (mapheaderinfo[gamemap-1]->actnum[0]) - CONS_Printf("%s (%d): %s %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum); + CONS_Printf("%s (%d): %s %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum); else - CONS_Printf("%s (%d): %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl); + CONS_Printf("%s (%d): %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl); } else { if (mapheaderinfo[gamemap-1]->actnum[0]) - CONS_Printf("%s (%d): %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); + CONS_Printf("%s (%d): %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); else - CONS_Printf("%s (%d): %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl); + CONS_Printf("%s (%d): %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl); } } else @@ -5034,7 +5034,7 @@ static void Command_Mapmd5_f(void) char md5tmp[33]; for (i = 0; i < 16; ++i) sprintf(&md5tmp[i*2], "%02x", mapmd5[i]); - CONS_Printf("%s: %s\n", globalmapname, md5tmp); + CONS_Printf("%s: %s\n", G_BuildMapName(gamemap), md5tmp); } else CONS_Printf(M_GetText("You must be in a level to use this.\n")); diff --git a/src/discord.c b/src/discord.c index 6941eac2b..17b8ea836 100644 --- a/src/discord.c +++ b/src/discord.c @@ -547,7 +547,7 @@ void DRPC_UpdatePresence(void) if ((gamemap >= 1 && gamemap <= 60) // supported race maps || (gamemap >= 136 && gamemap <= 164)) // supported battle maps { - snprintf(mapimg, 8, "%s", globalmapname); + snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap)); strlwr(mapimg); discordPresence.largeImageKey = mapimg; // Map image } diff --git a/src/doomstat.h b/src/doomstat.h index 5e6c07f91..f69402f25 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -32,7 +32,6 @@ // Selected by user. extern INT16 gamemap; extern char *maptitle; -extern const char *globalmapname; extern char mapmusname[7]; extern UINT16 mapmusflags; extern UINT32 mapmusposition; diff --git a/src/g_game.c b/src/g_game.c index d2a4cbbb3..465be2dff 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -92,7 +92,6 @@ UINT32 mapmusresume; INT16 gamemap = 1; char *maptitle = NULL; -const char *globalmapname = NULL; INT16 maptol; UINT8 globalweather = 0; INT32 curWeather = PRECIP_NONE; @@ -571,14 +570,6 @@ INT16 rw_maximums[NUM_WEAPONS] = 50 // MAX_RAIL }; -void G_AllocMapTitles(INT16 map) -{ - if (maptitle) - Z_Free(maptitle); - maptitle = G_BuildMapTitle(map); - globalmapname = G_BuildMapName(map); -} - // Allocation for time and nights data void G_AllocMainRecordData(INT16 i) { @@ -4258,7 +4249,9 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool gamemap = (INT16)M_MapNumber(mapname[3], mapname[4]); // get xx out of MAPxx - G_AllocMapTitles(gamemap); + if (maptitle) + Z_Free(maptitle); + maptitle = G_BuildMapTitle(gamemap); // gamemap changed; we assume that its map header is always valid, // so make it so @@ -4285,7 +4278,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool if (netgame) { - CON_LogMessage(va(M_GetText("Map is now \"%s"), globalmapname)); + CON_LogMessage(va(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap))); if (maptitle) CON_LogMessage(va(": %s", maptitle)); CON_LogMessage("\"\n"); @@ -7970,7 +7963,7 @@ void G_DoPlayMetal(void) thinker_t *th; // it's an internal demo - if ((l = W_CheckNumForName(va("%sMS", globalmapname))) == LUMPERROR) + if ((l = W_CheckNumForName(va("%sMS",G_BuildMapName(gamemap)))) == LUMPERROR) { CONS_Alert(CONS_WARNING, M_GetText("No bot recording for this map.\n")); return; @@ -8075,13 +8068,13 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker md5_buffer((char *)p+16, demobuf.p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. #endif - saved = FIL_WriteFile(va("%sMS.LMP", globalmapname), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. + saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. } free(demobuf.buffer); demobuf.buffer = NULL; metalrecording = false; if (saved) - I_Error("Saved to %sMS.LMP", globalmapname); + I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); I_Error("Failed to save demo!"); } diff --git a/src/g_game.h b/src/g_game.h index ad4ce0e88..6f727f9da 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -339,8 +339,6 @@ void G_WriteMetalTic(mobj_t *metal); void G_SaveMetal(UINT8 **buffer); void G_LoadMetal(UINT8 **buffer); -void G_AllocMapTitles(INT16 map); - // Your naming conventions are stupid and useless. // There is no conflict here. typedef struct demoghost { diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 4c7ad808e..0af7f2c36 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -679,10 +679,10 @@ static int libd_drawOnMinimap(lua_State *L) if (stplyr != &players[displayplayers[0]]) return 0; - lumpnum = W_CheckNumForName(va("%sR", globalmapname)); + lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); if (lumpnum != -1) - AutomapPic = W_CachePatchName(va("%sR", globalmapname), PU_HUDGFX); + AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); else return 0; // no pic, just get outta here @@ -1612,4 +1612,4 @@ void LUAh_VoteHUD(huddrawlist_h list) lua_pushlightuserdata(gL, NULL); lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); -} +} \ No newline at end of file diff --git a/src/m_cheat.c b/src/m_cheat.c index 1c6a0f185..22126bd4f 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -1226,7 +1226,7 @@ void Command_Writethings_f(void) REQUIRE_SINGLEPLAYER; REQUIRE_OBJECTPLACE; - P_WriteThings(W_GetNumForName(globalmapname) + ML_THINGS); + P_WriteThings(W_GetNumForName(G_BuildMapName(gamemap)) + ML_THINGS); } void Command_ObjectPlace_f(void) diff --git a/src/m_misc.c b/src/m_misc.c index 604c14e8c..c6e4bca8f 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -793,7 +793,7 @@ static void M_PNGText(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png } if (gamestate == GS_LEVEL) - snprintf(maptext, 8, "%s", globalmapname); + snprintf(maptext, 8, "%s", G_BuildMapName(gamemap)); else snprintf(maptext, 8, "Unknown"); @@ -1616,11 +1616,11 @@ void M_MinimapGenerate(void) return; } - filepath = va("%s" PATHSEP "%s-MINIMAP-%d.png", srb2home, globalmapname, mul); + filepath = va("%s" PATHSEP "%s-MINIMAP-%d.png", srb2home, G_BuildMapName(gamemap), mul); } else { - filepath = va("%s" PATHSEP "%s-MINIMAP.png", srb2home, globalmapname); + filepath = va("%s" PATHSEP "%s-MINIMAP.png", srb2home, G_BuildMapName(gamemap)); } minigen = AM_MinimapGenerate(mul); diff --git a/src/p_saveg.c b/src/p_saveg.c index 39d29c8c4..efb96f75c 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3186,8 +3186,6 @@ static inline void P_UnArchiveSPGame(savebuffer_t *save, INT16 mapoverride) else gamecomplete = false; - G_AllocMapTitles(gamemap); - // gamemap changed; we assume that its map header is always valid, // so make it so if(!mapheaderinfo[gamemap-1]) @@ -3332,8 +3330,6 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool gamemap = READINT16(save->p); - G_AllocMapTitles(gamemap); - // gamemap changed; we assume that its map header is always valid, // so make it so if(!mapheaderinfo[gamemap-1]) @@ -3507,7 +3503,7 @@ boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride) } // Only do this after confirming savegame is ok - G_DeferedInitNew(false, globalmapname, savedata.skin, 0, true); + G_DeferedInitNew(false, G_BuildMapName(gamemap), savedata.skin, 0, true); COM_BufAddText("dummyconsvar 1\n"); // G_DeferedInitNew doesn't do this return true; diff --git a/src/p_setup.c b/src/p_setup.c index d345e9f3b..ab567de22 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2315,7 +2315,7 @@ static void P_LoadRecordGhosts(void) if (!gpath) return; - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, globalmapname); + sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); // Best Time ghost if (cv_ghost_besttime.value) @@ -2365,9 +2365,9 @@ static void P_LoadRecordGhosts(void) { lumpnum_t l; UINT8 j = 1; - while (j <= 99 && (l = W_CheckNumForName(va("%sS%02u", globalmapname, j))) != LUMPERROR) + while (j <= 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(gamemap),j))) != LUMPERROR) { - G_AddGhost(va("%sS%02u", globalmapname, j)); + G_AddGhost(va("%sS%02u",G_BuildMapName(gamemap),j)); j++; } } @@ -2450,10 +2450,10 @@ static void P_InitMinimapInfo(void) fixed_t a; fixed_t b; node_t *bsp = &nodes[numnodes-1]; - lumpnum = W_CheckNumForName(va("%sR", globalmapname)); + lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); if (lumpnum != -1) - minimapinfo.minimap_pic = W_CachePatchName(va("%sR", globalmapname), PU_HUDGFX); + minimapinfo.minimap_pic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); minimapinfo.mapthingcount = 0; // TODO iterate over mapthings to look for possible user-defined bounds @@ -2714,7 +2714,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) } // internal game map - maplumpname = globalmapname; + maplumpname = G_BuildMapName(gamemap); lastloadedmaplumpnum = W_CheckNumForName(maplumpname); if (lastloadedmaplumpnum == INT16_MAX) I_Error("Map %s not found.\n", maplumpname); @@ -2823,7 +2823,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! if (!demo.playback && multiplayer && D_NumPlayers()) { static char buf[256]; - sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), globalmapname); + sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); diff --git a/src/p_spec.c b/src/p_spec.c index 5d5d6593d..61ddd7ebb 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2308,7 +2308,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) lumpnum_t lumpnum; char newname[9]; - strcpy(newname, globalmapname); + strcpy(newname, G_BuildMapName(gamemap)); newname[0] = 'S'; newname[1] = 'C'; newname[2] = 'R'; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index be8c9cf03..b77832260 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -351,7 +351,7 @@ static void write_backtrace(bt_crash_reason_t reason) fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); if (gamestate == GS_LEVEL) - fprintf(out, "Game map: %s\n", globalmapname); + fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); diff --git a/src/y_inter.c b/src/y_inter.c index 38a0b9146..bf6dfe359 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -728,7 +728,7 @@ static void Y_UpdateRecordReplays(void) if ((gpath = malloc(glen)) == NULL) I_Error("Out of memory for replay filepath\n"); - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, globalmapname); + sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); snprintf(lastdemo, 255, "%s-%s-last.lmp", gpath, cv_chooseskin.string); if (FIL_FileExists(lastdemo))