From 8012d006845119e37e4342b4fcb300310671ab05 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 17 Dec 2021 01:06:38 -0800 Subject: [PATCH] Add HU_UpdatePatch, recaches patch only if it exists in pwad --- src/hu_stuff.c | 38 +++++++++++++++++++++++++++++++++----- src/hu_stuff.h | 3 ++- src/p_setup.c | 6 ++++++ src/p_setup.h | 2 ++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 7afc7d531..e9b3d4c41 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -302,19 +302,47 @@ void HU_Init(void) HU_LoadGraphics(); } -patch_t *HU_CachePatch(const char *format, ...) +patch_t *HU_UpdatePatch(patch_t **user, const char *format, ...) { va_list ap; char buffer[9]; + lumpnum_t lump; + patch_t *patch; + va_start (ap, format); - vsprintf(buffer, format, ap); + vsnprintf(buffer, sizeof buffer, format, ap); va_end (ap); - if (W_CheckNumForName(buffer) == LUMPERROR) - return NULL; + if (user && p_adding_file != INT16_MAX) + { + lump = W_CheckNumForNamePwad(buffer, p_adding_file, 0); + + /* no update in this wad */ + if (lump == INT16_MAX) + return *user; + + lump |= (p_adding_file << 16); + } else - return (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + { + lump = W_CheckNumForName(buffer); + + if (lump == LUMPERROR) + return NULL; + } + + patch = W_CachePatchNum(lump, PU_HUDGFX); + + if (user) + { + if (*user) + Patch_Free(*user); + + *user = patch; + } + + return patch; } static inline void HU_Stop(void) diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 4d686516e..a8d8bee22 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -123,7 +123,8 @@ void HU_Init(void); void HU_LoadGraphics(void); // Load a HUDGFX patch or NULL. -patch_t *HU_CachePatch(const char *format, ...); +patch_t *HU_UpdatePatch(patch_t **user, const char *format, ...); +#define HU_CachePatch(...) HU_UpdatePatch(NULL, __VA_ARGS__) // reset heads up when consoleplayer respawns. void HU_Start(void); diff --git a/src/p_setup.c b/src/p_setup.c index e36c20a0a..62cb26d81 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4319,6 +4319,8 @@ static lumpinfo_t* FindFolder(const char *folName, UINT16 *start, UINT16 *end, l return lumpinfo; } +UINT16 p_adding_file = INT16_MAX; + // // Add a wadfile to the active wad files, // replace sounds, musics, patches, textures, sprites and maps @@ -4356,6 +4358,8 @@ boolean P_AddWadFile(const char *wadfilename) else wadnum = (UINT16)(numwadfiles-1); + p_adding_file = wadnum; + switch(wadfiles[wadnum]->type) { case RET_PK3: @@ -4538,5 +4542,7 @@ boolean P_AddWadFile(const char *wadfilename) refreshdirmenu &= ~REFRESHDIR_GAMEDATA; // Under usual circumstances we'd wait for REFRESHDIR_GAMEDATA to disappear the next frame, but it's a bit too dangerous for that... + p_adding_file = INT16_MAX; + return true; } diff --git a/src/p_setup.h b/src/p_setup.h index 0a7587ec0..cbb697b0e 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -93,6 +93,8 @@ INT32 P_CheckLevelFlat(const char *flatname); extern size_t nummapthings; extern mapthing_t *mapthings; +extern UINT16 p_adding_file; + void P_SetupLevelSky(const char *skytexname, boolean global); #ifdef SCANTHINGS void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum);