first steps

This commit is contained in:
Bill Currie 2001-04-11 19:56:01 +00:00
parent 99fd4ab464
commit b025bb32e1
7 changed files with 258 additions and 210 deletions

View file

@ -1,2 +1,3 @@
.vimrc
Makefile
Makefile.in

View file

@ -26,20 +26,32 @@
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "QF/qtypes.h"
#include "QF/cvar.h"
#include "protocol.h"
#define JOY_MAX_AXES 6
#define JOY_MAX_BUTTONS 16
extern cvar_t *joy_device; // Joystick device name
extern cvar_t *joy_enable; // Joystick enabling flag
extern cvar_t *joy_sensitivity; // Joystick sensitivity
extern struct cvar_s *joy_device; // Joystick device name
extern struct cvar_s *joy_enable; // Joystick enabling flag
extern struct cvar_s *joy_sensitivity; // Joystick sensitivity
extern qboolean joy_found; // Joystick present?
extern qboolean joy_active; // Joystick in use?
struct joy_axis {
struct cvar_s *axis;
int current;
};
struct joy_button {
int old;
int current;
};
extern struct joy_axis joy_axes[JOY_MAX_AXES];
extern struct joy_button joy_buttons[JOY_MAX_BUTTONS];
/*
JOY_Command ()
@ -81,3 +93,19 @@ void JOY_Init_Cvars (void);
elsewhere to disable the device.
*/
void JOY_Shutdown (void);
/*
JOY_Open ()
JOY_Close ()
os specific joystick init/deinit
*/
int JOY_Open (void);
void JOY_Close (void);
/*
JOY_Read ()
os specific joystick reading
*/
void JOY_Read (void);

View file

@ -5,13 +5,13 @@ lib_LTLIBRARIES = libQFjs.la
libQFjs_la_LDFLAGS = -version-info 1:0:0 $(CD_LIBS)
if JOYTYPE_LINUX
libQFjs_la_SOURCES= joy_linux.c
libQFjs_la_SOURCES= joy.c joy_linux.c
endif
if JOYTYPE_WIN32
libQFjs_la_SOURCES= joy_win.c
libQFjs_la_SOURCES= joy.c joy_win.c
endif
if JOYTYPE_NULL
libQFjs_la_SOURCES= joy_null.c
libQFjs_la_SOURCES= joy.c joy_null.c
endif
libQFjs_la_CFLAGS= $(JOY_CFLAGS)

179
libs/video/targets/joy.c Normal file
View file

