WinRT: merged with latest SDL 2.x/HG code

SDL 2.x recently accepted patches to enable OpenGL ES 2 support via Google's ANGLE library.  The thought is to try to eventually merge SDL/WinRT's OpenGL code with SDL-official's.
This commit is contained in:
David Ludwig
2013-11-28 22:09:21 -05:00
999 changed files with 140431 additions and 5035 deletions

View File

@@ -289,8 +289,6 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
return SDL_PrivateGetControllerMappingForGUID(&jGUID);
}
return NULL;
}
static const char* map_StringForControllerAxis[] = {

View File

@@ -57,9 +57,11 @@ static const char *s_ControllerMappings [] =
"030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
"030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
"03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,"
"030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
#endif
NULL
};

View File

@@ -832,7 +832,7 @@ SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
int maxoutputbytes= sizeof(guid);
size_t len = SDL_strlen( pchGUID );
Uint8 *p;
int i;
size_t i;
/* Make sure it's even */
len = ( len ) & ~0x1;

View File

@@ -29,11 +29,115 @@
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_joystick.h"
#include "SDL_hints.h"
#include "SDL_assert.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#include "../../core/android/SDL_android.h"
static const char *accelerometerName = "Android accelerometer";
#include "android/keycodes.h"
/* As of platform android-14, android/keycodes.h is missing these defines */
#ifndef AKEYCODE_BUTTON_1
#define AKEYCODE_BUTTON_1 188
#define AKEYCODE_BUTTON_2 189
#define AKEYCODE_BUTTON_3 190
#define AKEYCODE_BUTTON_4 191
#define AKEYCODE_BUTTON_5 192
#define AKEYCODE_BUTTON_6 193
#define AKEYCODE_BUTTON_7 194
#define AKEYCODE_BUTTON_8 195
#define AKEYCODE_BUTTON_9 196
#define AKEYCODE_BUTTON_10 197
#define AKEYCODE_BUTTON_11 198
#define AKEYCODE_BUTTON_12 199
#define AKEYCODE_BUTTON_13 200
#define AKEYCODE_BUTTON_14 201
#define AKEYCODE_BUTTON_15 202
#define AKEYCODE_BUTTON_16 203
#endif
#define ANDROID_ACCELEROMETER_INDEX (SYS_numjoysticks - 1)
#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer"
#define ANDROID_MAX_NBUTTONS 36
static SDL_Joystick **SYS_Joysticks;
static char **SYS_JoystickNames;
static int SYS_numjoysticks;
static SDL_bool SYS_accelAsJoy;
/* Function to convert Android keyCodes into SDL ones.
* This code manipulation is done to get a sequential list of codes.
* FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
*/
static int
keycode_to_SDL(int keycode)
{
/* FIXME: If this function gets too unwiedly in the future, replace with a lookup table */
int button = 0;
switch(keycode)
{
/* D-Pad key codes (API 1), these get mapped to 0...4 */
case AKEYCODE_DPAD_UP:
case AKEYCODE_DPAD_DOWN:
case AKEYCODE_DPAD_LEFT:
case AKEYCODE_DPAD_RIGHT:
case AKEYCODE_DPAD_CENTER:
button = keycode - AKEYCODE_DPAD_UP;
break;
/* Some gamepad buttons (API 9), these get mapped to 5...19*/
case AKEYCODE_BUTTON_A:
case AKEYCODE_BUTTON_B:
case AKEYCODE_BUTTON_C:
case AKEYCODE_BUTTON_X:
case AKEYCODE_BUTTON_Y:
case AKEYCODE_BUTTON_Z:
case AKEYCODE_BUTTON_L1:
case AKEYCODE_BUTTON_L2:
case AKEYCODE_BUTTON_R1:
case AKEYCODE_BUTTON_R2:
case AKEYCODE_BUTTON_THUMBL:
case AKEYCODE_BUTTON_THUMBR:
case AKEYCODE_BUTTON_START:
case AKEYCODE_BUTTON_SELECT:
case AKEYCODE_BUTTON_MODE:
button = keycode - AKEYCODE_BUTTON_A + 5;
break;
/* More gamepad buttons (API 12), these get mapped to 20...35*/
case AKEYCODE_BUTTON_1:
case AKEYCODE_BUTTON_2:
case AKEYCODE_BUTTON_3:
case AKEYCODE_BUTTON_4:
case AKEYCODE_BUTTON_5:
case AKEYCODE_BUTTON_6:
case AKEYCODE_BUTTON_7:
case AKEYCODE_BUTTON_8:
case AKEYCODE_BUTTON_9:
case AKEYCODE_BUTTON_10:
case AKEYCODE_BUTTON_11:
case AKEYCODE_BUTTON_12:
case AKEYCODE_BUTTON_13:
case AKEYCODE_BUTTON_14:
case AKEYCODE_BUTTON_15:
case AKEYCODE_BUTTON_16:
button = keycode - AKEYCODE_BUTTON_1 + 20;
break;
default:
return -1;
break;
}
/* This is here in case future generations, probably with six fingers per hand,
* happily add new cases up above and forget to update the max number of buttons.
*/
SDL_assert(button < ANDROID_MAX_NBUTTONS);
return button;
}
/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
@@ -43,18 +147,54 @@ static const char *accelerometerName = "Android accelerometer";
int
SDL_SYS_JoystickInit(void)
{
return (1);
int i = 0;
const char *env;
env = SDL_GetHint(SDL_HINT_ACCEL_AS_JOY);
if (env && !SDL_atoi(env))
SYS_accelAsJoy = SDL_FALSE;
else
SYS_accelAsJoy = SDL_TRUE; /* Default behavior */
SYS_numjoysticks = Android_JNI_GetNumJoysticks();
if (SYS_accelAsJoy) {
SYS_numjoysticks++;
}
SYS_Joysticks = (SDL_Joystick **)SDL_calloc(1, SYS_numjoysticks*sizeof(SDL_Joystick *));
if (SYS_Joysticks == NULL)
{
return SDL_OutOfMemory();
}
SYS_JoystickNames = (char **)SDL_calloc(1, SYS_numjoysticks*sizeof(char *));
if (SYS_JoystickNames == NULL)
{
SDL_free(SYS_Joysticks);
SYS_Joysticks = NULL;
return SDL_OutOfMemory();
}
for (i = 0; i < SYS_numjoysticks; i++)
{
if ( SYS_accelAsJoy && i == ANDROID_ACCELEROMETER_INDEX ) {
SYS_JoystickNames[i] = ANDROID_ACCELEROMETER_NAME;
} else {
SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i);
}
}
return (SYS_numjoysticks);
}
int SDL_SYS_NumJoysticks()
{
return 1;
return SYS_numjoysticks;
}
void SDL_SYS_JoystickDetect()
{
}
/* TODO: Hotplugging support */
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
@@ -64,7 +204,7 @@ SDL_bool SDL_SYS_JoystickNeedsPolling()
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
{
return accelerometerName;
return SYS_JoystickNames[device_index];
}
/* Function to perform the mapping from device index to the instance id for this index */
@@ -81,15 +221,22 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
int
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
{
if (device_index == 0) {
joystick->nbuttons = 0;
if (device_index < SYS_numjoysticks) {
joystick->nhats = 0;
joystick->nballs = 0;
joystick->naxes = 3;
if (SYS_accelAsJoy && device_index == ANDROID_ACCELEROMETER_INDEX) {
joystick->nbuttons = 0;
joystick->naxes = 3;
} else {
/* FIXME: Get the real number of buttons in the device? */
joystick->nbuttons = ANDROID_MAX_NBUTTONS;
joystick->naxes = Android_JNI_GetJoystickAxes(device_index);
}
SYS_Joysticks[device_index] = joystick;
return 0;
} else {
SDL_SetError("No joystick available with that index");
return (-1);
return SDL_SetError("No joystick available with that index");
}
}
@@ -111,7 +258,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
Sint16 value;
float values[3];
if (Android_JNI_GetAccelerometerValues(values)) {
if (SYS_accelAsJoy && Android_JNI_GetAccelerometerValues(values) &&
joystick->instance_id == ANDROID_ACCELEROMETER_INDEX) {
for ( i = 0; i < 3; i++ ) {
value = (Sint16)(values[i] * 32767.0f);
SDL_PrivateJoystickAxis(joystick, i, value);
@@ -123,12 +271,25 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
int device_index;
for (device_index = 0; device_index < SYS_numjoysticks; device_index++) {
if ( SYS_Joysticks[device_index] == joystick ) {
SYS_Joysticks[device_index] = NULL;
}
}
joystick->closed = 1;
}
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
{
SDL_free(SYS_JoystickNames);
SDL_free(SYS_Joysticks);
SYS_JoystickNames = NULL;
SYS_Joysticks = NULL;
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
@@ -151,6 +312,46 @@ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
return guid;
}
int
Android_OnPadDown(int padId, int keycode)
{
int button = keycode_to_SDL(keycode);
if (button >= 0) {
if (SYS_Joysticks[padId]) {
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button , SDL_PRESSED);
}
return 0;
}
return -1;
}
int
Android_OnPadUp(int padId, int keycode)
{
int button = keycode_to_SDL(keycode);
if (button >= 0) {
if (SYS_Joysticks[padId]) {
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button, SDL_RELEASED);
}
return 0;
}
return -1;
}
int
Android_OnJoy(int joyId, int axis, float value)
{
/* Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] */
/* TODO: Are the reported values right? */
if (SYS_Joysticks[joyId]) {
SDL_PrivateJoystickAxis(SYS_Joysticks[joyId], axis, (Sint16) (32767.*value) );
}
return 0;
}
#endif /* SDL_JOYSTICK_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,28 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
extern int Android_OnPadDown(int padId, int keycode);
extern int Android_OnPadUp(int padId, int keycode);
extern int Android_OnJoy(int joyId, int axisnum, float value);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -32,12 +32,7 @@
#include <mach/mach_error.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#ifdef MACOS_10_0_4
#include <IOKit/hidsystem/IOHIDUsageTables.h>
#else
/* The header was moved here in Mac OS X 10.1 */
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
#endif
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>

View File

@@ -20,12 +20,12 @@
*/
#include "SDL_config.h"
#ifdef SDL_JOYSTICK_BEOS
#ifdef SDL_JOYSTICK_HAIKU
/* This is the system specific header for the SDL joystick API */
#include <be/support/String.h>
#include <be/device/Joystick.h>
#include <os/support/String.h>
#include <os/device/Joystick.h>
extern "C"
{
@@ -276,5 +276,6 @@ extern "C"
}; // extern "C"
#endif /* SDL_JOYSTICK_BEOS */
#endif /* SDL_JOYSTICK_HAIKU */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -85,11 +85,14 @@ static int instance_counter = 0;
static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
struct input_id inpid;
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
#if !SDL_USE_LIBUDEV
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
unsigned long evbit[NBITS(EV_MAX)] = { 0 };
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
struct input_id inpid;
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
@@ -101,6 +104,7 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
return 0;
}
#endif
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
return 0;
@@ -230,12 +234,15 @@ MaybeAddDevice(const char *path)
SDL_joylist_tail = item;
}
/* Need to increment the joystick count before we post the event */
++numjoysticks;
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
#if !SDL_EVENTS_DISABLED
event.type = SDL_JOYDEVICEADDED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = numjoysticks;
event.jdevice.which = (numjoysticks - 1);
if ( (SDL_EventOK == NULL) ||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
SDL_PushEvent(&event);
@@ -243,7 +250,7 @@ MaybeAddDevice(const char *path)
}
#endif /* !SDL_EVENTS_DISABLED */
return numjoysticks++;
return numjoysticks;
}
#if SDL_USE_LIBUDEV
@@ -278,6 +285,9 @@ MaybeRemoveDevice(const char *path)
SDL_joylist_tail = prev;
}
/* Need to decrement the joystick count before we post the event */
--numjoysticks;
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
#if !SDL_EVENTS_DISABLED
event.type = SDL_JOYDEVICEREMOVED;
@@ -294,7 +304,6 @@ MaybeRemoveDevice(const char *path)
SDL_free(item->path);
SDL_free(item->name);
SDL_free(item);
numjoysticks--;
return retval;
}
prev = item;