Browse Source

engine: finish sdl1.2 port

pull/2/head
Alibek Omarov 5 years ago
parent
commit
9d826016b0
  1. 1
      engine/client/client.h
  2. 16
      engine/client/input.c
  3. 18
      engine/client/keys.c
  4. 6
      engine/client/vgui/vgui_draw.c
  5. 1
      engine/client/vid_common.h
  6. 2
      engine/common/host.c
  7. 2
      engine/platform/android/android.c
  8. 6
      engine/platform/linux/in_evdev.c
  9. 4
      engine/platform/linux/vid_fbdev.c
  10. 10
      engine/platform/platform.h
  11. 2
      engine/platform/posix/sys_posix.c
  12. 400
      engine/platform/sdl/events.c
  13. 12
      engine/platform/sdl/s_sdl.c
  14. 2
      engine/platform/sdl/sys_sdl.c
  15. 164
      engine/platform/sdl/vid_sdl.c
  16. 4
      engine/platform/win32/sys_win.c

1
engine/client/client.h

@ -1137,6 +1137,7 @@ int Key_GetKey( const char *binding );
void Key_EnumCmds_f( void ); void Key_EnumCmds_f( void );
void Key_SetKeyDest( int key_dest ); void Key_SetKeyDest( int key_dest );
void Key_EnableTextInput( qboolean enable, qboolean force ); void Key_EnableTextInput( qboolean enable, qboolean force );
int Key_ToUpper( int key );
void OSK_Draw( void ); void OSK_Draw( void );
extern rgba_t g_color_table[8]; extern rgba_t g_color_table[8];

16
engine/client/input.c

