Merge sdl12-port into master

This commit is contained in:
Alibek Omarov 2019-11-06 22:29:04 +03:00
commit 0cb591821a
42 changed files with 709 additions and 280 deletions

View File

@ -47,4 +47,10 @@ GNU General Public License for more details.
#define TIMER_LINUX 2 #define TIMER_LINUX 2
#define TIMER_WIN32 3 #define TIMER_WIN32 3
// messageboxes (XASH_MESSAGEBOX)
#define MSGBOX_STDERR 0
#define MSGBOX_SDL 1
#define MSGBOX_ANDROID 2
#define MSGBOX_WIN32 3
#endif /* BACKENDS_H */ #endif /* BACKENDS_H */

View File

@ -16,11 +16,9 @@ GNU General Public License for more details.
#ifndef COM_MODEL_H #ifndef COM_MODEL_H
#define COM_MODEL_H #define COM_MODEL_H
#include "xash3d_types.h"
#include "bspfile.h" // we need some declarations from it #include "bspfile.h" // we need some declarations from it
typedef vec_t vec2_t[2];
typedef vec_t vec4_t[4];
/* /*
============================================================================== ==============================================================================
@ -232,7 +230,7 @@ typedef struct mextrasurf_s
int reserved[32]; // just for future expansions or mod-makers int reserved[32]; // just for future expansions or mod-makers
} mextrasurf_t; } mextrasurf_t;
typedef struct msurface_s struct msurface_s
{ {
int visframe; // should be drawn when node is crossed int visframe; // should be drawn when node is crossed
@ -264,7 +262,7 @@ typedef struct msurface_s
color24 *samples; // note: this is the actual lightmap data for this surface color24 *samples; // note: this is the actual lightmap data for this surface
decal_t *pdecals; decal_t *pdecals;
} msurface_t; };
typedef struct hull_s typedef struct hull_s
{ {

View File

@ -729,7 +729,6 @@ enum
typedef int func_t; typedef int func_t;
typedef int string_t; typedef int string_t;
typedef unsigned char byte;
typedef unsigned short word; typedef unsigned short word;
#include "xash3d_types.h" #include "xash3d_types.h"

View File

@ -27,17 +27,30 @@ SETUP BACKENDS DEFINITIONS
*/ */
#ifndef XASH_DEDICATED #ifndef XASH_DEDICATED
#ifdef XASH_SDL #if XASH_SDL == 2
#ifndef XASH_TIMER
#define XASH_TIMER TIMER_SDL
#endif
#ifndef XASH_MESSAGEBOX
#define XASH_MESSAGEBOX MSGBOX_SDL
#endif
#else
#ifndef XASH_TIMER
#define XASH_TIMER TIMER_LINUX
#endif
#ifndef XASH_MESSAGEBOX
#define XASH_MESSAGEBOX MSGBOX_STDERR
#endif
#endif
#ifdef XASH_SDL
// by default, use SDL subsystems // by default, use SDL subsystems
#ifndef XASH_VIDEO #ifndef XASH_VIDEO
#define XASH_VIDEO VIDEO_SDL #define XASH_VIDEO VIDEO_SDL
#endif // XASH_VIDEO #endif // XASH_VIDEO
#ifndef XASH_TIMER
#define XASH_TIMER TIMER_SDL
#endif
#ifndef XASH_INPUT #ifndef XASH_INPUT
#define XASH_INPUT INPUT_SDL #define XASH_INPUT INPUT_SDL
#endif #endif
@ -65,6 +78,10 @@ SETUP BACKENDS DEFINITIONS
#ifndef XASH_SOUND #ifndef XASH_SOUND
#define XASH_SOUND SOUND_OPENSLES #define XASH_SOUND SOUND_OPENSLES
#endif #endif
#ifndef XASH_MESSAGEBOX
#define XASH_MESSAGEBOX MSGBOX_ANDROID
#endif
#endif // android case #endif // android case
#ifdef XASH_FBDEV #ifdef XASH_FBDEV
@ -83,6 +100,10 @@ SETUP BACKENDS DEFINITIONS
#ifndef XASH_SOUND #ifndef XASH_SOUND
#define XASH_SOUND SOUND_ALSA #define XASH_SOUND SOUND_ALSA
#endif #endif
#ifndef XASH_MESSAGEBOX
#define XASH_MESSAGEBOX MSGBOX_STDERR
#endif
#define XASH_USE_EVDEV #define XASH_USE_EVDEV
#endif // android case #endif // android case
@ -125,6 +146,10 @@ SETUP BACKENDS DEFINITIONS
#define XASH_INPUT INPUT_NULL #define XASH_INPUT INPUT_NULL
#endif #endif
#ifndef XASH_MESSAGEBOX
#define XASH_MESSAGEBOX MSGBOX_STDERR
#endif
/* /*
========================================================================= =========================================================================

View File

@ -84,7 +84,6 @@ color24 gTracerColors[] =
#define FTENT_CLIENTCUSTOM 0x00080000 // Must specify callback. Callback function is responsible for killing tempent and updating fields ( unless other flags specify how to do things ) #define FTENT_CLIENTCUSTOM 0x00080000 // Must specify callback. Callback function is responsible for killing tempent and updating fields ( unless other flags specify how to do things )
#define FTENT_SCALE 0x00100000 // An experiment #define FTENT_SCALE 0x00100000 // An experiment
typedef struct tempent_s TEMPENTITY;
struct pmtrace_s; struct pmtrace_s;
typedef struct tempent_s typedef struct tempent_s
{ {
@ -99,7 +98,7 @@ typedef struct tempent_s
int hitSound; int hitSound;
void (*hitcallback)( struct tempent_s *ent, struct pmtrace_s *ptr ); void (*hitcallback)( struct tempent_s *ent, struct pmtrace_s *ptr );
void (*callback)( struct tempent_s *ent, float frametime, float currenttime ); void (*callback)( struct tempent_s *ent, float frametime, float currenttime );
TEMPENTITY *next; struct tempent_s *next;
int priority; int priority;
short clientIndex; // if attached, this is the index of the client to stick to short clientIndex; // if attached, this is the index of the client to stick to
// if COLLIDEALL, this is the index of the client to ignore // if COLLIDEALL, this is the index of the client to ignore

View File

@ -1988,7 +1988,7 @@ static int pfnGetWindowCenterX( void )
} }
#endif #endif
#ifdef XASH_SDL #if XASH_SDL == 2
SDL_GetWindowPosition( host.hWnd, &x, NULL ); SDL_GetWindowPosition( host.hWnd, &x, NULL );
#endif #endif
@ -2013,7 +2013,7 @@ static int pfnGetWindowCenterY( void )
} }
#endif #endif
#ifdef XASH_SDL #if XASH_SDL == 2
SDL_GetWindowPosition( host.hWnd, NULL, &y ); SDL_GetWindowPosition( host.hWnd, NULL, &y );
#endif #endif

View File

@ -1938,7 +1938,7 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
return; return;
} }
#ifdef XASH_SDL #if XASH_SDL == 2
SDL_ShowWindow( host.hWnd ); SDL_ShowWindow( host.hWnd );
#endif #endif
args = MSG_ReadString( msg ); args = MSG_ReadString( msg );

View File

@ -16,7 +16,11 @@ GNU General Public License for more details.
#include "common.h" #include "common.h"
#include "client.h" #include "client.h"
#if XASH_LOW_MEMORY
#define NET_TIMINGS 1024 #define NET_TIMINGS 1024
#else
#define NET_TIMINGS 64
#endif
#define NET_TIMINGS_MASK (NET_TIMINGS - 1) #define NET_TIMINGS_MASK (NET_TIMINGS - 1)
#define LATENCY_AVG_FRAC 0.5f #define LATENCY_AVG_FRAC 0.5f
#define FRAMERATE_AVG_FRAC 0.5f #define FRAMERATE_AVG_FRAC 0.5f

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
#ifndef CLIENT_H #ifndef CLIENT_H
#define CLIENT_H #define CLIENT_H
#include "xash3d_types.h"
#include "mathlib.h" #include "mathlib.h"
#include "cdll_int.h" #include "cdll_int.h"
#include "menu_int.h" #include "menu_int.h"
@ -38,8 +39,6 @@ GNU General Public License for more details.
#define SPR_HUDSPRITE 1 // hud sprite #define SPR_HUDSPRITE 1 // hud sprite
#define SPR_MAPSPRITE 2 // contain overview.bmp that diced into frames 128x128 #define SPR_MAPSPRITE 2 // contain overview.bmp that diced into frames 128x128
typedef int sound_t;
//============================================================================= //=============================================================================
typedef struct netbandwithgraph_s typedef struct netbandwithgraph_s
{ {
@ -1137,6 +1136,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];

View File

@ -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
#ifdef XASH_SDL #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( )))
{ {
#ifdef XASH_SDL
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;
#ifdef XASH_SDL
SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
#endif
} }
/* /*
@ -416,10 +416,12 @@ void IN_MouseEvent( void )
} }
else else
{ {
#if defined(XASH_SDL) && !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();
} }
} }

View File

@ -815,8 +815,7 @@ 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:
* *

View File

@ -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
#ifdef XASH_SDL #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;
} }
#ifdef XASH_SDL #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 ) )

View File

@ -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

View File

@ -41,8 +41,8 @@ typedef struct
float length; float length;
} sentence_t; } sentence_t;
typedef struct channel_s channel_t; struct channel_s;
void VOX_LoadWord( channel_t *pchan ); void VOX_LoadWord( struct channel_s *pchan );
void VOX_FreeWord( channel_t *pchan ); void VOX_FreeWord( struct channel_s *pchan );
#endif #endif

View File

@ -19,6 +19,7 @@ GNU General Public License for more details.
#include "const.h" #include "const.h"
#include "client.h" #include "client.h"
#include "library.h" #include "library.h"
#include "sequence.h"
static const char *file_exts[] = static const char *file_exts[] =
{ {

View File

@ -832,7 +832,7 @@ void HPAK_FlushHostQueue( void );
// shared calls // shared calls
struct physent_s; struct physent_s;
typedef struct sv_client_s sv_client_t; struct sv_client_s;
typedef struct sizebuf_s sizebuf_t; typedef struct sizebuf_s sizebuf_t;
qboolean CL_IsInGame( void ); qboolean CL_IsInGame( void );
qboolean CL_IsInMenu( void ); qboolean CL_IsInMenu( void );
@ -861,7 +861,7 @@ void SV_CreateDecal( sizebuf_t *msg, const float *origin, int decalIndex, int en
void Log_Printf( const char *fmt, ... ) _format( 1 ); void Log_Printf( const char *fmt, ... ) _format( 1 );
void SV_BroadcastCommand( const char *fmt, ... ) _format( 1 ); void SV_BroadcastCommand( const char *fmt, ... ) _format( 1 );
qboolean SV_RestoreCustomDecal( struct decallist_s *entry, edict_t *pEdict, qboolean adjacent ); qboolean SV_RestoreCustomDecal( struct decallist_s *entry, edict_t *pEdict, qboolean adjacent );
void SV_BroadcastPrintf( sv_client_t *ignore, char *fmt, ... ) _format( 2 ); void SV_BroadcastPrintf( struct sv_client_s *ignore, char *fmt, ... ) _format( 2 );
int R_CreateDecalList( struct decallist_s *pList ); int R_CreateDecalList( struct decallist_s *pList );
void R_ClearAllDecals( void ); void R_ClearAllDecals( void );
void CL_ClearStaticEntities( void ); void CL_ClearStaticEntities( void );
@ -963,14 +963,6 @@ void ID_Init( void );
const char *ID_GetMD5( void ); const char *ID_GetMD5( void );
void GAME_EXPORT ID_SetCustomClientID( const char *id ); void GAME_EXPORT ID_SetCustomClientID( const char *id );
//
// sequence.c
//
typedef struct sequenceEntry_ sequenceEntry_s;
typedef struct sentenceEntry_ sentenceEntry_s;
sequenceEntry_s *Sequence_Get( const char *fileName, const char *entryName );
sentenceEntry_s *Sequence_PickSentence( const char *groupName, int pickMethod, int *picked );
// //
// masterlist.c // masterlist.c
// //

View File

@ -74,7 +74,7 @@ typedef struct wadtype_s
signed char type; signed char type;
} wadtype_t; } wadtype_t;
typedef struct file_s struct file_s
{ {
int handle; // file descriptor int handle; // file descriptor
fs_offset_t real_length; // uncompressed file size (for files opened in "read" mode) fs_offset_t real_length; // uncompressed file size (for files opened in "read" mode)
@ -85,9 +85,9 @@ typedef struct file_s
// contents buffer // contents buffer
fs_offset_t buff_ind, buff_len; // buffer current index and length fs_offset_t buff_ind, buff_len; // buffer current index and length
byte buff[FILE_BUFF_SIZE]; // intermediate buffer byte buff[FILE_BUFF_SIZE]; // intermediate buffer
} file_t; };
typedef struct wfile_s struct wfile_s
{ {
string filename; string filename;
int infotableofs; int infotableofs;
@ -96,7 +96,7 @@ typedef struct wfile_s
file_t *handle; file_t *handle;
dlumpinfo_t *lumps; dlumpinfo_t *lumps;
time_t filetime; time_t filetime;
} wfile_t; };
typedef struct pack_s typedef struct pack_s
{ {

View File

@ -733,7 +733,7 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
#if TARGET_OS_IOS #if TARGET_OS_IOS
const char *IOS_GetDocsDir(); const char *IOS_GetDocsDir();
Q_strncpy( host.rootdir, IOS_GetDocsDir(), sizeof(host.rootdir) ); Q_strncpy( host.rootdir, IOS_GetDocsDir(), sizeof(host.rootdir) );
#elif defined(XASH_SDL) #elif XASH_SDL == 2
char *szBasePath; char *szBasePath;
if( !( szBasePath = SDL_GetBasePath() ) ) if( !( szBasePath = SDL_GetBasePath() ) )
@ -814,18 +814,21 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
#endif #endif
#ifdef XASH_SDL #ifdef XASH_SDL
// should work even if it failed #ifndef SDL_INIT_EVENTS
SDL_Init( SDL_INIT_TIMER ); #define SDL_INIT_EVENTS 0
#endif
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) )
{ {
Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); Sys_Warn( "SDL_Init failed: %s", SDL_GetError() );
host.type = HOST_DEDICATED; host.type = HOST_DEDICATED;
} }
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
#if XASH_SDL == 2
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
SDL_StopTextInput(); SDL_StopTextInput();
#endif #endif // XASH_SDL == 2
#endif // XASH_SDL
if ( !host.rootdir[0] || SetCurrentDirectory( host.rootdir ) != 0) if ( !host.rootdir[0] || SetCurrentDirectory( host.rootdir ) != 0)
Con_Reportf( "%s is working directory now\n", host.rootdir ); Con_Reportf( "%s is working directory now\n", host.rootdir );

View File

@ -20,6 +20,7 @@ GNU General Public License for more details.
#include "edict.h" #include "edict.h"
#include "eiface.h" #include "eiface.h"
#include "ref_api.h" #include "ref_api.h"
#include "studio.h"
#define LM_SAMPLE_SIZE 16 #define LM_SAMPLE_SIZE 16
#define LM_SAMPLE_EXTRASIZE 8 #define LM_SAMPLE_EXTRASIZE 8
@ -172,10 +173,6 @@ void Mod_ReleaseHullPolygons( void );
// //
// mod_studio.c // mod_studio.c
// //
typedef struct studiohdr_s studiohdr_t;
typedef struct mstudioseqdesc_s mstudioseqdesc_t;
typedef struct mstudiobone_s mstudiobone_t;
typedef struct mstudioanim_s mstudioanim_t;
void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded );
void Mod_UnloadStudioModel( model_t *mod ); void Mod_UnloadStudioModel( model_t *mod );
void Mod_InitStudioAPI( void ); void Mod_InitStudioAPI( void );

View File

@ -35,7 +35,7 @@ _inline int BitByte( int bits )
return PAD_NUMBER( bits, 8 ) >> 3; return PAD_NUMBER( bits, 8 ) >> 3;
} }
typedef struct sizebuf_s struct sizebuf_s
{ {
qboolean bOverflow; // overflow reading or writing qboolean bOverflow; // overflow reading or writing
const char *pDebugName; // buffer name (pointer to const name) const char *pDebugName; // buffer name (pointer to const name)
@ -43,7 +43,7 @@ typedef struct sizebuf_s
byte *pData; byte *pData;
int iCurBit; int iCurBit;
int nDataBits; int nDataBits;
} sizebuf_t; };
#define MSG_StartReading MSG_StartWriting #define MSG_StartReading MSG_StartWriting
#define MSG_GetNumBytesRead MSG_GetNumBytesWritten #define MSG_GetNumBytesRead MSG_GetNumBytesWritten

View File

@ -16,6 +16,8 @@ GNU General Public License for more details.
#ifndef NET_ENCODE_H #ifndef NET_ENCODE_H
#define NET_ENCODE_H #define NET_ENCODE_H
#include "eiface.h"
#define DT_BYTE BIT( 0 ) // A byte #define DT_BYTE BIT( 0 ) // A byte
#define DT_SHORT BIT( 1 ) // 2 byte field #define DT_SHORT BIT( 1 ) // 2 byte field
#define DT_FLOAT BIT( 2 ) // A floating point field #define DT_FLOAT BIT( 2 ) // A floating point field
@ -62,7 +64,7 @@ typedef struct
} delta_field_t; } delta_field_t;
// one field // one field
typedef struct delta_s struct delta_s
{ {
const char *name; const char *name;
int offset; // in bytes int offset; // in bytes
@ -72,9 +74,9 @@ typedef struct delta_s
float post_multiplier; // for DEFINE_DELTA_POST float post_multiplier; // for DEFINE_DELTA_POST
int bits; // how many bits we send\receive int bits; // how many bits we send\receive
qboolean bInactive; // unsetted by user request qboolean bInactive; // unsetted by user request
} delta_t; };
typedef void (*pfnDeltaEncode)( delta_t *pFields, const byte *from, const byte *to ); typedef void (*pfnDeltaEncode)( struct delta_s *pFields, const byte *from, const byte *to );
typedef struct typedef struct
{ {
@ -113,24 +115,24 @@ void Delta_ParseTableField( sizebuf_t *msg );
// encode routines // encode routines
typedef struct entity_state_s entity_state_t; struct entity_state_s;
typedef struct usercmd_s usercmd_t; struct usercmd_s;
typedef struct event_args_s event_args_t; struct event_args_s;
typedef struct movevars_s movevars_t; struct movevars_s;
typedef struct clientdata_s clientdata_t; struct clientdata_s;
typedef struct weapon_data_s weapon_data_t; struct weapon_data_s;
void MSG_WriteDeltaUsercmd( sizebuf_t *msg, usercmd_t *from, usercmd_t *to ); void MSG_WriteDeltaUsercmd( sizebuf_t *msg, struct usercmd_s *from, struct usercmd_s *to );
void MSG_ReadDeltaUsercmd( sizebuf_t *msg, usercmd_t *from, usercmd_t *to ); void MSG_ReadDeltaUsercmd( sizebuf_t *msg, struct usercmd_s *from, struct usercmd_s *to );
void MSG_WriteDeltaEvent( sizebuf_t *msg, event_args_t *from, event_args_t *to ); void MSG_WriteDeltaEvent( sizebuf_t *msg, struct event_args_s *from, struct event_args_s *to );
void MSG_ReadDeltaEvent( sizebuf_t *msg, event_args_t *from, event_args_t *to ); void MSG_ReadDeltaEvent( sizebuf_t *msg, struct event_args_s *from, struct event_args_s *to );
qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, movevars_t *from, movevars_t *to ); qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, struct movevars_s *from, struct movevars_s *to );
void MSG_ReadDeltaMovevars( sizebuf_t *msg, movevars_t *from, movevars_t *to ); void MSG_ReadDeltaMovevars( sizebuf_t *msg, struct movevars_s *from, struct movevars_s *to );
void MSG_WriteClientData( sizebuf_t *msg, clientdata_t *from, clientdata_t *to, float timebase ); void MSG_WriteClientData( sizebuf_t *msg, struct clientdata_s *from, struct clientdata_s *to, float timebase );
void MSG_ReadClientData( sizebuf_t *msg, clientdata_t *from, clientdata_t *to, float timebase ); void MSG_ReadClientData( sizebuf_t *msg, struct clientdata_s *from, struct clientdata_s *to, float timebase );
void MSG_WriteWeaponData( sizebuf_t *msg, weapon_data_t *from, weapon_data_t *to, float timebase, int index ); void MSG_WriteWeaponData( sizebuf_t *msg, struct weapon_data_s *from, struct weapon_data_s *to, float timebase, int index );
void MSG_ReadWeaponData( sizebuf_t *msg, weapon_data_t *from, weapon_data_t *to, float timebase ); void MSG_ReadWeaponData( sizebuf_t *msg, struct weapon_data_s *from, struct weapon_data_s *to, float timebase );
void MSG_WriteDeltaEntity( entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, int type, float tbase, int ofs ); void MSG_WriteDeltaEntity( struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, qboolean force, int type, float tbase, int ofs );
qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, entity_state_t *from, entity_state_t *to, int num, int type, float timebase ); qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, struct entity_state_s *from, struct entity_state_s *to, int num, int type, float timebase );
int Delta_TestBaseline( entity_state_t *from, entity_state_t *to, qboolean player, float timebase ); int Delta_TestBaseline( struct entity_state_s *from, struct entity_state_s *to, qboolean player, float timebase );
#endif//NET_ENCODE_H #endif//NET_ENCODE_H

View File

@ -60,7 +60,7 @@ typedef struct sndlib_s
int cmd_flags; int cmd_flags;
} sndlib_t; } sndlib_t;
typedef struct stream_s struct stream_s
{ {
const streamfmt_t *format; // streamformat to operate const streamfmt_t *format; // streamformat to operate
@ -77,7 +77,7 @@ typedef struct stream_s
char temp[OUTBUF_SIZE]; // mpeg decoder stuff char temp[OUTBUF_SIZE]; // mpeg decoder stuff
size_t pos; // actual track position (or actual buffer remains) size_t pos; // actual track position (or actual buffer remains)
int buffsize; // cached buffer size int buffsize; // cached buffer size
} stream_t; };
/* /*
======================================================================== ========================================================================

View File

@ -426,7 +426,7 @@ void Sys_Error( const char *error, ... )
if( !Host_IsDedicated() ) if( !Host_IsDedicated() )
{ {
#ifdef XASH_SDL #if XASH_SDL == 2
if( host.hWnd ) SDL_HideWindow( host.hWnd ); if( host.hWnd ) SDL_HideWindow( host.hWnd );
#endif #endif
} }

View File

@ -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
/* /*
======================== ========================

View File

@ -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 );
} }

View File

@ -268,10 +268,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 )
{ {

View File

@ -0,0 +1,25 @@
/*
sys_magx.cpp - MotoMAGX system utils
Copyright (C) 2019 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "platform/platform.h"
#include <ZApplication.h>
typedef void (*pfnChangeGame)( const char *progname );
extern "C" int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func );
extern "C" int EXPORT Platform_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func )
{
ZApplication app( argc, argv );
return Host_Main( argc, argv, progname, bChangeGame, func );
}

View File

@ -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 );
@ -93,15 +103,14 @@ typedef enum
rserr_unknown rserr_unknown
} rserr_t; } rserr_t;
typedef struct vidmode_s vidmode_t; struct vidmode_s;
// Window // Window
qboolean R_Init_Video( const int type ); qboolean R_Init_Video( const int type );
void R_Free_Video( void ); void R_Free_Video( void );
qboolean VID_SetMode( void ); qboolean VID_SetMode( void );
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ); rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen );
int R_MaxVideoModes( void ); int R_MaxVideoModes( void );
vidmode_t*R_GetVideoMode( int num ); struct vidmode_s *R_GetVideoMode( int num );
void* GL_GetProcAddress( const char *name ); // RenderAPI requirement void* GL_GetProcAddress( const char *name ); // RenderAPI requirement
void GL_UpdateSwapInterval( void ); void GL_UpdateSwapInterval( void );
int GL_SetAttribute( int attr, int val ); int GL_SetAttribute( int attr, int val );

View File

@ -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,

View File

@ -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"
@ -27,6 +28,71 @@ GNU General Public License for more details.
static int wheelbutton; static int wheelbutton;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_SCANCODE_A SDLK_a
#define SDL_SCANCODE_Z SDLK_z
#define SDL_SCANCODE_1 SDLK_1
#define SDL_SCANCODE_9 SDLK_9
#define SDL_SCANCODE_F1 SDLK_F1
#define SDL_SCANCODE_F12 SDLK_F12
#define SDL_SCANCODE_GRAVE SDLK_BACKQUOTE
#define SDL_SCANCODE_0 SDLK_0
#define SDL_SCANCODE_BACKSLASH SDLK_BACKSLASH
#define SDL_SCANCODE_LEFTBRACKET SDLK_LEFTBRACKET
#define SDL_SCANCODE_RIGHTBRACKET SDLK_RIGHTBRACKET
#define SDL_SCANCODE_EQUALS SDLK_EQUALS
#define SDL_SCANCODE_MINUS SDLK_MINUS
#define SDL_SCANCODE_TAB SDLK_TAB
#define SDL_SCANCODE_RETURN SDLK_RETURN
#define SDL_SCANCODE_ESCAPE SDLK_ESCAPE
#define SDL_SCANCODE_SPACE SDLK_SPACE
#define SDL_SCANCODE_BACKSPACE SDLK_BACKSPACE
#define SDL_SCANCODE_UP SDLK_UP
#define SDL_SCANCODE_LEFT SDLK_LEFT
#define SDL_SCANCODE_DOWN SDLK_DOWN
#define SDL_SCANCODE_RIGHT SDLK_RIGHT
#define SDL_SCANCODE_LALT SDLK_LALT
#define SDL_SCANCODE_RALT SDLK_RALT
#define SDL_SCANCODE_LCTRL SDLK_LCTRL
#define SDL_SCANCODE_RCTRL SDLK_RCTRL
#define SDL_SCANCODE_LSHIFT SDLK_LSHIFT
#define SDL_SCANCODE_RSHIFT SDLK_RSHIFT
#define SDL_SCANCODE_LGUI SDLK_LMETA
#define SDL_SCANCODE_RGUI SDLK_RMETA
#define SDL_SCANCODE_INSERT SDLK_INSERT
#define SDL_SCANCODE_DELETE SDLK_DELETE
#define SDL_SCANCODE_PAGEDOWN SDLK_PAGEDOWN
#define SDL_SCANCODE_PAGEUP SDLK_PAGEUP
#define SDL_SCANCODE_HOME SDLK_HOME
#define SDL_SCANCODE_END SDLK_END
#define SDL_SCANCODE_KP_1 SDLK_KP1
#define SDL_SCANCODE_KP_2 SDLK_KP2
#define SDL_SCANCODE_KP_3 SDLK_KP3
#define SDL_SCANCODE_KP_4 SDLK_KP4
#define SDL_SCANCODE_KP_5 SDLK_KP5
#define SDL_SCANCODE_KP_6 SDLK_KP6
#define SDL_SCANCODE_KP_7 SDLK_KP7
#define SDL_SCANCODE_KP_8 SDLK_KP8
#define SDL_SCANCODE_KP_9 SDLK_KP9
#define SDL_SCANCODE_KP_0 SDLK_KP0
#define SDL_SCANCODE_KP_PERIOD SDLK_KP_PERIOD
#define SDL_SCANCODE_KP_ENTER SDLK_KP_ENTER
#define SDL_SCANCODE_KP_PLUS SDLK_KP_PLUS
#define SDL_SCANCODE_KP_MINUS SDLK_KP_MINUS
#define SDL_SCANCODE_KP_DIVIDE SDLK_KP_DIVIDE
#define SDL_SCANCODE_KP_MULTIPLY SDLK_KP_MULTIPLY
#define SDL_SCANCODE_NUMLOCKCLEAR SDLK_NUMLOCK
#define SDL_SCANCODE_CAPSLOCK SDLK_CAPSLOCK
#define SDL_SCANCODE_SLASH SDLK_SLASH
#define SDL_SCANCODE_PERIOD SDLK_PERIOD
#define SDL_SCANCODE_SEMICOLON SDLK_SEMICOLON
#define SDL_SCANCODE_APOSTROPHE SDLK_QUOTE
#define SDL_SCANCODE_COMMA SDLK_COMMA
#define SDL_SCANCODE_PRINTSCREEN SDLK_PRINT
#define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN
#define SDL_GetScancodeName( x ) "unknown"
#endif
/* /*
============= =============
SDLash_KeyEvent SDLash_KeyEvent
@ -36,7 +102,11 @@ 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_IsTextInputActive() && down ) if( SDL_IsTextInputActive() && down )
@ -51,6 +121,22 @@ 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
} }
#define DECLARE_KEY_RANGE( min, max, repl ) \ #define DECLARE_KEY_RANGE( min, max, repl ) \
@ -62,7 +148,6 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
DECLARE_KEY_RANGE( SDL_SCANCODE_A, SDL_SCANCODE_Z, 'a' ) DECLARE_KEY_RANGE( SDL_SCANCODE_A, SDL_SCANCODE_Z, 'a' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_1, SDL_SCANCODE_9, '1' ) else DECLARE_KEY_RANGE( SDL_SCANCODE_1, SDL_SCANCODE_9, '1' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_F1, SDL_SCANCODE_F12, K_F1 ) else DECLARE_KEY_RANGE( SDL_SCANCODE_F1, SDL_SCANCODE_F12, K_F1 )
#undef DECLARE_KEY_RANGE
else else
{ {
switch( keynum ) switch( keynum )
@ -115,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;
@ -127,6 +211,8 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
break; break;
} }
#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:
@ -134,6 +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 // 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" );
@ -145,9 +232,23 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
} }
} }
#undef DECLARE_KEY_RANGE
Key_Event( keynum, down ); Key_Event( keynum, down );
} }
static void SDLash_MouseKey( int key, int down, int istouch )
{
if( CVAR_TO_BOOL( touch_emulate ) )
{
Touch_KeyEvent( key, down );
}
else if( in_mouseinitialized && !m_ignore->value && !istouch )
{
Key_Event( key, down );
}
}
/* /*
============= =============
SDLash_MouseEvent SDLash_MouseEvent
@ -157,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;
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
istouch = false;
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
switch( button.button )
{ {
Touch_KeyEvent( K_MOUSE1 - 1 + button.button, down ); case SDL_BUTTON_LEFT:
} SDLash_MouseKey( K_MOUSE1, down, istouch );
else if( in_mouseinitialized && !m_ignore->value && button.which != SDL_TOUCH_MOUSEID ) break;
{ case SDL_BUTTON_RIGHT:
Key_Event( K_MOUSE1 - 1 + button.button, down ); 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 );
} }
} }
@ -174,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;
@ -192,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();
}
}
/* /*
============= =============
@ -213,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:
@ -247,7 +439,7 @@ static void SDLash_EventFilter( SDL_Event *event )
type = event_down; type = event_down;
else if( event->type == SDL_FINGERUP ) else if( event->type == SDL_FINGERUP )
type = event_up ; type = event_up ;
else if(event->type == SDL_FINGERMOTION ) else if( event->type == SDL_FINGERMOTION )
type = event_motion; type = event_motion;
else break; else break;
@ -288,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;
@ -361,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;
@ -393,47 +562,33 @@ 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:
{ {
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 ); VID_SaveWindowSize( w, h );
SCR_VidInit(); // tell the client.dll what vid_mode has changed SCR_VidInit(); // tell the client.dll that vid_mode has changed
break; break;
} }
default: default:
break; break;
} }
#else
case SDL_VIDEORESIZE:
VID_SaveWindowSize( 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
} }
} }

View File

@ -25,7 +25,13 @@ GNU General Public License for more details.
#include "vid_common.h" #include "vid_common.h"
static SDL_Joystick *joy; static SDL_Joystick *joy;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
static SDL_GameController *gamecontroller; static SDL_GameController *gamecontroller;
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
#endif
/* /*
============= =============
@ -57,6 +63,7 @@ Platform_GetClipobardText
*/ */
void Platform_GetClipboardText( char *buffer, size_t size ) void Platform_GetClipboardText( char *buffer, size_t size )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
char *sdlbuffer = SDL_GetClipboardText(); char *sdlbuffer = SDL_GetClipboardText();
if( !sdlbuffer ) if( !sdlbuffer )
@ -64,6 +71,9 @@ void Platform_GetClipboardText( char *buffer, size_t size )
Q_strncpy( buffer, sdlbuffer, size ); Q_strncpy( buffer, sdlbuffer, size );
SDL_free( sdlbuffer ); SDL_free( sdlbuffer );
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
buffer[0] = 0;
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -74,7 +84,9 @@ Platform_SetClipobardText
*/ */
void Platform_SetClipboardText( const char *buffer, size_t size ) void Platform_SetClipboardText( const char *buffer, size_t size )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_SetClipboardText( buffer ); SDL_SetClipboardText( buffer );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -96,7 +108,9 @@ SDLash_EnableTextInput
*/ */
void Platform_EnableTextInput( qboolean enable ) void Platform_EnableTextInput( qboolean enable )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
enable ? SDL_StartTextInput() : SDL_StopTextInput(); enable ? SDL_StartTextInput() : SDL_StopTextInput();
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -134,8 +148,10 @@ static int SDLash_JoyInit_Old( int numjoy )
return 0; return 0;
} }
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
for( i = 0; i < num; i++ ) for( i = 0; i < num; i++ )
Con_Reportf( "%i\t: %s\n", i, SDL_JoystickNameForIndex( i ) ); Con_Reportf( "%i\t: %s\n", i, SDL_JoystickNameForIndex( i ) );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Pass +set joy_index N to command line, where N is number, to select active joystick\n" ); Con_Reportf( "Pass +set joy_index N to command line, where N is number, to select active joystick\n" );
@ -147,6 +163,7 @@ static int SDLash_JoyInit_Old( int numjoy )
return 0; return 0;
} }
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Selected joystick: %s\n" Con_Reportf( "Selected joystick: %s\n"
"\tAxes: %i\n" "\tAxes: %i\n"
"\tHats: %i\n" "\tHats: %i\n"
@ -156,11 +173,13 @@ static int SDLash_JoyInit_Old( int numjoy )
SDL_JoystickNumButtons( joy ), SDL_JoystickNumBalls( joy ) ); SDL_JoystickNumButtons( joy ), SDL_JoystickNumBalls( joy ) );
SDL_GameControllerEventState( SDL_DISABLE ); SDL_GameControllerEventState( SDL_DISABLE );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_JoystickEventState( SDL_ENABLE ); SDL_JoystickEventState( SDL_ENABLE );
return num; return num;
} }
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
/* /*
============= =============
SDLash_JoyInit_New SDLash_JoyInit_New
@ -219,18 +238,19 @@ static int SDLash_JoyInit_New( int numjoy )
return 0; return 0;
} }
// was added in SDL2-2.0.6, allow build with earlier versions just in case // was added in SDL2-2.0.6, allow build with earlier versions just in case
#if SDL_MAJOR_VERSION > 2 || SDL_MINOR_VERSION > 0 || SDL_PATCHLEVEL >= 6 #if SDL_VERSION_ATLEAST( 2, 0, 6 )
Con_Reportf( "Selected joystick: %s (%i:%i:%i)\n", Con_Reportf( "Selected joystick: %s (%i:%i:%i)\n",
SDL_GameControllerName( gamecontroller ), SDL_GameControllerName( gamecontroller ),
SDL_GameControllerGetVendor( gamecontroller ), SDL_GameControllerGetVendor( gamecontroller ),
SDL_GameControllerGetProduct( gamecontroller ), SDL_GameControllerGetProduct( gamecontroller ),
SDL_GameControllerGetProductVersion( gamecontroller )); SDL_GameControllerGetProductVersion( gamecontroller ));
#endif #endif // SDL_VERSION_ATLEAST( 2, 0, 6 )
SDL_GameControllerEventState( SDL_ENABLE ); SDL_GameControllerEventState( SDL_ENABLE );
SDL_JoystickEventState( SDL_DISABLE ); SDL_JoystickEventState( SDL_DISABLE );
return num; return num;
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
/* /*
============= =============
@ -240,12 +260,13 @@ Platform_JoyInit
*/ */
int Platform_JoyInit( int numjoy ) int Platform_JoyInit( int numjoy )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// SDL_Joystick is now an old API // SDL_Joystick is now an old API
// SDL_GameController is preferred // SDL_GameController is preferred
if( Sys_CheckParm( "-sdl_joy_old_api" ) ) if( !Sys_CheckParm( "-sdl_joy_old_api" ) )
return SDLash_JoyInit_Old(numjoy); return SDLash_JoyInit_New(numjoy);
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return SDLash_JoyInit_New(numjoy); return SDLash_JoyInit_Old(numjoy);
} }
#endif // XASH_DEDICATED #endif // XASH_DEDICATED

View File

@ -24,6 +24,18 @@ GNU General Public License for more details.
#define SAMPLE_16BIT_SHIFT 1 #define SAMPLE_16BIT_SHIFT 1
#define SECONDARY_BUFFER_SIZE 0x10000 #define SECONDARY_BUFFER_SIZE 0x10000
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <stdlib.h>
#define SDL_setenv setenv
#define SDL_GetCurrentAudioDriver() "legacysdl"
#define SDL_OpenAudioDevice( a, b, c, d, e ) SDL_OpenAudio( ( c ), ( d ) )
#define SDL_CloseAudioDevice( a ) SDL_CloseAudio()
#define SDL_PauseAudioDevice( a, b ) SDL_PauseAudio( ( b ) )
#define SDLash_IsAudioError( x ) ( x ) != 0
#else
#define SDLash_IsAudioError( x ) ( x ) == 0
#endif
/* /*
======================================================================= =======================================================================
Global variables. Must be visible to window-procedure function Global variables. Must be visible to window-procedure function
@ -41,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 );
@ -88,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;
@ -113,12 +130,12 @@ 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 );
SDL_PauseAudioDevice( sdl_dev, 0 ); SNDDMA_Activate( true );
dma.initialized = true; dma.initialized = true;
return true; return true;
@ -218,10 +235,10 @@ void SNDDMA_Shutdown( void )
if( sdl_dev ) if( sdl_dev )
{ {
SDL_PauseAudioDevice( sdl_dev, 1 ); SNDDMA_Activate( false );
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
SDL_CloseAudioDevice( sdl_dev ); SDL_CloseAudioDevice( sdl_dev );
SDL_CloseAudio( );
#endif #endif
} }

View File

@ -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

View File

@ -31,8 +31,10 @@ struct
struct struct
{ {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Texture *tex; SDL_Texture *tex;
#endif
int width, height; int width, height;
SDL_Surface *surf; SDL_Surface *surf;
SDL_Surface *win; SDL_Surface *win;
@ -43,6 +45,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
sw.width = width; sw.width = width;
sw.height = height; sw.height = height;
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( sw.renderer ) if( sw.renderer )
{ {
unsigned int format = SDL_GetWindowPixelFormat( host.hWnd ); unsigned int format = SDL_GetWindowPixelFormat( host.hWnd );
@ -54,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;
@ -110,10 +113,16 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
sw.renderer = NULL; sw.renderer = NULL;
} }
} }
#endif
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !sw.renderer ) if( !sw.renderer )
{ {
sw.win = SDL_GetWindowSurface( host.hWnd ); sw.win = SDL_GetWindowSurface( host.hWnd );
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
{
sw.win = SDL_GetVideoSurface();
#endif
// sdl will create renderer if hw framebuffer unavailiable, so cannot fallback here // sdl will create renderer if hw framebuffer unavailiable, so cannot fallback here
// if it is failed, it is not possible to draw with SDL in REF_SOFTWARE mode // if it is failed, it is not possible to draw with SDL in REF_SOFTWARE mode
@ -145,6 +154,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
void *SW_LockBuffer( void ) void *SW_LockBuffer( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.renderer ) if( sw.renderer )
{ {
void *pixels; void *pixels;
@ -154,35 +164,38 @@ void *SW_LockBuffer( void )
Sys_Error("%s", SDL_GetError()); Sys_Error("%s", SDL_GetError());
return pixels; return pixels;
} }
else
// ensure it not changed (do we really need this?)
sw.win = SDL_GetWindowSurface( host.hWnd );
//if( !sw.win )
//SDL_GetWindowSurface( host.hWnd );
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
sw.win = SDL_GetVideoSurface();
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// prevent buffer overrun
if( !sw.win || sw.win->w < sw.width || sw.win->h < sw.height )
return NULL;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.surf )
{ {
// ensure it not changed (do we really need this?) SDL_LockSurface( sw.surf );
sw.win = SDL_GetWindowSurface( host.hWnd ); return sw.surf->pixels;
}
//if( !sw.win ) else
//SDL_GetWindowSurface( host.hWnd ); #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
{
// prevent buffer overrun // real window pixels (x11 shm region, dma buffer, etc)
if( !sw.win || sw.win->w < sw.width || sw.win->h < sw.height ) // or SDL_Renderer texture if not supported
return NULL; SDL_LockSurface( sw.win );
return sw.win->pixels;
if( sw.surf )
{
SDL_LockSurface( sw.surf );
return sw.surf->pixels;
}
else
{
// real window pixels (x11 shm region, dma buffer, etc)
// or SDL_Renderer texture if not supported
SDL_LockSurface( sw.win );
return sw.win->pixels;
}
} }
} }
void SW_UnlockBuffer( void ) void SW_UnlockBuffer( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( sw.renderer ) if( sw.renderer )
{ {
SDL_Rect src, dst; SDL_Rect src, dst;
@ -197,26 +210,33 @@ void SW_UnlockBuffer( void )
SDL_RenderCopy(sw.renderer, sw.tex, &src, &dst); SDL_RenderCopy(sw.renderer, sw.tex, &src, &dst);
SDL_RenderPresent(sw.renderer); SDL_RenderPresent(sw.renderer);
return;
//Con_Printf("%s\n", SDL_GetError()); //Con_Printf("%s\n", SDL_GetError());
} }
else
{
// blit if blitting surface availiable
if( sw.surf )
{
SDL_Rect src, dst;
src.x = src.y = 0;
src.w = sw.width;
src.h = sw.height;
dst = src;
SDL_UnlockSurface( sw.surf );
SDL_BlitSurface( sw.surf, &src, sw.win, &dst );
}
else // already blitted
SDL_UnlockSurface( sw.win );
SDL_UpdateWindowSurface( host.hWnd ); // blit if blitting surface availiable
if( sw.surf )
{
SDL_Rect src, dst;
src.x = src.y = 0;
src.w = sw.width;
src.h = sw.height;
dst = src;
SDL_UnlockSurface( sw.surf );
SDL_BlitSurface( sw.surf, &src, sw.win, &dst );
return;
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
// already blitted
SDL_UnlockSurface( sw.win );
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_UpdateWindowSurface( host.hWnd );
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Flip( host.hWnd );
#endif
} }
int R_MaxVideoModes( void ) int R_MaxVideoModes( void )
@ -236,6 +256,7 @@ vidmode_t *R_GetVideoMode( int num )
static void R_InitVideoModes( void ) static void R_InitVideoModes( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
int displayIndex = 0; // TODO: handle multiple displays somehow int displayIndex = 0; // TODO: handle multiple displays somehow
int i, modes; int i, modes;
@ -250,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 ) )
@ -267,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;
} }
} }
@ -280,6 +299,43 @@ static void R_InitVideoModes( void )
num_vidmodes++; num_vidmodes++;
} }
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_Rect **modes;
int len = 0, i = 0, j;
modes = SDL_ListModes( NULL, SDL_FULLSCREEN );
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];
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 )
} }
static void R_FreeVideoModes( void ) static void R_FreeVideoModes( void )
@ -364,9 +420,9 @@ GL_GetProcAddress
void *GL_GetProcAddress( const char *name ) void *GL_GetProcAddress( const char *name )
{ {
#if defined( XASH_NANOGL ) #if defined( XASH_NANOGL )
void *func = nanoGL_GetProcAddress(name); void *func = nanoGL_GetProcAddress( name );
#else #else
void *func = SDL_GL_GetProcAddress(name); void *func = SDL_GL_GetProcAddress( name );
#endif #endif
if( !func ) if( !func )
@ -384,6 +440,7 @@ GL_UpdateSwapInterval
*/ */
void GL_UpdateSwapInterval( void ) void GL_UpdateSwapInterval( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// disable VSync while level is loading // disable VSync while level is loading
if( cls.state < ca_active ) if( cls.state < ca_active )
{ {
@ -397,6 +454,7 @@ void GL_UpdateSwapInterval( void )
if( SDL_GL_SetSwapInterval( gl_vsync->value ) ) if( SDL_GL_SetSwapInterval( gl_vsync->value ) )
Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) ); Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) );
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
} }
/* /*
@ -408,12 +466,13 @@ always return false
*/ */
qboolean GL_DeleteContext( void ) qboolean GL_DeleteContext( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( glw_state.context ) if( glw_state.context )
{ {
SDL_GL_DeleteContext(glw_state.context); SDL_GL_DeleteContext(glw_state.context);
glw_state.context = NULL; glw_state.context = NULL;
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return false; return false;
} }
@ -424,12 +483,13 @@ GL_CreateContext
*/ */
qboolean GL_CreateContext( void ) qboolean GL_CreateContext( void )
{ {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL) if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL)
{ {
Con_Reportf( S_ERROR "GL_CreateContext: %s\n", SDL_GetError()); Con_Reportf( S_ERROR "GL_CreateContext: %s\n", SDL_GetError());
return GL_DeleteContext(); return GL_DeleteContext();
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true; return true;
} }
@ -440,12 +500,13 @@ GL_UpdateContext
*/ */
qboolean GL_UpdateContext( void ) qboolean GL_UpdateContext( void )
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context )) if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ))
{ {
Con_Reportf( S_ERROR "GL_UpdateContext: %s\n", SDL_GetError()); Con_Reportf( S_ERROR "GL_UpdateContext: %s\n", SDL_GetError());
return GL_DeleteContext(); return GL_DeleteContext();
} }
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return true; return true;
} }
@ -454,10 +515,12 @@ void VID_SaveWindowSize( int width, int height )
int render_w = width, render_h = height; int render_w = width, render_h = height;
uint rotate = vid_rotate->value; uint rotate = vid_rotate->value;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !glw_state.software ) if( !glw_state.software )
SDL_GL_GetDrawableSize( host.hWnd, &render_w, &render_h ); SDL_GL_GetDrawableSize( host.hWnd, &render_w, &render_h );
else else
SDL_RenderSetLogicalSize( sw.renderer, width, height ); SDL_RenderSetLogicalSize( sw.renderer, width, height );
#endif
if( ref.dllFuncs.R_SetDisplayTransform( rotate, 0, 0, vid_scale->value, vid_scale->value ) ) if( ref.dllFuncs.R_SetDisplayTransform( rotate, 0, 0, vid_scale->value, vid_scale->value ) )
{ {
@ -482,6 +545,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;
@ -511,12 +575,15 @@ static qboolean VID_SetScreenResolution( int width, int height )
SDL_SetWindowSize( host.hWnd, got.w, got.h ); SDL_SetWindowSize( host.hWnd, got.w, got.h );
VID_SaveWindowSize( got.w, got.h ); VID_SaveWindowSize( got.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 );
@ -527,6 +594,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
@ -553,6 +621,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;
@ -704,6 +773,52 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
} }
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
Uint32 flags = 0;
if( fullscreen )
{
flags |= SDL_FULLSCREEN|SDL_HWSURFACE;
}
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, 16, 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_SaveWindowSize( width, height ); VID_SaveWindowSize( width, height );
return true; return true;
@ -721,7 +836,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;
} }
@ -738,14 +855,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 )
@ -763,12 +886,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
@ -776,16 +907,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;
} }
@ -804,12 +928,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
@ -817,11 +944,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;
} }
@ -836,22 +961,21 @@ 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 = 16;
#endif
#if !defined(_WIN32) #if SDL_VERSION_ATLEAST( 2, 0, 0 ) && !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
R_InitVideoModes();
// must be initialized before creating window // must be initialized before creating window
#ifdef _WIN32 #ifdef _WIN32
WIN_SetDPIAwareness(); WIN_SetDPIAwareness();
@ -896,6 +1020,8 @@ qboolean R_Init_Video( const int type )
break; break;
} }
R_InitVideoModes();
host.renderinfo_changed = false; host.renderinfo_changed = false;
return true; return true;
@ -903,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;
@ -929,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 )
@ -936,6 +1063,8 @@ 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 );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
VID_SaveWindowSize( width, height ); VID_SaveWindowSize( width, height );
} }
@ -961,6 +1090,7 @@ qboolean VID_SetMode( void )
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
{ {
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#if !defined( DEFAULT_MODE_WIDTH ) || !defined( DEFAULT_MODE_HEIGHT ) #if !defined( DEFAULT_MODE_WIDTH ) || !defined( DEFAULT_MODE_HEIGHT )
SDL_DisplayMode mode; SDL_DisplayMode mode;
@ -972,13 +1102,17 @@ qboolean VID_SetMode( void )
iScreenWidth = DEFAULT_MODE_WIDTH; iScreenWidth = DEFAULT_MODE_WIDTH;
iScreenHeight = DEFAULT_MODE_HEIGHT; iScreenHeight = DEFAULT_MODE_HEIGHT;
#endif #endif
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) ) iScreenWidth = 320;
Cvar_SetValue( "fullscreen", DEFAULT_FULLSCREEN ); iScreenHeight = 240;
else #endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
ClearBits( vid_fullscreen->flags, FCVAR_CHANGED );
} }
if( !FBitSet( vid_fullscreen->flags, FCVAR_CHANGED ) )
Cvar_SetValue( "fullscreen", DEFAULT_FULLSCREEN );
else
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;
@ -1020,7 +1154,7 @@ R_Free_Video
================== ==================
*/ */
void R_Free_Video( void ) void R_Free_Video( void )
{ {
GL_DeleteContext (); GL_DeleteContext ();
VID_DestroyWindow (); VID_DestroyWindow ();
@ -1028,6 +1162,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

View File

@ -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

View File

@ -106,6 +106,8 @@ typedef struct ref_globals_s
sortedface_t *draw_surfaces; // used for sorting translucent surfaces sortedface_t *draw_surfaces; // used for sorting translucent surfaces
int max_surfaces; // max surfaces per submodel (for all models) int max_surfaces; // max surfaces per submodel (for all models)
size_t visbytes; // cluster size size_t visbytes; // cluster size
int desktopBitsPixel;
} ref_globals_t; } ref_globals_t;
enum enum

