diff options
author | Tim Angus <tim@ngus.net> | 2009-10-03 11:58:50 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:15:34 +0000 |
commit | ac3e5586cd56657ff1b6f5f64af7e1d7c76b410d (patch) | |
tree | b245f2cbd4e7491b948aea5c7c080be61307c950 /src/sdl | |
parent | dc3819f1e99d8159bdb0ea1da26506b00fe78e62 (diff) |
* Merge ioq3-r1458
Diffstat (limited to 'src/sdl')
-rw-r--r-- | src/sdl/sdl_glimp.c | 77 | ||||
-rw-r--r-- | src/sdl/sdl_input.c | 287 |
2 files changed, 227 insertions, 137 deletions
diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index 068ab02c..6125a321 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -76,8 +76,10 @@ typedef enum } rserr_t; static SDL_Surface *screen = NULL; +static const SDL_VideoInfo *videoInfo = NULL; cvar_t *r_allowSoftwareGL; // Don't abort out if a hardware visual can't be obtained +cvar_t *r_sdlDriver; void (APIENTRYP qglActiveTextureARB) (GLenum texture); void (APIENTRYP qglClientActiveTextureARB) (GLenum texture); @@ -152,8 +154,16 @@ static void GLimp_DetectAvailableModes(void) SDL_Rect **modes; int numModes; int i; + SDL_PixelFormat *format = NULL; - modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN ); +#if SDL_VERSION_ATLEAST(1, 2, 10) + format = videoInfo->vfmt; +# if MINSDL_PATCH >= 10 +# error Ifdeffery no longer necessary, please remove +# endif +#endif + + modes = SDL_ListModes( format, SDL_OPENGL | SDL_FULLSCREEN ); if( !modes ) { @@ -207,27 +217,37 @@ static int GLimp_SetMode( qboolean failSafe, qboolean fullscreen ) int i = 0; SDL_Surface *vidscreen = NULL; Uint32 flags = SDL_OPENGL; - const SDL_VideoInfo *videoInfo; ri.Printf( PRINT_ALL, "Initializing OpenGL display\n"); - if( glConfig.displayAspect == 0.0f ) - { #if !SDL_VERSION_ATLEAST(1, 2, 10) - // 1.2.10 is needed to get the desktop resolution - glConfig.displayAspect = 4.0f / 3.0f; + // 1.2.10 is needed to get the desktop resolution + glConfig.displayAspect = 4.0f / 3.0f; #elif MINSDL_PATCH >= 10 # error Ifdeffery no longer necessary, please remove #else + if( videoInfo == NULL ) + { + static SDL_VideoInfo sVideoInfo; + static SDL_PixelFormat sPixelFormat; + + videoInfo = SDL_GetVideoInfo( ); + + // Take a copy of the videoInfo + Com_Memcpy( &sPixelFormat, videoInfo->vfmt, sizeof( SDL_PixelFormat ) ); + sPixelFormat.palette = NULL; // Should already be the case + Com_Memcpy( &sVideoInfo, videoInfo, sizeof( SDL_VideoInfo ) ); + sVideoInfo.vfmt = &sPixelFormat; + videoInfo = &sVideoInfo; + // 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( ); glConfig.displayAspect = (float)videoInfo->current_w / (float)videoInfo->current_h; -#endif ri.Printf( PRINT_ALL, "Estimated display aspect: %.3f\n", glConfig.displayAspect ); } +#endif if( !failSafe ) { @@ -431,13 +451,18 @@ static qboolean GLimp_StartDriverAndSetMode( qboolean failSafe, qboolean fullscr if (!SDL_WasInit(SDL_INIT_VIDEO)) { - ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO )... "); + char driverName[ 64 ]; + if (SDL_Init(SDL_INIT_VIDEO) == -1) { - ri.Printf( PRINT_ALL, "FAILED (%s)\n", SDL_GetError()); + ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n", + SDL_GetError()); return qfalse; } - ri.Printf( PRINT_ALL, "OK\n"); + + SDL_VideoDriverName( driverName, sizeof( driverName ) - 1 ); + ri.Printf( PRINT_ALL, "SDL using driver \"%s\"\n", driverName ); + Cvar_Set( "r_sdlDriver", driverName ); } if (fullscreen && Cvar_VariableIntegerValue( "in_nograb" ) ) @@ -655,6 +680,9 @@ void GLimp_Init( void ) qboolean success = qtrue; r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH ); + r_sdlDriver = ri.Cvar_Get( "r_sdlDriver", "", CVAR_ROM ); + + Sys_GLimpInit( ); // create the window and set up the context if( !GLimp_StartDriverAndSetMode( qfalse, r_fullscreen->integer ) ) @@ -686,8 +714,6 @@ void GLimp_Init( void ) // This depends on SDL_INIT_VIDEO, hence having it here IN_Init( ); - - return; } @@ -709,18 +735,16 @@ void GLimp_EndFrame( void ) if( r_fullscreen->modified ) { qboolean fullscreen; + qboolean needToToggle = qtrue; qboolean sdlToggled = qfalse; SDL_Surface *s = SDL_GetVideoSurface( ); if( s ) { // Find out the current state - if( s->flags & SDL_FULLSCREEN ) - fullscreen = qtrue; - else - fullscreen = qfalse; + fullscreen = !!( s->flags & SDL_FULLSCREEN ); - if (r_fullscreen->integer && Cvar_VariableIntegerValue( "in_nograb" )) + if( r_fullscreen->integer && Cvar_VariableIntegerValue( "in_nograb" ) ) { ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n"); ri.Cvar_Set( "r_fullscreen", "0" ); @@ -728,15 +752,20 @@ void GLimp_EndFrame( void ) } // Is the state we want different from the current state? - if( !!r_fullscreen->integer != fullscreen ) + needToToggle = !!r_fullscreen->integer != fullscreen; + + if( needToToggle ) sdlToggled = SDL_WM_ToggleFullScreen( s ); - else - sdlToggled = qtrue; } - // SDL_WM_ToggleFullScreen didn't work, so do it the slow way - if( !sdlToggled ) - Cbuf_AddText( "vid_restart" ); + if( needToToggle ) + { + // SDL_WM_ToggleFullScreen didn't work, so do it the slow way + if( !sdlToggled ) + Cbuf_AddText( "vid_restart" ); + + IN_Restart( ); + } r_fullscreen->modified = qfalse; } diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c index f7cb0d85..c209f0a5 100644 --- a/src/sdl/sdl_input.c +++ b/src/sdl/sdl_input.c @@ -34,6 +34,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "../client/client.h" #include "../sys/sys_local.h" +#define ARRAYLEN(x) (sizeof(x)/sizeof(x[0])) + #ifdef MACOS_X // Mouse acceleration needs to be disabled #define MACOS_X_ACCELERATION_HACK @@ -48,7 +50,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include <IOKit/hidsystem/event_status_driver.h> #endif -//#define KBD_DBG +static cvar_t *in_keyboardDebug = NULL; static SDL_Joystick *stick = NULL; @@ -56,9 +58,9 @@ static qboolean mouseAvailable = qfalse; static qboolean mouseActive = qfalse; static qboolean keyRepeatEnabled = qfalse; -static cvar_t *in_mouse; +static cvar_t *in_mouse = NULL; #ifdef MACOS_X_ACCELERATION_HACK -static cvar_t *in_disablemacosxmouseaccel; +static cvar_t *in_disablemacosxmouseaccel = NULL; static double originalMouseSpeed = -1.0; #endif static cvar_t *in_nograb; @@ -66,23 +68,66 @@ static cvar_t *in_nograb; static cvar_t *in_joystick = NULL; static cvar_t *in_joystickDebug = NULL; static cvar_t *in_joystickThreshold = NULL; +static cvar_t *in_joystickNo = NULL; + +#define CTRL(a) ((a)-'a'+1) + +/* +=============== +IN_PrintKey +=============== +*/ +static void IN_PrintKey( const SDL_keysym *keysym, int key, qboolean down ) +{ + if( down ) + Com_Printf( "+ " ); + else + Com_Printf( " " ); + + Com_Printf( "0x%hx \"%s\"", keysym->scancode, + SDL_GetKeyName( keysym->sym ) ); + + if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" ); + if( keysym->mod & KMOD_RSHIFT ) Com_Printf( " KMOD_RSHIFT" ); + if( keysym->mod & KMOD_LCTRL ) Com_Printf( " KMOD_LCTRL" ); + 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( keysym->mod & KMOD_LMETA ) Com_Printf( " KMOD_LMETA" ); + if( keysym->mod & KMOD_RMETA ) Com_Printf( " KMOD_RMETA" ); + 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" ); + + if( keysym->unicode ) + { + Com_Printf( " %d", keysym->unicode ); + + if( keysym->unicode > ' ' && keysym->unicode < '~' ) + Com_Printf( "(%c)", (char)keysym->unicode ); + } + + Com_Printf( " %d(%s)\n", key, Key_KeynumToString( key ) ); +} /* =============== IN_TranslateSDLToQ3Key =============== */ -static const char *IN_TranslateSDLToQ3Key(SDL_keysym *keysym, int *key) +static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym, + int *key, qboolean down ) { - static char buf[2] = { '\0', '\0' }; - *buf = '\0'; + static char buf[ 2 ] = { '\0', '\0' }; + *buf = '\0'; *key = 0; - // these happen to match the ASCII chars. - if ((keysym->sym >= ' ') && (keysym->sym <= '~')) + if( keysym->sym >= SDLK_SPACE && keysym->sym < SDLK_DELETE ) { - *key = (int) keysym->sym; + // These happen to match the ASCII chars + *key = (int)keysym->sym; } else { @@ -124,7 +169,7 @@ static const char *IN_TranslateSDLToQ3Key(SDL_keysym *keysym, int *key) case SDLK_F14: *key = K_F14; break; case SDLK_F15: *key = K_F15; break; - case SDLK_BACKSPACE: *key = K_BACKSPACE; break; // ctrl-h + 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; @@ -167,51 +212,42 @@ static const char *IN_TranslateSDLToQ3Key(SDL_keysym *keysym, int *key) case SDLK_CAPSLOCK: *key = K_CAPSLOCK; break; default: - if (keysym->sym >= SDLK_WORLD_0 && keysym->sym <= SDLK_WORLD_95) - *key = (keysym->sym - SDLK_WORLD_0) + K_WORLD_0; + if( keysym->sym >= SDLK_WORLD_0 && keysym->sym <= SDLK_WORLD_95 ) + *key = ( keysym->sym - SDLK_WORLD_0 ) + K_WORLD_0; break; } } - if( keysym->unicode <= 127 ) // maps to ASCII? + if( down && !( keysym->unicode & 0xFF80 ) ) { - char ch = (char) keysym->unicode; - if (ch == '~') - *key = '~'; // console HACK + char ch = (char)keysym->unicode & 0x7F; - // translate K_BACKSPACE to ctrl-h for MACOS_X (others?) - if (ch == K_BACKSPACE && keysym->sym != SDLK_DELETE) + switch( ch ) { - *key = 'h' - 'a' + 1; - buf[0] = *key; - } - else - buf[0] = ch; - } + // So the key marked ~ always drops the console + case '~': *key = '~'; break; - return buf; -} + case 127: // ASCII delete + if( *key != K_DEL ) + { + // ctrl-h + *buf = CTRL('h'); + break; + } + // fallthrough -/* -=============== -IN_PrintKey -=============== -*/ -static void IN_PrintKey(const SDL_Event* event) -{ -#ifdef KBD_DBG - fprintf( stderr, "key name: %s", SDL_GetKeyName (event->key.keysym.sym ) ); - if(event->key.keysym.unicode) - { - fprintf( stderr, " unicode: %hx", event->key.keysym.unicode ); - if( event->key.keysym.unicode >= '0' && - event->key.keysym.unicode <= '~') // printable? - { - fprintf( stderr, " (%c)", (unsigned char)event->key.keysym.unicode ); + default: *buf = ch; break; } } - fflush( stderr ); -#endif + + // Never allow a '~' SE_CHAR event to be generated + if( *key == '~' ) + *buf = '\0'; + + if( in_keyboardDebug->integer ) + IN_PrintKey( keysym, *key, down ); + + return buf; } #ifdef MACOS_X_ACCELERATION_HACK @@ -323,7 +359,15 @@ IN_DeactivateMouse */ static void IN_DeactivateMouse( void ) { - if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) ) + if( !SDL_WasInit( SDL_INIT_VIDEO ) ) + return; + + // Always show the cursor when the mouse is disabled, + // but not when fullscreen + if( !r_fullscreen->integer ) + SDL_ShowCursor( 1 ); + + if( !mouseAvailable ) return; #ifdef MACOS_X_ACCELERATION_HACK @@ -348,8 +392,10 @@ static void IN_DeactivateMouse( void ) if( mouseActive ) { SDL_WM_GrabInput( SDL_GRAB_OFF ); - SDL_WarpMouse( glConfig.vidWidth >> 1, glConfig.vidHeight >> 1 ); - SDL_ShowCursor( 1 ); + + // Don't warp the mouse unless the cursor is within the window + if( SDL_GetAppState( ) & SDL_APPMOUSEFOCUS ) + SDL_WarpMouse( glConfig.vidWidth / 2, glConfig.vidHeight / 2 ); mouseActive = qfalse; } @@ -382,12 +428,6 @@ static int hat_keys[16] = { }; -extern cvar_t * in_joystick; -extern cvar_t * in_joystickDebug; -extern cvar_t * in_joystickThreshold; -cvar_t *in_joystickNo; - -#define ARRAYLEN(x) (sizeof (x) / sizeof (x[0])) struct { qboolean buttons[16]; // !!! FIXME: these might be too many. @@ -398,10 +438,10 @@ struct /* =============== -IN_StartupJoystick +IN_InitJoystick =============== */ -static void IN_StartupJoystick( void ) +static void IN_InitJoystick( void ) { int i = 0; int total = 0; @@ -452,8 +492,22 @@ static void IN_StartupJoystick( void ) Com_DPrintf( "Balls: %d\n", SDL_JoystickNumBalls(stick) ); SDL_JoystickEventState(SDL_QUERY); +} - return; +/* +=============== +IN_ShutdownJoystick +=============== +*/ +static void IN_ShutdownJoystick( void ) +{ + if (stick) + { + SDL_JoystickClose(stick); + stick = NULL; + } + + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } /* @@ -653,7 +707,6 @@ static void IN_ProcessEvents( void ) SDL_Event e; const char *p = NULL; int key = 0; - int mx = 0, my = 0; if( !SDL_WasInit( SDL_INIT_VIDEO ) ) return; @@ -670,13 +723,12 @@ static void IN_ProcessEvents( void ) keyRepeatEnabled = qtrue; } - while (SDL_PollEvent(&e)) + while( SDL_PollEvent( &e ) ) { - switch (e.type) + switch( e.type ) { case SDL_KEYDOWN: - IN_PrintKey(&e); - p = IN_TranslateSDLToQ3Key(&e.key.keysym, &key); + p = IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qtrue ); if( key ) Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL ); @@ -688,23 +740,20 @@ static void IN_ProcessEvents( void ) break; case SDL_KEYUP: - IN_TranslateSDLToQ3Key(&e.key.keysym, &key); + IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qfalse ); Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); break; case SDL_MOUSEMOTION: - if (mouseActive) - { - mx += e.motion.xrel; - my += e.motion.yrel; - } + if( mouseActive ) + Com_QueueEvent( 0, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL ); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { unsigned char b; - switch (e.button.button) + switch( e.button.button ) { case 1: b = K_MOUSE1; break; case 2: b = K_MOUSE3; break; @@ -713,33 +762,21 @@ static void IN_ProcessEvents( void ) case 5: b = K_MWHEELDOWN; break; case 6: b = K_MOUSE4; break; case 7: b = K_MOUSE5; break; - default: b = K_AUX1 + (e.button.button - 8)%16; break; + default: b = K_AUX1 + ( e.button.button - 8 ) % 16; break; } Com_QueueEvent( 0, SE_KEY, b, ( e.type == SDL_MOUSEBUTTONDOWN ? qtrue : qfalse ), 0, NULL ); } break; - case SDL_ACTIVEEVENT: - if( e.active.state == SDL_APPINPUTFOCUS ) { - if( e.active.gain ) - IN_ActivateMouse(); - else - IN_DeactivateMouse(); - } - break; - case SDL_QUIT: - Sys_Quit(); + Sys_Quit( ); break; default: break; } } - - if(mx || my) - Com_QueueEvent( 0, SE_MOUSE, mx, my, 0, NULL ); } /* @@ -747,19 +784,33 @@ static void IN_ProcessEvents( void ) IN_Frame =============== */ -void IN_Frame (void) +void IN_Frame( void ) { + qboolean loading; + IN_JoyMove( ); + IN_ProcessEvents( ); + + // If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading + loading = !!( cls.state != CA_DISCONNECTED && cls.state != CA_ACTIVE ); - // Release the mouse if the console is down in windowed mode - // or if the window loses focus due to task switching - if( ( ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) && !r_fullscreen->integer ) || - !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) ) + if( !r_fullscreen->integer && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) + { + // Console is down in windowed mode + IN_DeactivateMouse( ); + } + else if( !r_fullscreen->integer && loading ) + { + // Loading in windowed mode + IN_DeactivateMouse( ); + } + else if( !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) ) + { + // Window not got focus IN_DeactivateMouse( ); + } else IN_ActivateMouse( ); - - IN_ProcessEvents( ); } /* @@ -767,7 +818,7 @@ void IN_Frame (void) IN_Init =============== */ -void IN_Init(void) +void IN_Init( void ) { if( !SDL_WasInit( SDL_INIT_VIDEO ) ) { @@ -775,33 +826,39 @@ void IN_Init(void) return; } - Com_DPrintf ("\n------- Input Initialization -------\n"); + Com_DPrintf( "\n------- Input Initialization -------\n" ); + + in_keyboardDebug = Cvar_Get( "in_keyboardDebug", "0", CVAR_ARCHIVE ); // mouse variables - in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE); - in_nograb = Cvar_Get ("in_nograb", "0", CVAR_ARCHIVE); + in_mouse = Cvar_Get( "in_mouse", "1", CVAR_ARCHIVE ); + in_nograb = Cvar_Get( "in_nograb", "0", CVAR_ARCHIVE ); - in_joystick = Cvar_Get ("in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH); - in_joystickDebug = Cvar_Get ("in_debugjoystick", "0", CVAR_TEMP); - in_joystickThreshold = Cvar_Get ("in_joystickThreshold", "0.15", CVAR_ARCHIVE); + in_joystick = Cvar_Get( "in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH ); + in_joystickDebug = Cvar_Get( "in_joystickDebug", "0", CVAR_TEMP ); + in_joystickThreshold = Cvar_Get( "in_joystickThreshold", "0.15", CVAR_ARCHIVE ); #ifdef MACOS_X_ACCELERATION_HACK - in_disablemacosxmouseaccel = Cvar_Get ("in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE); + in_disablemacosxmouseaccel = Cvar_Get( "in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE ); #endif - Cvar_Set( "cl_platformSensitivity", "1.0" ); - - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableUNICODE( 1 ); + SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); keyRepeatEnabled = qtrue; - if (in_mouse->value) + if( in_mouse->value ) + { mouseAvailable = qtrue; + IN_ActivateMouse( ); + } else + { + IN_DeactivateMouse( ); mouseAvailable = qfalse; + } - IN_StartupJoystick( ); - Com_DPrintf ("------------------------------------\n"); + IN_InitJoystick( ); + Com_DPrintf( "------------------------------------\n" ); } /* @@ -809,17 +866,21 @@ void IN_Init(void) IN_Shutdown =============== */ -void IN_Shutdown(void) +void IN_Shutdown( void ) { - IN_DeactivateMouse(); - + IN_DeactivateMouse( ); mouseAvailable = qfalse; - if (stick) - { - SDL_JoystickClose(stick); - stick = NULL; - } + IN_ShutdownJoystick( ); +} - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); +/* +=============== +IN_Restart +=============== +*/ +void IN_Restart( void ) +{ + IN_ShutdownJoystick( ); + IN_Init( ); } |