mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-25 13:32:01 +00:00
David Jeffery's linux joystick support ala nuq
This commit is contained in:
parent
9a4e650790
commit
fb55453675
6 changed files with 197 additions and 2 deletions
|
@ -64,7 +64,7 @@ AC_CHECK_HEADERS(
|
||||||
dsound.h mmsystem.h initguid.h mme/mmsystem.h mme/mme_public.h \
|
dsound.h mmsystem.h initguid.h mme/mmsystem.h mme/mme_public.h \
|
||||||
sys/asoundlib.h string.h strings.h memory.h malloc.h \
|
sys/asoundlib.h string.h strings.h memory.h malloc.h \
|
||||||
errno.h sys/dir.h fnmatch.h \
|
errno.h sys/dir.h fnmatch.h \
|
||||||
mgraph.h
|
mgraph.h linux/joystick.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
25
include/joystick.h
Normal file
25
include/joystick.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2000 David Jeffery
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 2 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void joystick_init(void);
|
||||||
|
void joystick_command(void);
|
||||||
|
void joystick_move(usercmd_t *cmd);
|
|
@ -136,7 +136,7 @@ client_SOURCES= cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c cl_main.c \
|
||||||
cl_misc.c cl_parse.c cl_pred.c cl_tent.c cl_cam.c teamplay.c \
|
cl_misc.c cl_parse.c cl_pred.c cl_tent.c cl_cam.c teamplay.c \
|
||||||
r_view.c wad.c model_alias.c model_sprite.c \
|
r_view.c wad.c model_alias.c model_sprite.c \
|
||||||
console.c keys.c menu.c nonintel.c skin.c sbar.c \
|
console.c keys.c menu.c nonintel.c skin.c sbar.c \
|
||||||
cl_slist.c $(client_ASM)
|
cl_slist.c $(client_ASM) joystick.c
|
||||||
|
|
||||||
#
|
#
|
||||||
# Software-rendering clients
|
# Software-rendering clients
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "cvar.h"
|
#include "cvar.h"
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "qargs.h"
|
#include "qargs.h"
|
||||||
|
#include "joystick.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -112,6 +113,8 @@ int IN_Init(void)
|
||||||
if (UseMouse)
|
if (UseMouse)
|
||||||
IN_init_mouse();
|
IN_init_mouse();
|
||||||
|
|
||||||
|
joystick_init();
|
||||||
|
|
||||||
in_svgalib_inited = 1;
|
in_svgalib_inited = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "context_x11.h"
|
#include "context_x11.h"
|
||||||
#include "qargs.h"
|
#include "qargs.h"
|
||||||
|
#include "joystick.h"
|
||||||
|
|
||||||
#ifdef HAVE_STRINGS_H
|
#ifdef HAVE_STRINGS_H
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
@ -424,6 +425,8 @@ IN_Init(void)
|
||||||
XChangeWindowAttributes(x_disp, x_win, attribmask, &attribs_2);
|
XChangeWindowAttributes(x_disp, x_win, attribmask, &attribs_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joystick_init();
|
||||||
|
|
||||||
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
|
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
|
||||||
m_filter = Cvar_Get ("m_filter","0",CVAR_ARCHIVE,"None");
|
m_filter = Cvar_Get ("m_filter","0",CVAR_ARCHIVE,"None");
|
||||||
|
|
||||||
|
|
164
source/joystick.c
Normal file
164
source/joystick.c
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2000 David Jeffery
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 2 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX_JOYSTICK_H
|
||||||
|
|
||||||
|
#include <linux/joystick.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "console.h"
|
||||||
|
#include "client.h"
|
||||||
|
#include "cvar.h"
|
||||||
|
#include "keys.h"
|
||||||
|
|
||||||
|
//joystick variables and structures
|
||||||
|
#define MAX_JOYAXIS 6
|
||||||
|
#define MAX_JOYBUTTON 10
|
||||||
|
#define JOYLOOK_MAX 200
|
||||||
|
#define JOYMOVE_MAX 200
|
||||||
|
int joydev;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char *string;
|
||||||
|
} ocvar_t;
|
||||||
|
|
||||||
|
struct joyaxis{
|
||||||
|
int current;
|
||||||
|
ocvar_t var;
|
||||||
|
cvar_t *axis;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct joybutton{
|
||||||
|
int old;
|
||||||
|
int current;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct joyaxis joyaxiscontrol[MAX_JOYAXIS] = {
|
||||||
|
{0,{"joyaxis1","1"}} ,
|
||||||
|
{0,{"joyaxis2","2"}} ,
|
||||||
|
{0,{"joyaxis3","3"}} ,
|
||||||
|
{0,{"joyaxis4","0"}} ,
|
||||||
|
{0,{"joyaxis5","0"}} ,
|
||||||
|
{0,{"joyaxis6","0"}}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct joybutton joybuttoncontrol[MAX_JOYBUTTON];
|
||||||
|
int joyfound = 0;
|
||||||
|
|
||||||
|
void joystick_command(void)
|
||||||
|
{
|
||||||
|
struct js_event event;
|
||||||
|
|
||||||
|
if(!joyfound)
|
||||||
|
return;
|
||||||
|
while(read(joydev, &event, sizeof(struct js_event)) > -1){
|
||||||
|
if(event.type & JS_EVENT_BUTTON){
|
||||||
|
if(event.number >= MAX_JOYBUTTON)
|
||||||
|
continue;
|
||||||
|
joybuttoncontrol[event.number].current = event.value;
|
||||||
|
if(joybuttoncontrol[event.number].current >
|
||||||
|
joybuttoncontrol[event.number].old)
|
||||||
|
Key_Event(K_AUX1 + event.number, true);
|
||||||
|
else if(joybuttoncontrol[event.number].current <
|
||||||
|
joybuttoncontrol[event.number].old)
|
||||||
|
Key_Event(K_AUX1 + event.number, false);
|
||||||
|
joybuttoncontrol[event.number].old =
|
||||||
|
joybuttoncontrol[event.number].current;
|
||||||
|
}
|
||||||
|
else if(event.type & JS_EVENT_AXIS){
|
||||||
|
if(event.number >= MAX_JOYAXIS)
|
||||||
|
continue;
|
||||||
|
joyaxiscontrol[event.number].current = event.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void joystick_move(usercmd_t *cmd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(!joyfound)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_JOYAXIS; i++) {
|
||||||
|
switch(joyaxiscontrol[i].axis->int_val){
|
||||||
|
case 1:
|
||||||
|
cl.viewangles[YAW] -= m_yaw->value * (float)joyaxiscontrol[i].current/JOYLOOK_MAX;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cmd->forwardmove -= m_forward->value * (float)joyaxiscontrol[i].current/JOYMOVE_MAX;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
cmd->sidemove += m_side->value * (float)joyaxiscontrol[i].current/JOYMOVE_MAX;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if(joyaxiscontrol[i].current){
|
||||||
|
V_StopPitchDrift();
|
||||||
|
cl.viewangles[PITCH] -= m_pitch->value * (float)joyaxiscontrol[i].current/JOYLOOK_MAX;
|
||||||
|
if(cl.viewangles[PITCH] > 80)
|
||||||
|
cl.viewangles[PITCH] = 80;
|
||||||
|
else if(cl.viewangles[PITCH] < -70)
|
||||||
|
cl.viewangles[PITCH] = -70;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void joystick_init(void)
|
||||||
|
{
|
||||||
|
/*initialize joystick if found */
|
||||||
|
if ((joydev = open("/dev/js0", O_RDONLY | O_NONBLOCK)) < 0) {
|
||||||
|
joyfound = 0;
|
||||||
|
Con_DPrintf("no joystick\n");
|
||||||
|
} else {
|
||||||
|
int i;
|
||||||
|
joyfound = 1;
|
||||||
|
for(i = 0; i < MAX_JOYAXIS; i++) {
|
||||||
|
joyaxiscontrol[i].axis = Cvar_Get(joyaxiscontrol[i].var.name,
|
||||||
|
joyaxiscontrol[i].var.string,
|
||||||
|
CVAR_ARCHIVE, "None");
|
||||||
|
}
|
||||||
|
for(i = 0; i < MAX_JOYBUTTON; i++) {
|
||||||
|
joybuttoncontrol[i].old = 0;
|
||||||
|
joybuttoncontrol[i].current = 0;
|
||||||
|
}
|
||||||
|
Con_DPrintf("joystick enabled\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
void joystick_init(void){
|
||||||
|
}
|
||||||
|
|
||||||
|
void joystick_command(void){
|
||||||
|
}
|
||||||
|
|
||||||
|
void joystick_move(usercmd_t *cmd){
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue