From 0bbd8246cc9c9950e7087152df25235efd9ee052 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 15 Dec 2021 14:02:56 -0800 Subject: [PATCH] Read only header bytes when creating textures list R_LoadTextures was reading in the entirety of every texture lump, now it only reads the 8 byte PNG header. This saved more than 1 second for me (1.68 s -> 0.24 s). PNG still need to be read in entirely to check their dimensions; I didn't bother looking into optimizing it since we don't have many PNG textures right now. --- src/r_data.c | 10 ++++------ src/r_patch.h | 2 ++ src/r_things.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index ab704675c..6c999d1ae 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -573,9 +573,9 @@ Rloadtextures (INT32 i, INT32 w) { UINT16 j, numlumps = 0; UINT16 texstart, texend, texturesLumpPos; - softwarepatch_t *patchlump; texpatch_t *patch; texture_t *texture; + softwarepatch_t patchlump; // Get the lump numbers for the markers in the WAD, if they exist. if (W_FileHasFolders(wadfiles[w])) @@ -615,7 +615,7 @@ Rloadtextures (INT32 i, INT32 w) continue; // If it is then SKIP IT } - patchlump = (softwarepatch_t *)W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); + W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, PNG_HEADER_SIZE, 0); //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((wadnum, lumpnum), patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); @@ -624,8 +624,8 @@ Rloadtextures (INT32 i, INT32 w) M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->hash = quickncasehash(texture->name, 8); - texture->width = SHORT(patchlump->width); - texture->height = SHORT(patchlump->height); + texture->width = SHORT(patchlump.width); + texture->height = SHORT(patchlump.height); texture->type = TEXTURETYPE_SINGLEPATCH; texture->patchcount = 1; @@ -638,8 +638,6 @@ Rloadtextures (INT32 i, INT32 w) patch->wad = wadnum; patch->lump = texstart + j; - Z_Free(patchlump); - texturewidth[i] = texture->width; textureheight[i] = texture->height << FRACBITS; i++; diff --git a/src/r_patch.h b/src/r_patch.h index 2dc9c2f4e..4d44b5416 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -36,6 +36,8 @@ typedef struct boolean available; } spriteinfo_t; +#define PNG_HEADER_SIZE (8) + // Patch functions patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest); void Patch_Free(patch_t *patch); diff --git a/src/r_things.cpp b/src/r_things.cpp index 8229369a7..4713bc50e 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -312,7 +312,7 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements - W_ReadLumpHeaderPwad(wadnum, l, &patch, (sizeof(INT16) *4), 0); + W_ReadLumpHeaderPwad(wadnum, l, &patch, PNG_HEADER_SIZE, 0); spritecachedinfo[numspritelumps].width = (INT32)(SHORT(patch.width))<