* Replace "powered by ioq3" text with ui_ioq3 CVAR_ROM

* Guess display aspect based on the desktop resolution
* Sort detected resolutions by...
  + closeness to display aspect
  + ascending width
  + ascending height
* Apply Q3 coding style to resolution detection code
This commit is contained in:
Tim Angus 2007-12-11 00:19:23 +00:00
parent 6b5fbd189d
commit b9ab949ec7
7 changed files with 209 additions and 135 deletions

View file

@ -92,6 +92,7 @@ extern vmCvar_t ui_server16;
extern vmCvar_t ui_cdkey; extern vmCvar_t ui_cdkey;
extern vmCvar_t ui_cdkeychecked; extern vmCvar_t ui_cdkeychecked;
extern vmCvar_t ui_ioq3;
// //

View file

@ -155,6 +155,7 @@ vmCvar_t ui_server15;
vmCvar_t ui_server16; vmCvar_t ui_server16;
vmCvar_t ui_cdkeychecked; vmCvar_t ui_cdkeychecked;
vmCvar_t ui_ioq3;
static cvarTable_t cvarTable[] = { static cvarTable_t cvarTable[] = {
{ &ui_ffa_fraglimit, "ui_ffa_fraglimit", "20", CVAR_ARCHIVE }, { &ui_ffa_fraglimit, "ui_ffa_fraglimit", "20", CVAR_ARCHIVE },
@ -212,7 +213,8 @@ static cvarTable_t cvarTable[] = {
{ &ui_server15, "server15", "", CVAR_ARCHIVE }, { &ui_server15, "server15", "", CVAR_ARCHIVE },
{ &ui_server16, "server16", "", CVAR_ARCHIVE }, { &ui_server16, "server16", "", CVAR_ARCHIVE },
{ &ui_cdkeychecked, "ui_cdkeychecked", "0", CVAR_ROM } { &ui_cdkeychecked, "ui_cdkeychecked", "0", CVAR_ROM },
{ &ui_ioq3, "ui_ioq3", "1", CVAR_ROM }
}; };
static int cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]); static int cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]);

View file

@ -222,10 +222,11 @@ static void Main_MenuDraw( void ) {
} }
if (uis.demoversion) { if (uis.demoversion) {
UI_DrawProportionalString( 320, 412, "DEMO FOR MATURE AUDIENCES DEMO", UI_CENTER|UI_SMALLFONT, color ); UI_DrawProportionalString( 320, 372, "DEMO FOR MATURE AUDIENCES DEMO", UI_CENTER|UI_SMALLFONT, color );
UI_DrawString( 320, 400, "Quake III Arena(c) 1999-2000, Id Software, Inc. All Rights Reserved", UI_CENTER|UI_SMALLFONT, color );
} else {
UI_DrawString( 320, 450, "Quake III Arena(c) 1999-2000, Id Software, Inc. All Rights Reserved", UI_CENTER|UI_SMALLFONT, color );
} }
UI_DrawString( 320, 440, "Quake III Arena(c) 1999-2000, Id Software, Inc. All Rights Reserved", UI_CENTER|UI_SMALLFONT, color );
UI_DrawString( 320, 460, "powered by the ioquake3 engine", UI_CENTER|UI_SMALLFONT, color );
} }

View file

