Add SDL2 compile option.

This sets SDL2 as the default as well.
This commit is contained in:
Joey Herguth
2021-08-25 18:51:53 -07:00
parent f507a7a87a
commit c2250b7fca
12 changed files with 683 additions and 48 deletions

View File

@@ -240,6 +240,10 @@ ifndef DEBUG_CFLAGS
DEBUG_CFLAGS=-g -O0
endif
ifndef SDL_VERSION
SDL_VERSION=2
endif
#############################################################################
BD=$(BUILD_DIR)/debug-$(PLATFORM)-$(ARCH)
@@ -274,7 +278,11 @@ Q3LCCETCDIR=$(MOUNT_DIR)/tools/lcc/etc
Q3LCCSRCDIR=$(MOUNT_DIR)/tools/lcc/src
LOKISETUPDIR=misc/setup
NSISDIR=misc/nsis
SDLHDIR=$(MOUNT_DIR)/SDL12
ifeq ($(SDL_VERSION),2)
SDLHDIR=$(MOUNT_DIR)/SDL2
else
SDLHDIR=$(MOUNT_DIR)/SDL12
endif
LIBSDIR=$(MOUNT_DIR)/libs
bin_path=$(shell which $(1) 2> /dev/null)
@@ -288,15 +296,27 @@ ifneq ($(BUILD_CLIENT),0)
CURL_LIBS=$(shell pkg-config --silence-errors --libs libcurl)
OPENAL_CFLAGS=$(shell pkg-config --silence-errors --cflags openal)
OPENAL_LIBS=$(shell pkg-config --silence-errors --libs openal)
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//')
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl)
ifeq ($(SDL_VERSION),2)
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl2|sed 's/-Dmain=SDL_main//')
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl2)
else
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//')
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl)
endif
FREETYPE_CFLAGS=$(shell pkg-config --silence-errors --cflags freetype2)
endif
# Use sdl-config if all else fails
ifeq ($(SDL_CFLAGS),)
ifneq ($(call bin_path, sdl-config),)
SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LIBS=$(shell sdl-config --libs)
ifeq ($(SDL_VERSION),2)
ifneq ($(call bin_path, sdl2-config),)
SDL_CFLAGS=$(shell sdl2-config --cflags)
SDL_LIBS=$(shell sdl2-config --libs)
endif
else
ifneq ($(call bin_path, sdl-config),)
SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LIBS=$(shell sdl-config --libs)
endif
endif
endif
endif
@@ -495,11 +515,17 @@ ifeq ($(PLATFORM),darwin)
# We copy sdlmain before ranlib'ing it so that subversion doesn't think
# the file has been modified by each build.
LIBSDLMAIN=$(B)/libSDLmain.a
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDLmain.a
CLIENT_LIBS += -framework IOKit \
$(LIBSDIR)/macosx/libSDL-1.2.0.dylib
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
ifeq ($(SDL_VERSION),2)
LIBSDLMAIN=$(B)/libSDL2main.a
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDL2main.a
CLIENT_LIBS += -framework IOKit $(LIBSDIR)/macosx/libSDL2-2.0.0.dylib
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL2-2.0.0.dylib
else
LIBSDLMAIN=$(B)/libSDLmain.a
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDLmain.a
CLIENT_LIBS += -framework IOKit $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
endif
OPTIMIZEVM += -falign-loops=16
OPTIMIZE = $(OPTIMIZEVM) -ffast-math
@@ -643,24 +669,44 @@ ifeq ($(PLATFORM),mingw32)
ifeq ($(USE_LOCAL_HEADERS),1)
CLIENT_CFLAGS += -I$(SDLHDIR)/include
ifeq ($(ARCH),x86)
CLIENT_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
$(LIBSDIR)/win32/libSDL.dll.a
RENDERER_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
$(LIBSDIR)/win32/libSDL.dll.a
SDLDLL=SDL.dll
ifeq ($(SDL_VERSION),2)
ifeq ($(ARCH),x86)
CLIENT_LIBS += $(LIBSDIR)/win32/libSDL2main.a \
$(LIBSDIR)/win32/libSDL2.dll.a
RENDERER_LIBS += $(LIBSDIR)/win32/libSDL2main.a \
$(LIBSDIR)/win32/libSDL2.dll.a
SDLDLL=SDL2.dll
else
CLIENT_LIBS += $(LIBSDIR)/win64/libSDL264main.a \
$(LIBSDIR)/win64/libSDL264.dll.a
RENDERER_LIBS += $(LIBSDIR)/win64/libSDL264main.a \
$(LIBSDIR)/win64/libSDL264.dll.a
SDLDLL=SDL264.dll
endif
else
CLIENT_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
$(LIBSDIR)/win64/libSDL64.dll.a
RENDERER_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
$(LIBSDIR)/win64/libSDL64.dll.a
SDLDLL=SDL64.dll
ifeq ($(ARCH),x86)
CLIENT_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
$(LIBSDIR)/win32/libSDL.dll.a
RENDERER_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
$(LIBSDIR)/win32/libSDL.dll.a
SDLDLL=SDL.dll
else
CLIENT_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
$(LIBSDIR)/win64/libSDL64.dll.a
RENDERER_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
$(LIBSDIR)/win64/libSDL64.dll.a
SDLDLL=SDL64.dll
endif
endif
else
CLIENT_CFLAGS += $(SDL_CFLAGS)
CLIENT_LIBS += $(SDL_LIBS)
RENDERER_LIBS += $(SDL_LIBS)
SDLDLL=SDL.dll
ifeq ($(SDL_VERSION),2)
SDLDLL=SDL2.dll
else
SDLDLL=SDL.dll
endif
endif
else # ifeq mingw32

View File

@@ -33,6 +33,9 @@ BUILD_RENDERER_OPENGL2=0
# You can disable the renderer libraries and build in the OA renderer by default
USE_RENDERER_DLOPEN=0
# Choose version 1 or 2
SDL_VERSION=2
ifndef USE_CONSOLE_WINDOW
USE_CONSOLE_WINDOW=1 # use an early console window (WIN32 only)
endif

