summaryrefslogtreecommitdiff
path: root/macosx/plugins/Common/SDL/src
diff options
context:
space:
mode:
authorSND\edgbla_cp <SND\edgbla_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-05-02 12:56:41 +0000
committerSND\edgbla_cp <SND\edgbla_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-05-02 12:56:41 +0000
commit1b994def069a2a09e792f88bb9287387a9a4cc97 (patch)
treec2436e7fc76bb7e834dc3a4a1c79390c8538fe54 /macosx/plugins/Common/SDL/src
parent2cd82c7b149157c303828d09ef44073c5ff169bf (diff)
downloadpcsxr-1b994def069a2a09e792f88bb9287387a9a4cc97.tar.gz
Patch 9232 (MaddTheSane).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@66465 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/plugins/Common/SDL/src')
-rw-r--r--macosx/plugins/Common/SDL/src/haptic/SDL_haptic.c146
-rw-r--r--macosx/plugins/Common/SDL/src/haptic/SDL_haptic_c.h31
-rw-r--r--macosx/plugins/Common/SDL/src/haptic/SDL_syshaptic.h40
-rw-r--r--macosx/plugins/Common/SDL/src/haptic/darwin/SDL_syshaptic.c49
4 files changed, 193 insertions, 73 deletions
diff --git a/macosx/plugins/Common/SDL/src/haptic/SDL_haptic.c b/macosx/plugins/Common/SDL/src/haptic/SDL_haptic.c
index af8c39a7..db7dd121 100644
--- a/macosx/plugins/Common/SDL/src/haptic/SDL_haptic.c
+++ b/macosx/plugins/Common/SDL/src/haptic/SDL_haptic.c
@@ -1,23 +1,22 @@
/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 2008 Edgar Simo
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
@@ -143,6 +142,7 @@ SDL_HapticOpen(int device_index)
/* Initialize the haptic device */
SDL_memset(haptic, 0, (sizeof *haptic));
+ haptic->rumble_id = -1;
haptic->index = device_index;
if (SDL_SYS_HapticOpen(haptic) < 0) {
SDL_free(haptic);
@@ -292,6 +292,7 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
/* Initialize the haptic device */
SDL_memset(haptic, 0, sizeof(SDL_Haptic));
+ haptic->rumble_id = -1;
if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
SDL_free(haptic);
return NULL;
@@ -706,3 +707,110 @@ SDL_HapticStopAll(SDL_Haptic * haptic)
return SDL_SYS_HapticStopAll(haptic);
}
+
+static void
+SDL_HapticRumbleCreate(SDL_HapticEffect * efx)
+{
+ SDL_memset(efx, 0, sizeof(SDL_HapticEffect));
+ efx->type = SDL_HAPTIC_SINE;
+ efx->periodic.period = 1000;
+ efx->periodic.magnitude = 0x4000;
+ efx->periodic.length = 5000;
+ efx->periodic.attack_length = 0;
+ efx->periodic.fade_length = 0;
+}
+
+/*
+ * Checks to see if rumble is supported.
+ */
+int
+SDL_HapticRumbleSupported(SDL_Haptic * haptic)
+{
+ SDL_HapticEffect efx;
+
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ SDL_HapticRumbleCreate(&efx);
+ return SDL_HapticEffectSupported(haptic, &efx);
+}
+
+/*
+ * Initializes the haptic device for simple rumble playback.
+ */
+int
+SDL_HapticRumbleInit(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ /* Already allocated. */
+ if (haptic->rumble_id >= 0) {
+ return 0;
+ }
+
+ /* Copy over. */
+ SDL_HapticRumbleCreate(&haptic->rumble_effect);
+ haptic->rumble_id = SDL_HapticNewEffect(haptic, &haptic->rumble_effect);
+ if (haptic->rumble_id >= 0) {
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * Runs simple rumble on a haptic device
+ */
+int
+SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
+{
+ int ret;
+ SDL_HapticPeriodic *efx;
+
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if (haptic->rumble_id < 0) {
+ SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
+ return -1;
+ }
+
+ /* Clamp strength. */
+ if (strength > 1.0f) {
+ strength = 1.0f;
+ }
+ else if (strength < 0.0f) {
+ strength = 0.0f;
+ }
+
+ /* New effect. */
+ efx = &haptic->rumble_effect.periodic;
+ efx->magnitude = (Sint16)(32767.0f*strength);
+ efx->length = length;
+ ret = SDL_HapticUpdateEffect(haptic, haptic->rumble_id, &haptic->rumble_effect);
+
+ return SDL_HapticRunEffect(haptic, haptic->rumble_id, 1);
+}
+
+/*
+ * Stops the simple rumble on a haptic device.
+ */
+int
+SDL_HapticRumbleStop(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if (haptic->rumble_id < 0) {
+ SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
+ return -1;
+ }
+
+ return SDL_HapticStopEffect(haptic, haptic->rumble_id);
+}
+
+
diff --git a/macosx/plugins/Common/SDL/src/haptic/SDL_haptic_c.h b/macosx/plugins/Common/SDL/src/haptic/SDL_haptic_c.h
index 4144a0fb..d7e81105 100644
--- a/macosx/plugins/Common/SDL/src/haptic/SDL_haptic_c.h
+++ b/macosx/plugins/Common/SDL/src/haptic/SDL_haptic_c.h
@@ -1,23 +1,22 @@
/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2010 Sam Lantinga
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
extern int SDL_HapticInit(void);
diff --git a/macosx/plugins/Common/SDL/src/haptic/SDL_syshaptic.h b/macosx/plugins/Common/SDL/src/haptic/SDL_syshaptic.h
index 9542a0d7..b28e1a9c 100644
--- a/macosx/plugins/Common/SDL/src/haptic/SDL_syshaptic.h
+++ b/macosx/plugins/Common/SDL/src/haptic/SDL_syshaptic.h
@@ -1,23 +1,22 @@
/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 2008 Edgar Simo
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
@@ -52,6 +51,9 @@ struct _SDL_Haptic
struct haptic_hwdata *hwdata; /* Driver dependent */
int ref_count; /* Count for multiple opens */
+
+ int rumble_id; /* ID of rumble effect for simple rumble API. */
+ SDL_HapticEffect rumble_effect; /* Rumble effect. */
};
/*
diff --git a/macosx/plugins/Common/SDL/src/haptic/darwin/SDL_syshaptic.c b/macosx/plugins/Common/SDL/src/haptic/darwin/SDL_syshaptic.c
index c5b1e54b..48a7c45c 100644
--- a/macosx/plugins/Common/SDL/src/haptic/darwin/SDL_syshaptic.c
+++ b/macosx/plugins/Common/SDL/src/haptic/darwin/SDL_syshaptic.c
@@ -1,23 +1,22 @@
/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 2008 Edgar Simo
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
@@ -534,6 +533,18 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
+ int i;
+ for (i=0; i<SDL_numhaptics; i++) {
+ if (IOObjectIsEqualTo((io_object_t) SDL_hapticlist[i].dev,
+ joystick->hwdata->ffservice)) {
+ haptic->index = i;
+ break;
+ }
+ }
+ if (i >= SDL_numhaptics) {
+ return -1;
+ }
+
return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
}