@ -24,66 +24,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
void GraphicsOptions_MenuInit( void ); void GraphicsOptions_MenuInit( void );
static const char *builtin_resolutions[] =
{
"320x240",
"400x300",
"512x384",
"640x480",
"800x600",
"960x720",
"1024x768",
"1152x864",
"1280x1024",
"1600x1200",
"2048x1536",
"856x480 wide screen",
NULL
};
static char resbuf[MAX_STRING_CHARS];
static const char* detected_resolutions[32];
static const char** reslist = builtin_resolutions;
static int use_builtin_resolutions = qtrue;
static int det2builtinres(int mode)
{
int i;
if(use_builtin_resolutions)
return mode;
if(mode < 0)
return -1;
for(i = 0; builtin_resolutions[i]; ++i)
{
if(!strcmp(builtin_resolutions[i], detected_resolutions[mode]))
return i;
}
return -1;
}
static int builtin2detres(int mode)
{
int i;
if(use_builtin_resolutions)
return mode;
if(mode < 0)
return -1;
for(i = 0; detected_resolutions[i]; ++i)
{
if(!strcmp(builtin_resolutions[mode], detected_resolutions[i]))
return i;
}
return -1;
}
/* /*
======================================================================= =======================================================================
@ -378,6 +318,77 @@ static InitialVideoOptions_s s_ivo_templates[] =
#define NUM_IVO_TEMPLATES ( sizeof( s_ivo_templates ) / sizeof( s_ivo_templates[0] ) ) #define NUM_IVO_TEMPLATES ( sizeof( s_ivo_templates ) / sizeof( s_ivo_templates[0] ) )
static const char *builtinResolutions[ ] =
{
"320x240",
"400x300",
"512x384",
"640x480",
"800x600",
"960x720",
"1024x768",
"1152x864",
"1280x1024",
"1600x1200",
"2048x1536",
"856x480 wide screen",
NULL
};
static char resbuf[ MAX_STRING_CHARS ];
static const char* detectedResolutions[ 32 ];
static const char** resolutions = builtinResolutions;
static qboolean resolutionsDetected = qfalse;
/*
=================
GraphicsOptions_FindBuiltinResolution
=================
*/
static int GraphicsOptions_FindBuiltinResolution( int mode )
{
int i;
if( !resolutionsDetected )
return mode;
if( mode < 0 )
return -1;
for( i = 0; builtinResolutions[ i ]; i++ )
{
if( !strcmp( builtinResolutions[ i ], detectedResolutions[ mode ] ) )
return i;
}
return -1;
}
/*
=================
GraphicsOptions_FindDetectedResolution
=================
*/
static int GraphicsOptions_FindDetectedResolution( int mode )
{
int i;
if( !resolutionsDetected )
return mode;
if( mode < 0 )
return -1;
for( i = 0; detectedResolutions[ i ]; i++ )
{
if( !strcmp( builtinResolutions[ mode ], detectedResolutions[ i ] ) )
return i;
}
return -1;
}
/* /*
================= =================
GraphicsOptions_GetInitialVideo GraphicsOptions_GetInitialVideo
@ -541,23 +552,22 @@ static void GraphicsOptions_ApplyChanges( void *unused, int notification )
trap_Cvar_SetValue( "r_picmip", 3 - s_graphicsoptions.tq.curvalue ); trap_Cvar_SetValue( "r_picmip", 3 - s_graphicsoptions.tq.curvalue );
trap_Cvar_SetValue( "r_allowExtensions", s_graphicsoptions.allow_extensions.curvalue ); trap_Cvar_SetValue( "r_allowExtensions", s_graphicsoptions.allow_extensions.curvalue );
if(!use_builtin_resolutions) if( resolutionsDetected )
{ {
// search for builtin mode that matches the detected mode // search for builtin mode that matches the detected mode
int i; int mode = GraphicsOptions_FindBuiltinResolution( s_graphicsoptions.mode.curvalue );
int mode = s_graphicsoptions.mode.curvalue; if( mode == -1 )
i = det2builtinres(mode);
if(i == -1)
{ {
char w[16], h[16]; char w[ 16 ], h[ 16 ];
Q_strncpyz(w, detected_resolutions[mode], sizeof(w)); Q_strncpyz( w, detectedResolutions[ s_graphicsoptions.mode.curvalue ], sizeof( w ) );
*strchr(w, 'x') = 0; *strchr( w, 'x' ) = 0;
Q_strncpyz(h, strchr(detected_resolutions[mode], 'x')+1, sizeof(h)); Q_strncpyz( h,
trap_Cvar_Set( "r_customwidth", w); strchr( detectedResolutions[ s_graphicsoptions.mode.curvalue ], 'x' ) + 1, sizeof( h ) );
trap_Cvar_Set( "r_customheight", h); trap_Cvar_Set( "r_customwidth", w );
trap_Cvar_Set( "r_customheight", h );
} }
trap_Cvar_SetValue( "r_mode", i ); trap_Cvar_SetValue( "r_mode", mode );
} }
else else
trap_Cvar_SetValue( "r_mode", s_graphicsoptions.mode.curvalue ); trap_Cvar_SetValue( "r_mode", s_graphicsoptions.mode.curvalue );
@ -695,15 +705,12 @@ GraphicsOptions_SetMenuItems
*/ */
static void GraphicsOptions_SetMenuItems( void ) static void GraphicsOptions_SetMenuItems( void )
{ {
s_graphicsoptions.mode.curvalue = trap_Cvar_VariableValue( "r_mode" ); s_graphicsoptions.mode.curvalue =
s_graphicsoptions.mode.curvalue = builtin2detres(s_graphicsoptions.mode.curvalue); GraphicsOptions_FindDetectedResolution( trap_Cvar_VariableValue( "r_mode" ) );
if ( s_graphicsoptions.mode.curvalue < 0 ) if ( s_graphicsoptions.mode.curvalue < 0 )
{ {
if(use_builtin_resolutions) if( resolutionsDetected )
{
s_graphicsoptions.mode.curvalue = 3;
}
else
{ {
int i; int i;
char buf[MAX_STRING_CHARS]; char buf[MAX_STRING_CHARS];
@ -712,9 +719,9 @@ static void GraphicsOptions_SetMenuItems( void )
buf[strlen(buf)] = 'x'; buf[strlen(buf)] = 'x';
trap_Cvar_VariableStringBuffer("r_customheight", buf+strlen(buf), sizeof(buf)-strlen(buf)); trap_Cvar_VariableStringBuffer("r_customheight", buf+strlen(buf), sizeof(buf)-strlen(buf));
for(i = 0; detected_resolutions[i]; ++i) for(i = 0; detectedResolutions[i]; ++i)
{ {
if(!strcmp(buf, detected_resolutions[i])) if(!strcmp(buf, detectedResolutions[i]))
{ {
s_graphicsoptions.mode.curvalue = i; s_graphicsoptions.mode.curvalue = i;
break; break;
@ -723,6 +730,10 @@ static void GraphicsOptions_SetMenuItems( void )
if ( s_graphicsoptions.mode.curvalue < 0 ) if ( s_graphicsoptions.mode.curvalue < 0 )
s_graphicsoptions.mode.curvalue = 0; s_graphicsoptions.mode.curvalue = 0;
} }
else
{
s_graphicsoptions.mode.curvalue = 3;
}
} }
s_graphicsoptions.fs.curvalue = trap_Cvar_VariableValue("r_fullscreen"); s_graphicsoptions.fs.curvalue = trap_Cvar_VariableValue("r_fullscreen");
s_graphicsoptions.allow_extensions.curvalue = trap_Cvar_VariableValue("r_allowExtensions"); s_graphicsoptions.allow_extensions.curvalue = trap_Cvar_VariableValue("r_allowExtensions");
@ -878,18 +889,20 @@ void GraphicsOptions_MenuInit( void )
if(*resbuf) if(*resbuf)
{ {
char* s = resbuf; char* s = resbuf;
unsigned i = 0; unsigned int i = 0;
while( s && i < sizeof(detected_resolutions)/sizeof(detected_resolutions[0])-1) while( s && i < sizeof(detectedResolutions)/sizeof(detectedResolutions[0])-1)
{ {
detected_resolutions[i++] = s; detectedResolutions[i++] = s;
s = strchr(s, ' '); s = strchr(s, ' ');
if(s) *s++ = '\0'; if( s )
*s++ = '\0';
} }
detected_resolutions[i] = NULL; detectedResolutions[ i ] = NULL;
if(i)
if( i > 0 )
{ {
reslist = detected_resolutions; resolutions = detectedResolutions;
use_builtin_resolutions = 0; resolutionsDetected = qtrue;
} }
} }
@ -997,7 +1010,7 @@ void GraphicsOptions_MenuInit( void )
s_graphicsoptions.mode.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT; s_graphicsoptions.mode.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
s_graphicsoptions.mode.generic.x = 400; s_graphicsoptions.mode.generic.x = 400;
s_graphicsoptions.mode.generic.y = y; s_graphicsoptions.mode.generic.y = y;
s_graphicsoptions.mode.itemnames = reslist; s_graphicsoptions.mode.itemnames = resolutions;
s_graphicsoptions.mode.generic.callback = GraphicsOptions_Event; s_graphicsoptions.mode.generic.callback = GraphicsOptions_Event;
s_graphicsoptions.mode.generic.id = ID_MODE; s_graphicsoptions.mode.generic.id = ID_MODE;
y += BIGCHAR_HEIGHT+2; y += BIGCHAR_HEIGHT+2;

View file

@ -23,9 +23,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h" #include "tr_local.h"
glconfig_t glConfig; glconfig_t glConfig;
qboolean textureFilterAnisotropic = qfalse; qboolean textureFilterAnisotropic = qfalse;
int maxAnisotropy = 0; int maxAnisotropy = 0;
float displayAspect = 0.0f;
glstate_t glState; glstate_t glState;

View file

@ -973,8 +973,9 @@ extern glstate_t glState; // outside of TR since it shouldn't be cleared during
// These two variables should live inside glConfig but can't because of compatibility issues to the original ID vms. // These two variables should live inside glConfig but can't because of compatibility issues to the original ID vms.
// If you release a stand-alone game and your mod uses tr_types.h from this build you can safely move them to // If you release a stand-alone game and your mod uses tr_types.h from this build you can safely move them to
// the glconfig_t struct. // the glconfig_t struct.
extern qboolean textureFilterAnisotropic; extern qboolean textureFilterAnisotropic;
extern int maxAnisotropy; extern int maxAnisotropy;
extern float displayAspect;
// //

View file

@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#include "../renderer/tr_local.h" #include "../renderer/tr_local.h"
#include "../client/client.h" #include "../client/client.h"
@ -110,44 +111,79 @@ void GLimp_LogComment( char *comment )
{ {
} }
static void set_available_modes(void) /*
===============
GLimp_CompareModes
===============
*/
static int GLimp_CompareModes( const void *a, const void *b )
{ {
char buf[MAX_STRING_CHARS]; const float ASPECT_EPSILON = 0.001f;
SDL_Rect **modes; SDL_Rect *modeA = *(SDL_Rect **)a;
size_t len = 0; SDL_Rect *modeB = *(SDL_Rect **)b;
int i; float aspectDiffA = fabs( ( (float)modeA->w / (float)modeA->h ) - displayAspect );
float aspectDiffB = fabs( ( (float)modeB->w / (float)modeB->h ) - displayAspect );
float aspectDiffsDiff = aspectDiffA - aspectDiffB;
modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); if( aspectDiffsDiff > ASPECT_EPSILON )
return 1;
else if( aspectDiffsDiff < -ASPECT_EPSILON )
return -1;
else
{
if( modeA->w == modeB->w )
return modeA->h - modeB->h;
else
return modeA->w - modeB->w;
}
}
if (!modes) /*
{ ===============
ri.Printf( PRINT_WARNING, "Can't get list of available modes\n"); GLimp_DetectAvailableModes
return; ===============
} */
static void GLimp_DetectAvailableModes(void)
{
char buf[ MAX_STRING_CHARS ] = { 0 };
SDL_Rect **modes;
int numModes;
int i;
if (modes == (SDL_Rect **)-1) modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN );
{
ri.Printf( PRINT_ALL, "Display supports any resolution\n");
return; // can set any resolution
}
for (i = 0; modes[i]; ++i) if( !modes )
{ {
if(snprintf(NULL, 0, "%ux%u ", modes[i]->w, modes[i]->h) < (int)sizeof(buf)-len) ri.Printf( PRINT_WARNING, "Can't get list of available modes\n" );
{ return;
len += sprintf(buf+len, "%ux%u ", modes[i]->w, modes[i]->h); }
}
else if( modes == (SDL_Rect **)-1 )
{ {
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i]->w, modes[i]->h); ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
} return; // can set any resolution
} }
if(len)
{ for( numModes = 0; modes[ numModes ]; numModes++ );
buf[strlen(buf)-1] = 0;
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf); qsort( modes, numModes, sizeof( SDL_Rect* ), GLimp_CompareModes );
ri.Cvar_Set( "r_availableModes", buf );
} for( i = 0; i < numModes; i++ )
{
const char *newModeString = va( "%ux%u ", modes[ i ]->w, modes[ i ]->h );
if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) )
Q_strcat( buf, sizeof( buf ), newModeString );
else
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i]->w, modes[i]->h );
}
if( *buf )
{
buf[ strlen( buf ) - 1 ] = 0;
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
ri.Cvar_Set( "r_availableModes", buf );
}
} }
/* /*
@ -164,9 +200,28 @@ static int GLimp_SetMode( int mode, qboolean fullscreen )
int i = 0; int i = 0;
SDL_Surface *vidscreen = NULL; SDL_Surface *vidscreen = NULL;
Uint32 flags = SDL_OPENGL; Uint32 flags = SDL_OPENGL;
const SDL_VideoInfo *videoInfo;
ri.Printf( PRINT_ALL, "Initializing OpenGL display\n"); ri.Printf( PRINT_ALL, "Initializing OpenGL display\n");
if( displayAspect == 0.0f )
{
#if !SDL_VERSION_ATLEAST(1, 2, 10)
// 1.2.10 is needed to get the desktop resolution
displayAspect = 4.0f / 3.0f;
#elif MINSDL_PATCH >= 10
# error Ifdeffery no longer necessary, please remove
#else
// Guess the display aspect ratio through the desktop resolution
// by assuming (relatively safely) that it is set at or close to
// the display's native aspect ratio
videoInfo = SDL_GetVideoInfo( );
displayAspect = (float)videoInfo->current_w / (float)videoInfo->current_h;
#endif
ri.Printf( PRINT_ALL, "Estimated display aspect: %.3f\n", displayAspect );
}
ri.Printf (PRINT_ALL, "...setting mode %d:", mode ); ri.Printf (PRINT_ALL, "...setting mode %d:", mode );
if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) ) if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) )
@ -315,7 +370,7 @@ static int GLimp_SetMode( int mode, qboolean fullscreen )
break; break;
} }
set_available_modes(); GLimp_DetectAvailableModes();
if (!vidscreen) if (!vidscreen)
{ {