@ -194,28 +194,30 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
else if( newstate == key_game ) else if( newstate == key_game )
{ {
// reset mouse pos, so cancel effect in game // reset mouse pos, so cancel effect in game
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( CVAR_TO_BOOL( touch_enable ) ) if( CVAR_TO_BOOL( touch_enable ) )
{ {
SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE );
SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
} }
else else
#endif
{ {
Platform_SetMousePos( host.window_center_x, host.window_center_y ); Platform_SetMousePos( host.window_center_x, host.window_center_y );
SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( clgame.dllFuncs.pfnLookEvent ) if( clgame.dllFuncs.pfnLookEvent )
SDL_SetRelativeMouseMode( SDL_TRUE ); SDL_SetRelativeMouseMode( SDL_TRUE );
#endif
} }
#endif // XASH_SDL
if( cls.initialized ) if( cls.initialized )
clgame.dllFuncs.IN_ActivateMouse(); clgame.dllFuncs.IN_ActivateMouse();
} }
if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( ))) if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
{ {
#if XASH_SDL == 2
SDL_SetWindowGrab(host.hWnd, SDL_FALSE); SDL_SetWindowGrab(host.hWnd, SDL_FALSE);
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( clgame.dllFuncs.pfnLookEvent ) if( clgame.dllFuncs.pfnLookEvent )
SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE );
#endif #endif
@ -316,9 +318,7 @@ void IN_DeactivateMouse( void )
} }
in_mouseactive = false; in_mouseactive = false;
#if XASH_SDL == 2
SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
#endif
} }
/* /*
@ -416,10 +416,12 @@ void IN_MouseEvent( void )
} }
else else
{ {
#if XASH_SDL == 2 && !defined(_WIN32) #if XASH_SDL && !defined(_WIN32)
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_ShowCursor( SDL_TRUE ); SDL_ShowCursor( SDL_TRUE );
#endif #endif // XASH_SDL && !defined(_WIN32)
IN_MouseMove(); IN_MouseMove();
} }
} }

18
engine/client/keys.c

@ -815,7 +815,6 @@ void Key_EnableTextInput( qboolean enable, qboolean force )
else if( !enable ) else if( !enable )
Platform_EnableTextInput( false ); Platform_EnableTextInput( false );
if( !force )
host.textmode = enable; host.textmode = enable;
} }
@ -907,6 +906,23 @@ void CL_CharEvent( int key )
} }
} }
/*
============
Key_ToUpper
A helper function if platform input doesn't support text mode properly
============
*/
int Key_ToUpper( int keynum )
{
keynum = Q_toupper( keynum );
if( keynum == '-' )
keynum = '_';
if( keynum == '=' )
keynum = '+';
return keynum;
}
/* On-screen keyboard: /* On-screen keyboard:
* *

6
engine/client/vgui/vgui_draw.c

@ -25,7 +25,7 @@ GNU General Public License for more details.
#include "ref_common.h" #include "ref_common.h"
#include "input.h" #include "input.h"
#ifdef XASH_SDL #ifdef XASH_SDL
#include <SDL_events.h> #include <SDL.h>
static SDL_Cursor* s_pDefaultCursor[20]; static SDL_Cursor* s_pDefaultCursor[20];
#endif #endif
#include "platform/platform.h" #include "platform/platform.h"
@ -72,7 +72,7 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y )
void VGUI_InitCursors( void ) void VGUI_InitCursors( void )
{ {
// load up all default cursors // load up all default cursors
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
s_pDefaultCursor[dc_none] = NULL; s_pDefaultCursor[dc_none] = NULL;
s_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); s_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
s_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); s_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
@ -108,7 +108,7 @@ void GAME_EXPORT VGUI_CursorSelect(enum VGUI_DefaultCursor cursor )
break; break;
} }
#if XASH_SDL == 2 #if SDL_VERSION_ATLEAST( 2, 0, 0 )
/// TODO: platform cursors /// TODO: platform cursors
if( CVAR_TO_BOOL( touch_emulate ) ) if( CVAR_TO_BOOL( touch_emulate ) )

1
engine/client/vid_common.h

@ -16,7 +16,6 @@ typedef struct
int safe; int safe;
int desktopBitsPixel; int desktopBitsPixel;
int desktopWidth;
int desktopHeight; int desktopHeight;
qboolean initialized; // OpenGL subsystem started qboolean initialized; // OpenGL subsystem started

2
engine/common/host.c

@ -323,9 +323,7 @@ void Host_MemStats_f( void )
void Host_Minimize_f( void ) void Host_Minimize_f( void )
{ {
#if XASH_SDL == 2
if( host.hWnd ) SDL_MinimizeWindow( host.hWnd ); if( host.hWnd ) SDL_MinimizeWindow( host.hWnd );
#endif
} }
/* /*

2
engine/platform/android/android.c

@ -645,10 +645,12 @@ Android_MessageBox
Show messagebox and wait for OK button press Show messagebox and wait for OK button press
======================== ========================
*/ */
#if XASH_MESSAGEBOX == MSGBOX_ANDROID
void Platform_MessageBox( const char *title, const char *text, qboolean parentMainWindow ) void Platform_MessageBox( const char *title, const char *text, qboolean parentMainWindow )
{ {
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.messageBox, (*jni.env)->NewStringUTF( jni.env, title ), (*jni.env)->NewStringUTF( jni.env ,text ) ); (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.messageBox, (*jni.env)->NewStringUTF( jni.env, title ), (*jni.env)->NewStringUTF( jni.env ,text ) );
} }
#endif // XASH_MESSAGEBOX == MSGBOX_ANDROID
/* /*
======================== ========================

6
engine/platform/linux/in_evdev.c

@ -378,11 +378,7 @@ void IN_EvdevFrame ( void )
{ {
if( evdev.shift ) if( evdev.shift )
{ {
key = Q_toupper( key ); key = Key_ToUpper( key );
if( key == '-' )
key = '_';
if( key == '=' )
key = '+';
} }
CL_CharEvent( key ); CL_CharEvent( key );
} }

4
engine/platform/linux/vid_fbdev.c

@ -266,10 +266,6 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
} }
// unrelated stubs // unrelated stubs
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
{
}
void Platform_GetClipboardText( char *buffer, size_t size ) void Platform_GetClipboardText( char *buffer, size_t size )
{ {

10
engine/platform/platform.h

@ -73,6 +73,16 @@ void Platform_PreCreateMove( void );
void Platform_GetClipboardText( char *buffer, size_t size ); void Platform_GetClipboardText( char *buffer, size_t size );
void Platform_SetClipboardText( const char *buffer, size_t size ); void Platform_SetClipboardText( const char *buffer, size_t size );
#if XASH_SDL == 12
#define SDL_SetWindowGrab( wnd, state ) SDL_WM_GrabInput( (state) )
#define SDL_MinimizeWindow( wnd ) SDL_WM_IconifyWindow()
#define SDL_IsTextInputActive() host.textmode
#endif
#if !XASH_SDL
#define SDL_VERSION_ATLEAST( x, y, z ) 0
#endif
#ifdef __ANDROID__ #ifdef __ANDROID__
void Android_ShowMouse( qboolean show ); void Android_ShowMouse( qboolean show );
void Android_MouseMove( float *x, float *y ); void Android_MouseMove( float *x, float *y );

2
engine/platform/posix/sys_posix.c

@ -92,7 +92,7 @@ void Platform_ShellExecute( const char *path, const char *parms )
} }
#endif // __ANDROID__ #endif // __ANDROID__
#ifdef XASH_DEDICATED #if XASH_MESSAGEBOX == MSGBOX_STDERR
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ) void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
{ {
fprintf( stderr, fprintf( stderr,

400
engine/platform/sdl/events.c

@ -15,6 +15,7 @@ GNU General Public License for more details.
#if defined( XASH_SDL ) && !defined( XASH_DEDICATED ) #if defined( XASH_SDL ) && !defined( XASH_DEDICATED )
#include <SDL.h> #include <SDL.h>
#include <ctype.h>
#include "common.h" #include "common.h"
#include "keydefs.h" #include "keydefs.h"
@ -39,56 +40,57 @@ static int wheelbutton;
#define SDL_SCANCODE_BACKSLASH SDLK_BACKSLASH #define SDL_SCANCODE_BACKSLASH SDLK_BACKSLASH
#define SDL_SCANCODE_LEFTBRACKET SDLK_LEFTBRACKET #define SDL_SCANCODE_LEFTBRACKET SDLK_LEFTBRACKET
#define SDL_SCANCODE_RIGHTBRACKET SDLK_RIGHTBRACKET #define SDL_SCANCODE_RIGHTBRACKET SDLK_RIGHTBRACKET
#define SDL_SCANCODE_EQUALS: keynum = '='; break; #define SDL_SCANCODE_EQUALS SDLK_EQUALS
#define SDL_SCANCODE_MINUS: keynum = '-'; break; #define SDL_SCANCODE_MINUS SDLK_MINUS
#define SDL_SCANCODE_TAB: keynum = K_TAB; break; #define SDL_SCANCODE_TAB SDLK_TAB
#define SDL_SCANCODE_RETURN: keynum = K_ENTER; break; #define SDL_SCANCODE_RETURN SDLK_RETURN
#define SDL_SCANCODE_ESCAPE: keynum = K_ESCAPE; break; #define SDL_SCANCODE_ESCAPE SDLK_ESCAPE
#define SDL_SCANCODE_SPACE: keynum = K_SPACE; break; #define SDL_SCANCODE_SPACE SDLK_SPACE
#define SDL_SCANCODE_BACKSPACE: keynum = K_BACKSPACE; break; #define SDL_SCANCODE_BACKSPACE SDLK_BACKSPACE
#define SDL_SCANCODE_UP: keynum = K_UPARROW; break; #define SDL_SCANCODE_UP SDLK_UP
#define SDL_SCANCODE_LEFT: keynum = K_LEFTARROW; break; #define SDL_SCANCODE_LEFT SDLK_LEFT
#define SDL_SCANCODE_DOWN: keynum = K_DOWNARROW; break; #define SDL_SCANCODE_DOWN SDLK_DOWN
#define SDL_SCANCODE_RIGHT: keynum = K_RIGHTARROW; break; #define SDL_SCANCODE_RIGHT SDLK_RIGHT
#define SDL_SCANCODE_LALT: #define SDL_SCANCODE_LALT SDLK_LALT
#define SDL_SCANCODE_RALT: keynum = K_ALT; break; #define SDL_SCANCODE_RALT SDLK_RALT
#define SDL_SCANCODE_LCTRL: #define SDL_SCANCODE_LCTRL SDLK_LCTRL
#define SDL_SCANCODE_RCTRL: keynum = K_CTRL; break; #define SDL_SCANCODE_RCTRL SDLK_RCTRL
#define SDL_SCANCODE_LSHIFT: #define SDL_SCANCODE_LSHIFT SDLK_LSHIFT
#define SDL_SCANCODE_RSHIFT: keynum = K_SHIFT; break; #define SDL_SCANCODE_RSHIFT SDLK_RSHIFT
#define SDL_SCANCODE_LGUI: #define SDL_SCANCODE_LGUI SDLK_LMETA
#define SDL_SCANCODE_RGUI: keynum = K_WIN; break; #define SDL_SCANCODE_RGUI SDLK_RMETA
#define SDL_SCANCODE_INSERT: keynum = K_INS; break; #define SDL_SCANCODE_INSERT SDLK_INSERT
#define SDL_SCANCODE_DELETE: keynum = K_DEL; break; #define SDL_SCANCODE_DELETE SDLK_DELETE
#define SDL_SCANCODE_PAGEDOWN: keynum = K_PGDN; break; #define SDL_SCANCODE_PAGEDOWN SDLK_PAGEDOWN
#define SDL_SCANCODE_PAGEUP: keynum = K_PGUP; break; #define SDL_SCANCODE_PAGEUP SDLK_PAGEUP
#define SDL_SCANCODE_HOME: keynum = K_HOME; break; #define SDL_SCANCODE_HOME SDLK_HOME
#define SDL_SCANCODE_END: keynum = K_END; break; #define SDL_SCANCODE_END SDLK_END
#define SDL_SCANCODE_KP_1: keynum = numLock ? '1' : K_KP_END; break; #define SDL_SCANCODE_KP_1 SDLK_KP1
#define SDL_SCANCODE_KP_2: keynum = numLock ? '2' : K_KP_DOWNARROW; break; #define SDL_SCANCODE_KP_2 SDLK_KP2
#define SDL_SCANCODE_KP_3: keynum = numLock ? '3' : K_KP_PGDN; break; #define SDL_SCANCODE_KP_3 SDLK_KP3
#define SDL_SCANCODE_KP_4: keynum = numLock ? '4' : K_KP_LEFTARROW; break; #define SDL_SCANCODE_KP_4 SDLK_KP4
#define SDL_SCANCODE_KP_5: keynum = numLock ? '5' : K_KP_5; break; #define SDL_SCANCODE_KP_5 SDLK_KP5
#define SDL_SCANCODE_KP_6: keynum = numLock ? '6' : K_KP_RIGHTARROW; break; #define SDL_SCANCODE_KP_6 SDLK_KP6
#define SDL_SCANCODE_KP_7: keynum = numLock ? '7' : K_KP_HOME; break; #define SDL_SCANCODE_KP_7 SDLK_KP7
#define SDL_SCANCODE_KP_8: keynum = numLock ? '8' : K_KP_UPARROW; break; #define SDL_SCANCODE_KP_8 SDLK_KP8
#define SDL_SCANCODE_KP_9: keynum = numLock ? '9' : K_KP_PGUP; break; #define SDL_SCANCODE_KP_9 SDLK_KP9
#define SDL_SCANCODE_KP_0: keynum = numLock ? '0' : K_KP_INS; break; #define SDL_SCANCODE_KP_0 SDLK_KP0
#define SDL_SCANCODE_KP_PERIOD: keynum = K_KP_DEL; break; #define SDL_SCANCODE_KP_PERIOD SDLK_KP_PERIOD
#define SDL_SCANCODE_KP_ENTER: keynum = K_KP_ENTER; break; #define SDL_SCANCODE_KP_ENTER SDLK_KP_ENTER
#define SDL_SCANCODE_KP_PLUS: keynum = K_KP_PLUS; break; #define SDL_SCANCODE_KP_PLUS SDLK_KP_PLUS
#define SDL_SCANCODE_KP_MINUS: keynum = K_KP_MINUS; break; #define SDL_SCANCODE_KP_MINUS SDLK_KP_MINUS
#define SDL_SCANCODE_KP_DIVIDE: keynum = K_KP_SLASH; break; #define SDL_SCANCODE_KP_DIVIDE SDLK_KP_DIVIDE
#define SDL_SCANCODE_KP_MULTIPLY: keynum = '*'; break; #define SDL_SCANCODE_KP_MULTIPLY SDLK_KP_MULTIPLY
#define SDL_SCANCODE_NUMLOCKCLEAR: keynum = K_KP_NUMLOCK; break; #define SDL_SCANCODE_NUMLOCKCLEAR SDLK_NUMLOCK
#define SDL_SCANCODE_CAPSLOCK: keynum = K_CAPSLOCK; break; #define SDL_SCANCODE_CAPSLOCK SDLK_CAPSLOCK
#define SDL_SCANCODE_APPLICATION: keynum = K_WIN; break; // (compose key) ??? #define SDL_SCANCODE_SLASH SDLK_SLASH
#define SDL_SCANCODE_SLASH: keynum = '/'; break; #define SDL_SCANCODE_PERIOD SDLK_PERIOD
#define SDL_SCANCODE_PERIOD: keynum = '.'; break; #define SDL_SCANCODE_SEMICOLON SDLK_SEMICOLON
#define SDL_SCANCODE_SEMICOLON: keynum = ';'; break; #define SDL_SCANCODE_APOSTROPHE SDLK_QUOTE
#define SDL_SCANCODE_APOSTROPHE: keynum = '\''; break; #define SDL_SCANCODE_COMMA SDLK_COMMA
#define SDL_SCANCODE_COMMA: keynum = ','; break; #define SDL_SCANCODE_PRINTSCREEN SDLK_PRINT
#define SDL_SCANCODE_PRINTSCREEN: #define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN
#define SDL_GetScancodeName( x ) "unknown"
#endif #endif
/* /*
@ -100,10 +102,13 @@ SDLash_KeyEvent
static void SDLash_KeyEvent( SDL_KeyboardEvent key ) static void SDLash_KeyEvent( SDL_KeyboardEvent key )
{ {
int down = key.state != SDL_RELEASED; int down = key.state != SDL_RELEASED;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
int keynum = key.keysym.scancode; int keynum = key.keysym.scancode;
#else
int keynum = key.keysym.sym;
#endif
qboolean numLock = SDL_GetModState() & KMOD_NUM; qboolean numLock = SDL_GetModState() & KMOD_NUM;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_IsTextInputActive() && down ) if( SDL_IsTextInputActive() && down )
{ {
if( SDL_GetModState() & KMOD_CTRL ) if( SDL_GetModState() & KMOD_CTRL )
@ -116,8 +121,23 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
return; return;
} }
#if !SDL_VERSION_ATLEAST( 2, 0, 0 )
if( keynum >= SDLK_KP0 && keynum <= SDLK_KP9 )
keynum -= SDLK_KP0 + '0';
if( isprint( keynum ) )
{
if( SDL_GetModState() & KMOD_SHIFT )
{
keynum = Key_ToUpper( keynum );
}
CL_CharEvent( keynum );
return;
}
#endif
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
#define DECLARE_KEY_RANGE( min, max, repl ) \ #define DECLARE_KEY_RANGE( min, max, repl ) \
if( keynum >= (min) && keynum <= (max) ) \ if( keynum >= (min) && keynum <= (max) ) \
@ -180,7 +200,6 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
case SDL_SCANCODE_KP_MULTIPLY: keynum = '*'; break; case SDL_SCANCODE_KP_MULTIPLY: keynum = '*'; break;
case SDL_SCANCODE_NUMLOCKCLEAR: keynum = K_KP_NUMLOCK; break; case SDL_SCANCODE_NUMLOCKCLEAR: keynum = K_KP_NUMLOCK; break;
case SDL_SCANCODE_CAPSLOCK: keynum = K_CAPSLOCK; break; case SDL_SCANCODE_CAPSLOCK: keynum = K_CAPSLOCK; break;
case SDL_SCANCODE_APPLICATION: keynum = K_WIN; break; // (compose key) ???
case SDL_SCANCODE_SLASH: keynum = '/'; break; case SDL_SCANCODE_SLASH: keynum = '/'; break;
case SDL_SCANCODE_PERIOD: keynum = '.'; break; case SDL_SCANCODE_PERIOD: keynum = '.'; break;
case SDL_SCANCODE_SEMICOLON: keynum = ';'; break; case SDL_SCANCODE_SEMICOLON: keynum = ';'; break;
@ -193,6 +212,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
break; break;
} }
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_SCANCODE_APPLICATION: keynum = K_WIN; break; // (compose key) ???
// don't console spam on known functional buttons, but not used in engine // don't console spam on known functional buttons, but not used in engine
case SDL_SCANCODE_MUTE: case SDL_SCANCODE_MUTE:
case SDL_SCANCODE_VOLUMEUP: case SDL_SCANCODE_VOLUMEUP:
@ -200,7 +220,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
case SDL_SCANCODE_BRIGHTNESSDOWN: case SDL_SCANCODE_BRIGHTNESSDOWN:
case SDL_SCANCODE_BRIGHTNESSUP: case SDL_SCANCODE_BRIGHTNESSUP:
return; return;
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_SCANCODE_UNKNOWN: case SDL_SCANCODE_UNKNOWN:
{ {
if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown scancode\n" ); if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown scancode\n" );
@ -211,88 +231,22 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
return; return;
} }
} }
#else
DECLARE_KEY_RANGE( SDLK_a, SDLK_z, 'a' ) #undef DECLARE_KEY_RANGE
else DECLARE_KEY_RANGE( SDLK_1, SDLK_9, '1' )
else DECLARE_KEY_RANGE( SDLK_F1, SDLK_F12, K_F1 ) Key_Event( keynum, down );
else }
{
switch( keynum ) static void SDLash_MouseKey( int key, int down, int istouch )
{ {
case SDLK_BACKQUOTE: keynum = '`'; break; if( CVAR_TO_BOOL( touch_emulate ) )
case SDLK_0: keynum = '0'; break;
case SDLK_BACKSLASH: keynum = '\\'; break;
case SDLK_LEFTBRACKET: keynum = '['; break;
case SDLK_RIGHTBRACKET: keynum = ']'; break;
case SDLK_EQUALS: keynum = '='; break;
case SDLK_MINUS: keynum = '-'; break;
case SDLK_TAB: keynum = K_TAB; break;
case SDLK_RETURN: keynum = K_ENTER; break;
case SDLK_ESCAPE: keynum = K_ESCAPE; break;
case SDLK_SPACE: keynum = K_SPACE; break;
case SDLK_BACKSPACE: keynum = K_BACKSPACE; break;
case SDLK_UP: keynum = K_UPARROW; break;
case SDLK_LEFT: keynum = K_LEFTARROW; break;
case SDLK_DOWN: keynum = K_DOWNARROW; break;
case SDLK_RIGHT: keynum = K_RIGHTARROW; break;
case SDLK_LALT:
case SDLK_RALT: keynum = K_ALT; break;
case SDLK_LCTRL:
case SDLK_RCTRL: keynum = K_CTRL; break;
case SDLK_LSHIFT:
case SDLK_RSHIFT: keynum = K_SHIFT; break;
case SDLK_LMETA:
case SDLK_RMETA: keynum = K_WIN; break;
case SDLK_INSERT: keynum = K_INS; break;
case SDLK_DELETE: keynum = K_DEL; break;
case SDLK_PAGEDOWN: keynum = K_PGDN; break;
case SDLK_PAGEUP: keynum = K_PGUP; break;
case SDLK_HOME: keynum = K_HOME; break;
case SDLK_END: keynum = K_END; break;
case SDLK_KP1: keynum = numLock ? '1' : K_KP_END; break;
case SDLK_KP2: keynum = numLock ? '2' : K_KP_DOWNARROW; break;
case SDLK_KP3: keynum = numLock ? '3' : K_KP_PGDN; break;
case SDLK_KP4: keynum = numLock ? '4' : K_KP_LEFTARROW; break;
case SDLK_KP5: keynum = numLock ? '5' : K_KP_5; break;
case SDLK_KP6: keynum = numLock ? '6' : K_KP_RIGHTARROW; break;
case SDLK_KP7: keynum = numLock ? '7' : K_KP_HOME; break;
case SDLK_KP8: keynum = numLock ? '8' : K_KP_UPARROW; break;
case SDLK_KP9: keynum = numLock ? '9' : K_KP_PGUP; break;
case SDLK_KP0: keynum = numLock ? '0' : K_KP_INS; break;
case SDLK_KP_PERIOD: keynum = K_KP_DEL; break;
case SDLK_KP_ENTER: keynum = K_KP_ENTER; break;
case SDLK_KP_PLUS: keynum = K_KP_PLUS; break;
case SDLK_KP_MINUS: keynum = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: keynum = K_KP_SLASH; break;
case SDLK_KP_MULTIPLY: keynum = '*'; break;
case SDLK_NUMLOCK: keynum = K_KP_NUMLOCK; break;
case SDLK_CAPSLOCK: keynum = K_CAPSLOCK; break;
case SDLK_SLASH: keynum = '/'; break;
case SDLK_PERIOD: keynum = '.'; break;
case SDLK_SEMICOLON: keynum = ';'; break;
case SDLK_QUOTE: keynum = '\''; break;
case SDLK_COMMA: keynum = ','; break;
case SDLK_PRINT:
{ {
host.force_draw_version = true; Touch_KeyEvent( key, down );
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
break;
} }
case SDLK_UNKNOWN: else if( in_mouseinitialized && !m_ignore->value && !istouch )
{ {
if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown scancode\n" ); Key_Event( key, down );
return;
}
default:
if( down ) Con_Reportf( "SDLash_KeyEvent: Unknown key: %s = %i\n", SDL_GetScancodeName( keynum ), keynum );
return;
}
} }
#endif
#undef DECLARE_KEY_RANGE
Key_Event( keynum, down );
} }
/* /*
@ -304,14 +258,41 @@ SDLash_MouseEvent
static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
{ {
int down = button.state != SDL_RELEASED; int down = button.state != SDL_RELEASED;
qboolean istouch;
if( CVAR_TO_BOOL( touch_emulate ) ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
{ istouch = button.which == SDL_TOUCH_MOUSEID;
Touch_KeyEvent( K_MOUSE1 - 1 + button.button, down ); #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
} istouch = false;
else if( in_mouseinitialized && !m_ignore->value && button.which != SDL_TOUCH_MOUSEID ) #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
switch( button.button )
{ {
Key_Event( K_MOUSE1 - 1 + button.button, down ); case SDL_BUTTON_LEFT:
SDLash_MouseKey( K_MOUSE1, down, istouch );
break;
case SDL_BUTTON_RIGHT:
SDLash_MouseKey( K_MOUSE2, down, istouch );
break;
case SDL_BUTTON_MIDDLE:
SDLash_MouseKey( K_MOUSE3, down, istouch );
break;
case SDL_BUTTON_X1:
SDLash_MouseKey( K_MOUSE4, down, istouch );
break;
case SDL_BUTTON_X2:
SDLash_MouseKey( K_MOUSE5, down, istouch );
break;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_BUTTON_WHEELUP:
Key_Event( K_MWHEELUP, down );
break;
case SDL_BUTTON_WHEELDOWN:
Key_Event( K_MWHEELDOWN, down );
break;
#endif // ! SDL_VERSION_ATLEAST( 2, 0, 0 )
default:
Con_Printf( "Unknown mouse button ID: %d\n", button.button );
} }
} }
@ -321,6 +302,7 @@ SDLash_InputEvent
============= =============
*/ */
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
static void SDLash_InputEvent( SDL_TextInputEvent input ) static void SDLash_InputEvent( SDL_TextInputEvent input )
{ {
char *text; char *text;
@ -339,6 +321,43 @@ static void SDLash_InputEvent( SDL_TextInputEvent input )
CL_CharEvent( ch ); CL_CharEvent( ch );
} }
} }
#endif // SDL_VERSION_AT_LEAST( 2, 0, 0 )
static void SDLash_ActiveEvent( int gain )
{
if( gain )
{
host.status = HOST_FRAME;
IN_ActivateMouse(true);
if( snd_mute_losefocus->value )
{
SNDDMA_Activate( true );
}
host.force_draw_version = true;
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
if( vid_fullscreen->value )
VID_SetMode();
}
else
{
#if TARGET_OS_IPHONE
{
// Keep running if ftp server enabled
void IOS_StartBackgroundTask( void );
IOS_StartBackgroundTask();
}
#endif
host.status = HOST_NOFOCUS;
IN_DeactivateMouse();
if( snd_mute_losefocus->value )
{
SNDDMA_Activate( false );
}
host.force_draw_version = true;
host.force_draw_version_time = host.realtime + 2;
VID_RestoreScreenResolution();
}
}
/* /*
============= =============
@ -360,27 +379,53 @@ static void SDLash_EventFilter( SDL_Event *event )
{ {
/* Mouse events */ /* Mouse events */
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if( !host.mouse_visible && event->motion.which != SDL_TOUCH_MOUSEID ) if( !host.mouse_visible
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
&& event->motion.which != SDL_TOUCH_MOUSEID )
#else
)
#endif
IN_MouseEvent(); IN_MouseEvent();
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
SDLash_MouseEvent( event->button ); SDLash_MouseEvent( event->button );
break; break;
case SDL_MOUSEWHEEL:
wheelbutton = event->wheel.y < 0 ? K_MWHEELDOWN : K_MWHEELUP;
Key_Event( wheelbutton, true );
break;
/* Keyboard events */ /* Keyboard events */
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
SDLash_KeyEvent( event->key ); SDLash_KeyEvent( event->key );
break; break;
/* Joystick events */
case SDL_JOYAXISMOTION:
Joy_AxisMotionEvent( event->jaxis.axis, event->jaxis.value );
break;
case SDL_JOYBALLMOTION:
Joy_BallMotionEvent( event->jball.ball, event->jball.xrel, event->jball.yrel );
break;
case SDL_JOYHATMOTION:
Joy_HatMotionEvent( event->jhat.hat, event->jhat.value );
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
Joy_ButtonEvent( event->jbutton.button, event->jbutton.state );
break;
case SDL_QUIT:
Sys_Quit();
break;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_MOUSEWHEEL:
wheelbutton = event->wheel.y < 0 ? K_MWHEELDOWN : K_MWHEELUP;
Key_Event( wheelbutton, true );
break;
/* Touch events */ /* Touch events */
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
case SDL_FINGERUP: case SDL_FINGERUP:
@ -435,30 +480,11 @@ static void SDLash_EventFilter( SDL_Event *event )
break; break;
} }
/* IME */ /* IME */
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
SDLash_InputEvent( event->text ); SDLash_InputEvent( event->text );
break; break;
/* Joystick events */
case SDL_JOYAXISMOTION:
Joy_AxisMotionEvent( event->jaxis.axis, event->jaxis.value );
break;
case SDL_JOYBALLMOTION:
Joy_BallMotionEvent( event->jball.ball, event->jball.xrel, event->jball.yrel );
break;
case SDL_JOYHATMOTION:
Joy_HatMotionEvent( event->jhat.hat, event->jhat.value );
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
Joy_ButtonEvent( event->jbutton.button, event->jbutton.state );
break;
case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEADDED:
Joy_AddEvent(); Joy_AddEvent();
break; break;
@ -508,10 +534,6 @@ static void SDLash_EventFilter( SDL_Event *event )
Joy_RemoveEvent( ); Joy_RemoveEvent( );
break; break;
case SDL_QUIT:
Sys_Quit();
break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if( event->window.windowID != SDL_GetWindowID( host.hWnd ) ) if( event->window.windowID != SDL_GetWindowID( host.hWnd ) )
return; return;
@ -540,47 +562,35 @@ static void SDLash_EventFilter( SDL_Event *event )
VID_SetMode(); VID_SetMode();
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
host.status = HOST_FRAME; SDLash_ActiveEvent( true );
IN_ActivateMouse(true);
if( snd_mute_losefocus->value )
{
SNDDMA_Activate( true );
}
host.force_draw_version = true;
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
if( vid_fullscreen->value )
VID_SetMode();
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
#if TARGET_OS_IPHONE SDLash_ActiveEvent( false );
{
// Keep running if ftp server enabled
void IOS_StartBackgroundTask( void );
IOS_StartBackgroundTask();
}
#endif
host.status = HOST_NOFOCUS;
IN_DeactivateMouse();
if( snd_mute_losefocus->value )
{
SNDDMA_Activate( false );
}
host.force_draw_version = true;
host.force_draw_version_time = host.realtime + 2;
VID_RestoreScreenResolution();
break; break;
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_MAXIMIZED:
{ {
int w = VID_MIN_WIDTH, h = VID_MIN_HEIGHT;
if( vid_fullscreen->value ) if( vid_fullscreen->value )
break; break;
VID_SaveWindowSize( event->window.data1, event->window.data2 ); SDL_GL_GetDrawableSize( host.hWnd, &w, &h );
SCR_VidInit(); // tell the client.dll what vid_mode has changed R_SaveVideoMode( w, h );
SCR_VidInit(); // tell the client.dll that vid_mode has changed
break; break;
} }
default: default:
break; break;
} }
#else
case SDL_VIDEORESIZE:
R_SaveVideoMode( event->resize.w, event->resize.h );
SCR_VidInit();
break; // tell the client.dll that vid_mode has changed
case SDL_ACTIVEEVENT:
SDLash_ActiveEvent( event->active.gain );
break;
#endif
} }
} }

