Cache emote patches as they are used to prevent excess calls to W_CachePatchName
This commit is contained in:
parent
d1510cc682
commit
bbcf2bb6f9
2 changed files with 45 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "m_emotes.h"
|
||||
#include "i_time.h" // I_GetTime
|
||||
|
|
@ -20,6 +21,8 @@ static void Command_ListEmotes_f(void);
|
|||
|
||||
static std::map<std::string, emote_t> emotes;
|
||||
|
||||
static std::vector<emotecache_t> emotecache;
|
||||
|
||||
// TODO - Would be really nice to generalize soc-like file parsing and not reimplement it 100 times :)))))
|
||||
void M_LoadEmotes(UINT16 wadnum)
|
||||
{
|
||||
|
|
@ -243,13 +246,48 @@ 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];
|
||||
patch_t *emotepatch = (patch_t*)W_CachePatchName(lumpname, PU_CACHE);
|
||||
// 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 int CHARHEIGHT = 6;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ typedef struct emote_s {
|
|||
tic_t timeperframe;
|
||||
} 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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue