Skip to content

Commit

Permalink
engine: client: split the sprites indices only when loading new sprit…
Browse files Browse the repository at this point in the history
…e. Scan the whole array when searching.

Fixes incorrect sprite loading in XDM
  • Loading branch information
a1batross committed Dec 14, 2023
1 parent 13aab4e commit 93ceb0e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions engine/client/cl_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,7 @@ static model_t *CL_LoadSpriteModel( const char *filename, uint type, uint texFla
{
char name[MAX_QPATH];
model_t *mod;
int i;

// use high indices for client sprites
// for GoldSrc bug-compatibility
const int start = type != SPR_HUDSPRITE ? MAX_CLIENT_SPRITES / 2 : 0;
int i, start;

if( !COM_CheckString( filename ))
{
Expand All @@ -1250,7 +1246,7 @@ static model_t *CL_LoadSpriteModel( const char *filename, uint type, uint texFla
Q_strncpy( name, filename, sizeof( name ));
COM_FixSlashes( name );

for( i = 0, mod = clgame.sprites + start; i < MAX_CLIENT_SPRITES / 2; i++, mod++ )
for( i = 0, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ )
{
if( !Q_stricmp( mod->name, name ))
{
Expand All @@ -1267,8 +1263,15 @@ static model_t *CL_LoadSpriteModel( const char *filename, uint type, uint texFla
}

// find a free model slot spot
for( i = 0, mod = clgame.sprites + start; i < MAX_CLIENT_SPRITES / 2; i++, mod++ )
if( !mod->name[0] ) break; // this is a valid spot
// use low indices only for HUD sprites
// for GoldSrc bug compatibility
start = type == SPR_HUDSPRITE ? 0 : MAX_CLIENT_SPRITES / 2;

for( i = 0, mod = &clgame.sprites[start]; i < MAX_CLIENT_SPRITES / 2; i++, mod++ )
{
if( !mod->name[0] )
break; // this is a valid spot
}

if( i == MAX_CLIENT_SPRITES / 2 )
{
Expand Down

0 comments on commit 93ceb0e

Please sign in to comment.