File style cleanup for the SDL 2.0 release

This commit is contained in:
Sam Lantinga 2013-05-18 14:17:52 -07:00
parent 2ac8624930
commit 0cb6385637
376 changed files with 17562 additions and 17773 deletions

File diff suppressed because it is too large Load diff

View file

@ -78,26 +78,26 @@ SDL_Joystick *
SDL_JoystickOpen(int device_index)
{
SDL_Joystick *joystick;
SDL_Joystick *joysticklist;
const char *joystickname = NULL;
SDL_Joystick *joysticklist;
const char *joystickname = NULL;
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
return (NULL);
}
joysticklist = SDL_joysticks;
/* If the joystick is already open, return it
* it is important that we have a single joystick * for each instance id
*/
while ( joysticklist )
{
if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id ) {
joystick = joysticklist;
++joystick->ref_count;
return (joystick);
}
joysticklist = joysticklist->next;
joysticklist = SDL_joysticks;
/* If the joystick is already open, return it
* it is important that we have a single joystick * for each instance id
*/
while ( joysticklist )
{
if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id ) {
joystick = joysticklist;
++joystick->ref_count;
return (joystick);
}
joysticklist = joysticklist->next;
}
/* Create and initialize the joystick */
@ -113,11 +113,11 @@ SDL_JoystickOpen(int device_index)
return NULL;
}
joystickname = SDL_SYS_JoystickNameForDeviceIndex( device_index );
if ( joystickname )
joystick->name = SDL_strdup( joystickname );
else
joystick->name = NULL;
joystickname = SDL_SYS_JoystickNameForDeviceIndex( device_index );
if ( joystickname )
joystick->name = SDL_strdup( joystickname );
else
joystick->name = NULL;
if (joystick->naxes > 0) {
joystick->axes = (Sint16 *) SDL_malloc
@ -159,11 +159,11 @@ SDL_JoystickOpen(int device_index)
/* Add joystick to list */
++joystick->ref_count;
/* Link the joystick in the list */
joystick->next = SDL_joysticks;
SDL_joysticks = joystick;
/* Link the joystick in the list */
joystick->next = SDL_joysticks;
SDL_joysticks = joystick;
SDL_SYS_JoystickUpdate( joystick );
SDL_SYS_JoystickUpdate( joystick );
return (joystick);
}
@ -183,12 +183,12 @@ SDL_PrivateJoystickValid(SDL_Joystick * joystick)
} else {
valid = 1;
}
if ( joystick && joystick->closed )
{
valid = 0;
}
if ( joystick && joystick->closed )
{
valid = 0;
}
return valid;
}
@ -335,24 +335,24 @@ SDL_JoystickGetButton(SDL_Joystick * joystick, int button)
SDL_bool
SDL_JoystickGetAttached(SDL_Joystick * joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
return SDL_SYS_JoystickAttached(joystick);
return SDL_SYS_JoystickAttached(joystick);
}
/*
* Get the instance id for this opened joystick
*/
SDL_JoystickID
SDL_JoystickID
SDL_JoystickInstanceID(SDL_Joystick * joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->instance_id);
return (joystick->instance_id);
}
/*
@ -364,7 +364,7 @@ SDL_JoystickName(SDL_Joystick * joystick)
if (!SDL_PrivateJoystickValid(joystick)) {
return (NULL);
}
return (joystick->name);
}
@ -374,8 +374,8 @@ SDL_JoystickName(SDL_Joystick * joystick)
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
SDL_Joystick *joysticklist;
SDL_Joystick *joysticklistprev;
SDL_Joystick *joysticklist;
SDL_Joystick *joysticklistprev;
if (!joystick) {
return;
@ -391,31 +391,31 @@ SDL_JoystickClose(SDL_Joystick * joystick)
}
SDL_SYS_JoystickClose(joystick);
joysticklist = SDL_joysticks;
joysticklistprev = NULL;
while ( joysticklist )
{
if (joystick == joysticklist)
{
if ( joysticklistprev )
{
// unlink this entry
joysticklistprev->next = joysticklist->next;
}
else
{
SDL_joysticks = joystick->next;
}
break;
}
joysticklistprev = joysticklist;
joysticklist = joysticklist->next;
}
if (joystick->name)
SDL_free(joystick->name);
joysticklist = SDL_joysticks;
joysticklistprev = NULL;
while ( joysticklist )
{
if (joystick == joysticklist)
{
if ( joysticklistprev )
{
/* unlink this entry */
joysticklistprev->next = joysticklist->next;
}
else
{
SDL_joysticks = joystick->next;
}
break;
}
joysticklistprev = joysticklist;
joysticklist = joysticklist->next;
}
if (joystick->name)
SDL_free(joystick->name);
/* Free the data associated with this joystick */
if (joystick->axes) {
@ -440,11 +440,11 @@ SDL_JoystickQuit(void)
SDL_assert(!SDL_updating_joystick);
/* Stop the event polling */
while ( SDL_joysticks )
{
SDL_joysticks->ref_count = 1;
while ( SDL_joysticks )
{
SDL_joysticks->ref_count = 1;
SDL_JoystickClose(SDL_joysticks);
}
}
/* Quit the joystick setup */
SDL_SYS_JoystickQuit();
@ -587,25 +587,25 @@ SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
void
SDL_JoystickUpdate(void)
{
SDL_Joystick *joystick;
joystick = SDL_joysticks;
while ( joystick )
{
SDL_Joystick *joysticknext;
/* save off the next pointer, the Update call may cause a joystick removed event
* and cause our joystick pointer to be freed
*/
joysticknext = joystick->next;
SDL_Joystick *joystick;
joystick = SDL_joysticks;
while ( joystick )
{
SDL_Joystick *joysticknext;
/* save off the next pointer, the Update call may cause a joystick removed event
* and cause our joystick pointer to be freed
*/
joysticknext = joystick->next;
SDL_updating_joystick = joystick;
SDL_SYS_JoystickUpdate( joystick );
if ( joystick->closed && joystick->uncentered )
{
int i;
joystick->uncentered = 0;
if ( joystick->closed && joystick->uncentered )
{
int i;
joystick->uncentered = 0;
/* Tell the app that everything is centered/unpressed... */
for (i = 0; i < joystick->naxes; i++)
@ -617,7 +617,7 @@ SDL_JoystickUpdate(void)
for (i = 0; i < joystick->nhats; i++)
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
}
}
SDL_updating_joystick = NULL;
@ -626,12 +626,13 @@ SDL_JoystickUpdate(void)
SDL_JoystickClose(joystick);
}
joystick = joysticknext;
}
joystick = joysticknext;
}
// this needs to happen AFTER walking the joystick list above, so that any
// dangling hardware data from removed devices can be free'd
SDL_SYS_JoystickDetect();
/* this needs to happen AFTER walking the joystick list above, so that any
dangling hardware data from removed devices can be free'd
*/
SDL_SYS_JoystickDetect();
}
int
@ -667,106 +668,106 @@ SDL_JoystickEventState(int state)
}
/* return 1 if you want to run the joystick update loop this frame, used by hotplug support */
SDL_bool
SDL_bool
SDL_PrivateJoystickNeedsPolling()
{
if (SDL_joysticks != NULL) {
return SDL_TRUE;
} else {
return SDL_SYS_JoystickNeedsPolling();
}
if (SDL_joysticks != NULL) {
return SDL_TRUE;
} else {
return SDL_SYS_JoystickNeedsPolling();
}
}
/* return the guid for this index */
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
{
return SDL_SYS_JoystickGetDeviceGUID( device_index );
return SDL_SYS_JoystickGetDeviceGUID( device_index );
}
/* return the guid for this opened device */
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
{
return SDL_SYS_JoystickGetGUID( joystick );
return SDL_SYS_JoystickGetGUID( joystick );
}
/* convert the guid to a printable string */
void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
if ((pszGUID == NULL) || (cbGUID <= 0)) {
return;
}
for ( i = 0; i < sizeof(guid.data) && i < (cbGUID-1); i++ )
{
// each input byte writes 2 ascii chars, and might write a null byte.
// If we don't have room for next input byte, stop
unsigned char c = guid.data[i];
for ( i = 0; i < sizeof(guid.data) && i < (cbGUID-1); i++ )
{
/* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */
unsigned char c = guid.data[i];
*pszGUID++ = k_rgchHexToASCII[ c >> 4 ];
*pszGUID++ = k_rgchHexToASCII[ c & 0x0F ];
}
*pszGUID = '\0';
*pszGUID++ = k_rgchHexToASCII[ c >> 4 ];
*pszGUID++ = k_rgchHexToASCII[ c & 0x0F ];
}
*pszGUID = '\0';
}
//-----------------------------------------------------------------------------
// Purpose: Returns the 4 bit nibble for a hex character
// Input : c -
// Output : unsigned char
//-----------------------------------------------------------------------------
/*-----------------------------------------------------------------------------
* Purpose: Returns the 4 bit nibble for a hex character
* Input : c -
* Output : unsigned char
*-----------------------------------------------------------------------------*/
static unsigned char nibble( char c )
{
if ( ( c >= '0' ) &&
( c <= '9' ) )
{
return (unsigned char)(c - '0');
}
if ( ( c >= '0' ) &&
( c <= '9' ) )
{
return (unsigned char)(c - '0');
}
if ( ( c >= 'A' ) &&
( c <= 'F' ) )
{
return (unsigned char)(c - 'A' + 0x0a);
}
if ( ( c >= 'A' ) &&
( c <= 'F' ) )
{
return (unsigned char)(c - 'A' + 0x0a);
}
if ( ( c >= 'a' ) &&
( c <= 'f' ) )
{
return (unsigned char)(c - 'a' + 0x0a);
}
if ( ( c >= 'a' ) &&
( c <= 'f' ) )
{
return (unsigned char)(c - 'a' + 0x0a);
}
// received an invalid character, and no real way to return an error
// AssertMsg1( false, "Q_nibble invalid hex character '%c' ", c );
return 0;
/* received an invalid character, and no real way to return an error */
/* AssertMsg1( false, "Q_nibble invalid hex character '%c' ", c ); */
return 0;
}
/* convert the string version of a joystick guid to the struct */
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
{
SDL_JoystickGUID guid;
int maxoutputbytes= sizeof(guid);
int len = SDL_strlen( pchGUID );
Uint8 *p;
int i;
SDL_JoystickGUID guid;
int maxoutputbytes= sizeof(guid);
int len = SDL_strlen( pchGUID );
Uint8 *p;
int i;
// Make sure it's even
len = ( len ) & ~0x1;
/* Make sure it's even */
len = ( len ) & ~0x1;
SDL_memset( &guid, 0x00, sizeof(guid) );
SDL_memset( &guid, 0x00, sizeof(guid) );
p = (Uint8 *)&guid;
for ( i = 0;
( i < len ) && ( ( p - (Uint8 *)&guid ) < maxoutputbytes );
i+=2, p++ )
{
*p = ( nibble( pchGUID[i] ) << 4 ) | nibble( pchGUID[i+1] );
}
p = (Uint8 *)&guid;
for ( i = 0;
( i < len ) && ( ( p - (Uint8 *)&guid ) < maxoutputbytes );
i+=2, p++ )
{
*p = ( nibble( pchGUID[i] ) << 4 ) | nibble( pchGUID[i+1] );
}
return guid;
return guid;
}

