This commit is contained in:
Yamagi Burmeister 2012-06-08 12:23:01 +02:00
parent 9ad40b2a17
commit 26b15dbe07
4 changed files with 594 additions and 435 deletions

View file

@ -30,9 +30,9 @@
#include <stdio.h>
#ifdef _WIN32
#include "SDL/SDL.h"
#include "SDL/SDL.h"
#else
#include "SDL.h"
#include "SDL.h"
#endif
#include "../client/header/client.h"
@ -49,39 +49,39 @@ cvar_t *cd_volume;
cvar_t *cd_nocd;
cvar_t *cd_dev;
static void CD_f ();
static void CD_f();
static void
CDAudio_Eject ()
CDAudio_Eject()
{
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
if ( SDL_CDEject( cd_id ) )
if (SDL_CDEject(cd_id))
{
Com_DPrintf( "Unable to eject CD-ROM tray.\n" );
Com_DPrintf("Unable to eject CD-ROM tray.\n");
}
}
void
CDAudio_Play ( int track, qboolean looping )
CDAudio_Play(int track, qboolean looping)
{
CDstatus cd_stat;
lastTrack = track + 1;
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
cd_stat = SDL_CDStatus( cd_id );
cd_stat = SDL_CDStatus(cd_id);
if ( !cdValid )
if (!cdValid)
{
if ( !CD_INDRIVE( cd_stat ) || ( !cd_id->numtracks ) )
if (!CD_INDRIVE(cd_stat) || (!cd_id->numtracks))
{
return;
}
@ -89,17 +89,17 @@ CDAudio_Play ( int track, qboolean looping )
cdValid = true;
}
if ( ( track < 1 ) || ( track >= cd_id->numtracks ) )
if ((track < 1) || (track >= cd_id->numtracks))
{
Com_DPrintf( "CDAudio: Bad track number: %d\n", track );
Com_DPrintf("CDAudio: Bad track number: %d\n", track);
return;
}
track--;
if ( cd_stat == CD_PLAYING )
if (cd_stat == CD_PLAYING)
{
if ( cd_id->cur_track == track )
if (cd_id->cur_track == track)
{
return;
}
@ -107,10 +107,11 @@ CDAudio_Play ( int track, qboolean looping )
CDAudio_Stop();
}
if ( SDL_CDPlay( cd_id, cd_id->track [ track ].offset,
cd_id->track [ track ].length ) )
if (SDL_CDPlay(cd_id, cd_id->track[track].offset,
cd_id->track[track].length))
{
Com_DPrintf( "CDAudio_Play: Unable to play track: %d (%s)\n", track + 1, SDL_GetError() );
Com_DPrintf("CDAudio_Play: Unable to play track: %d (%s)\n",
track + 1, SDL_GetError());
return;
}
@ -118,35 +119,35 @@ CDAudio_Play ( int track, qboolean looping )
}
void
CDAudio_RandomPlay ( void )
CDAudio_RandomPlay(void)
{
int track, i = 0, free_tracks = 0;
float f;
CDstatus cd_stat;
byte *track_bools;
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
track_bools = (byte *) malloc( cd_id->numtracks * sizeof ( byte ) );
track_bools = (byte *)malloc(cd_id->numtracks * sizeof(byte));
if ( track_bools == 0 )
if (track_bools == 0)
{
return;
}
/* create an array of available audio tracknumbers */
for ( ; i < cd_id->numtracks; i++ )
for ( ; i < cd_id->numtracks; i++)
{
track_bools [ i ] = cd_id->track [ i ].type == SDL_AUDIO_TRACK;
free_tracks += track_bools [ i ];
track_bools[i] = cd_id->track[i].type == SDL_AUDIO_TRACK;
free_tracks += track_bools[i];
}
if ( !free_tracks )
if (!free_tracks)
{
Com_DPrintf( "CDAudio_RandomPlay: Unable to find and play a random audio track, insert an audio cd please" );
Com_DPrintf("CDAudio_RandomPlay: Unable to find and play a random audio track, insert an audio cd please");
goto free_end;
}
@ -155,18 +156,18 @@ CDAudio_RandomPlay ( void )
{
do
{
f = ( (float) randk() ) / ( (float) RAND_MAX + 1.0 );
track = (int) ( cd_id->numtracks * f );
f = ((float)randk()) / ((float)RAND_MAX + 1.0);
track = (int)(cd_id->numtracks * f);
}
while ( !track_bools [ track ] );
while (!track_bools[track]);
lastTrack = track + 1;
cd_stat = SDL_CDStatus( cd_id );
cd_stat = SDL_CDStatus(cd_id);
if ( !cdValid )
if (!cdValid)
{
if ( !CD_INDRIVE( cd_stat ) || ( !cd_id->numtracks ) )
if (!CD_INDRIVE(cd_stat) || (!cd_id->numtracks))
{
goto free_end;
}
@ -174,9 +175,9 @@ CDAudio_RandomPlay ( void )
cdValid = true;
}
if ( cd_stat == CD_PLAYING )
if (cd_stat == CD_PLAYING)
{
if ( cd_id->cur_track == track + 1 )
if (cd_id->cur_track == track + 1)
{
goto free_end;
}
@ -184,10 +185,10 @@ CDAudio_RandomPlay ( void )
CDAudio_Stop();
}
if ( SDL_CDPlay( cd_id, cd_id->track [ track ].offset,
cd_id->track [ track ].length ) )
if (SDL_CDPlay(cd_id, cd_id->track[track].offset,
cd_id->track[track].length))
{
track_bools [ track ] = 0;
track_bools[track] = 0;
free_tracks--;
}
else
@ -196,95 +197,95 @@ CDAudio_RandomPlay ( void )
break;
}
}
while ( free_tracks > 0 );
while (free_tracks > 0);
free_end:
free( (void *) track_bools );
free((void *)track_bools);
}
void
CDAudio_Stop ()
CDAudio_Stop()
{
int cdstate;
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
cdstate = SDL_CDStatus( cd_id );
cdstate = SDL_CDStatus(cd_id);
if ( ( cdstate != CD_PLAYING ) && ( cdstate != CD_PAUSED ) )
if ((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED))
{
return;
}
if ( SDL_CDStop( cd_id ) )
if (SDL_CDStop(cd_id))
{
Com_DPrintf( "CDAudio_Stop: Failed to stop track.\n" );
Com_DPrintf("CDAudio_Stop: Failed to stop track.\n");
}
playLooping = 0;
}
void
CDAudio_Pause ()
CDAudio_Pause()
{
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
if ( SDL_CDStatus( cd_id ) != CD_PLAYING )
if (SDL_CDStatus(cd_id) != CD_PLAYING)
{
return;
}
if ( SDL_CDPause( cd_id ) )
if (SDL_CDPause(cd_id))
{
Com_DPrintf( "CDAudio_Pause: Failed to pause track.\n" );
Com_DPrintf("CDAudio_Pause: Failed to pause track.\n");
}
}
void
CDAudio_Resume ()
CDAudio_Resume()
{
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
if ( SDL_CDStatus( cd_id ) != CD_PAUSED )
if (SDL_CDStatus(cd_id) != CD_PAUSED)
{
return;
}
if ( SDL_CDResume( cd_id ) )
if (SDL_CDResume(cd_id))
{
Com_DPrintf( "CDAudio_Resume: Failed to resume track.\n" );
Com_DPrintf("CDAudio_Resume: Failed to resume track.\n");
}
}
void
CDAudio_Update ()
CDAudio_Update()
{
static int cnt = 0;
if ( !cd_id || !enabled )
if (!cd_id || !enabled)
{
return;
}
if ( cd_volume && ( cd_volume->value != cdvolume ) )
if (cd_volume && (cd_volume->value != cdvolume))
{
if ( cdvolume )
if (cdvolume)
{
Cvar_SetValue( "cd_volume", 0.0 );
Cvar_SetValue("cd_volume", 0.0);
CDAudio_Pause();
}
else
{
Cvar_SetValue( "cd_volume", 1.0 );
Cvar_SetValue("cd_volume", 1.0);
CDAudio_Resume();
}
@ -293,150 +294,150 @@ CDAudio_Update ()
}
/* this causes too much overhead to be executed every frame */
if ( ++cnt == 16 )
if (++cnt == 16)
{
cnt = 0;
if ( cd_nocd->value )
if (cd_nocd->value)
{
CDAudio_Stop();
return;
}
if ( playLooping &&
( SDL_CDStatus( cd_id ) != CD_PLAYING ) &&
( SDL_CDStatus( cd_id ) != CD_PAUSED ) )
if (playLooping &&
(SDL_CDStatus(cd_id) != CD_PLAYING) &&
(SDL_CDStatus(cd_id) != CD_PAUSED))
{
CDAudio_Play( lastTrack, true );
CDAudio_Play(lastTrack, true);
}
}
}
int
CDAudio_Init ()
CDAudio_Init()
{
cvar_t *cv;
if ( initialized )
if (initialized)
{
return ( 0 );
return 0;
}
cv = Cvar_Get( "nocdaudio", "0", CVAR_NOSET );
cv = Cvar_Get("nocdaudio", "0", CVAR_NOSET);
if ( cv->value )
if (cv->value)
{
return ( -1 );
return -1;
}
cd_nocd = Cvar_Get( "cd_nocd", "0", CVAR_ARCHIVE );
cd_nocd = Cvar_Get("cd_nocd", "0", CVAR_ARCHIVE);
if ( cd_nocd->value )
if (cd_nocd->value)
{
return ( -1 );
return -1;
}
cd_volume = Cvar_Get( "cd_volume", "1", CVAR_ARCHIVE );
cd_volume = Cvar_Get("cd_volume", "1", CVAR_ARCHIVE);
if ( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 )
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0)
{
if ( SDL_Init( SDL_INIT_CDROM ) < 0 )
if (SDL_Init(SDL_INIT_CDROM) < 0)
{
Com_Printf( "Couldn't init SDL cdrom: %s\n", SDL_GetError() );
return ( -1 );
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
return -1;
}
}
else if ( SDL_WasInit( SDL_INIT_CDROM ) == 0 )
else if (SDL_WasInit(SDL_INIT_CDROM) == 0)
{
if ( SDL_InitSubSystem( SDL_INIT_CDROM ) < 0 )
if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
{
Com_Printf( "Couldn't init SDL cdrom: %s\n", SDL_GetError() );
return ( -1 );
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
return -1;
}
}
cd_id = SDL_CDOpen( 0 );
cd_id = SDL_CDOpen(0);
if ( !cd_id )
if (!cd_id)
{
Com_Printf( "CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
SDL_GetError() );
return ( -1 );
Com_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
SDL_GetError());
return -1;
}
initialized = true;
enabled = true;
cdValid = true;
if ( !CD_INDRIVE( SDL_CDStatus( cd_id ) ) )
if (!CD_INDRIVE(SDL_CDStatus(cd_id)))
{
Com_Printf( "CDAudio_Init: No CD in drive.\n" );
Com_Printf("CDAudio_Init: No CD in drive.\n");
cdValid = false;
}
if ( !cd_id->numtracks )
if (!cd_id->numtracks)
{
Com_Printf( "CDAudio_Init: CD contains no audio tracks.\n" );
Com_Printf("CDAudio_Init: CD contains no audio tracks.\n");
cdValid = false;
}
Cmd_AddCommand( "cd", CD_f );
Com_Printf( "CD Audio Initialized.\n" );
return ( 0 );
Cmd_AddCommand("cd", CD_f);
Com_Printf("CD Audio Initialized.\n");
return 0;
}
void
CDAudio_Shutdown ()
CDAudio_Shutdown()
{
if ( !cd_id )
if (!cd_id)
{
return;
}
CDAudio_Stop();
SDL_CDClose( cd_id );
SDL_CDClose(cd_id);
cd_id = NULL;
if ( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_CDROM )
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_CDROM)
{
SDL_Quit();
}
else
{
SDL_QuitSubSystem( SDL_INIT_CDROM );
SDL_QuitSubSystem(SDL_INIT_CDROM);
}
initialized = false;
}
static void
CD_f ()
CD_f()
{
char *command;
int cdstate;
if ( Cmd_Argc() < 2 )
if (Cmd_Argc() < 2)
{
return;
}
command = Cmd_Argv( 1 );
command = Cmd_Argv(1);
if ( !Q_strcasecmp( command, "on" ) )
if (!Q_strcasecmp(command, "on"))
{
enabled = true;
}
if ( !Q_strcasecmp( command, "off" ) )
if (!Q_strcasecmp(command, "off"))
{
if ( !cd_id )
if (!cd_id)
{
return;
}
cdstate = SDL_CDStatus( cd_id );
cdstate = SDL_CDStatus(cd_id);
if ( ( cdstate == CD_PLAYING ) || ( cdstate == CD_PAUSED ) )
if ((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
{
CDAudio_Stop();
}
@ -445,64 +446,64 @@ CD_f ()
return;
}
if ( !Q_strcasecmp( command, "play" ) )
if (!Q_strcasecmp(command, "play"))
{
CDAudio_Play( (byte) (int)strtol( Cmd_Argv( 2 ), (char **)NULL, 10 ), false );
CDAudio_Play((byte)(int)strtol(Cmd_Argv(2), (char **)NULL, 10), false);
return;
}
if ( !Q_strcasecmp( command, "loop" ) )
if (!Q_strcasecmp(command, "loop"))
{
CDAudio_Play( (byte) (int)strtol( Cmd_Argv( 2 ), (char **)NULL, 10 ), true );
CDAudio_Play((byte)(int)strtol(Cmd_Argv(2), (char **)NULL, 10), true);
return;
}
if ( !Q_strcasecmp( command, "stop" ) )
if (!Q_strcasecmp(command, "stop"))
{
CDAudio_Stop();
return;
}
if ( !Q_strcasecmp( command, "pause" ) )
if (!Q_strcasecmp(command, "pause"))
{
CDAudio_Pause();
return;
}
if ( !Q_strcasecmp( command, "resume" ) )
if (!Q_strcasecmp(command, "resume"))
{
CDAudio_Resume();
return;
}
if ( !Q_strcasecmp( command, "eject" ) )
if (!Q_strcasecmp(command, "eject"))
{
CDAudio_Eject();
return;
}
if ( !Q_strcasecmp( command, "info" ) )
if (!Q_strcasecmp(command, "info"))
{
if ( !cd_id )
if (!cd_id)
{
return;
}
cdstate = SDL_CDStatus( cd_id );
Com_Printf( "%d tracks\n", cd_id->numtracks );
cdstate = SDL_CDStatus(cd_id);
Com_Printf("%d tracks\n", cd_id->numtracks);
if ( cdstate == CD_PLAYING )
if (cdstate == CD_PLAYING)
{
Com_Printf( "Currently %s track %d\n",
Com_Printf("Currently %s track %d\n",
playLooping ? "looping" : "playing",
cd_id->cur_track + 1 );
cd_id->cur_track + 1);
}
else
if ( cdstate == CD_PAUSED )
if (cdstate == CD_PAUSED)
{
Com_Printf( "Paused %s track %d\n",
Com_Printf("Paused %s track %d\n",
playLooping ? "looping" : "playing",
cd_id->cur_track + 1 );
cd_id->cur_track + 1);
}
return;
@ -510,9 +511,9 @@ CD_f ()
}
void
CDAudio_Activate ( qboolean active )
CDAudio_Activate(qboolean active)
{
if ( active )
if (active)
{
CDAudio_Resume();
}

View file

@ -26,9 +26,9 @@
*/
#ifdef _WIN32
#include <SDL/SDL.h>
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif
#include "../refresh/header/local.h"
@ -38,31 +38,31 @@
#define MOUSE_MAX 3000
#define MOUSE_MIN 40
static int old_windowed_mouse;
static cvar_t *windowed_mouse;
static cvar_t *in_grab;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static int old_windowed_mouse;
static cvar_t *windowed_mouse;
static cvar_t *in_grab;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
struct
{
int key;
int down;
int key;
int down;
} keyq[128];
int keyq_head=0;
int keyq_tail=0;
int keyq_head = 0;
int keyq_tail = 0;
int mx;
int my;
Key_Event_fp_t Key_Event_fp;
extern SDL_Surface *surface;
static in_state_t *in_state;
extern SDL_Surface *surface;
static in_state_t *in_state;
static unsigned char KeyStates[SDLK_LAST];
static qboolean mlooking;
static qboolean mlooking;
static cvar_t *sensitivity;
static cvar_t *exponential_speedup;
@ -83,103 +83,228 @@ static cvar_t *in_mouse;
int
IN_TranslateSDLtoQ2Key(unsigned int keysym)
{
int key = 0;
int key = 0;
if( keysym >= SDLK_SPACE && keysym < SDLK_DELETE )
{
/* These happen to match the ASCII chars */
key = (int)keysym;
}
else
{
switch( keysym )
{
case SDLK_PAGEUP: key = K_PGUP; break;
case SDLK_KP9: key = K_KP_PGUP; break;
case SDLK_PAGEDOWN: key = K_PGDN; break;
case SDLK_KP3: key = K_KP_PGDN; break;
case SDLK_KP7: key = K_KP_HOME; break;
case SDLK_HOME: key = K_HOME; break;
case SDLK_KP1: key = K_KP_END; break;
case SDLK_END: key = K_END; break;
case SDLK_KP4: key = K_KP_LEFTARROW; break;
case SDLK_LEFT: key = K_LEFTARROW; break;
case SDLK_KP6: key = K_KP_RIGHTARROW; break;
case SDLK_RIGHT: key = K_RIGHTARROW; break;
case SDLK_KP2: key = K_KP_DOWNARROW; break;
case SDLK_DOWN: key = K_DOWNARROW; break;
case SDLK_KP8: key = K_KP_UPARROW; break;
case SDLK_UP: key = K_UPARROW; break;
case SDLK_ESCAPE: key = K_ESCAPE; break;
case SDLK_KP_ENTER: key = K_KP_ENTER; break;
case SDLK_RETURN: key = K_ENTER; break;
case SDLK_TAB: key = K_TAB; break;
case SDLK_F1: key = K_F1; break;
case SDLK_F2: key = K_F2; break;
case SDLK_F3: key = K_F3; break;
case SDLK_F4: key = K_F4; break;
case SDLK_F5: key = K_F5; break;
case SDLK_F6: key = K_F6; break;
case SDLK_F7: key = K_F7; break;
case SDLK_F8: key = K_F8; break;
case SDLK_F9: key = K_F9; break;
case SDLK_F10: key = K_F10; break;
case SDLK_F11: key = K_F11; break;
case SDLK_F12: key = K_F12; break;
case SDLK_F13: key = K_F13; break;
case SDLK_F14: key = K_F14; break;
case SDLK_F15: key = K_F15; break;
if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE))
{
/* These happen to match
the ASCII chars */
key = (int)keysym;
}
else
{
switch (keysym)
{
case SDLK_PAGEUP:
key = K_PGUP;
break;
case SDLK_KP9:
key = K_KP_PGUP;
break;
case SDLK_PAGEDOWN:
key = K_PGDN;
break;
case SDLK_KP3:
key = K_KP_PGDN;
break;
case SDLK_KP7:
key = K_KP_HOME;
break;
case SDLK_HOME:
key = K_HOME;
break;
case SDLK_KP1:
key = K_KP_END;
break;
case SDLK_END:
key = K_END;
break;
case SDLK_KP4:
key = K_KP_LEFTARROW;
break;
case SDLK_LEFT:
key = K_LEFTARROW;
break;
case SDLK_KP6:
key = K_KP_RIGHTARROW;
break;
case SDLK_RIGHT:
key = K_RIGHTARROW;
break;
case SDLK_KP2:
key = K_KP_DOWNARROW;
break;
case SDLK_DOWN:
key = K_DOWNARROW;
break;
case SDLK_KP8:
key = K_KP_UPARROW;
break;
case SDLK_UP:
key = K_UPARROW;
break;
case SDLK_ESCAPE:
key = K_ESCAPE;
break;
case SDLK_KP_ENTER:
key = K_KP_ENTER;
break;
case SDLK_RETURN:
key = K_ENTER;
break;
case SDLK_TAB:
key = K_TAB;
break;
case SDLK_F1:
key = K_F1;
break;
case SDLK_F2:
key = K_F2;
break;
case SDLK_F3:
key = K_F3;
break;
case SDLK_F4:
key = K_F4;
break;
case SDLK_F5:
key = K_F5;
break;
case SDLK_F6:
key = K_F6;
break;
case SDLK_F7:
key = K_F7;
break;
case SDLK_F8:
key = K_F8;
break;
case SDLK_F9:
key = K_F9;
break;
case SDLK_F10:
key = K_F10;
break;
case SDLK_F11:
key = K_F11;
break;
case SDLK_F12:
key = K_F12;
break;
case SDLK_F13:
key = K_F13;
break;
case SDLK_F14:
key = K_F14;
break;
case SDLK_F15:
key = K_F15;
break;
case SDLK_BACKSPACE:
key = K_BACKSPACE;
break;
case SDLK_KP_PERIOD:
key = K_KP_DEL;
break;
case SDLK_DELETE:
key = K_DEL;
break;
case SDLK_PAUSE:
key = K_PAUSE;
break;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
key = K_SHIFT;
break;
case SDLK_LCTRL:
case SDLK_RCTRL:
key = K_CTRL;
break;
case SDLK_RMETA:
case SDLK_LMETA:
key = K_COMMAND;
break;
case SDLK_RALT:
case SDLK_LALT:
key = K_ALT;
break;
case SDLK_LSUPER:
case SDLK_RSUPER:
key = K_SUPER;
break;
case SDLK_KP5:
key = K_KP_5;
break;
case SDLK_INSERT:
key = K_INS;
break;
case SDLK_KP0:
key = K_KP_INS;
break;
case SDLK_KP_MULTIPLY:
key = K_KP_STAR;
break;
case SDLK_KP_PLUS:
key = K_KP_PLUS;
break;
case SDLK_KP_MINUS:
key = K_KP_MINUS;
break;
case SDLK_KP_DIVIDE:
key = K_KP_SLASH;
break;
case SDLK_MODE:
key = K_MODE;
break;
case SDLK_COMPOSE:
key = K_COMPOSE;
break;
case SDLK_HELP:
key = K_HELP;
break;
case SDLK_PRINT:
key = K_PRINT;
break;
case SDLK_SYSREQ:
key = K_SYSREQ;
break;
case SDLK_BREAK:
key = K_BREAK;
break;
case SDLK_MENU:
key = K_MENU;
break;
case SDLK_POWER:
key = K_POWER;
break;
case SDLK_EURO:
key = K_EURO;
break;
case SDLK_UNDO:
key = K_UNDO;
break;
case SDLK_SCROLLOCK:
key = K_SCROLLOCK;
break;
case SDLK_NUMLOCK:
key = K_KP_NUMLOCK;
break;
case SDLK_CAPSLOCK:
key = K_CAPSLOCK;
break;
case SDLK_BACKSPACE: key = K_BACKSPACE; break;
case SDLK_KP_PERIOD: key = K_KP_DEL; break;
case SDLK_DELETE: key = K_DEL; break;
case SDLK_PAUSE: key = K_PAUSE; break;
default:
case SDLK_LSHIFT:
case SDLK_RSHIFT: key = K_SHIFT; break;
if ((keysym >= SDLK_WORLD_0) && (keysym <= SDLK_WORLD_95))
{
key = (keysym - SDLK_WORLD_0) + K_WORLD_0;
}
case SDLK_LCTRL:
case SDLK_RCTRL: key = K_CTRL; break;
break;
}
}
case SDLK_RMETA:
case SDLK_LMETA: key = K_COMMAND; break;
case SDLK_RALT:
case SDLK_LALT: key = K_ALT; break;
case SDLK_LSUPER:
case SDLK_RSUPER: key = K_SUPER; break;
case SDLK_KP5: key = K_KP_5; break;
case SDLK_INSERT: key = K_INS; break;
case SDLK_KP0: key = K_KP_INS; break;
case SDLK_KP_MULTIPLY: key = K_KP_STAR; break;
case SDLK_KP_PLUS: key = K_KP_PLUS; break;
case SDLK_KP_MINUS: key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: key = K_KP_SLASH; break;
case SDLK_MODE: key = K_MODE; break;
case SDLK_COMPOSE: key = K_COMPOSE; break;
case SDLK_HELP: key = K_HELP; break;
case SDLK_PRINT: key = K_PRINT; break;
case SDLK_SYSREQ: key = K_SYSREQ; break;
case SDLK_BREAK: key = K_BREAK; break;
case SDLK_MENU: key = K_MENU; break;
case SDLK_POWER: key = K_POWER; break;
case SDLK_EURO: key = K_EURO; break;
case SDLK_UNDO: key = K_UNDO; break;
case SDLK_SCROLLOCK: key = K_SCROLLOCK; break;
case SDLK_NUMLOCK: key = K_KP_NUMLOCK; break;
case SDLK_CAPSLOCK: key = K_CAPSLOCK; break;
default:
if( keysym >= SDLK_WORLD_0 && keysym <= SDLK_WORLD_95 )
key = ( keysym - SDLK_WORLD_0 ) + K_WORLD_0;
break;
}
}
return key;
return key;
}
/*
@ -190,10 +315,11 @@ IN_GetEvent(SDL_Event *event)
{
unsigned int key;
switch(event->type)
switch (event->type)
{
/* The mouse wheel */
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == 4)
{
keyq[keyq_head].key = K_MWHEELUP;
@ -212,6 +338,7 @@ IN_GetEvent(SDL_Event *event)
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 127;
}
break;
case SDL_MOUSEBUTTONUP:
@ -219,8 +346,11 @@ IN_GetEvent(SDL_Event *event)
/* The user pressed a button */
case SDL_KEYDOWN:
/* Fullscreen switch via Alt-Return */
if ( (KeyStates[SDLK_LALT] || KeyStates[SDLK_RALT]) && (event->key.keysym.sym == SDLK_RETURN) )
if ((KeyStates[SDLK_LALT] ||
KeyStates[SDLK_RALT]) &&
(event->key.keysym.sym == SDLK_RETURN))
{
cvar_t *fullscreen;
@ -228,14 +358,14 @@ IN_GetEvent(SDL_Event *event)
if (surface->flags & SDL_FULLSCREEN)
{
ri.Cvar_SetValue( "vid_fullscreen", 1 );
ri.Cvar_SetValue("vid_fullscreen", 1);
}
else
{
ri.Cvar_SetValue( "vid_fullscreen", 0 );
ri.Cvar_SetValue("vid_fullscreen", 0);
}
fullscreen = ri.Cvar_Get( "vid_fullscreen", "0", 0 );
fullscreen = ri.Cvar_Get("vid_fullscreen", "0", 0);
fullscreen->modified = false;
break;
@ -245,22 +375,26 @@ IN_GetEvent(SDL_Event *event)
/* Get the pressed key and add it to the key list */
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 127;
}
break;
/* The user released a key */
case SDL_KEYUP:
if (KeyStates[event->key.keysym.sym])
{
KeyStates[event->key.keysym.sym] = 0;
/* Get the pressed key and remove it from the key list */
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
@ -268,6 +402,7 @@ IN_GetEvent(SDL_Event *event)
keyq_head = (keyq_head + 1) & 127;
}
}
break;
}
}
@ -275,104 +410,105 @@ IN_GetEvent(SDL_Event *event)
/*
* Updates the state of the input queue
*/
void IN_Update(void)
void
IN_Update(void)
{
SDL_Event event;
static int IN_Update_Flag;
int bstate;
SDL_Event event;
static int IN_Update_Flag;
int bstate;
/* Protection against multiple calls */
if (IN_Update_Flag == 1)
{
return;
}
/* Protection against multiple calls */
if (IN_Update_Flag == 1)
{
return;
}
IN_Update_Flag = 1;
IN_Update_Flag = 1;
while (SDL_PollEvent(&event))
{
IN_GetEvent(&event);
}
while (SDL_PollEvent(&event))
{
IN_GetEvent(&event);
}
/* Mouse button processing. Button 4
and 5 are the mousewheel and thus
not processed here. */
/* Mouse button processing. Button 4
and 5 are the mousewheel and thus
not processed here. */
if (!mx && !my)
{
SDL_GetRelativeMouseState(&mx, &my);
}
if (!mx && !my)
{
SDL_GetRelativeMouseState(&mx, &my);
}
mouse_buttonstate = 0;
bstate = SDL_GetMouseState(NULL, NULL);
mouse_buttonstate = 0;
bstate = SDL_GetMouseState(NULL, NULL);
if (SDL_BUTTON(1) & bstate)
{
mouse_buttonstate |= (1 << 0);
}
if (SDL_BUTTON(1) & bstate)
{
mouse_buttonstate |= (1 << 0);
}
if (SDL_BUTTON(3) & bstate)
{
mouse_buttonstate |= (1 << 1);
}
if (SDL_BUTTON(3) & bstate)
{
mouse_buttonstate |= (1 << 1);
}
if (SDL_BUTTON(2) & bstate)
{
mouse_buttonstate |= (1 << 2);
}
if (SDL_BUTTON(2) & bstate)
{
mouse_buttonstate |= (1 << 2);
}
if (SDL_BUTTON(6) & bstate)
{
mouse_buttonstate |= (1 << 3);
}
if (SDL_BUTTON(6) & bstate)
{
mouse_buttonstate |= (1 << 3);
}
if (SDL_BUTTON(7) & bstate)
{
mouse_buttonstate |= (1 << 4);
}
if (SDL_BUTTON(7) & bstate)
{
mouse_buttonstate |= (1 << 4);
}
/* Grab and ungrab the mouse if the
* console is opened */
if (in_grab->value == 2)
{
if (old_windowed_mouse != windowed_mouse->value)
{
old_windowed_mouse = windowed_mouse->value;
/* Grab and ungrab the mouse if the
console is opened */
if (in_grab->value == 2)
{
if (old_windowed_mouse != windowed_mouse->value)
{
old_windowed_mouse = windowed_mouse->value;
if (!windowed_mouse->value)
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
else
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
}
}
else if (in_grab->value == 1)
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
else
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
if (!windowed_mouse->value)
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
else
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
}
}
else if (in_grab->value == 1)
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
else
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
/* Process the key events */
while (keyq_head != keyq_tail)
{
in_state->Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
keyq_tail = (keyq_tail + 1) & 127;
}
/* Process the key events */
while (keyq_head != keyq_tail)
{
in_state->Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
keyq_tail = (keyq_tail + 1) & 127;
}
IN_Update_Flag = 0;
IN_Update_Flag = 0;
}
/*
* Closes all inputs and clears
* the input queue.
*/
void IN_Close(void)
void
IN_Close(void)
{
keyq_head = 0;
keyq_tail = 0;
@ -383,34 +519,37 @@ void IN_Close(void)
/*
* Gets the mouse state
*/
void IN_GetMouseState(int *x, int *y, int *state) {
*x = mx;
*y = my;
*state = mouse_buttonstate;
void
IN_GetMouseState(int *x, int *y, int *state)
{
*x = mx;
*y = my;
*state = mouse_buttonstate;
}
/*
* Cleares the mouse state
*/
void IN_ClearMouseState()
void
IN_ClearMouseState()
{
mx = my = 0;
mx = my = 0;
}
/*
* Centers the view
*/
static void
IN_ForceCenterView ( void )
IN_ForceCenterView(void)
{
in_state->viewangles [ PITCH ] = 0;
in_state->viewangles[PITCH] = 0;
}
/*
* Look up
*/
static void
IN_MLookDown ( void )
IN_MLookDown(void)
{
mlooking = true;
}
@ -419,7 +558,7 @@ IN_MLookDown ( void )
* Look down
*/
static void
IN_MLookUp ( void )
IN_MLookUp(void)
{
mlooking = false;
in_state->IN_CenterView_fp();
@ -439,47 +578,48 @@ IN_KeyboardInit(Key_Event_fp_t fp)
* Initializes the backend
*/
void
IN_BackendInit ( in_state_t *in_state_p )
IN_BackendInit(in_state_t *in_state_p)
{
in_state = in_state_p;
m_filter = ri.Cvar_Get( "m_filter", "0", CVAR_ARCHIVE );
in_mouse = ri.Cvar_Get( "in_mouse", "0", CVAR_ARCHIVE );
m_filter = ri.Cvar_Get("m_filter", "0", CVAR_ARCHIVE);
in_mouse = ri.Cvar_Get("in_mouse", "0", CVAR_ARCHIVE);
freelook = ri.Cvar_Get( "freelook", "1", 0 );
lookstrafe = ri.Cvar_Get( "lookstrafe", "0", 0 );
sensitivity = ri.Cvar_Get( "sensitivity", "3", 0 );
exponential_speedup = ri.Cvar_Get( "exponential_speedup", "0", CVAR_ARCHIVE );
freelook = ri.Cvar_Get("freelook", "1", 0);
lookstrafe = ri.Cvar_Get("lookstrafe", "0", 0);
sensitivity = ri.Cvar_Get("sensitivity", "3", 0);
exponential_speedup = ri.Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE);
m_pitch = ri.Cvar_Get( "m_pitch", "0.022", 0 );
m_yaw = ri.Cvar_Get( "m_yaw", "0.022", 0 );
m_forward = ri.Cvar_Get( "m_forward", "1", 0 );
m_side = ri.Cvar_Get( "m_side", "0.8", 0 );
m_pitch = ri.Cvar_Get("m_pitch", "0.022", 0);
m_yaw = ri.Cvar_Get("m_yaw", "0.022", 0);
m_forward = ri.Cvar_Get("m_forward", "1", 0);
m_side = ri.Cvar_Get("m_side", "0.8", 0);
ri.Cmd_AddCommand( "+mlook", IN_MLookDown );
ri.Cmd_AddCommand( "-mlook", IN_MLookUp );
ri.Cmd_AddCommand( "force_centerview", IN_ForceCenterView );
ri.Cmd_AddCommand("+mlook", IN_MLookDown);
ri.Cmd_AddCommand("-mlook", IN_MLookUp);
ri.Cmd_AddCommand("force_centerview", IN_ForceCenterView);
mouse_x = mouse_y = 0.0;
/* SDL stuff */
SDL_EnableUNICODE( 0 );
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE);
in_grab = ri.Cvar_Get ("in_grab", "2", CVAR_ARCHIVE);
windowed_mouse = ri.Cvar_Get("windowed_mouse", "1",
CVAR_USERINFO | CVAR_ARCHIVE);
in_grab = ri.Cvar_Get("in_grab", "2", CVAR_ARCHIVE);
Com_Printf( "Input initialized.\n" );
Com_Printf("Input initialized.\n");
}
/*
* Shuts the backend down
*/
void
IN_BackendShutdown ( void )
IN_BackendShutdown(void)
{
ri.Cmd_RemoveCommand( "+mlook" );
ri.Cmd_RemoveCommand( "-mlook" );
ri.Cmd_RemoveCommand( "force_centerview" );
ri.Cmd_RemoveCommand("+mlook");
ri.Cmd_RemoveCommand("-mlook");
ri.Cmd_RemoveCommand("force_centerview");
Com_Printf("Input shut down.\n");
}
@ -487,43 +627,43 @@ IN_BackendShutdown ( void )
* Mouse button handling
*/
void
IN_BackendMouseButtons ( void )
IN_BackendMouseButtons(void)
{
int i;
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
IN_GetMouseState(&mouse_x, &mouse_y, &mouse_buttonstate);
for ( i = 0; i < 3; i++ )
for (i = 0; i < 3; i++)
{
if ( ( mouse_buttonstate & ( 1 << i ) ) && !( mouse_oldbuttonstate & ( 1 << i ) ) )
if ((mouse_buttonstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i)))
{
in_state->Key_Event_fp( K_MOUSE1 + i, true );
in_state->Key_Event_fp(K_MOUSE1 + i, true);
}
if ( !( mouse_buttonstate & ( 1 << i ) ) && ( mouse_oldbuttonstate & ( 1 << i ) ) )
if (!(mouse_buttonstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i)))
{
in_state->Key_Event_fp( K_MOUSE1 + i, false );
in_state->Key_Event_fp(K_MOUSE1 + i, false);
}
}
if ( ( mouse_buttonstate & ( 1 << 3 ) ) && !( mouse_oldbuttonstate & ( 1 << 3 ) ) )
if ((mouse_buttonstate & (1 << 3)) && !(mouse_oldbuttonstate & (1 << 3)))
{
in_state->Key_Event_fp( K_MOUSE4, true );
in_state->Key_Event_fp(K_MOUSE4, true);
}
if ( !( mouse_buttonstate & ( 1 << 3 ) ) && ( mouse_oldbuttonstate & ( 1 << 3 ) ) )
if (!(mouse_buttonstate & (1 << 3)) && (mouse_oldbuttonstate & (1 << 3)))
{
in_state->Key_Event_fp( K_MOUSE4, false );
in_state->Key_Event_fp(K_MOUSE4, false);
}
if ( ( mouse_buttonstate & ( 1 << 4 ) ) && !( mouse_oldbuttonstate & ( 1 << 4 ) ) )
if ((mouse_buttonstate & (1 << 4)) && !(mouse_oldbuttonstate & (1 << 4)))
{
in_state->Key_Event_fp( K_MOUSE5, true );
in_state->Key_Event_fp(K_MOUSE5, true);
}
if ( !( mouse_buttonstate & ( 1 << 4 ) ) && ( mouse_oldbuttonstate & ( 1 << 4 ) ) )
if (!(mouse_buttonstate & (1 << 4)) && (mouse_oldbuttonstate & (1 << 4)))
{
in_state->Key_Event_fp( K_MOUSE5, false );
in_state->Key_Event_fp(K_MOUSE5, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
@ -533,54 +673,55 @@ IN_BackendMouseButtons ( void )
* Move handling
*/
void
IN_BackendMove ( usercmd_t *cmd )
IN_BackendMove(usercmd_t *cmd)
{
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
IN_GetMouseState(&mouse_x, &mouse_y, &mouse_buttonstate);
if ( m_filter->value )
if (m_filter->value)
{
if ( ( mouse_x > 1 ) || ( mouse_x < -1) )
if ((mouse_x > 1) || (mouse_x < -1))
{
mouse_x = ( mouse_x + old_mouse_x ) * 0.5;
mouse_x = (mouse_x + old_mouse_x) * 0.5;
}
if ( ( mouse_y > 1 ) || ( mouse_y < -1) )
if ((mouse_y > 1) || (mouse_y < -1))
{
mouse_y = ( mouse_y + old_mouse_y ) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
if ( mouse_x || mouse_y )
if (mouse_x || mouse_y)
{
if ( !exponential_speedup->value )
if (!exponential_speedup->value)
{
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
}
else
{
if ( ( mouse_x > MOUSE_MIN ) || ( mouse_y > MOUSE_MIN ) ||
( mouse_x < -MOUSE_MIN ) || ( mouse_y < -MOUSE_MIN ) )
if ((mouse_x > MOUSE_MIN) || (mouse_y > MOUSE_MIN) ||
(mouse_x < -MOUSE_MIN) || (mouse_y < -MOUSE_MIN))
{
mouse_x = ( mouse_x * mouse_x * mouse_x ) / 4;
mouse_y = ( mouse_y * mouse_y * mouse_y ) / 4;
mouse_x = (mouse_x * mouse_x * mouse_x) / 4;
mouse_y = (mouse_y * mouse_y * mouse_y) / 4;
if ( mouse_x > MOUSE_MAX )
if (mouse_x > MOUSE_MAX)
{
mouse_x = MOUSE_MAX;
}
else if ( mouse_x < -MOUSE_MAX )
else if (mouse_x < -MOUSE_MAX)
{
mouse_x = -MOUSE_MAX;
}
if ( mouse_y > MOUSE_MAX )
if (mouse_y > MOUSE_MAX)
{
mouse_y = MOUSE_MAX;
}
else if ( mouse_y < -MOUSE_MAX )
else if (mouse_y < -MOUSE_MAX)
{
mouse_y = -MOUSE_MAX;
}
@ -588,20 +729,20 @@ IN_BackendMove ( usercmd_t *cmd )
}
/* add mouse X/Y movement to cmd */
if ( ( *in_state->in_strafe_state & 1 ) ||
( lookstrafe->value && mlooking ) )
if ((*in_state->in_strafe_state & 1) ||
(lookstrafe->value && mlooking))
{
cmd->sidemove += m_side->value * mouse_x;
}
else
{
in_state->viewangles [ YAW ] -= m_yaw->value * mouse_x;
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
}
if ( ( mlooking || freelook->value ) &&
!( *in_state->in_strafe_state & 1 ) )
if ((mlooking || freelook->value) &&
!(*in_state->in_strafe_state & 1))
{
in_state->viewangles [ PITCH ] += m_pitch->value * mouse_y;
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
}
else
{
@ -611,3 +752,4 @@ IN_BackendMove ( usercmd_t *cmd )
IN_ClearMouseState();
}
}

View file

@ -26,9 +26,9 @@
*/
#ifdef _WIN32
#include <SDL/SDL.h>
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include <SDL.h>
#endif
#include <GL/gl.h>
@ -41,15 +41,15 @@
/* X.org stuff */
#ifdef X11GAMMA
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#endif
SDL_Surface *surface;
glwstate_t glw_state;
qboolean have_stencil = false;
SDL_Surface *surface;
glwstate_t glw_state;
qboolean have_stencil = false;
char *displayname = NULL;
int screen = -1;
@ -62,19 +62,22 @@ XF86VidModeGamma x11_oldgamma;
/*
* Initialzes the SDL OpenGL context
*/
int GLimp_Init(void)
int
GLimp_Init(void)
{
if (!SDL_WasInit(SDL_INIT_VIDEO))
{
char driverName[ 64 ];
{
char driverName[64];
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
ri.Con_Printf( PRINT_ALL, "Couldn't init SDL video: %s.\n", SDL_GetError());
return false;
}
SDL_VideoDriverName( driverName, sizeof( driverName ) - 1 );
ri.Con_Printf( PRINT_ALL, "SDL video driver is \"%s\".\n", driverName );
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
ri.Con_Printf(PRINT_ALL, "Couldn't init SDL video: %s.\n",
SDL_GetError());
return false;
}
SDL_VideoDriverName(driverName, sizeof(driverName) - 1);
ri.Con_Printf(PRINT_ALL, "SDL video driver is \"%s\".\n", driverName);
}
return true;
@ -83,15 +86,18 @@ int GLimp_Init(void)
/*
* Sets the window icon
*/
static void SetSDLIcon()
static void
SetSDLIcon()
{
SDL_Surface *icon;
SDL_Color color;
Uint8 *ptr;
int i;
int mask;
SDL_Color color;
Uint8 *ptr;
int i;
int mask;
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0);
icon = SDL_CreateRGBSurface(SDL_SWSURFACE,
q2icon_width, q2icon_height, 8,
0, 0, 0, 0);
if (icon == NULL)
{
@ -116,7 +122,8 @@ static void SetSDLIcon()
for (i = 0; i < sizeof(q2icon_bits); i++)
{
for (mask = 1; mask != 0x100; mask <<= 1) {
for (mask = 1; mask != 0x100; mask <<= 1)
{
*ptr = (q2icon_bits[i] & mask) ? 1 : 0;
ptr++;
}
@ -136,7 +143,7 @@ UpdateHardwareGamma(void)
float gamma;
XF86VidModeGamma x11_gamma;
gamma =vid_gamma->value;
gamma = vid_gamma->value;
x11_gamma.red = gamma;
x11_gamma.green = gamma;
@ -147,6 +154,7 @@ UpdateHardwareGamma(void)
/* This forces X11 to update the gamma tables */
XF86VidModeGetGamma(dpy, screen, &x11_gamma);
}
#else
void
UpdateHardwareGamma(void)
@ -161,7 +169,8 @@ UpdateHardwareGamma(void)
/*
* Initializes the OpenGL window
*/
static qboolean GLimp_InitGraphics( qboolean fullscreen )
static qboolean
GLimp_InitGraphics(qboolean fullscreen)
{
int counter = 0;
int flags;
@ -195,7 +204,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
}
/* Create the window */
ri.Vid_NewWindow (vid.width, vid.height);
ri.Vid_NewWindow(vid.width, vid.height);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
@ -217,15 +226,17 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
while (1)
{
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL)
if ((surface =
SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL)
{
if (counter == 1)
if (counter == 1)
{
Sys_Error(PRINT_ALL, "Failed to revert to gl_mode 4. Exiting...\n");
return false;
}
ri.Con_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n", SDL_GetError());
ri.Con_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n",
SDL_GetError());
ri.Con_Printf(PRINT_ALL, "Reverting to gl_mode 4 (640x480) and windowed mode.\n");
/* Try to recover */
@ -256,7 +267,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
/* Initialize hardware gamma */
#ifdef X11GAMMA
if ( ( dpy = XOpenDisplay( displayname ) ) == NULL )
if ((dpy = XOpenDisplay(displayname)) == NULL)
{
ri.Con_Printf(PRINT_ALL, "Unable to open display.\n");
}
@ -270,7 +281,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
gl_state.hwgamma = true;
vid_gamma->modified = true;
XF86VidModeGetGamma(dpy, screen, &x11_oldgamma);
XF86VidModeGetGamma(dpy, screen, &x11_oldgamma);
ri.Con_Printf(PRINT_ALL, "Using hardware gamma via X11.\n");
}
@ -293,7 +304,8 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
/*
* Swaps the buffers to show the new frame
*/
void GLimp_EndFrame (void)
void
GLimp_EndFrame(void)
{
SDL_GL_SwapBuffers();
}
@ -301,21 +313,22 @@ void GLimp_EndFrame (void)
/*
* Changes the video mode
*/
int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
int
GLimp_SetMode(int *pwidth, int *pheight, int mode, qboolean fullscreen)
{
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
ri.Con_Printf(PRINT_ALL, "setting mode %d:", mode);
/* mode -1 is not in the vid mode table - so we keep the values in pwidth
and pheight and don't even try to look up the mode info */
if ( mode != -1 && !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
if ((mode != -1) && !ri.Vid_GetModeInfo(pwidth, pheight, mode))
{
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
ri.Con_Printf(PRINT_ALL, " invalid mode\n");
return rserr_invalid_mode;
}
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
ri.Con_Printf(PRINT_ALL, " %d %d\n", *pwidth, *pheight);
if ( !GLimp_InitGraphics( fullscreen ) )
if (!GLimp_InitGraphics(fullscreen))
{
return rserr_invalid_mode;
}
@ -326,7 +339,8 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
/*
* Shuts the SDL render backend down
*/
void GLimp_Shutdown( void )
void
GLimp_Shutdown(void)
{
if (surface)
{
@ -356,3 +370,4 @@ void GLimp_Shutdown( void )
gl_state.hwgamma = false;
}

View file

@ -272,3 +272,4 @@ SNDDMA_BeginPainting(void)
{
SDL_LockAudio();
}