@ -0,0 +1,179 @@
/*
joy.c
Joystick input interface
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 "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/mathlib.h"
#define JOY_MAX_AXES 6
#define JOY_MAX_BUTTONS 16
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;
typedef struct {
char *name;
char *string;
} ocvar_t;
ocvar_t joy_axes_cvar_init[JOY_MAX_AXES] = {
{"joyaxis1", "1"},
{"joyaxis2", "2"},
{"joyaxis3", "3"},
{"joyaxis4", "0"},
{"joyaxis5", "0"},
{"joyaxis6", "0"}
};
struct joy_axis joy_axes[JOY_MAX_AXES];
struct joy_button joy_buttons[JOY_MAX_BUTTONS];
void
JOY_Command (void)
{
JOY_Read ();
}
void
JOY_Move (void)
{
int i;
if (!joy_active || !joy_enable->int_val)
return;
Cvar_SetValue (joy_sensitivity, max (0.01, joy_sensitivity->value));
for (i = 0; i < JOY_MAX_AXES; i++) {
switch (joy_axes[i].axis->int_val) {
case 1:
viewdelta.angles[YAW] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 2:
viewdelta.position[2] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 3:
viewdelta.position[0] +=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 4:
if (joy_axes[i].current) {
viewdelta.angles[PITCH] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value *
4)));
}
break;
}
}
}
void
JOY_Init (void)
{
int i;
if (JOY_Open () == -1) {
Con_Printf ("JOY: Joystick not found.\n");
joy_found = false;
joy_active = false;
return;
}
joy_found = true;
if (!joy_enable->int_val) {
Con_Printf ("JOY: Joystick found, but not enabled.\n");
joy_active = false;
JOY_Close ();
}
Con_Printf ("JOY: Joystick found and activated.\n");
// Initialize joystick if found and enabled
for (i = 0; i < JOY_MAX_BUTTONS; i++) {
joy_buttons[i].old = 0;
joy_buttons[i].current = 0;
}
joy_active = true;
}
void
JOY_Init_Cvars (void)
{
int i;
joy_device =
Cvar_Get ("joy_device", "/dev/js0", CVAR_NONE | CVAR_ROM, 0,
"Joystick device");
joy_enable =
Cvar_Get ("joy_enable", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick enable flag");
joy_sensitivity =
Cvar_Get ("joy_sensitivity", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick sensitivity");
for (i = 0; i < JOY_MAX_AXES; i++) {
joy_axes[i].axis = Cvar_Get (joy_axes_cvar_init[i].name,
joy_axes_cvar_init[i].string,
CVAR_ARCHIVE, 0, "Set joystick axes");
}
}
void
JOY_Shutdown (void)
{
if (!joy_active)
return;
JOY_Close ();
joy_active = false;
joy_found = false;
}

View file

@ -35,55 +35,17 @@
#include <fcntl.h>
#include <unistd.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/mathlib.h"
#define JOY_MAX_AXES 6
#define JOY_MAX_BUTTONS 16
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;
#include "QF/qtypes.h"
// 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)
JOY_Read (void)
{
struct js_event event;
@ -117,114 +79,26 @@ JOY_Command (void)
}
}
void
JOY_Move (void)
{
int i;
if (!joy_active || !joy_enable->int_val)
return;
Cvar_SetValue (joy_sensitivity, max (0.01, joy_sensitivity->value));
for (i = 0; i < JOY_MAX_AXES; i++) {
switch (joy_axes[i].axis->int_val) {
case 1:
viewdelta.angles[YAW] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 2:
viewdelta.position[2] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 3:
viewdelta.position[0] +=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value * 4)));
break;
case 4:
if (joy_axes[i].current) {
viewdelta.angles[PITCH] -=
(float) (joy_axes[i].current /
(201 -
(joy_sensitivity->value *
4)));
}
break;
}
}
}
void
JOY_Init (void)
int
JOY_Open (void)
{
// 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_BUTTONS; i++) {
joy_buttons[i].old = 0;
joy_buttons[i].current = 0;
}
joy_active = true;
Con_Printf ("JOY: Joystick found and activated.\n");
}
return -1;
}
return 0;
}
void
JOY_Init_Cvars (void)
JOY_Close (void)
{
int i;
joy_device =
Cvar_Get ("joy_device", "/dev/js0", CVAR_NONE | CVAR_ROM, 0,
"Joystick device");
joy_enable =
Cvar_Get ("joy_enable", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick enable flag");
joy_sensitivity =
Cvar_Get ("joy_sensitivity", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick sensitivity");
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, 0, "Set joystick axes");
}
}
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;
}

View file

@ -32,49 +32,21 @@
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/joystick.h"
#include "QF/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)
JOY_Read (void)
{
}
void
JOY_Move (void)
int
JOY_Open (void)
{
return -1;
}
void
JOY_Init (void)
JOY_Close (void)
{
Con_DPrintf ("This system does not have joystick support.\n");
}
void
JOY_Init_Cvars (void)
{
joy_device =
Cvar_Get ("joy_device", "none", CVAR_NONE | CVAR_ROM, 0,
"Joystick device");
joy_enable =
Cvar_Get ("joy_enable", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick enable flag");
joy_sensitivity =
Cvar_Get ("joy_sensitivity", "1", CVAR_NONE | CVAR_ARCHIVE, 0,
"Joystick sensitivity");
}
void
JOY_Shutdown (void)
{
joy_active = false;
joy_found = false;
}

View file

@ -1,11 +1,11 @@
/*
joy_win.c
joy_win.c
Joystick device driver for Win32
Joystick device driver for Win32
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
Copyright (C) 2000 Jukka Sorjonen <jukka.sorjone@asikkala.fi>
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
Copyright (C) 2000 Jukka Sorjonen <jukka.sorjone@asikkala.fi>
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
@ -32,6 +32,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <math.h>
#ifdef __MINGW32__
# define INITGUID
#endif
@ -44,7 +45,6 @@
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "host.h"
#include "QF/input.h"
#include "QF/keys.h"
#include "QF/qargs.h"
@ -146,13 +146,13 @@ JOY_Read (void)
ji.dwUpos += 100;
}
if (joy_debug->int_val) {
if (ji.dwXpos) Con_Printf("X: %ld\n",ji.dwXpos);
if (ji.dwYpos) Con_Printf("Y: %ld\n",ji.dwYpos);
if (ji.dwZpos) Con_Printf("Z: %ld\n",ji.dwZpos);
if (ji.dwRpos) Con_Printf("R: %ld\n",ji.dwRpos);
if (ji.dwUpos) Con_Printf("U: %ld\n",ji.dwUpos);
if (ji.dwVpos) Con_Printf("V: %ld\n",ji.dwVpos);
if (ji.dwButtons) Con_Printf("B: %ld\n",ji.dwButtons);
if (ji.dwXpos) Con_Printf("X: %ld\n",ji.dwXpos);
if (ji.dwYpos) Con_Printf("Y: %ld\n",ji.dwYpos);
if (ji.dwZpos) Con_Printf("Z: %ld\n",ji.dwZpos);
if (ji.dwRpos) Con_Printf("R: %ld\n",ji.dwRpos);
if (ji.dwUpos) Con_Printf("U: %ld\n",ji.dwUpos);
if (ji.dwVpos) Con_Printf("V: %ld\n",ji.dwVpos);
if (ji.dwButtons) Con_Printf("B: %ld\n",ji.dwButtons);
}
return true;
} else { // read error
@ -166,7 +166,7 @@ JOY_Command (void)
int i, key_index;
DWORD buttonstate, povstate;
if (!joy_found) {
if (!joy_found) {
return;
}
// loop through the joystick buttons
@ -219,17 +219,16 @@ JOY_Command (void)
void
JOY_Move (void)
{
float speed, aspeed;
float fAxisValue, fTemp;
int i;
static int lastjoy=0;
static int lastjoy=0;
// complete initialization if first time in
// this is needed as cvars are not available at initialization time
if (!joy_advancedinit || lastjoy!=joy_advanced->int_val) {
if (!joy_advancedinit || lastjoy!=joy_advanced->int_val) {
JOY_AdvancedUpdate_f ();
joy_advancedinit = true;
lastjoy=joy_advanced->int_val;
lastjoy=joy_advanced->int_val;
}
// verify joystick is available and that the user wants to use it
if (!joy_active || !joy_enable->int_val) {
@ -240,12 +239,6 @@ JOY_Move (void)
return;
}
if (in_speed.state & 1)
speed = cl_movespeedkey->value;
else
speed = 1;
aspeed = speed * host_frametime;
// loop through the axes
for (i = 0; i < JOY_MAX_AXES; i++) {
// get the floating point zero-centered, potentially-inverted data
@ -274,6 +267,7 @@ JOY_Move (void)
switch (dwAxisMap[i]) {
case AxisForward:
if (!joy_advanced->int_val && freelook) {
// user wants forward control to become look control
if (fabs (fAxisValue) > joy_pitchthreshold->value) {
@ -378,10 +372,10 @@ JOY_Move (void)
void
JOY_Init (void)
{
JOY_StartupJoystick();
JOY_StartupJoystick();
Cmd_AddCommand ("joyadvancedupdate", JOY_AdvancedUpdate_f, "FIXME: This appears to update the joystick poll? No Description");
// Con_DPrintf ("This system does not have joystick support.\n");
// Con_DPrintf ("This system does not have joystick support.\n");
}
void
@ -465,7 +459,7 @@ JOY_StartupJoystick (void)
MMRESULT mmr = !JOYERR_NOERROR;
// assume no joystick
joy_found = false;
joy_found = false;
// abort startup if user requests no joystick
if (COM_CheckParm ("-nojoy"))
@ -512,9 +506,9 @@ JOY_StartupJoystick (void)
// this is needed as cvars are not available during initialization
joy_advancedinit = false;
joy_found = true;
// FIXME: do this right
joy_active = true;
joy_found = true;
// FIXME: do this right
joy_active = true;
Con_Printf ("\njoystick detected\n\n");
}
@ -593,7 +587,7 @@ JOY_Init_Cvars(void)
joy_wwhack1 = Cvar_Get ("joywwhack1", "0.0", CVAR_NONE, 0, "FIXME: No Description");
joy_wwhack2 = Cvar_Get ("joywwhack2", "0.0", CVAR_NONE, 0, "FIXME: No Description");
joy_debug = Cvar_Get ("joy_debug", "0.0", CVAR_NONE, 0, "FIXME: No Description");
joy_debug = Cvar_Get ("joy_debug", "0.0", CVAR_NONE, 0, "FIXME: No Description");
return;
}