View file

@ -41,7 +41,7 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
Uint8 hat, Uint8 value);
extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
Uint8 button, Uint8 state);
/* Helper function to let lower sys layer tell the event system if the joystick code needs to think */
extern SDL_bool SDL_PrivateJoystickNeedsPolling();

View file

@ -87,10 +87,10 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
joystick->nballs = 0;
joystick->naxes = 3;
return 0;
} else {
SDL_SetError("No joystick available with that index");
return (-1);
}
} else {
SDL_SetError("No joystick available with that index");
return (-1);
}
}
/* Function to determine is this joystick is attached to the system right now */
@ -134,7 +134,7 @@ SDL_SYS_JoystickQuit(void)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -144,7 +144,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

View file

@ -261,7 +261,7 @@ extern "C"
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -271,7 +271,7 @@ extern "C"
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

View file

@ -76,9 +76,9 @@
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#define MAX_UHID_JOYS 16
#define MAX_JOY_JOYS 2
#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
#define MAX_UHID_JOYS 16
#define MAX_JOY_JOYS 2
#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
struct report
@ -589,7 +589,7 @@ SDL_SYS_JoystickQuit(void)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -599,7 +599,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

View file

@ -127,7 +127,7 @@ HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
{
recDevice *device = (recDevice *) refcon;
device->removed = 1;
s_bDeviceRemoved = SDL_TRUE;
s_bDeviceRemoved = SDL_TRUE;
}
@ -137,10 +137,10 @@ void JoystickDeviceWasRemovedCallback( void * refcon, io_service_t service, natu
{
if( messageType == kIOMessageServiceIsTerminated && refcon )
{
recDevice *device = (recDevice *) refcon;
device->removed = 1;
s_bDeviceRemoved = SDL_TRUE;
}
recDevice *device = (recDevice *) refcon;
device->removed = 1;
s_bDeviceRemoved = SDL_TRUE;
}
}
@ -186,33 +186,33 @@ HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
HIDReportErrorNum
("Failed to open pDevice->interface via open.", result);
else
{
pDevice->portIterator = 0;
{
pDevice->portIterator = 0;
// It's okay if this fails, we have another detection method below
/* It's okay if this fails, we have another detection method below */
(*(pDevice->interface))->setRemovalCallback(pDevice->interface,
HIDRemovalCallback,
pDevice, pDevice);
/* now connect notification for new devices */
pDevice->notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(pDevice->notificationPort),
kCFRunLoopDefaultMode);
// Register for notifications when a serial port is added to the system
result = IOServiceAddInterestNotification(pDevice->notificationPort,
hidDevice,
kIOGeneralInterest,
JoystickDeviceWasRemovedCallback,
pDevice,
&pDevice->portIterator);
if (kIOReturnSuccess != result) {
HIDReportErrorNum
("Failed to register for removal callback.", result);
}
}
/* now connect notification for new devices */
pDevice->notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(pDevice->notificationPort),
kCFRunLoopDefaultMode);
/* Register for notifications when a serial port is added to the system */
result = IOServiceAddInterestNotification(pDevice->notificationPort,
hidDevice,
kIOGeneralInterest,
JoystickDeviceWasRemovedCallback,
pDevice,
&pDevice->portIterator);
if (kIOReturnSuccess != result) {
HIDReportErrorNum
("Failed to register for removal callback.", result);
}
}
}
return result;
@ -243,12 +243,12 @@ HIDCloseReleaseInterface(recDevice * pDevice)
HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
result);
pDevice->interface = NULL;
if ( pDevice->portIterator )
{
IOObjectRelease( pDevice->portIterator );
pDevice->portIterator = 0;
}
if ( pDevice->portIterator )
{
IOObjectRelease( pDevice->portIterator );
pDevice->portIterator = 0;
}
}
return result;
}
@ -272,32 +272,32 @@ HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
pElement->maxReport = pElement->max = number;
/*
TODO: maybe should handle the following stuff somehow?
TODO: maybe should handle the following stuff somehow?
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->scaledMin = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->scaledMax = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->size = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
if (refType)
pElement->relative = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
if (refType)
pElement->wrapping = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
if (refType)
pElement->nonLinear = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
if (refType)
pElement->preferredState = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
if (refType)
pElement->nullState = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->scaledMin = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->scaledMax = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
pElement->size = number;
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
if (refType)
pElement->relative = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
if (refType)
pElement->wrapping = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
if (refType)
pElement->nonLinear = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
if (refType)
pElement->preferredState = CFBooleanGetValue (refType);
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
if (refType)
pElement->nullState = CFBooleanGetValue (refType);
*/
}
@ -501,14 +501,14 @@ HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
}
}
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey));
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey));
if (refCF) {
if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[0])) {
SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[0]");
}
}
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey));
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey));
if (refCF) {
if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[8])) {
SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[8]");
@ -573,7 +573,7 @@ HIDBuildDevice(io_object_t hidDevice)
if (kIOReturnSuccess == result) {
HIDGetDeviceInfo(hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */
HIDGetCollectionElements(hidProperties, pDevice);
pDevice->instance_id = ++s_joystick_instance_id;
pDevice->instance_id = ++s_joystick_instance_id;
} else {
DisposePtr((Ptr) pDevice);
pDevice = NULL;
@ -640,57 +640,57 @@ HIDDisposeDevice(recDevice ** ppDevice)
/* Given an io_object_t from OSX adds a joystick device to our list if appropriate
*/
int
int
AddDeviceHelper( io_object_t ioHIDDeviceObject )
{
recDevice *device;
/* build a device record */
device = HIDBuildDevice(ioHIDDeviceObject);
if (!device)
return 0;
/* Filter device list to non-keyboard/mouse stuff */
if ((device->usagePage != kHIDPage_GenericDesktop) ||
((device->usage != kHIDUsage_GD_Joystick &&
device->usage != kHIDUsage_GD_GamePad &&
device->usage != kHIDUsage_GD_MultiAxisController))) {
/* release memory for the device */
HIDDisposeDevice(&device);
DisposePtr((Ptr) device);
return 0;
}
/* We have to do some storage of the io_service_t for
* SDL_HapticOpenFromJoystick */
if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
device->ffservice = ioHIDDeviceObject;
} else {
device->ffservice = 0;
}
device->send_open_event = 1;
s_bDeviceAdded = SDL_TRUE;
/* Add device to the end of the list */
if ( !gpDeviceList )
{
gpDeviceList = device;
}
else
{
recDevice *curdevice;
curdevice = gpDeviceList;
while ( curdevice->pNext )
{
curdevice = curdevice->pNext;
}
curdevice->pNext = device;
}
return 1;
/* build a device record */
device = HIDBuildDevice(ioHIDDeviceObject);
if (!device)
return 0;
/* Filter device list to non-keyboard/mouse stuff */
if ((device->usagePage != kHIDPage_GenericDesktop) ||
((device->usage != kHIDUsage_GD_Joystick &&
device->usage != kHIDUsage_GD_GamePad &&
device->usage != kHIDUsage_GD_MultiAxisController))) {
/* release memory for the device */
HIDDisposeDevice(&device);
DisposePtr((Ptr) device);
return 0;
}
/* We have to do some storage of the io_service_t for
* SDL_HapticOpenFromJoystick */
if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
device->ffservice = ioHIDDeviceObject;
} else {
device->ffservice = 0;
}
device->send_open_event = 1;
s_bDeviceAdded = SDL_TRUE;
/* Add device to the end of the list */
if ( !gpDeviceList )
{
gpDeviceList = device;
}
else
{
recDevice *curdevice;
curdevice = gpDeviceList;
while ( curdevice->pNext )
{
curdevice = curdevice->pNext;
}
curdevice->pNext = device;
}
return 1;
}
@ -700,16 +700,16 @@ AddDeviceHelper( io_object_t ioHIDDeviceObject )
void JoystickDeviceWasAddedCallback( void *refcon, io_iterator_t iterator )
{
io_object_t ioHIDDeviceObject = 0;
while ( ( ioHIDDeviceObject = IOIteratorNext(iterator) ) )
{
if ( ioHIDDeviceObject )
{
AddDeviceHelper( ioHIDDeviceObject );
}
}
while ( ( ioHIDDeviceObject = IOIteratorNext(iterator) ) )
{
if ( ioHIDDeviceObject )
{
AddDeviceHelper( ioHIDDeviceObject );
}
}
}
/* Function to scan the system for joysticks.
* Joystick 0 should be the system default joystick.
@ -724,7 +724,7 @@ SDL_SYS_JoystickInit(void)
io_iterator_t hidObjectIterator = 0;
CFMutableDictionaryRef hidMatchDictionary = NULL;
io_object_t ioHIDDeviceObject = 0;
io_iterator_t portIterator = 0;
io_iterator_t portIterator = 0;
if (gpDeviceList) {
return SDL_SetError("Joystick: Device list already inited.");
@ -774,26 +774,26 @@ SDL_SYS_JoystickInit(void)
gpDeviceList = NULL;
while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
AddDeviceHelper( ioHIDDeviceObject );
AddDeviceHelper( ioHIDDeviceObject );
}
result = IOObjectRelease(hidObjectIterator); /* release the iterator */
/* now connect notification for new devices */
notificationPort = IONotificationPortCreate(masterPort);
hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
// Register for notifications when a serial port is added to the system
result = IOServiceAddMatchingNotification(notificationPort,
kIOFirstMatchNotification,
hidMatchDictionary,
JoystickDeviceWasAddedCallback,
NULL,
&portIterator);
while (IOIteratorNext(portIterator)) {}; // Run out the iterator or notifications won't start (you can also use it to iterate the available devices).
/* now connect notification for new devices */
notificationPort = IONotificationPortCreate(masterPort);
hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
/* Register for notifications when a serial port is added to the system */
result = IOServiceAddMatchingNotification(notificationPort,
kIOFirstMatchNotification,
hidMatchDictionary,
JoystickDeviceWasAddedCallback,
NULL,
&portIterator);
while (IOIteratorNext(portIterator)) {}; /* Run out the iterator or notifications won't start (you can also use it to iterate the available devices). */
return SDL_SYS_NumJoysticks();
}
@ -802,17 +802,17 @@ SDL_SYS_JoystickInit(void)
int
SDL_SYS_NumJoysticks()
{
recDevice *device = gpDeviceList;
recDevice *device = gpDeviceList;
int nJoySticks = 0;
while ( device )
{
if ( !device->removed )
nJoySticks++;
device = device->pNext;
}
return nJoySticks;
while ( device )
{
if ( !device->removed )
nJoySticks++;
device = device->pNext;
}
return nJoySticks;
}
/* Function to cause any queued joystick insertions to be processed
@ -820,81 +820,81 @@ SDL_SYS_NumJoysticks()
void
SDL_SYS_JoystickDetect()
{
if ( s_bDeviceAdded || s_bDeviceRemoved )
{
recDevice *device = gpDeviceList;
s_bDeviceAdded = SDL_FALSE;
s_bDeviceRemoved = SDL_FALSE;
int device_index = 0;
// send notifications
while ( device )
{
if ( device->send_open_event )
{
device->send_open_event = 0;
if ( s_bDeviceAdded || s_bDeviceRemoved )
{
recDevice *device = gpDeviceList;
s_bDeviceAdded = SDL_FALSE;
s_bDeviceRemoved = SDL_FALSE;
int device_index = 0;
/* send notifications */
while ( device )
{
if ( device->send_open_event )
{
device->send_open_event = 0;
#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 */
}
if ( device->removed )
{
recDevice *removeDevice = device;
if ( gpDeviceList == removeDevice )
{
device = device->pNext;
gpDeviceList = device;
}
else
{
device = gpDeviceList;
while ( device->pNext != removeDevice )
{
device = device->pNext;
}
device->pNext = removeDevice->pNext;
}
#if !SDL_EVENTS_DISABLED
SDL_Event event;
event.type = SDL_JOYDEVICEREMOVED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = removeDevice->instance_id;
if ((SDL_EventOK == NULL)
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
SDL_PushEvent(&event);
}
}
SDL_Event event;
event.type = SDL_JOYDEVICEADDED;
DisposePtr((Ptr) removeDevice);
#endif /* !SDL_EVENTS_DISABLED */
}
else
{
device = device->pNext;
device_index++;
}
}
}
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 */
}
if ( device->removed )
{
recDevice *removeDevice = device;
if ( gpDeviceList == removeDevice )
{
device = device->pNext;
gpDeviceList = device;
}
else
{
device = gpDeviceList;
while ( device->pNext != removeDevice )
{
device = device->pNext;
}
device->pNext = removeDevice->pNext;
}
#if !SDL_EVENTS_DISABLED
SDL_Event event;
event.type = SDL_JOYDEVICEREMOVED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = removeDevice->instance_id;
if ((SDL_EventOK == NULL)
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
SDL_PushEvent(&event);
}
}
DisposePtr((Ptr) removeDevice);
#endif /* !SDL_EVENTS_DISABLED */
}
else
{
device = device->pNext;
device_index++;
}
}
}
}
SDL_bool
SDL_SYS_JoystickNeedsPolling()
{
return s_bDeviceAdded || s_bDeviceRemoved;
return s_bDeviceAdded || s_bDeviceRemoved;
}
/* Function to get the device-dependent name of a joystick */
@ -906,7 +906,7 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
for (; device_index > 0; device_index--)
device = device->pNext;
return device->product;
return device->product;
}
/* Function to return the instance id of the joystick at device_index
@ -916,11 +916,11 @@ SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
{
recDevice *device = gpDeviceList;
int index;
for (index = device_index; index > 0; index--)
device = device->pNext;
return device->instance_id;
return device->instance_id;
}
/* Function to open a joystick for use.
@ -937,14 +937,14 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
for (index = device_index; index > 0; index--)
device = device->pNext;
joystick->instance_id = device->instance_id;
joystick->instance_id = device->instance_id;
joystick->hwdata = device;
joystick->name = device->product;
joystick->name = device->product;
joystick->naxes = device->axes;
joystick->nhats = device->hats;
joystick->nballs = 0;
joystick->nbuttons = device->buttons;
joystick->naxes = device->axes;
joystick->nhats = device->hats;
joystick->nballs = 0;
joystick->nbuttons = device->buttons;
return 0;
}
@ -954,17 +954,17 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
SDL_bool
SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
{
recDevice *device = gpDeviceList;
while ( device )
{
if ( joystick->instance_id == device->instance_id )
return SDL_TRUE;
recDevice *device = gpDeviceList;
while ( device )
{
if ( joystick->instance_id == device->instance_id )
return SDL_TRUE;
device = device->pNext;
}
return SDL_FALSE;
}
return SDL_FALSE;
}
/* Function to update the state of a joystick - called as a device poll.
@ -975,49 +975,49 @@ SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
recDevice *device = joystick->hwdata;
recDevice *device = joystick->hwdata;
recElement *element;
SInt32 value, range;
int i;
if ( !device )
return;
if ( !device )
return;
if (device->removed) { /* device was unplugged; ignore it. */
recDevice *devicelist = gpDeviceList;
joystick->closed = 1;
joystick->uncentered = 1;
if ( devicelist == device )
{
gpDeviceList = device->pNext;
}
else
{
while ( devicelist->pNext != device )
{
devicelist = devicelist->pNext;
}
devicelist->pNext = device->pNext;
}
DisposePtr((Ptr) device);
joystick->hwdata = NULL;
recDevice *devicelist = gpDeviceList;
joystick->closed = 1;
joystick->uncentered = 1;
if ( devicelist == device )
{
gpDeviceList = device->pNext;
}
else
{
while ( devicelist->pNext != device )
{
devicelist = devicelist->pNext;
}
devicelist->pNext = device->pNext;
}
DisposePtr((Ptr) device);
joystick->hwdata = NULL;
#if !SDL_EVENTS_DISABLED
SDL_Event event;
event.type = SDL_JOYDEVICEREMOVED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = joystick->instance_id;
if ((SDL_EventOK == NULL)
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
SDL_PushEvent(&event);
}
}
SDL_Event event;
event.type = SDL_JOYDEVICEREMOVED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = joystick->instance_id;
if ((SDL_EventOK == NULL)
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
SDL_PushEvent(&event);
}
}
#endif /* !SDL_EVENTS_DISABLED */
return;
}
@ -1099,8 +1099,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
/* Function to close a joystick after use */
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
joystick->closed = 1;
{
joystick->closed = 1;
}
/* Function to perform any system-specific joystick related cleanup */
@ -1109,12 +1109,12 @@ SDL_SYS_JoystickQuit(void)
{
while (NULL != gpDeviceList)
gpDeviceList = HIDDisposeDevice(&gpDeviceList);
if ( notificationPort )
{
IONotificationPortDestroy( notificationPort );
notificationPort = 0;
}
if ( notificationPort )
{
IONotificationPortDestroy( notificationPort );
notificationPort = 0;
}
}
@ -1122,16 +1122,16 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
recDevice *device = gpDeviceList;
int index;
for (index = device_index; index > 0; index--)
device = device->pNext;
return device->guid;
return device->guid;
}
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
{
return joystick->hwdata->guid;
return joystick->hwdata->guid;
}
#endif /* SDL_JOYSTICK_IOKIT */

