Reapply Store terrain ID instead of terrain pointer, add new helpers and accomodate for this

This reverts commit cb3b95c0e1.
This commit is contained in:
NepDisk 2024-08-21 22:53:16 -04:00
parent 5c0d57a58a
commit 594a26ea5e
4 changed files with 78 additions and 1 deletions

View file

@ -332,6 +332,16 @@ terrain_t *K_GetDefaultTerrain(void)
return K_GetTerrainByIndex(defaultTerrain);
}
/*--------------------------------------------------
size_t K_GetDefaultTerrainID(void)
See header file for description.
--------------------------------------------------*/
size_t K_GetDefaultTerrainID(void)
{
return defaultTerrain;
}
/*--------------------------------------------------
terrain_t *K_GetTerrainForTextureName(const char *checkName)
@ -360,6 +370,34 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName)
return K_GetDefaultTerrain();
}
/*--------------------------------------------------
size_t K_GetTerrainIDForTextureName(const char *checkName)
See header file for description.
--------------------------------------------------*/
size_t K_GetTerrainIDForTextureName(const char *checkName)
{
UINT32 checkHash = quickncasehash(checkName, 8);
size_t i;
if (numTerrainFloorDefs > 0)
{
for (i = 0; i < numTerrainFloorDefs; i++)
{
t_floor_t *f = &terrainFloorDefs[i];
if (checkHash == f->textureHash && !strncasecmp(checkName, f->textureName, 8))
{
return f->terrainID;
}
}
}
// This texture doesn't have a terrain directly applied to it,
// so we fallback to the default terrain.
return K_GetDefaultTerrainID();
}
/*--------------------------------------------------
terrain_t *K_GetTerrainForTextureNum(INT32 textureNum)
@ -370,7 +408,7 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum)
if (textureNum >= 0 && textureNum < numtextures)
{
texture_t *tex = textures[textureNum];
return K_GetTerrainForTextureName(tex->name);
return K_GetTerrainByIndex(tex->terrainID);
}
// This texture doesn't have a terrain directly applied to it,
@ -1828,6 +1866,12 @@ static boolean K_TERRAINLumpParser(UINT8 *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]->terrainID = f->terrainID;
}
}
}
else

View file

@ -388,6 +388,19 @@ terrain_t *K_GetTerrainByName(const char *checkName);
terrain_t *K_GetDefaultTerrain(void);
/*--------------------------------------------------
size_t K_GetDefaultTerrainID(void)
Returns the default terrain definition's ID, used
in cases where terrain is not set for a texture.
Input Arguments:-
None
Return:-
The default terrain definition's ID, NULL if it didn't exist.
--------------------------------------------------*/
size_t K_GetDefaultTerrainID(void);
/*--------------------------------------------------
terrain_t *K_GetTerrainForTextureName(const char *checkName);
@ -407,6 +420,22 @@ terrain_t *K_GetDefaultTerrain(void);
terrain_t *K_GetTerrainForTextureName(const char *checkName);
/*--------------------------------------------------
size_t K_GetTerrainIDForTextureName(const char *checkName)
Returns the ID of the terrain definition applied
to the texture name inputted.
Input Arguments:-
checkName - The texture's name.
Return:-
The texture's terrain definition's ID if it exists,
otherwise the default terrain's ID if it exists,
otherwise NULL.
--------------------------------------------------*/
size_t K_GetTerrainIDForTextureName(const char *checkName);
/*--------------------------------------------------
terrain_t *K_GetTerrainForTextureNum(INT32 textureNum);

View file

@ -853,6 +853,7 @@ Rloadflats (INT32 i, INT32 w)
texture->patchcount = 1;
texture->holes = false;
texture->flip = 0;
texture->terrainID = K_GetTerrainIDForTextureName(texture->name);
// Allocate information for the texture's patches.
patch = &texture->patches[0];
@ -955,6 +956,7 @@ Rloadtextures (INT32 i, INT32 w)
texture->patchcount = 1;
texture->holes = false;
texture->flip = 0;
texture->terrainID = K_GetTerrainIDForTextureName(texture->name);
// Allocate information for the texture's patches.
patch = &texture->patches[0];
@ -1475,6 +1477,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
resultTexture->width = newTextureWidth;
resultTexture->height = newTextureHeight;
resultTexture->type = TEXTURETYPE_COMPOSITE;
resultTexture->terrainID = K_GetTerrainIDForTextureName(newTextureName);
}
Z_Free(texturesToken);
texturesToken = M_GetToken(NULL);

View file

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