mirror of
https://git.code.sf.net/p/quake/nuq
synced 2024-11-21 19:51:09 +00:00
port David Jeffery's linux joystick port patch. it fires up ok, but I can't tell
how well it works as I don't seem to have js support compiled into my kernel :/
This commit is contained in:
parent
459f7f3087
commit
8ed4ef45cb
6 changed files with 197 additions and 2 deletions
|
@ -67,7 +67,7 @@ AC_CHECK_HEADERS(
|
|||
dsound.h mmsystem.h initguid.h mme/mmsystem.h mme/mme_public.h \
|
||||
sys/asoundlib.h string.h strings.h memory.h malloc.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);
|
|
@ -120,7 +120,7 @@ client_LIBS= -L. -lqfsys -lqfsnd -lqfcd -lqfnet $(SOUND_LIBS) $(NET_LIBS)
|
|||
client_SOURCES= cl_cam.c cl_demo.c cl_input.c cl_main.c cl_parse.c \
|
||||
cl_tent.c console.c keys.c menu.c sbar.c r_part.c r_view.c \
|
||||
nonintel.c gib.c gib_instructions.c gib_vars.c \
|
||||
gib_interpret.c gib_modules.c gib_parse.c gib_stack.c
|
||||
gib_interpret.c gib_modules.c gib_parse.c gib_stack.c joystick.c
|
||||
|
||||
server_SOURCES= host.c host_cmd.c \
|
||||
pr_cmds.c pr_edict.c pr_exec.c \
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "cmd.h"
|
||||
#include "host.h"
|
||||
#include "qargs.h"
|
||||
#include "joystick.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -116,6 +117,8 @@ int IN_Init(void)
|
|||
if (UseMouse)
|
||||
IN_init_mouse();
|
||||
|
||||
joystick_init();
|
||||
|
||||
in_svgalib_inited = 1;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "context_x11.h"
|
||||
#include "qargs.h"
|
||||
#include "host.h"
|
||||
#include "joystick.h"
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
|
@ -424,6 +425,8 @@ IN_Init(void)
|
|||
XChangeWindowAttributes(x_disp, x_win, attribmask, &attribs_2);
|
||||
}
|
||||
|
||||
joystick_init();
|
||||
|
||||
_windowed_mouse = Cvar_Get ("_windowed_mouse","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