From 3f6825e62711dab1553d238fb253f6881a0d4af1 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Thu, 25 Dec 2008 06:58:26 +0000 Subject: [PATCH] - Now supports Wiimotes (with "WiiJi" application running) --- defs.h | 5 +++++ rc.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/defs.h b/defs.h index 082ef96..50e922b 100644 --- a/defs.h +++ b/defs.h @@ -13,6 +13,11 @@ /* Macros */ //#define OPENGL +// joysticks +#define J_PLAYSTATION 1 +#define J_WII 2 +#define J_OTHER 3 + // sound channel numbers #define CH_LASTCHANNEL 21 #define CH_HURRYUP 20 diff --git a/rc.c b/rc.c index c69f8a8..d40c736 100644 --- a/rc.c +++ b/rc.c @@ -55,8 +55,11 @@ int gothiscore = -1; int gothiscore2 = -1; +int joytest = B_FALSE; int havejoysticks; int joybuttons[2]; +const char *joyname[2]; +int joytype[2]; int joyanalog[2]; int joythresh[2]; SDL_Joystick *joy[2]; @@ -236,11 +239,14 @@ int main (int argc, char **argv) { skipto = atoi(argv[i]); printf("Skipping to level %d.\n",skipto); } else if (!strcmp(argv[i], "-1")) { - printf("1up added."); + printf("1up added.\n"); force1up = B_TRUE; } else if (!strcmp(argv[i], "-2")) { - printf("2up added."); + printf("2up added.\n"); force2up = B_TRUE; + } else if (!strcmp(argv[i], "-jt")) { + printf("Joystick test mode enabled.\n"); + joytest = B_TRUE; } else if (!strcmp(argv[i], "-hs")) { if (++i >= argc) { printf("Missing hiscore server name.\n"); @@ -295,6 +301,42 @@ int main (int argc, char **argv) { 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()) { printf("Error loading images.\n"); return 1; @@ -8747,6 +8789,7 @@ void usage(void) { printf(" -l xx Skip to level xx.\n"); printf(" -hs xx Set hiscore_server to http://xx.\n"); printf(" -hp xx Connect to hiscore_server on port xx.\n"); + printf(" -js Joystick test mode.\n"); printf("\n"); } @@ -9587,11 +9630,23 @@ void initsdl(void) { for (i = 0; i < 2; i++) { joy[i] = SDL_JoystickOpen(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++; joybuttons[i] = SDL_JoystickNumButtons(joy[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; } else { joyanalog[i] = B_FALSE; @@ -12685,6 +12740,8 @@ void doplayermovement(sprite_t *pl) { if (keydown(pnum,KEY_SHOOT)) { if (!havejoysticks && keydown(pnum,KEY_DOWN)) { trytoslam(pl); + } else if (havejoysticks && (joytype[pnum] == J_WII) && keydown(pnum, KEY_DOWN)) { + trytoslam(pl); } else { trytoshoot(pl); }