From 7753d4cba5d4066061048bed747155c7a912ba40 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Thu, 10 Jul 2008 17:16:11 +0000 Subject: [PATCH] Added SDL_HapticNumEffectsPlaying(). --- include/SDL_haptic.h | 15 +++++++++++++++ src/haptic/SDL_haptic.c | 15 +++++++++++++++ src/haptic/SDL_syshaptic.h | 1 + src/haptic/linux/SDL_syshaptic.c | 1 + 4 files changed, 32 insertions(+) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 5a1393e59..b9e6d1e45 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -740,10 +740,25 @@ extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic); * \return The number of effects the haptic device can store or * -1 on error. * + * \sa SDL_HapticNumEffectsPlaying * \sa SDL_HapticQuery */ extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic); +/** + * \fn int SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic) + * + * \brief Returns the number of effects a haptic device can play at the same time. + * + * \param haptic The haptic device to query maximum playing effect.s + * \return The number of effects the haptic device can play at the same time + * or -1 on error. + * + * \sa SDL_HapticNumEffects + * \sa SDL_HapticQuery + */ +extern DECLSPEC int SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic); + /** * \fn unsigned int SDL_HapticQuery(SDL_Haptic * haptic) * diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index fbf2f76ad..6a9e255fa 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -356,6 +356,21 @@ SDL_HapticNumEffects(SDL_Haptic * haptic) return haptic->neffects; } + +/* + * Returns the number of effects a haptic device can play. + */ +int +SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + + return haptic->nplaying; +} + + /* * Returns supported effects by the device. */ diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index 55ee2f6fa..effa7304b 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -47,6 +47,7 @@ struct _SDL_Haptic struct haptic_effect *effects; /* Allocated effects */ int neffects; /* Maximum amount of effects */ + int nplaying; /* Maximum amount of effects to play at the same time */ unsigned int supported; /* Supported effects */ struct haptic_hwdata *hwdata; /* Driver dependent */ diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 22c1f25d7..3a1ccc00e 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -260,6 +260,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd) SDL_SetError("Haptic: Unable to query device memory: %s", strerror(errno)); goto open_err; } + haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */ haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (haptic->effects == NULL) {