w_wad: replace lumpnumcache with unordered_map hash lookup

Holy shit, thanks Alug!!!!

This is a major performance boost with a large amount of lumps loaded compared to the barely functional lumpnumcache that was there before.
This commit is contained in:
NepDisk 2025-12-04 15:08:20 -05:00
parent 204d476b3e
commit a9cbaae799
2 changed files with 90 additions and 101 deletions

View file

@ -94,7 +94,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
v_video.c
s_sound.c
sounds.c
w_wad.c
w_wad.cpp
filesrch.c
mserv.c
http-mserv.c

View file

@ -87,18 +87,33 @@ typedef struct
} lumpchecklist_t;
// Must be a power of two
#define LUMPNUMCACHESIZE 64
#define LUMPNUMCACHESIZE 2048 // should be reasonable ig
#define LUMPNUMCACHENAME 32
typedef struct lumpnum_cache_s
{
char lumpname[32];
UINT32 lumphash;
lumpnum_t lumpnum;
} lumpnum_cache_t;
#include <unordered_map>
#include <string>
#include <cstring>
struct LumpnumNameHash
{
std::size_t operator()(const std::string& str) const
{
// hopefully this is fast enough but should be
return static_cast<std::size_t>(HASH32(str.c_str(), str.length()));
}
};
struct LumpnumStringEquals
{
bool operator()(const std::string& str1, const std::string& str2) const
{
// fasticmp should be plenty fast and ignores case
return fasticmp(str1.c_str(), str2.c_str());
}
};
static std::unordered_map<std::string, lumpnum_t, LumpnumNameHash, LumpnumStringEquals> lumpnumcache(LUMPNUMCACHESIZE);
static lumpnum_cache_t lumpnumcache[LUMPNUMCACHESIZE];
static UINT16 lumpnumcacheindex = 0;
//===========================================================================
// GLOBALS
@ -258,7 +273,7 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum, boolean mainfile)
{
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = malloc(length + 1);
char *name = (char *)malloc(length + 1);
if (!name)
I_Error("W_LoadDehackedLumpsPK3: Out of memory!\n");
@ -291,7 +306,7 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile)
if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = malloc(length + 1);
char *name = (char *)malloc(length + 1);
if (!name)
I_Error("W_LoadDehackedLumps: Out of memory!\n");
@ -319,13 +334,13 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile)
static inline boolean CheckCompatFilename(const char *filename)
{
// check for a K prefix
char *basename = strrchr(filename, *PATHSEP);
char *basename = (char *)strrchr(filename, *PATHSEP);
return (toupper(basename ? basename[1] : filename[0]) == 'K');
}
static inline boolean CheckCompatExtension(const char *filename)
{
char *basename = strrchr(filename, '.');
char *basename = (char *)strrchr(filename, '.');
if (!stricmp(basename+1, "KART"))
return true;
@ -435,7 +450,7 @@ boolean W_MakeFileHash(const char *filename, boolean openwad, UINT64 *ret)
// Invalidates the cache of lump numbers. Call this whenever a wad is added.
static void W_InvalidateLumpnumCache(void)
{
memset(lumpnumcache, 0, sizeof (lumpnumcache));
lumpnumcache.clear();
}
UINT32 W_HashLumpName(const char *name, size_t len)
@ -465,7 +480,7 @@ static restype_t ResourceFileDetect (const char* filename)
*/
static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const char* lumpname)
{
lumpinfo_t* lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL);
lumpinfo_t* lumpinfo = (lumpinfo_t *)Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL);
lumpinfo->position = 0;
fseek(handle, 0, SEEK_END);
lumpinfo->size = ftell(handle);
@ -475,14 +490,14 @@ static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const
lumpinfo->hash.name = W_HashLumpName(lumpname, lumpinfo->namelength);
// Allocate the lump's long name.
lumpinfo->longname = Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
lumpinfo->longname = (char *)Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->longname, lumpname);
lumpinfo->longname[lumpinfo->namelength] = '\0';
lumpinfo->longnamelength = lumpinfo->namelength;
lumpinfo->hash.longname = lumpinfo->hash.name;
// Allocate the lump's full name.
lumpinfo->fullname = Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
lumpinfo->fullname = (char *)Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->fullname, lumpname);
lumpinfo->fullname[lumpinfo->namelength] = '\0';
lumpinfo->fullnamelength = lumpinfo->namelength;
@ -528,7 +543,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
// read wad file directory
i = header.numlumps * sizeof (*fileinfo);
fileinfov = fileinfo = malloc(i);
fileinfov = fileinfo = (filelump_t *)malloc(i);
if (fseek(handle, header.infotableofs, SEEK_SET) == -1
|| fread(fileinfo, 1, i, handle) < i)
{
@ -540,7 +555,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
numlumps = header.numlumps;
// fill in lumpinfo for this wad
lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
lump_p = lumpinfo = (lumpinfo_t *)Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
for (i = 0; i < numlumps; i++, lump_p++, fileinfo++)
{
lump_p->position = LONG(fileinfo->filepos);
@ -621,7 +636,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
namelen = strlen(trimname);
// Allocate the lump's long and full name (save on memory).
lump_p->longname = lump_p->fullname = Z_Calloc(namelen * sizeof(char), PU_STATIC, NULL);
lump_p->longname = lump_p->fullname = (char *)Z_Calloc(namelen * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->longname, trimname, namelen);
lump_p->longname[namelen-1] = '\0';
@ -629,14 +644,14 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
lump_p->hash.name = W_HashLumpName(lump_p->longname, lump_p->namelength);
// Allocate the lump's long name.
lump_p->longname = Z_Malloc(namelen * sizeof(char), PU_STATIC, NULL);
lump_p->longname = (char *)Z_Malloc(namelen * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->longname, fileinfo->name, 8);
lump_p->longname[namelen-1] = '\0';
lump_p->longnamelength = lump_p->namelength;
lump_p->hash.longname = lump_p->hash.name;
// Allocate the lump's full name.
lump_p->fullname = Z_Malloc(namelen * sizeof(char), PU_STATIC, NULL);
lump_p->fullname =(char *) Z_Malloc(namelen * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->fullname, fileinfo->name, 8);
lump_p->fullname[namelen-1] = '\0';
lump_p->fullnamelength = lump_p->namelength;
@ -652,14 +667,14 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
lump_p->hash.name = W_HashLumpName(lump_p->name, lump_p->namelength);
// Allocate the lump's long name.
lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
lump_p->longname = (char *)Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->longname, fileinfo->name, 8);
lump_p->longname[8] = '\0';
lump_p->longnamelength = lump_p->namelength;
lump_p->hash.longname = lump_p->hash.name;
// Allocate the lump's full name.
lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
lump_p->fullname = (char *)Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->fullname, fileinfo->name, 8);
lump_p->fullname[8] = '\0';
lump_p->fullnamelength = lump_p->namelength;
@ -763,7 +778,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
// Look for central directory end signature near end of file.
// Contains entry number (number of lumps), and central directory start offset.
fseek(handle, 0, SEEK_END);
if (!ResFindSignature(handle, pat_end, max(0, ftell(handle) - (22 + 65536))))
if (!ResFindSignature(handle, pat_end, std::max<long>(0, ftell(handle) - (22 + 65536))))
{
CONS_Alert(CONS_ERROR, "Missing central directory\n");
return NULL;
@ -777,7 +792,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
}
numlumps = zend.entries;
lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
lump_p = lumpinfo = (lumpinfo_t *)Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
fseek(handle, zend.cdiroffset, SEEK_SET);
for (i = 0; i < numlumps; i++, lump_p++)
@ -803,7 +818,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
lump_p->disksize = zentry.compsize;
lump_p->size = zentry.size;
fullname = malloc(zentry.namelen + 1);
fullname = (char *)malloc(zentry.namelen + 1);
if (fgets(fullname, zentry.namelen + 1, handle) != fullname)
{
CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle));
@ -822,16 +837,16 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
dotpos = fullname + strlen(fullname); // Watch for files without extension.
memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary?
strncpy(lump_p->name, trimname, min(8, dotpos - trimname));
strncpy(lump_p->name, trimname, std::min<size_t>(8, dotpos - trimname));
lump_p->namelength = strlen(lump_p->name);
lump_p->hash.name = W_HashLumpName(lump_p->name, lump_p->namelength);
lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL);
lump_p->longname = (char *)Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL);
strlcpy(lump_p->longname, trimname, dotpos - trimname + 1);
lump_p->longnamelength = strlen(lump_p->longname);
lump_p->hash.longname = W_HashLumpName(lump_p->longname, lump_p->longnamelength);
lump_p->fullname = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL);
lump_p->fullname = (char *)Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL);
strncpy(lump_p->fullname, fullname, zentry.namelen);
lump_p->fullnamelength = zentry.namelen;
lump_p->hash.fullname = W_HashLumpName(lump_p->fullname, lump_p->fullnamelength);
@ -1017,7 +1032,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, boole
//
// link wad file to search files
//
wadfile = Z_Malloc(sizeof (*wadfile), PU_STATIC, NULL);
wadfile = (wadfile_t *)Z_Malloc(sizeof (*wadfile), PU_STATIC, NULL);
wadfile->filename = Z_StrDup(filename);
wadfile->type = type;
wadfile->handle = handle;
@ -1297,7 +1312,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
continue;
if (lump_p->hash.name != hash)
continue;
if (strncasecmp(lump_p->name, name, strlen(name)))
if (strncasecmp(lump_p->name, name, sizeof(name) - 1))
continue;
return i;
}
@ -1418,7 +1433,6 @@ UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump)
lumpnum_t W_CheckNumForName(const char *name)
{
INT32 i;
UINT32 hash = name ? quickncasehash(name, 8) : 0;
lumpnum_t check = INT16_MAX;
if (name == NULL)
@ -1429,16 +1443,9 @@ lumpnum_t W_CheckNumForName(const char *name)
// Check the lumpnumcache first. Loop backwards so that we check
// most recent entries first
for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{
if (!lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname[8]
&& lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash
&& strncasecmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0)
{
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum;
}
}
auto it = lumpnumcache.find(name);
if (it != lumpnumcache.end())
return it->second;
// scan wad files backwards so patch lump files take precedence
for (i = numwadfiles - 1; i >= 0; i--)
@ -1452,12 +1459,9 @@ lumpnum_t W_CheckNumForName(const char *name)
else
{
// Update the cache.
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', 32);
strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
return lumpnumcache[lumpnumcacheindex].lumpnum;
lumpnum_t lumpnum = (i << 16) | check;
lumpnumcache.insert({name, lumpnum});
return lumpnum;
}
}
@ -1470,7 +1474,6 @@ lumpnum_t W_CheckNumForName(const char *name)
lumpnum_t W_CheckNumForLongName(const char *name)
{
INT32 i;
UINT32 hash = name ? quickncasehash(name, 8) : 0;
lumpnum_t check = INT16_MAX;
if (name == NULL)
@ -1481,14 +1484,10 @@ lumpnum_t W_CheckNumForLongName(const char *name)
// Check the lumpnumcache first. Loop backwards so that we check
// most recent entries first
for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{
if (strcasecmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0)
{
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum;
}
}
auto it = lumpnumcache.find(name);
if (it != lumpnumcache.end())
return it->second;
// scan wad files backwards so patch lump files take precedence
for (i = numwadfiles - 1; i >= 0; i--)
@ -1504,11 +1503,9 @@ lumpnum_t W_CheckNumForLongName(const char *name)
if (strlen(name) < 32)
{
// Update the cache.
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', 32);
strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 32);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
lumpnumcache[lumpnumcacheindex].lumphash = hash;
lumpnum_t lumpnum = (i << 16) | check;
lumpnumcache.insert({name, lumpnum});
return lumpnum;
}
return (i << 16) | check;
@ -1520,21 +1517,15 @@ lumpnum_t W_CheckNumForLongName(const char *name)
lumpnum_t W_CheckNumForMap(const char *name, boolean checktofirst)
{
lumpnum_t check = INT16_MAX;
UINT32 uhash, hash = quickncasehash(name, LUMPNUMCACHENAME);
UINT32 uhash;
INT32 i;
UINT16 firstfile = (checktofirst || (partadd_earliestfile == UINT16_MAX)) ? 0 : partadd_earliestfile;
// Check the lumpnumcache first. Loop backwards so that we check
// most recent entries first
for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{
if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash
&& strcasecmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0)
{
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum;
}
}
auto it = lumpnumcache.find(name);
if (it != lumpnumcache.end())
return it->second;
uhash = W_HashLumpName(name, strlen(name)); // Not a mistake, legacy system for short lumpnames
@ -1555,11 +1546,9 @@ lumpnum_t W_CheckNumForMap(const char *name, boolean checktofirst)
if (strlen(name) < LUMPNUMCACHENAME)
{
// Update the cache.
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME);
strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
lumpnumcache[lumpnumcacheindex].lumphash = hash;
lumpnum_t lumpnum = (i << 16) | check;
lumpnumcache.insert({name, lumpnum});
return lumpnum;
}
return (i << 16) | check;
@ -1840,8 +1829,8 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
char *decData; // Lump's decompressed real data.
size_t retval; // Helper var, lzf_decompress returns 0 when an error occurs.
rawData = Z_Malloc(l->disksize, PU_STATIC, NULL);
decData = Z_Malloc(l->size, PU_STATIC, NULL);
rawData = (char *)Z_Malloc(l->disksize, PU_STATIC, NULL);
decData = (char *)Z_Malloc(l->size, PU_STATIC, NULL);
if (fread(rawData, 1, l->disksize, handle) < l->disksize)
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
@ -1889,8 +1878,8 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
unsigned long rawSize = l->disksize;
unsigned long decSize = size;
rawData = Z_Malloc(rawSize, PU_STATIC, NULL);
decData = dest;
rawData = (UINT8 *)Z_Malloc(rawSize, PU_STATIC, NULL);
decData = (UINT8 *)dest;
if (fread(rawData, 1, rawSize, handle) < rawSize)
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
@ -2104,15 +2093,15 @@ static void *MakePatch(void *lumpdata, size_t size, INT32 tag, void *cache, bool
#ifndef NO_PNG_LUMPS
if (Picture_IsLumpPNG((UINT8 *)lumpdata, len))
ptr = Picture_PNGConvert((UINT8 *)lumpdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, len, &len, 0);
ptr = Picture_PNGConvert((UINT8 *)lumpdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, len, &len, (pictureflags_t)0);
#endif
if (remap)
R_DoPaletteRemapPatch(ptr, len);
R_DoPaletteRemapPatch((softwarepatch_t *)ptr, len);
dest = Z_Calloc(sizeof(patch_t), tag, cache);
Patch_Create(ptr, len, dest);
Patch_Create((softwarepatch_t *)ptr, len, dest);
return dest;
}
@ -2134,7 +2123,7 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
// read the lump in full
W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0);
if (!Picture_IsLumpPNG(lumpdata,len) && !Picture_CheckIfDoomPatch(lumpdata, len))
if (!Picture_IsLumpPNG((UINT8 *)lumpdata, len) && !Picture_CheckIfDoomPatch((softwarepatch_t *)lumpdata, len))
return NULL;
MakePatch(lumpdata, len, tag, &lumpcache[lump], wadfiles[wad]->compatmode);
@ -2158,7 +2147,7 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
if (!TestValidLump(wad, lump))
return NULL;
patch = W_CacheSoftwarePatchNumPwad(wad, lump, tag);
patch = (patch_t *)W_CacheSoftwarePatchNumPwad(wad, lump, tag);
if (!patch)
return NULL;
@ -2246,7 +2235,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
{
INT32 xpivot = 0, ypivot = 0;
ptr = W_CachePatchNum(num, PU_PATCH);
ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH);
// >y pivot centered
// >x pivot not centered
@ -2409,7 +2398,7 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
if (!ResFindSignature(fp, pat_end, max(0, ftell(fp) - (22 + 65536))))
if (!ResFindSignature(fp, pat_end, std::max<long>(0, ftell(fp) - (22 + 65536))))
return true;
fseek(fp, -4, SEEK_CUR);
@ -2434,7 +2423,7 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
if (verified == true)
{
fullname = malloc(zentry.namelen + 1);
fullname = (char *)malloc(zentry.namelen + 1);
if (fgets(fullname, zentry.namelen + 1, fp) != fullname)
return true;
@ -2450,7 +2439,7 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
dotpos = fullname + strlen(fullname); // Watch for files without extension.
memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary?
strncpy(lumpname, trimname, min(8, dotpos - trimname));
strncpy(lumpname, trimname,std::min<size_t>(8, dotpos - trimname));
if (! W_VerifyName(lumpname, checklist, status))
verified = false;
@ -2640,11 +2629,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
size_t *vsizecache;
// Remember that we're assuming that the WAD will have a specific set of lumps in a specific order.
UINT8 *wadData = W_CacheLumpNum(lumpnum, PU_LEVEL);
UINT8 *wadData = (UINT8 *)W_CacheLumpNum(lumpnum, PU_LEVEL);
filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
i = ((wadinfo_t *)wadData)->numlumps;
vsizecache = Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL);
vsizecache = (size_t *)Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL);
for (realentry = 0; realentry < i; realentry++)
{
@ -2656,7 +2645,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
numlumps++;
}
vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
vlumps = (virtlump_t *)Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
// Build the lumps, skipping over empty entries.
for (i = 0, realentry = 0; i < numlumps; realentry++)
@ -2667,7 +2656,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
// Play it safe with the name in this case.
memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8);
vlumps[i].name[8] = '\0';
vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that.
vlumps[i].data = (UINT8 *)Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that.
memcpy(vlumps[i].data, wadData + (fileinfo + realentry)->filepos, vlumps[i].size);
i++;
}
@ -2685,7 +2674,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
{
const char *fullname = W_CheckFullNameForNum(lumpnum);
const char *dirend = strrchr(fullname, '/');
char *dirname = malloc(dirend - fullname + 2);
char *dirname = (char *)malloc(dirend - fullname + 2);
strlcpy(dirname, fullname, dirend - fullname + 2);
lastlump = W_CheckNumForFolderEndPK3(dirname, WADFILENUM(lumpnum), lumpnum);
free(dirname);
@ -2699,16 +2688,16 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
}
numlumps++;
vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
vlumps = (virtlump_t *)Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
for (i = 0; i < numlumps; i++, lumpnum++)
{
vlumps[i].size = W_LumpLength(lumpnum);
memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8);
vlumps[i].name[8] = '\0';
vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL);
vlumps[i].data = (UINT8 *)W_CacheLumpNum(lumpnum, PU_LEVEL);
}
}
vres = Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL);
vres = (virtres_t *)Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL);
vres->vlumps = vlumps;
vres->numlumps = numlumps;
@ -2778,7 +2767,7 @@ void *vres_GetPatch(virtlump_t *vlump, INT32 tag)
if (!vlump)
return NULL;
patch = MakePatch(vlump->data, vlump->size, tag, NULL, false);
patch = (patch_t *)MakePatch(vlump->data, vlump->size, tag, NULL, false);
#ifdef HWRENDER
// Software-only compile cache the data without conversion