- Now supports Wiimotes (with "WiiJi" application running)

This commit is contained in:
Rob Pearce 2008-12-25 06:58:26 +00:00
parent 30ec68f70d
commit 3f6825e627
2 changed files with 66 additions and 4 deletions

5
defs.h
View File

@ -13,6 +13,11 @@
/* Macros */ /* Macros */
//#define OPENGL //#define OPENGL
// joysticks
#define J_PLAYSTATION 1
#define J_WII 2
#define J_OTHER 3
// sound channel numbers // sound channel numbers
#define CH_LASTCHANNEL 21 #define CH_LASTCHANNEL 21
#define CH_HURRYUP 20 #define CH_HURRYUP 20

65
rc.c
View File

@ -55,8 +55,11 @@ int gothiscore = -1;
int gothiscore2 = -1; int gothiscore2 = -1;
int joytest = B_FALSE;
int havejoysticks; int havejoysticks;
int joybuttons[2]; int joybuttons[2];
const char *joyname[2];
int joytype[2];
int joyanalog[2]; int joyanalog[2];
int joythresh[2]; int joythresh[2];
SDL_Joystick *joy[2]; SDL_Joystick *joy[2];
@ -236,11 +239,14 @@ int main (int argc, char **argv) {
skipto = atoi(argv[i]); skipto = atoi(argv[i]);
printf("Skipping to level %d.\n",skipto); printf("Skipping to level %d.\n",skipto);
} else if (!strcmp(argv[i], "-1")) { } else if (!strcmp(argv[i], "-1")) {
printf("1up added."); printf("1up added.\n");
force1up = B_TRUE; force1up = B_TRUE;
} else if (!strcmp(argv[i], "-2")) { } else if (!strcmp(argv[i], "-2")) {
printf("2up added."); printf("2up added.\n");
force2up = B_TRUE; force2up = B_TRUE;
} else if (!strcmp(argv[i], "-jt")) {
printf("Joystick test mode enabled.\n");
joytest = B_TRUE;
} else if (!strcmp(argv[i], "-hs")) { } else if (!strcmp(argv[i], "-hs")) {
if (++i >= argc) { if (++i >= argc) {
printf("Missing hiscore server name.\n"); printf("Missing hiscore server name.\n");
@ -295,6 +301,42 @@ int main (int argc, char **argv) {
atexit(cleanup); atexit(cleanup);
if (joytest) {
if (havejoysticks) {
int done = B_FALSE;
SDL_Event event;
printf("Joystick test mode\n");
printf("------------------\n\n");
while (!done) {
/* check for key releases */
SDL_PumpEvents();
while (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
done = B_TRUE;
}
} else if (event.type == SDL_JOYBUTTONUP) {
printf("Joy %d: Button %d pressed.\n",event.jbutton.which, event.jbutton.button);
} else if (event.type == SDL_JOYAXISMOTION) {
int j,jx,jy;
j = event.jaxis.which;
jx = SDL_JoystickGetAxis(joy[j],0);
jy = SDL_JoystickGetAxis(joy[j],1);
printf("Joy %d: Moved ",j);
if (jy <= -6000) printf("UP\n");
if (jy >= 6000) printf("DOWN\n");
if (jx <= -6000) printf("LEFT\n");
if (jx >= 6000) printf("RIGHT\n");
}
}
}
} else {
printf("ERROR: no joysticks found.\n");
}
return 0;
}
if (loadimagesets()) { if (loadimagesets()) {
printf("Error loading images.\n"); printf("Error loading images.\n");
return 1; return 1;
@ -8747,6 +8789,7 @@ void usage(void) {
printf(" -l xx Skip to level xx.\n"); printf(" -l xx Skip to level xx.\n");
printf(" -hs xx Set hiscore_server to http://xx.\n"); printf(" -hs xx Set hiscore_server to http://xx.\n");
printf(" -hp xx Connect to hiscore_server on port xx.\n"); printf(" -hp xx Connect to hiscore_server on port xx.\n");
printf(" -js Joystick test mode.\n");
printf("\n"); printf("\n");
} }
@ -9587,11 +9630,23 @@ void initsdl(void) {
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
joy[i] = SDL_JoystickOpen(i); joy[i] = SDL_JoystickOpen(i);
if (joy[i]) { if (joy[i]) {
printf("Joystick #%d found.\n",i); joyname[i] = SDL_JoystickName(i);
printf("Joystick #%d found: %s",i, joyname[i]);
if (strstr(joyname[i], "aystati")) {
joytype[i] = J_PLAYSTATION;
printf(" (PS3 controller)\n");
} else if (strstr(joyname[i], "Wii")) {
joytype[i] = J_WII;
printf(" (Wiimote)\n");
} else {
joytype[i] = J_OTHER;
printf(" (Generic joystick)\n");
}
havejoysticks++; havejoysticks++;
joybuttons[i] = SDL_JoystickNumButtons(joy[i]); joybuttons[i] = SDL_JoystickNumButtons(joy[i]);
printf("Joy %d has %d buttons\n",i,joybuttons[i]); printf("Joy %d has %d buttons\n",i,joybuttons[i]);
if (joybuttons[i] >= 15) { // ps3 controller? if (joytype[i] == J_PLAYSTATION) {
joyanalog[i] = B_TRUE; joyanalog[i] = B_TRUE;
} else { } else {
joyanalog[i] = B_FALSE; joyanalog[i] = B_FALSE;
@ -12685,6 +12740,8 @@ void doplayermovement(sprite_t *pl) {
if (keydown(pnum,KEY_SHOOT)) { if (keydown(pnum,KEY_SHOOT)) {
if (!havejoysticks && keydown(pnum,KEY_DOWN)) { if (!havejoysticks && keydown(pnum,KEY_DOWN)) {
trytoslam(pl); trytoslam(pl);
} else if (havejoysticks && (joytype[pnum] == J_WII) && keydown(pnum, KEY_DOWN)) {
trytoslam(pl);
} else { } else {
trytoshoot(pl); trytoshoot(pl);
} }