Merge branch 'terrain-optimise-fresh' into 'master'

Terrain hashes

See merge request KartKrew/Kart!666
This commit is contained in:
Sal 2022-09-11 06:29:45 +00:00
commit 2660271911
4 changed files with 73 additions and 51 deletions

View file

@ -75,7 +75,7 @@ static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkN
{ {
brightmapStorage_t *bms = &brightmapStorage[i]; brightmapStorage_t *bms = &brightmapStorage[i];
if (checkHash == bms->textureHash) if (checkHash == bms->textureHash && !strncmp(checkName, bms->textureName, 8))
{ {
// Name matches. // Name matches.
return bms; return bms;
@ -119,8 +119,8 @@ static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size)
if (bms == NULL) if (bms == NULL)
{ {
bms = K_NewBrightmap(); bms = K_NewBrightmap();
strncpy(bms->textureName, tkn, 9); strncpy(bms->textureName, tkn, 8);
bms->textureHash = quickncasehash(bms->textureName, 8); bms->textureHash = quickncasehash(tkn, 8);
} }
Z_Free(tkn); Z_Free(tkn);
@ -129,8 +129,8 @@ static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size)
if (tkn && pos < size) if (tkn && pos < size)
{ {
strncpy(bms->brightmapName, tkn, 9); strncpy(bms->brightmapName, tkn, 8);
bms->brightmapHash = quickncasehash(bms->brightmapName, 8); bms->brightmapHash = quickncasehash(tkn, 8);
} }
else else
{ {

View file

@ -23,11 +23,11 @@ typedef struct brightmapStorage_s
// Stores data for brightmap definitions, // Stores data for brightmap definitions,
// before putting them into texturebrightmaps. // before putting them into texturebrightmaps.
char textureName[9]; // The texture's name. char textureName[8]; // The texture's name.
UINT32 textureHash; // The texture name's hash. UINT32 textureHash; // The texture name's hash.
char brightmapName[9]; // The brightmap's name. char brightmapName[8]; // The brightmap's name.
UINT32 brightmapHash; // The brightmap name's hash. UINT32 brightmapHash; // The brightmap name's hash.
} brightmapStorage_t; } brightmapStorage_t;
/*-------------------------------------------------- /*--------------------------------------------------

View file

@ -91,6 +91,7 @@ t_splash_t *K_GetSplashByIndex(size_t checkIndex)
--------------------------------------------------*/ --------------------------------------------------*/
t_splash_t *K_GetSplashByName(const char *checkName) t_splash_t *K_GetSplashByName(const char *checkName)
{ {
UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
size_t i; size_t i;
if (numSplashDefs == 0) if (numSplashDefs == 0)
@ -102,7 +103,7 @@ t_splash_t *K_GetSplashByName(const char *checkName)
{ {
t_splash_t *s = &splashDefs[i]; t_splash_t *s = &splashDefs[i];
if (stricmp(checkName, s->name) == 0) if (checkHash == s->hash && !strncmp(checkName, s->name, TERRAIN_NAME_LEN))
{ {
// Name matches. // Name matches.
return s; return s;
@ -159,6 +160,7 @@ t_footstep_t *K_GetFootstepByIndex(size_t checkIndex)
--------------------------------------------------*/ --------------------------------------------------*/
t_footstep_t *K_GetFootstepByName(const char *checkName) t_footstep_t *K_GetFootstepByName(const char *checkName)
{ {
UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
size_t i; size_t i;
if (numFootstepDefs == 0) if (numFootstepDefs == 0)
@ -170,7 +172,7 @@ t_footstep_t *K_GetFootstepByName(const char *checkName)
{ {
t_footstep_t *fs = &footstepDefs[i]; t_footstep_t *fs = &footstepDefs[i];
if (stricmp(checkName, fs->name) == 0) if (checkHash == fs->hash && !strncmp(checkName, fs->name, TERRAIN_NAME_LEN))
{ {
// Name matches. // Name matches.
return fs; return fs;
@ -227,21 +229,20 @@ terrain_t *K_GetTerrainByIndex(size_t checkIndex)
--------------------------------------------------*/ --------------------------------------------------*/
terrain_t *K_GetTerrainByName(const char *checkName) terrain_t *K_GetTerrainByName(const char *checkName)
{ {
UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
size_t i; size_t i;
if (numTerrainDefs == 0) if (numTerrainDefs > 0)
{ {
return NULL; for (i = 0; i < numTerrainDefs; i++)
}
for (i = 0; i < numTerrainDefs; i++)
{
terrain_t *t = &terrainDefs[i];
if (stricmp(checkName, t->name) == 0)
{ {
// Name matches. terrain_t *t = &terrainDefs[i];
return t;
if (checkHash == t->hash && !strncmp(checkName, t->name, TERRAIN_NAME_LEN))
{
// Name matches.
return t;
}
} }
} }
@ -265,20 +266,19 @@ terrain_t *K_GetDefaultTerrain(void)
--------------------------------------------------*/ --------------------------------------------------*/
terrain_t *K_GetTerrainForTextureName(const char *checkName) terrain_t *K_GetTerrainForTextureName(const char *checkName)
{ {
UINT32 checkHash = quickncasehash(checkName, 8);
size_t i; size_t i;
if (numTerrainFloorDefs == 0) if (numTerrainFloorDefs > 0)
{ {
return NULL; for (i = 0; i < numTerrainFloorDefs; i++)
}
for (i = 0; i < numTerrainFloorDefs; i++)
{
t_floor_t *f = &terrainFloorDefs[i];
if (strncasecmp(checkName, f->textureName, 8) == 0)
{ {
return K_GetTerrainByIndex(f->terrainID); t_floor_t *f = &terrainFloorDefs[i];
if (checkHash == f->textureHash && !strncmp(checkName, f->textureName, 8))
{
return K_GetTerrainByIndex(f->terrainID);
}
} }
} }
@ -294,15 +294,15 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName)
--------------------------------------------------*/ --------------------------------------------------*/
terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) terrain_t *K_GetTerrainForTextureNum(INT32 textureNum)
{ {
texture_t *tex = NULL; if (textureNum >= 0 && textureNum < numtextures)
if (textureNum < 0 || textureNum >= numtextures)
{ {
return NULL; texture_t *tex = textures[textureNum];
return K_GetTerrainForTextureName(tex->name);
} }
tex = textures[textureNum]; // This texture doesn't have a terrain directly applied to it,
return K_GetTerrainForTextureName(tex->name); // so we fallback to the default terrain.
return K_GetDefaultTerrain();
} }
/*-------------------------------------------------- /*--------------------------------------------------
@ -1187,6 +1187,7 @@ static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(size_t, char *, c
static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
char *tkn = M_GetToken((char *)data); char *tkn = M_GetToken((char *)data);
UINT32 tknHash = 0;
size_t pos = 0; size_t pos = 0;
size_t i; size_t i;
@ -1211,11 +1212,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
t_splash_t *s = NULL; t_splash_t *s = NULL;
tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
for (i = 0; i < numSplashDefs; i++) for (i = 0; i < numSplashDefs; i++)
{ {
s = &splashDefs[i]; s = &splashDefs[i];
if (stricmp(tkn, s->name) == 0) if (tknHash == s->hash && !strncmp(tkn, s->name, TERRAIN_NAME_LEN))
{ {
break; break;
} }
@ -1227,6 +1230,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
s = &splashDefs[i]; s = &splashDefs[i];
strncpy(s->name, tkn, TERRAIN_NAME_LEN); strncpy(s->name, tkn, TERRAIN_NAME_LEN);
s->hash = tknHash;
CONS_Printf("Created new Splash type '%s'\n", s->name); CONS_Printf("Created new Splash type '%s'\n", s->name);
} }
@ -1248,11 +1253,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
t_footstep_t *fs = NULL; t_footstep_t *fs = NULL;
tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
for (i = 0; i < numFootstepDefs; i++) for (i = 0; i < numFootstepDefs; i++)
{ {
fs = &footstepDefs[i]; fs = &footstepDefs[i];
if (stricmp(tkn, fs->name) == 0) if (tknHash == fs->hash && !strncmp(tkn, fs->name, TERRAIN_NAME_LEN))
{ {
break; break;
} }
@ -1264,6 +1271,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
fs = &footstepDefs[i]; fs = &footstepDefs[i];
strncpy(fs->name, tkn, TERRAIN_NAME_LEN); strncpy(fs->name, tkn, TERRAIN_NAME_LEN);
fs->hash = tknHash;
CONS_Printf("Created new Footstep type '%s'\n", fs->name); CONS_Printf("Created new Footstep type '%s'\n", fs->name);
} }
@ -1285,11 +1294,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
terrain_t *t = NULL; terrain_t *t = NULL;
tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
for (i = 0; i < numTerrainDefs; i++) for (i = 0; i < numTerrainDefs; i++)
{ {
t = &terrainDefs[i]; t = &terrainDefs[i];
if (stricmp(tkn, t->name) == 0) if (tknHash == t->hash && !strncmp(tkn, t->name, TERRAIN_NAME_LEN))
{ {
break; break;
} }
@ -1301,6 +1312,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
t = &terrainDefs[i]; t = &terrainDefs[i];
strncpy(t->name, tkn, TERRAIN_NAME_LEN); strncpy(t->name, tkn, TERRAIN_NAME_LEN);
t->hash = tknHash;
CONS_Printf("Created new Terrain type '%s'\n", t->name); CONS_Printf("Created new Terrain type '%s'\n", t->name);
} }
@ -1333,11 +1346,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
t_floor_t *f = NULL; t_floor_t *f = NULL;
tknHash = quickncasehash(tkn, 8);
for (i = 0; i < numTerrainFloorDefs; i++) for (i = 0; i < numTerrainFloorDefs; i++)
{ {
f = &terrainFloorDefs[i]; f = &terrainFloorDefs[i];
if (stricmp(tkn, f->textureName) == 0) if (f->textureHash == tknHash && !strncmp(tkn, f->textureName, 8))
{ {
break; break;
} }
@ -1348,7 +1363,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
K_NewTerrainFloorDefs(); K_NewTerrainFloorDefs();
f = &terrainFloorDefs[i]; f = &terrainFloorDefs[i];
strncpy(f->textureName, tkn, 9); strncpy(f->textureName, tkn, 8);
f->textureHash = tknHash;
} }
Z_Free(tkn); Z_Free(tkn);
@ -1398,11 +1414,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
terrain_t *t = NULL; terrain_t *t = NULL;
tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
for (i = 0; i < numTerrainDefs; i++) for (i = 0; i < numTerrainDefs; i++)
{ {
t = &terrainDefs[i]; t = &terrainDefs[i];
if (stricmp(tkn, t->name) == 0) if (tknHash == t->hash && !strncmp(tkn, t->name, TERRAIN_NAME_LEN))
{ {
break; break;
} }
@ -1435,11 +1453,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
{ {
t_footstep_t *fs = NULL; t_footstep_t *fs = NULL;
tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
for (i = 0; i < numFootstepDefs; i++) for (i = 0; i < numFootstepDefs; i++)
{ {
fs = &footstepDefs[i]; fs = &footstepDefs[i];
if (stricmp(tkn, fs->name) == 0) if (tknHash == fs->hash && !strncmp(tkn, fs->name, TERRAIN_NAME_LEN))
{ {
break; break;
} }

View file

@ -28,6 +28,7 @@ typedef struct t_splash_s
// These are particles spawned when hitting the floor. // These are particles spawned when hitting the floor.
char name[TERRAIN_NAME_LEN]; // Lookup name. char name[TERRAIN_NAME_LEN]; // Lookup name.
UINT32 hash; // Lookup name's hash.
UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. UINT16 mobjType; // Thing type. MT_NULL to not spawn anything.
UINT16 sfx; // Sound to play. UINT16 sfx; // Sound to play.
@ -48,6 +49,7 @@ typedef struct t_footstep_s
// These are particles spawned when moving fast enough on a floor. // These are particles spawned when moving fast enough on a floor.
char name[TERRAIN_NAME_LEN]; // Lookup name. char name[TERRAIN_NAME_LEN]; // Lookup name.
UINT32 hash; // Lookup name's hash.
UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. UINT16 mobjType; // Thing type. MT_NULL to not spawn anything.
UINT16 sfx; // Sound to play. UINT16 sfx; // Sound to play.
@ -79,6 +81,7 @@ typedef struct terrain_s
// These are all of the properties that the floor gets. // These are all of the properties that the floor gets.
char name[TERRAIN_NAME_LEN]; // Lookup name. char name[TERRAIN_NAME_LEN]; // Lookup name.
UINT32 hash; // Lookup name's hash.
size_t splashID; // Splash defintion ID. size_t splashID; // Splash defintion ID.
size_t footstepID; // Footstep defintion ID. size_t footstepID; // Footstep defintion ID.
@ -93,16 +96,14 @@ typedef struct terrain_s
typedef struct t_floor_s typedef struct t_floor_s
{ {
// Terrain floor definition. // Terrain floor definition.
// Ties texture names to a . // Ties a texture name to a terrain definition.
// (Could be optimized by using texture IDs instead of names, char textureName[8]; // Floor texture name.
// but was concerned because I recall sooomething about those not being netsafe? UINT32 textureHash; // Floor texture hash.
// Someone confirm if I just hallucinated that. :V)
char textureName[9]; // Floor texture name.
size_t terrainID; // Terrain definition ID. size_t terrainID; // Terrain definition ID.
} t_floor_t; } t_floor_t;
/*-------------------------------------------------- /*--------------------------------------------------
size_t K_GetSplashHeapIndex(t_splash_t *splash); size_t K_GetSplashHeapIndex(t_splash_t *splash);
@ -285,6 +286,7 @@ terrain_t *K_GetTerrainByIndex(size_t checkIndex);
terrain_t *K_GetTerrainByName(const char *checkName); terrain_t *K_GetTerrainByName(const char *checkName);
/*-------------------------------------------------- /*--------------------------------------------------
terrain_t *K_GetDefaultTerrain(void); terrain_t *K_GetDefaultTerrain(void);