12
engine/platform/sdl/s_sdl.c

@ -31,6 +31,9 @@ GNU General Public License for more details.
#define SDL_OpenAudioDevice( a, b, c, d, e ) SDL_OpenAudio( ( c ), ( d ) ) #define SDL_OpenAudioDevice( a, b, c, d, e ) SDL_OpenAudio( ( c ), ( d ) )
#define SDL_CloseAudioDevice( a ) SDL_CloseAudio() #define SDL_CloseAudioDevice( a ) SDL_CloseAudio()
#define SDL_PauseAudioDevice( a, b ) SDL_PauseAudio( ( b ) ) #define SDL_PauseAudioDevice( a, b ) SDL_PauseAudio( ( b ) )
#define SDLash_IsAudioError( x ) ( x ) != 0
#else
#define SDLash_IsAudioError( x ) ( x ) == 0
#endif #endif
/* /*
@ -50,6 +53,11 @@ void SDL_SoundCallback( void *userdata, Uint8 *stream, int len )
int pos = dma.samplepos << 1; int pos = dma.samplepos << 1;
int wrapped = pos + len - size; int wrapped = pos + len - size;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !dma.buffer )
return;
#endif
if( wrapped < 0 ) if( wrapped < 0 )
{ {
memcpy( stream, dma.buffer + pos, len ); memcpy( stream, dma.buffer + pos, len );
@ -97,7 +105,7 @@ qboolean SNDDMA_Init( void )
sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 ); sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 );
if( !sdl_dev ) if( SDLash_IsAudioError( sdl_dev ))
{ {
Con_Printf( "Couldn't open SDL audio: %s\n", SDL_GetError( ) ); Con_Printf( "Couldn't open SDL audio: %s\n", SDL_GetError( ) );
return false; return false;
@ -122,7 +130,7 @@ qboolean SNDDMA_Init( void )
if( !samplecount ) if( !samplecount )
samplecount = 0x8000; samplecount = 0x8000;
dma.samples = samplecount * obtained.channels; dma.samples = samplecount * obtained.channels;
dma.buffer = Z_Malloc( dma.samples * 2 ); dma.buffer = Z_Calloc( dma.samples * 2 );
dma.samplepos = 0; dma.samplepos = 0;
Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), obtained.freq ); Con_Printf( "Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver( ), obtained.freq );

2
engine/platform/sdl/sys_sdl.c

@ -38,7 +38,9 @@ void Platform_Sleep( int msec )
} }
#endif // XASH_TIMER == TIMER_SDL #endif // XASH_TIMER == TIMER_SDL
#if XASH_MESSAGEBOX == MSGBOX_SDL
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ) void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
{ {
SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, title, message, parentMainWindow ? host.hWnd : NULL ); SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, title, message, parentMainWindow ? host.hWnd : NULL );
} }
#endif // XASH_MESSAGEBOX == MSGBOX_SDL

164
engine/platform/sdl/vid_sdl.c

@ -57,7 +57,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
// guess // guess
if( format == SDL_PIXELFORMAT_UNKNOWN ) if( format == SDL_PIXELFORMAT_UNKNOWN )
{ {
if( glw_state.desktopBitsPixel == 16 ) if( refState.desktopBitsPixel == 16 )
format = SDL_PIXELFORMAT_RGB565; format = SDL_PIXELFORMAT_RGB565;
else else
format = SDL_PIXELFORMAT_RGBA8888; format = SDL_PIXELFORMAT_RGBA8888;
@ -234,7 +234,9 @@ void SW_UnlockBuffer( void )
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_UpdateWindowSurface( host.hWnd ); SDL_UpdateWindowSurface( host.hWnd );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Flip( host.hWnd );
#endif
} }
int R_MaxVideoModes( void ) int R_MaxVideoModes( void )
@ -269,7 +271,6 @@ static void R_InitVideoModes( void )
for( i = 0; i < modes; i++ ) for( i = 0; i < modes; i++ )
{ {
int j; int j;
qboolean skip = false;
SDL_DisplayMode mode; SDL_DisplayMode mode;
if( SDL_GetDisplayMode( displayIndex, i, &mode ) ) if( SDL_GetDisplayMode( displayIndex, i, &mode ) )
@ -286,7 +287,6 @@ static void R_InitVideoModes( void )
if( mode.w == vidmodes[j].width && if( mode.w == vidmodes[j].width &&
mode.h == vidmodes[j].height ) mode.h == vidmodes[j].height )
{ {
skip = true;
break; break;
} }
} }
@ -300,8 +300,38 @@ static void R_InitVideoModes( void )
num_vidmodes++; num_vidmodes++;
} }
#else // SDL_VERSION_ATLEAST( 2, 0, 0 ) #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Rect **modes = SDL_ListModes( NULL, SDL_FULLSCREEN );
int len = 0, i = 0, j;
if( !modes || modes == (void*)-1 )
return;
for( len = 0; modes[len]; len++ );
vidmodes = Mem_Malloc( host.mempool, len * sizeof( vidmode_t ) );
// from smallest to largest
for( ; i < len; i++ )
{
SDL_Rect *mode = modes[len - i - 1];
# error TODO for( j = 0; j < num_vidmodes; j++ )
{
if( mode->w == vidmodes[j].width &&
mode->h == vidmodes[j].height )
{
break;
}
}
if( j != num_vidmodes )
continue;
vidmodes[num_vidmodes].width = mode->w;
vidmodes[num_vidmodes].height = mode->h;
vidmodes[num_vidmodes].desc = copystring( va( "%ix%i", mode->w, mode->h ));
num_vidmodes++;
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 ) #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
@ -511,6 +541,7 @@ void VID_SaveWindowSize( int width, int height )
static qboolean VID_SetScreenResolution( int width, int height ) static qboolean VID_SetScreenResolution( int width, int height )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode want, got; SDL_DisplayMode want, got;
Uint32 wndFlags = 0; Uint32 wndFlags = 0;
static string wndname; static string wndname;
@ -539,13 +570,16 @@ static qboolean VID_SetScreenResolution( int width, int height )
SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
SDL_SetWindowSize( host.hWnd, got.w, got.h ); SDL_SetWindowSize( host.hWnd, got.w, got.h );
VID_SaveWindowSize( got.w, got.h ); VID_SaveWindowSize( gow.w, got.h );
#else
VID_SaveWindowSize( width, height );
#endif
return true; return true;
} }
void VID_RestoreScreenResolution( void ) void VID_RestoreScreenResolution( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !Cvar_VariableInteger("fullscreen") ) if( !Cvar_VariableInteger("fullscreen") )
{ {
SDL_SetWindowBordered( host.hWnd, SDL_TRUE ); SDL_SetWindowBordered( host.hWnd, SDL_TRUE );
@ -556,6 +590,7 @@ void VID_RestoreScreenResolution( void )
SDL_MinimizeWindow( host.hWnd ); SDL_MinimizeWindow( host.hWnd );
SDL_SetWindowFullscreen( host.hWnd, 0 ); SDL_SetWindowFullscreen( host.hWnd, 0 );
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
#if defined(_WIN32) && !defined(XASH_64BIT) // ICO support only for Win32 #if defined(_WIN32) && !defined(XASH_64BIT) // ICO support only for Win32
@ -582,6 +617,7 @@ VID_CreateWindow
qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
{ {
static string wndname; static string wndname;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
Uint32 wndFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS; Uint32 wndFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS;
rgbdata_t *icon = NULL; rgbdata_t *icon = NULL;
qboolean iconLoaded = false; qboolean iconLoaded = false;
@ -733,7 +769,53 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
} }
VID_SaveWindowSize( width, height ); #else // SDL_VERSION_ATLEAST( 2, 0, 0 )
Uint32 flags = 0;
if( fullscreen )
{
// flags |= SDL_FULLSCREEN;
}
if( glw_state.software )
{
// flags |= SDL_ASYNCBLIT;
}
else
{
flags |= SDL_OPENGL;
}
while( glw_state.safe >= SAFE_NO && glw_state.safe < SAFE_LAST )
{
host.hWnd = sw.surf = SDL_SetVideoMode( width, height, 0, flags );
// we have window, exit loop
if( host.hWnd )
break;
Con_Reportf( S_ERROR "VID_CreateWindow: couldn't create '%s' with safegl level %d: %s\n", wndname, glw_state.safe, SDL_GetError());
glw_state.safe++;
if( !gl_wgl_msaa_samples->value && glw_state.safe == SAFE_NOMSAA )
glw_state.safe++; // no need to skip msaa, if we already disabled it
GL_SetupAttributes(); // re-choose attributes
// try again create window
}
// window creation has failed...
if( glw_state.safe >= SAFE_LAST )
{
return false;
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
VID_SaveVideoMode( width, height );
return true; return true;
} }
@ -750,7 +832,9 @@ void VID_DestroyWindow( void )
VID_RestoreScreenResolution(); VID_RestoreScreenResolution();
if( host.hWnd ) if( host.hWnd )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DestroyWindow ( host.hWnd ); SDL_DestroyWindow ( host.hWnd );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
host.hWnd = NULL; host.hWnd = NULL;
} }
@ -767,14 +851,20 @@ GL_SetupAttributes
*/ */
static void GL_SetupAttributes( void ) static void GL_SetupAttributes( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_GL_ResetAttributes(); SDL_GL_ResetAttributes();
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
ref.dllFuncs.GL_SetupAttributes( glw_state.safe ); ref.dllFuncs.GL_SetupAttributes( glw_state.safe );
} }
void GL_SwapBuffers( void ) void GL_SwapBuffers( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_GL_SwapWindow( host.hWnd ); SDL_GL_SwapWindow( host.hWnd );
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Flip( host.hWnd );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
int GL_SetAttribute( int attr, int val ) int GL_SetAttribute( int attr, int val )
@ -792,12 +882,20 @@ int GL_SetAttribute( int attr, int val )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL );
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE );
case REF_GL_CONTEXT_PROFILE_MASK:
#ifdef SDL_HINT_OPENGL_ES_DRIVER
if( val == REF_GL_CONTEXT_PROFILE_ES )
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1");
#endif // SDL_HINT_OPENGL_ES_DRIVER
return SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, val );
#endif
#if SDL_VERSION_ATLEAST( 2, 0, 4 ) #if SDL_VERSION_ATLEAST( 2, 0, 4 )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR );
#endif #endif
@ -805,16 +903,9 @@ int GL_SetAttribute( int attr, int val )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR );
#endif #endif
case REF_GL_CONTEXT_PROFILE_MASK:
#ifdef SDL_HINT_OPENGL_ES_DRIVER
if (val == REF_GL_CONTEXT_PROFILE_ES)
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1");
#endif // SDL_HINT_OPENGL_ES_DRIVER
return SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, val );
#undef MAP_REF_API_ATTRIBUTE_TO_SDL #undef MAP_REF_API_ATTRIBUTE_TO_SDL
} }
ASSERT( 0 );
return -1; return -1;
} }
@ -833,12 +924,15 @@ int GL_GetAttribute( int attr, int *val )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL );
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_PROFILE_MASK );
#endif
#if SDL_VERSION_ATLEAST( 2, 0, 4 ) #if SDL_VERSION_ATLEAST( 2, 0, 4 )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR );
#endif #endif
@ -846,11 +940,9 @@ int GL_GetAttribute( int attr, int *val )
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION );
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR ); MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR );
#endif #endif
MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_PROFILE_MASK );
#undef MAP_REF_API_ATTRIBUTE_TO_SDL #undef MAP_REF_API_ATTRIBUTE_TO_SDL
} }
ASSERT( 0 );
return 0; return 0;
} }
@ -865,18 +957,23 @@ R_Init_Video
*/ */
qboolean R_Init_Video( const int type ) qboolean R_Init_Video( const int type )
{ {
SDL_DisplayMode displayMode;
string safe; string safe;
qboolean retval; qboolean retval;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode displayMode;
SDL_GetCurrentDisplayMode(0, &displayMode); SDL_GetCurrentDisplayMode(0, &displayMode);
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format); refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format );
glw_state.desktopWidth = displayMode.w; #else
glw_state.desktopHeight = displayMode.h; refState.desktopBitsPixel = 32;
#endif
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_VideoInit( "caca", 0 );
#else
#if !defined(_WIN32) #if !defined(_WIN32)
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" ); SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" ); SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif
#endif #endif
R_InitVideoModes(); R_InitVideoModes();
@ -932,16 +1029,16 @@ qboolean R_Init_Video( const int type )
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode displayMode; SDL_DisplayMode displayMode;
SDL_GetCurrentDisplayMode( 0, &displayMode ); SDL_GetCurrentDisplayMode( 0, &displayMode );
Con_Reportf( "R_ChangeDisplaySettings: Setting video mode to %dx%d %s\n", width, height, fullscreen ? "fullscreen" : "windowed" );
// check our desktop attributes // check our desktop attributes
glw_state.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format ); refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format );
glw_state.desktopWidth = displayMode.w; #endif
glw_state.desktopHeight = displayMode.h;
Con_Reportf( "R_ChangeDisplaySettings: Setting video mode to %dx%d %s\n", width, height, fullscreen ? "fullscreen" : "windowed" );
refState.fullScreen = fullscreen; refState.fullScreen = fullscreen;
@ -958,6 +1055,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
else else
{ {
VID_RestoreScreenResolution(); VID_RestoreScreenResolution();
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_SetWindowFullscreen( host.hWnd, 0 ) ) if( SDL_SetWindowFullscreen( host.hWnd, 0 ) )
return rserr_invalid_fullscreen; return rserr_invalid_fullscreen;
#if SDL_VERSION_ATLEAST( 2, 0, 5 ) #if SDL_VERSION_ATLEAST( 2, 0, 5 )
@ -965,7 +1063,9 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
#endif #endif
SDL_SetWindowBordered( host.hWnd, SDL_TRUE ); SDL_SetWindowBordered( host.hWnd, SDL_TRUE );
SDL_SetWindowSize( host.hWnd, width, height ); SDL_SetWindowSize( host.hWnd, width, height );
VID_SaveWindowSize( width, height );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
VID_SaveVideoMode( width, height );
} }
return rserr_ok; return rserr_ok;
@ -987,6 +1087,7 @@ qboolean VID_SetMode( void )
iScreenWidth = Cvar_VariableInteger( "width" ); iScreenWidth = Cvar_VariableInteger( "width" );
iScreenHeight = Cvar_VariableInteger( "height" ); iScreenHeight = Cvar_VariableInteger( "height" );
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( iScreenWidth < VID_MIN_WIDTH || if( iScreenWidth < VID_MIN_WIDTH ||
iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default
{ {
@ -1001,12 +1102,13 @@ qboolean VID_SetMode( void )
iScreenWidth = DEFAULT_MODE_WIDTH; iScreenWidth = DEFAULT_MODE_WIDTH;
iScreenHeight = DEFAULT_MODE_HEIGHT; iScreenHeight = DEFAULT_MODE_HEIGHT;
#endif #endif
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) ) if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) )
Cvar_SetValue( "fullscreen", DEFAULT_FULLSCREEN ); Cvar_SetValue( "fullscreen", DEFAULT_FULLSCREEN );
else else
ClearBits( vid_fullscreen->flags, FCVAR_CHANGED ); ClearBits( vid_fullscreen->flags, FCVAR_CHANGED );
}
SetBits( gl_vsync->flags, FCVAR_CHANGED ); SetBits( gl_vsync->flags, FCVAR_CHANGED );
fullscreen = Cvar_VariableInteger("fullscreen") != 0; fullscreen = Cvar_VariableInteger("fullscreen") != 0;
@ -1057,6 +1159,10 @@ void R_Free_Video( void )
R_FreeVideoModes(); R_FreeVideoModes();
ref.dllFuncs.GL_ClearExtensions(); ref.dllFuncs.GL_ClearExtensions();
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_VideoQuit();
#endif
} }
#endif // XASH_DEDICATED #endif // XASH_DEDICATED

4
engine/platform/win32/sys_win.c

@ -53,9 +53,9 @@ void Platform_ShellExecute( const char *path, const char *parms )
ShellExecute( NULL, "open", path, parms, NULL, SW_SHOW ); ShellExecute( NULL, "open", path, parms, NULL, SW_SHOW );
} }
#ifdef XASH_DEDICATED #if XASH_MESSAGEBOX == MSGBOX_WIN32
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ) void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
{ {
MessageBox( parentMainWindow ? host.hWnd : NULL, message, title, MB_OK|MB_SETFOREGROUND|MB_ICONSTOP ); MessageBox( parentMainWindow ? host.hWnd : NULL, message, title, MB_OK|MB_SETFOREGROUND|MB_ICONSTOP );
} }
#endif #endif // XASH_MESSAGEBOX == MSGBOX_WIN32

Loading…
Cancel
Save