Zeropad: Yes it's a bunch *more* cleanup work on Zeropad.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1256 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-05-25 01:59:17 +00:00
parent a8094d5786
commit bd9886b332
8 changed files with 252 additions and 269 deletions

View File

@ -20,10 +20,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <pthread.h> #include <pthread.h>
#define JOYSTICK_SUPPORT
#ifdef JOYSTICK_SUPPORT
#include "joystick.h" #include "joystick.h"
#endif
#include "zeropad.h" #include "zeropad.h"
#include "linux.h" #include "linux.h"

View File

@ -48,9 +48,7 @@ s32 _PADopen(void *pDsp)
s_keyRelease[0] = s_keyRelease[1] = 0; s_keyRelease[0] = s_keyRelease[1] = 0;
XAutoRepeatOff(GSdsp); XAutoRepeatOff(GSdsp);
#ifdef JOYSTICK_SUPPORT
JoystickInfo::EnumerateJoysticks(s_vjoysticks); JoystickInfo::EnumerateJoysticks(s_vjoysticks);
#endif
return 0; return 0;
} }
@ -100,6 +98,16 @@ int _GetJoystickIdFromPAD(int pad)
} }
} }
} }
if ((joyid < 0) || (joyid >= (int)s_vjoysticks.size()))
{
// get first unused joystick
for (joyid = 0; joyid < s_vjoysticks.size(); ++joyid)
{
if (s_vjoysticks[joyid]->GetPAD() < 0) break;
}
}
return joyid; return joyid;
} }
@ -186,8 +194,6 @@ void CALLBACK PADupdate(int pad)
} }
// joystick info // joystick info
#ifdef JOYSTICK_SUPPORT
SDL_JoystickUpdate(); SDL_JoystickUpdate();
for (int i = 0; i < PADKEYS; i++) for (int i = 0; i < PADKEYS; i++)
@ -202,22 +208,24 @@ void CALLBACK PADupdate(int pad)
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size())) if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
{ {
pjoy = s_vjoysticks[joyid]; pjoy = s_vjoysticks[joyid];
int pad = (pjoy)->GetPAD();
int value = SDL_JoystickGetButton((pjoy)->GetJoy(), PAD_GETJOYBUTTON(key));
if (SDL_JoystickGetButton((pjoy)->GetJoy(), PAD_GETJOYBUTTON(key))) if (value)
clear_bit(status[(pjoy)->GetPAD()], i); // pressed clear_bit(status[pad], i); // pressed
else else
set_bit(status[(pjoy)->GetPAD()], i); // pressed set_bit(status[pad], i); // pressed
} }
} }
else if (IS_JOYSTICK(key)) else if (IS_JOYSTICK(key))
{ {
int joyid = PAD_GETJOYID(key); int joyid = PAD_GETJOYID(key);
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size())) if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
{ {
pjoy = s_vjoysticks[joyid]; pjoy = s_vjoysticks[joyid];
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
int pad = (pjoy)->GetPAD(); int pad = (pjoy)->GetPAD();
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
switch (i) switch (i)
{ {
@ -233,34 +241,16 @@ void CALLBACK PADupdate(int pad)
} }
} }
} }
else if (IS_POV(key))
{
int joyid = PAD_GETJOYID(key);
if (joyid >= 0 && (joyid < (int)s_vjoysticks.size()))
{
pjoy = s_vjoysticks[joyid];
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
int pad = (pjoy)->GetPAD();
if (PAD_GETPOVSIGN(key) && (value < -2048))
clear_bit(status[pad], i);
else if (!PAD_GETPOVSIGN(key) && (value > 2048))
clear_bit(status[pad], i);
else
set_bit(status[pad], i);
}
}
#ifdef EXPERIMENTAL_POV_CODE #ifdef EXPERIMENTAL_POV_CODE
else if (IS_HAT(key)) else if (IS_HAT(key))
{ {
int joyid = PAD_GETJOYID(key); int joyid = PAD_GETJOYID(key);
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size())) if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
{ {
pjoy = s_vjoysticks[joyid]; pjoy = s_vjoysticks[joyid];
int value = SDL_JoystickGetHat((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
int pad = (pjoy)->GetPAD(); int pad = (pjoy)->GetPAD();
int value = SDL_JoystickGetHat((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
//PAD_LOG("Hat = %d for key %d\n", PAD_GETPOVDIR(key), key); //PAD_LOG("Hat = %d for key %d\n", PAD_GETPOVDIR(key), key);
if ((value != SDL_HAT_CENTERED) && (PAD_GETHATDIR(key) == value)) if ((value != SDL_HAT_CENTERED) && (PAD_GETHATDIR(key) == value))
@ -268,45 +258,12 @@ void CALLBACK PADupdate(int pad)
if ((value == SDL_HAT_UP) || (value == SDL_HAT_RIGHT) || (value == SDL_HAT_DOWN) ||(value == SDL_HAT_LEFT)) if ((value == SDL_HAT_UP) || (value == SDL_HAT_RIGHT) || (value == SDL_HAT_DOWN) ||(value == SDL_HAT_LEFT))
{ {
set_bit(status[pad], i); set_bit(status[pad], i);
PAD_LOG("Registered %s. Set (%d)\n", HatName(value), i);
} }
else else
{ {
clear_bit(status[pad], i); clear_bit(status[pad], i);
} }
switch (i)
{
case PAD_LEFT:
PAD_LOG("Hat Left!\n");
break;
case PAD_DOWN:
PAD_LOG("Hat Down!\n");
break;
case PAD_RIGHT:
PAD_LOG("Hat Right!\n");
break;
case PAD_UP:
PAD_LOG("Hat Up!\n");
break;
}
switch (value)
{
case SDL_HAT_UP:
PAD_LOG("D-pad Up!\n");
break;
case SDL_HAT_RIGHT:
PAD_LOG("D-pad Right!\n");
break;
case SDL_HAT_DOWN:
PAD_LOG("D-pad Down!\n");
break;
case SDL_HAT_LEFT:
PAD_LOG("D-pad Left!\n");
break;
}
} }
else else
{ {
@ -315,8 +272,27 @@ void CALLBACK PADupdate(int pad)
} }
} }
#endif #endif
else if (IS_POV(key))
{
int joyid = PAD_GETJOYID(key);
if (joyid >= 0 && (joyid < (int)s_vjoysticks.size()))
{
pjoy = s_vjoysticks[joyid];
int pad = (pjoy)->GetPAD();
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
if (PAD_GETPOVSIGN(key) && (value < -2048))
clear_bit(status[pad], i);
else if (!PAD_GETPOVSIGN(key) && (value > 2048))
clear_bit(status[pad], i);
else
set_bit(status[pad], i);
}
}
} }
#endif
pthread_spin_lock(&s_mutexStatus); pthread_spin_lock(&s_mutexStatus);
s_keyPress[pad] |= keyPress; s_keyPress[pad] |= keyPress;
@ -335,6 +311,7 @@ void UpdateConf(int pad)
GtkWidget *Btn; GtkWidget *Btn;
for (i = 0; i < ArraySize(s_pGuiKeyMap); i++) for (i = 0; i < ArraySize(s_pGuiKeyMap); i++)
{ {
string tmp;
if (s_pGuiKeyMap[i] == NULL) continue; if (s_pGuiKeyMap[i] == NULL) continue;
@ -344,8 +321,7 @@ void UpdateConf(int pad)
PAD_LOG("ZeroPAD: cannot find key %s\n", s_pGuiKeyMap[i]); PAD_LOG("ZeroPAD: cannot find key %s\n", s_pGuiKeyMap[i]);
continue; continue;
} }
string tmp;
if (IS_KEYBOARD(conf.keys[pad][i])) if (IS_KEYBOARD(conf.keys[pad][i]))
{ {
char* pstr = XKeysymToString(PAD_GETKEY(conf.keys[pad][i])); char* pstr = XKeysymToString(PAD_GETKEY(conf.keys[pad][i]));
@ -353,44 +329,49 @@ void UpdateConf(int pad)
} }
else if (IS_JOYBUTTONS(conf.keys[pad][i])) else if (IS_JOYBUTTONS(conf.keys[pad][i]))
{ {
int button = PAD_GETJOYBUTTON(conf.keys[pad][i]);
tmp.resize(28); tmp.resize(28);
sprintf(&tmp[0], "JBut %d", PAD_GETJOYBUTTON(conf.keys[pad][i]));
sprintf(&tmp[0], "JBut %d", button);
} }
else if (IS_JOYSTICK(conf.keys[pad][i])) else if (IS_JOYSTICK(conf.keys[pad][i]))
{ {
int axis = PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]);
tmp.resize(28); tmp.resize(28);
sprintf(&tmp[0], "JAxis %d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
sprintf(&tmp[0], "JAxis %d", axis);
} }
#ifdef EXPERIMENTAL_POV_CODE #ifdef EXPERIMENTAL_POV_CODE
else if (IS_HAT(conf.keys[pad][i])) else if (IS_HAT(conf.keys[pad][i]))
{ {
int axis = PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]);
tmp.resize(28); tmp.resize(28);
switch(PAD_GETHATDIR(conf.keys[pad][i])) switch(PAD_GETHATDIR(conf.keys[pad][i]))
{ {
case SDL_HAT_UP: case SDL_HAT_UP:
sprintf(&tmp[0], "JPOVU-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i])); sprintf(&tmp[0], "JPOVU-%d", axis);
break; break;
case SDL_HAT_RIGHT: case SDL_HAT_RIGHT:
sprintf(&tmp[0], "JPOVR-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i])); sprintf(&tmp[0], "JPOVR-%d", axis);
break; break;
case SDL_HAT_DOWN: case SDL_HAT_DOWN:
sprintf(&tmp[0], "JPOVD-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i])); sprintf(&tmp[0], "JPOVD-%d", axis);
break; break;
case SDL_HAT_LEFT: case SDL_HAT_LEFT:
sprintf(&tmp[0], "JPOVL-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i])); sprintf(&tmp[0], "JPOVL-%d", axis);
break; break;
} }
} }
#else #endif
else if (IS_POV(conf.keys[pad][i])) else if (IS_POV(conf.keys[pad][i]))
{ {
tmp.resize(28); tmp.resize(28);
sprintf(&tmp[0], "JPOV %d%s", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]), PAD_GETPOVSIGN(conf.keys[pad][i]) ? "-" : "+"); sprintf(&tmp[0], "JPOV %d%s", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]), PAD_GETPOVSIGN(conf.keys[pad][i]) ? "-" : "+");
} }
#endif
if (tmp.size() > 0) if (tmp.size() > 0)
{ {
@ -404,17 +385,8 @@ void UpdateConf(int pad)
// check bounds // check bounds
int joyid = _GetJoystickIdFromPAD(pad); int joyid = _GetJoystickIdFromPAD(pad);
if ((joyid < 0) || (joyid >= (int)s_vjoysticks.size()))
{
// get first unused joystick
for (joyid = 0; joyid < s_vjoysticks.size(); ++joyid)
{
if (s_vjoysticks[joyid]->GetPAD() < 0) break;
}
}
if (joyid >= 0 && joyid < (int)s_vjoysticks.size()) if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); // select the combo gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); // select the combo
else else
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), s_vjoysticks.size()); // no gamepad gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), s_vjoysticks.size()); // no gamepad
@ -446,21 +418,7 @@ int GetLabelId(GtkWidget *label)
return (int)(uptr)gtk_object_get_user_data(GTK_OBJECT(label)); return (int)(uptr)gtk_object_get_user_data(GTK_OBJECT(label));
} }
void UpdateJoysticks(vector<JoystickInfo*>::iterator itjoy) bool PollKeyboard(char* &temp, u32 &pkey)
{
itjoy = s_vjoysticks.begin();
SDL_JoystickUpdate();
// Save everything in the vector s_vjoysticks.
while (itjoy != s_vjoysticks.end())
{
(*itjoy)->SaveState();
itjoy++;
}
}
bool PollKeyboard(char* &temp, u32* &pkey)
{ {
GdkEvent *ev = gdk_event_get(); GdkEvent *ev = gdk_event_get();
@ -472,15 +430,14 @@ bool PollKeyboard(char* &temp, u32* &pkey)
if (ev->key.keyval == GDK_Escape) if (ev->key.keyval == GDK_Escape)
{ {
temp = "Unknown"; temp = "Unknown";
*pkey = NULL; pkey = NULL;
} }
else else
{ {
temp = XKeysymToString(ev->key.keyval); temp = XKeysymToString(ev->key.keyval);
*pkey = ev->key.keyval; pkey = ev->key.keyval;
} }
return true; return true;
} }
} }
@ -488,170 +445,64 @@ bool PollKeyboard(char* &temp, u32* &pkey)
return false; return false;
} }
bool PollButtons(vector<JoystickInfo*>::iterator itjoy, int &jbutton, u32* &pkey)
{
// MAKE sure to look for changes in the state!!
for (int i = 0; i < (*itjoy)->GetNumButtons(); ++i)
{
int but = SDL_JoystickGetButton((*itjoy)->GetJoy(), i);
if (but != (*itjoy)->GetButtonState(i))
{
if (!but) // released, we don't really want this
{
(*itjoy)->SetButtonState(i, 0);
break;
}
*pkey = PAD_JOYBUTTON((*itjoy)->GetId(), i);
jbutton = i;
return true;
}
}
return false;
}
bool PollAxes(vector<JoystickInfo*>::iterator itjoy, bool pov, int &jbutton, bool &negative, u32* &pkey)
{
for (int i = 0; i < (*itjoy)->GetNumAxes(); ++i)
{
int value = SDL_JoystickGetAxis((*itjoy)->GetJoy(), i);
if (value != (*itjoy)->GetAxisState(i))
{
PAD_LOG("Change in joystick %d: %d.\n", i, value);
if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this
{
// released, we don't really want this
(*itjoy)->SetAxisState(i, value);
break;
}
if (abs(value) > 0x3fff)
{
jbutton = i;
if (pov)
{
negative = (value < 0);
*pkey = PAD_POV((*itjoy)->GetId(), negative, i);
}
else // axis
{
*pkey = PAD_JOYSTICK((*itjoy)->GetId(), i);
}
return true;
}
}
}
return false;
}
/*SDL_HAT_CENTERED,
SDL_HAT_UP, SDL_HAT_RIGHT,
SDL_HAT_DOWN, SDL_HAT_LEFT,
SDL_HAT_RIGHTUP, SDL_HAT_RIGHTDOWN,
SDL_HAT_LEFTUP, SDL_HAT_LEFTDOWN*/
bool PollHAT(vector<JoystickInfo*>::iterator itjoy, int &jbutton, int &dir, u32* &pkey)
{
#ifdef EXPERIMENTAL_POV_CODE
for (int i = 0; i < (*itjoy)->GetNumPOV(); ++i)
{
int value = SDL_JoystickGetHat((*itjoy)->GetJoy(), i);
if (value != SDL_HAT_CENTERED)
{
switch (value)
{
case SDL_HAT_UP:
case SDL_HAT_RIGHT:
case SDL_HAT_DOWN:
case SDL_HAT_LEFT:
*pkey = PAD_HAT((*itjoy)->GetId(), value, i);
jbutton = i;
dir = value;
PAD_LOG("Hat Pressed!");
return true;
default:
break;
}
}
}
#endif
return false;
}
void OnConf_Key(GtkButton *button, gpointer user_data) void OnConf_Key(GtkButton *button, gpointer user_data)
{ {
u32 *pkey;
GtkWidget* label = GetLabelWidget(button); GtkWidget* label = GetLabelWidget(button);
bool captured = false;
char str[32];
int id = GetLabelId(label); int id = GetLabelId(label);
if (id == -1) return; if (id == -1) return;
int pad = id / PADKEYS; int pad = id / PADKEYS;
int key = id % PADKEYS; int key = id % PADKEYS;
pkey = &conf.keys[pad][key];
// save the states // save the joystick states
#ifdef JOYSTICK_SUPPORT UpdateJoysticks();
vector<JoystickInfo*>::iterator itjoy;
UpdateJoysticks(itjoy); while (!captured)
#endif
for (;;)
{ {
vector<JoystickInfo*>::iterator itjoy;
char *tmp; char *tmp;
if (PollKeyboard(tmp, pkey)) if (PollKeyboard(tmp, conf.keys[pad][key]))
{ {
gtk_entry_set_text(GTK_ENTRY(label), tmp); strcpy(str, tmp);
return; captured = true;
break;
} }
#ifdef JOYSTICK_SUPPORT
itjoy = s_vjoysticks.begin();
SDL_JoystickUpdate(); SDL_JoystickUpdate();
while (itjoy != s_vjoysticks.end()) itjoy = s_vjoysticks.begin();
while ((itjoy != s_vjoysticks.end()) && (!captured))
{ {
int jbutton, direction; int jbutton, direction;
if (PollButtons(itjoy, jbutton, pkey)) if ((*itjoy)->PollButtons(jbutton, conf.keys[pad][key]))
{ {
char str[32];
sprintf(str, "JBut %d", jbutton); sprintf(str, "JBut %d", jbutton);
gtk_entry_set_text(GTK_ENTRY(label), str); captured = true;
return; break;
} }
bool negative = false, pov = (key < 16); bool negative = false;
bool pov = (!((key == PAD_RY) || (key == PAD_LY) || (key == PAD_RX) || (key == PAD_LX)));
if (PollAxes(itjoy, pov, jbutton, negative, pkey)) if ((*itjoy)->PollAxes(pov, jbutton, negative, conf.keys[pad][key]))
{ {
char str[32];
if (pov) if (pov)
sprintf(str, "JPOV %d%s", jbutton, (negative) ? "-" : "+"); sprintf(str, "JPOV %d%s", jbutton, (negative) ? "-" : "+");
else else
sprintf(str, "JAxis %d", jbutton); sprintf(str, "JAxis %d", jbutton);
captured = true;
gtk_entry_set_text(GTK_ENTRY(label), str); break;
return;
} }
#ifdef EXPERIMENTAL_POV_CODE #ifdef EXPERIMENTAL_POV_CODE
if (PollHAT(itjoy, jbutton, direction, pkey)) if ((*itjoy)->PollHats(jbutton, direction, conf.keys[pad][key]))
{ {
char str[32];
switch (direction) switch (direction)
{ {
case SDL_HAT_UP: sprintf(str, "JPOVU-%d", jbutton); break; case SDL_HAT_UP: sprintf(str, "JPOVU-%d", jbutton); break;
@ -659,16 +510,15 @@ void OnConf_Key(GtkButton *button, gpointer user_data)
case SDL_HAT_DOWN: sprintf(str, "JPOVD-%d", jbutton); break; case SDL_HAT_DOWN: sprintf(str, "JPOVD-%d", jbutton); break;
case SDL_HAT_LEFT: sprintf(str, "JPOVL-%d", jbutton); break; case SDL_HAT_LEFT: sprintf(str, "JPOVL-%d", jbutton); break;
} }
captured = true;
gtk_entry_set_text(GTK_ENTRY(label), str); break;
return;
} }
#endif #endif
itjoy++; itjoy++;
} }
#endif
} }
gtk_entry_set_text(GTK_ENTRY(label), str);
} }
void CALLBACK PADconfigure() void CALLBACK PADconfigure()
@ -683,9 +533,7 @@ void CALLBACK PADconfigure()
Conf = create_Conf(); Conf = create_Conf();
// recreate // recreate
#ifdef JOYSTICK_SUPPORT
JoystickInfo::EnumerateJoysticks(s_vjoysticks); JoystickInfo::EnumerateJoysticks(s_vjoysticks);
#endif
s_devicecombo = lookup_widget(Conf, "joydevicescombo"); s_devicecombo = lookup_widget(Conf, "joydevicescombo");
@ -696,8 +544,8 @@ void CALLBACK PADconfigure()
// Delete everything in the vector vjoysticks. // Delete everything in the vector vjoysticks.
while (it != s_vjoysticks.end()) while (it != s_vjoysticks.end())
{ {
sprintf(str, "%d: %s - but: %d, axes: %d, pov: %d", (*it)->GetId(), (*it)->GetName().c_str(), sprintf(str, "%d: %s - but: %d, axes: %d, hats: %d", (*it)->GetId(), (*it)->GetName().c_str(),
(*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV()); (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumHats());
gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), str); gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), str);
it++; it++;
} }

