ref: gl: simplify strings operations.

This commit is contained in:
Andrey Akhmichin 2022-12-20 00:24:22 +05:00 committed by Alibek Omarov
parent f4fb8b4ac2
commit 7555fefc18
2 changed files with 17 additions and 8 deletions

View File

@ -1570,6 +1570,8 @@ int GL_LoadTextureArray( const char **names, int flags )
uint picFlags = 0;
char name[256];
gl_texture_t *tex;
size_t len = 0;
int ret = 0;
uint i, j;
if( !names || !names[0] || !glw_state.initialized )
@ -1583,14 +1585,22 @@ int GL_LoadTextureArray( const char **names, int flags )
if( numLayers <= 0 ) return 0;
// create complexname from layer names
for( i = 0; i < numLayers; i++ )
for( i = 0; i < numLayers - 1; i++ )
{
COM_FileBase( names[i], basename );
Q_strncat( name, basename, sizeof( name ) );
if( i != ( numLayers - 1 )) Q_strncat( name, "|", sizeof( name ));
}
ret = Q_snprintf( &name[len], sizeof( name ) - len, "%s|", basename );
Q_strncat( name, va( "[%i]", numLayers ), sizeof( name ));
if( ret == -1 )
return 0;
len += ret;
}
COM_FileBase( names[i], basename );
ret = Q_snprintf( &name[len], sizeof( name ) - len, "%s[%i]", basename, numLayers );
if( ret == -1 )
return 0;
if( !GL_CheckTexName( name ))
return 0;

View File

@ -46,14 +46,13 @@ static void R_ParseDetailTextures( const char *filename )
// NOTE: COM_ParseFile handled some symbols seperately
// this code will be fix it
pfile = COM_ParseFile( pfile, token, sizeof( token ));
Q_strncat( texname, "{", sizeof( texname ));
Q_strncat( texname, token, sizeof( texname ));
Q_snprintf( texname, sizeof( texname ), "{%s", token );
}
else Q_strncpy( texname, token, sizeof( texname ));
// read detailtexture name
pfile = COM_ParseFile( pfile, token, sizeof( token ));
Q_strncat( detail_texname, token, sizeof( detail_texname ));
Q_strncpy( detail_texname, token, sizeof( detail_texname ));
// trying the scales or '{'
pfile = COM_ParseFile( pfile, token, sizeof( token ));