Reapply "Cache start and end locations for WAD folders"

This reverts commit 30d64ad538.
This commit is contained in:
Alug committed 2025-05-27 22:43:53 +02:00
1 parent 6ab1f06452
commit 3c62ff266c
2 files changed
+25

No files matched your search

+21
View File
@@ -125,6 +125,9 @@ void W_Shutdown(void)
Z_Free(wad->lumpinfo[wad->numlumps].longname);
Z_Free(wad->lumpinfo[wad->numlumps].fullname);
}
M_AATreeFree(wad->startfolders);
M_AATreeFree(wad->endfolders);
Z_Free(wad->lumpinfo);
Z_Free(wad);
}
@@ -844,6 +847,8 @@ UINT16 W_InitFile(const char *filename, boolean local)
fseek(handle, 0, SEEK_END);
wadfile->filesize = (unsigned)ftell(handle);
wadfile->type = type;
wadfile->startfolders = M_AATreeAlloc(0);
wadfile->endfolders = M_AATreeAlloc(0);
// already generated, just copy it over
M_Memcpy(&wadfile->md5sum, &md5sum, 16);
@@ -1085,6 +1090,12 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum
INT32 i;
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
name_length = strlen(name);
UINT32 hash = quickncasehash(name, name_length);
void *val = M_AATreeGet(wadfiles[wad]->startfolders, hash);
if (val != NULL)
return (uintptr_t)val;
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{
if (strnicmp(name, lump_p->fullname, name_length) == 0)
@@ -1092,9 +1103,11 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum
/* SLADE is special and puts a single directory entry. Skip that. */
if (strlen(lump_p->fullname) == name_length)
i++;
M_AATreeSet(wadfiles[wad]->startfolders, hash, (void *)(uintptr_t)i);
return i;
}
}
M_AATreeSet(wadfiles[wad]->startfolders, hash, (void *)INT16_MAX);
return INT16_MAX;
}
@@ -1106,11 +1119,19 @@ UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump)
INT32 i;
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
size_t name_length = strlen(name);
UINT32 hash = quickncasehash(name, name_length);
void *val = M_AATreeGet(wadfiles[wad]->endfolders, hash);
if (val != NULL)
return (uintptr_t)val;
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{
if (strnicmp(name, lump_p->fullname, name_length))
break;
}
M_AATreeSet(wadfiles[wad]->endfolders, hash, (void *)(uintptr_t)i);
return i;
}
+4
View File
@@ -18,6 +18,8 @@
#include "hardware/hw_data.h"
#endif
#include "m_aatree.h"
#ifdef __GNUG__
#pragma interface
#endif
@@ -138,6 +140,8 @@ typedef struct wadfile_s
#ifdef ROTSPRITE
lumpcache_t *rotcache; // Cache rotsprites for rotating patches.
#endif
aatree_t *startfolders;
aatree_t *endfolders;
UINT16 numlumps; // this wad's number of resources
FILE *handle;
UINT32 filesize; // for network