View File

@ -21,10 +21,7 @@
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <pthread.h> #include <pthread.h>
#define JOYSTICK_SUPPORT
#ifdef JOYSTICK_SUPPORT
#include "joystick.h" #include "joystick.h"
#endif
#include "zeropad.h" #include "zeropad.h"

View File

@ -22,5 +22,5 @@ libZeroPAD_LDFLAGS= @SHARED_LDFLAGS@
libZeroPAD_LDFLAGS+=-Wl,-soname,@ZEROPAD_SONAME@ libZeroPAD_LDFLAGS+=-Wl,-soname,@ZEROPAD_SONAME@
libZeroPAD_LDADD=$(libZeroPAD_a_OBJECTS) libZeroPAD_LDADD=$(libZeroPAD_a_OBJECTS)
libZeroPAD_a_SOURCES = analog.cpp analog.h zeropad.cpp zeropad.h \ libZeroPAD_a_SOURCES = joystick.cpp analog.cpp analog.h zeropad.cpp zeropad.h \
Linux/gui.cpp Linux/linux.cpp Linux/joystick.cpp Linux/support.c Linux/interface.c Linux/gui.cpp Linux/linux.cpp Linux/support.c Linux/interface.c

View File

@ -126,7 +126,7 @@ namespace Analog
if (RevertPad(padvalue)) InvertPad(padvalue, i); if (RevertPad(padvalue)) InvertPad(padvalue, i);
SetPad(padvalue, i, Pad(padvalue, i) + 0x80); SetPad(padvalue, i, Pad(padvalue, i) + 0x80);
PAD_LOG("Setting pad[%d]@%d to %d from %d\n", padvalue, i, value, temp); //PAD_LOG("Setting pad[%d]@%d to %d from %d\n", padvalue, i, value, temp);
} }
int AnalogToPad(int padvalue) int AnalogToPad(int padvalue)
{ {

View File

@ -29,14 +29,14 @@ AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [debug build]),
if test "x$debug" == xyes if test "x$debug" == xyes
then then
AC_DEFINE(_DEBUG,1,[_DEBUG]) AC_DEFINE(_DEBUG,1,[_DEBUG])
CFLAGS+="-g -m32 " CFLAGS+="-g -m32 -fpic "
CXXFLAGS+="-g -m32 " CXXFLAGS+="-g -m32 -fpic "
CCASFLAGS+=" -m32 " CCASFLAGS+=" -m32 -fpic "
else else
AC_DEFINE(NDEBUG,1,[NDEBUG]) AC_DEFINE(NDEBUG,1,[NDEBUG])
CFLAGS+="-O2 -fomit-frame-pointer -m32 " CFLAGS+="-O2 -fomit-frame-pointer -m32 -fpic "
CXXFLAGS+="-O2 -fomit-frame-pointer -m32 " CXXFLAGS+="-O2 -fomit-frame-pointer -m32 -fpic "
CCASFLAGS+=" -m32 " CCASFLAGS+=" -m32 -fpic "
fi fi
AM_CONDITIONAL(DEBUGBUILD, test x$debug = xyes) AM_CONDITIONAL(DEBUGBUILD, test x$debug = xyes)
AC_MSG_RESULT($debug) AC_MSG_RESULT($debug)

View File

@ -26,6 +26,49 @@ int s_selectedpad = 0;
vector<JoystickInfo*> s_vjoysticks; vector<JoystickInfo*> s_vjoysticks;
static u32 s_bSDLInit = false; static u32 s_bSDLInit = false;
void UpdateJoysticks()
{
vector<JoystickInfo*>::iterator itjoy = s_vjoysticks.begin();
SDL_JoystickUpdate();
// Save everything in the vector s_vjoysticks.
while (itjoy != s_vjoysticks.end())
{
(*itjoy)->SaveState();
itjoy++;
}
}
const char *HatName(int value)
{
switch(value)
{
case SDL_HAT_CENTERED:
return "SDL_HAT_CENTERED";
case SDL_HAT_UP:
return "SDL_HAT_UP";
case SDL_HAT_RIGHT:
return "SDL_HAT_RIGHT";
case SDL_HAT_DOWN:
return "SDL_HAT_DOWN";
case SDL_HAT_LEFT:
return "SDL_HAT_LEFT";
case SDL_HAT_RIGHTUP:
return "SDL_HAT_RIGHTUP";
case SDL_HAT_RIGHTDOWN:
return "SDL_HAT_RIGHTDOWN";
case SDL_HAT_LEFTUP:
return "SDL_HAT_LEFTUP";
case SDL_HAT_LEFTDOWN:
return "SDL_HAT_LEFTDOWN";
default:
return "Unknown";
}
return "Unknown";
}
// opens handles to all possible joysticks // opens handles to all possible joysticks
void JoystickInfo::EnumerateJoysticks(vector<JoystickInfo*>& vjoysticks) void JoystickInfo::EnumerateJoysticks(vector<JoystickInfo*>& vjoysticks)
{ {
@ -107,14 +150,14 @@ bool JoystickInfo::Init(int id, bool bStartThread)
numaxes = SDL_JoystickNumAxes(joy); numaxes = SDL_JoystickNumAxes(joy);
numbuttons = SDL_JoystickNumButtons(joy); numbuttons = SDL_JoystickNumButtons(joy);
numpov = SDL_JoystickNumHats(joy); numhats = SDL_JoystickNumHats(joy);
devname = SDL_JoystickName(id); devname = SDL_JoystickName(id);
vaxisstate.resize(numaxes); vaxisstate.resize(numaxes);
vbutstate.resize(numbuttons); vbuttonstate.resize(numbuttons);
vpovstate.resize(numpov); vhatstate.resize(numhats);
//PAD_LOG("There are %d buttons, %d axises, and %d povs.\n", numbuttons, numaxes, numpov); //PAD_LOG("There are %d buttons, %d axises, and %d hats.\n", numbuttons, numaxes, numhats);
return true; return true;
} }
@ -146,10 +189,100 @@ void JoystickInfo::SaveState()
SetButtonState(i, SDL_JoystickGetButton(joy, i)); SetButtonState(i, SDL_JoystickGetButton(joy, i));
for (int i = 0; i < numaxes; ++i) for (int i = 0; i < numaxes; ++i)
SetAxisState(i, SDL_JoystickGetAxis(joy, i)); SetAxisState(i, SDL_JoystickGetAxis(joy, i));
for (int i = 0; i < numpov; ++i) for (int i = 0; i < numhats; ++i)
SetPOVState(i, SDL_JoystickGetHat(joy, i)); SetHatState(i, SDL_JoystickGetHat(joy, i));
} }
void JoystickInfo::TestForce() void JoystickInfo::TestForce()
{ {
} }
bool JoystickInfo::PollButtons(int &jbutton, u32 &pkey)
{
// MAKE sure to look for changes in the state!!
for (int i = 0; i < GetNumButtons(); ++i)
{
int but = SDL_JoystickGetButton(GetJoy(), i);
if (but != GetButtonState(i))
{
if (!but) // released, we don't really want this
{
SetButtonState(i, 0);
break;
}
pkey = PAD_JOYBUTTON(GetId(), i);
jbutton = i;
return true;
}
}
return false;
}
bool JoystickInfo::PollAxes(bool pov, int &jbutton, bool &negative, u32 &pkey)
{
for (int i = 0; i < GetNumAxes(); ++i)
{
int value = SDL_JoystickGetAxis(GetJoy(), i);
if (value != GetAxisState(i))
{
PAD_LOG("Change in joystick %d: %d.\n", i, value);
if (abs(value) <= GetAxisState(i)) // we don't want this
{
// released, we don't really want this
SetAxisState(i, value);
break;
}
if (abs(value) > 0x3fff)
{
jbutton = i;
if (pov)
{
negative = (value < 0);
pkey = PAD_POV(GetId(), negative, i);
}
else // axis
{
pkey = PAD_JOYSTICK(GetId(), i);
}
return true;
}
}
}
return false;
}
bool JoystickInfo::PollHats(int &jbutton, int &dir, u32 &pkey)
{
#ifdef EXPERIMENTAL_POV_CODE
for (int i = 0; i < GetNumHats(); ++i)
{
int value = SDL_JoystickGetHat(GetJoy(), i);
if (value != SDL_HAT_CENTERED)
{
switch (value)
{
case SDL_HAT_UP:
case SDL_HAT_RIGHT:
case SDL_HAT_DOWN:
case SDL_HAT_LEFT:
pkey = PAD_HAT(GetId(), value, i);
jbutton = i;
dir = value;
PAD_LOG("Hat Pressed!");
return true;
default:
break;
}
}
}
#endif
return false;
}

