mirror of
https://git.code.sf.net/p/quake/quake2forge
synced 2024-12-13 06:01:19 +00:00
- Added patch from icculus CVS for SDL joystick support
(patchsets 60, 61)
This commit is contained in:
parent
27349bfd44
commit
206594ccc6
1 changed files with 174 additions and 52 deletions
226
src/rw_sdl.c
226
src/rw_sdl.c
|
@ -37,6 +37,13 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define JOY_AXIS_X 0
|
||||
#define JOY_AXIS_Y 1
|
||||
#define JOY_AXIS_Z 2
|
||||
#define JOY_AXIS_R 3
|
||||
#define JOY_AXIS_U 4
|
||||
#define JOY_AXIS_V 5
|
||||
|
||||
static qboolean X11_active = false;
|
||||
|
||||
static SDL_Surface *surface;
|
||||
|
@ -96,6 +103,17 @@ static cvar_t *m_pitch;
|
|||
static cvar_t *m_forward;
|
||||
static cvar_t *my_freelook;
|
||||
|
||||
/************************
|
||||
* Joystick
|
||||
************************/
|
||||
static cvar_t *in_joystick;
|
||||
static cvar_t *j_invert_y;
|
||||
static qboolean joystick_avail;
|
||||
static SDL_Joystick *joy;
|
||||
static int joy_oldbuttonstate;
|
||||
static int joy_numbuttons;
|
||||
static int jx, jy, jt;
|
||||
|
||||
static void Force_CenterView_f (void)
|
||||
{
|
||||
in_state->viewangles[PITCH] = 0;
|
||||
|
@ -120,6 +138,7 @@ void RW_IN_Init(in_state_t *in_state_p)
|
|||
_windowed_mouse = ri.Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE);
|
||||
m_filter = ri.Cvar_Get ("m_filter", "0", 0);
|
||||
in_mouse = ri.Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE);
|
||||
in_joystick = ri.Cvar_Get("in_joystick", "0", CVAR_ARCHIVE);
|
||||
my_freelook = ri.Cvar_Get( "freelook", "0", 0);
|
||||
my_lookstrafe = ri.Cvar_Get ("lookstrafe", "0", 0);
|
||||
|
||||
|
@ -129,6 +148,8 @@ void RW_IN_Init(in_state_t *in_state_p)
|
|||
m_forward = ri.Cvar_Get ("m_forward", "1", 0);
|
||||
m_side = ri.Cvar_Get ("m_side", "0.8", 0);
|
||||
|
||||
j_invert_y = ri.Cvar_Get("j_invert_y", "1", 0);
|
||||
|
||||
ri.Cmd_AddCommand ("+mlook", RW_IN_MLookDown);
|
||||
ri.Cmd_AddCommand ("-mlook", RW_IN_MLookUp);
|
||||
|
||||
|
@ -157,30 +178,43 @@ IN_Commands
|
|||
*/
|
||||
void RW_IN_Commands (void)
|
||||
{
|
||||
int i;
|
||||
int i, key_index;
|
||||
|
||||
if (!mouse_avail)
|
||||
return;
|
||||
|
||||
for (i=0 ; i<3 ; i++) {
|
||||
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
|
||||
in_state->Key_Event_fp (K_MOUSE1 + i, true);
|
||||
|
||||
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
|
||||
in_state->Key_Event_fp (K_MOUSE1 + i, false);
|
||||
if (mouse_avail) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
|
||||
in_state->Key_Event_fp (K_MOUSE1 + i, true);
|
||||
|
||||
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
|
||||
in_state->Key_Event_fp (K_MOUSE1 + i, false);
|
||||
}
|
||||
/* can't put in loop because K_MOUSE4 doesn't come after K_MOUSE3 */
|
||||
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)))
|
||||
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)))
|
||||
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)))
|
||||
in_state->Key_Event_fp(K_MOUSE5, false);
|
||||
in_state->Key_Event_fp(K_MOUSE5, false);
|
||||
|
||||
mouse_oldbuttonstate = mouse_buttonstate;
|
||||
}
|
||||
if (joystick_avail && joy) {
|
||||
for (i = 0; i < joy_numbuttons; i++) {
|
||||
if (SDL_JoystickGetButton(joy, i) && joy_oldbuttonstate != i) {
|
||||
key_index = (i < 4) ? K_JOY1 : K_AUX1;
|
||||
in_state->Key_Event_fp(key_index + i, true);
|
||||
joy_oldbuttonstate = i;
|
||||
}
|
||||
if (!SDL_JoystickGetButton(joy, i) && joy_oldbuttonstate != i) {
|
||||
key_index = (i < 4) ? K_JOY1 : K_AUX1;
|
||||
in_state->Key_Event_fp(key_index + i, false);
|
||||
joy_oldbuttonstate = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -190,50 +224,73 @@ IN_Move
|
|||
*/
|
||||
void RW_IN_Move (usercmd_t *cmd)
|
||||
{
|
||||
if (!mouse_avail)
|
||||
return;
|
||||
|
||||
if (m_filter->value)
|
||||
/*** FIXME
|
||||
* You can accelerate while in the air, this doesn't
|
||||
* make physical sense. Try falling off something and then moving
|
||||
* forward.
|
||||
***/
|
||||
|
||||
if (mouse_avail) {
|
||||
if (m_filter->value)
|
||||
{
|
||||
mouse_x = (mx + old_mouse_x) * 0.5;
|
||||
mouse_y = (my + old_mouse_y) * 0.5;
|
||||
} else {
|
||||
mouse_x = mx;
|
||||
mouse_y = my;
|
||||
}
|
||||
|
||||
old_mouse_x = mx;
|
||||
old_mouse_y = my;
|
||||
|
||||
if (mouse_x || mouse_y) {
|
||||
mouse_x *= sensitivity->value;
|
||||
mouse_y *= sensitivity->value;
|
||||
|
||||
// add mouse X/Y movement to cmd
|
||||
if ( (*in_state->in_strafe_state & 1) ||
|
||||
(my_lookstrafe->value && mlooking ))
|
||||
cmd->sidemove += m_side->value * mouse_x;
|
||||
else
|
||||
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
|
||||
|
||||
|
||||
if ( (mlooking || my_freelook->value) &&
|
||||
!(*in_state->in_strafe_state & 1))
|
||||
{
|
||||
mouse_x = (mx + old_mouse_x) * 0.5;
|
||||
mouse_y = (my + old_mouse_y) * 0.5;
|
||||
} else {
|
||||
mouse_x = mx;
|
||||
mouse_y = my;
|
||||
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd->forwardmove -= m_forward->value * mouse_y;
|
||||
}
|
||||
mx = my = 0;
|
||||
}
|
||||
}
|
||||
if (joystick_avail && joy) {
|
||||
// add joy X/Y movement to cmd
|
||||
if ( (*in_state->in_strafe_state & 1) ||
|
||||
(my_lookstrafe->value && mlooking ))
|
||||
cmd->sidemove += m_side->value * (jx/100);
|
||||
else
|
||||
in_state->viewangles[YAW] -= m_yaw->value * (jx/100);
|
||||
|
||||
old_mouse_x = mx;
|
||||
old_mouse_y = my;
|
||||
|
||||
if (!mouse_x && !mouse_y)
|
||||
return;
|
||||
|
||||
mouse_x *= sensitivity->value;
|
||||
mouse_y *= sensitivity->value;
|
||||
|
||||
// add mouse X/Y movement to cmd
|
||||
if ( (*in_state->in_strafe_state & 1) ||
|
||||
(my_lookstrafe->value && mlooking ))
|
||||
cmd->sidemove += m_side->value * mouse_x;
|
||||
if ((mlooking || my_freelook->value) && !(*in_state->in_strafe_state & 1)) {
|
||||
if (j_invert_y)
|
||||
in_state->viewangles[PITCH] -= m_pitch->value * (jy/100);
|
||||
else
|
||||
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
|
||||
|
||||
|
||||
if ( (mlooking || my_freelook->value) &&
|
||||
!(*in_state->in_strafe_state & 1))
|
||||
{
|
||||
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd->forwardmove -= m_forward->value * mouse_y;
|
||||
}
|
||||
mx = my = 0;
|
||||
in_state->viewangles[PITCH] += m_pitch->value * (jy/100);
|
||||
cmd->forwardmove -= m_forward->value * (jt/100);
|
||||
} else {
|
||||
cmd_forwardmove -= m_forward->value * (jy/100);
|
||||
}
|
||||
jt = jx = jy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void IN_DeactivateMouse( void )
|
||||
{
|
||||
{
|
||||
if (!mouse_avail)
|
||||
return;
|
||||
|
||||
|
@ -400,6 +457,20 @@ void GetEvent(SDL_Event *event)
|
|||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
keyq[keyq_head].key =
|
||||
((((SDL_JoyButtonEvent*)event)->button < 4)?K_JOY1:K_AUX1)+
|
||||
((SDL_JoyButtonEvent*)event)->button;
|
||||
keyq[keyq_head].down = true;
|
||||
keyq_head = (keyq_head+1)&63;
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
keyq[keyq_head].key =
|
||||
((((SDL_JoyButtonEvent*)event)->button < 4)?K_JOY1:K_AUX1)+
|
||||
((SDL_JoyButtonEvent*)event)->button;
|
||||
keyq[keyq_head].down = false;
|
||||
keyq_head = (keyq_head+1)&63;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if ( (KeyStates[SDLK_LALT] || KeyStates[SDLK_RALT]) &&
|
||||
(event->key.keysym.sym == SDLK_RETURN) ) {
|
||||
|
@ -459,6 +530,45 @@ void GetEvent(SDL_Event *event)
|
|||
|
||||
}
|
||||
|
||||
void InitJoystick() {
|
||||
int num_joysticks, i;
|
||||
|
||||
if (!(SDL_INIT_JOYSTICK&SDL_WasInit(SDL_INIT_JOYSTICK))) {
|
||||
ri.Con_Printf(PRINT_ALL, "SDL Joystick not initialized, trying to init...\n");
|
||||
SDL_Init(SDL_INIT_JOYSTICK);
|
||||
}
|
||||
if (in_joystick) {
|
||||
ri.Con_Printf(PRINT_ALL, "Trying to start-up joystick...\n");
|
||||
if ((num_joysticks=SDL_NumJoysticks())) {
|
||||
for(i=0;i<num_joysticks;i++) {
|
||||
ri.Con_Printf(PRINT_ALL, "Trying joystick [%s]\n",
|
||||
SDL_JoystickName(i));
|
||||
if (!SDL_JoystickOpened(i)) {
|
||||
joy = SDL_JoystickOpen(0);
|
||||
if (joy) {
|
||||
ri.Con_Printf(PRINT_ALL, "Joytick activated.\n");
|
||||
joystick_avail = true;
|
||||
joy_numbuttons = SDL_JoystickNumButtons(joy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!joy) {
|
||||
ri.Con_Printf(PRINT_ALL, "Failed to open any joysticks\n");
|
||||
joystick_avail = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ri.Con_Printf(PRINT_ALL, "No joysticks available\n");
|
||||
joystick_avail = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ri.Con_Printf(PRINT_ALL, "Joystick Inactive\n");
|
||||
joystick_avail = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
|
@ -494,9 +604,13 @@ int SWimp_Init( void *hInstance, void *wndProc )
|
|||
}
|
||||
#endif
|
||||
|
||||
InitJoystick();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef OPENGL
|
||||
void *GLimp_GetProcAddress(const char *func)
|
||||
{
|
||||
|
@ -609,6 +723,8 @@ static qboolean SWimp_InitGraphics( qboolean fullscreen )
|
|||
|
||||
X11_active = true;
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
|
@ -867,7 +983,13 @@ void KBD_Update(void)
|
|||
|
||||
if (!mx && !my)
|
||||
SDL_GetRelativeMouseState(&mx, &my);
|
||||
|
||||
|
||||
if (joystick_avail && joy) {
|
||||
jx = SDL_JoystickGetAxis(joy, 0);
|
||||
jy = SDL_JoystickGetAxis(joy, 1);
|
||||
jt = SDL_JoystickGetAxis(joy, 3);
|
||||
}
|
||||
|
||||
mouse_buttonstate = 0;
|
||||
bstate = SDL_GetMouseState(NULL, NULL);
|
||||
if (SDL_BUTTON(1) & bstate)
|
||||
|
|
Loading…
Reference in a new issue