From 3c62ff266c41216bb0a4b9e4cb3806cbcf31eba6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 27 May 2025 22:43:53 +0200 Subject: [PATCH] Reapply "Cache start and end locations for WAD folders" This reverts commit 30d64ad538fb97657829d6e03b1c9b99e5c15671. --- src/w_wad.c | 21 +++++++++++++++++++++ src/w_wad.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/w_wad.c b/src/w_wad.c index ddebd9c21..3c33c1bfa 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -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; } diff --git a/src/w_wad.h b/src/w_wad.h index dd7e94050..1dffb3735 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -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