diff --git a/jni/SDL2-2.0.3/src/core/windows/SDL_windows.c b/jni/SDL2-2.0.3/src/core/windows/SDL_windows.c deleted file mode 100644 index 16934d5e..00000000 --- a/jni/SDL2-2.0.3/src/core/windows/SDL_windows.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if defined(__WIN32__) || defined(__WINRT__) - -#include "SDL_windows.h" -#include "SDL_error.h" -#include "SDL_assert.h" - -#include /* for CoInitialize/CoUninitialize (Win32 only) */ - -/* Sets an error message based on GetLastError() */ -int -WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) -{ - TCHAR buffer[1024]; - char *message; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, - buffer, SDL_arraysize(buffer), NULL); - message = WIN_StringToUTF8(buffer); - SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); - SDL_free(message); - return -1; -} - -/* Sets an error message based on GetLastError() */ -int -WIN_SetError(const char *prefix) -{ - return WIN_SetErrorFromHRESULT(prefix, GetLastError()); -} - -HRESULT -WIN_CoInitialize(void) -{ - /* SDL handles any threading model, so initialize with the default, which - is compatible with OLE and if that doesn't work, try multi-threaded mode. - - If you need multi-threaded mode, call CoInitializeEx() before SDL_Init() - */ -#ifdef __WINRT__ - /* DLudwig: On WinRT, it is assumed that COM was initialized in main(). - CoInitializeEx is available (not CoInitialize though), however - on WinRT, main() is typically declared with the [MTAThread] - attribute, which, AFAIK, should initialize COM. - */ - return S_OK; -#else - HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - if (hr == RPC_E_CHANGED_MODE) { - hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - } - - /* S_FALSE means success, but someone else already initialized. */ - /* You still need to call CoUninitialize in this case! */ - if (hr == S_FALSE) { - return S_OK; - } - - return hr; -#endif -} - -void -WIN_CoUninitialize(void) -{ -#ifndef __WINRT__ - CoUninitialize(); -#endif -} - -#endif /* __WIN32__ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/core/windows/SDL_windows.h b/jni/SDL2-2.0.3/src/core/windows/SDL_windows.h deleted file mode 100644 index 45c9d734..00000000 --- a/jni/SDL2-2.0.3/src/core/windows/SDL_windows.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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. -*/ - -/* This is an include file for windows.h with the SDL build settings */ - -#ifndef _INCLUDED_WINDOWS_H -#define _INCLUDED_WINDOWS_H - -#if defined(__WIN32__) -#define WIN32_LEAN_AND_MEAN -#define STRICT -#ifndef UNICODE -#define UNICODE 1 -#endif -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */ -#endif - -#include - -/* Routines to convert from UTF8 to native Windows text */ -#if UNICODE -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR)) -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1) -#else -/* !!! FIXME: UTF8ToString() can just be a SDL_strdup() here. */ -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1)) -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1) -#endif - -/* Sets an error message based on a given HRESULT */ -extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr); - -/* Sets an error message based on GetLastError(). Always return -1. */ -extern int WIN_SetError(const char *prefix); - -/* Wrap up the oddities of CoInitialize() into a common function. */ -extern HRESULT WIN_CoInitialize(void); -extern void WIN_CoUninitialize(void); - -#endif /* _INCLUDED_WINDOWS_H */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic.c b/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic.c deleted file mode 100644 index a4b5e426..00000000 --- a/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic.c +++ /dev/null @@ -1,1792 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#ifdef SDL_HAPTIC_DINPUT - -#include "SDL_assert.h" -#include "SDL_thread.h" -#include "SDL_mutex.h" -#include "SDL_timer.h" -#include "SDL_hints.h" -#include "SDL_haptic.h" -#include "../SDL_syshaptic.h" -#include "SDL_joystick.h" -#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ -#include "../../joystick/windows/SDL_dxjoystick_c.h" /* For joystick hwdata */ - -#include "SDL_syshaptic_c.h" - -/* - * List of available haptic devices. - */ -typedef struct SDL_hapticlist_item -{ - DIDEVICEINSTANCE instance; - char *name; - SDL_Haptic *haptic; - DIDEVCAPS capabilities; - Uint8 bXInputHaptic; /* Supports force feedback via XInput. */ - Uint8 userid; /* XInput userid index for this joystick */ - struct SDL_hapticlist_item *next; -} SDL_hapticlist_item; - - -/* - * Haptic system hardware data. - */ -struct haptic_hwdata -{ - LPDIRECTINPUTDEVICE8 device; - DWORD axes[3]; /* Axes to use. */ - SDL_bool is_joystick; /* Device is loaded as joystick. */ - Uint8 bXInputHaptic; /* Supports force feedback via XInput. */ - Uint8 userid; /* XInput userid index for this joystick */ - SDL_Thread *thread; - SDL_mutex *mutex; - volatile Uint32 stopTicks; - volatile int stopThread; -}; - - -/* - * Haptic system effect data. - */ -struct haptic_hweffect -{ - DIEFFECT effect; - LPDIRECTINPUTEFFECT ref; - XINPUT_VIBRATION vibration; -}; - - -/* - * Internal stuff. - */ -static SDL_bool coinitialized = SDL_FALSE; -static LPDIRECTINPUT8 dinput = NULL; -static SDL_bool loaded_xinput = SDL_FALSE; -static SDL_hapticlist_item *SDL_hapticlist = NULL; -static SDL_hapticlist_item *SDL_hapticlist_tail = NULL; -static int numhaptics = 0; - -/* - * External stuff. - */ -extern HWND SDL_HelperWindow; - - -/* - * Prototypes. - */ -static int DI_SetError(const char *str, HRESULT err); -static int DI_GUIDIsSame(const GUID * a, const GUID * b); -static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, - DIDEVICEINSTANCE instance); -static int SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, - LPDIRECTINPUTDEVICE8 device8, - SDL_bool is_joystick); -static int SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, const Uint8 userid); -static DWORD DIGetTriggerButton(Uint16 button); -static int SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, - int naxes); -static int SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, - SDL_HapticEffect * src); -static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type); -static REFGUID SDL_SYS_HapticEffectType(SDL_HapticEffect * effect); -static int SDLCALL SDL_RunXInputHaptic(void *arg); - -/* Callbacks. */ -static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE * - pdidInstance, VOID * pContext); -static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv); - - -/* - * Like SDL_SetError but for DX error codes. - */ -static int -DI_SetError(const char *str, HRESULT err) -{ - /* - SDL_SetError("Haptic: %s - %s: %s", str, - DXGetErrorString8A(err), DXGetErrorDescription8A(err)); - */ - return SDL_SetError("Haptic error %s", str); -} - - -/* - * Checks to see if two GUID are the same. - */ -static int -DI_GUIDIsSame(const GUID * a, const GUID * b) -{ - return (SDL_memcmp(a, b, sizeof (GUID)) == 0); -} - - -/* - * Initializes the haptic subsystem. - */ -int -SDL_SYS_HapticInit(void) -{ - const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); - HRESULT ret; - HINSTANCE instance; - - if (dinput != NULL) { /* Already open. */ - return SDL_SetError("Haptic: SubSystem already open."); - } - - ret = WIN_CoInitialize(); - if (FAILED(ret)) { - return DI_SetError("Coinitialize", ret); - } - - coinitialized = SDL_TRUE; - - ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER, - &IID_IDirectInput8, (LPVOID) & dinput); - if (FAILED(ret)) { - SDL_SYS_HapticQuit(); - return DI_SetError("CoCreateInstance", ret); - } - - /* Because we used CoCreateInstance, we need to Initialize it, first. */ - instance = GetModuleHandle(NULL); - if (instance == NULL) { - SDL_SYS_HapticQuit(); - return SDL_SetError("GetModuleHandle() failed with error code %d.", - GetLastError()); - } - ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); - if (FAILED(ret)) { - SDL_SYS_HapticQuit(); - return DI_SetError("Initializing DirectInput device", ret); - } - - /* Look for haptic devices. */ - ret = IDirectInput8_EnumDevices(dinput, - 0, - EnumHapticsCallback, - NULL, - DIEDFL_FORCEFEEDBACK | - DIEDFL_ATTACHEDONLY); - if (FAILED(ret)) { - SDL_SYS_HapticQuit(); - return DI_SetError("Enumerating DirectInput devices", ret); - } - - if (!env || SDL_atoi(env)) { - loaded_xinput = (WIN_LoadXInputDLL() == 0); - } - - if (loaded_xinput) { - DWORD i; - for (i = 0; i < SDL_XINPUT_MAX_DEVICES; i++) { - XInputHaptic_MaybeAddDevice(i); - } - } - - return numhaptics; -} - - -int -DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance) -{ - HRESULT ret; - LPDIRECTINPUTDEVICE8 device; - const DWORD needflags = DIDC_ATTACHED | DIDC_FORCEFEEDBACK; - DIDEVCAPS capabilities; - SDL_hapticlist_item *item = NULL; - - if (dinput == NULL) { - return -1; /* not initialized. We'll pick these up on enumeration if we init later. */ - } - - /* Make sure we don't already have it */ - for (item = SDL_hapticlist; item; item = item->next) { - if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) { - return -1; /* Already added */ - } - } - - /* Open the device */ - ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL); - if (FAILED(ret)) { - /* DI_SetError("Creating DirectInput device",ret); */ - return -1; - } - - /* Get capabilities. */ - SDL_zero(capabilities); - capabilities.dwSize = sizeof (DIDEVCAPS); - ret = IDirectInputDevice8_GetCapabilities(device, &capabilities); - IDirectInputDevice8_Release(device); - if (FAILED(ret)) { - /* DI_SetError("Getting device capabilities",ret); */ - return -1; - } - - if ((capabilities.dwFlags & needflags) != needflags) { - return -1; /* not a device we can use. */ - } - - item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); - if (item == NULL) { - return SDL_OutOfMemory(); - } - - item->name = WIN_StringToUTF8(pdidInstance->tszProductName); - if (!item->name) { - SDL_free(item); - return -1; - } - - /* Copy the instance over, useful for creating devices. */ - SDL_memcpy(&item->instance, pdidInstance, sizeof (DIDEVICEINSTANCE)); - SDL_memcpy(&item->capabilities, &capabilities, sizeof (capabilities)); - - if (SDL_hapticlist_tail == NULL) { - SDL_hapticlist = SDL_hapticlist_tail = item; - } else { - SDL_hapticlist_tail->next = item; - SDL_hapticlist_tail = item; - } - - /* Device has been added. */ - ++numhaptics; - - return numhaptics; -} - - -int -DirectInputHaptic_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance) -{ - SDL_hapticlist_item *item; - SDL_hapticlist_item *prev = NULL; - - if (dinput == NULL) { - return -1; /* not initialized, ignore this. */ - } - - for (item = SDL_hapticlist; item != NULL; item = item->next) { - if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) { - /* found it, remove it. */ - const int retval = item->haptic ? item->haptic->index : -1; - if (prev != NULL) { - prev->next = item->next; - } else { - SDL_assert(SDL_hapticlist == item); - SDL_hapticlist = item->next; - } - if (item == SDL_hapticlist_tail) { - SDL_hapticlist_tail = prev; - } - --numhaptics; - /* !!! TODO: Send a haptic remove event? */ - SDL_free(item); - return retval; - } - prev = item; - } - - return -1; -} - - -int -XInputHaptic_MaybeAddDevice(const DWORD dwUserid) -{ - const Uint8 userid = (Uint8) dwUserid; - XINPUT_CAPABILITIES caps; - const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); - SDL_hapticlist_item *item; - - if ((!loaded_xinput) || (dwUserid >= SDL_XINPUT_MAX_DEVICES)) { - return -1; - } - - /* Make sure we don't already have it */ - for (item = SDL_hapticlist; item; item = item->next) { - if ((item->bXInputHaptic) && (item->userid == userid)) { - return -1; /* Already added */ - } - } - - if (XINPUTGETCAPABILITIES(dwUserid, XINPUT_FLAG_GAMEPAD, &caps) != ERROR_SUCCESS) { - return -1; /* maybe controller isn't plugged in. */ - } - - /* XInput < 1.4 is probably only for original XBox360 controllers, - which don't offer the flag, and always have force feedback */ - if ( (bIs14OrLater) && ((caps.Flags & XINPUT_CAPS_FFB_SUPPORTED) == 0) ) { - return -1; /* no force feedback on this device. */ - } - - item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item)); - if (item == NULL) { - return SDL_OutOfMemory(); - } - - SDL_zerop(item); - - /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */ - { - char buf[64]; - SDL_snprintf(buf, sizeof (buf), "XInput Controller #%u", (unsigned int) (userid+1)); - item->name = SDL_strdup(buf); - } - - if (!item->name) { - SDL_free(item); - return -1; - } - - /* Copy the instance over, useful for creating devices. */ - item->bXInputHaptic = 1; - item->userid = userid; - - if (SDL_hapticlist_tail == NULL) { - SDL_hapticlist = SDL_hapticlist_tail = item; - } else { - SDL_hapticlist_tail->next = item; - SDL_hapticlist_tail = item; - } - - /* Device has been added. */ - ++numhaptics; - - return numhaptics; -} - - -int -XInputHaptic_MaybeRemoveDevice(const DWORD dwUserid) -{ - const Uint8 userid = (Uint8) dwUserid; - SDL_hapticlist_item *item; - SDL_hapticlist_item *prev = NULL; - - if ((!loaded_xinput) || (dwUserid >= SDL_XINPUT_MAX_DEVICES)) { - return -1; - } - - for (item = SDL_hapticlist; item != NULL; item = item->next) { - if ((item->bXInputHaptic) && (item->userid == userid)) { - /* found it, remove it. */ - const int retval = item->haptic ? item->haptic->index : -1; - if (prev != NULL) { - prev->next = item->next; - } else { - SDL_assert(SDL_hapticlist == item); - SDL_hapticlist = item->next; - } - if (item == SDL_hapticlist_tail) { - SDL_hapticlist_tail = prev; - } - --numhaptics; - /* !!! TODO: Send a haptic remove event? */ - SDL_free(item); - return retval; - } - prev = item; - } - - return -1; -} - - -/* - * Callback to find the haptic devices. - */ -static BOOL CALLBACK -EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) -{ - (void) pContext; - DirectInputHaptic_MaybeAddDevice(pdidInstance); - return DIENUM_CONTINUE; /* continue enumerating */ -} - - -int -SDL_SYS_NumHaptics() -{ - return numhaptics; -} - -static SDL_hapticlist_item * -HapticByDevIndex(int device_index) -{ - SDL_hapticlist_item *item = SDL_hapticlist; - - if ((device_index < 0) || (device_index >= numhaptics)) { - return NULL; - } - - while (device_index > 0) { - SDL_assert(item != NULL); - --device_index; - item = item->next; - } - - return item; -} - -/* - * Return the name of a haptic device, does not need to be opened. - */ -const char * -SDL_SYS_HapticName(int index) -{ - SDL_hapticlist_item *item = HapticByDevIndex(index); - return item->name; -} - - -/* - * Callback to get all supported effects. - */ -#define EFFECT_TEST(e,s) \ -if (DI_GUIDIsSame(&pei->guid, &(e))) \ - haptic->supported |= (s) -static BOOL CALLBACK -DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv) -{ - /* Prepare the haptic device. */ - SDL_Haptic *haptic = (SDL_Haptic *) pv; - - /* Get supported. */ - EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING); - EFFECT_TEST(GUID_Damper, SDL_HAPTIC_DAMPER); - EFFECT_TEST(GUID_Inertia, SDL_HAPTIC_INERTIA); - EFFECT_TEST(GUID_Friction, SDL_HAPTIC_FRICTION); - EFFECT_TEST(GUID_ConstantForce, SDL_HAPTIC_CONSTANT); - EFFECT_TEST(GUID_CustomForce, SDL_HAPTIC_CUSTOM); - EFFECT_TEST(GUID_Sine, SDL_HAPTIC_SINE); - /* !!! FIXME: put this back when we have more bits in 2.1 */ - /* EFFECT_TEST(GUID_Square, SDL_HAPTIC_SQUARE); */ - EFFECT_TEST(GUID_Triangle, SDL_HAPTIC_TRIANGLE); - EFFECT_TEST(GUID_SawtoothUp, SDL_HAPTIC_SAWTOOTHUP); - EFFECT_TEST(GUID_SawtoothDown, SDL_HAPTIC_SAWTOOTHDOWN); - EFFECT_TEST(GUID_RampForce, SDL_HAPTIC_RAMP); - - /* Check for more. */ - return DIENUM_CONTINUE; -} - - -/* - * Callback to get supported axes. - */ -static BOOL CALLBACK -DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef) -{ - SDL_Haptic *haptic = (SDL_Haptic *) pvRef; - - if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) { - - haptic->hwdata->axes[haptic->naxes] = dev->dwOfs; - haptic->naxes++; - - /* Currently using the artificial limit of 3 axes. */ - if (haptic->naxes >= 3) { - return DIENUM_STOP; - } - } - - return DIENUM_CONTINUE; -} - - -/* - * Opens the haptic device from the file descriptor. - * - * Steps: - * - Open temporary DirectInputDevice interface. - * - Create DirectInputDevice8 interface. - * - Release DirectInputDevice interface. - * - Call SDL_SYS_HapticOpenFromDevice8 - */ -static int -SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance) -{ - HRESULT ret; - int ret2; - LPDIRECTINPUTDEVICE8 device; - LPDIRECTINPUTDEVICE8 device8; - - /* Open the device */ - ret = IDirectInput8_CreateDevice(dinput, &instance.guidInstance, - &device, NULL); - if (FAILED(ret)) { - DI_SetError("Creating DirectInput device", ret); - return -1; - } - - /* Now get the IDirectInputDevice8 interface, instead. */ - ret = IDirectInputDevice8_QueryInterface(device, - &IID_IDirectInputDevice8, - (LPVOID *) &device8); - /* Done with the temporary one now. */ - IDirectInputDevice8_Release(device); - if (FAILED(ret)) { - DI_SetError("Querying DirectInput interface", ret); - return -1; - } - - ret2 = SDL_SYS_HapticOpenFromDevice8(haptic, device8, SDL_FALSE); - if (ret2 < 0) { - IDirectInputDevice8_Release(device8); - return -1; - } - - return 0; -} - -static int -SDL_SYS_HapticOpenFromXInput(SDL_Haptic *haptic, const Uint8 userid) -{ - char threadName[32]; - XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */ - XINPUTSETSTATE(userid, &vibration); - - haptic->supported = SDL_HAPTIC_LEFTRIGHT; - - haptic->neffects = 1; - haptic->nplaying = 1; - - /* Prepare effects memory. */ - haptic->effects = (struct haptic_effect *) - SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); - if (haptic->effects == NULL) { - return SDL_OutOfMemory(); - } - /* Clear the memory */ - SDL_memset(haptic->effects, 0, - sizeof(struct haptic_effect) * haptic->neffects); - - haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); - if (haptic->hwdata == NULL) { - SDL_free(haptic->effects); - haptic->effects = NULL; - return SDL_OutOfMemory(); - } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); - - haptic->hwdata->bXInputHaptic = 1; - haptic->hwdata->userid = userid; - - haptic->hwdata->mutex = SDL_CreateMutex(); - if (haptic->hwdata->mutex == NULL) { - SDL_free(haptic->effects); - SDL_free(haptic->hwdata); - haptic->effects = NULL; - return SDL_SetError("Couldn't create XInput haptic mutex"); - } - - SDL_snprintf(threadName, sizeof (threadName), "SDLXInputDev%d", (int) userid); - -#if defined(__WIN32__) && !defined(HAVE_LIBC) /* !!! FIXME: this is nasty. */ - #undef SDL_CreateThread - #if SDL_DYNAMIC_API - haptic->hwdata->thread = SDL_CreateThread_REAL(SDL_RunXInputHaptic, threadName, haptic->hwdata, NULL, NULL); - #else - haptic->hwdata->thread = SDL_CreateThread(SDL_RunXInputHaptic, threadName, haptic->hwdata, NULL, NULL); - #endif -#else - haptic->hwdata->thread = SDL_CreateThread(SDL_RunXInputHaptic, threadName, haptic->hwdata); -#endif - if (haptic->hwdata->thread == NULL) { - SDL_DestroyMutex(haptic->hwdata->mutex); - SDL_free(haptic->effects); - SDL_free(haptic->hwdata); - haptic->effects = NULL; - return SDL_SetError("Couldn't create XInput haptic thread"); - } - - return 0; - } - -/* - * Opens the haptic device from the file descriptor. - * - * Steps: - * - Set cooperative level. - * - Set data format. - * - Acquire exclusiveness. - * - Reset actuators. - * - Get supported features. - */ -static int -SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, - LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick) -{ - HRESULT ret; - DIPROPDWORD dipdw; - - /* Allocate the hwdata */ - haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata)); - if (haptic->hwdata == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); - - /* We'll use the device8 from now on. */ - haptic->hwdata->device = device8; - haptic->hwdata->is_joystick = is_joystick; - - /* Grab it exclusively to use force feedback stuff. */ - ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, - SDL_HelperWindow, - DISCL_EXCLUSIVE | - DISCL_BACKGROUND); - if (FAILED(ret)) { - DI_SetError("Setting cooperative level to exclusive", ret); - goto acquire_err; - } - - /* Set data format. */ - ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device, - &c_dfDIJoystick2); - if (FAILED(ret)) { - DI_SetError("Setting data format", ret); - goto acquire_err; - } - - /* Get number of axes. */ - ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device, - DI_DeviceObjectCallback, - haptic, DIDFT_AXIS); - if (FAILED(ret)) { - DI_SetError("Getting device axes", ret); - goto acquire_err; - } - - /* Acquire the device. */ - ret = IDirectInputDevice8_Acquire(haptic->hwdata->device); - if (FAILED(ret)) { - DI_SetError("Acquiring DirectInput device", ret); - goto acquire_err; - } - - /* Reset all actuators - just in case. */ - ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, - DISFFC_RESET); - if (FAILED(ret)) { - DI_SetError("Resetting device", ret); - goto acquire_err; - } - - /* Enabling actuators. */ - ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, - DISFFC_SETACTUATORSON); - if (FAILED(ret)) { - DI_SetError("Enabling actuators", ret); - goto acquire_err; - } - - /* Get supported effects. */ - ret = IDirectInputDevice8_EnumEffects(haptic->hwdata->device, - DI_EffectCallback, haptic, - DIEFT_ALL); - if (FAILED(ret)) { - DI_SetError("Enumerating supported effects", ret); - goto acquire_err; - } - if (haptic->supported == 0) { /* Error since device supports nothing. */ - SDL_SetError("Haptic: Internal error on finding supported effects."); - goto acquire_err; - } - - /* Check autogain and autocenter. */ - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = 10000; - ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, - DIPROP_FFGAIN, &dipdw.diph); - if (!FAILED(ret)) { /* Gain is supported. */ - haptic->supported |= SDL_HAPTIC_GAIN; - } - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DIPROPAUTOCENTER_OFF; - ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, - DIPROP_AUTOCENTER, &dipdw.diph); - if (!FAILED(ret)) { /* Autocenter is supported. */ - haptic->supported |= SDL_HAPTIC_AUTOCENTER; - } - - /* Status is always supported. */ - haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE; - - /* Check maximum effects. */ - haptic->neffects = 128; /* This is not actually supported as thus under windows, - there is no way to tell the number of EFFECTS that a - device can hold, so we'll just use a "random" number - instead and put warnings in SDL_haptic.h */ - haptic->nplaying = 128; /* Even more impossible to get this then neffects. */ - - /* Prepare effects memory. */ - haptic->effects = (struct haptic_effect *) - SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); - if (haptic->effects == NULL) { - SDL_OutOfMemory(); - goto acquire_err; - } - /* Clear the memory */ - SDL_memset(haptic->effects, 0, - sizeof(struct haptic_effect) * haptic->neffects); - - return 0; - - /* Error handling */ - acquire_err: - IDirectInputDevice8_Unacquire(haptic->hwdata->device); - return -1; - -} - - -/* - * Opens a haptic device for usage. - */ -int -SDL_SYS_HapticOpen(SDL_Haptic * haptic) -{ - SDL_hapticlist_item *item = HapticByDevIndex(haptic->index); - return (item->bXInputHaptic) ? SDL_SYS_HapticOpenFromXInput(haptic, item->userid) : SDL_SYS_HapticOpenFromInstance(haptic, item->instance); -} - - -/* - * Opens a haptic device from first mouse it finds for usage. - */ -int -SDL_SYS_HapticMouse(void) -{ - SDL_hapticlist_item *item; - int index = 0; - - /* Grab the first mouse haptic device we find. */ - for (item = SDL_hapticlist; item != NULL; item = item->next) { - SDL_assert(index >= 0); - if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) { - return index; - } - ++index; - } - - return -1; -} - - -/* - * Checks to see if a joystick has haptic features. - */ -int -SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) -{ - const struct joystick_hwdata *hwdata = joystick->hwdata; - return ( (hwdata->bXInputHaptic) || - ((hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) != 0) ); -} - - -/* - * Checks to see if the haptic device and joystick are in reality the same. - */ -int -SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - if (joystick->hwdata->bXInputHaptic != haptic->hwdata->bXInputHaptic) { - return 0; /* one is XInput, one is not; not the same device. */ - } else if (joystick->hwdata->bXInputHaptic) { /* XInput */ - return (haptic->hwdata->userid == joystick->hwdata->userid); - } else { /* DirectInput */ - HRESULT ret; - DIDEVICEINSTANCE hap_instance, joy_instance; - - hap_instance.dwSize = sizeof(DIDEVICEINSTANCE); - joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); - - /* Get the device instances. */ - ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, - &hap_instance); - if (FAILED(ret)) { - return 0; - } - ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, - &joy_instance); - if (FAILED(ret)) { - return 0; - } - - if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance)) - return 1; - } - - return 0; -} - - -/* - * Opens a SDL_Haptic from a SDL_Joystick. - */ -int -SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - SDL_hapticlist_item *item; - int index = 0; - - /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ - if (joystick->hwdata->bXInputDevice) { - const Uint8 userid = joystick->hwdata->userid; - for (item = SDL_hapticlist; item != NULL; item = item->next) { - if ((item->bXInputHaptic) && (item->userid == userid)) { - SDL_assert(joystick->hwdata->bXInputHaptic); - haptic->index = index; - return SDL_SYS_HapticOpenFromXInput(haptic, userid); - } - ++index; - } - } else { - HRESULT idret; - DIDEVICEINSTANCE joy_instance; - - joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); - idret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance); - if (FAILED(idret)) { - return -1; - } - - for (item = SDL_hapticlist; item != NULL; item = item->next) { - if (DI_GUIDIsSame(&item->instance.guidInstance, &joy_instance.guidInstance)) { - haptic->index = index; - return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE); - } - ++index; - } - } - - /* No match to our haptic list */ - return -1; -} - - -/* - * Closes the haptic device. - */ -void -SDL_SYS_HapticClose(SDL_Haptic * haptic) -{ - if (haptic->hwdata) { - - /* Free effects. */ - SDL_free(haptic->effects); - haptic->effects = NULL; - haptic->neffects = 0; - - /* Clean up */ - if (haptic->hwdata->bXInputHaptic) { - haptic->hwdata->stopThread = 1; - SDL_WaitThread(haptic->hwdata->thread, NULL); - SDL_DestroyMutex(haptic->hwdata->mutex); - } else { - IDirectInputDevice8_Unacquire(haptic->hwdata->device); - /* Only release if isn't grabbed by a joystick. */ - if (haptic->hwdata->is_joystick == 0) { - IDirectInputDevice8_Release(haptic->hwdata->device); - } - } - - /* Free */ - SDL_free(haptic->hwdata); - haptic->hwdata = NULL; - } -} - - -/* - * Clean up after system specific haptic stuff - */ -void -SDL_SYS_HapticQuit(void) -{ - SDL_hapticlist_item *item; - SDL_hapticlist_item *next = NULL; - SDL_Haptic *hapticitem = NULL; - - extern SDL_Haptic *SDL_haptics; - for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) { - if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) { - /* we _have_ to stop the thread before we free the XInput DLL! */ - hapticitem->hwdata->stopThread = 1; - SDL_WaitThread(hapticitem->hwdata->thread, NULL); - hapticitem->hwdata->thread = NULL; - } - } - - for (item = SDL_hapticlist; item; item = next) { - /* Opened and not closed haptics are leaked, this is on purpose. - * Close your haptic devices after usage. */ - /* !!! FIXME: (...is leaking on purpose a good idea?) */ - next = item->next; - SDL_free(item->name); - SDL_free(item); - } - - if (loaded_xinput) { - WIN_UnloadXInputDLL(); - loaded_xinput = SDL_FALSE; - } - - if (dinput != NULL) { - IDirectInput8_Release(dinput); - dinput = NULL; - } - - if (coinitialized) { - WIN_CoUninitialize(); - coinitialized = SDL_FALSE; - } -} - - -/* - * Converts an SDL trigger button to an DIEFFECT trigger button. - */ -static DWORD -DIGetTriggerButton(Uint16 button) -{ - DWORD dwTriggerButton; - - dwTriggerButton = DIEB_NOTRIGGER; - - if (button != 0) { - dwTriggerButton = DIJOFS_BUTTON(button - 1); - } - - return dwTriggerButton; -} - - -/* - * Sets the direction. - */ -static int -SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) -{ - LONG *rglDir; - - /* Handle no axes a part. */ - if (naxes == 0) { - effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */ - effect->rglDirection = NULL; - return 0; - } - - /* Has axes. */ - rglDir = SDL_malloc(sizeof(LONG) * naxes); - if (rglDir == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(rglDir, 0, sizeof(LONG) * naxes); - effect->rglDirection = rglDir; - - switch (dir->type) { - case SDL_HAPTIC_POLAR: - effect->dwFlags |= DIEFF_POLAR; - rglDir[0] = dir->dir[0]; - return 0; - case SDL_HAPTIC_CARTESIAN: - effect->dwFlags |= DIEFF_CARTESIAN; - rglDir[0] = dir->dir[0]; - if (naxes > 1) - rglDir[1] = dir->dir[1]; - if (naxes > 2) - rglDir[2] = dir->dir[2]; - return 0; - case SDL_HAPTIC_SPHERICAL: - effect->dwFlags |= DIEFF_SPHERICAL; - rglDir[0] = dir->dir[0]; - if (naxes > 1) - rglDir[1] = dir->dir[1]; - if (naxes > 2) - rglDir[2] = dir->dir[2]; - return 0; - - default: - return SDL_SetError("Haptic: Unknown direction type."); - } -} - -#define CONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF) -/* - * Creates the DIEFFECT from a SDL_HapticEffect. - */ -static int -SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, - SDL_HapticEffect * src) -{ - int i; - DICONSTANTFORCE *constant; - DIPERIODIC *periodic; - DICONDITION *condition; /* Actually an array of conditions - one per axis. */ - DIRAMPFORCE *ramp; - DICUSTOMFORCE *custom; - DIENVELOPE *envelope; - SDL_HapticConstant *hap_constant; - SDL_HapticPeriodic *hap_periodic; - SDL_HapticCondition *hap_condition; - SDL_HapticRamp *hap_ramp; - SDL_HapticCustom *hap_custom; - DWORD *axes; - - /* Set global stuff. */ - SDL_memset(dest, 0, sizeof(DIEFFECT)); - dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */ - dest->dwSamplePeriod = 0; /* Not used by us. */ - dest->dwGain = 10000; /* Gain is set globally, not locally. */ - dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */ - - /* Envelope. */ - envelope = SDL_malloc(sizeof(DIENVELOPE)); - if (envelope == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(envelope, 0, sizeof(DIENVELOPE)); - dest->lpEnvelope = envelope; - envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */ - - /* Axes. */ - dest->cAxes = haptic->naxes; - if (dest->cAxes > 0) { - axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); - if (axes == NULL) { - return SDL_OutOfMemory(); - } - axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ - if (dest->cAxes > 1) { - axes[1] = haptic->hwdata->axes[1]; - } - if (dest->cAxes > 2) { - axes[2] = haptic->hwdata->axes[2]; - } - dest->rgdwAxes = axes; - } - - - /* The big type handling switch, even bigger then Linux's version. */ - switch (src->type) { - case SDL_HAPTIC_CONSTANT: - hap_constant = &src->constant; - constant = SDL_malloc(sizeof(DICONSTANTFORCE)); - if (constant == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(constant, 0, sizeof(DICONSTANTFORCE)); - - /* Specifics */ - constant->lMagnitude = CONVERT(hap_constant->level); - dest->cbTypeSpecificParams = sizeof(DICONSTANTFORCE); - dest->lpvTypeSpecificParams = constant; - - /* Generics */ - dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */ - dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button); - dest->dwTriggerRepeatInterval = hap_constant->interval; - dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */ - - /* Direction. */ - if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) - < 0) { - return -1; - } - - /* Envelope */ - if ((hap_constant->attack_length == 0) - && (hap_constant->fade_length == 0)) { - SDL_free(dest->lpEnvelope); - dest->lpEnvelope = NULL; - } else { - envelope->dwAttackLevel = CONVERT(hap_constant->attack_level); - envelope->dwAttackTime = hap_constant->attack_length * 1000; - envelope->dwFadeLevel = CONVERT(hap_constant->fade_level); - envelope->dwFadeTime = hap_constant->fade_length * 1000; - } - - break; - - case SDL_HAPTIC_SINE: - /* !!! FIXME: put this back when we have more bits in 2.1 */ - /* case SDL_HAPTIC_SQUARE: */ - case SDL_HAPTIC_TRIANGLE: - case SDL_HAPTIC_SAWTOOTHUP: - case SDL_HAPTIC_SAWTOOTHDOWN: - hap_periodic = &src->periodic; - periodic = SDL_malloc(sizeof(DIPERIODIC)); - if (periodic == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(periodic, 0, sizeof(DIPERIODIC)); - - /* Specifics */ - periodic->dwMagnitude = CONVERT(hap_periodic->magnitude); - periodic->lOffset = CONVERT(hap_periodic->offset); - periodic->dwPhase = hap_periodic->phase; - periodic->dwPeriod = hap_periodic->period * 1000; - dest->cbTypeSpecificParams = sizeof(DIPERIODIC); - dest->lpvTypeSpecificParams = periodic; - - /* Generics */ - dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */ - dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button); - dest->dwTriggerRepeatInterval = hap_periodic->interval; - dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */ - - /* Direction. */ - if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) - < 0) { - return -1; - } - - /* Envelope */ - if ((hap_periodic->attack_length == 0) - && (hap_periodic->fade_length == 0)) { - SDL_free(dest->lpEnvelope); - dest->lpEnvelope = NULL; - } else { - envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level); - envelope->dwAttackTime = hap_periodic->attack_length * 1000; - envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level); - envelope->dwFadeTime = hap_periodic->fade_length * 1000; - } - - break; - - case SDL_HAPTIC_SPRING: - case SDL_HAPTIC_DAMPER: - case SDL_HAPTIC_INERTIA: - case SDL_HAPTIC_FRICTION: - hap_condition = &src->condition; - condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes); - if (condition == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(condition, 0, sizeof(DICONDITION)); - - /* Specifics */ - for (i = 0; i < (int) dest->cAxes; i++) { - condition[i].lOffset = CONVERT(hap_condition->center[i]); - condition[i].lPositiveCoefficient = - CONVERT(hap_condition->right_coeff[i]); - condition[i].lNegativeCoefficient = - CONVERT(hap_condition->left_coeff[i]); - condition[i].dwPositiveSaturation = - CONVERT(hap_condition->right_sat[i]); - condition[i].dwNegativeSaturation = - CONVERT(hap_condition->left_sat[i]); - condition[i].lDeadBand = CONVERT(hap_condition->deadband[i]); - } - dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes; - dest->lpvTypeSpecificParams = condition; - - /* Generics */ - dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */ - dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button); - dest->dwTriggerRepeatInterval = hap_condition->interval; - dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */ - - /* Direction. */ - if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) - < 0) { - return -1; - } - - /* Envelope - Not actually supported by most CONDITION implementations. */ - SDL_free(dest->lpEnvelope); - dest->lpEnvelope = NULL; - - break; - - case SDL_HAPTIC_RAMP: - hap_ramp = &src->ramp; - ramp = SDL_malloc(sizeof(DIRAMPFORCE)); - if (ramp == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(ramp, 0, sizeof(DIRAMPFORCE)); - - /* Specifics */ - ramp->lStart = CONVERT(hap_ramp->start); - ramp->lEnd = CONVERT(hap_ramp->end); - dest->cbTypeSpecificParams = sizeof(DIRAMPFORCE); - dest->lpvTypeSpecificParams = ramp; - - /* Generics */ - dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */ - dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button); - dest->dwTriggerRepeatInterval = hap_ramp->interval; - dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */ - - /* Direction. */ - if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) { - return -1; - } - - /* Envelope */ - if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) { - SDL_free(dest->lpEnvelope); - dest->lpEnvelope = NULL; - } else { - envelope->dwAttackLevel = CONVERT(hap_ramp->attack_level); - envelope->dwAttackTime = hap_ramp->attack_length * 1000; - envelope->dwFadeLevel = CONVERT(hap_ramp->fade_level); - envelope->dwFadeTime = hap_ramp->fade_length * 1000; - } - - break; - - case SDL_HAPTIC_CUSTOM: - hap_custom = &src->custom; - custom = SDL_malloc(sizeof(DICUSTOMFORCE)); - if (custom == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(custom, 0, sizeof(DICUSTOMFORCE)); - - /* Specifics */ - custom->cChannels = hap_custom->channels; - custom->dwSamplePeriod = hap_custom->period * 1000; - custom->cSamples = hap_custom->samples; - custom->rglForceData = - SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels); - for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */ - custom->rglForceData[i] = CONVERT(hap_custom->data[i]); - } - dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE); - dest->lpvTypeSpecificParams = custom; - - /* Generics */ - dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */ - dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button); - dest->dwTriggerRepeatInterval = hap_custom->interval; - dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */ - - /* Direction. */ - if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < - 0) { - return -1; - } - - /* Envelope */ - if ((hap_custom->attack_length == 0) - && (hap_custom->fade_length == 0)) { - SDL_free(dest->lpEnvelope); - dest->lpEnvelope = NULL; - } else { - envelope->dwAttackLevel = CONVERT(hap_custom->attack_level); - envelope->dwAttackTime = hap_custom->attack_length * 1000; - envelope->dwFadeLevel = CONVERT(hap_custom->fade_level); - envelope->dwFadeTime = hap_custom->fade_length * 1000; - } - - break; - - - default: - return SDL_SetError("Haptic: Unknown effect type."); - } - - return 0; -} - - -/* - * Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT. - */ -static void -SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type) -{ - DICUSTOMFORCE *custom; - - SDL_free(effect->lpEnvelope); - effect->lpEnvelope = NULL; - SDL_free(effect->rgdwAxes); - effect->rgdwAxes = NULL; - if (effect->lpvTypeSpecificParams != NULL) { - if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */ - custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams; - SDL_free(custom->rglForceData); - custom->rglForceData = NULL; - } - SDL_free(effect->lpvTypeSpecificParams); - effect->lpvTypeSpecificParams = NULL; - } - SDL_free(effect->rglDirection); - effect->rglDirection = NULL; -} - - -/* - * Gets the effect type from the generic SDL haptic effect wrapper. - */ -static REFGUID -SDL_SYS_HapticEffectType(SDL_HapticEffect * effect) -{ - switch (effect->type) { - case SDL_HAPTIC_CONSTANT: - return &GUID_ConstantForce; - - case SDL_HAPTIC_RAMP: - return &GUID_RampForce; - - /* !!! FIXME: put this back when we have more bits in 2.1 */ - /* case SDL_HAPTIC_SQUARE: - return &GUID_Square; */ - - case SDL_HAPTIC_SINE: - return &GUID_Sine; - - case SDL_HAPTIC_TRIANGLE: - return &GUID_Triangle; - - case SDL_HAPTIC_SAWTOOTHUP: - return &GUID_SawtoothUp; - - case SDL_HAPTIC_SAWTOOTHDOWN: - return &GUID_SawtoothDown; - - case SDL_HAPTIC_SPRING: - return &GUID_Spring; - - case SDL_HAPTIC_DAMPER: - return &GUID_Damper; - - case SDL_HAPTIC_INERTIA: - return &GUID_Inertia; - - case SDL_HAPTIC_FRICTION: - return &GUID_Friction; - - case SDL_HAPTIC_CUSTOM: - return &GUID_CustomForce; - - default: - return NULL; - } -} - - -/* - * Creates a new haptic effect. - */ -int -SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, - SDL_HapticEffect * base) -{ - HRESULT ret; - REFGUID type = SDL_SYS_HapticEffectType(base); - - if ((type == NULL) && (!haptic->hwdata->bXInputHaptic)) { - SDL_SetError("Haptic: Unknown effect type."); - goto err_hweffect; - } - - /* Alloc the effect. */ - effect->hweffect = (struct haptic_hweffect *) - SDL_malloc(sizeof(struct haptic_hweffect)); - if (effect->hweffect == NULL) { - SDL_OutOfMemory(); - goto err_hweffect; - } - - SDL_zerop(effect->hweffect); - - if (haptic->hwdata->bXInputHaptic) { - SDL_assert(base->type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */ - return SDL_SYS_HapticUpdateEffect(haptic, effect, base); - } - - /* Get the effect. */ - if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { - goto err_effectdone; - } - - /* Create the actual effect. */ - ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type, - &effect->hweffect->effect, - &effect->hweffect->ref, NULL); - if (FAILED(ret)) { - DI_SetError("Unable to create effect", ret); - goto err_effectdone; - } - - return 0; - - err_effectdone: - SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type); - err_hweffect: - SDL_free(effect->hweffect); - effect->hweffect = NULL; - return -1; -} - - -/* - * Updates an effect. - */ -int -SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - SDL_HapticEffect * data) -{ - HRESULT ret; - DWORD flags; - DIEFFECT temp; - - if (haptic->hwdata->bXInputHaptic) { - XINPUT_VIBRATION *vib = &effect->hweffect->vibration; - SDL_assert(data->type == SDL_HAPTIC_LEFTRIGHT); - vib->wLeftMotorSpeed = data->leftright.large_magnitude; - vib->wRightMotorSpeed = data->leftright.small_magnitude; - SDL_LockMutex(haptic->hwdata->mutex); - if (haptic->hwdata->stopTicks) { /* running right now? Update it. */ - XINPUTSETSTATE(haptic->hwdata->userid, vib); - } - SDL_UnlockMutex(haptic->hwdata->mutex); - return 0; - } - - /* Get the effect. */ - SDL_memset(&temp, 0, sizeof(DIEFFECT)); - if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) { - goto err_update; - } - - /* Set the flags. Might be worthwhile to diff temp with loaded effect and - * only change those parameters. */ - flags = DIEP_DIRECTION | - DIEP_DURATION | - DIEP_ENVELOPE | - DIEP_STARTDELAY | - DIEP_TRIGGERBUTTON | - DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS; - - /* Create the actual effect. */ - ret = - IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags); - if (FAILED(ret)) { - DI_SetError("Unable to update effect", ret); - goto err_update; - } - - /* Copy it over. */ - SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type); - SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT)); - - return 0; - - err_update: - SDL_SYS_HapticFreeDIEFFECT(&temp, data->type); - return -1; -} - - -/* - * Runs an effect. - */ -int -SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, - Uint32 iterations) -{ - HRESULT ret; - DWORD iter; - - if (haptic->hwdata->bXInputHaptic) { - XINPUT_VIBRATION *vib = &effect->hweffect->vibration; - SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */ - SDL_LockMutex(haptic->hwdata->mutex); - if(effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) { - haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY; - } else if ((!effect->effect.leftright.length) || (!iterations)) { - /* do nothing. Effect runs for zero milliseconds. */ - } else { - haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations); - if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) { - haptic->hwdata->stopTicks = 1; /* fix edge cases. */ - } - } - SDL_UnlockMutex(haptic->hwdata->mutex); - return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1; - } - - /* Check if it's infinite. */ - if (iterations == SDL_HAPTIC_INFINITY) { - iter = INFINITE; - } else - iter = iterations; - - /* Run the effect. */ - ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0); - if (FAILED(ret)) { - return DI_SetError("Running the effect", ret); - } - - return 0; -} - - -/* - * Stops an effect. - */ -int -SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - HRESULT ret; - - if (haptic->hwdata->bXInputHaptic) { - XINPUT_VIBRATION vibration = { 0, 0 }; - SDL_LockMutex(haptic->hwdata->mutex); - haptic->hwdata->stopTicks = 0; - SDL_UnlockMutex(haptic->hwdata->mutex); - return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1; - } - - ret = IDirectInputEffect_Stop(effect->hweffect->ref); - if (FAILED(ret)) { - return DI_SetError("Unable to stop effect", ret); - } - - return 0; -} - - -/* - * Frees the effect. - */ -void -SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - HRESULT ret; - - if (haptic->hwdata->bXInputHaptic) { - SDL_SYS_HapticStopEffect(haptic, effect); - } else { - ret = IDirectInputEffect_Unload(effect->hweffect->ref); - if (FAILED(ret)) { - DI_SetError("Removing effect from the device", ret); - } - SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, - effect->effect.type); - } - SDL_free(effect->hweffect); - effect->hweffect = NULL; -} - - -/* - * Gets the status of a haptic effect. - */ -int -SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, - struct haptic_effect *effect) -{ - HRESULT ret; - DWORD status; - - ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status); - if (FAILED(ret)) { - return DI_SetError("Getting effect status", ret); - } - - if (status == 0) - return SDL_FALSE; - return SDL_TRUE; -} - - -/* - * Sets the gain. - */ -int -SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) -{ - HRESULT ret; - DIPROPDWORD dipdw; - - /* Create the weird structure thingy. */ - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = gain * 100; /* 0 to 10,000 */ - - /* Try to set the autocenter. */ - ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, - DIPROP_FFGAIN, &dipdw.diph); - if (FAILED(ret)) { - return DI_SetError("Setting gain", ret); - } - - return 0; -} - - -/* - * Sets the autocentering. - */ -int -SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) -{ - HRESULT ret; - DIPROPDWORD dipdw; - - /* Create the weird structure thingy. */ - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF : - DIPROPAUTOCENTER_ON; - - /* Try to set the autocenter. */ - ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, - DIPROP_AUTOCENTER, &dipdw.diph); - if (FAILED(ret)) { - return DI_SetError("Setting autocenter", ret); - } - - return 0; -} - - -/* - * Pauses the device. - */ -int -SDL_SYS_HapticPause(SDL_Haptic * haptic) -{ - HRESULT ret; - - /* Pause the device. */ - ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, - DISFFC_PAUSE); - if (FAILED(ret)) { - return DI_SetError("Pausing the device", ret); - } - - return 0; -} - - -/* - * Pauses the device. - */ -int -SDL_SYS_HapticUnpause(SDL_Haptic * haptic) -{ - HRESULT ret; - - /* Unpause the device. */ - ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, - DISFFC_CONTINUE); - if (FAILED(ret)) { - return DI_SetError("Pausing the device", ret); - } - - return 0; -} - - -/* - * Stops all the playing effects on the device. - */ -int -SDL_SYS_HapticStopAll(SDL_Haptic * haptic) -{ - HRESULT ret; - - if (haptic->hwdata->bXInputHaptic) { - XINPUT_VIBRATION vibration = { 0, 0 }; - SDL_LockMutex(haptic->hwdata->mutex); - haptic->hwdata->stopTicks = 0; - SDL_UnlockMutex(haptic->hwdata->mutex); - return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1; - } - - /* Try to stop the effects. */ - ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, - DISFFC_STOPALL); - if (FAILED(ret)) { - return DI_SetError("Stopping the device", ret); - } - - return 0; -} - - -/* !!! FIXME: this is a hack, remove this later. */ -/* Since XInput doesn't offer a way to vibrate for X time, we hook into - * SDL_PumpEvents() to check if it's time to stop vibrating with some - * frequency. - * In practice, this works for 99% of use cases. But in an ideal world, - * we do this in a separate thread so that: - * - we aren't bound to when the app chooses to pump the event queue. - * - we aren't adding more polling to the event queue - * - we can emulate all the haptic effects correctly (start on a delay, - * mix multiple effects, etc). - * - * Mostly, this is here to get rumbling to work, and all the other features - * are absent in the XInput path for now. :( - */ -static int SDLCALL -SDL_RunXInputHaptic(void *arg) -{ - struct haptic_hwdata *hwdata = (struct haptic_hwdata *) arg; - - while (!hwdata->stopThread) { - SDL_Delay(50); - SDL_LockMutex(hwdata->mutex); - /* If we're currently running and need to stop... */ - if (hwdata->stopTicks) { - if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_TICKS_PASSED(SDL_GetTicks(), hwdata->stopTicks)) { - XINPUT_VIBRATION vibration = { 0, 0 }; - hwdata->stopTicks = 0; - XINPUTSETSTATE(hwdata->userid, &vibration); - } - } - SDL_UnlockMutex(hwdata->mutex); - } - - return 0; -} - -#endif /* SDL_HAPTIC_DINPUT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic_c.h b/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic_c.h deleted file mode 100644 index 1e0fa190..00000000 --- a/jni/SDL2-2.0.3/src/haptic/windows/SDL_syshaptic_c.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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. -*/ - -extern int DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance); -extern int DirectInputHaptic_MaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance); -extern int XInputHaptic_MaybeAddDevice(const DWORD dwUserid); -extern int XInputHaptic_MaybeRemoveDevice(const DWORD dwUserid); - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick.c b/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick.c deleted file mode 100644 index 3c009746..00000000 --- a/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick.c +++ /dev/null @@ -1,1683 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#ifdef SDL_JOYSTICK_DINPUT - -/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de - * A. Formiga's WINMM driver. - * - * Hats and sliders are completely untested; the app I'm writing this for mostly - * doesn't use them and I don't own any joysticks with them. - * - * We don't bother to use event notification here. It doesn't seem to work - * with polled devices, and it's fine to call IDirectInputDevice8_GetDeviceData and - * let it return 0 events. */ - -#include "SDL_error.h" -#include "SDL_assert.h" -#include "SDL_events.h" -#include "SDL_thread.h" -#include "SDL_timer.h" -#include "SDL_mutex.h" -#include "SDL_events.h" -#include "SDL_hints.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#if !SDL_EVENTS_DISABLED -#include "../../events/SDL_events_c.h" -#endif - -#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */ -#include "SDL_dxjoystick_c.h" - -#if SDL_HAPTIC_DINPUT -#include "../../haptic/windows/SDL_syshaptic_c.h" /* For haptic hot plugging */ -#endif - -#ifndef DIDFT_OPTIONAL -#define DIDFT_OPTIONAL 0x80000000 -#endif - -DEFINE_GUID(GUID_DEVINTERFACE_HID, 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30); - - -#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ -#define AXIS_MIN -32768 /* minimum value for axis coordinate */ -#define AXIS_MAX 32767 /* maximum value for axis coordinate */ -#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */ - -/* external variables referenced. */ -extern HWND SDL_HelperWindow; - - -/* local variables */ -static SDL_bool coinitialized = SDL_FALSE; -static LPDIRECTINPUT8 dinput = NULL; -static SDL_bool s_bDeviceAdded = SDL_FALSE; -static SDL_bool s_bDeviceRemoved = SDL_FALSE; -static SDL_JoystickID s_nInstanceID = -1; -static SDL_cond *s_condJoystickThread = NULL; -static SDL_mutex *s_mutexJoyStickEnum = NULL; -static SDL_Thread *s_threadJoystick = NULL; -static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; -static SDL_bool s_bXInputEnabled = SDL_TRUE; - -XInputGetState_t SDL_XInputGetState = NULL; -XInputSetState_t SDL_XInputSetState = NULL; -XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; -DWORD SDL_XInputVersion = 0; - -static HANDLE s_pXInputDLL = 0; -static int s_XInputDLLRefCount = 0; - -int -WIN_LoadXInputDLL(void) -{ - DWORD version = 0; - - if (s_pXInputDLL) { - SDL_assert(s_XInputDLLRefCount > 0); - s_XInputDLLRefCount++; - return 0; /* already loaded */ - } - - version = (1 << 16) | 4; - s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); /* 1.4 Ships with Windows 8. */ - if (!s_pXInputDLL) { - version = (1 << 16) | 3; - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); /* 1.3 Ships with Vista and Win7, can be installed as a redistributable component. */ - } - if (!s_pXInputDLL) { - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - } - if (!s_pXInputDLL) { - return -1; - } - - SDL_assert(s_XInputDLLRefCount == 0); - SDL_XInputVersion = version; - s_XInputDLLRefCount = 1; - - /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ - SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { - WIN_UnloadXInputDLL(); - return -1; - } - - return 0; -} - -void -WIN_UnloadXInputDLL(void) -{ - if ( s_pXInputDLL ) { - SDL_assert(s_XInputDLLRefCount > 0); - if (--s_XInputDLLRefCount == 0) { - FreeLibrary( s_pXInputDLL ); - s_pXInputDLL = NULL; - } - } else { - SDL_assert(s_XInputDLLRefCount == 0); - } -} - - -extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, - LPDIRECTINPUT * ppDI, - LPUNKNOWN punkOuter); -struct JoyStick_DeviceData_ -{ - SDL_JoystickGUID guid; - DIDEVICEINSTANCE dxdevice; - char *joystickname; - Uint8 send_add_event; - SDL_JoystickID nInstanceID; - SDL_bool bXInputDevice; - Uint8 XInputUserId; - struct JoyStick_DeviceData_ *pNext; -}; - -typedef struct JoyStick_DeviceData_ JoyStick_DeviceData; - -static JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */ - -/* local prototypes */ -static int SetDIerror(const char *function, HRESULT code); -static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE * - pdidInstance, VOID * pContext); -static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, - LPVOID pvRef); -static void SortDevObjects(SDL_Joystick *joystick); -static Uint8 TranslatePOV(DWORD value); -static int SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, - Sint16 value); -static int SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, - Uint8 value); -static int SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, - Uint8 button, Uint8 state); - -/* Taken from Wine - Thanks! */ -DIOBJECTDATAFORMAT dfDIJoystick2[] = { - { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,DIJOFS_SLIDER(0),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,DIJOFS_SLIDER(1),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_POV,DIJOFS_POV(0),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0}, - { &GUID_POV,DIJOFS_POV(1),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0}, - { &GUID_POV,DIJOFS_POV(2),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0}, - { &GUID_POV,DIJOFS_POV(3),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(11),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(12),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(13),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(14),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(15),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(16),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(17),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(18),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(19),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(20),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(21),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(22),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(23),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(24),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(25),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(26),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(27),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(28),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(29),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(30),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(31),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(32),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(33),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(34),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(35),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(36),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(37),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(38),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(39),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(40),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(41),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(42),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(43),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(44),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(45),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(46),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(47),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(48),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(49),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(50),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(51),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(52),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(53),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(54),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(55),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(56),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(57),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(58),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(59),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(60),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(61),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(62),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(63),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(64),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(65),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(66),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(67),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(68),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(69),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(70),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(71),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(72),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(73),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(74),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(75),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(76),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(77),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(78),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(79),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(80),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(81),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(82),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(83),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(84),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(85),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(86),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(87),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(88),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(89),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(90),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(91),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(92),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(93),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(94),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(95),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(96),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(97),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(98),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(99),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(100),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(101),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(102),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(103),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(104),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(105),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(106),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(107),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(108),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(109),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(110),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(111),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(112),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(113),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(114),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(115),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(116),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(117),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(118),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(119),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(120),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(121),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(122),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(123),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(124),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(125),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(126),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { NULL,DIJOFS_BUTTON(127),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lVX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lVY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lVZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lVRx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lVRy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lVRz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglVSlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglVSlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lAX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lAY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lAZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lARx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lARy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lARz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglASlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglASlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lFX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lFY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lFZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lFRx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lFRy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lFRz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglFSlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglFSlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, -}; - -const DIDATAFORMAT c_dfDIJoystick2 = { - sizeof(DIDATAFORMAT), - sizeof(DIOBJECTDATAFORMAT), - DIDF_ABSAXIS, - sizeof(DIJOYSTATE2), - SDL_arraysize(dfDIJoystick2), - dfDIJoystick2 -}; - - -/* Convert a DirectInput return code to a text message */ -static int -SetDIerror(const char *function, HRESULT code) -{ - /* - return SDL_SetError("%s() [%s]: %s", function, - DXGetErrorString9A(code), DXGetErrorDescription9A(code)); - */ - return SDL_SetError("%s() DirectX error %d", function, code); -} - - -#define SAFE_RELEASE(p) \ -{ \ - if (p) { \ - (p)->lpVtbl->Release((p)); \ - (p) = 0; \ - } \ -} - -DEFINE_GUID(IID_ValveStreamingGamepad, MAKELONG( 0x28DE, 0x11FF ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44); -DEFINE_GUID(IID_X360WiredGamepad, MAKELONG( 0x045E, 0x02A1 ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44); -DEFINE_GUID(IID_X360WirelessGamepad, MAKELONG( 0x045E, 0x028E ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44); - -static PRAWINPUTDEVICELIST SDL_RawDevList = NULL; -static UINT SDL_RawDevListCount = 0; - -static SDL_bool -SDL_IsXInputDevice( const GUID* pGuidProductFromDirectInput ) -{ - static const GUID *s_XInputProductGUID[] = { - &IID_ValveStreamingGamepad, - &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */ - &IID_X360WirelessGamepad /* Microsoft's wireless X360 controller for Windows. */ - }; - - size_t iDevice; - UINT i; - - if (!s_bXInputEnabled) { - return SDL_FALSE; - } - - /* Check for well known XInput device GUIDs */ - /* This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. */ - for ( iDevice = 0; iDevice < SDL_arraysize(s_XInputProductGUID); ++iDevice ) { - if (SDL_memcmp(pGuidProductFromDirectInput, s_XInputProductGUID[iDevice], sizeof(GUID)) == 0) { - return SDL_TRUE; - } - } - - /* Go through RAWINPUT (WinXP and later) to find HID devices. */ - /* Cache this if we end up using it. */ - if (SDL_RawDevList == NULL) { - if ((GetRawInputDeviceList(NULL, &SDL_RawDevListCount, sizeof (RAWINPUTDEVICELIST)) == -1) || (!SDL_RawDevListCount)) { - return SDL_FALSE; /* oh well. */ - } - - SDL_RawDevList = (PRAWINPUTDEVICELIST) SDL_malloc(sizeof (RAWINPUTDEVICELIST) * SDL_RawDevListCount); - if (SDL_RawDevList == NULL) { - SDL_OutOfMemory(); - return SDL_FALSE; - } - - if (GetRawInputDeviceList(SDL_RawDevList, &SDL_RawDevListCount, sizeof (RAWINPUTDEVICELIST)) == -1) { - SDL_free(SDL_RawDevList); - SDL_RawDevList = NULL; - return SDL_FALSE; /* oh well. */ - } - } - - for (i = 0; i < SDL_RawDevListCount; i++) { - RID_DEVICE_INFO rdi; - char devName[128]; - UINT rdiSize = sizeof (rdi); - UINT nameSize = SDL_arraysize(devName); - - rdi.cbSize = sizeof (rdi); - if ( (SDL_RawDevList[i].dwType == RIM_TYPEHID) && - (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) && - (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)pGuidProductFromDirectInput->Data1)) && - (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) && - (SDL_strstr(devName, "IG_") != NULL) ) { - return SDL_TRUE; - } - } - - return SDL_FALSE; -} - - -static SDL_bool s_bWindowsDeviceChanged = SDL_FALSE; - -/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal - */ -LRESULT CALLBACK SDL_PrivateJoystickDetectProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) { - case WM_DEVICECHANGE: - switch (wParam) { - case DBT_DEVICEARRIVAL: - if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { - s_bWindowsDeviceChanged = SDL_TRUE; - } - break; - case DBT_DEVICEREMOVECOMPLETE: - if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { - s_bWindowsDeviceChanged = SDL_TRUE; - } - break; - } - return 0; - } - - return DefWindowProc (hwnd, message, wParam, lParam); -} - - -DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \ - 0xC0, 0x4F, 0xB9, 0x51, 0xED); - -/* Function/thread to scan the system for joysticks. - */ -static int -SDL_JoystickThread(void *_data) -{ - HWND messageWindow = 0; - HDEVNOTIFY hNotify = 0; - DEV_BROADCAST_DEVICEINTERFACE dbh; - SDL_bool bOpenedXInputDevices[SDL_XINPUT_MAX_DEVICES]; - WNDCLASSEX wincl; - - SDL_zero(bOpenedXInputDevices); - - WIN_CoInitialize(); - - SDL_memset( &wincl, 0x0, sizeof(wincl) ); - wincl.hInstance = GetModuleHandle( NULL ); - wincl.lpszClassName = L"Message"; - wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */ - wincl.cbSize = sizeof (WNDCLASSEX); - - if (!RegisterClassEx (&wincl)) - { - return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError()); - } - - messageWindow = (HWND)CreateWindowEx( 0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL ); - if ( !messageWindow ) - { - return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError()); - } - - SDL_zero(dbh); - - dbh.dbcc_size = sizeof(dbh); - dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; - dbh.dbcc_classguid = GUID_DEVINTERFACE_HID; - - hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ); - if ( !hNotify ) - { - return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError()); - } - - SDL_LockMutex( s_mutexJoyStickEnum ); - while ( s_bJoystickThreadQuit == SDL_FALSE ) - { - MSG messages; - SDL_bool bXInputChanged = SDL_FALSE; - - SDL_CondWaitTimeout( s_condJoystickThread, s_mutexJoyStickEnum, 300 ); - - while ( s_bJoystickThreadQuit == SDL_FALSE && PeekMessage(&messages, messageWindow, 0, 0, PM_NOREMOVE) ) - { - if ( GetMessage(&messages, messageWindow, 0, 0) != 0 ) { - TranslateMessage(&messages); - DispatchMessage(&messages); - } - } - - if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) { - /* scan for any change in XInput devices */ - Uint8 userId; - for (userId = 0; userId < SDL_XINPUT_MAX_DEVICES; userId++) { - XINPUT_CAPABILITIES capabilities; - const DWORD result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities ); - const SDL_bool available = (result == ERROR_SUCCESS); - if (bOpenedXInputDevices[userId] != available) { - bXInputChanged = SDL_TRUE; - bOpenedXInputDevices[userId] = available; - } - } - } - - if (s_bWindowsDeviceChanged || bXInputChanged) { - SDL_UnlockMutex( s_mutexJoyStickEnum ); /* let main thread go while we SDL_Delay(). */ - SDL_Delay( 300 ); /* wait for direct input to find out about this device */ - SDL_LockMutex( s_mutexJoyStickEnum ); - - s_bDeviceRemoved = SDL_TRUE; - s_bDeviceAdded = SDL_TRUE; - s_bWindowsDeviceChanged = SDL_FALSE; - } - } - SDL_UnlockMutex( s_mutexJoyStickEnum ); - - if ( hNotify ) - UnregisterDeviceNotification( hNotify ); - - if ( messageWindow ) - DestroyWindow( messageWindow ); - - UnregisterClass( wincl.lpszClassName, wincl.hInstance ); - messageWindow = 0; - WIN_CoUninitialize(); - return 1; -} - - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int -SDL_SYS_JoystickInit(void) -{ - HRESULT result; - HINSTANCE instance; - const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); - if (env && !SDL_atoi(env)) { - s_bXInputEnabled = SDL_FALSE; - } - - result = WIN_CoInitialize(); - if (FAILED(result)) { - return SetDIerror("CoInitialize", result); - } - - coinitialized = SDL_TRUE; - - result = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER, - &IID_IDirectInput8, (LPVOID)&dinput); - - if (FAILED(result)) { - SDL_SYS_JoystickQuit(); - return SetDIerror("CoCreateInstance", result); - } - - /* Because we used CoCreateInstance, we need to Initialize it, first. */ - instance = GetModuleHandle(NULL); - if (instance == NULL) { - SDL_SYS_JoystickQuit(); - return SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError()); - } - result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); - - if (FAILED(result)) { - SDL_SYS_JoystickQuit(); - return SetDIerror("IDirectInput::Initialize", result); - } - - if ((s_bXInputEnabled) && (WIN_LoadXInputDLL() == -1)) { - s_bXInputEnabled = SDL_FALSE; /* oh well. */ - } - - s_mutexJoyStickEnum = SDL_CreateMutex(); - s_condJoystickThread = SDL_CreateCond(); - s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */ - - SDL_SYS_JoystickDetect(); - - if ( !s_threadJoystick ) - { - s_bJoystickThreadQuit = SDL_FALSE; - /* spin up the thread to detect hotplug of devices */ -#if defined(__WIN32__) && !defined(HAVE_LIBC) -#undef SDL_CreateThread -#if SDL_DYNAMIC_API - s_threadJoystick= SDL_CreateThread_REAL( SDL_JoystickThread, "SDL_joystick", NULL, NULL, NULL ); -#else - s_threadJoystick= SDL_CreateThread( SDL_JoystickThread, "SDL_joystick", NULL, NULL, NULL ); -#endif -#else - s_threadJoystick = SDL_CreateThread( SDL_JoystickThread, "SDL_joystick", NULL ); -#endif - } - return SDL_SYS_NumJoysticks(); -} - -/* return the number of joysticks that are connected right now */ -int SDL_SYS_NumJoysticks() -{ - int nJoysticks = 0; - JoyStick_DeviceData *device = SYS_Joystick; - while ( device ) - { - nJoysticks++; - device = device->pNext; - } - - return nJoysticks; -} - -/* helper function for direct input, gets called for each connected joystick */ -static BOOL CALLBACK - EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) -{ - JoyStick_DeviceData *pNewJoystick; - JoyStick_DeviceData *pPrevJoystick = NULL; - - if (SDL_IsXInputDevice( &pdidInstance->guidProduct )) { - return DIENUM_CONTINUE; /* ignore XInput devices here, keep going. */ - } - - pNewJoystick = *(JoyStick_DeviceData **)pContext; - while ( pNewJoystick ) - { - if ( !SDL_memcmp( &pNewJoystick->dxdevice.guidInstance, &pdidInstance->guidInstance, sizeof(pNewJoystick->dxdevice.guidInstance) ) ) - { - /* if we are replacing the front of the list then update it */ - if ( pNewJoystick == *(JoyStick_DeviceData **)pContext ) - { - *(JoyStick_DeviceData **)pContext = pNewJoystick->pNext; - } - else if ( pPrevJoystick ) - { - pPrevJoystick->pNext = pNewJoystick->pNext; - } - - pNewJoystick->pNext = SYS_Joystick; - SYS_Joystick = pNewJoystick; - - return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */ - } - - pPrevJoystick = pNewJoystick; - pNewJoystick = pNewJoystick->pNext; - } - - pNewJoystick = (JoyStick_DeviceData *)SDL_malloc( sizeof(JoyStick_DeviceData) ); - if (!pNewJoystick) { - return DIENUM_CONTINUE; /* better luck next time? */ - } - - SDL_zerop(pNewJoystick); - pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName); - if (!pNewJoystick->joystickname) { - SDL_free(pNewJoystick); - return DIENUM_CONTINUE; /* better luck next time? */ - } - - SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance, - sizeof(DIDEVICEINSTANCE)); - - pNewJoystick->XInputUserId = INVALID_XINPUT_USERID; - pNewJoystick->send_add_event = 1; - pNewJoystick->nInstanceID = ++s_nInstanceID; - SDL_memcpy( &pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid) ); - pNewJoystick->pNext = SYS_Joystick; - SYS_Joystick = pNewJoystick; - - s_bDeviceAdded = SDL_TRUE; - - return DIENUM_CONTINUE; /* get next device, please */ -} - -static void -AddXInputDevice(const Uint8 userid, JoyStick_DeviceData **pContext) -{ - char name[32]; - JoyStick_DeviceData *pPrevJoystick = NULL; - JoyStick_DeviceData *pNewJoystick = *pContext; - - while (pNewJoystick) { - if ((pNewJoystick->bXInputDevice) && (pNewJoystick->XInputUserId == userid)) { - /* if we are replacing the front of the list then update it */ - if (pNewJoystick == *pContext) { - *pContext = pNewJoystick->pNext; - } else if (pPrevJoystick) { - pPrevJoystick->pNext = pNewJoystick->pNext; - } - - pNewJoystick->pNext = SYS_Joystick; - SYS_Joystick = pNewJoystick; - return; /* already in the list. */ - } - - pPrevJoystick = pNewJoystick; - pNewJoystick = pNewJoystick->pNext; - } - - pNewJoystick = (JoyStick_DeviceData *) SDL_malloc(sizeof (JoyStick_DeviceData)); - if (!pNewJoystick) { - return; /* better luck next time? */ - } - SDL_zerop(pNewJoystick); - - SDL_snprintf(name, sizeof (name), "XInput Controller #%u", ((unsigned int) userid) + 1); - pNewJoystick->joystickname = SDL_strdup(name); - if (!pNewJoystick->joystickname) { - SDL_free(pNewJoystick); - return; /* better luck next time? */ - } - - pNewJoystick->bXInputDevice = SDL_TRUE; - pNewJoystick->XInputUserId = userid; - pNewJoystick->send_add_event = 1; - pNewJoystick->nInstanceID = ++s_nInstanceID; - pNewJoystick->pNext = SYS_Joystick; - SYS_Joystick = pNewJoystick; - - s_bDeviceAdded = SDL_TRUE; -} - -static void -EnumXInputDevices(JoyStick_DeviceData **pContext) -{ - if (s_bXInputEnabled) { - int iuserid; - /* iterate in reverse, so these are in the final list in ascending numeric order. */ - for (iuserid = SDL_XINPUT_MAX_DEVICES-1; iuserid >= 0; iuserid--) { - const Uint8 userid = (Uint8) iuserid; - XINPUT_CAPABILITIES capabilities; - if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) { - /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */ - /* !!! FIXME: we might want to support steering wheels or guitars or whatever later. */ - if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) { - AddXInputDevice(userid, pContext); - } - } - } - } -} - - -/* detect any new joysticks being inserted into the system */ -void SDL_SYS_JoystickDetect() -{ - JoyStick_DeviceData *pCurList = NULL; - /* only enum the devices if the joystick thread told us something changed */ - if ( s_bDeviceAdded || s_bDeviceRemoved ) - { - SDL_LockMutex( s_mutexJoyStickEnum ); - - s_bDeviceAdded = SDL_FALSE; - s_bDeviceRemoved = SDL_FALSE; - - pCurList = SYS_Joystick; - SYS_Joystick = NULL; - - /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */ - IDirectInput8_EnumDevices(dinput, - DI8DEVCLASS_GAMECTRL, - EnumJoysticksCallback, - &pCurList, DIEDFL_ATTACHEDONLY); - - SDL_free(SDL_RawDevList); /* in case we used this in DirectInput enumerator. */ - SDL_RawDevList = NULL; - SDL_RawDevListCount = 0; - - /* Look for XInput devices. Do this last, so they're first in the final list. */ - EnumXInputDevices(&pCurList); - - SDL_UnlockMutex( s_mutexJoyStickEnum ); - } - - if ( pCurList ) - { - while ( pCurList ) - { - JoyStick_DeviceData *pListNext = NULL; - -#if SDL_HAPTIC_DINPUT - if (pCurList->bXInputDevice) { - XInputHaptic_MaybeRemoveDevice(pCurList->XInputUserId); - } else { - DirectInputHaptic_MaybeRemoveDevice(&pCurList->dxdevice); - } -#endif - -#if !SDL_EVENTS_DISABLED - { - SDL_Event event; - event.type = SDL_JOYDEVICEREMOVED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = pCurList->nInstanceID; - if ((SDL_EventOK == NULL) - || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } - } -#endif /* !SDL_EVENTS_DISABLED */ - - pListNext = pCurList->pNext; - SDL_free(pCurList->joystickname); - SDL_free(pCurList); - pCurList = pListNext; - } - - } - - if ( s_bDeviceAdded ) - { - JoyStick_DeviceData *pNewJoystick; - int device_index = 0; - s_bDeviceAdded = SDL_FALSE; - pNewJoystick = SYS_Joystick; - while ( pNewJoystick ) - { - if ( pNewJoystick->send_add_event ) - { -#if SDL_HAPTIC_DINPUT - if (pNewJoystick->bXInputDevice) { - XInputHaptic_MaybeAddDevice(pNewJoystick->XInputUserId); - } else { - DirectInputHaptic_MaybeAddDevice(&pNewJoystick->dxdevice); - } -#endif - -#if !SDL_EVENTS_DISABLED - { - SDL_Event event; - event.type = SDL_JOYDEVICEADDED; - - if (SDL_GetEventState(event.type) == SDL_ENABLE) { - event.jdevice.which = device_index; - if ((SDL_EventOK == NULL) - || (*SDL_EventOK) (SDL_EventOKParam, &event)) { - SDL_PushEvent(&event); - } - } - } -#endif /* !SDL_EVENTS_DISABLED */ - pNewJoystick->send_add_event = 0; - } - device_index++; - pNewJoystick = pNewJoystick->pNext; - } - } -} - -/* we need to poll if we have pending hotplug device changes or connected devices */ -SDL_bool SDL_SYS_JoystickNeedsPolling() -{ - /* we have a new device or one was pulled, we need to think this frame please */ - if ( s_bDeviceAdded || s_bDeviceRemoved ) - return SDL_TRUE; - - return SDL_FALSE; -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) -{ - JoyStick_DeviceData *device = SYS_Joystick; - - for (; device_index > 0; device_index--) - device = device->pNext; - - return device->joystickname; -} - -/* Function to perform the mapping between current device instance and this joysticks instance id */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) -{ - JoyStick_DeviceData *device = SYS_Joystick; - int index; - - for (index = device_index; index > 0; index--) - device = device->pNext; - - return device->nInstanceID; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) -{ - HRESULT result; - JoyStick_DeviceData *joystickdevice = SYS_Joystick; - - for (; device_index > 0; device_index--) - joystickdevice = joystickdevice->pNext; - - /* allocate memory for system specific hardware data */ - joystick->instance_id = joystickdevice->nInstanceID; - joystick->closed = 0; - joystick->hwdata = - (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); - if (joystick->hwdata == NULL) { - return SDL_OutOfMemory(); - } - SDL_zerop(joystick->hwdata); - - if (joystickdevice->bXInputDevice) { - const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); - const Uint8 userId = joystickdevice->XInputUserId; - XINPUT_CAPABILITIES capabilities; - - SDL_assert(s_bXInputEnabled); - SDL_assert(XINPUTGETCAPABILITIES); - SDL_assert(userId >= 0); - SDL_assert(userId < SDL_XINPUT_MAX_DEVICES); - - joystick->hwdata->bXInputDevice = SDL_TRUE; - - if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) { - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?"); - } else { - /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */ - SDL_assert(capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD); - if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) { - joystick->hwdata->bXInputHaptic = SDL_TRUE; - } - joystick->hwdata->userid = userId; - - /* The XInput API has a hard coded button/axis mapping, so we just match it */ - joystick->naxes = 6; - joystick->nbuttons = 15; - joystick->nballs = 0; - joystick->nhats = 0; - } - } else { /* use DirectInput, not XInput. */ - LPDIRECTINPUTDEVICE8 device; - DIPROPDWORD dipdw; - - joystick->hwdata->buffered = 1; - joystick->hwdata->removed = 0; - joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS); - joystick->hwdata->guid = joystickdevice->guid; - - SDL_zero(dipdw); - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - - result = - IDirectInput8_CreateDevice(dinput, - &(joystickdevice->dxdevice.guidInstance), &device, NULL); - if (FAILED(result)) { - return SetDIerror("IDirectInput::CreateDevice", result); - } - - /* Now get the IDirectInputDevice8 interface, instead. */ - result = IDirectInputDevice8_QueryInterface(device, - &IID_IDirectInputDevice8, - (LPVOID *) & joystick-> - hwdata->InputDevice); - /* We are done with this object. Use the stored one from now on. */ - IDirectInputDevice8_Release(device); - - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::QueryInterface", result); - } - - /* Acquire shared access. Exclusive access is required for forces, - * though. */ - result = - IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata-> - InputDevice, SDL_HelperWindow, - DISCL_NONEXCLUSIVE | - DISCL_BACKGROUND); - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); - } - - /* Use the extended data structure: DIJOYSTATE2. */ - result = - IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice, - &c_dfDIJoystick2); - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::SetDataFormat", result); - } - - /* Get device capabilities */ - result = - IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice, - &joystick->hwdata->Capabilities); - - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::GetCapabilities", result); - } - - /* Force capable? */ - if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) { - - result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); - - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::Acquire", result); - } - - /* reset all accuators. */ - result = - IDirectInputDevice8_SendForceFeedbackCommand(joystick->hwdata-> - InputDevice, - DISFFC_RESET); - - /* Not necessarily supported, ignore if not supported. - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result); - } - */ - - result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); - - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::Unacquire", result); - } - - /* Turn on auto-centering for a ForceFeedback device (until told - * otherwise). */ - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DIPROPAUTOCENTER_ON; - - result = - IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, - DIPROP_AUTOCENTER, &dipdw.diph); - - /* Not necessarily supported, ignore if not supported. - if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::SetProperty", result); - } - */ - } - - /* What buttons and axes does it have? */ - IDirectInputDevice8_EnumObjects(joystick->hwdata->InputDevice, - EnumDevObjectsCallback, joystick, - DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); - - /* Reorder the input objects. Some devices do not report the X axis as - * the first axis, for example. */ - SortDevObjects(joystick); - - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = INPUT_QSIZE; - - /* Set the buffer size */ - result = - IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, - DIPROP_BUFFERSIZE, &dipdw.diph); - - if (result == DI_POLLEDDEVICE) { - /* This device doesn't support buffering, so we're forced - * to use less reliable polling. */ - joystick->hwdata->buffered = 0; - } else if (FAILED(result)) { - return SetDIerror("IDirectInputDevice8::SetProperty", result); - } - } - return (0); -} - -/* return true if this joystick is plugged in right now */ -SDL_bool SDL_SYS_JoystickAttached( SDL_Joystick * joystick ) -{ - return joystick->closed == 0 && joystick->hwdata->removed == 0; -} - - -/* Sort using the data offset into the DInput struct. - * This gives a reasonable ordering for the inputs. */ -static int -SortDevFunc(const void *a, const void *b) -{ - const input_t *inputA = (const input_t*)a; - const input_t *inputB = (const input_t*)b; - - if (inputA->ofs < inputB->ofs) - return -1; - if (inputA->ofs > inputB->ofs) - return 1; - return 0; -} - -/* Sort the input objects and recalculate the indices for each input. */ -static void -SortDevObjects(SDL_Joystick *joystick) -{ - input_t *inputs = joystick->hwdata->Inputs; - int nButtons = 0; - int nHats = 0; - int nAxis = 0; - int n; - - SDL_qsort(inputs, joystick->hwdata->NumInputs, sizeof(input_t), SortDevFunc); - - for (n = 0; n < joystick->hwdata->NumInputs; n++) - { - switch (inputs[n].type) - { - case BUTTON: - inputs[n].num = nButtons; - nButtons++; - break; - - case HAT: - inputs[n].num = nHats; - nHats++; - break; - - case AXIS: - inputs[n].num = nAxis; - nAxis++; - break; - } - } -} - -static BOOL CALLBACK -EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef) -{ - SDL_Joystick *joystick = (SDL_Joystick *) pvRef; - HRESULT result; - input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs]; - - if (dev->dwType & DIDFT_BUTTON) { - in->type = BUTTON; - in->num = joystick->nbuttons; - in->ofs = DIJOFS_BUTTON( in->num ); - joystick->nbuttons++; - } else if (dev->dwType & DIDFT_POV) { - in->type = HAT; - in->num = joystick->nhats; - in->ofs = DIJOFS_POV( in->num ); - joystick->nhats++; - } else if (dev->dwType & DIDFT_AXIS) { - DIPROPRANGE diprg; - DIPROPDWORD dilong; - - in->type = AXIS; - in->num = joystick->naxes; - /* work our the axis this guy maps too, thanks for the code icculus! */ - if ( !SDL_memcmp( &dev->guidType, &GUID_XAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_X; - else if ( !SDL_memcmp( &dev->guidType, &GUID_YAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_Y; - else if ( !SDL_memcmp( &dev->guidType, &GUID_ZAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_Z; - else if ( !SDL_memcmp( &dev->guidType, &GUID_RxAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_RX; - else if ( !SDL_memcmp( &dev->guidType, &GUID_RyAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_RY; - else if ( !SDL_memcmp( &dev->guidType, &GUID_RzAxis, sizeof(dev->guidType) ) ) - in->ofs = DIJOFS_RZ; - else if ( !SDL_memcmp( &dev->guidType, &GUID_Slider, sizeof(dev->guidType) ) ) - { - in->ofs = DIJOFS_SLIDER( joystick->hwdata->NumSliders ); - ++joystick->hwdata->NumSliders; - } - else - { - return DIENUM_CONTINUE; /* not an axis we can grok */ - } - - diprg.diph.dwSize = sizeof(diprg); - diprg.diph.dwHeaderSize = sizeof(diprg.diph); - diprg.diph.dwObj = dev->dwType; - diprg.diph.dwHow = DIPH_BYID; - diprg.lMin = AXIS_MIN; - diprg.lMax = AXIS_MAX; - - result = - IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, - DIPROP_RANGE, &diprg.diph); - if (FAILED(result)) { - return DIENUM_CONTINUE; /* don't use this axis */ - } - - /* Set dead zone to 0. */ - dilong.diph.dwSize = sizeof(dilong); - dilong.diph.dwHeaderSize = sizeof(dilong.diph); - dilong.diph.dwObj = dev->dwType; - dilong.diph.dwHow = DIPH_BYID; - dilong.dwData = 0; - result = - IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, - DIPROP_DEADZONE, &dilong.diph); - if (FAILED(result)) { - return DIENUM_CONTINUE; /* don't use this axis */ - } - - joystick->naxes++; - } else { - /* not supported at this time */ - return DIENUM_CONTINUE; - } - - joystick->hwdata->NumInputs++; - - if (joystick->hwdata->NumInputs == MAX_INPUTS) { - return DIENUM_STOP; /* too many */ - } - - return DIENUM_CONTINUE; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void -SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick) -{ - DIJOYSTATE2 state; - HRESULT result; - int i; - - result = - IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice, - sizeof(DIJOYSTATE2), &state); - if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { - IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); - result = - IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice, - sizeof(DIJOYSTATE2), &state); - } - - if ( result != DI_OK ) - { - joystick->hwdata->send_remove_event = 1; - joystick->hwdata->removed = 1; - return; - } - - /* Set each known axis, button and POV. */ - for (i = 0; i < joystick->hwdata->NumInputs; ++i) { - const input_t *in = &joystick->hwdata->Inputs[i]; - - switch (in->type) { - case AXIS: - switch (in->ofs) { - case DIJOFS_X: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lX); - break; - case DIJOFS_Y: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lY); - break; - case DIJOFS_Z: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lZ); - break; - case DIJOFS_RX: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lRx); - break; - case DIJOFS_RY: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lRy); - break; - case DIJOFS_RZ: - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.lRz); - break; - case DIJOFS_SLIDER(0): - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.rglSlider[0]); - break; - case DIJOFS_SLIDER(1): - SDL_PrivateJoystickAxis_Int(joystick, in->num, - (Sint16) state.rglSlider[1]); - break; - } - - break; - - case BUTTON: - SDL_PrivateJoystickButton_Int(joystick, in->num, - (Uint8) (state. - rgbButtons[in->ofs - - DIJOFS_BUTTON0] - ? SDL_PRESSED : - SDL_RELEASED)); - break; - case HAT: - { - Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - - DIJOFS_POV(0)]); - SDL_PrivateJoystickHat_Int(joystick, in->num, pos); - break; - } - } - } -} - -void -SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick) -{ - int i; - HRESULT result; - DWORD numevents; - DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; - - numevents = INPUT_QSIZE; - result = - IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice, - sizeof(DIDEVICEOBJECTDATA), evtbuf, - &numevents, 0); - if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { - IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); - result = - IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice, - sizeof(DIDEVICEOBJECTDATA), - evtbuf, &numevents, 0); - } - - /* Handle the events or punt */ - if (FAILED(result)) - { - joystick->hwdata->send_remove_event = 1; - joystick->hwdata->removed = 1; - return; - } - - for (i = 0; i < (int) numevents; ++i) { - int j; - - for (j = 0; j < joystick->hwdata->NumInputs; ++j) { - const input_t *in = &joystick->hwdata->Inputs[j]; - - if (evtbuf[i].dwOfs != in->ofs) - continue; - - switch (in->type) { - case AXIS: - SDL_PrivateJoystickAxis(joystick, in->num, - (Sint16) evtbuf[i].dwData); - break; - case BUTTON: - SDL_PrivateJoystickButton(joystick, in->num, - (Uint8) (evtbuf[i]. - dwData ? SDL_PRESSED : - SDL_RELEASED)); - break; - case HAT: - { - Uint8 pos = TranslatePOV(evtbuf[i].dwData); - SDL_PrivateJoystickHat(joystick, in->num, pos); - } - } - } - } -} - - -/* Function to return > 0 if a bit array of buttons differs after applying a mask -*/ -int ButtonChanged( int ButtonsNow, int ButtonsPrev, int ButtonMask ) -{ - return ( ButtonsNow & ButtonMask ) != ( ButtonsPrev & ButtonMask ); -} - -/* Function to update the state of a XInput style joystick. -*/ -void -SDL_SYS_JoystickUpdate_XInput(SDL_Joystick * joystick) -{ - HRESULT result; - - if ( !XINPUTGETSTATE ) - return; - - result = XINPUTGETSTATE( joystick->hwdata->userid, &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot] ); - if ( result == ERROR_DEVICE_NOT_CONNECTED ) - { - joystick->hwdata->send_remove_event = 1; - joystick->hwdata->removed = 1; - return; - } - - /* only fire events if the data changed from last time */ - if ( joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot].dwPacketNumber != 0 - && joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot].dwPacketNumber != joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot^1].dwPacketNumber ) - { - XINPUT_STATE_EX *pXInputState = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot]; - XINPUT_STATE_EX *pXInputStatePrev = &joystick->hwdata->XInputState[joystick->hwdata->currentXInputSlot ^ 1]; - - /* !!! FIXME: why isn't this just using SDL_PrivateJoystickAxis_Int()? */ - SDL_PrivateJoystickAxis( joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX ); - SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)) ); - SDL_PrivateJoystickAxis( joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX ); - SDL_PrivateJoystickAxis( joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)) ); - SDL_PrivateJoystickAxis( joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger*65535/255) - 32768)); - SDL_PrivateJoystickAxis( joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger*65535/255) - 32768)); - - /* !!! FIXME: why isn't this just using SDL_PrivateJoystickButton_Int(), instead of keeping these two alternating state buffers? */ - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_UP ) ) - SDL_PrivateJoystickButton(joystick, 0, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_DOWN ) ) - SDL_PrivateJoystickButton(joystick, 1, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_LEFT ) ) - SDL_PrivateJoystickButton(joystick, 2, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_RIGHT ) ) - SDL_PrivateJoystickButton(joystick, 3, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_START ) ) - SDL_PrivateJoystickButton(joystick, 4, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_START ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_BACK ) ) - SDL_PrivateJoystickButton(joystick, 5, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_BACK ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_LEFT_THUMB ) ) - SDL_PrivateJoystickButton(joystick, 6, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_RIGHT_THUMB ) ) - SDL_PrivateJoystickButton(joystick, 7, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_LEFT_SHOULDER ) ) - SDL_PrivateJoystickButton(joystick, 8, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_RIGHT_SHOULDER ) ) - SDL_PrivateJoystickButton(joystick, 9, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_A ) ) - SDL_PrivateJoystickButton(joystick, 10, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_A ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_B ) ) - SDL_PrivateJoystickButton(joystick, 11, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_B ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_X ) ) - SDL_PrivateJoystickButton(joystick, 12, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_X ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, XINPUT_GAMEPAD_Y ) ) - SDL_PrivateJoystickButton(joystick, 13, pXInputState->Gamepad.wButtons & XINPUT_GAMEPAD_Y ? SDL_PRESSED : SDL_RELEASED ); - if ( ButtonChanged( pXInputState->Gamepad.wButtons, pXInputStatePrev->Gamepad.wButtons, 0x400 ) ) - SDL_PrivateJoystickButton(joystick, 14, pXInputState->Gamepad.wButtons & 0x400 ? SDL_PRESSED : SDL_RELEASED ); /* 0x400 is the undocumented code for the guide button */ - - joystick->hwdata->currentXInputSlot ^= 1; - - } -} - - -static Uint8 -TranslatePOV(DWORD value) -{ - const int HAT_VALS[] = { - SDL_HAT_UP, - SDL_HAT_UP | SDL_HAT_RIGHT, - SDL_HAT_RIGHT, - SDL_HAT_DOWN | SDL_HAT_RIGHT, - SDL_HAT_DOWN, - SDL_HAT_DOWN | SDL_HAT_LEFT, - SDL_HAT_LEFT, - SDL_HAT_UP | SDL_HAT_LEFT - }; - - if (LOWORD(value) == 0xFFFF) - return SDL_HAT_CENTERED; - - /* Round the value up: */ - value += 4500 / 2; - value %= 36000; - value /= 4500; - - if (value >= 8) - return SDL_HAT_CENTERED; /* shouldn't happen */ - - return HAT_VALS[value]; -} - -/* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to - * do it. */ -/* !!! FIXME: SDL_PrivateJoystickAxis _does_ discard duplicate events now. Ditch this code. */ -static int -SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value) -{ - if (joystick->axes[axis] != value) - return SDL_PrivateJoystickAxis(joystick, axis, value); - return 0; -} - -static int -SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, Uint8 value) -{ - if (joystick->hats[hat] != value) - return SDL_PrivateJoystickHat(joystick, hat, value); - return 0; -} - -static int -SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button, - Uint8 state) -{ - if (joystick->buttons[button] != state) - return SDL_PrivateJoystickButton(joystick, button, state); - return 0; -} - -void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ - HRESULT result; - - if ( joystick->closed || !joystick->hwdata ) - return; - - if (joystick->hwdata->bXInputDevice) - { - SDL_SYS_JoystickUpdate_XInput(joystick); - } - else - { - result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice); - if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { - IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); - IDirectInputDevice8_Poll(joystick->hwdata->InputDevice); - } - - if (joystick->hwdata->buffered) - SDL_SYS_JoystickUpdate_Buffered(joystick); - else - SDL_SYS_JoystickUpdate_Polled(joystick); - } - - if ( joystick->hwdata->removed ) - { - joystick->closed = 1; - joystick->uncentered = 1; - } -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ - if (!joystick->hwdata->bXInputDevice) { - IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); - IDirectInputDevice8_Release(joystick->hwdata->InputDevice); - } - - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - - joystick->closed = 1; -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ - JoyStick_DeviceData *device = SYS_Joystick; - - while ( device ) - { - JoyStick_DeviceData *device_next = device->pNext; - SDL_free(device->joystickname); - SDL_free(device); - device = device_next; - } - SYS_Joystick = NULL; - - if ( s_threadJoystick ) - { - SDL_LockMutex( s_mutexJoyStickEnum ); - s_bJoystickThreadQuit = SDL_TRUE; - SDL_CondBroadcast( s_condJoystickThread ); /* signal the joystick thread to quit */ - SDL_UnlockMutex( s_mutexJoyStickEnum ); - SDL_WaitThread( s_threadJoystick, NULL ); /* wait for it to bugger off */ - - SDL_DestroyMutex( s_mutexJoyStickEnum ); - SDL_DestroyCond( s_condJoystickThread ); - s_condJoystickThread= NULL; - s_mutexJoyStickEnum = NULL; - s_threadJoystick = NULL; - } - - if (dinput != NULL) { - IDirectInput8_Release(dinput); - dinput = NULL; - } - - if (coinitialized) { - WIN_CoUninitialize(); - coinitialized = SDL_FALSE; - } - - if (s_bXInputEnabled) { - WIN_UnloadXInputDLL(); - } -} - -/* return the stable device guid for this device index */ -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - JoyStick_DeviceData *device = SYS_Joystick; - int index; - - for (index = device_index; index > 0; index--) - device = device->pNext; - - return device->guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - return joystick->hwdata->guid; -} - -/* return SDL_TRUE if this device is using XInput */ -SDL_bool SDL_SYS_IsXInputDeviceIndex(int device_index) -{ - JoyStick_DeviceData *device = SYS_Joystick; - int index; - - for (index = device_index; index > 0; index--) - device = device->pNext; - - return device->bXInputDevice; -} - -/* return SDL_TRUE if this device was opened with XInput */ -SDL_bool SDL_SYS_IsXInputJoystick(SDL_Joystick * joystick) -{ - return joystick->hwdata->bXInputDevice; -} - -#endif /* SDL_JOYSTICK_DINPUT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick_c.h b/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick_c.h deleted file mode 100644 index 2808fed5..00000000 --- a/jni/SDL2-2.0.3/src/joystick/windows/SDL_dxjoystick_c.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#ifndef SDL_JOYSTICK_DINPUT_H - -/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de - * A. Formiga's WINMM driver. - * - * Hats and sliders are completely untested; the app I'm writing this for mostly - * doesn't use them and I don't own any joysticks with them. - * - * We don't bother to use event notification here. It doesn't seem to work - * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and - * let it return 0 events. */ - -#include "../../core/windows/SDL_windows.h" - -#define DIRECTINPUT_VERSION 0x0800 /* Need version 7 for force feedback. Need version 8 so IDirectInput8_EnumDevices doesn't leak like a sieve... */ -#include -#define COBJMACROS -#include -#include -#include -#include -#include - - -#ifndef XUSER_MAX_COUNT -#define XUSER_MAX_COUNT 4 -#endif -#ifndef XUSER_INDEX_ANY -#define XUSER_INDEX_ANY 0x000000FF -#endif -#ifndef XINPUT_CAPS_FFB_SUPPORTED -#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 -#endif - - -/* typedef's for XInput structs we use */ -typedef struct -{ - WORD wButtons; - BYTE bLeftTrigger; - BYTE bRightTrigger; - SHORT sThumbLX; - SHORT sThumbLY; - SHORT sThumbRX; - SHORT sThumbRY; - DWORD dwPaddingReserved; -} XINPUT_GAMEPAD_EX; - -typedef struct -{ - DWORD dwPacketNumber; - XINPUT_GAMEPAD_EX Gamepad; -} XINPUT_STATE_EX; - -/* Forward decl's for XInput API's we load dynamically and use if available */ -typedef DWORD (WINAPI *XInputGetState_t) - ( - DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */ - XINPUT_STATE_EX* pState /* [out] Receives the current state */ - ); - -typedef DWORD (WINAPI *XInputSetState_t) - ( - DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */ - XINPUT_VIBRATION* pVibration /* [in, out] The vibration information to send to the controller */ - ); - -typedef DWORD (WINAPI *XInputGetCapabilities_t) - ( - DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */ - DWORD dwFlags, /* [in] Input flags that identify the device type */ - XINPUT_CAPABILITIES* pCapabilities /* [out] Receives the capabilities */ - ); - -extern int WIN_LoadXInputDLL(void); -extern void WIN_UnloadXInputDLL(void); - -extern XInputGetState_t SDL_XInputGetState; -extern XInputSetState_t SDL_XInputSetState; -extern XInputGetCapabilities_t SDL_XInputGetCapabilities; -extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */ - -#define XINPUTGETSTATE SDL_XInputGetState -#define XINPUTSETSTATE SDL_XInputSetState -#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities -#define INVALID_XINPUT_USERID XUSER_INDEX_ANY -#define SDL_XINPUT_MAX_DEVICES XUSER_MAX_COUNT - -#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ - - -/* local types */ -typedef enum Type -{ BUTTON, AXIS, HAT } Type; - -typedef struct input_t -{ - /* DirectInput offset for this input type: */ - DWORD ofs; - - /* Button, axis or hat: */ - Type type; - - /* SDL input offset: */ - Uint8 num; -} input_t; - -/* The private structure used to keep track of a joystick */ -struct joystick_hwdata -{ - LPDIRECTINPUTDEVICE8 InputDevice; - DIDEVCAPS Capabilities; - int buffered; - SDL_JoystickGUID guid; - - input_t Inputs[MAX_INPUTS]; - int NumInputs; - int NumSliders; - Uint8 removed; - Uint8 send_remove_event; - Uint8 bXInputDevice; /* 1 if this device supports using the xinput API rather than DirectInput */ - Uint8 bXInputHaptic; /* Supports force feedback via XInput. */ - Uint8 userid; /* XInput userid index for this joystick */ - Uint8 currentXInputSlot; /* the current position to write to in XInputState below, used so we can compare old and new values */ - XINPUT_STATE_EX XInputState[2]; -}; - -#endif /* SDL_JOYSTICK_DINPUT_H */ diff --git a/jni/SDL2-2.0.3/src/joystick/windows/SDL_mmjoystick.c b/jni/SDL2-2.0.3/src/joystick/windows/SDL_mmjoystick.c deleted file mode 100644 index c28ed91b..00000000 --- a/jni/SDL2-2.0.3/src/joystick/windows/SDL_mmjoystick.c +++ /dev/null @@ -1,475 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#ifdef SDL_JOYSTICK_WINMM - -/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ - -#include "../../core/windows/SDL_windows.h" -#include -#include - -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#ifdef REGSTR_VAL_JOYOEMNAME -#undef REGSTR_VAL_JOYOEMNAME -#endif -#define REGSTR_VAL_JOYOEMNAME "OEMName" - -#define MAX_JOYSTICKS 16 -#define MAX_AXES 6 /* each joystick can have up to 6 axes */ -#define MAX_BUTTONS 32 /* and 32 buttons */ -#define AXIS_MIN -32768 /* minimum value for axis coordinate */ -#define AXIS_MAX 32767 /* maximum value for axis coordinate */ -/* limit axis to 256 possible positions to filter out noise */ -#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256) -#define JOY_BUTTON_FLAG(n) (1<instance_id = device_index; - joystick->hwdata = - (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) { - return SDL_OutOfMemory(); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - - /* set hardware data */ - joystick->hwdata->id = SYS_JoystickID[index]; - for (i = 0; i < MAX_AXES; ++i) { - if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) { - joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i]; - joystick->hwdata->transaxis[i].scale = - (float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); - } else { - joystick->hwdata->transaxis[i].offset = 0; - joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ - } - } - - /* fill nbuttons, naxes, and nhats fields */ - joystick->nbuttons = SYS_Joystick[index].wNumButtons; - joystick->naxes = SYS_Joystick[index].wNumAxes; - if (SYS_Joystick[index].wCaps & JOYCAPS_HASPOV) { - joystick->nhats = 1; - } else { - joystick->nhats = 0; - } - return (0); -} - -/* Function to determine is this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -static Uint8 -TranslatePOV(DWORD value) -{ - Uint8 pos; - - pos = SDL_HAT_CENTERED; - if (value != JOY_POVCENTERED) { - if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) { - pos |= SDL_HAT_UP; - } - if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) { - pos |= SDL_HAT_RIGHT; - } - if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) { - pos |= SDL_HAT_DOWN; - } - if (value > JOY_POVBACKWARD) { - pos |= SDL_HAT_LEFT; - } - } - return (pos); -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ - MMRESULT result; - int i; - DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, - JOY_RETURNR, JOY_RETURNU, JOY_RETURNV - }; - DWORD pos[MAX_AXES]; - struct _transaxis *transaxis; - int value, change; - JOYINFOEX joyinfo; - - joyinfo.dwSize = sizeof(joyinfo); - joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS; - if (!joystick->hats) { - joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS); - } - result = joyGetPosEx(joystick->hwdata->id, &joyinfo); - if (result != JOYERR_NOERROR) { - SetMMerror("joyGetPosEx", result); - return; - } - - /* joystick motion events */ - pos[0] = joyinfo.dwXpos; - pos[1] = joyinfo.dwYpos; - pos[2] = joyinfo.dwZpos; - pos[3] = joyinfo.dwRpos; - pos[4] = joyinfo.dwUpos; - pos[5] = joyinfo.dwVpos; - - transaxis = joystick->hwdata->transaxis; - for (i = 0; i < joystick->naxes; i++) { - if (joyinfo.dwFlags & flags[i]) { - value = - (int) (((float) pos[i] + - transaxis[i].offset) * transaxis[i].scale); - change = (value - joystick->axes[i]); - if ((change < -JOY_AXIS_THRESHOLD) - || (change > JOY_AXIS_THRESHOLD)) { - SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value); - } - } - } - - /* joystick button events */ - if (joyinfo.dwFlags & JOY_RETURNBUTTONS) { - for (i = 0; i < joystick->nbuttons; ++i) { - if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) { - if (!joystick->buttons[i]) { - SDL_PrivateJoystickButton(joystick, (Uint8) i, - SDL_PRESSED); - } - } else { - if (joystick->buttons[i]) { - SDL_PrivateJoystickButton(joystick, (Uint8) i, - SDL_RELEASED); - } - } - } - } - - /* joystick hat events */ - if (joyinfo.dwFlags & JOY_RETURNPOV) { - Uint8 pos; - - pos = TranslatePOV(joyinfo.dwPOV); - if (pos != joystick->hats[0]) { - SDL_PrivateJoystickHat(joystick, 0, pos); - } - } -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ - int i; - for (i = 0; i < MAX_JOYSTICKS; i++) { - SDL_free(SYS_JoystickName[i]); - SYS_JoystickName[i] = NULL; - } -} - -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - SDL_JoystickGUID guid; - /* the GUID is just the first 16 chars of the name for now */ - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - /* the GUID is just the first 16 chars of the name for now */ - const char *name = joystick->name; - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - - -/* implementation functions */ -void -SetMMerror(char *function, int code) -{ - static char *error; - static char errbuf[1024]; - - errbuf[0] = 0; - switch (code) { - case MMSYSERR_NODRIVER: - error = "Joystick driver not present"; - break; - - case MMSYSERR_INVALPARAM: - case JOYERR_PARMS: - error = "Invalid parameter(s)"; - break; - - case MMSYSERR_BADDEVICEID: - error = "Bad device ID"; - break; - - case JOYERR_UNPLUGGED: - error = "Joystick not attached"; - break; - - case JOYERR_NOCANDO: - error = "Can't capture joystick input"; - break; - - default: - SDL_snprintf(errbuf, SDL_arraysize(errbuf), - "%s: Unknown Multimedia system error: 0x%x", - function, code); - break; - } - - if (!errbuf[0]) { - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, - error); - } - SDL_SetError("%s", errbuf); -} - -#endif /* SDL_JOYSTICK_WINMM */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents.cpp deleted file mode 100644 index 7c0cf49a..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if SDL_VIDEO_DRIVER_WINRT - -/* - * Windows includes: - */ -#include -using namespace Windows::UI::Core; -using Windows::UI::Core::CoreCursor; - -/* - * SDL includes: - */ -#include "SDL_winrtevents_c.h" -#include "../../core/winrt/SDL_winrtapp_common.h" -#include "../../core/winrt/SDL_winrtapp_direct3d.h" -#include "../../core/winrt/SDL_winrtapp_xaml.h" -#include "SDL_assert.h" -#include "SDL_system.h" - -extern "C" { -#include "../SDL_sysvideo.h" -#include "../../events/SDL_events_c.h" -} - - -/* Forward declarations */ -static void WINRT_YieldXAMLThread(); - - -/* Global event management */ - -void -WINRT_PumpEvents(_THIS) -{ - if (SDL_WinRTGlobalApp) { - SDL_WinRTGlobalApp->PumpEvents(); - } else if (WINRT_XAMLWasEnabled) { - WINRT_YieldXAMLThread(); - } -} - - -/* XAML Thread management */ - -enum SDL_XAMLAppThreadState -{ - ThreadState_NotLaunched = 0, - ThreadState_Running, - ThreadState_Yielding -}; - -static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched; -static SDL_Thread * _XAMLThread = nullptr; -static SDL_mutex * _mutex = nullptr; -static SDL_cond * _cond = nullptr; - -static void -WINRT_YieldXAMLThread() -{ - SDL_LockMutex(_mutex); - SDL_assert(_threadState == ThreadState_Running); - _threadState = ThreadState_Yielding; - SDL_UnlockMutex(_mutex); - - SDL_CondSignal(_cond); - - SDL_LockMutex(_mutex); - while (_threadState != ThreadState_Running) { - SDL_CondWait(_cond, _mutex); - } - SDL_UnlockMutex(_mutex); -} - -static int -WINRT_XAMLThreadMain(void * userdata) -{ - // TODO, WinRT: pass the C-style main() a reasonably realistic - // representation of command line arguments. - int argc = 0; - char **argv = NULL; - return WINRT_SDLAppEntryPoint(argc, argv); -} - -void -WINRT_CycleXAMLThread() -{ - switch (_threadState) { - case ThreadState_NotLaunched: - { - _cond = SDL_CreateCond(); - - _mutex = SDL_CreateMutex(); - _threadState = ThreadState_Running; - _XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr); - - SDL_LockMutex(_mutex); - while (_threadState != ThreadState_Yielding) { - SDL_CondWait(_cond, _mutex); - } - SDL_UnlockMutex(_mutex); - - break; - } - - case ThreadState_Running: - { - SDL_assert(false); - break; - } - - case ThreadState_Yielding: - { - SDL_LockMutex(_mutex); - SDL_assert(_threadState == ThreadState_Yielding); - _threadState = ThreadState_Running; - SDL_UnlockMutex(_mutex); - - SDL_CondSignal(_cond); - - SDL_LockMutex(_mutex); - while (_threadState != ThreadState_Yielding) { - SDL_CondWait(_cond, _mutex); - } - SDL_UnlockMutex(_mutex); - } - } -} - -#endif /* SDL_VIDEO_DRIVER_WINRT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents_c.h b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents_c.h deleted file mode 100644 index 826cad74..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtevents_c.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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" - -extern "C" { -#include "../SDL_sysvideo.h" -} - -/* - * Internal-use, C-style functions: - */ - -#ifdef __cplusplus -extern "C" { -#endif - -extern void WINRT_InitTouch(_THIS); -extern void WINRT_PumpEvents(_THIS); - -#ifdef __cplusplus -} -#endif - - -/* - * Internal-use, C++/CX functions: - */ -#ifdef __cplusplus_winrt - -/* Pointers (Mice, Touch, etc.) */ -typedef enum { - NormalizeZeroToOne, - TransformToSDLWindowSize -} WINRT_CursorNormalizationType; -extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, - Windows::Foundation::Point rawPosition, - WINRT_CursorNormalizationType normalization); -extern Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt); -extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint); -extern void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint); -extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint); -extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint); -extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args); - -/* Keyboard */ -extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args); -extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args); - -/* XAML Thread Management */ -extern void WINRT_CycleXAMLThread(); - -#endif // ifdef __cplusplus_winrt - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtkeyboard.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtkeyboard.cpp deleted file mode 100644 index f2fa59d6..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtkeyboard.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if SDL_VIDEO_DRIVER_WINRT - -/* Standard C++11 includes */ -#include - - -/* Windows-specific includes */ -#include -#include - - -/* SDL-specific includes */ -#include -#include "SDL_winrtevents_c.h" - -extern "C" { -#include "../../events/scancodes_windows.h" -#include "../../events/SDL_keyboard_c.h" -} - - -static SDL_Scancode WinRT_Official_Keycodes[] = { - SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0 - SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1 - SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2 - SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3 - SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4 - SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5 - SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6 - SDL_SCANCODE_UNKNOWN, // -- 7 - SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8 - SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9 - SDL_SCANCODE_UNKNOWN, // -- 10 - SDL_SCANCODE_UNKNOWN, // -- 11 - SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12 - SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13 - SDL_SCANCODE_UNKNOWN, // -- 14 - SDL_SCANCODE_UNKNOWN, // -- 15 - SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16 - SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17 - SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18 - SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19 - SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21 - SDL_SCANCODE_UNKNOWN, // -- 22 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25 - SDL_SCANCODE_UNKNOWN, // -- 26 - SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28 - SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30 - SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?) - SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32 - SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33 - SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34 - SDL_SCANCODE_END, // VirtualKey.End -- 35 - SDL_SCANCODE_HOME, // VirtualKey.Home -- 36 - SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37 - SDL_SCANCODE_UP, // VirtualKey.Up -- 38 - SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39 - SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40 - SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?) - SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44 - SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45 - SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46 - SDL_SCANCODE_HELP, // VirtualKey.Help -- 47 - SDL_SCANCODE_0, // VirtualKey.Number0 -- 48 - SDL_SCANCODE_1, // VirtualKey.Number1 -- 49 - SDL_SCANCODE_2, // VirtualKey.Number2 -- 50 - SDL_SCANCODE_3, // VirtualKey.Number3 -- 51 - SDL_SCANCODE_4, // VirtualKey.Number4 -- 52 - SDL_SCANCODE_5, // VirtualKey.Number5 -- 53 - SDL_SCANCODE_6, // VirtualKey.Number6 -- 54 - SDL_SCANCODE_7, // VirtualKey.Number7 -- 55 - SDL_SCANCODE_8, // VirtualKey.Number8 -- 56 - SDL_SCANCODE_9, // VirtualKey.Number9 -- 57 - SDL_SCANCODE_UNKNOWN, // -- 58 - SDL_SCANCODE_UNKNOWN, // -- 59 - SDL_SCANCODE_UNKNOWN, // -- 60 - SDL_SCANCODE_UNKNOWN, // -- 61 - SDL_SCANCODE_UNKNOWN, // -- 62 - SDL_SCANCODE_UNKNOWN, // -- 63 - SDL_SCANCODE_UNKNOWN, // -- 64 - SDL_SCANCODE_A, // VirtualKey.A -- 65 - SDL_SCANCODE_B, // VirtualKey.B -- 66 - SDL_SCANCODE_C, // VirtualKey.C -- 67 - SDL_SCANCODE_D, // VirtualKey.D -- 68 - SDL_SCANCODE_E, // VirtualKey.E -- 69 - SDL_SCANCODE_F, // VirtualKey.F -- 70 - SDL_SCANCODE_G, // VirtualKey.G -- 71 - SDL_SCANCODE_H, // VirtualKey.H -- 72 - SDL_SCANCODE_I, // VirtualKey.I -- 73 - SDL_SCANCODE_J, // VirtualKey.J -- 74 - SDL_SCANCODE_K, // VirtualKey.K -- 75 - SDL_SCANCODE_L, // VirtualKey.L -- 76 - SDL_SCANCODE_M, // VirtualKey.M -- 77 - SDL_SCANCODE_N, // VirtualKey.N -- 78 - SDL_SCANCODE_O, // VirtualKey.O -- 79 - SDL_SCANCODE_P, // VirtualKey.P -- 80 - SDL_SCANCODE_Q, // VirtualKey.Q -- 81 - SDL_SCANCODE_R, // VirtualKey.R -- 82 - SDL_SCANCODE_S, // VirtualKey.S -- 83 - SDL_SCANCODE_T, // VirtualKey.T -- 84 - SDL_SCANCODE_U, // VirtualKey.U -- 85 - SDL_SCANCODE_V, // VirtualKey.V -- 86 - SDL_SCANCODE_W, // VirtualKey.W -- 87 - SDL_SCANCODE_X, // VirtualKey.X -- 88 - SDL_SCANCODE_Y, // VirtualKey.Y -- 89 - SDL_SCANCODE_Z, // VirtualKey.Z -- 90 - SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?) - SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?) - SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93 - SDL_SCANCODE_UNKNOWN, // -- 94 - SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95 - SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96 - SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97 - SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98 - SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99 - SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100 - SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101 - SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102 - SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103 - SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104 - SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105 - SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106 - SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108 - SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109 - SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110 (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?) - SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111 - SDL_SCANCODE_F1, // VirtualKey.F1 -- 112 - SDL_SCANCODE_F2, // VirtualKey.F2 -- 113 - SDL_SCANCODE_F3, // VirtualKey.F3 -- 114 - SDL_SCANCODE_F4, // VirtualKey.F4 -- 115 - SDL_SCANCODE_F5, // VirtualKey.F5 -- 116 - SDL_SCANCODE_F6, // VirtualKey.F6 -- 117 - SDL_SCANCODE_F7, // VirtualKey.F7 -- 118 - SDL_SCANCODE_F8, // VirtualKey.F8 -- 119 - SDL_SCANCODE_F9, // VirtualKey.F9 -- 120 - SDL_SCANCODE_F10, // VirtualKey.F10 -- 121 - SDL_SCANCODE_F11, // VirtualKey.F11 -- 122 - SDL_SCANCODE_F12, // VirtualKey.F12 -- 123 - SDL_SCANCODE_F13, // VirtualKey.F13 -- 124 - SDL_SCANCODE_F14, // VirtualKey.F14 -- 125 - SDL_SCANCODE_F15, // VirtualKey.F15 -- 126 - SDL_SCANCODE_F16, // VirtualKey.F16 -- 127 - SDL_SCANCODE_F17, // VirtualKey.F17 -- 128 - SDL_SCANCODE_F18, // VirtualKey.F18 -- 129 - SDL_SCANCODE_F19, // VirtualKey.F19 -- 130 - SDL_SCANCODE_F20, // VirtualKey.F20 -- 131 - SDL_SCANCODE_F21, // VirtualKey.F21 -- 132 - SDL_SCANCODE_F22, // VirtualKey.F22 -- 133 - SDL_SCANCODE_F23, // VirtualKey.F23 -- 134 - SDL_SCANCODE_F24, // VirtualKey.F24 -- 135 - SDL_SCANCODE_UNKNOWN, // -- 136 - SDL_SCANCODE_UNKNOWN, // -- 137 - SDL_SCANCODE_UNKNOWN, // -- 138 - SDL_SCANCODE_UNKNOWN, // -- 139 - SDL_SCANCODE_UNKNOWN, // -- 140 - SDL_SCANCODE_UNKNOWN, // -- 141 - SDL_SCANCODE_UNKNOWN, // -- 142 - SDL_SCANCODE_UNKNOWN, // -- 143 - SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144 - SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145 - SDL_SCANCODE_UNKNOWN, // -- 146 - SDL_SCANCODE_UNKNOWN, // -- 147 - SDL_SCANCODE_UNKNOWN, // -- 148 - SDL_SCANCODE_UNKNOWN, // -- 149 - SDL_SCANCODE_UNKNOWN, // -- 150 - SDL_SCANCODE_UNKNOWN, // -- 151 - SDL_SCANCODE_UNKNOWN, // -- 152 - SDL_SCANCODE_UNKNOWN, // -- 153 - SDL_SCANCODE_UNKNOWN, // -- 154 - SDL_SCANCODE_UNKNOWN, // -- 155 - SDL_SCANCODE_UNKNOWN, // -- 156 - SDL_SCANCODE_UNKNOWN, // -- 157 - SDL_SCANCODE_UNKNOWN, // -- 158 - SDL_SCANCODE_UNKNOWN, // -- 159 - SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160 - SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161 - SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162 - SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163 - SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164 - SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165 -}; - -static std::unordered_map WinRT_Unofficial_Keycodes; - -static SDL_Scancode -TranslateKeycode(int keycode) -{ - if (WinRT_Unofficial_Keycodes.empty()) { - /* Set up a table of undocumented (by Microsoft), WinRT-specific, - key codes: */ - // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible - WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE; - WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH; - } - - /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at - http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ). - If that fails, fall back to a Win32 virtual key. - */ - // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints - //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode); - SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; - if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) { - scancode = WinRT_Official_Keycodes[keycode]; - } - if (scancode == SDL_SCANCODE_UNKNOWN) { - if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) { - scancode = WinRT_Unofficial_Keycodes[keycode]; - } - } - if (scancode == SDL_SCANCODE_UNKNOWN) { - if (keycode < SDL_arraysize(windows_scancode_table)) { - scancode = windows_scancode_table[keycode]; - } - } - if (scancode == SDL_SCANCODE_UNKNOWN) { - SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode); - } - return scancode; -} - -void -WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args) -{ - SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey); -#if 0 - SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode); - SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n", - (args->Handled ? "1" : "0"), - (args->KeyStatus.IsExtendedKey ? "1" : "0"), - (args->KeyStatus.IsKeyReleased ? "1" : "0"), - (args->KeyStatus.IsMenuKeyDown ? "1" : "0"), - args->KeyStatus.RepeatCount, - args->KeyStatus.ScanCode, - (args->KeyStatus.WasKeyDown ? "1" : "0"), - args->VirtualKey, - sdlScancode, - SDL_GetScancodeName(sdlScancode), - keycode, - SDL_GetKeyName(keycode)); - //args->Handled = true; - //VirtualKey vkey = args->VirtualKey; -#endif - SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode); -} - -void -WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args) -{ - SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey); -#if 0 - SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode); - SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n", - (args->Handled ? "1" : "0"), - (args->KeyStatus.IsExtendedKey ? "1" : "0"), - (args->KeyStatus.IsKeyReleased ? "1" : "0"), - (args->KeyStatus.IsMenuKeyDown ? "1" : "0"), - args->KeyStatus.RepeatCount, - args->KeyStatus.ScanCode, - (args->KeyStatus.WasKeyDown ? "1" : "0"), - args->VirtualKey, - sdlScancode, - SDL_GetScancodeName(sdlScancode), - keycode, - SDL_GetKeyName(keycode)); - //args->Handled = true; -#endif - SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode); -} - -#endif // SDL_VIDEO_DRIVER_WINRT diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse.cpp deleted file mode 100644 index 4c04a211..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if SDL_VIDEO_DRIVER_WINRT - -/* - * Windows includes: - */ -#include -using namespace Windows::UI::Core; -using Windows::UI::Core::CoreCursor; - -/* - * SDL includes: - */ -extern "C" { -#include "SDL_assert.h" -#include "../../events/SDL_mouse_c.h" -#include "../../events/SDL_touch_c.h" -#include "../SDL_sysvideo.h" -#include "SDL_events.h" -#include "SDL_log.h" -} - -#include "../../core/winrt/SDL_winrtapp_direct3d.h" -#include "SDL_winrtvideo_cpp.h" -#include "SDL_winrtmouse_c.h" - - -extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE; - - -static SDL_Cursor * -WINRT_CreateSystemCursor(SDL_SystemCursor id) -{ - SDL_Cursor *cursor; - CoreCursorType cursorType = CoreCursorType::Arrow; - - switch(id) - { - default: - SDL_assert(0); - return NULL; - case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break; - case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break; - case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break; - case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break; - case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break; - case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break; - case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break; - case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break; - case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break; - case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break; - case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break; - case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break; - } - - cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor)); - if (cursor) { - /* Create a pointer to a COM reference to a cursor. The extra - pointer is used (on top of the COM reference) to allow the cursor - to be referenced by the SDL_cursor's driverdata field, which is - a void pointer. - */ - CoreCursor ^* theCursor = new CoreCursor^(nullptr); - *theCursor = ref new CoreCursor(cursorType, 0); - cursor->driverdata = (void *) theCursor; - } else { - SDL_OutOfMemory(); - } - - return cursor; -} - -static SDL_Cursor * -WINRT_CreateDefaultCursor() -{ - return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); -} - -static void -WINRT_FreeCursor(SDL_Cursor * cursor) -{ - if (cursor->driverdata) { - CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata; - *theCursor = nullptr; // Release the COM reference to the CoreCursor - delete theCursor; // Delete the pointer to the COM reference - } - SDL_free(cursor); -} - -static int -WINRT_ShowCursor(SDL_Cursor * cursor) -{ - // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled. - if ( ! CoreWindow::GetForCurrentThread()) { - return 0; - } - - if (cursor) { - CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata; - CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor; - } else { - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - } - return 0; -} - -static int -WINRT_SetRelativeMouseMode(SDL_bool enabled) -{ - WINRT_UsingRelativeMouseMode = enabled; - return 0; -} - -void -WINRT_InitMouse(_THIS) -{ - SDL_Mouse *mouse = SDL_GetMouse(); - - /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for - the following features, AFAIK: - - custom cursors (multiple system cursors are, however, available) - - programmatically moveable cursors - */ - -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP - //mouse->CreateCursor = WINRT_CreateCursor; - mouse->CreateSystemCursor = WINRT_CreateSystemCursor; - mouse->ShowCursor = WINRT_ShowCursor; - mouse->FreeCursor = WINRT_FreeCursor; - //mouse->WarpMouse = WINRT_WarpMouse; - mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode; - - SDL_SetDefaultCursor(WINRT_CreateDefaultCursor()); -#endif -} - -void -WINRT_QuitMouse(_THIS) -{ -} - -#endif /* SDL_VIDEO_DRIVER_WINRT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse_c.h b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse_c.h deleted file mode 100644 index 676669b3..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtmouse_c.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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" - -#ifndef _SDL_winrtmouse_h -#define _SDL_winrtmouse_h - -#ifdef __cplusplus -extern "C" { -#endif - -extern void WINRT_InitMouse(_THIS); -extern void WINRT_QuitMouse(_THIS); -extern SDL_bool WINRT_UsingRelativeMouseMode; - -#ifdef __cplusplus -} -#endif - -#endif /* _SDL_windowsmouse_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.cpp deleted file mode 100644 index 6f3ddced..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -// TODO: WinRT, make this file compile via C code - -#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL - -/* EGL implementation of SDL OpenGL support */ - -#include "SDL_winrtvideo_cpp.h" -extern "C" { -#include "SDL_winrtopengles.h" -} - -#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3) - -extern "C" int -WINRT_GLES_LoadLibrary(_THIS, const char *path) { - return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE); -} - -extern "C" { -SDL_EGL_CreateContext_impl(WINRT) -SDL_EGL_SwapWindow_impl(WINRT) -SDL_EGL_MakeCurrent_impl(WINRT) -} - -#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */ - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.h b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.h deleted file mode 100644 index f051132e..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtopengles.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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" - -#ifndef _SDL_winrtopengles_h -#define _SDL_winrtopengles_h - -#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL - -#include "../SDL_sysvideo.h" -#include "../SDL_egl_c.h" - -/* OpenGLES functions */ -#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute -#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress -#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary -#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval -#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext - -extern int WINRT_GLES_LoadLibrary(_THIS, const char *path); -extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window); -extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window); -extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); - -#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */ - -#endif /* _SDL_winrtopengles_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtpointerinput.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtpointerinput.cpp deleted file mode 100644 index e3afffba..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtpointerinput.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if SDL_VIDEO_DRIVER_WINRT - -/* SDL includes */ -#include "SDL_winrtevents_c.h" -#include "SDL_winrtmouse_c.h" -#include "SDL_winrtvideo_cpp.h" -#include "SDL_assert.h" -#include "SDL_system.h" - -extern "C" { -#include "../SDL_sysvideo.h" -#include "../../events/SDL_events_c.h" -#include "../../events/SDL_mouse_c.h" -#include "../../events/SDL_touch_c.h" -} - -/* File-specific globals: */ -static SDL_TouchID WINRT_TouchID = 1; -static unsigned int WINRT_LeftFingerDown = 0; - - -void -WINRT_InitTouch(_THIS) -{ - SDL_AddTouch(WINRT_TouchID, ""); -} - - -// -// Applies necessary geometric transformations to raw cursor positions: -// -Windows::Foundation::Point -WINRT_TransformCursorPosition(SDL_Window * window, - Windows::Foundation::Point rawPosition, - WINRT_CursorNormalizationType normalization) -{ - using namespace Windows::UI::Core; - using namespace Windows::Graphics::Display; - - if (!window) { - return rawPosition; - } - - SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata; - if (windowData->coreWindow == nullptr) { - // For some reason, the window isn't associated with a CoreWindow. - // This might end up being the case as XAML support is extended. - // For now, if there's no CoreWindow attached to the SDL_Window, - // don't do any transforms. - - // TODO, WinRT: make sure touch input coordinate ranges are correct when using XAML support - return rawPosition; - } - - // The CoreWindow can only be accessed on certain thread(s). - SDL_assert(CoreWindow::GetForCurrentThread() != nullptr); - - CoreWindow ^ nativeWindow = windowData->coreWindow.Get(); - Windows::Foundation::Point outputPosition; - - // Compute coordinates normalized from 0..1. - // If the coordinates need to be sized to the SDL window, - // we'll do that after. -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP - outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width; - outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height; -#else - switch (DisplayProperties::CurrentOrientation) - { - case DisplayOrientations::Portrait: - outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width; - outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height; - break; - case DisplayOrientations::PortraitFlipped: - outputPosition.X = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width); - outputPosition.Y = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height); - break; - case DisplayOrientations::Landscape: - outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height; - outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width); - break; - case DisplayOrientations::LandscapeFlipped: - outputPosition.X = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height); - outputPosition.Y = rawPosition.X / nativeWindow->Bounds.Width; - break; - default: - break; - } -#endif - - if (normalization == TransformToSDLWindowSize) { - outputPosition.X *= ((float32) window->w); - outputPosition.Y *= ((float32) window->h); - } - - return outputPosition; -} - -static inline int -_lround(float arg) -{ - if (arg >= 0.0f) { - return (int)floor(arg + 0.5f); - } else { - return (int)ceil(arg - 0.5f); - } -} - -Uint8 -WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt) -{ - using namespace Windows::UI::Input; - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - return SDL_BUTTON_LEFT; -#else - switch (pt->Properties->PointerUpdateKind) - { - case PointerUpdateKind::LeftButtonPressed: - case PointerUpdateKind::LeftButtonReleased: - return SDL_BUTTON_LEFT; - - case PointerUpdateKind::RightButtonPressed: - case PointerUpdateKind::RightButtonReleased: - return SDL_BUTTON_RIGHT; - - case PointerUpdateKind::MiddleButtonPressed: - case PointerUpdateKind::MiddleButtonReleased: - return SDL_BUTTON_MIDDLE; - - case PointerUpdateKind::XButton1Pressed: - case PointerUpdateKind::XButton1Released: - return SDL_BUTTON_X1; - - case PointerUpdateKind::XButton2Pressed: - case PointerUpdateKind::XButton2Released: - return SDL_BUTTON_X2; - - default: - break; - } -#endif - - return 0; -} - -//const char * -//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind) -//{ -// using namespace Windows::UI::Input; -// -// switch (kind) -// { -// case PointerUpdateKind::Other: -// return "Other"; -// case PointerUpdateKind::LeftButtonPressed: -// return "LeftButtonPressed"; -// case PointerUpdateKind::LeftButtonReleased: -// return "LeftButtonReleased"; -// case PointerUpdateKind::RightButtonPressed: -// return "RightButtonPressed"; -// case PointerUpdateKind::RightButtonReleased: -// return "RightButtonReleased"; -// case PointerUpdateKind::MiddleButtonPressed: -// return "MiddleButtonPressed"; -// case PointerUpdateKind::MiddleButtonReleased: -// return "MiddleButtonReleased"; -// case PointerUpdateKind::XButton1Pressed: -// return "XButton1Pressed"; -// case PointerUpdateKind::XButton1Released: -// return "XButton1Released"; -// case PointerUpdateKind::XButton2Pressed: -// return "XButton2Pressed"; -// case PointerUpdateKind::XButton2Released: -// return "XButton2Released"; -// } -// -// return ""; -//} - -static bool -WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint) -{ -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - return true; -#else - using namespace Windows::Devices::Input; - switch (pointerPoint->PointerDevice->PointerDeviceType) { - case PointerDeviceType::Touch: - case PointerDeviceType::Pen: - return true; - default: - return false; - } -#endif -} - -void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint) -{ - if (!window) { - return; - } - - Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint); - - if ( ! WINRT_IsTouchEvent(pointerPoint)) { - SDL_SendMouseButton(window, 0, SDL_PRESSED, button); - } else { - Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne); - Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize); - - if (!WINRT_LeftFingerDown) { - if (button) { - SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y); - SDL_SendMouseButton(window, 0, SDL_PRESSED, button); - } - - WINRT_LeftFingerDown = pointerPoint->PointerId; - } - - SDL_SendTouch( - WINRT_TouchID, - (SDL_FingerID) pointerPoint->PointerId, - SDL_TRUE, - normalizedPoint.X, - normalizedPoint.Y, - pointerPoint->Properties->Pressure); - } -} - -void -WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint) -{ - if (!window || WINRT_UsingRelativeMouseMode) { - return; - } - - Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne); - Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize); - - if ( ! WINRT_IsTouchEvent(pointerPoint)) { - SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y); - } else if (pointerPoint->PointerId == WINRT_LeftFingerDown) { - if (pointerPoint->PointerId == WINRT_LeftFingerDown) { - SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y); - } - - SDL_SendTouchMotion( - WINRT_TouchID, - (SDL_FingerID) pointerPoint->PointerId, - normalizedPoint.X, - normalizedPoint.Y, - pointerPoint->Properties->Pressure); - } -} - -void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint) -{ - if (!window) { - return; - } - - Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint); - - if (!WINRT_IsTouchEvent(pointerPoint)) { - SDL_SendMouseButton(window, 0, SDL_RELEASED, button); - } else { - Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne); - - if (WINRT_LeftFingerDown == pointerPoint->PointerId) { - if (button) { - SDL_SendMouseButton(window, 0, SDL_RELEASED, button); - } - WINRT_LeftFingerDown = 0; - } - - SDL_SendTouch( - WINRT_TouchID, - (SDL_FingerID) pointerPoint->PointerId, - SDL_FALSE, - normalizedPoint.X, - normalizedPoint.Y, - pointerPoint->Properties->Pressure); - } -} - -void -WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint) -{ - if (!window) { - return; - } - - // FIXME: This may need to accumulate deltas up to WHEEL_DELTA - short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA; - SDL_SendMouseWheel(window, 0, 0, motion); -} - -void -WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args) -{ - if (!window || !WINRT_UsingRelativeMouseMode) { - return; - } - - // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows - // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs' - // MouseDelta field often reports very large values. More information - // on this can be found at the following pages on MSDN: - // - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8 - // - https://connect.microsoft.com/VisualStudio/Feedback/details/756515 - // - // The values do not appear to be as large when running on some systems, - // most notably a Surface RT. Furthermore, the values returned by - // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved - // method, do not ever appear to be large, even when MouseEventArgs' - // MouseDelta is reporting to the contrary. - // - // On systems with the large-values behavior, it appears that the values - // get reported as if the screen's size is 65536 units in both the X and Y - // dimensions. This can be viewed by using Windows' now-private, "Raw Input" - // APIs. (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.) - // - // MSDN's documentation on MouseEventArgs' MouseDelta field (at - // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ), - // does not seem to indicate (to me) that its values should be so large. It - // says that its values should be a "change in screen location". I could - // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: - // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ), - // indicates that these values are in DIPs, which is the same unit used - // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint - // property. See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx - // for details.) - // - // To note, PointerMoved events are sent a 'RawPosition' value (via the - // CurrentPoint property in MouseEventArgs), however these do not seem - // to exhibit the same large-value behavior. - // - // The values passed via PointerMoved events can't always be used for relative - // mouse motion, unfortunately. Its values are bound to the cursor's position, - // which stops when it hits one of the screen's edges. This can be a problem in - // first person shooters, whereby it is normal for mouse motion to travel far - // along any one axis for a period of time. MouseMoved events do not have the - // screen-bounding limitation, and can be used regardless of where the system's - // cursor is. - // - // One possible workaround would be to programmatically set the cursor's - // position to the screen's center (when SDL's relative mouse mode is enabled), - // however WinRT does not yet seem to have the ability to set the cursor's - // position via a public API. Win32 did this via an API call, SetCursorPos, - // however WinRT makes this function be private. Apps that use it won't get - // approved for distribution in the Windows Store. I've yet to be able to find - // a suitable, store-friendly counterpart for WinRT. - // - // There may be some room for a workaround whereby OnPointerMoved's values - // are compared to the values from OnMouseMoved in order to detect - // when this bug is active. A suitable transformation could then be made to - // OnMouseMoved's values. For now, however, the system-reported values are sent - // to SDL with minimal transformation: from native screen coordinates (in DIPs) - // to SDL window coordinates. - // - const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y); - const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize); - SDL_SendMouseMotion( - window, - 0, - 1, - _lround(mouseDeltaInSDLWindowCoords.X), - _lround(mouseDeltaInSDLWindowCoords.Y)); -} - -#endif // SDL_VIDEO_DRIVER_WINRT diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo.cpp b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo.cpp deleted file mode 100644 index 4a5301f2..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo.cpp +++ /dev/null @@ -1,409 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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_internal.h" - -#if SDL_VIDEO_DRIVER_WINRT - -/* WinRT SDL video driver implementation - - Initial work on this was done by David Ludwig (dludwig@pobox.com), and - was based off of SDL's "dummy" video driver. - */ - -/* Windows includes */ -#include -using namespace Windows::UI::Core; - - -/* SDL includes */ -extern "C" { -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "../../events/SDL_events_c.h" -#include "../../render/SDL_sysrender.h" -#include "SDL_syswm.h" -#include "SDL_winrtopengles.h" -} - -#include "../../core/winrt/SDL_winrtapp_direct3d.h" -#include "../../core/winrt/SDL_winrtapp_xaml.h" -#include "SDL_winrtvideo_cpp.h" -#include "SDL_winrtevents_c.h" -#include "SDL_winrtmouse_c.h" -#include "SDL_main.h" -#include "SDL_system.h" - - -/* Initialization/Query functions */ -static int WINRT_VideoInit(_THIS); -static int WINRT_InitModes(_THIS); -static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); -static void WINRT_VideoQuit(_THIS); - - -/* Window functions */ -static int WINRT_CreateWindow(_THIS, SDL_Window * window); -static void WINRT_DestroyWindow(_THIS, SDL_Window * window); -static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info); - - -/* SDL-internal globals: */ -SDL_Window * WINRT_GlobalSDLWindow = NULL; -SDL_VideoDevice * WINRT_GlobalSDLVideoDevice = NULL; - - -/* WinRT driver bootstrap functions */ - -static int -WINRT_Available(void) -{ - return (1); -} - -static void -WINRT_DeleteDevice(SDL_VideoDevice * device) -{ - if (device == WINRT_GlobalSDLVideoDevice) { - WINRT_GlobalSDLVideoDevice = NULL; - } - SDL_free(device); -} - -static SDL_VideoDevice * -WINRT_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return (0); - } - - /* Set the function pointers */ - device->VideoInit = WINRT_VideoInit; - device->VideoQuit = WINRT_VideoQuit; - device->CreateWindow = WINRT_CreateWindow; - device->DestroyWindow = WINRT_DestroyWindow; - device->SetDisplayMode = WINRT_SetDisplayMode; - device->PumpEvents = WINRT_PumpEvents; - device->GetWindowWMInfo = WINRT_GetWindowWMInfo; -#ifdef SDL_VIDEO_OPENGL_EGL - device->GL_LoadLibrary = WINRT_GLES_LoadLibrary; - device->GL_GetProcAddress = WINRT_GLES_GetProcAddress; - device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary; - device->GL_CreateContext = WINRT_GLES_CreateContext; - device->GL_MakeCurrent = WINRT_GLES_MakeCurrent; - device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval; - device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval; - device->GL_SwapWindow = WINRT_GLES_SwapWindow; - device->GL_DeleteContext = WINRT_GLES_DeleteContext; -#endif - device->free = WINRT_DeleteDevice; - WINRT_GlobalSDLVideoDevice = device; - - return device; -} - -#define WINRTVID_DRIVER_NAME "winrt" -VideoBootStrap WINRT_bootstrap = { - WINRTVID_DRIVER_NAME, "SDL WinRT video driver", - WINRT_Available, WINRT_CreateDevice -}; - -int -WINRT_VideoInit(_THIS) -{ - if (WINRT_InitModes(_this) < 0) { - return -1; - } - WINRT_InitMouse(_this); - WINRT_InitTouch(_this); - - return 0; -} - -int -WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode) -{ - SDL_DisplayModeData * driverdata; - - using namespace Windows::Graphics::Display; - - // Go no further if a native window cannot be accessed. This can happen, - // for example, if this function is called from certain threads, such as - // the SDL/XAML thread. - if (!CoreWindow::GetForCurrentThread()) { - return SDL_SetError("SDL/WinRT display modes cannot be calculated outside of the main thread, such as in SDL's XAML thread"); - } - - // Calculate the display size given the window size, taking into account - // the current display's DPI: -#if NTDDI_VERSION > NTDDI_WIN8 - const float currentDPI = DisplayInformation::GetForCurrentView()->LogicalDpi; -#else - const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; -#endif - const float dipsPerInch = 96.0f; - const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch); - const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch); - if (w == 0 || w == h) { - return SDL_SetError("Unable to calculate the WinRT window/display's size"); - } - - // Create a driverdata field: - driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata)); - if (!driverdata) { - return SDL_OutOfMemory(); - } - SDL_zerop(driverdata); - - // Fill in most fields: - SDL_zerop(mode); - mode->format = SDL_PIXELFORMAT_RGB888; - mode->refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps) - mode->w = w; - mode->h = h; - mode->driverdata = driverdata; -#if NTDDI_VERSION > NTDDI_WIN8 - driverdata->currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation; -#else - driverdata->currentOrientation = DisplayProperties::CurrentOrientation; -#endif - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - // On Windows Phone, the native window's size is always in portrait, - // regardless of the device's orientation. This is in contrast to - // Windows 8/RT, which will resize the native window as the device's - // orientation changes. In order to compensate for this behavior, - // on Windows Phone, the mode's width and height will be swapped when - // the device is in a landscape (non-portrait) mode. - switch (DisplayProperties::CurrentOrientation) { - case DisplayOrientations::Landscape: - case DisplayOrientations::LandscapeFlipped: - { - const int tmp = mode->h; - mode->h = mode->w; - mode->w = tmp; - break; - } - - default: - break; - } -#endif - - return 0; -} - -int -WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src) -{ - SDL_DisplayModeData * driverdata; - driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata)); - if (!driverdata) { - return SDL_OutOfMemory(); - } - SDL_memcpy(driverdata, src->driverdata, sizeof(SDL_DisplayModeData)); - SDL_memcpy(dest, src, sizeof(SDL_DisplayMode)); - dest->driverdata = driverdata; - return 0; -} - -int -WINRT_InitModes(_THIS) -{ - // Retrieve the display mode: - SDL_DisplayMode mode, desktop_mode; - if (WINRT_CalcDisplayModeUsingNativeWindow(&mode) != 0) { - return -1; // If WINRT_CalcDisplayModeUsingNativeWindow fails, it'll already have set the SDL error - } - - if (WINRT_DuplicateDisplayMode(&desktop_mode, &mode) != 0) { - return -1; - } - if (SDL_AddBasicVideoDisplay(&desktop_mode) < 0) { - return -1; - } - - SDL_AddDisplayMode(&_this->displays[0], &mode); - return 0; -} - -static int -WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) -{ - return 0; -} - -void -WINRT_VideoQuit(_THIS) -{ - WINRT_QuitMouse(_this); -} - -int -WINRT_CreateWindow(_THIS, SDL_Window * window) -{ - // Make sure that only one window gets created, at least until multimonitor - // support is added. - if (WINRT_GlobalSDLWindow != NULL) { - SDL_SetError("WinRT only supports one window"); - return -1; - } - - SDL_WindowData *data = new SDL_WindowData; - if (!data) { - SDL_OutOfMemory(); - return -1; - } - window->driverdata = data; - data->sdlWindow = window; - - /* To note, when XAML support is enabled, access to the CoreWindow will not - be possible, at least not via the SDL/XAML thread. Attempts to access it - from there will throw exceptions. As such, the SDL_WindowData's - 'coreWindow' field will only be set (to a non-null value) if XAML isn't - enabled. - */ - if (!WINRT_XAMLWasEnabled) { - data->coreWindow = CoreWindow::GetForCurrentThread(); - } - -#if SDL_VIDEO_OPENGL_EGL - /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */ - if (!(window->flags & SDL_WINDOW_OPENGL)) { - /* OpenGL ES 2 wasn't requested. Don't set up an EGL surface. */ - data->egl_surface = EGL_NO_SURFACE; - } else { - /* OpenGL ES 2 was reuqested. Set up an EGL surface. */ - - /* HACK: ANGLE/WinRT currently uses non-pointer, C++ objects to represent - native windows. The object only contains a single pointer to a COM - interface pointer, which on x86 appears to be castable to the object - without apparant problems. On other platforms, notable ARM and x64, - doing so will cause a crash. To avoid this crash, we'll bypass - SDL's normal call to eglCreateWindowSurface, which is invoked from C - code, and call it here, where an appropriate C++ object may be - passed in. - */ - typedef EGLSurface (*eglCreateWindowSurfaceFunction)(EGLDisplay dpy, EGLConfig config, - Microsoft::WRL::ComPtr win, - const EGLint *attrib_list); - eglCreateWindowSurfaceFunction WINRT_eglCreateWindowSurface = - (eglCreateWindowSurfaceFunction) _this->egl_data->eglCreateWindowSurface; - - Microsoft::WRL::ComPtr nativeWindow = reinterpret_cast(data->coreWindow.Get()); - data->egl_surface = WINRT_eglCreateWindowSurface( - _this->egl_data->egl_display, - _this->egl_data->egl_config, - nativeWindow, NULL); - if (data->egl_surface == NULL) { - // TODO, WinRT: see if eglCreateWindowSurface, or its callee(s), sets an error message. If so, attach it to the SDL error. - return SDL_SetError("eglCreateWindowSurface failed"); - } - } -#endif - - /* Make sure the window is considered to be positioned at {0,0}, - and is considered fullscreen, shown, and the like. - */ - window->x = 0; - window->y = 0; - window->flags = - SDL_WINDOW_FULLSCREEN | - SDL_WINDOW_SHOWN | - SDL_WINDOW_BORDERLESS | - SDL_WINDOW_MAXIMIZED | - SDL_WINDOW_INPUT_GRABBED; - -#if SDL_VIDEO_OPENGL_EGL - if (data->egl_surface) { - window->flags |= SDL_WINDOW_OPENGL; - } -#endif - - /* WinRT does not, as of this writing, appear to support app-adjustable - window sizes. Set the window size to whatever the native WinRT - CoreWindow is set at. - - TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces. - */ - window->w = _this->displays[0].current_mode.w; - window->h = _this->displays[0].current_mode.h; - - /* For now, treat WinRT apps as if they always have focus. - TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps - */ - SDL_SetMouseFocus(window); - SDL_SetKeyboardFocus(window); - - /* Make sure the WinRT app's IFramworkView can post events on - behalf of SDL: - */ - WINRT_GlobalSDLWindow = window; - - /* All done! */ - return 0; -} - -void -WINRT_DestroyWindow(_THIS, SDL_Window * window) -{ - SDL_WindowData * data = (SDL_WindowData *) window->driverdata; - - if (WINRT_GlobalSDLWindow == window) { - WINRT_GlobalSDLWindow = NULL; - } - - if (data) { - // Delete the internal window data: - delete data; - data = NULL; - } -} - -SDL_bool -WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) -{ - SDL_WindowData * data = (SDL_WindowData *) window->driverdata; - - if (info->version.major <= SDL_MAJOR_VERSION) { - info->subsystem = SDL_SYSWM_WINRT; - info->info.winrt.window = reinterpret_cast(data->coreWindow.Get()); - return SDL_TRUE; - } else { - SDL_SetError("Application not compiled with SDL %d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION); - return SDL_FALSE; - } - return SDL_FALSE; -} - -#endif /* SDL_VIDEO_DRIVER_WINRT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo_cpp.h b/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo_cpp.h deleted file mode 100644 index b5f44510..00000000 --- a/jni/SDL2-2.0.3/src/video/winrt/SDL_winrtvideo_cpp.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2014 Sam Lantinga - - 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. -*/ - -/* Windows includes: */ -#include -#ifdef __cplusplus_winrt -#include -#endif - -/* SDL includes: */ -#include "SDL_video.h" -#include "SDL_events.h" - -extern "C" { -#include "../SDL_sysvideo.h" -#include "../SDL_egl_c.h" -} - - -/* The global, WinRT, SDL Window. - For now, SDL/WinRT only supports one window (due to platform limitations of - WinRT. -*/ -extern SDL_Window * WINRT_GlobalSDLWindow; - -/* The global, WinRT, video device. */ -extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice; - -/* Creates a display mode for Plain Direct3D (non-XAML) apps, using the lone, native window's settings. - - Pass in an allocated SDL_DisplayMode field to store the data in. - - This function will return 0 on success, -1 on failure. - - If this function succeeds, be sure to call SDL_free on the - SDL_DisplayMode's driverdata field. -*/ -extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode); - -/* Duplicates a display mode, copying over driverdata as necessary */ -extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src); - -/* Display mode internals */ -typedef struct -{ - Windows::Graphics::Display::DisplayOrientations currentOrientation; -} SDL_DisplayModeData; - -#ifdef __cplusplus_winrt - -/* Internal window data */ -struct SDL_WindowData -{ - SDL_Window *sdlWindow; - Platform::Agile coreWindow; -#ifdef SDL_VIDEO_OPENGL_EGL - EGLSurface egl_surface; -#endif -}; - -#endif // ifdef __cplusplus_winrt diff --git a/jni/libjpeg-turbo-1.3.1/Android.mk b/jni/libjpeg-turbo-1.3.1/Android.mk index 6e6006fb..ea6f5865 100644 --- a/jni/libjpeg-turbo-1.3.1/Android.mk +++ b/jni/libjpeg-turbo-1.3.1/Android.mk @@ -15,6 +15,7 @@ LOCAL_SRC_FILES := \ jccolext.c \ jdcolext.c \ jdmrgext.c \ + turbojpeg-jni.c \ ,$(subst $(LOCAL_PATH)/,,\ $(wildcard ${LOCAL_PATH}/*.c) \ )) diff --git a/jni/love/src/modules/filesystem/physfs/wrap_File.cpp b/jni/love/src/modules/filesystem/physfs/wrap_File.cpp deleted file mode 100644 index d136e4b4..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_File.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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 "wrap_File.h" - -#include "common/Data.h" -#include "common/Exception.h" -#include "common/int.h" - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -int luax_ioError(lua_State *L, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - - lua_pushnil(L); - lua_pushvfstring(L, fmt, args); - - va_end(args); - return 2; -} - -File *luax_checkfile(lua_State *L, int idx) -{ - return luax_checktype(L, idx, "File", FILESYSTEM_FILE_T); -} - -int w_File_getSize(lua_State *L) -{ - File *t = luax_checkfile(L, 1); - - int64 size = -1; - try - { - size = t->getSize(); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - // Push nil on failure or if size does not fit into a double precision floating-point number. - if (size == -1) - return luax_ioError(L, "Could not determine file size."); - else if (size >= 0x20000000000000LL) - return luax_ioError(L, "Size is too large."); - - lua_pushnumber(L, (lua_Number) size); - return 1; -} - -int w_File_open(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - const char *str = luaL_checkstring(L, 2); - File::Mode mode; - - if (!File::getConstant(str, mode)) - return luaL_error(L, "Incorrect file open mode: %s", str); - - try - { - luax_pushboolean(L, file->open(mode)); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - return 1; -} - -int w_File_close(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - luax_pushboolean(L, file->close()); - return 1; -} - -int w_File_isOpen(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - luax_pushboolean(L, file->isOpen()); - return 1; -} - -int w_File_read(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - Data *d = 0; - - int64 size = (int64)luaL_optnumber(L, 2, File::ALL); - - try - { - d = file->read(size); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - lua_pushlstring(L, (const char *) d->getData(), d->getSize()); - lua_pushnumber(L, d->getSize()); - d->release(); - return 2; -} - -int w_File_write(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - bool result = false; - - if (lua_isstring(L, 2)) - { - try - { - size_t datasize = 0; - const char *data = lua_tolstring(L, 2, &datasize); - - if (!lua_isnoneornil(L, 3)) - datasize = luaL_checkinteger(L, 3); - - result = file->write(data, datasize); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - } - else if (luax_istype(L, 2, DATA_T)) - { - try - { - love::Data *data = luax_totype(L, 2, "Data", DATA_T); - result = file->write(data, luaL_optinteger(L, 3, data->getSize())); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - } - else - { - return luaL_argerror(L, 2, "string or data expected"); - } - - luax_pushboolean(L, result); - return 1; -} - -int w_File_flush(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - bool success = false; - try - { - success = file->flush(); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - luax_pushboolean(L, success); - return 1; -} - -int w_File_eof(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - luax_pushboolean(L, file->eof()); - return 1; -} - -int w_File_tell(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - int64 pos = file->tell(); - // Push nil on failure or if pos does not fit into a double precision floating-point number. - if (pos == -1) - return luax_ioError(L, "Invalid position."); - else if (pos >= 0x20000000000000LL) - return luax_ioError(L, "Number is too large."); - else - lua_pushnumber(L, (lua_Number)pos); - return 1; -} - -int w_File_seek(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - lua_Number pos = luaL_checknumber(L, 2); - - // Push false on negative and precision-problematic numbers. - // Better fail than seek to an unknown position. - if (pos < 0.0 || pos >= 9007199254740992.0) - luax_pushboolean(L, false); - else - luax_pushboolean(L, file->seek((uint64)pos)); - return 1; -} - -int w_File_lines(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - - lua_pushnumber(L, 0); // File position. - luax_pushboolean(L, file->getMode() != File::CLOSED); // Save current file mode. - - if (file->getMode() != File::READ) - { - if (file->getMode() != File::CLOSED) - file->close(); - - bool success = false; - EXCEPT_GUARD(success = file->open(File::READ);) - - if (!success) - return luaL_error(L, "Could not open file."); - } - - lua_pushcclosure(L, Filesystem::lines_i, 3); - return 1; -} - -int w_File_setBuffer(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - const char *str = luaL_checkstring(L, 2); - int64 size = (int64) luaL_optnumber(L, 3, 0.0); - - File::BufferMode bufmode; - if (!File::getConstant(str, bufmode)) - return luaL_error(L, "Incorrect file buffer mode: %s", str); - - bool success = false; - try - { - success = file->setBuffer(bufmode, size); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - luax_pushboolean(L, success); - return 1; -} - -int w_File_getBuffer(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - int64 size = 0; - File::BufferMode bufmode = file->getBuffer(size); - const char *str = 0; - - if (!File::getConstant(bufmode, str)) - return luax_ioError(L, "Unknown file buffer mode."); - - lua_pushstring(L, str); - lua_pushnumber(L, (lua_Number) size); - return 2; -} - -int w_File_getMode(lua_State *L) -{ - File *file = luax_checkfile(L, 1); - - File::Mode mode = file->getMode(); - const char *str = 0; - - if (!File::getConstant(mode, str)) - return luax_ioError(L, "Unknown file mode."); - - lua_pushstring(L, str); - return 1; -} - -static const luaL_Reg functions[] = -{ - { "getSize", w_File_getSize }, - { "open", w_File_open }, - { "close", w_File_close }, - { "isOpen", w_File_isOpen }, - { "read", w_File_read }, - { "write", w_File_write }, - { "flush", w_File_flush }, - { "eof", w_File_eof }, - { "tell", w_File_tell }, - { "seek", w_File_seek }, - { "lines", w_File_lines }, - { "setBuffer", w_File_setBuffer }, - { "getBuffer", w_File_getBuffer }, - { "getMode", w_File_getMode }, - { 0, 0 } -}; - -extern "C" int luaopen_file(lua_State *L) -{ - return luax_register_type(L, "File", functions); -} - -} // physfs -} // filesystem -} // love diff --git a/jni/love/src/modules/filesystem/physfs/wrap_File.h b/jni/love/src/modules/filesystem/physfs/wrap_File.h deleted file mode 100644 index a3d0b964..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_File.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -#ifndef LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_H -#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_H - -// LOVE -#include "common/runtime.h" -#include "Filesystem.h" -#include "File.h" - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -// Does not use lua_error, so it's safe to call in exception handling code. -int luax_ioError(lua_State *L, const char *fmt, ...); - -File *luax_checkfile(lua_State *L, int idx); -int w_File_getSize(lua_State *L); -int w_File_open(lua_State *L); -int w_File_close(lua_State *L); -int w_File_isOpen(lua_State *L); -int w_File_read(lua_State *L); -int w_File_write(lua_State *L); -int w_File_flush(lua_State *L); -int w_File_eof(lua_State *L); -int w_File_tell(lua_State *L); -int w_File_seek(lua_State *L); -int w_File_lines(lua_State *L); -int w_File_setBuffer(lua_State *L); -int w_File_getBuffer(lua_State *L); -int w_File_getMode(lua_State *L); -extern "C" int luaopen_file(lua_State *L); - -} // physfs -} // filesystem -} // love - -#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_H diff --git a/jni/love/src/modules/filesystem/physfs/wrap_FileData.cpp b/jni/love/src/modules/filesystem/physfs/wrap_FileData.cpp deleted file mode 100644 index b50c8123..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_FileData.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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 "wrap_FileData.h" - -#include "common/wrap_Data.h" - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -FileData *luax_checkfiledata(lua_State *L, int idx) -{ - return luax_checktype(L, idx, "FileData", FILESYSTEM_FILE_DATA_T); -} - -int w_FileData_getFilename(lua_State *L) -{ - FileData *t = luax_checkfiledata(L, 1); - lua_pushstring(L, t->getFilename().c_str()); - return 1; -} - -int w_FileData_getExtension(lua_State *L) -{ - FileData *t = luax_checkfiledata(L, 1); - lua_pushstring(L, t->getExtension().c_str()); - return 1; -} - -static const luaL_Reg w_FileData_functions[] = -{ - // Data - { "getString", w_Data_getString }, - { "getPointer", w_Data_getPointer }, - { "getSize", w_Data_getSize }, - - { "getFilename", w_FileData_getFilename }, - { "getExtension", w_FileData_getExtension }, - - { 0, 0 } -}; - -extern "C" int luaopen_filedata(lua_State *L) -{ - return luax_register_type(L, "FileData", w_FileData_functions); -} - -} // physfs -} // filesystem -} // love diff --git a/jni/love/src/modules/filesystem/physfs/wrap_FileData.h b/jni/love/src/modules/filesystem/physfs/wrap_FileData.h deleted file mode 100644 index 2d46165f..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_FileData.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -#ifndef LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H -#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H - -// LOVE -#include "common/runtime.h" - -#include "filesystem/FileData.h" - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -FileData *luax_checkfiledata(lua_State *L, int idx); -int w_FileData_getFilename(lua_State *L); -int w_FileData_getExtension(lua_State *L); -extern "C" int luaopen_filedata(lua_State *L); - -} // physfs -} // filesystem -} // love - -#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H diff --git a/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.cpp b/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.cpp deleted file mode 100644 index 77845ef1..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.cpp +++ /dev/null @@ -1,643 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -// LOVE -#include "wrap_Filesystem.h" - -// SDL -#include - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -static Filesystem *instance = 0; - -bool hack_setupWriteDirectory() -{ - if (instance != 0) - return instance->setupWriteDirectory(); - return false; -} - -int w_init(lua_State *L) -{ - const char *arg0 = luaL_checkstring(L, 1); - EXCEPT_GUARD(instance->init(arg0);) - return 0; -} - -int w_setFused(lua_State *L) -{ - // no error checking needed, everything, even nothing - // can be converted to a boolean - instance->setFused(luax_toboolean(L, 1)); - return 0; -} - -int w_isFused(lua_State *L) -{ - luax_pushboolean(L, instance->isFused()); - return 1; -} - -int w_setIdentity(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - bool append = luax_optboolean(L, 2, false); - - if (!instance->setIdentity(arg, append)) - return luaL_error(L, "Could not set write directory."); - - return 0; -} - -int w_getIdentity(lua_State *L) -{ - lua_pushstring(L, instance->getIdentity()); - return 1; -} - -int w_setSource(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - - if (!instance->setSource(arg)) - return luaL_error(L, "Could not set source."); - - return 0; -} - -int w_getSource(lua_State *L) -{ - lua_pushstring(L, instance->getSource()); - return 1; -} - -int w_mount(lua_State *L) -{ - const char *archive = luaL_checkstring(L, 1); - const char *mountpoint = luaL_checkstring(L, 2); - bool append = luax_optboolean(L, 3, false); - - luax_pushboolean(L, instance->mount(archive, mountpoint, append)); - return 1; -} - -int w_unmount(lua_State *L) -{ - const char *archive = luaL_checkstring(L, 1); - - luax_pushboolean(L, instance->unmount(archive)); - return 1; -} - -int w_newFile(lua_State *L) -{ - const char *filename = luaL_checkstring(L, 1); - - const char *str = 0; - File::Mode mode = File::CLOSED; - - if (lua_isstring(L, 2)) - { - str = luaL_checkstring(L, 2); - if (!File::getConstant(str, mode)) - return luaL_error(L, "Incorrect file open mode: %s", str); - } - - File *t = instance->newFile(filename); - - if (mode != File::CLOSED) - { - try - { - if (!t->open(mode)) - throw love::Exception("Could not open file."); - } - catch (love::Exception &e) - { - t->release(); - return luax_ioError(L, "%s", e.what()); - } - } - - luax_pushtype(L, "File", FILESYSTEM_FILE_T, t); - return 1; -} - -int w_newFileData(lua_State *L) -{ - // Single argument: treat as filepath or File. - if (lua_gettop(L) == 1) - { - if (lua_isstring(L, 1)) - luax_convobj(L, 1, "filesystem", "newFile"); - - // Get FileData from the File. - if (luax_istype(L, 1, FILESYSTEM_FILE_T)) - { - File *file = luax_checktype(L, 1, "File", FILESYSTEM_FILE_T); - - FileData *data = 0; - try - { - data = file->read(); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, data); - return 1; - } - else - return luaL_argerror(L, 1, "string or File expected"); - } - - size_t length = 0; - const char *str = luaL_checklstring(L, 1, &length); - const char *filename = luaL_checkstring(L, 2); - const char *decstr = lua_isstring(L, 3) ? lua_tostring(L, 3) : 0; - - FileData::Decoder decoder = FileData::FILE; - - if (decstr && !FileData::getConstant(decstr, decoder)) - return luaL_error(L, "Invalid FileData decoder: %s", decstr); - - FileData *t = 0; - - switch (decoder) - { - case FileData::FILE: - t = instance->newFileData((void *)str, (int)length, filename); - break; - case FileData::BASE64: - t = instance->newFileData(str, filename); - break; - default: - return luaL_error(L, "Invalid FileData decoder: %s", decstr); - } - - luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, t); - return 1; -} - -int w_getWorkingDirectory(lua_State *L) -{ - lua_pushstring(L, instance->getWorkingDirectory()); - return 1; -} - -int w_getUserDirectory(lua_State *L) -{ - luax_pushstring(L, instance->getUserDirectory()); - return 1; -} - -int w_getAppdataDirectory(lua_State *L) -{ - luax_pushstring(L, instance->getAppdataDirectory()); - return 1; -} - -int w_getSaveDirectory(lua_State *L) -{ - lua_pushstring(L, instance->getSaveDirectory()); - return 1; -} - -int w_getSourceBaseDirectory(lua_State *L) -{ - luax_pushstring(L, instance->getSourceBaseDirectory()); - return 1; -} - -int w_exists(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - luax_pushboolean(L, instance->exists(arg)); - return 1; -} - -int w_isDirectory(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - luax_pushboolean(L, instance->isDirectory(arg)); - return 1; -} - -int w_isFile(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - luax_pushboolean(L, instance->isFile(arg)); - return 1; -} - -int w_createDirectory(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - luax_pushboolean(L, instance->createDirectory(arg)); - return 1; -} - -int w_remove(lua_State *L) -{ - const char *arg = luaL_checkstring(L, 1); - luax_pushboolean(L, instance->remove(arg)); - return 1; -} - -int w_read(lua_State *L) -{ - const char *filename = luaL_checkstring(L, 1); - int64 len = (int64) luaL_optinteger(L, 2, File::ALL); - - Data *data = 0; - try - { - data = instance->read(filename, len); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - if (data == 0) - return luax_ioError(L, "File could not be read."); - - // Push the string. - lua_pushlstring(L, (const char *) data->getData(), data->getSize()); - - // Push the size. - lua_pushinteger(L, data->getSize()); - - // Lua has a copy now, so we can free it. - data->release(); - - return 2; -} - -static int w_write_or_append(lua_State *L, File::Mode mode) -{ - const char *filename = luaL_checkstring(L, 1); - - const char *input = 0; - size_t len = 0; - - if (luax_istype(L, 2, DATA_T)) - { - love::Data *data = luax_totype(L, 2, "Data", DATA_T); - input = (const char *) data->getData(); - len = data->getSize(); - } - else if (lua_isstring(L, 2)) - input = lua_tolstring(L, 2, &len); - else - return luaL_argerror(L, 2, "string or Data expected"); - - // Get how much we should write. Length of string default. - len = luaL_optinteger(L, 3, len); - - try - { - if (mode == File::APPEND) - instance->append(filename, (const void *) input, len); - else - instance->write(filename, (const void *) input, len); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - luax_pushboolean(L, true); - return 1; -} - -int w_write(lua_State *L) -{ - return w_write_or_append(L, File::WRITE); -} - -int w_append(lua_State *L) -{ - return w_write_or_append(L, File::APPEND); -} - -int w_getDirectoryItems(lua_State *L) -{ - return instance->getDirectoryItems(L); -} - -int w_lines(lua_State *L) -{ - File *file; - - if (lua_isstring(L, 1)) - { - file = instance->newFile(lua_tostring(L, 1)); - bool success = false; - - EXCEPT_GUARD(success = file->open(File::READ);) - - if (!success) - return luaL_error(L, "Could not open file."); - - luax_pushtype(L, "File", FILESYSTEM_FILE_T, file); - } - else - return luaL_argerror(L, 1, "expected filename."); - - lua_pushcclosure(L, Filesystem::lines_i, 1); - return 1; -} - -int w_load(lua_State *L) -{ - std::string filename = std::string(luaL_checkstring(L, 1)); - - Data *data = 0; - try - { - data = instance->read(filename.c_str()); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - int status = luaL_loadbuffer(L, (const char *)data->getData(), data->getSize(), ("@" + filename).c_str()); - - data->release(); - - // Load the chunk, but don't run it. - switch (status) - { - case LUA_ERRMEM: - return luaL_error(L, "Memory allocation error: %s\n", lua_tostring(L, -1)); - case LUA_ERRSYNTAX: - return luaL_error(L, "Syntax error: %s\n", lua_tostring(L, -1)); - default: // success - return 1; - } -} - -int w_getLastModified(lua_State *L) -{ - const char *filename = luaL_checkstring(L, 1); - - int64 time = 0; - try - { - time = instance->getLastModified(filename); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - lua_pushnumber(L, static_cast(time)); - return 1; -} - -int w_getSize(lua_State *L) -{ - const char *filename = luaL_checkstring(L, 1); - - int64 size = -1; - try - { - size = instance->getSize(filename); - } - catch (love::Exception &e) - { - return luax_ioError(L, "%s", e.what()); - } - - // Error on failure or if size does not fit into a double precision floating-point number. - if (size == -1) - return luax_ioError(L, "Could not determine file size."); - else if (size >= 0x20000000000000LL) - return luax_ioError(L, "Size too large to fit into a Lua number!"); - - lua_pushnumber(L, (lua_Number) size); - return 1; -} - -int loader(lua_State *L) -{ - const char *filename = lua_tostring(L, -1); - - std::string tmp(filename); - tmp += ".lua"; - - int size = tmp.size(); - - for (int i=0; iexists(tmp.c_str())) - { - lua_pop(L, 1); - lua_pushstring(L, tmp.c_str()); - // Ok, load it. - return w_load(L); - } - - tmp = filename; - size = tmp.size(); - for (int i=0; iisDirectory(tmp.c_str())) - { - tmp += "/init.lua"; - if (instance->exists(tmp.c_str())) - { - lua_pop(L, 1); - lua_pushstring(L, tmp.c_str()); - // Ok, load it. - return w_load(L); - } - } - - std::string errstr = "\n\tno file '%s' in LOVE game directories."; - errstr += errstr; - - lua_pushfstring(L, errstr.c_str(), (tmp + ".lua").c_str(), (tmp + "/init.lua").c_str()); - return 1; -} - -inline const char *library_extension() -{ -#ifdef LOVE_WINDOWS - return ".dll"; -#else - return ".so"; -#endif -} - -int extloader(lua_State *L) -{ - const char *filename = lua_tostring(L, -1); - std::string tokenized_name(filename); - std::string tokenized_function(filename); - - for (unsigned int i = 0; i < tokenized_name.size(); i++) - { - if (tokenized_name[i] == '.') - { - tokenized_name[i] = '/'; - tokenized_function[i] = '_'; - } - } - - tokenized_name += library_extension(); - - void *handle = nullptr; - - // If the game is fused, try looking for the DLL in the game's read paths. - if (instance->isFused()) - { - try - { - std::string dir = instance->getRealDirectory(tokenized_name.c_str()); - - // We don't want to look in the game's source, because it can be a - // zip sometimes and a folder other times. - if (dir.find(instance->getSource()) == std::string::npos) - handle = SDL_LoadObject((dir + LOVE_PATH_SEPARATOR + tokenized_name).c_str()); - } - catch (love::Exception &) - { - // Nothing... - } - } - - if (!handle) - { - std::string path = std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name; - handle = SDL_LoadObject(path.c_str()); - } - - if (!handle) - { - lua_pushfstring(L, "\n\tno file '%s' in LOVE paths.", tokenized_name.c_str()); - return 1; - } - - void *func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str()); - if (!func) - func = SDL_LoadFunction(handle, ("luaopen_" + tokenized_function).c_str()); - - if (!func) - { - SDL_UnloadObject(handle); - lua_pushfstring(L, "\n\tC library '%s' is incompatible.", tokenized_name.c_str()); - return 1; - } - - lua_pushcfunction(L, (lua_CFunction) func); - return 1; -} - -// List of functions to wrap. -static const luaL_Reg functions[] = -{ - { "init", w_init }, - { "setFused", w_setFused }, - { "isFused", w_isFused }, - { "setIdentity", w_setIdentity }, - { "getIdentity", w_getIdentity }, - { "setSource", w_setSource }, - { "getSource", w_getSource }, - { "mount", w_mount }, - { "unmount", w_unmount }, - { "newFile", w_newFile }, - { "getWorkingDirectory", w_getWorkingDirectory }, - { "getUserDirectory", w_getUserDirectory }, - { "getAppdataDirectory", w_getAppdataDirectory }, - { "getSaveDirectory", w_getSaveDirectory }, - { "getSourceBaseDirectory", w_getSourceBaseDirectory }, - { "exists", w_exists }, - { "isDirectory", w_isDirectory }, - { "isFile", w_isFile }, - { "createDirectory", w_createDirectory }, - { "remove", w_remove }, - { "read", w_read }, - { "write", w_write }, - { "append", w_append }, - { "getDirectoryItems", w_getDirectoryItems }, - { "lines", w_lines }, - { "load", w_load }, - { "getLastModified", w_getLastModified }, - { "getSize", w_getSize }, - { "newFileData", w_newFileData }, - { 0, 0 } -}; - -static const lua_CFunction types[] = -{ - luaopen_file, - luaopen_filedata, - 0 -}; - -extern "C" int luaopen_love_filesystem(lua_State *L) -{ - if (instance == 0) - { - EXCEPT_GUARD(instance = new Filesystem();) - } - else - instance->retain(); - - // The love loaders should be tried after package.preload. - love::luax_register_searcher(L, loader, 2); - love::luax_register_searcher(L, extloader, 3); - - WrappedModule w; - w.module = instance; - w.name = "filesystem"; - w.flags = MODULE_FILESYSTEM_T; - w.functions = functions; - w.types = types; - - return luax_register_module(L, w); -} - -} // physfs -} // filesystem -} // love diff --git a/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.h b/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.h deleted file mode 100644 index 711c5eb5..00000000 --- a/jni/love/src/modules/filesystem/physfs/wrap_Filesystem.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -#ifndef LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H -#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H - -// LOVE -#include "Filesystem.h" -#include "wrap_File.h" -#include "wrap_FileData.h" - -namespace love -{ -namespace filesystem -{ -namespace physfs -{ - -bool hack_setupWriteDirectory(); -int w_init(lua_State *L); -int w_setFused(lua_State *L); -int w_isFused(lua_State *L); -int w_setIdentity(lua_State *L); -int w_getIdentity(lua_State *L); -int w_setSource(lua_State *L); -int w_getSource(lua_State *L); -int w_mount(lua_State *L); -int w_unmount(lua_State *L); -int w_newFile(lua_State *L); -int w_newFileData(lua_State *L); -int w_getWorkingDirectory(lua_State *L); -int w_getUserDirectory(lua_State *L); -int w_getAppdataDirectory(lua_State *L); -int w_getSaveDirectory(lua_State *L); -int w_getSourceBaseDirectory(lua_State *L); -int w_exists(lua_State *L); -int w_isDirectory(lua_State *L); -int w_isFile(lua_State *L); -int w_createDirectory(lua_State *L); -int w_remove(lua_State *L); -int w_open(lua_State *L); -int w_close(lua_State *L); -int w_read(lua_State *L); -int w_write(lua_State *L); -int w_append(lua_State *L); -int w_getDirectoryItems(lua_State *L); -int w_lines(lua_State *L); -int w_load(lua_State *L); -int w_getLastModified(lua_State *L); -int w_getSize(lua_State *L); -int loader(lua_State *L); -int extloader(lua_State *L); -extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State *L); - -} // physfs -} // filesystem -} // love - -#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H diff --git a/jni/love/src/modules/joystick/sdl/wrap_Joystick.cpp b/jni/love/src/modules/joystick/sdl/wrap_Joystick.cpp deleted file mode 100644 index 90a3f4d3..00000000 --- a/jni/love/src/modules/joystick/sdl/wrap_Joystick.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -// LOVE -#include "wrap_Joystick.h" -#include "wrap_JoystickModule.h" - -#include - -namespace love -{ -namespace joystick -{ -namespace sdl -{ - -Joystick *luax_checkjoystick(lua_State *L, int idx) -{ - return luax_checktype(L, idx, "Joystick", JOYSTICK_JOYSTICK_T); -} - -int w_Joystick_isConnected(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - luax_pushboolean(L, j->isConnected()); - return 1; -} - -int w_Joystick_getName(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - lua_pushstring(L, j->getName()); - return 1; -} - -int w_Joystick_getID(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - - // IDs are 1-based in Lua. - lua_pushinteger(L, j->getID() + 1); - - int instanceid = j->getInstanceID(); - if (instanceid >= 0) - lua_pushinteger(L, instanceid + 1); - else - lua_pushnil(L); - - return 2; -} - -int w_Joystick_getGUID(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - luax_pushstring(L, j->getGUID()); - return 1; -} - -int w_Joystick_getAxisCount(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - lua_pushinteger(L, j->getAxisCount()); - return 1; -} - -int w_Joystick_getButtonCount(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - lua_pushinteger(L, j->getButtonCount()); - return 1; -} - -int w_Joystick_getHatCount(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - lua_pushinteger(L, j->getHatCount()); - return 1; -} - -int w_Joystick_getAxis(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - int axisindex = luaL_checkint(L, 2) - 1; - lua_pushnumber(L, j->getAxis(axisindex)); - return 1; -} - -int w_Joystick_getAxes(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - std::vector axes = j->getAxes(); - - for (size_t i = 0; i < axes.size(); i++) - lua_pushnumber(L, axes[i]); - - return (int) axes.size(); -} - -int w_Joystick_getHat(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - int hatindex = luaL_checkint(L, 2) - 1; - - Joystick::Hat h = j->getHat(hatindex); - - const char *direction = ""; - love::joystick::Joystick::getConstant(h, direction); - - lua_pushstring(L, direction); - return 1; -} - -int w_Joystick_isDown(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - - luaL_checkinteger(L, 2); - - std::vector buttons; - for (int i = 2; i <= lua_gettop(L); i++) - buttons.push_back(luaL_checkint(L, i) - 1); - - luax_pushboolean(L, j->isDown(buttons)); - return 1; -} - -int w_Joystick_isGamepad(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - luax_pushboolean(L, j->isGamepad()); - return 1; -} - -int w_Joystick_getGamepadAxis(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - - const char *str = luaL_checkstring(L, 2); - Joystick::GamepadAxis axis; - - if (!joystick::Joystick::getConstant(str, axis)) - return luaL_error(L, "Invalid gamepad axis: %s", str); - - lua_pushnumber(L, j->getGamepadAxis(axis)); - return 1; -} - -int w_Joystick_isGamepadDown(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - - std::vector buttons; - buttons.reserve(lua_gettop(L) - 1); - - luaL_checkstring(L, 2); - - for (int i = 2; i <= lua_gettop(L); i++) - { - const char *str = luaL_checkstring(L, i); - Joystick::GamepadButton button; - - if (!joystick::Joystick::getConstant(str, button)) - return luaL_error(L, "Invalid gamepad button: %s", str); - - buttons.push_back(button); - } - - luax_pushboolean(L, j->isGamepadDown(buttons)); - return 1; -} - -int w_Joystick_isVibrationSupported(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - luax_pushboolean(L, j->isVibrationSupported()); - return 1; -} - -int w_Joystick_setVibration(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - bool success = false; - - if (lua_isnoneornil(L, 2)) - { - // Disable joystick vibration if no argument is given. - success = j->setVibration(); - } - else - { - float left = (float) luaL_checknumber(L, 2); - float right = (float) luaL_optnumber(L, 3, left); - float duration = (float) luaL_optnumber(L, 4, -1.0); // -1 is infinite. - success = j->setVibration(left, right, duration); - } - - luax_pushboolean(L, success); - return 1; -} - -int w_Joystick_getVibration(lua_State *L) -{ - Joystick *j = luax_checkjoystick(L, 1); - float left, right; - j->getVibration(left, right); - lua_pushnumber(L, left); - lua_pushnumber(L, right); - return 2; -} - -// List of functions to wrap. -static const luaL_Reg functions[] = -{ - { "isConnected", w_Joystick_isConnected }, - { "getName", w_Joystick_getName }, - { "getID", w_Joystick_getID }, - { "getGUID", w_Joystick_getGUID }, - { "getAxisCount", w_Joystick_getAxisCount }, - { "getButtonCount", w_Joystick_getButtonCount }, - { "getHatCount", w_Joystick_getHatCount }, - { "getAxis", w_Joystick_getAxis }, - { "getAxes", w_Joystick_getAxes }, - { "getHat", w_Joystick_getHat }, - { "isDown", w_Joystick_isDown }, - - { "isGamepad", w_Joystick_isGamepad }, - { "getGamepadAxis", w_Joystick_getGamepadAxis }, - { "isGamepadDown", w_Joystick_isGamepadDown }, - - { "isVibrationSupported", w_Joystick_isVibrationSupported }, - { "setVibration", w_Joystick_setVibration }, - { "getVibration", w_Joystick_getVibration }, - - // From wrap_JoystickModule. - { "getConnectedIndex", w_getIndex }, - { "getGamepadMapping", w_getGamepadMapping }, - { 0, 0 }, -}; - -extern "C" int luaopen_joystick(lua_State *L) -{ - return luax_register_type(L, "Joystick", functions); -} - -} // sdl -} // joystick -} // love diff --git a/jni/love/src/modules/joystick/sdl/wrap_Joystick.h b/jni/love/src/modules/joystick/sdl/wrap_Joystick.h deleted file mode 100644 index 42f446d8..00000000 --- a/jni/love/src/modules/joystick/sdl/wrap_Joystick.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -#ifndef LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_H -#define LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_H - -// LOVE -#include "common/config.h" -#include "Joystick.h" -#include "common/runtime.h" - -namespace love -{ -namespace joystick -{ -namespace sdl -{ - -Joystick *luax_checkjoystick(lua_State *L, int idx); -int w_Joystick_isConnected(lua_State *L); -int w_Joystick_getName(lua_State *L); -int w_Joystick_getID(lua_State *L); -int w_Joystick_getGUID(lua_State *L); -int w_Joystick_getAxisCount(lua_State *L); -int w_Joystick_getButtonCount(lua_State *L); -int w_Joystick_getHatCount(lua_State *L); -int w_Joystick_getAxis(lua_State *L); -int w_Joystick_getAxes(lua_State *L); -int w_Joystick_getHat(lua_State *L); -int w_Joystick_isDown(lua_State *L); -int w_Joystick_isGamepad(lua_State *L); -int w_Joystick_getGamepadAxis(lua_State *L); -int w_Joystick_isGamepadDown(lua_State *L); -int w_Joystick_isVibrationSupported(lua_State *L); -int w_Joystick_setVibration(lua_State *L); -int w_Joystick_getVibration(lua_State *L); -extern "C" int luaopen_joystick(lua_State *L); - -} // sdl -} // joystick -} // love - -#endif // LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_H diff --git a/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.cpp b/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.cpp deleted file mode 100644 index 7a438ff1..00000000 --- a/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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 "wrap_JoystickModule.h" -#include "wrap_Joystick.h" - -namespace love -{ -namespace joystick -{ -namespace sdl -{ - -static JoystickModule *instance = nullptr; - -int w_getJoysticks(lua_State *L) -{ - int stickcount = instance->getJoystickCount(); - lua_createtable(L, stickcount, 0); - - for (int i = 0; i < stickcount; i++) - { - love::joystick::Joystick *stick = instance->getJoystick(i); - stick->retain(); - luax_pushtype(L, "Joystick", JOYSTICK_JOYSTICK_T, stick); - lua_rawseti(L, -2, i + 1); - } - - return 1; -} - -int w_getIndex(lua_State *L) -{ - love::joystick::Joystick *j = luax_checkjoystick(L, 1); - int index = instance->getIndex(j); - if (index >= 0) - lua_pushinteger(L, index + 1); - else - lua_pushnil(L); - return 1; -} - -int w_getJoystickCount(lua_State *L) -{ - lua_pushinteger(L, instance->getJoystickCount()); - return 1; -} - -int w_setGamepadMapping(lua_State *L) -{ - // Only accept a GUID string. We don't accept a Joystick object because - // the gamepad mapping applies to all joysticks with the same GUID (e.g. all - // Xbox 360 controllers on the system), rather than individual objects. - const char *guid = luaL_checkstring(L, 1); - - const char *gpbindstr = luaL_checkstring(L, 2); - Joystick::GamepadInput gpinput; - - if (love::joystick::Joystick::getConstant(gpbindstr, gpinput.axis)) - gpinput.type = Joystick::INPUT_TYPE_AXIS; - else if (love::joystick::Joystick::getConstant(gpbindstr, gpinput.button)) - gpinput.type = Joystick::INPUT_TYPE_BUTTON; - else - return luaL_error(L, "Invalid gamepad axis/button: %s", gpbindstr); - - const char *jinputtypestr = luaL_checkstring(L, 3); - Joystick::JoystickInput jinput; - - if (!love::joystick::Joystick::getConstant(jinputtypestr, jinput.type)) - return luaL_error(L, "Invalid joystick input type: %s", jinputtypestr); - - const char *hatstr; - switch (jinput.type) - { - case Joystick::INPUT_TYPE_AXIS: - jinput.axis = luaL_checkint(L, 4) - 1; - break; - case Joystick::INPUT_TYPE_BUTTON: - jinput.button = luaL_checkint(L, 4) - 1; - break; - case Joystick::INPUT_TYPE_HAT: - // Hats need both a hat index and a hat value. - jinput.hat.index = luaL_checkint(L, 4) - 1; - hatstr = luaL_checkstring(L, 5); - if (!love::joystick::Joystick::getConstant(hatstr, jinput.hat.value)) - return luaL_error(L, "Invalid joystick hat: %s", hatstr); - break; - default: - return luaL_error(L, "Invalid joystick input type: %s", jinputtypestr); - } - - bool success = false; - EXCEPT_GUARD(success = instance->setGamepadMapping(guid, gpinput, jinput);) - - luax_pushboolean(L, success); - return 1; -} - -int w_getGamepadMapping(lua_State *L) -{ - std::string guid; - - // Accept either a GUID string or a Joystick object. This way we can re-use - // the function for Joystick:getGamepadMapping. - if (lua_type(L, 1) == LUA_TSTRING) - guid = luax_checkstring(L, 1); - else - { - love::joystick::Joystick *stick = luax_checkjoystick(L, 1); - guid = stick->getGUID(); - } - - const char *gpbindstr = luaL_checkstring(L, 2); - Joystick::GamepadInput gpinput; - - if (love::joystick::Joystick::getConstant(gpbindstr, gpinput.axis)) - gpinput.type = Joystick::INPUT_TYPE_AXIS; - else if (love::joystick::Joystick::getConstant(gpbindstr, gpinput.button)) - gpinput.type = Joystick::INPUT_TYPE_BUTTON; - else - return luaL_error(L, "Invalid gamepad axis/button: %s", gpbindstr); - - Joystick::JoystickInput jinput; - jinput.type = Joystick::INPUT_TYPE_MAX_ENUM; - - EXCEPT_GUARD(jinput = instance->getGamepadMapping(guid, gpinput);) - - if (jinput.type == Joystick::INPUT_TYPE_MAX_ENUM) - return 0; - - const char *inputtypestr; - if (!love::joystick::Joystick::getConstant(jinput.type, inputtypestr)) - return luaL_error(L, "Unknown joystick input type."); - - lua_pushstring(L, inputtypestr); - - const char *hatstr; - switch (jinput.type) - { - case Joystick::INPUT_TYPE_AXIS: - lua_pushinteger(L, jinput.axis + 1); - return 2; - case Joystick::INPUT_TYPE_BUTTON: - lua_pushinteger(L, jinput.button + 1); - return 2; - case Joystick::INPUT_TYPE_HAT: - lua_pushinteger(L, jinput.hat.index + 1); - if (love::joystick::Joystick::getConstant(jinput.hat.value, hatstr)) - { - lua_pushstring(L, hatstr); - return 3; - } - else - return luaL_error(L, "Unknown joystick hat."); - default: - break; // ? - } - - return 1; -} - -// List of functions to wrap. -static const luaL_Reg functions[] = -{ - { "getJoysticks", w_getJoysticks }, - { "getJoystickCount", w_getJoystickCount }, - { "setGamepadMapping", w_setGamepadMapping }, - { "getGamepadMapping", w_getGamepadMapping }, - { 0, 0 } -}; - -static const lua_CFunction types[] = -{ - luaopen_joystick, - 0, -}; - -extern "C" int luaopen_love_joystick(lua_State *L) -{ - if (instance == nullptr) - { - EXCEPT_GUARD(instance = new JoystickModule();) - } - else - instance->retain(); - - WrappedModule w; - w.module = instance; - w.name = "joystick"; - w.flags = MODULE_T; - w.functions = functions; - w.types = types; - - return luax_register_module(L, w); -} - -} // sdl -} // joystick -} // love diff --git a/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.h b/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.h deleted file mode 100644 index 24de3264..00000000 --- a/jni/love/src/modules/joystick/sdl/wrap_JoystickModule.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2006-2014 LOVE Development Team - * - * 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. - **/ - -#ifndef LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_MODULE_H -#define LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_MODULE_H - -// LOVE -#include "common/config.h" -#include "common/runtime.h" -#include "JoystickModule.h" - -namespace love -{ -namespace joystick -{ -namespace sdl -{ - -int w_getJoysticks(lua_State *L); -int w_getIndex(lua_State *L); -int w_getJoystickCount(lua_State *L); -int w_setGamepadMapping(lua_State *L); -int w_getGamepadMapping(lua_State *L); -extern "C" LOVE_EXPORT int luaopen_love_joystick(lua_State *L); - -} // sdl -} // joystick -} // love - -#endif // LOVE_JOYSTICK_SDL_WRAP_JOYSTICK_MODULE_H diff --git a/src/org/love2d/android/GameLoaderActivity._java b/src/org/love2d/android/GameLoaderActivity._java deleted file mode 100644 index 5abda920..00000000 --- a/src/org/love2d/android/GameLoaderActivity._java +++ /dev/null @@ -1,117 +0,0 @@ -package org.love2d.android; - -import org.libsdl.app.SDLActivity; -import org.love2d.android.GameActivity; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; - -import android.app.Activity; -import android.app.DownloadManager; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.os.PowerManager; -import android.os.ResultReceiver; -import android.util.Log; -import android.util.DisplayMetrics; -import android.widget.Toast; - -public class GameLoaderActivity extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - Log.d("GameActivity", "started"); - - context = this.getApplicationContext(); - - String gamePath; - - Uri game = this.getIntent().getData(); - if (game != null) { - if (game.getScheme().equals ("file")) { - gamePath = game.getPath(); - } else { - copyGameToCache (game); - } - Log.d("GameActivity", "Selected the file: " + getGamePath()); - } - - this.getIntent().addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP); - - Toast.makeText ("Loading game " + gamePath); - - super.onCreate(savedInstanceState); - } - - public static void openURL (String url) { - Log.d ("GameActivity", "opening url = " + url); - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse(url)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); - } - - void copyGameToCache (Uri sourceuri) - { - String destinationFilename = this.getCacheDir().getPath()+"/downloaded.love"; - gamePath = destinationFilename; - - BufferedOutputStream bos = null; - try { - bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false)); - } catch (IOException e) { - Log.d ("GameActivity", "Could not open destination file:" + e.getMessage()); - } - - int chunk_read = 0; - int bytes_written = 0; - - BufferedInputStream bis = null; - if (sourceuri.getScheme().equals("content")) { - try { - bis = new BufferedInputStream(getContentResolver().openInputStream(sourceuri)); - } catch (IOException e) { - Log.d ("GameActivity", "Could not open game file:" + e.getMessage()); - } - } else { - Log.d ("GameActivity", "Unsupported scheme: " + sourceuri.getScheme()); - } - - if (bis != null) { - // actual copying - try { - byte[] buf = new byte[1024]; - chunk_read = bis.read(buf); - do { - bos.write(buf, 0, chunk_read); - bytes_written += chunk_read; - chunk_read = bis.read(buf); - } while(chunk_read != -1); - } catch (IOException e) { - Log.d ("GameActivity", "Copying failed:" + e.getMessage()); - } - } - - // close streams - try { - if (bis != null) bis.close(); - if (bos != null) bos.close(); - } catch (IOException e) { - Log.d ("GameActivity", "Copying failed: " + e.getMessage()); - } - - Log.d("GameActivity", "Copied " + bytes_written + " bytes"); - } -}