View File

@ -22,9 +22,26 @@ def options(opt):
grp.add_option('--enable-custom-swap', action = 'store_true', dest = 'CUSTOM_SWAP', default = False, grp.add_option('--enable-custom-swap', action = 'store_true', dest = 'CUSTOM_SWAP', default = False,
help = 'enable custom swap allocator. For devices with no swap support') help = 'enable custom swap allocator. For devices with no swap support')
grp.add_option('--enable-magx', action = 'store_true', dest = 'MAGX', default = False,
help = 'enable targetting for MotoMAGX phones [default: %default]')
grp.add_option('--enable-legacy-sdl', action = 'store_true', dest = 'SDL12', default = False,
help = 'enable using SDL1.2 instead of SDL2(not recommended) [default: %default')
opt.load('sdl2') opt.load('sdl2')
def configure(conf): def configure(conf):
conf.env.MAGX = conf.options.MAGX
if conf.options.MAGX:
# useless to change toolchain path, as toolchain meant to be placed in this path
toolchain_path = '/opt/toolchains/motomagx/arm-eabi2/lib/'
conf.env.INCLUDES_MAGX = [toolchain_path + i for i in ['ezx-z6/include', 'qt-2.3.8/include']]
conf.env.LIBPATH_MAGX = [toolchain_path + i for i in ['ezx-z6/lib', 'qt-2.3.8/lib']]
conf.env.LINKFLAGS_MAGX = ['-Wl,-rpath-link=' + i for i in conf.env.LIBPATH_MAGX]
for lib in ['qte-mt', 'ezxappbase', 'ezxpm', 'log_util']:
conf.check_cc(lib=lib, use='MAGX', uselib_store='MAGX')
conf.options.SDL12 = True
# check for dedicated server build # check for dedicated server build
if conf.options.DEDICATED: if conf.options.DEDICATED:
if conf.env.DEST_OS == 'linux': if conf.env.DEST_OS == 'linux':
@ -37,11 +54,17 @@ def configure(conf):
conf.define('XASH_FBDEV', 1) conf.define('XASH_FBDEV', 1)
conf.check_cc( lib = 'asound' ) conf.check_cc( lib = 'asound' )
conf.check_cc( lib = 'rt' ) conf.check_cc( lib = 'rt' )
elif conf.options.SDL12:
conf.define('XASH_SDL', 12)
conf.check_cfg(package='sdl', args='--cflags --libs', uselib_store='SDL2' )
if conf.env.DEST_OS == 'linux':
conf.check_cc( lib='rt' )
conf.env.HAVE_SDL2 = True
else: else:
conf.load('sdl2') conf.load('sdl2')
if not conf.env.HAVE_SDL2: if not conf.env.HAVE_SDL2:
conf.fatal('SDL2 not availiable! If you want to build dedicated server, specify --dedicated') conf.fatal('SDL2 not availiable! If you want to build dedicated server, specify --dedicated')
conf.define('XASH_SDL', 1) conf.define('XASH_SDL', 2)
if conf.options.USE_SELECT == None: if conf.options.USE_SELECT == None:
conf.options.USE_SELECT = conf.options.DEDICATED conf.options.USE_SELECT = conf.options.DEDICATED
@ -60,6 +83,7 @@ def configure(conf):
conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1 conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1
def build(bld): def build(bld):
is_cxx_link = False
libs = [ 'public' ] libs = [ 'public' ]
source = bld.path.ant_glob([ source = bld.path.ant_glob([
'common/*.c', 'common/*.c',
@ -86,6 +110,11 @@ def build(bld):
libs.append('SDL2') libs.append('SDL2')
source += bld.path.ant_glob(['platform/sdl/*.c']) source += bld.path.ant_glob(['platform/sdl/*.c'])
if bld.env.MAGX:
libs.append('MAGX')
source += bld.path.ant_glob(['platform/magx/*.cpp'])
is_cxx_link = True
if bld.env.DEST_OS == 'android': if bld.env.DEST_OS == 'android':
libs += ['LOG', 'EGL', 'ANDROID'] libs += ['LOG', 'EGL', 'ANDROID']
source += bld.path.ant_glob(['platform/android/*.cpp', 'platform/android/*.c', 'platform/linux/*.c']) source += bld.path.ant_glob(['platform/android/*.cpp', 'platform/android/*.c', 'platform/linux/*.c'])
@ -102,10 +131,10 @@ def build(bld):
if bld.env.SINGLE_BINARY: if bld.env.SINGLE_BINARY:
install_path = bld.env.BINDIR install_path = bld.env.BINDIR
features = 'c cprogram' features = ['c', 'cxxprogram' if is_cxx_link else 'cprogram']
else: else:
install_path = bld.env.LIBDIR install_path = bld.env.LIBDIR
features = 'c cshlib' features = ['c', 'cxxshlib' if is_cxx_link else 'cshlib']
bld(source = source, bld(source = source,
target = 'xash', target = 'xash',

View File

@ -92,7 +92,8 @@ static void Sys_LoadEngine( void )
Xash_Error("Unable to load the " XASHLIB ": %s", dlerror() ); Xash_Error("Unable to load the " XASHLIB ": %s", dlerror() );
} }
if(( Xash_Main = (pfnInit)GetProcAddress( hEngine, "Host_Main" )) == NULL ) if(( Xash_Main = (pfnInit)GetProcAddress( hEngine, "Platform_Main" )) == NULL &&
( Xash_Main = (pfnInit)GetProcAddress( hEngine, "Host_Main" )) == NULL )
{ {
Xash_Error( XASHLIB " missed 'Host_Main' export: %s", dlerror() ); Xash_Error( XASHLIB " missed 'Host_Main' export: %s", dlerror() );
} }

View File

@ -56,7 +56,7 @@ GNU General Public License for more details.
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define XASH_MSVC 1 #define XASH_MSVC 1
#endif #endif
#if defined(_WIN64) #if defined(_WIN64)
#define XASH_WIN64 1 #define XASH_WIN64 1
#endif #endif
@ -142,13 +142,13 @@ GNU General Public License for more details.
#elif defined __arm__ || defined _M_ARM #elif defined __arm__ || defined _M_ARM
#if defined _M_ARM #if defined _M_ARM
#define XASH_ARM 7 // MSVC can only ARMv7 #define XASH_ARM 7 // MSVC can only ARMv7
#elif __ARM_ARCH == 7 #elif __ARM_ARCH == 7 || __ARM_ARCH_7__
#define XASH_ARM 7 #define XASH_ARM 7
#elif __ARM_ARCH == 6 #elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__
#define XASH_ARM 6 #define XASH_ARM 6
#elif __ARM_ARCH == 5 #elif __ARM_ARCH == 5 || __ARM_ARCH_5__
#define XASH_ARM 5 #define XASH_ARM 5
#elif __ARM_ARCH == 4 #elif __ARM_ARCH == 4 || __ARM_ARCH_4__
#define XASH_ARM 4 #define XASH_ARM 4
#else #else
#error "Unknown ARM" #error "Unknown ARM"

View File

@ -687,25 +687,25 @@ static void GL_SetTextureFormat( gl_texture_t *tex, pixformat_t format, int chan
{ {
if( haveColor && haveAlpha ) if( haveColor && haveAlpha )
{ {
if( FBitSet( tex->flags, TF_ARB_16BIT ) || glw_state.desktopBitsPixel == 16 ) if( FBitSet( tex->flags, TF_ARB_16BIT ) || gpGlobals->desktopBitsPixel == 16 )
tex->format = GL_RGBA16F_ARB; tex->format = GL_RGBA16F_ARB;
else tex->format = GL_RGBA32F_ARB; else tex->format = GL_RGBA32F_ARB;
} }
else if( haveColor ) else if( haveColor )
{ {
if( FBitSet( tex->flags, TF_ARB_16BIT ) || glw_state.desktopBitsPixel == 16 ) if( FBitSet( tex->flags, TF_ARB_16BIT ) || gpGlobals->desktopBitsPixel == 16 )
tex->format = GL_RGB16F_ARB; tex->format = GL_RGB16F_ARB;
else tex->format = GL_RGB32F_ARB; else tex->format = GL_RGB32F_ARB;
} }
else if( haveAlpha ) else if( haveAlpha )
{ {
if( FBitSet( tex->flags, TF_ARB_16BIT ) || glw_state.desktopBitsPixel == 16 ) if( FBitSet( tex->flags, TF_ARB_16BIT ) || gpGlobals->desktopBitsPixel == 16 )
tex->format = GL_RG16F; tex->format = GL_RG16F;
else tex->format = GL_RG32F; else tex->format = GL_RG32F;
} }
else else
{ {
if( FBitSet( tex->flags, TF_ARB_16BIT ) || glw_state.desktopBitsPixel == 16 ) if( FBitSet( tex->flags, TF_ARB_16BIT ) || gpGlobals->desktopBitsPixel == 16 )
tex->format = GL_LUMINANCE16F_ARB; tex->format = GL_LUMINANCE16F_ARB;
else tex->format = GL_LUMINANCE32F_ARB; else tex->format = GL_LUMINANCE32F_ARB;
} }
@ -713,7 +713,7 @@ static void GL_SetTextureFormat( gl_texture_t *tex, pixformat_t format, int chan
else else
{ {
// NOTE: not all the types will be compressed // NOTE: not all the types will be compressed
int bits = glw_state.desktopBitsPixel; int bits = gpGlobals->desktopBitsPixel;
switch( GL_CalcTextureSamples( channelMask )) switch( GL_CalcTextureSamples( channelMask ))
{ {

View File

@ -33,6 +33,7 @@ GNU General Public License for more details.
#include "pm_movevars.h" #include "pm_movevars.h"
//#include "cvar.h" //#include "cvar.h"
#include "gl_export.h" #include "gl_export.h"
#include "wadfile.h"
#ifndef offsetof #ifndef offsetof
#define offsetof(s,m) (size_t)&(((s *)0)->m) #define offsetof(s,m) (size_t)&(((s *)0)->m)
@ -480,7 +481,6 @@ void R_AliasInit( void );
// //
// gl_warp.c // gl_warp.c
// //
typedef struct mip_s mip_t;
void R_InitSkyClouds( mip_t *mt, struct texture_s *tx, qboolean custom_palette ); void R_InitSkyClouds( mip_t *mt, struct texture_s *tx, qboolean custom_palette );
void R_AddSkyBoxSurface( msurface_t *fa ); void R_AddSkyBoxSurface( msurface_t *fa );
void R_ClearSkyBox( void ); void R_ClearSkyBox( void );
@ -691,13 +691,6 @@ typedef struct
typedef struct typedef struct
{ {
void* context; // handle to GL rendering context
int safe;
int desktopBitsPixel;
int desktopWidth;
int desktopHeight;
qboolean initialized; // OpenGL subsystem started qboolean initialized; // OpenGL subsystem started
qboolean extended; // extended context allows to GL_Debug qboolean extended; // extended context allows to GL_Debug
} glwstate_t; } glwstate_t;

View File

@ -1041,7 +1041,7 @@ void GL_SetupAttributes( int safegl )
if( safegl < SAFE_NOACC ) if( safegl < SAFE_NOACC )
gEngfuncs.GL_SetAttribute( REF_GL_ACCELERATED_VISUAL, 1 ); gEngfuncs.GL_SetAttribute( REF_GL_ACCELERATED_VISUAL, 1 );
gEngfuncs.Con_Printf( "bpp %d\n", glw_state.desktopBitsPixel ); gEngfuncs.Con_Printf( "bpp %d\n", gpGlobals->desktopBitsPixel );
if( safegl < SAFE_NOSTENCIL ) if( safegl < SAFE_NOSTENCIL )
gEngfuncs.GL_SetAttribute( REF_GL_STENCIL_SIZE, gl_stencilbits->value ); gEngfuncs.GL_SetAttribute( REF_GL_STENCIL_SIZE, gl_stencilbits->value );
@ -1056,13 +1056,13 @@ void GL_SetupAttributes( int safegl )
if( safegl < SAFE_NOCOLOR ) if( safegl < SAFE_NOCOLOR )
{ {
if( glw_state.desktopBitsPixel >= 24 ) if( gpGlobals->desktopBitsPixel >= 24 )
{ {
gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 8 ); gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 8 );
gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 8 ); gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 8 );
gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 8 ); gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 8 );
} }
else if( glw_state.desktopBitsPixel >= 16 ) else if( gpGlobals->desktopBitsPixel >= 16 )
{ {
gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 5 ); gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 5 );
gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 6 ); gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 6 );