Cache TERRAIN on texture_t

- K_GetTerrainForTextureNum no longer performs a string
  lookup
This commit is contained in:
James R 2023-12-22 04:22:04 -08:00
parent 2d4cc49101
commit 03deb45c67
3 changed files with 14 additions and 1 deletions

View file

@ -370,7 +370,7 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum)
if (textureNum >= 0 && textureNum < numtextures)
{
texture_t *tex = textures[textureNum];
return K_GetTerrainForTextureName(tex->name);
return tex->terrain;
}
// This texture doesn't have a terrain directly applied to it,
@ -2036,6 +2036,12 @@ static boolean K_TERRAINLumpParser(char *data, size_t size)
{
f->terrainID = K_GetTerrainHeapIndex(t);
CONS_Printf("Texture '%s' set to Terrain '%s'\n", f->textureName, tkn);
INT32 tex = R_CheckTextureNumForName(f->textureName);
if (tex != -1)
{
textures[tex]->terrain = t;
}
}
}
else
@ -2211,4 +2217,6 @@ void K_InitTerrain(UINT16 wadNum)
free(name);
}
}
R_ClearTextureNumCache(false);
}

View file

@ -27,6 +27,7 @@
#include "p_setup.h" // levelflats
#include "byteptr.h"
#include "dehacked.h"
#include "k_terrain.h"
#ifdef HWRENDER
#include "hardware/hw_glob.h" // HWR_LoadMapTextures
@ -1191,6 +1192,7 @@ Rloadflats (INT32 i, INT32 w)
texture->patchcount = 1;
texture->holes = false;
texture->flip = 0;
texture->terrain = K_GetTerrainForTextureName(texture->name);
// Allocate information for the texture's patches.
patch = &texture->patches[0];
@ -1293,6 +1295,7 @@ Rloadtextures (INT32 i, INT32 w)
texture->patchcount = 1;
texture->holes = false;
texture->flip = 0;
texture->terrain = K_GetTerrainForTextureName(texture->name);
// Allocate information for the texture's patches.
patch = &texture->patches[0];
@ -1830,6 +1833,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
resultTexture->width = newTextureWidth;
resultTexture->height = newTextureHeight;
resultTexture->type = TEXTURETYPE_COMPOSITE;
resultTexture->terrain = K_GetTerrainForTextureName(newTextureName);
}
Z_Free(texturesToken);
texturesToken = M_GetToken(NULL);

View file

@ -66,6 +66,7 @@ struct texture_t
boolean holes;
UINT8 flip; // 1 = flipx, 2 = flipy, 3 = both
void *flat; // The texture, as a flat.
terrain_t *terrain;
// All the patches[patchcount] are drawn back to front into the cached texture.
INT16 patchcount;