mirror of
https://git.code.sf.net/p/quake/nuq
synced 2024-11-24 21:12:07 +00:00
Backport joystick support from newtree.
This commit is contained in:
parent
ad7c97b4fc
commit
495cf79c09
8 changed files with 415 additions and 213 deletions
21
configure.in
21
configure.in
|
@ -699,6 +699,27 @@ AM_CONDITIONAL(SNDTYPE_SUN, test "$SNDTYPE" = "SUN")
|
|||
AM_CONDITIONAL(SNDTYPE_WIN32, test "$SNDTYPE" = "WIN32")
|
||||
AM_CONDITIONAL(SNDTYPE_NULL, test "$SNDTYPE" != "ALSA_0_5" -a "$SNDTYPE" != "ALSA_0_6" -a "$SNDTYPE" != "MME" -a "$SNDTYPE" != "OSS" -a "$SNDTYPE" != "SUN" -a "$SNDTYPE" != "WIN32")
|
||||
|
||||
dnl Tests for joystick support
|
||||
AC_MSG_CHECKING(for joystick support)
|
||||
if test -z "$JOYTYPE" -a "x$ac_cv_header_linux_joystick_h" = "xyes"; then
|
||||
AC_EGREP_CPP([QF_maGiC_VALUE],[
|
||||
#include <linux/joystick.h>
|
||||
#ifdef JS_VERSION
|
||||
QF_maGiC_VALUE
|
||||
#endif
|
||||
], JOYTYPE="Linux")
|
||||
fi
|
||||
|
||||
if test "$JOYTYPE"; then
|
||||
AC_MSG_RESULT([yes ($JOYTYPE)])
|
||||
else
|
||||
AC_MSG_RESULT([no, using null joystick driver])
|
||||
fi
|
||||
AC_SUBST(JOY_LIBS)
|
||||
AC_SUBST(JOY_CFLAGS)
|
||||
AM_CONDITIONAL(JOYTYPE_LINUX, test "$JOYTYPE" = "Linux")
|
||||
AM_CONDITIONAL(JOYTYPE_NULL, test "$JOYTYPE" != "Linux")
|
||||
|
||||
dnl ==================================================================
|
||||
dnl Checks for CD-ROM
|
||||
dnl ==================================================================
|
||||
|
|
|
@ -1,25 +1,82 @@
|
|||
/*
|
||||
joystick.h
|
||||
|
||||
/*
|
||||
* Copyright (C) 2000 David Jeffery
|
||||
*/
|
||||
QuakeForge joystick DPI (driver programming interface)
|
||||
|
||||
Copyright (C) 1996-1997 Jeff Teunissen <deek@dusknet.dhs.org>
|
||||
|
||||
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:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cvar.h"
|
||||
#include "protocol.h"
|
||||
|
||||
extern cvar_t *joy_device; // Joystick device name
|
||||
extern cvar_t *joy_enable; // Joystick enabling flag
|
||||
extern cvar_t *joy_sensitivity; // Joystick sensitivity
|
||||
|
||||
extern qboolean joy_found; // Joystick present?
|
||||
extern qboolean joy_active; // Joystick in use?
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
JOY_Command ()
|
||||
|
||||
void joystick_init(void);
|
||||
void joystick_command(void);
|
||||
void joystick_move(usercmd_t *cmd);
|
||||
Use this function to process joystick button presses and generate key
|
||||
events. It is called inside the IN_Commands () input function, once each
|
||||
frame.
|
||||
|
||||
You should exit this function immediately if either joy_active or
|
||||
joy_enable->int_val are zero.
|
||||
*/
|
||||
void JOY_Command (void);
|
||||
|
||||
/*
|
||||
JOY_Move (usercmd_t *)
|
||||
|
||||
Use this function to process joystick movements to move the player around.
|
||||
|
||||
You should exit this function immediately if either joy_active or
|
||||
joy_enable->int_val are zero.
|
||||
*/
|
||||
void JOY_Move (usercmd_t *);
|
||||
|
||||
/*
|
||||
JOY_Init ()
|
||||
|
||||
Use this function to initialize the joystick Cvars, open your joystick
|
||||
device, and get it ready for use. You MUST obey the value of the
|
||||
joy_enable Cvar. Set joy_found if there is a device, and joy_active if
|
||||
you have successfully enabled it.
|
||||
*/
|
||||
void JOY_Init (void);
|
||||
|
||||
/*
|
||||
JOY_Shutdown ()
|
||||
|
||||
Use this function to close the joystick device and tell QuakeForge that it
|
||||
is no longer available. It is called from IN_Init (), but may be called
|
||||
elsewhere to disable the device.
|
||||
*/
|
||||
void JOY_Shutdown (void);
|
||||
|
|
|
@ -37,7 +37,7 @@ bin_PROGRAMS = @TARGETS@
|
|||
EXTRA_PROGRAMS= nuq-ggi nuq-mgl nuq-sdl nuq-svga nuq-x11 \
|
||||
nuq-3dfx nuq-glx nuq-sgl nuq-wgl nuq-ded
|
||||
|
||||
noinst_LIBRARIES= libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
noinst_LIBRARIES= libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#if ASM_ARCH
|
||||
math_ASM= math.S cl_math.S
|
||||
|
@ -106,6 +106,18 @@ libqfcd_a_SOURCES= cd_null.c
|
|||
endif
|
||||
EXTRA_libqfcd_a_SOURCES= cd_audio.c cd_win.c cd_linux.c cd_null.c
|
||||
|
||||
#
|
||||
# ... Joystick
|
||||
#
|
||||
if JOYTYPE_LINUX
|
||||
libqfjs_a_SOURCES= joy_linux.c
|
||||
endif
|
||||
if JOYTYPE_NULL
|
||||
libqfjs_a_SOURCES= joy_null.c
|
||||
endif
|
||||
libqfjs_a_CFLAGS= $(JOY_CFLAGS)
|
||||
EXTRA_libqfjs_a_SOURCES= joy_linux.c joy_null.c
|
||||
|
||||
#
|
||||
# ... Networking
|
||||
#
|
||||
|
@ -115,12 +127,12 @@ libqfnet_a_SOURCES= mdfour.c net_bsd.c checksum.c net_dgrm.c net_loop.c \
|
|||
EXTRA_libqfcd_a_SOURCES=net_dos.c net_bw.c net_ipx.c net_mp.c net_ser.c \
|
||||
net_win.c net_wins.c net_wipx.c
|
||||
|
||||
client_LIBS= -L. -lqfsys -lqfsnd -lqfcd -lqfnet $(SOUND_LIBS) $(NET_LIBS)
|
||||
client_LIBS= -L. -lqfsys -lqfsnd -lqfcd -lqfjs -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 joystick.c
|
||||
gib_interpret.c gib_modules.c gib_parse.c gib_stack.c
|
||||
|
||||
server_SOURCES= host.c host_cmd.c \
|
||||
pr_cmds.c pr_edict.c pr_exec.c \
|
||||
|
@ -148,7 +160,7 @@ ggi_SOURCES= vid_ggi.c
|
|||
|
||||
nuq_ggi_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(ggi_SOURCES)
|
||||
nuq_ggi_LDADD= $(client_LIBS) $(GGI_LIBS)
|
||||
nuq_ggi_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_ggi_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... SciTech MGL
|
||||
|
@ -157,7 +169,7 @@ mgl_SOURCES= vid_mgl.c in_win.c
|
|||
|
||||
nuq_mgl_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(mgl_SOURCES)
|
||||
nuq_mgl_LDADD= $(client_LIBS) $(MGL_LIBS)
|
||||
nuq_mgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_mgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... Sam Lantinga's Simple DirectMedia Layer, version 1.0 and higher
|
||||
|
@ -166,7 +178,7 @@ sdl_SOURCES= vid_sdl.c
|
|||
|
||||
nuq_sdl_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(sdl_SOURCES)
|
||||
nuq_sdl_LDADD= $(client_LIBS) $(SDL_LIBS)
|
||||
nuq_sdl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_sdl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... Linux SVGAlib
|
||||
|
@ -175,7 +187,7 @@ svga_SOURCES= d_copy.S vid_svgalib.c in_svgalib.c
|
|||
|
||||
nuq_svga_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(svga_SOURCES)
|
||||
nuq_svga_LDADD= $(client_LIBS) $(SVGA_LIBS)
|
||||
nuq_svga_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_svga_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... X11
|
||||
|
@ -184,7 +196,7 @@ x11_SOURCES= in_x11.c context_x11.c dga_check.c
|
|||
|
||||
nuq_x11_SOURCES= $(combined_SOURCES) $(soft_SOURCES) $(x11_SOURCES) vid_x11.c
|
||||
nuq_x11_LDADD= $(client_LIBS) $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB)
|
||||
nuq_x11_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_x11_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
|
||||
#
|
||||
|
@ -204,7 +216,7 @@ tdfx_SOURCES= vid_3dfxsvga.c in_svgalib.c
|
|||
|
||||
nuq_3dfx_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(tdfx_SOURCES)
|
||||
nuq_3dfx_LDADD= $(client_LIBS) $(TDFXGL_LIBS) $(SVGA_LIBS) $(DL_LIBS)
|
||||
nuq_3dfx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_3dfx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... OpenGL in X Window
|
||||
|
@ -213,7 +225,7 @@ glx_SOURCES= vid_glx.c $(x11_SOURCES)
|
|||
|
||||
nuq_glx_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(glx_SOURCES)
|
||||
nuq_glx_LDADD= $(client_LIBS) $(GLX_LIBS) $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(DL_LIBS)
|
||||
nuq_glx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_glx_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# ... Sam Lantinga's Simple DirectMedia Layer, version 1.1 and higher, in GL mode
|
||||
|
@ -222,7 +234,7 @@ sgl_SOURCES= vid_sgl.c
|
|||
|
||||
nuq_sgl_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(sgl_SOURCES)
|
||||
nuq_sgl_LDADD= $(client_LIBS) $(SDL_LIBS) $(GLX_LIBS) $(DL_LIBS)
|
||||
nuq_sgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_sgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# SGI/Microsoft WGL (Windows OpenGL)
|
||||
|
@ -231,7 +243,7 @@ wgl_SOURCES= vid_wgl.c
|
|||
|
||||
nuq_wgl_SOURCES= $(combined_SOURCES) $(ogl_SOURCES) $(wgl_SOURCES)
|
||||
nuq_wgl_LDADD= $(client_LIBS)
|
||||
nuq_wgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfnet.a
|
||||
nuq_wgl_DEPENDENCIES=libqfsys.a libqfsnd.a libqfcd.a libqfjs.a libqfnet.a
|
||||
|
||||
#
|
||||
# dedicated server
|
||||
|
|
|
@ -117,7 +117,7 @@ int IN_Init(void)
|
|||
if (UseMouse)
|
||||
IN_init_mouse();
|
||||
|
||||
joystick_init();
|
||||
JOY_Init();
|
||||
|
||||
in_svgalib_inited = 1;
|
||||
return 1;
|
||||
|
@ -284,6 +284,7 @@ static void IN_init_mouse()
|
|||
|
||||
void IN_Shutdown(void)
|
||||
{
|
||||
JOY_Shutdown ();
|
||||
Con_Printf("IN_Shutdown\n");
|
||||
|
||||
if (UseMouse) mouse_close();
|
||||
|
@ -304,8 +305,8 @@ void IN_SendKeyEvents(void)
|
|||
|
||||
void IN_Commands(void)
|
||||
{
|
||||
if (UseMouse)
|
||||
{
|
||||
JOY_Command ();
|
||||
if (UseMouse) {
|
||||
/* Poll mouse values */
|
||||
while (mouse_update())
|
||||
;
|
||||
|
@ -339,6 +340,7 @@ void IN_Commands(void)
|
|||
|
||||
void IN_Move(usercmd_t *cmd)
|
||||
{
|
||||
JOY_Move (cmd);
|
||||
if (!UseMouse) return;
|
||||
|
||||
/* Poll mouse values */
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "sys.h"
|
||||
#include "cmd.h"
|
||||
#include "draw.h"
|
||||
#include "compat.h"
|
||||
#include "console.h"
|
||||
#include "client.h"
|
||||
#include "context_x11.h"
|
||||
|
@ -299,8 +300,9 @@ event_motion(XEvent *event)
|
|||
|
||||
|
||||
void
|
||||
IN_Commands(void)
|
||||
IN_Commands (void)
|
||||
{
|
||||
JOY_Command ();
|
||||
if (old__windowed_mouse != _windowed_mouse->value) {
|
||||
old__windowed_mouse = _windowed_mouse->value;
|
||||
|
||||
|
@ -319,7 +321,7 @@ IN_Commands(void)
|
|||
|
||||
|
||||
void
|
||||
IN_SendKeyEvents(void)
|
||||
IN_SendKeyEvents (void)
|
||||
{
|
||||
/* Get events from X server. */
|
||||
x11_process_events();
|
||||
|
@ -327,8 +329,10 @@ IN_SendKeyEvents(void)
|
|||
|
||||
|
||||
void
|
||||
IN_Move(usercmd_t *cmd)
|
||||
IN_Move (usercmd_t *cmd)
|
||||
{
|
||||
JOY_Move (cmd);
|
||||
|
||||
if (!mouse_avail)
|
||||
return;
|
||||
|
||||
|
@ -352,10 +356,7 @@ IN_Move(usercmd_t *cmd)
|
|||
|
||||
if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
|
||||
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
|
||||
if (cl.viewangles[PITCH] > 80)
|
||||
cl.viewangles[PITCH] = 80;
|
||||
if (cl.viewangles[PITCH] < -70)
|
||||
cl.viewangles[PITCH] = -70;
|
||||
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
|
||||
} else {
|
||||
if ((in_strafe.state & 1) && noclip_anglehack)
|
||||
cmd->upmove -= m_forward->value * mouse_y;
|
||||
|
@ -387,8 +388,9 @@ static void IN_ExtraOptionCmd(int option_cursor)
|
|||
Called at shutdown
|
||||
*/
|
||||
void
|
||||
IN_Shutdown(void)
|
||||
IN_Shutdown (void)
|
||||
{
|
||||
JOY_Shutdown ();
|
||||
Con_Printf("IN_Shutdown\n");
|
||||
mouse_avail = 0;
|
||||
if (x_disp) {
|
||||
|
@ -404,7 +406,7 @@ IN_Shutdown(void)
|
|||
extern int scr_width, scr_height;
|
||||
|
||||
int
|
||||
IN_Init(void)
|
||||
IN_Init (void)
|
||||
{
|
||||
// open the display
|
||||
if (!x_disp)
|
||||
|
@ -412,7 +414,7 @@ IN_Init(void)
|
|||
if (!x_win)
|
||||
Sys_Error("IN: No window!!\n");
|
||||
|
||||
x11_open_display(); // call to increment the reference counter
|
||||
x11_open_display (); // call to increment the reference counter
|
||||
{
|
||||
int attribmask = CWEventMask;
|
||||
XWindowAttributes attribs_1;
|
||||
|
@ -425,7 +427,7 @@ IN_Init(void)
|
|||
XChangeWindowAttributes(x_disp, x_win, attribmask, &attribs_2);
|
||||
}
|
||||
|
||||
joystick_init();
|
||||
JOY_Init ();
|
||||
|
||||
_windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None");
|
||||
m_filter = Cvar_Get ("m_filter","0",CVAR_ARCHIVE,"None");
|
||||
|
@ -441,8 +443,7 @@ IN_Init(void)
|
|||
in_nodga_grab = Cvar_Get ("in_nodga_grab", "0", CVAR_ROM,
|
||||
"grab keyboard and mouse input when using -nodga");
|
||||
|
||||
if (COM_CheckParm("-nodga"))
|
||||
{
|
||||
if (COM_CheckParm ("-nodga")) {
|
||||
if (in_nodga_grab->value) {
|
||||
XGrabKeyboard (x_disp, x_win, True, GrabModeAsync,
|
||||
GrabModeAsync, CurrentTime);
|
||||
|
|
203
source/joy_linux.c
Normal file
203
source/joy_linux.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
joy_linux.c
|
||||
|
||||
Joystick driver for Linux
|
||||
|
||||
Copyright (C) 2000 David Jeffery
|
||||
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
|
||||
|
||||
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:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <linux/joystick.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "console.h"
|
||||
#include "client.h"
|
||||
#include "cvar.h"
|
||||
#include "keys.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#define JOY_MAX_AXES 6
|
||||
#define JOY_MAX_BUTTONS 10
|
||||
|
||||
cvar_t *joy_device; // Joystick device name
|
||||
cvar_t *joy_enable; // Joystick enabling flag
|
||||
cvar_t *joy_sensitivity; // Joystick sensitivity
|
||||
|
||||
qboolean joy_found = false;
|
||||
qboolean joy_active = false;
|
||||
|
||||
// Variables and structures for this driver
|
||||
int joy_handle;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *string;
|
||||
} ocvar_t;
|
||||
|
||||
struct joy_axis {
|
||||
cvar_t *axis;
|
||||
ocvar_t var;
|
||||
int current;
|
||||
};
|
||||
|
||||
struct joy_button {
|
||||
int old;
|
||||
int current;
|
||||
};
|
||||
|
||||
struct joy_axis joy_axes[JOY_MAX_AXES] = {
|
||||
{NULL, {"joyaxis1", "1"}, 0},
|
||||
{NULL, {"joyaxis2", "2"}, 0},
|
||||
{NULL, {"joyaxis3", "3"}, 0},
|
||||
{NULL, {"joyaxis4", "0"}, 0},
|
||||
{NULL, {"joyaxis5", "0"}, 0},
|
||||
{NULL, {"joyaxis6", "0"}, 0}
|
||||
};
|
||||
|
||||
struct joy_button joy_buttons[JOY_MAX_BUTTONS];
|
||||
|
||||
void
|
||||
JOY_Command (void)
|
||||
{
|
||||
struct js_event event;
|
||||
|
||||
if (!joy_active || !joy_enable->int_val)
|
||||
return;
|
||||
|
||||
while (read (joy_handle, &event, sizeof (struct js_event)) > -1) {
|
||||
if (event.type & JS_EVENT_BUTTON) {
|
||||
if(event.number >= JOY_MAX_BUTTONS)
|
||||
continue;
|
||||
|
||||
joy_buttons[event.number].current = event.value;
|
||||
|
||||
if (joy_buttons[event.number].current > joy_buttons[event.number].old) {
|
||||
Key_Event(K_AUX1 + event.number, true);
|
||||
} else {
|
||||
if (joy_buttons[event.number].current < joy_buttons[event.number].old) {
|
||||
Key_Event(K_AUX1 + event.number, false);
|
||||
}
|
||||
}
|
||||
joy_buttons[event.number].old = joy_buttons[event.number].current;
|
||||
} else {
|
||||
if (event.type & JS_EVENT_AXIS) {
|
||||
if (event.number >= JOY_MAX_AXES)
|
||||
continue;
|
||||
joy_axes[event.number].current = event.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Move (usercmd_t *cmd)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!joy_active || !joy_enable->int_val)
|
||||
return;
|
||||
|
||||
Cvar_SetValue (joy_sensitivity, bound (1, joy_sensitivity->value, 25));
|
||||
for (i = 0; i < JOY_MAX_AXES; i++) {
|
||||
switch (joy_axes[i].axis->int_val) {
|
||||
case 1:
|
||||
cl.viewangles[YAW] -= m_yaw->value * (float) (joy_axes[i].current / (201 - (joy_sensitivity->value * 4)));
|
||||
break;
|
||||
case 2:
|
||||
cmd->forwardmove -= m_forward->value * (float) (joy_axes[i].current / (201 - (joy_sensitivity->value * 4)));
|
||||
break;
|
||||
case 3:
|
||||
cmd->sidemove += m_side->value * (float) (joy_axes[i].current / (201 - (joy_sensitivity->value * 4)));
|
||||
break;
|
||||
case 4:
|
||||
if (joy_axes[i].current) {
|
||||
V_StopPitchDrift();
|
||||
cl.viewangles[PITCH] -= m_pitch->value * (float) (joy_axes[i].current / (201 - (joy_sensitivity->value * 4)));
|
||||
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Init (void)
|
||||
{
|
||||
joy_device = Cvar_Get ("joy_device", "/dev/js0", CVAR_NONE|CVAR_ROM, "Joystick device");
|
||||
joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag");
|
||||
joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity");
|
||||
|
||||
// Open joystick device
|
||||
joy_handle = open (joy_device->string, O_RDONLY|O_NONBLOCK);
|
||||
if (joy_handle < 0) {
|
||||
Con_Printf ("JOY: Joystick not found.\n");
|
||||
} else {
|
||||
int i;
|
||||
joy_found = true;
|
||||
|
||||
if (!joy_enable->int_val) {
|
||||
Con_Printf ("JOY: Joystick found, but not enabled.\n");
|
||||
i = close (joy_handle);
|
||||
if (i) {
|
||||
Con_Printf ("JOY: Failed to close joystick device!\n");
|
||||
}
|
||||
} else {
|
||||
// Initialize joystick if found and enabled
|
||||
for (i = 0; i < JOY_MAX_AXES; i++) {
|
||||
joy_axes[i].axis = Cvar_Get (joy_axes[i].var.name,
|
||||
joy_axes[i].var.string,
|
||||
CVAR_ARCHIVE, "None");
|
||||
}
|
||||
for (i = 0; i < JOY_MAX_BUTTONS; i++) {
|
||||
joy_buttons[i].old = 0;
|
||||
joy_buttons[i].current = 0;
|
||||
}
|
||||
joy_active = true;
|
||||
Con_Printf ("JOY: Joystick found and activated.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Shutdown (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!joy_active)
|
||||
return;
|
||||
|
||||
i = close (joy_handle);
|
||||
if (i) {
|
||||
Con_Printf ("JOY: Failed to close joystick device!\n");
|
||||
} else {
|
||||
Con_Printf ("JOY_Shutdown\n");
|
||||
}
|
||||
joy_active = false;
|
||||
joy_found = false;
|
||||
}
|
70
source/joy_null.c
Normal file
70
source/joy_null.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
joy_null.c
|
||||
|
||||
Joystick device driver template
|
||||
|
||||
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
|
||||
|
||||
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:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cvar.h"
|
||||
#include "protocol.h"
|
||||
#include "qtypes.h"
|
||||
|
||||
// Joystick variables and structures
|
||||
cvar_t *joy_device; // Joystick device name
|
||||
cvar_t *joy_enable; // Joystick enabling flag
|
||||
cvar_t *joy_sensitivity; // Joystick sensitivity
|
||||
|
||||
qboolean joy_found = false;
|
||||
qboolean joy_active = false;
|
||||
|
||||
void
|
||||
JOY_Command (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Move (usercmd_t *cmd)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Init (void)
|
||||
{
|
||||
joy_device = Cvar_Get ("joy_device", "none", CVAR_NONE|CVAR_ROM, "Joystick device");
|
||||
joy_enable = Cvar_Get ("joy_enable", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick enable flag");
|
||||
joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_NONE|CVAR_ARCHIVE, "Joystick sensitivity");
|
||||
|
||||
Con_DPrintf ("This system does not have joystick support.\n");
|
||||
}
|
||||
|
||||
void
|
||||
JOY_Shutdown (void)
|
||||
{
|
||||
joy_active = false;
|
||||
joy_found = false;
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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