View file

@ -59,9 +59,9 @@ struct joystick_hwdata
{
io_service_t ffservice; /* Interface for force feedback, 0 = no ff */
IOHIDDeviceInterface **interface; /* interface to device, NULL = no interface */
IONotificationPortRef notificationPort; /* port to be notified on joystick removal */
io_iterator_t portIterator; /* iterator for removal callback */
IONotificationPortRef notificationPort; /* port to be notified on joystick removal */
io_iterator_t portIterator; /* iterator for removal callback */
char product[256]; /* name of product */
long usage; /* usage page from IOUSBHID Parser.h which defines general usage */
long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
@ -77,10 +77,10 @@ struct joystick_hwdata
int removed;
int uncentered;
int instance_id;
SDL_JoystickGUID guid;
Uint8 send_open_event; /* 1 if we need to send an Added event for this device */
int instance_id;
SDL_JoystickGUID guid;
Uint8 send_open_event; /* 1 if we need to send an Added event for this device */
struct joystick_hwdata *pNext; /* next device */
};

View file

@ -110,7 +110,7 @@ SDL_SYS_JoystickQuit(void)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -121,7 +121,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

View file

@ -28,114 +28,114 @@ static SDLUIAccelerationDelegate *sharedDelegate=nil;
@implementation SDLUIAccelerationDelegate
/*
Returns a shared instance of the SDLUIAccelerationDelegate, creating the shared delegate if it doesn't exist yet.
Returns a shared instance of the SDLUIAccelerationDelegate, creating the shared delegate if it doesn't exist yet.
*/
+(SDLUIAccelerationDelegate *)sharedDelegate {
if (sharedDelegate == nil) {
sharedDelegate = [[SDLUIAccelerationDelegate alloc] init];
}
return sharedDelegate;
if (sharedDelegate == nil) {
sharedDelegate = [[SDLUIAccelerationDelegate alloc] init];
}
return sharedDelegate;
}
/*
UIAccelerometerDelegate delegate method. Invoked by the UIAccelerometer instance when it has new data for us.
We just take the data and mark that we have new data available so that the joystick system will pump it to the
events system when SDL_SYS_JoystickUpdate is called.
*/
UIAccelerometerDelegate delegate method. Invoked by the UIAccelerometer instance when it has new data for us.
We just take the data and mark that we have new data available so that the joystick system will pump it to the
events system when SDL_SYS_JoystickUpdate is called.
*/
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
hasNewData = YES;
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
hasNewData = YES;
}
/*
getLastOrientation -- put last obtained accelerometer data into Sint16 array
Called from the joystick system when it needs the accelerometer data.
Function grabs the last data sent to the accelerometer and converts it
from floating point to Sint16, which is what the joystick system expects.
To do the conversion, the data is first clamped onto the interval
[-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
by MAX_SINT16 so that it is mapped to the full range of an Sint16.
You can customize the clamped range of this function by modifying the
SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
Once converted to Sint16, the accelerometer data no longer has coherent units.
You can convert the data back to units of g-force by multiplying it
in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
/*
getLastOrientation -- put last obtained accelerometer data into Sint16 array
Called from the joystick system when it needs the accelerometer data.
Function grabs the last data sent to the accelerometer and converts it
from floating point to Sint16, which is what the joystick system expects.
To do the conversion, the data is first clamped onto the interval
[-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
by MAX_SINT16 so that it is mapped to the full range of an Sint16.
You can customize the clamped range of this function by modifying the
SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
Once converted to Sint16, the accelerometer data no longer has coherent units.
You can convert the data back to units of g-force by multiplying it
in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
*/
-(void)getLastOrientation:(Sint16 *)data {
#define MAX_SINT16 0x7FFF
#define MAX_SINT16 0x7FFF
/* clamp the data */
if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE;
else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE;
if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE;
else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE;
if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE;
else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE;
/* pass in data mapped to range of SInt16 */
data[0] = (x / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[1] = (y / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[2] = (z / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
/* clamp the data */
if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE;
else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE;
if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE;
else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE;
if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE;
else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE;
/* pass in data mapped to range of SInt16 */
data[0] = (x / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[1] = (y / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[2] = (z / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
}
/*
Initialize SDLUIAccelerationDelegate. Since we don't have any data yet,
just set our last received data to zero, and indicate we don't have any;
Initialize SDLUIAccelerationDelegate. Since we don't have any data yet,
just set our last received data to zero, and indicate we don't have any;
*/
-(id)init {
self = [super init];
x = y = z = 0.0;
hasNewData = NO;
return self;
self = [super init];
x = y = z = 0.0;
hasNewData = NO;
return self;
}
-(void)dealloc {
sharedDelegate = nil;
[self shutdown];
[super dealloc];
sharedDelegate = nil;
[self shutdown];
[super dealloc];
}
/*
Lets our delegate start receiving accelerometer updates.
Lets our delegate start receiving accelerometer updates.
*/
-(void)startup {
[UIAccelerometer sharedAccelerometer].delegate = self;
isRunning = YES;
[UIAccelerometer sharedAccelerometer].delegate = self;
isRunning = YES;
}
/*
Stops our delegate from receiving accelerometer updates.
Stops our delegate from receiving accelerometer updates.
*/
-(void)shutdown {
if ([UIAccelerometer sharedAccelerometer].delegate == self) {
[UIAccelerometer sharedAccelerometer].delegate = nil;
}
isRunning = NO;
if ([UIAccelerometer sharedAccelerometer].delegate == self) {
[UIAccelerometer sharedAccelerometer].delegate = nil;
}
isRunning = NO;
}
/*
Our we currently receiving accelerometer updates?
Our we currently receiving accelerometer updates?
*/
-(BOOL)isRunning {
return isRunning;
return isRunning;
}
/*
Do we have any data that hasn't been pumped into SDL's event system?
Do we have any data that hasn't been pumped into SDL's event system?
*/
-(BOOL)hasNewData {
return hasNewData;
return hasNewData;
}
/*
When the joystick system grabs the new data, it sets this to NO.
When the joystick system grabs the new data, it sets this to NO.
*/
-(void)setHasNewData:(BOOL)value {
hasNewData = value;
hasNewData = value;
}
@end

View file

@ -97,20 +97,20 @@ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
Sint16 orientation[3];
if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) {
[[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation];
[[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO];
SDL_PrivateJoystickAxis(joystick, 0, orientation[0]);
SDL_PrivateJoystickAxis(joystick, 1, orientation[1]);
SDL_PrivateJoystickAxis(joystick, 2, orientation[2]);
}
Sint16 orientation[3];
if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) {
[[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation];
[[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO];
SDL_PrivateJoystickAxis(joystick, 0, orientation[0]);
SDL_PrivateJoystickAxis(joystick, 1, orientation[1]);
SDL_PrivateJoystickAxis(joystick, 2, orientation[2]);
}
return;
}
@ -118,10 +118,10 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
[[SDLUIAccelerationDelegate sharedDelegate] shutdown];
}
SDL_SetError("No joystick open with that index");
if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
[[SDLUIAccelerationDelegate sharedDelegate] shutdown];
}
SDL_SetError("No joystick open with that index");
}
/* Function to perform any system-specific joystick related cleanup */
@ -133,7 +133,7 @@ SDL_SYS_JoystickQuit(void)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -143,7 +143,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

View file

@ -510,7 +510,7 @@ void SDL_SYS_JoystickDetect()
SDL_PushEvent(&event);
}
}
#endif // !SDL_EVENTS_DISABLED
#endif /* !SDL_EVENTS_DISABLED */
}
} else if (SDL_strcmp(action, "remove") == 0) {
const int inst = MaybeRemoveDevice(devnode);
@ -527,7 +527,7 @@ void SDL_SYS_JoystickDetect()
SDL_PushEvent(&event);
}
}
#endif // !SDL_EVENTS_DISABLED
#endif /* !SDL_EVENTS_DISABLED */
}
}
UDEV_udev_device_unref(dev);
@ -760,7 +760,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
/* Get the number of buttons and axes on the joystick */
ConfigJoystick(joystick, fd);
// mark joystick as fresh and ready
/* mark joystick as fresh and ready */
joystick->hwdata->fresh = 1;
return (0);
@ -840,7 +840,7 @@ PollAllValues(SDL_Joystick * joystick)
struct input_absinfo absinfo;
int a, b = 0;
// Poll all axis
/* Poll all axis */
for (a = ABS_X; b < ABS_MAX; a++) {
switch (a) {
case ABS_HAT0X:
@ -851,7 +851,7 @@ PollAllValues(SDL_Joystick * joystick)
case ABS_HAT2Y:
case ABS_HAT3X:
case ABS_HAT3Y:
// ingore hats
/* ingore hats */
break;
default:
if (joystick->hwdata->abs_correct[b].used) {

View file

@ -23,7 +23,7 @@
#include <pspctrl.h>
#include <pspkernel.h>
#include <stdio.h> /* For the definition of NULL */
#include <stdio.h> /* For the definition of NULL */
#include <stdlib.h>
#include "../SDL_sysjoystick.h"
@ -41,10 +41,10 @@ static SDL_sem *pad_sem = NULL;
static SDL_Thread *thread = NULL;
static int running = 0;
static const enum PspCtrlButtons button_map[] = {
PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
typedef struct
@ -53,30 +53,30 @@ typedef struct
int y;
} point;
// 4 points define the bezier-curve.
/* 4 points define the bezier-curve. */
static point a = { 0, 0 };
static point b = { 50, 0 };
static point c = { 78, 32767 };
static point d = { 128, 32767 };
// simple linear interpolation between two points
/* simple linear interpolation between two points */
static __inline__ void lerp (point *dest, point *a, point *b, float t)
{
dest->x = a->x + (b->x - a->x)*t;
dest->y = a->y + (b->y - a->y)*t;
dest->x = a->x + (b->x - a->x)*t;
dest->y = a->y + (b->y - a->y)*t;
}
// evaluate a point on a bezier-curve. t goes from 0 to 1.0
/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
static int calc_bezier_y(float t)
{
point ab, bc, cd, abbc, bccd, dest;
lerp (&ab, &a, &b, t); // point between a and b
lerp (&bc, &b, &c, t); // point between b and c
lerp (&cd, &c, &d, t); // point between c and d
lerp (&abbc, &ab, &bc, t); // point between ab and bc
lerp (&bccd, &bc, &cd, t); // point between bc and cd
lerp (&dest, &abbc, &bccd, t); // point on the bezier-curve
return dest.y;
point ab, bc, cd, abbc, bccd, dest;
lerp (&ab, &a, &b, t); /* point between a and b */
lerp (&bc, &b, &c, t); /* point between b and c */
lerp (&cd, &c, &d, t); /* point between c and d */
lerp (&abbc, &ab, &bc, t); /* point between ab and bc */
lerp (&bccd, &bc, &cd, t); /* point between bc and cd */
lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */
return dest.y;
}
/*
@ -84,14 +84,14 @@ static int calc_bezier_y(float t)
*/
int JoystickUpdate(void *data)
{
while (running) {
SDL_SemWait(pad_sem);
sceCtrlPeekBufferPositive(&pad, 1);
SDL_SemPost(pad_sem);
/* Delay 1/60th of a second */
sceKernelDelayThread(1000000 / 60);
}
return 0;
while (running) {
SDL_SemWait(pad_sem);
sceCtrlPeekBufferPositive(&pad, 1);
SDL_SemPost(pad_sem);
/* Delay 1/60th of a second */
sceKernelDelayThread(1000000 / 60);
}
return 0;
}
@ -103,33 +103,33 @@ int JoystickUpdate(void *data)
*/
int SDL_SYS_JoystickInit(void)
{
int i;
int i;
// SDL_numjoysticks = 1;
/* SDL_numjoysticks = 1; */
/* Setup input */
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
/* Setup input */
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
/* Start thread to read data */
if((pad_sem = SDL_CreateSemaphore(1)) == NULL) {
return SDL_SetError("Can't create input semaphore");
}
running = 1;
if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) {
return SDL_SetError("Can't create input thread");
}
/* Start thread to read data */
if((pad_sem = SDL_CreateSemaphore(1)) == NULL) {
return SDL_SetError("Can't create input semaphore");
}
running = 1;
if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) {
return SDL_SetError("Can't create input thread");
}
/* Create an accurate map from analog inputs (0 to 255)
to SDL joystick positions (-32768 to 32767) */
for (i = 0; i < 128; i++)
{
float t = (float)i/127.0f;
analog_map[i+128] = calc_bezier_y(t);
analog_map[127-i] = -1 * analog_map[i+128];
}
/* Create an accurate map from analog inputs (0 to 255)
to SDL joystick positions (-32768 to 32767) */
for (i = 0; i < 128; i++)
{
float t = (float)i/127.0f;
analog_map[i+128] = calc_bezier_y(t);
analog_map[127-i] = -1 * analog_map[i+128];
}
return 1;
return 1;
}
int SDL_SYS_NumJoysticks()
@ -161,11 +161,11 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index)
{
if (index == 0)
return "PSP controller";
if (index == 0)
return "PSP controller";
SDL_SetError("No joystick available with that index");
return(NULL);
SDL_SetError("No joystick available with that index");
return(NULL);
}
/* Function to open a joystick for use.
@ -175,11 +175,11 @@ const char *SDL_SYS_JoystickName(int index)
*/
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
{
joystick->nbuttons = 14;
joystick->naxes = 2;
joystick->nhats = 0;
joystick->nbuttons = 14;
joystick->naxes = 2;
joystick->nhats = 0;
return 0;
return 0;
}
/* Function to determine is this joystick is attached to the system right now */
@ -195,65 +195,65 @@ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
{
int i;
enum PspCtrlButtons buttons;
enum PspCtrlButtons changed;
unsigned char x, y;
static enum PspCtrlButtons old_buttons = 0;
static unsigned char old_x = 0, old_y = 0;
int i;
enum PspCtrlButtons buttons;
enum PspCtrlButtons changed;
unsigned char x, y;
static enum PspCtrlButtons old_buttons = 0;
static unsigned char old_x = 0, old_y = 0;
SDL_SemWait(pad_sem);
buttons = pad.Buttons;
x = pad.Lx;
y = pad.Ly;
SDL_SemPost(pad_sem);
SDL_SemWait(pad_sem);
buttons = pad.Buttons;
x = pad.Lx;
y = pad.Ly;
SDL_SemPost(pad_sem);
/* Axes */
if(old_x != x) {
SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]);
old_x = x;
}
if(old_y != y) {
SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]);
old_y = y;
}
/* Axes */
if(old_x != x) {
SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]);
old_x = x;
}
if(old_y != y) {
SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]);
old_y = y;
}
/* Buttons */
changed = old_buttons ^ buttons;
old_buttons = buttons;
if(changed) {
for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
if(changed & button_map[i]) {
SDL_PrivateJoystickButton(
joystick, i,
(buttons & button_map[i]) ?
SDL_PRESSED : SDL_RELEASED);
}
}
}
/* Buttons */
changed = old_buttons ^ buttons;
old_buttons = buttons;
if(changed) {
for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
if(changed & button_map[i]) {
SDL_PrivateJoystickButton(
joystick, i,
(buttons & button_map[i]) ?
SDL_PRESSED : SDL_RELEASED);
}
}
}
sceKernelDelayThread(0);
sceKernelDelayThread(0);
}
/* Function to close a joystick after use */
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
{
/* Do nothing. */
/* Do nothing. */
}
/* Function to perform any system-specific joystick related cleanup */
void SDL_SYS_JoystickQuit(void)
{
/* Cleanup Threads and Semaphore. */
running = 0;
SDL_WaitThread(thread, NULL);
SDL_DestroySemaphore(pad_sem);
/* Cleanup Threads and Semaphore. */
running = 0;
SDL_WaitThread(thread, NULL);
SDL_DestroySemaphore(pad_sem);
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -263,7 +263,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );

File diff suppressed because it is too large Load diff

View file

@ -23,10 +23,10 @@
#ifndef SDL_JOYSTICK_DINPUT_H
/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
* A. Formiga's WINMM driver.
* 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.
* 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
@ -57,7 +57,7 @@ typedef struct
DWORD dwPaddingReserved;
} XINPUT_GAMEPAD_EX;
typedef struct
typedef struct
{
DWORD dwPacketNumber;
XINPUT_GAMEPAD_EX Gamepad;
@ -65,23 +65,23 @@ typedef struct
/* 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
);
(
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
);
(
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
);
(
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);
@ -89,11 +89,11 @@ 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)
extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
#define XINPUTGETSTATE SDL_XInputGetState
#define XINPUTSETSTATE SDL_XInputSetState
#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
#define XINPUTGETSTATE SDL_XInputGetState
#define XINPUTSETSTATE SDL_XInputSetState
#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
#define INVALID_XINPUT_USERID 255
#define SDL_XINPUT_MAX_DEVICES 4
@ -102,7 +102,7 @@ extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF)
#endif
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
/* local types */
@ -127,18 +127,18 @@ struct joystick_hwdata
LPDIRECTINPUTDEVICE8 InputDevice;
DIDEVCAPS Capabilities;
int buffered;
SDL_JoystickGUID guid;
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];
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 */

View file

@ -33,14 +33,14 @@
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#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 */
#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<<n)
#define JOY_BUTTON_FLAG(n) (1<<n)
/* array to hold joystick ID values */
@ -407,7 +407,7 @@ SDL_SYS_JoystickQuit(void)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );
@ -417,7 +417,7 @@ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
/* 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 ) ) );