Browse Source

ref_gl: use skybox names generated by CheckSkybox function, don't checking same file twice

Also fixes priority for skyboxes
pull/2/head
Alibek Omarov 2 years ago
parent
commit
f29a9f5f58
  1. 40
      ref_gl/gl_warp.c

40
ref_gl/gl_warp.c

@ -60,11 +60,7 @@ float r_turbsin[] =
#include "warpsin.h" #include "warpsin.h"
}; };
#define SKYBOX_MISSED 0 static qboolean CheckSkybox( const char *name, char out[6][MAX_STRING] )
#define SKYBOX_HLSTYLE 1
#define SKYBOX_Q1STYLE 2
static int CheckSkybox( const char *name )
{ {
const char *skybox_ext[3] = { "dds", "tga", "bmp" }; const char *skybox_ext[3] = { "dds", "tga", "bmp" };
int i, j, num_checked_sides; int i, j, num_checked_sides;
@ -73,32 +69,40 @@ static int CheckSkybox( const char *name )
// search for skybox images // search for skybox images
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
// check HL-style skyboxes
num_checked_sides = 0; num_checked_sides = 0;
for( j = 0; j < 6; j++ ) for( j = 0; j < 6; j++ )
{ {
// build side name // build side name
sidename = va( "%s%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] ); sidename = va( "%s%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] );
if( gEngfuncs.fsapi->FileExists( sidename, false )) if( gEngfuncs.fsapi->FileExists( sidename, false ))
{
Q_strncpy( out[j], sidename, sizeof( out[j] ));
num_checked_sides++; num_checked_sides++;
}
} }
if( num_checked_sides == 6 ) if( num_checked_sides == 6 )
return SKYBOX_HLSTYLE; // image exists return true; // image exists
// check Q1-style skyboxes
num_checked_sides = 0;
for( j = 0; j < 6; j++ ) for( j = 0; j < 6; j++ )
{ {
// build side name // build side name
sidename = va( "%s_%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] ); sidename = va( "%s_%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] );
if( gEngfuncs.fsapi->FileExists( sidename, false )) if( gEngfuncs.fsapi->FileExists( sidename, false ))
{
Q_strncpy( out[j], sidename, sizeof( out[j] ));
num_checked_sides++; num_checked_sides++;
}
} }
if( num_checked_sides == 6 ) if( num_checked_sides == 6 )
return SKYBOX_Q1STYLE; // images exists return true; // images exists
} }
return SKYBOX_MISSED; return false;
} }
void DrawSkyPolygon( int nump, vec3_t vecs ) void DrawSkyPolygon( int nump, vec3_t vecs )
@ -411,8 +415,9 @@ R_SetupSky
void R_SetupSky( const char *skyboxname ) void R_SetupSky( const char *skyboxname )
{ {
char loadname[MAX_STRING]; char loadname[MAX_STRING];
char sidename[MAX_STRING]; char sidenames[6][MAX_STRING];
int i, result, len; int i, len;
qboolean result;
if( !COM_CheckString( skyboxname )) if( !COM_CheckString( skyboxname ))
{ {
@ -428,10 +433,10 @@ void R_SetupSky( const char *skyboxname )
if( loadname[len - 1] == '_' ) if( loadname[len - 1] == '_' )
loadname[len - 1] = '\0'; loadname[len - 1] = '\0';
result = CheckSkybox( loadname ); result = CheckSkybox( loadname, sidenames );
// to prevent infinite recursion if default skybox was missed // to prevent infinite recursion if default skybox was missed
if( result == SKYBOX_MISSED && Q_stricmp( loadname, DEFAULT_SKYBOX_PATH )) if( !result && Q_stricmp( loadname, DEFAULT_SKYBOX_PATH ))
{ {
gEngfuncs.Con_Reportf( S_WARN "missed or incomplete skybox '%s'\n", skyboxname ); gEngfuncs.Con_Reportf( S_WARN "missed or incomplete skybox '%s'\n", skyboxname );
R_SetupSky( "desert" ); // force to default R_SetupSky( "desert" ); // force to default
@ -444,12 +449,11 @@ void R_SetupSky( const char *skyboxname )
for( i = 0; i < 6; i++ ) for( i = 0; i < 6; i++ )
{ {
if( result == SKYBOX_HLSTYLE ) tr.skyboxTextures[i] = GL_LoadTexture( sidenames[i], NULL, 0, TF_CLAMP|TF_SKY );
Q_snprintf( sidename, sizeof( sidename ), "%s%s", loadname, r_skyBoxSuffix[i] );
else Q_snprintf( sidename, sizeof( sidename ), "%s_%s", loadname, r_skyBoxSuffix[i] ); if( !tr.skyboxTextures[i] )
break;
tr.skyboxTextures[i] = GL_LoadTexture( sidename, NULL, 0, TF_CLAMP|TF_SKY );
if( !tr.skyboxTextures[i] ) break;
gEngfuncs.Con_DPrintf( "%s%s%s", skyboxname, r_skyBoxSuffix[i], i != 5 ? ", " : ". " ); gEngfuncs.Con_DPrintf( "%s%s%s", skyboxname, r_skyBoxSuffix[i], i != 5 ? ", " : ". " );
} }

Loading…
Cancel
Save