mirror of
				https://github.com/KartKrewDev/RingRacers.git
				synced 2025-10-30 08:01:28 +00:00 
			
		
		
		
	Merge branch 'terrain-optimise-fresh' into 'master'
Terrain hashes See merge request KartKrew/Kart!666
This commit is contained in:
		
						commit
						2660271911
					
				
					 4 changed files with 73 additions and 51 deletions
				
			
		| 
						 | 
				
			
			@ -75,7 +75,7 @@ static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkN
 | 
			
		|||
	{
 | 
			
		||||
		brightmapStorage_t *bms = &brightmapStorage[i];
 | 
			
		||||
 | 
			
		||||
		if (checkHash == bms->textureHash)
 | 
			
		||||
		if (checkHash == bms->textureHash && !strncmp(checkName, bms->textureName, 8))
 | 
			
		||||
		{
 | 
			
		||||
			// Name matches.
 | 
			
		||||
			return bms;
 | 
			
		||||
| 
						 | 
				
			
			@ -119,8 +119,8 @@ static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
				if (bms == NULL)
 | 
			
		||||
				{
 | 
			
		||||
					bms = K_NewBrightmap();
 | 
			
		||||
					strncpy(bms->textureName, tkn, 9);
 | 
			
		||||
					bms->textureHash = quickncasehash(bms->textureName, 8);
 | 
			
		||||
					strncpy(bms->textureName, tkn, 8);
 | 
			
		||||
					bms->textureHash = quickncasehash(tkn, 8);
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				Z_Free(tkn);
 | 
			
		||||
| 
						 | 
				
			
			@ -129,8 +129,8 @@ static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
 | 
			
		||||
				if (tkn && pos < size)
 | 
			
		||||
				{
 | 
			
		||||
					strncpy(bms->brightmapName, tkn, 9);
 | 
			
		||||
					bms->brightmapHash = quickncasehash(bms->brightmapName, 8);
 | 
			
		||||
					strncpy(bms->brightmapName, tkn, 8);
 | 
			
		||||
					bms->brightmapHash = quickncasehash(tkn, 8);
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,11 +23,11 @@ typedef struct brightmapStorage_s
 | 
			
		|||
	// Stores data for brightmap definitions,
 | 
			
		||||
	// before putting them into texturebrightmaps.
 | 
			
		||||
 | 
			
		||||
	char textureName[9]; // The texture's name.
 | 
			
		||||
	UINT32 textureHash; // The texture name's hash.
 | 
			
		||||
	char textureName[8];	// The texture's name.
 | 
			
		||||
	UINT32 textureHash;		// The texture name's hash.
 | 
			
		||||
 | 
			
		||||
	char brightmapName[9]; // The brightmap's name.
 | 
			
		||||
	UINT32 brightmapHash; // The brightmap name's hash.
 | 
			
		||||
	char brightmapName[8];	// The brightmap's name.
 | 
			
		||||
	UINT32 brightmapHash;	// The brightmap name's hash.
 | 
			
		||||
} brightmapStorage_t;
 | 
			
		||||
 | 
			
		||||
/*--------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,6 +91,7 @@ t_splash_t *K_GetSplashByIndex(size_t checkIndex)
 | 
			
		|||
--------------------------------------------------*/
 | 
			
		||||
t_splash_t *K_GetSplashByName(const char *checkName)
 | 
			
		||||
{
 | 
			
		||||
	UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
	if (numSplashDefs == 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -102,7 +103,7 @@ t_splash_t *K_GetSplashByName(const char *checkName)
 | 
			
		|||
	{
 | 
			
		||||
		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.
 | 
			
		||||
			return s;
 | 
			
		||||
| 
						 | 
				
			
			@ -159,6 +160,7 @@ t_footstep_t *K_GetFootstepByIndex(size_t checkIndex)
 | 
			
		|||
--------------------------------------------------*/
 | 
			
		||||
t_footstep_t *K_GetFootstepByName(const char *checkName)
 | 
			
		||||
{
 | 
			
		||||
	UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
	if (numFootstepDefs == 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -170,7 +172,7 @@ t_footstep_t *K_GetFootstepByName(const char *checkName)
 | 
			
		|||
	{
 | 
			
		||||
		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.
 | 
			
		||||
			return fs;
 | 
			
		||||
| 
						 | 
				
			
			@ -227,21 +229,20 @@ terrain_t *K_GetTerrainByIndex(size_t checkIndex)
 | 
			
		|||
--------------------------------------------------*/
 | 
			
		||||
terrain_t *K_GetTerrainByName(const char *checkName)
 | 
			
		||||
{
 | 
			
		||||
	UINT32 checkHash = quickncasehash(checkName, TERRAIN_NAME_LEN);
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
	if (numTerrainDefs == 0)
 | 
			
		||||
	if (numTerrainDefs > 0)
 | 
			
		||||
	{
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < numTerrainDefs; i++)
 | 
			
		||||
	{
 | 
			
		||||
		terrain_t *t = &terrainDefs[i];
 | 
			
		||||
 | 
			
		||||
		if (stricmp(checkName, t->name) == 0)
 | 
			
		||||
		for (i = 0; i < numTerrainDefs; i++)
 | 
			
		||||
		{
 | 
			
		||||
			// Name matches.
 | 
			
		||||
			return t;
 | 
			
		||||
			terrain_t *t = &terrainDefs[i];
 | 
			
		||||
 | 
			
		||||
			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)
 | 
			
		||||
{
 | 
			
		||||
	UINT32 checkHash = quickncasehash(checkName, 8);
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
	if (numTerrainFloorDefs == 0)
 | 
			
		||||
	if (numTerrainFloorDefs > 0)
 | 
			
		||||
	{
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < numTerrainFloorDefs; i++)
 | 
			
		||||
	{
 | 
			
		||||
		t_floor_t *f = &terrainFloorDefs[i];
 | 
			
		||||
 | 
			
		||||
		if (strncasecmp(checkName, f->textureName, 8) == 0)
 | 
			
		||||
		for (i = 0; i < numTerrainFloorDefs; i++)
 | 
			
		||||
		{
 | 
			
		||||
			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)
 | 
			
		||||
{
 | 
			
		||||
	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];
 | 
			
		||||
	return K_GetTerrainForTextureName(tex->name);
 | 
			
		||||
	// This texture doesn't have a terrain directly applied to it,
 | 
			
		||||
	// 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)
 | 
			
		||||
{
 | 
			
		||||
	char *tkn = M_GetToken((char *)data);
 | 
			
		||||
	UINT32 tknHash = 0;
 | 
			
		||||
	size_t pos = 0;
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1211,11 +1212,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
			{
 | 
			
		||||
				t_splash_t *s = NULL;
 | 
			
		||||
 | 
			
		||||
				tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
 | 
			
		||||
				for (i = 0; i < numSplashDefs; i++)
 | 
			
		||||
				{
 | 
			
		||||
					s = &splashDefs[i];
 | 
			
		||||
 | 
			
		||||
					if (stricmp(tkn, s->name) == 0)
 | 
			
		||||
					if (tknHash == s->hash && !strncmp(tkn, s->name, TERRAIN_NAME_LEN))
 | 
			
		||||
					{
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -1227,6 +1230,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
					s = &splashDefs[i];
 | 
			
		||||
 | 
			
		||||
					strncpy(s->name, tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
					s->hash = tknHash;
 | 
			
		||||
 | 
			
		||||
					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;
 | 
			
		||||
 | 
			
		||||
				tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
 | 
			
		||||
				for (i = 0; i < numFootstepDefs; i++)
 | 
			
		||||
				{
 | 
			
		||||
					fs = &footstepDefs[i];
 | 
			
		||||
 | 
			
		||||
					if (stricmp(tkn, fs->name) == 0)
 | 
			
		||||
					if (tknHash == fs->hash && !strncmp(tkn, fs->name, TERRAIN_NAME_LEN))
 | 
			
		||||
					{
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -1264,6 +1271,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
					fs = &footstepDefs[i];
 | 
			
		||||
 | 
			
		||||
					strncpy(fs->name, tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
					fs->hash = tknHash;
 | 
			
		||||
 | 
			
		||||
					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;
 | 
			
		||||
 | 
			
		||||
				tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
 | 
			
		||||
				for (i = 0; i < numTerrainDefs; i++)
 | 
			
		||||
				{
 | 
			
		||||
					t = &terrainDefs[i];
 | 
			
		||||
 | 
			
		||||
					if (stricmp(tkn, t->name) == 0)
 | 
			
		||||
					if (tknHash == t->hash && !strncmp(tkn, t->name, TERRAIN_NAME_LEN))
 | 
			
		||||
					{
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -1301,6 +1312,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
					t = &terrainDefs[i];
 | 
			
		||||
 | 
			
		||||
					strncpy(t->name, tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
					t->hash = tknHash;
 | 
			
		||||
 | 
			
		||||
					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;
 | 
			
		||||
 | 
			
		||||
					tknHash = quickncasehash(tkn, 8);
 | 
			
		||||
 | 
			
		||||
					for (i = 0; i < numTerrainFloorDefs; i++)
 | 
			
		||||
					{
 | 
			
		||||
						f = &terrainFloorDefs[i];
 | 
			
		||||
 | 
			
		||||
						if (stricmp(tkn, f->textureName) == 0)
 | 
			
		||||
						if (f->textureHash == tknHash && !strncmp(tkn, f->textureName, 8))
 | 
			
		||||
						{
 | 
			
		||||
							break;
 | 
			
		||||
						}
 | 
			
		||||
| 
						 | 
				
			
			@ -1348,7 +1363,8 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
						K_NewTerrainFloorDefs();
 | 
			
		||||
						f = &terrainFloorDefs[i];
 | 
			
		||||
 | 
			
		||||
						strncpy(f->textureName, tkn, 9);
 | 
			
		||||
						strncpy(f->textureName, tkn, 8);
 | 
			
		||||
						f->textureHash = tknHash;
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					Z_Free(tkn);
 | 
			
		||||
| 
						 | 
				
			
			@ -1398,11 +1414,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
			{
 | 
			
		||||
				terrain_t *t = NULL;
 | 
			
		||||
 | 
			
		||||
				tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
 | 
			
		||||
				for (i = 0; i < numTerrainDefs; i++)
 | 
			
		||||
				{
 | 
			
		||||
					t = &terrainDefs[i];
 | 
			
		||||
 | 
			
		||||
					if (stricmp(tkn, t->name) == 0)
 | 
			
		||||
					if (tknHash == t->hash && !strncmp(tkn, t->name, TERRAIN_NAME_LEN))
 | 
			
		||||
					{
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -1435,11 +1453,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size)
 | 
			
		|||
			{
 | 
			
		||||
				t_footstep_t *fs = NULL;
 | 
			
		||||
 | 
			
		||||
				tknHash = quickncasehash(tkn, TERRAIN_NAME_LEN);
 | 
			
		||||
 | 
			
		||||
				for (i = 0; i < numFootstepDefs; i++)
 | 
			
		||||
				{
 | 
			
		||||
					fs = &footstepDefs[i];
 | 
			
		||||
 | 
			
		||||
					if (stricmp(tkn, fs->name) == 0)
 | 
			
		||||
					if (tknHash == fs->hash && !strncmp(tkn, fs->name, TERRAIN_NAME_LEN))
 | 
			
		||||
					{
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ typedef struct t_splash_s
 | 
			
		|||
	// These are particles spawned when hitting the floor.
 | 
			
		||||
 | 
			
		||||
	char name[TERRAIN_NAME_LEN];	// Lookup name.
 | 
			
		||||
	UINT32 hash;					// Lookup name's hash.
 | 
			
		||||
 | 
			
		||||
	UINT16 mobjType;		// Thing type. MT_NULL to not spawn anything.
 | 
			
		||||
	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.
 | 
			
		||||
 | 
			
		||||
	char name[TERRAIN_NAME_LEN];	// Lookup name.
 | 
			
		||||
	UINT32 hash;					// Lookup name's hash.
 | 
			
		||||
 | 
			
		||||
	UINT16 mobjType;		// Thing type. MT_NULL to not spawn anything.
 | 
			
		||||
	UINT16 sfx;				// Sound to play.
 | 
			
		||||
| 
						 | 
				
			
			@ -79,6 +81,7 @@ typedef struct terrain_s
 | 
			
		|||
	// These are all of the properties that the floor gets.
 | 
			
		||||
 | 
			
		||||
	char name[TERRAIN_NAME_LEN];	// Lookup name.
 | 
			
		||||
	UINT32 hash;					// Lookup name's hash.
 | 
			
		||||
 | 
			
		||||
	size_t splashID;		// Splash defintion ID.
 | 
			
		||||
	size_t footstepID;		// Footstep defintion ID.
 | 
			
		||||
| 
						 | 
				
			
			@ -93,16 +96,14 @@ typedef struct terrain_s
 | 
			
		|||
typedef struct t_floor_s
 | 
			
		||||
{
 | 
			
		||||
	// 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,
 | 
			
		||||
	// but was concerned because I recall sooomething about those not being netsafe?
 | 
			
		||||
	// Someone confirm if I just hallucinated that. :V)
 | 
			
		||||
 | 
			
		||||
	char textureName[9];	// Floor texture name.
 | 
			
		||||
	char textureName[8];	// Floor texture name.
 | 
			
		||||
	UINT32 textureHash;		// Floor texture hash.
 | 
			
		||||
	size_t terrainID;		// Terrain definition ID.
 | 
			
		||||
} t_floor_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*--------------------------------------------------
 | 
			
		||||
	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_GetDefaultTerrain(void);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue