Removed balls from the joystick API

They were only used by one joystick decades ago, so removing them for SDL3

Fixes https://github.com/libsdl-org/SDL/issues/6766
This commit is contained in:
Sam Lantinga
2022-12-05 12:47:48 -08:00
parent 75f1eb9216
commit fcafe40948
22 changed files with 14 additions and 257 deletions

View File

@@ -240,7 +240,7 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
JNIEnv *env, jclass jcls,
jint device_id, jstring device_name, jstring device_desc, jint vendor_id, jint product_id,
jboolean is_accelerometer, jint button_mask, jint naxes, jint nhats, jint nballs);
jboolean is_accelerometer, jint button_mask, jint naxes, jint nhats);
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
JNIEnv *env, jclass jcls,
@@ -939,13 +939,13 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
JNIEnv *env, jclass jcls,
jint device_id, jstring device_name, jstring device_desc,
jint vendor_id, jint product_id, jboolean is_accelerometer,
jint button_mask, jint naxes, jint nhats, jint nballs)
jint button_mask, jint naxes, jint nhats)
{
int retval;
const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
const char *desc = (*env)->GetStringUTFChars(env, device_desc, NULL);
retval = Android_AddJoystick(device_id, name, desc, vendor_id, product_id, is_accelerometer ? SDL_TRUE : SDL_FALSE, button_mask, naxes, nhats, nballs);
retval = Android_AddJoystick(device_id, name, desc, vendor_id, product_id, is_accelerometer ? SDL_TRUE : SDL_FALSE, button_mask, naxes, nhats);
(*env)->ReleaseStringUTFChars(env, device_name, name);
(*env)->ReleaseStringUTFChars(env, device_desc, desc);

View File

@@ -746,7 +746,6 @@ SDL3_0.0.0 {
SDL_JoystickGetAttached;
SDL_JoystickInstanceID;
SDL_JoystickNumAxes;
SDL_JoystickNumBalls;
SDL_JoystickNumHats;
SDL_JoystickNumButtons;
SDL_JoystickUpdate;
@@ -754,7 +753,6 @@ SDL3_0.0.0 {
SDL_JoystickGetAxis;
SDL_JoystickGetAxisInitialState;
SDL_JoystickGetHat;
SDL_JoystickGetBall;
SDL_JoystickGetButton;
SDL_JoystickRumble;
SDL_JoystickRumbleTriggers;

View File

@@ -202,14 +202,12 @@
#define SDL_JoystickGetAttached SDL_JoystickGetAttached_REAL
#define SDL_JoystickInstanceID SDL_JoystickInstanceID_REAL
#define SDL_JoystickNumAxes SDL_JoystickNumAxes_REAL
#define SDL_JoystickNumBalls SDL_JoystickNumBalls_REAL
#define SDL_JoystickNumHats SDL_JoystickNumHats_REAL
#define SDL_JoystickNumButtons SDL_JoystickNumButtons_REAL
#define SDL_JoystickUpdate SDL_JoystickUpdate_REAL
#define SDL_JoystickEventState SDL_JoystickEventState_REAL
#define SDL_JoystickGetAxis SDL_JoystickGetAxis_REAL
#define SDL_JoystickGetHat SDL_JoystickGetHat_REAL
#define SDL_JoystickGetBall SDL_JoystickGetBall_REAL
#define SDL_JoystickGetButton SDL_JoystickGetButton_REAL
#define SDL_JoystickClose SDL_JoystickClose_REAL
#define SDL_GetKeyboardFocus SDL_GetKeyboardFocus_REAL

View File

@@ -229,14 +229,12 @@ SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetGUIDFromString,(const char *a),(
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickGetAttached,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_JoystickInstanceID,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_JoystickNumAxes,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_JoystickNumBalls,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_JoystickNumHats,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_JoystickNumButtons,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_JoystickUpdate,(void),(),)
SDL_DYNAPI_PROC(int,SDL_JoystickEventState,(int a),(a),return)
SDL_DYNAPI_PROC(Sint16,SDL_JoystickGetAxis,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(Uint8,SDL_JoystickGetHat,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_JoystickGetBall,(SDL_Joystick *a, int b, int *c, int *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(Uint8,SDL_JoystickGetButton,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_JoystickClose,(SDL_Joystick *a),(a),)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)

View File

@@ -360,12 +360,6 @@ static void SDL_LogEvent(const SDL_Event *event)
(uint)event->jaxis.axis, (int)event->jaxis.value);
break;
SDL_EVENT_CASE(SDL_JOYBALLMOTION)
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
(uint)event->jball.timestamp, (int)event->jball.which,
(uint)event->jball.ball, (int)event->jball.xrel, (int)event->jball.yrel);
break;
SDL_EVENT_CASE(SDL_JOYHATMOTION)
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d hat=%u value=%u)",
(uint)event->jhat.timestamp, (int)event->jhat.which,

View File

@@ -528,13 +528,10 @@ SDL_JoystickOpen(int device_index)
if (joystick->nhats > 0) {
joystick->hats = (Uint8 *)SDL_calloc(joystick->nhats, sizeof(Uint8));
}
if (joystick->nballs > 0) {
joystick->balls = (struct balldelta *)SDL_calloc(joystick->nballs, sizeof(*joystick->balls));
}
if (joystick->nbuttons > 0) {
joystick->buttons = (Uint8 *)SDL_calloc(joystick->nbuttons, sizeof(Uint8));
}
if (((joystick->naxes > 0) && !joystick->axes) || ((joystick->nhats > 0) && !joystick->hats) || ((joystick->nballs > 0) && !joystick->balls) || ((joystick->nbuttons > 0) && !joystick->buttons)) {
if (((joystick->naxes > 0) && !joystick->axes) || ((joystick->nhats > 0) && !joystick->hats) || ((joystick->nbuttons > 0) && !joystick->buttons)) {
SDL_OutOfMemory();
SDL_JoystickClose(joystick);
SDL_UnlockJoysticks();
@@ -719,16 +716,6 @@ int SDL_JoystickNumHats(SDL_Joystick *joystick)
return joystick->nhats;
}
/*
* Get the number of trackballs on a joystick
*/
int SDL_JoystickNumBalls(SDL_Joystick *joystick)
{
CHECK_JOYSTICK_MAGIC(joystick, -1);
return joystick->nballs;
}
/*
* Get the number of buttons on a joystick
*/
@@ -794,31 +781,6 @@ Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
return state;
}
/*
* Get the ball axis change since the last poll
*/
int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
{
int retval;
CHECK_JOYSTICK_MAGIC(joystick, -1);
retval = 0;
if (ball < joystick->nballs) {
if (dx) {
*dx = joystick->balls[ball].dx;
}
if (dy) {
*dy = joystick->balls[ball].dy;
}
joystick->balls[ball].dx = 0;
joystick->balls[ball].dy = 0;
} else {
return SDL_SetError("Joystick only has %d balls", joystick->nballs);
}
return retval;
}
/*
* Get the current state of a button on a joystick
*/
@@ -1160,7 +1122,6 @@ void SDL_JoystickClose(SDL_Joystick *joystick)
/* Free the data associated with this joystick */
SDL_free(joystick->axes);
SDL_free(joystick->hats);
SDL_free(joystick->balls);
SDL_free(joystick->buttons);
for (i = 0; i < joystick->ntouchpads; i++) {
SDL_JoystickTouchpadInfo *touchpad = &joystick->touchpads[i];
@@ -1563,46 +1524,6 @@ int SDL_PrivateJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat,
return posted;
}
int SDL_PrivateJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball,
Sint16 xrel, Sint16 yrel)
{
int posted;
SDL_AssertJoysticksLocked();
CHECK_JOYSTICK_MAGIC(joystick, 0);
/* Make sure we're not getting garbage events */
if (ball >= joystick->nballs) {
return 0;
}
/* We ignore events if we don't have keyboard focus. */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
return 0;
}
/* Update internal mouse state */
joystick->balls[ball].dx += xrel;
joystick->balls[ball].dy += yrel;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_JOYBALLMOTION;
event.common.timestamp = timestamp;
event.jball.which = joystick->instance_id;
event.jball.ball = ball;
event.jball.xrel = xrel;
event.jball.yrel = yrel;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
int SDL_PrivateJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state)
{
int posted;
@@ -1720,7 +1641,7 @@ int SDL_JoystickEventState(int state)
return SDL_DISABLE;
#else
const Uint32 event_list[] = {
SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
SDL_JOYAXISMOTION, SDL_JOYHATMOTION,
SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED,
SDL_JOYBATTERYUPDATED
};

View File

@@ -153,8 +153,6 @@ extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick);
extern int SDL_PrivateJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick,
Uint8 axis, Sint16 value);
extern int SDL_PrivateJoystickBall(Uint64 timestamp, SDL_Joystick *joystick,
Uint8 ball, Sint16 xrel, Sint16 yrel);
extern int SDL_PrivateJoystickHat(Uint64 timestamp, SDL_Joystick *joystick,
Uint8 hat, Uint8 value);
extern int SDL_PrivateJoystickButton(Uint64 timestamp, SDL_Joystick *joystick,

View File

@@ -82,13 +82,6 @@ struct _SDL_Joystick
int nhats; /* Number of hats on the joystick */
Uint8 *hats; /* Current hat states */
int nballs; /* Number of trackballs on the joystick */
struct balldelta
{
int dx;
int dy;
} *balls; /* Current ball motion deltas */
int nbuttons; /* Number of buttons on the joystick */
Uint8 *buttons; /* Current button states */

View File

@@ -297,7 +297,7 @@ int Android_OnHat(int device_id, int hat_id, int x, int y)
return -1;
}
int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, SDL_bool is_accelerometer, int button_mask, int naxes, int nhats, int nballs)
int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, SDL_bool is_accelerometer, int button_mask, int naxes, int nhats)
{
SDL_joylist_item *item;
SDL_JoystickGUID guid;
@@ -389,7 +389,6 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v
}
item->naxes = naxes;
item->nhats = nhats;
item->nballs = nballs;
item->device_instance = SDL_GetNextJoystickInstanceID();
if (SDL_joylist_tail == NULL) {
SDL_joylist = SDL_joylist_tail = item;
@@ -478,7 +477,7 @@ static int ANDROID_JoystickInit(void)
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
/* Default behavior, accelerometer as joystick */
Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, ANDROID_ACCELEROMETER_NAME, 0, 0, SDL_TRUE, 0, 3, 0, 0);
Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, ANDROID_ACCELEROMETER_NAME, 0, 0, SDL_TRUE, 0, 3, 0);
}
return 0;
}
@@ -588,7 +587,6 @@ static int ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->hwdata = (struct joystick_hwdata *)item;
item->joystick = joystick;
joystick->nhats = item->nhats;
joystick->nballs = item->nballs;
joystick->nbuttons = item->nbuttons;
joystick->naxes = item->naxes;

View File

@@ -32,7 +32,7 @@ extern int Android_OnPadDown(int device_id, int keycode);
extern int Android_OnPadUp(int device_id, int keycode);
extern int Android_OnJoy(int device_id, int axisnum, float value);
extern int Android_OnHat(int device_id, int hat_id, int x, int y);
extern int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, SDL_bool is_accelerometer, int button_mask, int naxes, int nhats, int nballs);
extern int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, SDL_bool is_accelerometer, int button_mask, int naxes, int nhats);
extern int Android_RemoveJoystick(int device_id);
/* A linked list of available joysticks */
@@ -44,7 +44,7 @@ typedef struct SDL_joylist_item
SDL_JoystickGUID guid;
SDL_bool is_accelerometer;
SDL_Joystick *joystick;
int nbuttons, naxes, nhats, nballs;
int nbuttons, naxes, nhats;
int dpad_state;
struct SDL_joylist_item *next;

View File

@@ -767,7 +767,6 @@ static int IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes = device->naxes;
joystick->nhats = device->nhats;
joystick->nbuttons = device->nbuttons;
joystick->nballs = 0;
if (device->has_dualshock_touchpad) {
SDL_PrivateJoystickAddTouchpad(joystick, 2);

View File

@@ -750,7 +750,6 @@ static int DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes = device->axes;
joystick->nhats = device->hats;
joystick->nballs = 0;
joystick->nbuttons = device->buttons;
return 0;
}

View File

@@ -309,7 +309,6 @@ static int EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
/* HTML5 Gamepad API doesn't say anything about these */
joystick->nhats = 0;
joystick->nballs = 0;
joystick->nbuttons = item->nbuttons;
joystick->naxes = item->naxes;

View File

@@ -861,23 +861,6 @@ static int allocate_hatdata(SDL_Joystick *joystick)
return 0;
}
static int allocate_balldata(SDL_Joystick *joystick)
{
int i;
joystick->hwdata->balls =
(struct hwdata_ball *)SDL_malloc(joystick->nballs *
sizeof(struct hwdata_ball));
if (joystick->hwdata->balls == NULL) {
return -1;
}
for (i = 0; i < joystick->nballs; ++i) {
joystick->hwdata->balls[i].axis[0] = 0;
joystick->hwdata->balls[i].axis[1] = 0;
}
return 0;
}
static SDL_bool GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo *absinfo_y)
{
/* A "hat" is assumed to be a digital input with at most 9 possible states
@@ -1029,9 +1012,6 @@ static void ConfigJoystick(SDL_Joystick *joystick, int fd)
++joystick->naxes;
}
}
if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
++joystick->nballs;
}
} else if ((ioctl(fd, JSIOCGBUTTONS, &key_pam_size, sizeof(key_pam_size)) >= 0) &&
(ioctl(fd, JSIOCGAXES, &abs_pam_size, sizeof(abs_pam_size)) >= 0)) {
@@ -1105,11 +1085,6 @@ static void ConfigJoystick(SDL_Joystick *joystick, int fd)
joystick->nhats = 0;
}
}
if (joystick->nballs > 0) {
if (allocate_balldata(joystick) < 0) {
joystick->nballs = 0;
}
}
if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffbit)), ffbit) >= 0) {
if (test_bit(FF_RUMBLE, ffbit)) {
@@ -1320,11 +1295,6 @@ static void HandleHat(Uint64 timestamp, SDL_Joystick *stick, int hatidx, int axi
}
}
static void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value)
{
stick->hwdata->balls[ball].axis[axis] += value;
}
static int AxisCorrect(SDL_Joystick *joystick, int which, int value)
{
struct axis_correct *correct;
@@ -1411,8 +1381,6 @@ static void PollAllValues(Uint64 timestamp, SDL_Joystick *joystick)
}
}
}
/* Joyballs are relative input, so there's no poll state. Events only! */
}
static void HandleInputEvents(SDL_Joystick *joystick)
@@ -1468,17 +1436,6 @@ static void HandleInputEvents(SDL_Joystick *joystick)
break;
}
break;
case EV_REL:
switch (code) {
case REL_X:
case REL_Y:
code -= REL_X;
HandleBall(joystick, code / 2, code % 2, event->value);
break;
default:
break;
}
break;
case EV_SYN:
switch (code) {
case SYN_DROPPED:
@@ -1554,8 +1511,6 @@ static void HandleClassicEvents(SDL_Joystick *joystick)
static void LINUX_JoystickUpdate(SDL_Joystick *joystick)
{
int i;
if (joystick->hwdata->m_bSteamController) {
SDL_UpdateSteamController(joystick);
return;
@@ -1566,19 +1521,6 @@ static void LINUX_JoystickUpdate(SDL_Joystick *joystick)
} else {
HandleInputEvents(joystick);
}
/* Deliver ball motion updates */
for (i = 0; i < joystick->nballs; ++i) {
int xrel, yrel;
xrel = joystick->hwdata->balls[i].axis[0];
yrel = joystick->hwdata->balls[i].axis[1];
if (xrel || yrel) {
joystick->hwdata->balls[i].axis[0] = 0;
joystick->hwdata->balls[i].axis[1] = 0;
SDL_PrivateJoystickBall(0, joystick, (Uint8)i, xrel, yrel);
}
}
}
/* Function to close a joystick after use */
@@ -1598,7 +1540,6 @@ static void LINUX_JoystickClose(SDL_Joystick *joystick)
SDL_free(joystick->hwdata->key_pam);
SDL_free(joystick->hwdata->abs_pam);
SDL_free(joystick->hwdata->hats);
SDL_free(joystick->hwdata->balls);
SDL_free(joystick->hwdata->fname);
SDL_free(joystick->hwdata);
}

View File

@@ -44,11 +44,6 @@ struct joystick_hwdata
{
int axis[2];
} *hats;
/* The current Linux joystick driver maps balls to two axes */
struct hwdata_ball
{
int axis[2];
} *balls;
/* Support for the Linux 2.4 unified input interface */
Uint8 key_map[KEY_MAX];

View File

@@ -1587,11 +1587,6 @@ static void SDLTest_PrintEvent(SDL_Event *event)
SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 " removed",
event->jdevice.which);
break;
case SDL_JOYBALLMOTION:
SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 ": ball %d moved by %d,%d",
event->jball.which, event->jball.ball, event->jball.xrel,
event->jball.yrel);
break;
case SDL_JOYHATMOTION:
{
const char *position = "UNKNOWN";