From 732b3fb308fac7ca5b1c1b5bdc228213c0945b33 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 4 Dec 2025 10:36:37 -0500 Subject: [PATCH] Cache emotes on registration rather then at runtime --- src/m_emotes.cpp | 55 ++++++++++++++---------------------------------- src/m_emotes.h | 7 +----- 2 files changed, 17 insertions(+), 45 deletions(-) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 1944eba42..ab4c02f5b 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -21,8 +21,6 @@ static void Command_ListEmotes_f(void); static std::map emotes; -static std::vector emotecache; - // TODO - Would be really nice to generalize soc-like file parsing and not reimplement it 100 times :))))) void M_LoadEmotes(UINT16 wadnum) { @@ -169,6 +167,13 @@ void M_LoadEmotes(UINT16 wadnum) { CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)\n", field.c_str(), wadfiles[wadnum]->filename, linenum); } + + // Cache frames for speedy use later. + for (size_t i = 0; i < MAXEMOTEFRAMES; i++) + { + emote->frames_cached[i] = (patch_t *)W_CachePatchName(emote->frames[i], PU_CACHE); + } + } else { @@ -246,48 +251,20 @@ emote_t *M_VerifyEmote(const char *name, int *emotelen) return match; } -static patch_t *M_ReturnEmotePatch(const char *lumpname) -{ - UINT32 hash = HASH32(lumpname, 8); - emotecache_t cache; - - if (emotecache.empty()) - { - cache = {lumpname, hash, (patch_t*)W_CachePatchName(lumpname, PU_CACHE)}; - - emotecache.push_back(cache); - return emotecache.back().patch; - } - else - { - size_t i; - - for (i = 0; i < emotecache.size(); i++) - { - if (emotecache[i].hash != hash) - continue; - if (stricmp(emotecache[i].name, lumpname)) - continue; - - return emotecache[i].patch; - } - - cache = {lumpname, hash, (patch_t*)W_CachePatchName(lumpname, PU_CACHE)}; - - emotecache.push_back(cache); - return emotecache.back().patch; - } -} - void M_DrawScaledEmote(fixed_t x, fixed_t y, fixed_t scale, emote_t *emote, INT32 flags) { if (emote->numframes == 0) return; - const char *lumpname = emote->frames[(I_GetTime()/emote->timeperframe) % emote->numframes]; - // Cache this emote patch after grabbing it for the first time - // so packed addon lists don't get their frames nuked by cachenum calls... - patch_t *emotepatch = M_ReturnEmotePatch(lumpname); + //const char *lumpname = emote->frames[(I_GetTime()/emote->timeperframe) % emote->numframes]; + INT32 emoteframe = (I_GetTime()/emote->timeperframe) % emote->numframes; + patch_t *emotepatch = emote->frames_cached[emoteframe]; + + if (!emotepatch) + { + CONS_Printf("Emote Patch is NULL?\n"); + return; + } const int CHARHEIGHT = 6; diff --git a/src/m_emotes.h b/src/m_emotes.h index 6c4959247..3d09b2fea 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -20,14 +20,9 @@ typedef struct emote_s { char frames[MAXEMOTEFRAMES][9]; UINT8 numframes; tic_t timeperframe; + patch_t *frames_cached[MAXEMOTEFRAMES]; } emote_t; -typedef struct emotecache_s { - const char *name; - UINT32 hash; - patch_t *patch; -} emotecache_t; - // Reads and adds emotes from EMOTES lump, with syntax similar to soc void M_LoadEmotes(UINT16 wadnum);