X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fjoystick.c;h=b21d682e3de4a33586984220baeac30e6a8e6499;hb=e6bde4abb3952d4689917ce66d6bde79cd8df7fc;hp=00d497f352b1cf938cdc726ea60277e02da9ab65;hpb=d5b2ac0f473b0868014826e2c6488c72c79008f1;p=rocksndiamonds.git diff --git a/src/joystick.c b/src/joystick.c index 00d497f3..b21d682e 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -11,14 +11,99 @@ * joystick.c * ***********************************************************/ -#ifdef __FreeBSD__ +#if defined(PLATFORM_FREEBSD) #include #endif +#include "libgame/libgame.h" + #include "joystick.h" -#include "misc.h" -#ifndef MSDOS +#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0 +#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1 + +void translate_joyname(int *joysymbol, char **name, int mode) +{ + static struct + { + int joysymbol; + char *name; + } translate_joy[] = + { + { JOY_LEFT, "joystick_left" }, + { JOY_RIGHT, "joystick_right" }, + { JOY_UP, "joystick_up" }, + { JOY_DOWN, "joystick_down" }, + { JOY_BUTTON_1, "joystick_button_1" }, + { JOY_BUTTON_2, "joystick_button_2" }, + }; + + int i; + + if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME) + { + *name = "[undefined]"; + + for (i=0; i<6; i++) + { + if (*joysymbol == translate_joy[i].joysymbol) + { + *name = translate_joy[i].name; + break; + } + } + } + else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL) + { + *joysymbol = 0; + + for (i=0; i<6; i++) + { + if (strcmp(*name, translate_joy[i].name) == 0) + { + *joysymbol = translate_joy[i].joysymbol; + break; + } + } + } +} + +char *getJoyNameFromJoySymbol(int joysymbol) +{ + char *name; + + translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME); + return name; +} + +int getJoySymbolFromJoyName(char *name) +{ + int joysymbol; + + translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL); + return joysymbol; +} + +int getJoystickNrFromDeviceName(char *device_name) +{ + char c; + int joystick_nr = 0; + + if (device_name == NULL || device_name[0] == '\0') + return 0; + + c = device_name[strlen(device_name) - 1]; + + if (c >= '0' && c <= '9') + joystick_nr = (int)(c - '0'); + + if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS) + joystick_nr = 0; + + return joystick_nr; +} + +#if !defined(PLATFORM_MSDOS) static int JoystickPosition(int middle, int margin, int actual) { long range, pos; @@ -40,7 +125,7 @@ static int JoystickPosition(int middle, int margin, int actual) } #endif -#ifdef USE_SDL_JOYSTICK +#if defined(TARGET_SDL) static SDL_Joystick *sdl_joystick[MAX_PLAYERS] = { NULL, NULL, NULL, NULL }; static int sdl_js_axis[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; @@ -205,7 +290,7 @@ int Joystick(int player_nr) return result; } -#else /* !USE_SDL_JOYSTICK */ +#else /* !TARGET_SDL */ void CheckJoystickData() { @@ -231,7 +316,7 @@ void CheckJoystickData() } } -#ifndef MSDOS +#if defined(PLATFORM_UNIX) int Joystick(int player_nr) { #ifdef __FreeBSD__ @@ -304,7 +389,7 @@ int Joystick(int player_nr) return result; } -#else /* MSDOS */ +#else /* PLATFORM_MSDOS */ /* allegro global variables for joystick control */ extern int num_joysticks; @@ -325,7 +410,7 @@ int Joystick(int player_nr) return 0; /* the allegro global variable 'num_joysticks' contains the number - of joysticks found at initialization under MSDOS / Windows */ + of joysticks found at initialization under MS-DOS / Windows */ #if 0 if (joystick_nr >= num_joysticks || !setup.input[player_nr].use_joystick) @@ -361,9 +446,9 @@ int Joystick(int player_nr) return result; } -#endif /* MSDOS */ +#endif /* PLATFORM_MSDOS */ -#endif /* !USE_SDL_JOYSTICK */ +#endif /* !TARGET_SDL */ int JoystickButton(int player_nr) {