View File

@ -41,6 +41,12 @@ class JoystickInfo
void TestForce(); void TestForce();
bool PollButtons(int &jbutton, u32 &pkey);
bool PollAxes(bool pov, int &jbutton, bool &negative, u32 &pkey);
bool PollHats(int &jbutton, int &dir, u32 &pkey);
const string& GetName() const string& GetName()
{ {
return devname; return devname;
@ -56,9 +62,9 @@ class JoystickInfo
return numaxes; return numaxes;
} }
int GetNumPOV() int GetNumHats()
{ {
return numpov; return numhats;
} }
int GetId() int GetId()
@ -80,7 +86,7 @@ class JoystickInfo
int GetButtonState(int i) int GetButtonState(int i)
{ {
return vbutstate[i]; return vbuttonstate[i];
} }
int GetAxisState(int i) int GetAxisState(int i)
@ -88,15 +94,15 @@ class JoystickInfo
return vaxisstate[i]; return vaxisstate[i];
} }
int GetPOVState(int i) int GetHatState(int i)
{ {
//PAD_LOG("Getting POV State of %d.\n", i); //PAD_LOG("Getting POV State of %d.\n", i);
return vpovstate[i]; return vhatstate[i];
} }
void SetButtonState(int i, int state) void SetButtonState(int i, int state)
{ {
vbutstate[i] = state; vbuttonstate[i] = state;
} }
void SetAxisState(int i, int value) void SetAxisState(int i, int value)
@ -104,10 +110,10 @@ class JoystickInfo
vaxisstate[i] = value; vaxisstate[i] = value;
} }
void SetPOVState(int i, int value) void SetHatState(int i, int value)
{ {
//PAD_LOG("We should set %d to %d.\n", i, value); //PAD_LOG("We should set %d to %d.\n", i, value);
vpovstate[i] = value; vhatstate[i] = value;
} }
SDL_Joystick* GetJoy() SDL_Joystick* GetJoy()
@ -119,11 +125,11 @@ class JoystickInfo
string devname; // pretty device name string devname; // pretty device name
int _id; int _id;
int numbuttons, numaxes, numpov; int numbuttons, numaxes, numhats;
int axisrange, deadzone; int axisrange, deadzone;
int pad; int pad;
vector<int> vbutstate, vaxisstate, vpovstate; vector<int> vbuttonstate, vaxisstate, vhatstate;
SDL_Joystick* joy; SDL_Joystick* joy;
}; };
@ -131,4 +137,6 @@ class JoystickInfo
extern int s_selectedpad; extern int s_selectedpad;
extern vector<JoystickInfo*> s_vjoysticks; extern vector<JoystickInfo*> s_vjoysticks;
extern void UpdateJoysticks();
extern const char *HatName(int value);
#endif #endif