View File

@@ -21,6 +21,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "client.h"
#ifdef USE_LOCAL_HEADERS
# include "SDL.h"
#else
# include <SDL.h>
#endif
/*
key up events are sent even if in console mode
@@ -401,7 +407,11 @@ void Field_Paste( field_t *edit ) {
char *cbd;
int pasteLen, i;
#if SDL_MAJOR_VERSION == 2
cbd = SDL_GetClipboardText();
#else
cbd = Sys_GetClipboardData();
#endif
if ( !cbd ) {
return;
@@ -413,7 +423,11 @@ void Field_Paste( field_t *edit ) {
Field_CharEvent( edit, cbd[i] );
}
#if SDL_MAJOR_VERSION == 2
SDL_free( cbd );
#else
Z_Free( cbd );
#endif
}
/*

View File

@@ -584,7 +584,11 @@ CL_GetClipboardData
static void CL_GetClipboardData( char *buf, int buflen ) {
char *cbd;
#if SDL_MAJOR_VERSION == 2
cbd = Sys_GetClipboardData2();
#else
cbd = Sys_GetClipboardData();
#endif
if ( !cbd ) {
*buf = 0;

View File

@@ -169,7 +169,11 @@ typedef struct {
void (*CL_WriteAVIVideoFrame)( const byte *buffer, int size );
// input event handling
#if SDL_MAJOR_VERSION == 2
void (*IN_Init)( void *windowData );
#else
void (*IN_Init)( void );
#endif
void (*IN_Shutdown)( void );
void (*IN_Restart)( void );

View File

@@ -29,6 +29,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../renderercommon/tr_common.h"
#include "../qcommon/qcommon.h"
#if SDL_MAJOR_VERSION == 2
extern SDL_Window *SDL_window;
#endif
#ifdef _WIN32
// leilei - 3dfx gamma fix
BOOL ( WINAPI * qwglGetDeviceGammaRamp3DFX)( HDC, LPVOID );
@@ -103,7 +107,11 @@ void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned
else
#endif
{
SDL_SetGammaRamp(table[0], table[1], table[2]);
#if SDL_MAJOR_VERSION == 2
SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]);
#else
SDL_SetGammaRamp(table[0], table[1], table[2]);
#endif
}
}

View File

@@ -47,7 +47,9 @@ typedef void *QGLContext;
#define GLimp_SetCurrentContext(ctx)
#endif
#if SDL_MAJOR_VERSION != 2
static QGLContext opengl_context;
#endif
int tvMode; // leilei - tvmode
int tvWidth;
@@ -69,8 +71,13 @@ typedef enum
RSERR_UNKNOWN
} rserr_t;
#if SDL_MAJOR_VERSION == 2
SDL_Window *SDL_window = NULL;
SDL_GLContext SDL_glContext = NULL;
#else
static SDL_Surface *screen = NULL;
static const SDL_VideoInfo *videoInfo = NULL;
#endif
cvar_t *r_allowSoftwareGL; // Don't abort out if a hardware visual can't be obtained
cvar_t *r_tvMode; // leilei - tv mode - force 480i rendering, which is then stretched and interlaced
@@ -100,7 +107,9 @@ void GLimp_Shutdown( void )
ri.IN_Shutdown();
SDL_QuitSubSystem( SDL_INIT_VIDEO );
#if SDL_MAJOR_VERSION != 2
screen = NULL;
#endif
}
/*
@@ -112,7 +121,11 @@ Minimize the game so that user is back at the desktop
*/
void GLimp_Minimize(void)
{
#if SDL_MAJOR_VERSION == 2
SDL_MinimizeWindow( SDL_window );
#else
SDL_WM_IconifyWindow();
#endif
}
@@ -133,8 +146,13 @@ GLimp_CompareModes
static int GLimp_CompareModes( const void *a, const void *b )
{
const float ASPECT_EPSILON = 0.001f;
#if SDL_MAJOR_VERSION == 2
SDL_Rect *modeA = (SDL_Rect *)a;
SDL_Rect *modeB = (SDL_Rect *)b;
#else
SDL_Rect *modeA = *(SDL_Rect **)a;
SDL_Rect *modeB = *(SDL_Rect **)b;
#endif
float aspectA = (float)modeA->w / (float)modeA->h;
float aspectB = (float)modeB->w / (float)modeB->h;
int areaA = modeA->w * modeA->h;
@@ -160,10 +178,59 @@ GLimp_DetectAvailableModes
static void GLimp_DetectAvailableModes(void)
{
char buf[ MAX_STRING_CHARS ] = { 0 };
#if SDL_MAJOR_VERSION == 2
SDL_Rect modes[ 128 ];
#else
SDL_Rect **modes;
int numModes;
#endif
int numModes = 0;
int i;
#if SDL_MAJOR_VERSION == 2
int display = SDL_GetWindowDisplayIndex( SDL_window );
SDL_DisplayMode windowMode;
if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 )
{
ri.Printf( PRINT_WARNING, "Couldn't get window display mode, no resolutions detected\n" );
return;
}
for( i = 0; i < SDL_GetNumDisplayModes( display ); i++ )
{
SDL_DisplayMode mode;
if( SDL_GetDisplayMode( display, i, &mode ) < 0 )
continue;
if( !mode.w || !mode.h )
{
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
return;
}
if( windowMode.format != mode.format )
continue;
modes[ numModes ].w = mode.w;
modes[ numModes ].h = mode.h;
numModes++;
}
if( numModes > 1 )
qsort( modes, numModes, sizeof( SDL_Rect ), GLimp_CompareModes );
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 );
}
#else
modes = SDL_ListModes( videoInfo->vfmt, SDL_OPENGL | SDL_FULLSCREEN );
if( !modes )
@@ -192,6 +259,7 @@ static void GLimp_DetectAvailableModes(void)
else
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i]->w, modes[i]->h );
}
#endif
if( *buf )
{
@@ -215,14 +283,45 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
int accumbits; // leilei - motionblur
int samples;
int i = 0;
SDL_Surface *icon = NULL;
#if SDL_MAJOR_VERSION == 2
Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
int display = 0;
SDL_DisplayMode desktopMode;
int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
#else
SDL_Surface *vidscreen = NULL;
Uint32 flags = SDL_OPENGL;
#endif
ri.Printf( PRINT_ALL, "Initializing OpenGL display\n");
if ( r_allowResize->integer )
#if SDL_MAJOR_VERSION == 2
flags |= SDL_WINDOW_RESIZABLE;
#else
flags |= SDL_RESIZABLE;
#endif
#if SDL_MAJOR_VERSION == 2
// If a window exists, note its display index
if( SDL_window != NULL )
display = SDL_GetWindowDisplayIndex( SDL_window );
if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
{
displayAspect = (float)desktopMode.w / (float)desktopMode.h;
ri.Printf( PRINT_ALL, "Display aspect: %.3f\n", displayAspect );
}
else
{
Com_Memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );
ri.Printf( PRINT_ALL,
"Cannot determine display aspect, assuming 1.333\n" );
}
#else
if( videoInfo == NULL )
{
static SDL_VideoInfo sVideoInfo;
@@ -252,17 +351,26 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
"Cannot estimate display aspect, assuming 1.333\n" );
}
}
#endif
ri.Printf (PRINT_ALL, "...setting mode %d:", mode );
if (mode == -2)
{
// use desktop video resolution
if( videoInfo->current_h > 0 )
#if SDL_MAJOR_VERSION == 2
if ( desktopMode.h > 0 )
{
glConfig.vidWidth = desktopMode.w;
glConfig.vidHeight = desktopMode.h;
}
#else
if ( videoInfo->current_h > 0 )
{
glConfig.vidWidth = videoInfo->current_w;
glConfig.vidHeight = videoInfo->current_h;
}
#endif
else
{
glConfig.vidWidth = 640;
@@ -280,15 +388,40 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
}
ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight);
#if SDL_MAJOR_VERSION == 2
// Destroy existing state if it exists
if( SDL_glContext != NULL )
{
SDL_GL_DeleteContext( SDL_glContext );
SDL_glContext = NULL;
}
if( SDL_window != NULL )
{
SDL_GetWindowPosition( SDL_window, &x, &y );
ri.Printf( PRINT_DEVELOPER, "Existing window at %dx%d before being destroyed\n", x, y );
SDL_DestroyWindow( SDL_window );
SDL_window = NULL;
}
#endif
if (fullscreen)
{
#if SDL_MAJOR_VERSION == 2
flags |= SDL_WINDOW_FULLSCREEN;
#else
flags |= SDL_FULLSCREEN;
#endif
glConfig.isFullscreen = qtrue;
}
else
{
if (noborder)
#if SDL_MAJOR_VERSION == 2
flags |= SDL_WINDOW_BORDERLESS;
#else
flags |= SDL_NOFRAME;
#endif
glConfig.isFullscreen = qfalse;
}
@@ -301,6 +434,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
depthbits = 24;
else
depthbits = r_depthbits->value;
stencilbits = r_stencilbits->value;
samples = r_ext_multisample->value;
@@ -419,13 +553,14 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
}
}
#endif
#if SDL_MAJOR_VERSION != 2
if( SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, r_swapInterval->integer ) < 0 )
ri.Printf( PRINT_ALL, "r_swapInterval requires libSDL >= 1.2.10\n" );
#endif
#ifdef USE_ICON
{
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(
icon = SDL_CreateRGBSurfaceFrom(
(void *)CLIENT_WINDOW_ICON.pixel_data,
CLIENT_WINDOW_ICON.width,
CLIENT_WINDOW_ICON.height,
@@ -438,11 +573,52 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
#endif
);
#if SDL_MAJOR_VERSION != 2
SDL_WM_SetIcon( icon, NULL );
SDL_FreeSurface( icon );
#endif
}
#endif
#if SDL_MAJOR_VERSION == 2
if( ( SDL_window = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
glConfig.vidWidth, glConfig.vidHeight, flags ) ) == 0 )
{
ri.Printf( PRINT_DEVELOPER, "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
continue;
}
if( fullscreen )
{
SDL_DisplayMode mode;
switch( tcolorbits )
{
case 16: mode.format = SDL_PIXELFORMAT_RGB565; break;
case 24: mode.format = SDL_PIXELFORMAT_RGB24; break;
default: ri.Printf( PRINT_DEVELOPER, "tcolorbits is %d, can't fullscreen\n", tcolorbits ); continue;
}
mode.w = glConfig.vidWidth;
mode.h = glConfig.vidHeight;
mode.refresh_rate = glConfig.displayFrequency = ri.Cvar_VariableIntegerValue( "r_displayRefresh" );
mode.driverdata = NULL;
if( SDL_SetWindowDisplayMode( SDL_window, &mode ) < 0 )
{
ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
continue;
}
}
SDL_SetWindowIcon( SDL_window, icon );
if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
{
ri.Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
continue;
}
SDL_GL_SetSwapInterval( r_swapInterval->integer );
#else
SDL_WM_SetCaption(CLIENT_WINDOW_TITLE, CLIENT_WINDOW_MIN_TITLE);
SDL_ShowCursor(0);
@@ -453,7 +629,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
}
opengl_context = GLimp_GetCurrentContext();
#endif
ri.Printf( PRINT_ALL, "Using %d/%d/%d Color bits, %d depth, %d stencil display.\n",
sdlcolorbits, sdlcolorbits, sdlcolorbits, tdepthbits, tstencilbits);
@@ -462,14 +638,18 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
glConfig.stencilBits = tstencilbits;
break;
}
SDL_FreeSurface( icon );
GLimp_DetectAvailableModes();
#if SDL_MAJOR_VERSION != 2
if (!vidscreen)
{
ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
return RSERR_INVALID_MODE;
}
#endif
//
// leilei - TV MODE
@@ -509,30 +689,21 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
if( r_tvModeForceAspect->integer ){
float ttw = (float)glConfig.vidWidth / ((float)tvWidth * (float)((float)glConfig.vidHeight/(float)tvHeight)); // 640 / 853 = 0.75 = ASPECT VALUE
tvAspectW = ttw; // let's try this first to see if we can get it to our renderer
//tvAspectW = 0.75f; // let's try this first to see if we can get it to our renderer
}
}
// leilei - tv mode hack end
#if SDL_MAJOR_VERSION != 2
screen = vidscreen;
#endif
if( r_tvModeAspect->integer ){
if( r_tvModeAspect->integer ) {
float aspe = 640.0f / tvWidth;
glConfig.vidWidth = tvWidth * aspe;
glConfig.vidHeight = tvHeight * aspe;
}
// then change the gl port..
}
// then change the gl port..
glstring = (char *) qglGetString (GL_RENDERER);
ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring );
@@ -551,7 +722,11 @@ static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qbool
if (!SDL_WasInit(SDL_INIT_VIDEO))
{
#if SDL_MAJOR_VERSION == 2
const char *driverName;
#else
char driverName[ 64 ];
#endif
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
@@ -560,7 +735,11 @@ static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qbool
return qfalse;
}
#if SDL_MAJOR_VERSION == 2
driverName = SDL_GetCurrentVideoDriver();
#else
SDL_VideoDriverName( driverName, sizeof( driverName ) - 1 );
#endif
ri.Printf( PRINT_ALL, "SDL using driver \"%s\"\n", driverName );
ri.Cvar_Set( "r_sdlDriver", driverName );
}
@@ -837,6 +1016,12 @@ success:
// This values force the UI to disable driver selection
glConfig.driverType = GLDRV_ICD;
glConfig.hardwareType = GLHW_GENERIC;
#if SDL_MAJOR_VERSION == 2
// Only using SDL_SetWindowBrightness to determine if hardware gamma is supported
glConfig.deviceSupportsGamma = !r_ignorehwgamma->integer &&
SDL_SetWindowBrightness( SDL_window, 1.0f ) >= 0;
#else
glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;
// Mysteriously, if you use an NVidia graphics card and multiple monitors,
@@ -844,7 +1029,7 @@ success:
// again and you get the correct answer. This is a suspected driver bug, see
// http://bugzilla.icculus.org/show_bug.cgi?id=4316
glConfig.deviceSupportsGamma = SDL_SetGamma( 1.0f, 1.0f, 1.0f ) >= 0;
#endif
#ifdef _WIN32
// leilei - 3dfx gamma
@@ -874,7 +1059,11 @@ success:
ri.Cvar_Get( "r_availableModes", "", CVAR_ROM );
// This depends on SDL_INIT_VIDEO, hence having it here
#if SDL_MAJOR_VERSION == 2
ri.IN_Init( SDL_window );
#else
ri.IN_Init( );
#endif
#if defined( _WIN32 ) && defined( USE_CONSOLE_WINDOW )
// leilei - hide our console window
@@ -895,7 +1084,11 @@ void GLimp_EndFrame( void )
// don't flip if drawing to front buffer
if ( Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) != 0 )
{
#if SDL_MAJOR_VERSION == 2
SDL_GL_SwapWindow( SDL_window );
#else
SDL_GL_SwapBuffers();
#endif
}
if( r_fullscreen->modified )
@@ -903,12 +1096,17 @@ void GLimp_EndFrame( void )
qboolean fullscreen;
qboolean needToToggle = qtrue;
qboolean sdlToggled = qfalse;
#if SDL_MAJOR_VERSION == 2
fullscreen = !!( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_FULLSCREEN );
#else
SDL_Surface *s = SDL_GetVideoSurface( );
if( s )
{
// Find out the current state
fullscreen = !!( s->flags & SDL_FULLSCREEN );
#endif
if( r_fullscreen->integer && ri.Cvar_VariableIntegerValue( "in_nograb" ) )
{
@@ -921,8 +1119,12 @@ void GLimp_EndFrame( void )
needToToggle = !!r_fullscreen->integer != fullscreen;
if( needToToggle )
#if SDL_MAJOR_VERSION == 2
sdlToggled = SDL_SetWindowFullscreen( SDL_window, r_fullscreen->integer ) >= 0;
#else
sdlToggled = SDL_WM_ToggleFullScreen( s );
}
#endif
if( needToToggle )
{

View File

@@ -53,7 +53,9 @@ static SDL_Joystick *stick = NULL;
static qboolean mouseAvailable = qfalse;
static qboolean mouseActive = qfalse;
#if SDL_MAJOR_VERSION != 2
static qboolean keyRepeatEnabled = qfalse;
#endif
static cvar_t *in_mouse = NULL;
#ifdef MACOS_X_ACCELERATION_HACK
@@ -70,6 +72,10 @@ static cvar_t *in_joystickUseAnalog = NULL;
static int vidRestartTime = 0;
#if SDL_MAJOR_VERSION == 2
static SDL_Window *SDL_window = NULL;
#endif
#define CTRL(a) ((a)-'a'+1)
/*
@@ -77,7 +83,11 @@ static int vidRestartTime = 0;
IN_PrintKey
===============
*/
#if SDL_MAJOR_VERSION == 2
static void IN_PrintKey( const SDL_Keysym *keysym, keyNum_t key, qboolean down )
#else
static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down )
#endif
{
if( down )
Com_Printf( "+ " );
@@ -93,15 +103,21 @@ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down )
if( keysym->mod & KMOD_RCTRL ) Com_Printf( " KMOD_RCTRL" );
if( keysym->mod & KMOD_LALT ) Com_Printf( " KMOD_LALT" );
if( keysym->mod & KMOD_RALT ) Com_Printf( " KMOD_RALT" );
#if SDL_MAJOR_VERSION == 2
if( keysym->mod & KMOD_LGUI ) Com_Printf( " KMOD_LGUI" );
if( keysym->mod & KMOD_RGUI ) Com_Printf( " KMOD_RGUI" );
#else
if( keysym->mod & KMOD_LMETA ) Com_Printf( " KMOD_LMETA" );
if( keysym->mod & KMOD_RMETA ) Com_Printf( " KMOD_RMETA" );
#endif
if( keysym->mod & KMOD_NUM ) Com_Printf( " KMOD_NUM" );
if( keysym->mod & KMOD_CAPS ) Com_Printf( " KMOD_CAPS" );
if( keysym->mod & KMOD_MODE ) Com_Printf( " KMOD_MODE" );
if( keysym->mod & KMOD_RESERVED ) Com_Printf( " KMOD_RESERVED" );
Com_Printf( " Q:0x%02x(%s)", key, Key_KeynumToString( key ) );
Com_Printf( " Q:0x%02x(%s)\n", key, Key_KeynumToString( key ) );
#if SDL_MAJOR_VERSION != 2
if( keysym->unicode )
{
Com_Printf( " U:0x%02x", keysym->unicode );
@@ -109,6 +125,7 @@ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down )
if( keysym->unicode > ' ' && keysym->unicode < '~' )
Com_Printf( "(%c)", (char)keysym->unicode );
}
#endif
Com_Printf( "\n" );
}
@@ -211,6 +228,108 @@ static qboolean IN_IsConsoleKey( keyNum_t key, const unsigned char character )
IN_TranslateSDLToQ3Key
===============
*/
#if SDL_MAJOR_VERSION == 2
static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
{
keyNum_t key = 0;
if( keysym->sym >= SDLK_SPACE && keysym->sym < SDLK_DELETE )
{
// These happen to match the ASCII chars
key = (int)keysym->sym;
}
else
{
switch( keysym->sym )
{
case SDLK_PAGEUP: key = K_PGUP; break;
case SDLK_KP_9: key = K_KP_PGUP; break;
case SDLK_PAGEDOWN: key = K_PGDN; break;
case SDLK_KP_3: key = K_KP_PGDN; break;
case SDLK_KP_7: key = K_KP_HOME; break;
case SDLK_HOME: key = K_HOME; break;
case SDLK_KP_1: key = K_KP_END; break;
case SDLK_END: key = K_END; break;
case SDLK_KP_4: key = K_KP_LEFTARROW; break;
case SDLK_LEFT: key = K_LEFTARROW; break;
case SDLK_KP_6: key = K_KP_RIGHTARROW; break;
case SDLK_RIGHT: key = K_RIGHTARROW; break;
case SDLK_KP_2: key = K_KP_DOWNARROW; break;
case SDLK_DOWN: key = K_DOWNARROW; break;
case SDLK_KP_8: key = K_KP_UPARROW; break;
case SDLK_UP: key = K_UPARROW; break;
case SDLK_ESCAPE: key = K_ESCAPE; break;
case SDLK_KP_ENTER: key = K_KP_ENTER; break;
case SDLK_RETURN: key = K_ENTER; break;
case SDLK_TAB: key = K_TAB; break;
case SDLK_F1: key = K_F1; break;
case SDLK_F2: key = K_F2; break;
case SDLK_F3: key = K_F3; break;
case SDLK_F4: key = K_F4; break;
case SDLK_F5: key = K_F5; break;
case SDLK_F6: key = K_F6; break;
case SDLK_F7: key = K_F7; break;
case SDLK_F8: key = K_F8; break;
case SDLK_F9: key = K_F9; break;
case SDLK_F10: key = K_F10; break;
case SDLK_F11: key = K_F11; break;
case SDLK_F12: key = K_F12; break;
case SDLK_F13: key = K_F13; break;
case SDLK_F14: key = K_F14; break;
case SDLK_F15: key = K_F15; break;
case SDLK_BACKSPACE: key = K_BACKSPACE; break;
case SDLK_KP_PERIOD: key = K_KP_DEL; break;
case SDLK_DELETE: key = K_DEL; break;
case SDLK_PAUSE: key = K_PAUSE; break;
case SDLK_LSHIFT:
case SDLK_RSHIFT: key = K_SHIFT; break;
case SDLK_LCTRL:
case SDLK_RCTRL: key = K_CTRL; break;
case SDLK_RGUI:
case SDLK_LGUI: key = K_COMMAND; break;
case SDLK_RALT:
case SDLK_LALT: key = K_ALT; break;
case SDLK_KP_5: key = K_KP_5; break;
case SDLK_INSERT: key = K_INS; break;
case SDLK_KP_0: key = K_KP_INS; break;
case SDLK_KP_MULTIPLY: key = K_KP_STAR; break;
case SDLK_KP_PLUS: key = K_KP_PLUS; break;
case SDLK_KP_MINUS: key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: key = K_KP_SLASH; break;
case SDLK_MODE: key = K_MODE; break;
case SDLK_HELP: key = K_HELP; break;
case SDLK_PRINTSCREEN: key = K_PRINT; break;
case SDLK_SYSREQ: key = K_SYSREQ; break;
case SDLK_MENU: key = K_MENU; break;
case SDLK_POWER: key = K_POWER; break;
case SDLK_UNDO: key = K_UNDO; break;
case SDLK_SCROLLLOCK: key = K_SCROLLOCK; break;
case SDLK_CAPSLOCK: key = K_CAPSLOCK; break;
default:
break;
}
}
if( in_keyboardDebug->integer )
IN_PrintKey( keysym, key, down );
if( IN_IsConsoleKey( key, 0 ) )
{
// Console keys can't be bound or generate characters
key = K_CONSOLE;
}
return key;
}
#else
static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym,
keyNum_t *key, qboolean down )
{
@@ -359,6 +478,7 @@ static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym,
return (char *)buf;
}
#endif
#ifdef MACOS_X_ACCELERATION_HACK
/*
@@ -397,10 +517,22 @@ static void IN_GobbleMotionEvents( void )
{
SDL_Event dummy[ 1 ];
#if SDL_MAJOR_VERSION == 2
int val = 0;
// Gobble any mouse motion events
SDL_PumpEvents( );
while( ( val = SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_MOUSEMOTION, SDL_MOUSEMOTION ) ) > 0 ) { }
if ( val < 0 )
Com_Printf( "IN_GobbleMotionEvents failed: %s\n", SDL_GetError( ) );
#else
// Gobble any mouse motion events
SDL_PumpEvents( );
while( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_EVENTMASK( SDL_MOUSEMOTION ) ) ) { }
#endif
}
/*
@@ -450,6 +582,10 @@ static void IN_ActivateMouse( void )
if( !mouseActive )
{
#if SDL_MAJOR_VERSION == 2
SDL_SetRelativeMouseMode( SDL_TRUE );
SDL_SetWindowGrab( SDL_window, 1 );
#else
SDL_ShowCursor( 0 );
#ifdef MACOS_X_CURSOR_HACK
// This is a bug in the current SDL/macosx...have to toggle it a few
@@ -458,7 +594,7 @@ static void IN_ActivateMouse( void )
SDL_ShowCursor( 0 );
#endif
SDL_WM_GrabInput( SDL_GRAB_ON );
#endif
IN_GobbleMotionEvents( );
}
@@ -468,9 +604,15 @@ static void IN_ActivateMouse( void )
if( in_nograb->modified || !mouseActive )
{
if( in_nograb->integer )
#if SDL_MAJOR_VERSION == 2
SDL_SetWindowGrab( SDL_window, SDL_FALSE );
else
SDL_SetWindowGrab( SDL_window, SDL_TRUE );
#else
SDL_WM_GrabInput( SDL_GRAB_OFF );
else
SDL_WM_GrabInput( SDL_GRAB_ON );
#endif
in_nograb->modified = qfalse;
}
@@ -520,11 +662,20 @@ static void IN_DeactivateMouse( void )
{
IN_GobbleMotionEvents( );
#if SDL_MAJOR_VERSION == 2
SDL_SetWindowGrab( SDL_window, 0 );
SDL_SetRelativeMouseMode( SDL_FALSE );
// Don't warp the mouse unless the cursor is within the window
if( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_MOUSE_FOCUS )
SDL_WarpMouseInWindow( SDL_window, cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2 );
#else
SDL_WM_GrabInput( SDL_GRAB_OFF );
// Don't warp the mouse unless the cursor is within the window
if( SDL_GetAppState( ) & SDL_APPMOUSEFOCUS )
SDL_WarpMouse( cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2 );
#endif
mouseActive = qfalse;
}
@@ -599,7 +750,11 @@ static void IN_InitJoystick( void )
// Print list and build cvar to allow ui to select joystick.
for (i = 0; i < total; i++)
{
#if SDL_MAJOR_VERSION == 2
Q_strcat(buf, sizeof(buf), SDL_JoystickNameForIndex(i));
#else
Q_strcat(buf, sizeof(buf), SDL_JoystickName(i));
#endif
Q_strcat(buf, sizeof(buf), "\n");
}
@@ -625,7 +780,11 @@ static void IN_InitJoystick( void )
}
Com_DPrintf( "Joystick %d opened\n", in_joystickNo->integer );
#if SDL_MAJOR_VERSION == 2
Com_DPrintf( "Name: %s\n", SDL_JoystickNameForIndex(in_joystickNo->integer) );
#else
Com_DPrintf( "Name: %s\n", SDL_JoystickName(in_joystickNo->integer) );
#endif
Com_DPrintf( "Axes: %d\n", SDL_JoystickNumAxes(stick) );
Com_DPrintf( "Hats: %d\n", SDL_JoystickNumHats(stick) );
Com_DPrintf( "Buttons: %d\n", SDL_JoystickNumButtons(stick) );
@@ -866,12 +1025,17 @@ IN_ProcessEvents
static void IN_ProcessEvents( void )
{
SDL_Event e;
#if SDL_MAJOR_VERSION == 2
static keyNum_t lastKeyDown = 0;
#else
const char *character = NULL;
#endif
keyNum_t key = 0;
if( !SDL_WasInit( SDL_INIT_VIDEO ) )
return;
#if SDL_MAJOR_VERSION != 2
if( Key_GetCatcher( ) == 0 && keyRepeatEnabled )
{
SDL_EnableKeyRepeat( 0, 0 );
@@ -883,27 +1047,98 @@ static void IN_ProcessEvents( void )
SDL_DEFAULT_REPEAT_INTERVAL );
keyRepeatEnabled = qtrue;
}
#endif
while( SDL_PollEvent( &e ) )
{
switch( e.type )
{
case SDL_KEYDOWN:
#if SDL_MAJOR_VERSION == 2
if( ( key = IN_TranslateSDLToQ3Key( &e.key.keysym, qtrue ) ) )
Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL );
if( key == K_BACKSPACE )
Com_QueueEvent( 0, SE_CHAR, CTRL('h'), 0, 0, NULL );
else if( keys[K_CTRL].down && key >= 'a' && key <= 'z' )
Com_QueueEvent( 0, SE_CHAR, CTRL(key), 0, 0, NULL );
lastKeyDown = key;
#else
character = IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qtrue );
if( key )
Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL );
if( character )
Com_QueueEvent( 0, SE_CHAR, *character, 0, 0, NULL );
#endif
break;
case SDL_KEYUP:
#if SDL_MAJOR_VERSION == 2
if( ( key = IN_TranslateSDLToQ3Key( &e.key.keysym, qfalse ) ) )
Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL );
lastKeyDown = 0;
#else
IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qfalse );
if( key )
Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL );
#endif
break;
#if SDL_MAJOR_VERSION == 2
case SDL_TEXTINPUT:
if( lastKeyDown != K_CONSOLE )
{
char *c = e.text.text;
// Quick and dirty UTF-8 to UTF-32 conversion
while( *c )
{
int utf32 = 0;
if( ( *c & 0x80 ) == 0 )
utf32 = *c++;
else if( ( *c & 0xE0 ) == 0xC0 ) // 110x xxxx
{
utf32 |= ( *c++ & 0x1F ) << 6;
utf32 |= ( *c++ & 0x3F );
}
else if( ( *c & 0xF0 ) == 0xE0 ) // 1110 xxxx
{
utf32 |= ( *c++ & 0x0F ) << 12;
utf32 |= ( *c++ & 0x3F ) << 6;
utf32 |= ( *c++ & 0x3F );
}
else if( ( *c & 0xF8 ) == 0xF0 ) // 1111 0xxx
{
utf32 |= ( *c++ & 0x07 ) << 18;
utf32 |= ( *c++ & 0x3F ) << 6;
utf32 |= ( *c++ & 0x3F ) << 6;
utf32 |= ( *c++ & 0x3F );
}
else
{
Com_DPrintf( "Unrecognised UTF-8 lead byte: 0x%x\n", (unsigned int)*c );
c++;
}
if( utf32 != 0 )
{
if( IN_IsConsoleKey( 0, utf32 ) )
{
Com_QueueEvent( 0, SE_KEY, K_CONSOLE, qtrue, 0, NULL );
Com_QueueEvent( 0, SE_KEY, K_CONSOLE, qfalse, 0, NULL );
}
else
Com_QueueEvent( 0, SE_CHAR, utf32, 0, 0, NULL );
}
}
}
break;
#endif
case SDL_MOUSEMOTION:
if( mouseActive )
Com_QueueEvent( 0, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL );
@@ -918,8 +1153,10 @@ static void IN_ProcessEvents( void )
case SDL_BUTTON_LEFT: b = K_MOUSE1; break;
case SDL_BUTTON_MIDDLE: b = K_MOUSE3; break;
case SDL_BUTTON_RIGHT: b = K_MOUSE2; break;
#if SDL_MAJOR_VERSION != 2
case SDL_BUTTON_WHEELUP: b = K_MWHEELUP; break;
case SDL_BUTTON_WHEELDOWN: b = K_MWHEELDOWN; break;
#endif
case SDL_BUTTON_X1: b = K_MOUSE4; break;
case SDL_BUTTON_X2: b = K_MOUSE5; break;
default: b = K_AUX1 + ( e.button.button - SDL_BUTTON_X2 + 1 ) % 16; break;
@@ -929,6 +1166,47 @@ static void IN_ProcessEvents( void )
}
break;
#if SDL_MAJOR_VERSION == 2
case SDL_MOUSEWHEEL:
if( e.wheel.y > 0 )
{
Com_QueueEvent( 0, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
Com_QueueEvent( 0, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
}
else
{
Com_QueueEvent( 0, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
Com_QueueEvent( 0, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
}
break;
case SDL_WINDOWEVENT:
switch( e.window.event )
{
case SDL_WINDOWEVENT_RESIZED:
{
char width[32], height[32];
Com_sprintf( width, sizeof( width ), "%d", e.window.data1 );
Com_sprintf( height, sizeof( height ), "%d", e.window.data2 );
Cvar_Set( "r_customwidth", width );
Cvar_Set( "r_customheight", height );
Cvar_Set( "r_mode", "-1" );
// Wait until user stops dragging for 1 second, so
// we aren't constantly recreating the GL context while
// he tries to drag...
vidRestartTime = Sys_Milliseconds( ) + 1000;
}
break;
case SDL_WINDOWEVENT_MINIMIZED: Cvar_SetValue( "com_minimized", 1 ); break;
case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_MAXIMIZED: Cvar_SetValue( "com_minimized", 0 ); break;
case SDL_WINDOWEVENT_FOCUS_LOST: Cvar_SetValue( "com_unfocused", 1 ); break;
case SDL_WINDOWEVENT_FOCUS_GAINED: Cvar_SetValue( "com_unfocused", 0 ); break;
}
break;
#else
case SDL_QUIT:
Cbuf_ExecuteText(EXEC_NOW, "quit Closed window\n");
break;
@@ -955,7 +1233,7 @@ static void IN_ProcessEvents( void )
Cvar_SetValue( "com_minimized", !e.active.gain);
}
break;
#endif
default:
break;
}
@@ -987,7 +1265,11 @@ void IN_Frame( qboolean in_com_frame )
// Loading in windowed mode
IN_DeactivateMouse( );
}
#if SDL_MAJOR_VERSION == 2
else if( !( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_INPUT_FOCUS ) )
#else
else if( !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) )
#endif
{
// Window not got focus
IN_DeactivateMouse( );
@@ -1010,11 +1292,19 @@ IN_InitKeyLockStates
*/
void IN_InitKeyLockStates( void )
{
#if SDL_MAJOR_VERSION == 2
const unsigned char *keystate = SDL_GetKeyboardState(NULL);
keys[K_SCROLLOCK].down = keystate[SDL_SCANCODE_SCROLLLOCK];
keys[K_KP_NUMLOCK].down = keystate[SDL_SCANCODE_NUMLOCKCLEAR];
keys[K_CAPSLOCK].down = keystate[SDL_SCANCODE_CAPSLOCK];
#else
unsigned char *keystate = SDL_GetKeyState(NULL);
keys[K_SCROLLOCK].down = keystate[SDLK_SCROLLOCK];
keys[K_KP_NUMLOCK].down = keystate[SDLK_NUMLOCK];
keys[K_CAPSLOCK].down = keystate[SDLK_CAPSLOCK];
#endif
}
/*
@@ -1022,7 +1312,11 @@ void IN_InitKeyLockStates( void )
IN_Init
===============
*/
#if SDL_MAJOR_VERSION == 2
void IN_Init( void *windowData )
#else
void IN_Init( void )
#endif
{
int appState;
@@ -1032,6 +1326,10 @@ void IN_Init( void )
return;
}
#if SDL_MAJOR_VERSION == 2
SDL_window = (SDL_Window *)windowData;
#endif
Com_DPrintf( "\n------- Input Initialization -------\n" );
in_keyboardDebug = Cvar_Get( "in_keyboardDebug", "0", CVAR_ARCHIVE );
@@ -1048,16 +1346,26 @@ void IN_Init( void )
in_disablemacosxmouseaccel = Cvar_Get( "in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE );
#endif
#if SDL_MAJOR_VERSION == 2
SDL_StartTextInput( );
#else
SDL_EnableUNICODE( 1 );
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
keyRepeatEnabled = qtrue;
#endif
mouseAvailable = ( in_mouse->value != 0 );
IN_DeactivateMouse( );
#if SDL_MAJOR_VERSION == 2
appState = SDL_GetWindowFlags( SDL_window );
Cvar_SetValue( "com_unfocused", !( appState & SDL_WINDOW_INPUT_FOCUS ) );
Cvar_SetValue( "com_minimized", appState & SDL_WINDOW_MINIMIZED );
#else
appState = SDL_GetAppState( );
Cvar_SetValue( "com_unfocused", !( appState & SDL_APPINPUTFOCUS ) );
Cvar_SetValue( "com_minimized", !( appState & SDL_APPACTIVE ) );
#endif
IN_InitKeyLockStates( );
@@ -1072,10 +1380,17 @@ IN_Shutdown
*/
void IN_Shutdown( void )
{
#if SDL_MAJOR_VERSION == 2
SDL_StopTextInput( );
#endif
IN_DeactivateMouse( );
mouseAvailable = qfalse;
IN_ShutdownJoystick( );
#if SDL_MAJOR_VERSION == 2
SDL_window = NULL;
#endif
}
/*
@@ -1086,5 +1401,9 @@ IN_Restart
void IN_Restart( void )
{
IN_ShutdownJoystick( );
#if SDL_MAJOR_VERSION == 2
IN_Init( SDL_window );
#else
IN_Init( );
#endif
}

View File

@@ -140,7 +140,9 @@ SNDDMA_Init
*/
qboolean SNDDMA_Init(void)
{
#if SDL_MAJOR_VERSION != 2
char drivername[128];
#endif
SDL_AudioSpec desired;
SDL_AudioSpec obtained;
int tmp;
@@ -169,9 +171,13 @@ qboolean SNDDMA_Init(void)
Com_Printf( "OK\n" );
#if SDL_MAJOR_VERSION == 2
Com_Printf( "SDL audio driver is \"%s\".\n", SDL_GetCurrentAudioDriver( ) );
#else
if (SDL_AudioDriverName(drivername, sizeof (drivername)) == NULL)
strcpy(drivername, "(UNKNOWN)");
Com_Printf("SDL audio driver is \"%s\".\n", drivername);
#endif
memset(&desired, '\0', sizeof (desired));
memset(&obtained, '\0', sizeof (obtained));

View File

@@ -29,7 +29,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MINSDL_PATCH 10
// Input subsystem
#if SDL_MAJOR_VERSION == 2
void IN_Init( void *windowData );
#else
void IN_Init( void );
#endif
void IN_Frame( qboolean in_com_frame ); // youurayy input lag fix
void IN_Shutdown( void );
void IN_Restart( void );

View File

@@ -245,9 +245,13 @@ cpuFeatures_t Sys_GetProcessorFeatures( void )
#ifndef DEDICATED
if( SDL_HasRDTSC( ) ) features |= CF_RDTSC;
if( SDL_HasMMX( ) ) features |= CF_MMX;
#if SDL_MAJOR_VERSION != 2
if( SDL_HasMMXExt( ) ) features |= CF_MMX_EXT;
#endif
if( SDL_Has3DNow( ) ) features |= CF_3DNOW;
#if SDL_MAJOR_VERSION != 2
if( SDL_Has3DNowExt( ) ) features |= CF_3DNOW_EXT;
#endif
if( SDL_HasSSE( ) ) features |= CF_SSE;
if( SDL_HasSSE2( ) ) features |= CF_SSE2;
if( SDL_HasAltiVec( ) ) features |= CF_ALTIVEC;
@@ -600,7 +604,12 @@ int main( int argc, char **argv )
# endif
// Run time
#if SDL_MAJOR_VERSION == 2
SDL_version ver[1];
SDL_GetVersion( ver );
#else
const SDL_version *ver = SDL_Linked_Version( );
#endif
#define MINSDL_VERSION \
XSTRING(MINSDL_MAJOR) "." \

View File

@@ -20,6 +20,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifndef DEDICATED
#ifdef USE_LOCAL_HEADERS
# include "SDL.h"
#else
# include <SDL.h>
#endif
#endif
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"
#include "sys_local.h"
@@ -681,8 +689,10 @@ dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *t
}
#ifndef DEDICATED
#if SDL_MAJOR_VERSION != 2
static qboolean SDL_VIDEODRIVER_externallySet = qfalse;
#endif
#endif
/*
==============
@@ -694,6 +704,7 @@ Windows specific "safe" GL implementation initialisation
void Sys_GLimpSafeInit( void )
{
#ifndef DEDICATED
#if SDL_MAJOR_VERSION != 2
if( !SDL_VIDEODRIVER_externallySet )
{
// Here, we want to let SDL decide what do to unless
@@ -701,6 +712,7 @@ void Sys_GLimpSafeInit( void )
_putenv( "SDL_VIDEODRIVER=" );
}
#endif
#endif
}
/*
@@ -713,6 +725,7 @@ Windows specific GL implementation initialisation
void Sys_GLimpInit( void )
{
#ifndef DEDICATED
#if SDL_MAJOR_VERSION != 2
if( !SDL_VIDEODRIVER_externallySet )
{
// It's a little bit weird having in_mouse control the
@@ -731,6 +744,7 @@ void Sys_GLimpInit( void )
}
}
#endif
#endif
}
#ifndef DEDICATED
#ifdef USE_CONSOLE_WINDOW
@@ -764,6 +778,7 @@ void Sys_PlatformInit( void )
#endif
#if SDL_MAJOR_VERSION != 2
if( SDL_VIDEODRIVER )
{
Com_Printf( "SDL_VIDEODRIVER is externally set to \"%s\", "
@@ -772,6 +787,7 @@ void Sys_PlatformInit( void )
}
else
SDL_VIDEODRIVER_externallySet = qfalse;
#endif
// leilei - no 3dfx splashes please
_putenv("FX_GLIDE_NO_SPLASH=1");