X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fjoystick.c;h=4a1bc7d5074fcdcbdd0df41599eb72544802cc3e;hb=023dd1a5d064b6a2fbfb8145af8c61261ea53886;hp=06ac654162e43f38da9f24b483d8d9de64db2691;hpb=c9433eab5c4317ed4f89164b386a7d33562e29be;p=rocksndiamonds.git diff --git a/src/libgame/joystick.c b/src/libgame/joystick.c index 06ac6541..4a1bc7d5 100644 --- a/src/libgame/joystick.c +++ b/src/libgame/joystick.c @@ -1,15 +1,13 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1995-2002 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* joystick.c * -***********************************************************/ +// ============================================================================ +// Artsoft Retro-Game Library +// ---------------------------------------------------------------------------- +// (c) 1995-2014 by Artsoft Entertainment +// Holger Schemel +// info@artsoft.org +// https://www.artsoft.org/ +// ---------------------------------------------------------------------------- +// joystick.c +// ============================================================================ #if defined(PLATFORM_FREEBSD) #include @@ -19,91 +17,14 @@ #include "misc.h" -/* ========================================================================= */ -/* platform dependant joystick functions */ -/* ========================================================================= */ - -#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL) -void UnixInitJoysticks() -{ - int i; - - for (i=0; i 0 && name[j - 1] == ' ') + j--; + + name[j] = '\0'; + + return name; +} + static int JoystickPositionPercent(int center, int border, int actual) { - long range, position; + int range, position; int percent; if (border < center && actual > center) @@ -219,12 +173,12 @@ static int JoystickPositionPercent(int center, int border, int actual) return percent; } -void CheckJoystickData() +void CheckJoystickData(void) { int i; int distance = 100; - for(i=0; i= setup.input[i].joy.xmiddle) setup.input[i].joy.xleft = setup.input[i].joy.xmiddle - distance; @@ -238,26 +192,30 @@ void CheckJoystickData() } } -int Joystick(int player_nr) +int JoystickExt(int player_nr, boolean use_as_joystick_nr) { - int joystick_fd = joystick.fd[player_nr]; + int joystick_nr = joystick.nr[player_nr]; int js_x, js_y; boolean js_b1, js_b2; int left, right, up, down; int result = JOY_NO_ACTION; + if (use_as_joystick_nr) + joystick_nr = player_nr; + if (joystick.status != JOYSTICK_ACTIVATED) return JOY_NO_ACTION; - if (joystick_fd < 0 || !setup.input[player_nr].use_joystick) + if (joystick_nr < 0) return JOY_NO_ACTION; - if (!ReadJoystick(joystick_fd, &js_x, &js_y, &js_b1, &js_b2)) + if (!ReadJoystick(joystick_nr, &js_x, &js_y, &js_b1, &js_b2)) { - Error(ERR_WARN, "cannot read joystick device '%s'", - setup.input[player_nr].joy.device_name); + Warn("cannot read joystick device '%s'", + setup.input[player_nr].joy.device_name); joystick.status = JOYSTICK_NOT_AVAILABLE; + return JOY_NO_ACTION; } @@ -287,10 +245,15 @@ int Joystick(int player_nr) return result; } -int JoystickButton(int player_nr) +int Joystick(int player_nr) +{ + return JoystickExt(player_nr, FALSE); +} + +static int JoystickButtonExt(int player_nr, boolean use_as_joystick_nr) { static int last_joy_button[MAX_PLAYERS] = { 0, 0, 0, 0 }; - int joy_button = (Joystick(player_nr) & JOY_BUTTON); + int joy_button = (JoystickExt(player_nr, use_as_joystick_nr) & JOY_BUTTON); int result; if (joy_button) @@ -312,25 +275,30 @@ int JoystickButton(int player_nr) return result; } -int AnyJoystick() +int JoystickButton(int player_nr) +{ + return JoystickButtonExt(player_nr, FALSE); +} + +int AnyJoystick(void) { int i; int result = 0; - for (i=0; i