Moved the platform-specific variables in the Joystick structure into their own platform-specific substructure.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1025 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2012-01-29 05:25:10 +00:00
parent 71de22bf85
commit ce296d938e
3 changed files with 159 additions and 152 deletions

View File

@ -788,50 +788,47 @@ struct tagSFG_StrokeFont
#if TARGET_HOST_MACINTOSH #if TARGET_HOST_MACINTOSH
# define _JS_MAX_AXES 9 # define _JS_MAX_AXES 9
#endif typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
struct tagSFG_PlatformJoystick
#if TARGET_HOST_MAC_OSX
# define _JS_MAX_AXES 16
#endif
#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)
# define _JS_MAX_AXES 8
#endif
#if TARGET_HOST_POSIX_X11
# define _JS_MAX_AXES 16
#endif
/*
* Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.
* See "js.h" lines 80-178.
*/
typedef struct tagSFG_Joystick SFG_Joystick;
struct tagSFG_Joystick
{ {
#if TARGET_HOST_MACINTOSH
#define ISP_NUM_AXIS 9 #define ISP_NUM_AXIS 9
#define ISP_NUM_NEEDS 41 #define ISP_NUM_NEEDS 41
ISpElementReference isp_elem [ ISP_NUM_NEEDS ]; ISpElementReference isp_elem [ ISP_NUM_NEEDS ];
ISpNeed isp_needs [ ISP_NUM_NEEDS ]; ISpNeed isp_needs [ ISP_NUM_NEEDS ];
};
#endif #endif
#if TARGET_HOST_MAC_OSX #if TARGET_HOST_MAC_OSX
# define _JS_MAX_AXES 16
typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
struct tagSFG_PlatformJoystick
{
IOHIDDeviceInterface ** hidDev; IOHIDDeviceInterface ** hidDev;
IOHIDElementCookie buttonCookies[41]; IOHIDElementCookie buttonCookies[41];
IOHIDElementCookie axisCookies[_JS_MAX_AXES]; IOHIDElementCookie axisCookies[_JS_MAX_AXES];
long minReport[_JS_MAX_AXES], /* The next two variables are not used anywhere */
maxReport[_JS_MAX_AXES]; /* long minReport[_JS_MAX_AXES],
* maxReport[_JS_MAX_AXES];
*/
};
#endif #endif
#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)
# define _JS_MAX_AXES 8
typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
struct tagSFG_PlatformJoystick
{
JOYCAPS jsCaps; JOYCAPS jsCaps;
JOYINFOEX js; JOYINFOEX js;
UINT js_id; UINT js_id;
};
#endif #endif
#if TARGET_HOST_POSIX_X11 #if TARGET_HOST_POSIX_X11
# define _JS_MAX_AXES 16
typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
struct tagSFG_PlatformJoystick
{
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
struct os_specific_s *os; struct os_specific_s *os;
# endif # endif
@ -846,8 +843,18 @@ struct tagSFG_Joystick
char fname [ 128 ]; char fname [ 128 ];
int fd; int fd;
};
#endif #endif
/*
* Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.
* See "js.h" lines 80-178.
*/
typedef struct tagSFG_Joystick SFG_Joystick;
struct tagSFG_Joystick
{
SFG_PlatformJoystick pJoystick;
int id; int id;
GLboolean error; GLboolean error;
char name [ 128 ]; char name [ 128 ];

View File

@ -594,7 +594,7 @@ static void fghJoystickAddAxisElement ( SFG_Joystick *joy, CFDictionaryRef axis
CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementCookieKey) ), CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementCookieKey) ),
kCFNumberLongType, &cookie); kCFNumberLongType, &cookie);
axisCookies[index] = (IOHIDElementCookie) cookie; joy->pJoystick.axisCookies[index] = (IOHIDElementCookie) cookie;
CFNumberGetValue ((CFNumberRef) CFNumberGetValue ((CFNumberRef)
CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementMinKey) ), CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementMinKey) ),
@ -618,7 +618,7 @@ static void fghJoystickAddButtonElement ( SFG_Joystick *joy, CFDictionaryRef but
CFDictionaryGetValue ( button, CFSTR(kIOHIDElementCookieKey) ), CFDictionaryGetValue ( button, CFSTR(kIOHIDElementCookieKey) ),
kCFNumberLongType, &cookie); kCFNumberLongType, &cookie);
joy->buttonCookies[num_buttons++] = (IOHIDElementCookie) cookie; joy->pJoystick.buttonCookies[num_buttons++] = (IOHIDElementCookie) cookie;
/* anything else for buttons? */ /* anything else for buttons? */
} }
@ -645,7 +645,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
for ( i = 0; i < joy->num_buttons; i++ ) for ( i = 0; i < joy->num_buttons; i++ )
{ {
UInt32 state; UInt32 state;
int err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state); int err = ISpElement_GetSimpleState ( joy->pJoystick.isp_elem [ i + ISP_NUM_AXIS ], &state);
ISP_CHECK_ERR(err) ISP_CHECK_ERR(err)
*buttons |= state << i; *buttons |= state << i;
@ -657,7 +657,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
for ( i = 0; i < joy->num_axes; i++ ) for ( i = 0; i < joy->num_axes; i++ )
{ {
UInt32 state; UInt32 state;
int err = ISpElement_GetSimpleState ( isp_elem [ i ], &state ); int err = ISpElement_GetSimpleState ( joy->pJoystick.isp_elem [ i ], &state );
ISP_CHECK_ERR(err) ISP_CHECK_ERR(err)
axes [i] = (float) state; axes [i] = (float) state;
@ -682,7 +682,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
joy->error = GL_TRUE; joy->error = GL_TRUE;
/* initialize the needs structure */ /* initialize the needs structure */
ISpNeed temp_isp_needs[ isp_num_needs ] = ISpNeed temp_isp_needs[ ISP_NUM_NEEDS ] =
{ {
{ "\pX-Axis", 128, 0, 0, kISpElementKind_Axis, kISpElementLabel_None, 0, 0, 0, 0 }, { "\pX-Axis", 128, 0, 0, kISpElementKind_Axis, kISpElementLabel_None, 0, 0, 0, 0 },
{ "\pY-Axis", 128, 0, 0, kISpElementKind_Axis, kISpElementLabel_None, 0, 0, 0, 0 }, { "\pY-Axis", 128, 0, 0, kISpElementKind_Axis, kISpElementLabel_None, 0, 0, 0, 0 },
@ -728,7 +728,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
{ "\pButton 31", 128, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_Select, 0, 0, 0, 0 }, { "\pButton 31", 128, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_Select, 0, 0, 0, 0 },
}; };
memcpy( joy->isp_needs, temp_isp_needs, sizeof (temp_isp_needs ) ); memcpy( joy->pJoystick.isp_needs, temp_isp_needs, sizeof (temp_isp_needs ) );
/* next two calls allow keyboard and mouse to emulate other input /* next two calls allow keyboard and mouse to emulate other input
@ -743,17 +743,17 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
ISP_CHECK_ERR(err) ISP_CHECK_ERR(err)
*/ */
err = ISpElement_NewVirtualFromNeeds( joy->isp_num_needs, err = ISpElement_NewVirtualFromNeeds( ISP_NUM_NEEDS,
joy->isp_needs, joy->isp_elem, joy->pJoystick.isp_needs, joy->pJoystick.isp_elem,
0 ); 0 );
ISP_CHECK_ERR( err ) ISP_CHECK_ERR( err )
err = ISpInit( joy->isp_num_needs, joy->isp_needs, joy->isp_elem, err = ISpInit( ISP_NUM_NEEDS, joy->pJoystick.isp_needs, joy->pJoystick.isp_elem,
'freeglut', nil, 0, 128, 0 ); 'freeglut', nil, 0, 128, 0 );
ISP_CHECK_ERR( err ) ISP_CHECK_ERR( err )
joy->num_buttons = joy->isp_num_needs - joy->isp_num_axis; joy->num_buttons = ISP_NUM_NEEDS - ISP_NUM_AXIS;
joy->num_axes = joy->isp_num_axis; joy->num_axes = ISP_NUM_AXIS;
for( i = 0; i < joy->num_axes; i++ ) for( i = 0; i < joy->num_axes; i++ )
{ {
@ -774,7 +774,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ) void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
{ {
fgJoystick[ ident ]->id = ident; fgJoystick[ ident ]->id = ident;
snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */ snprintf( fgJoystick[ ident ]->pJoystick.fname, sizeof(fgJoystick[ ident ]->pJoystick.fname), "/dev/js%d", ident ); /* FIXME */
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
} }
@ -799,7 +799,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
for ( i = 0; i < joy->num_buttons; i++ ) for ( i = 0; i < joy->num_buttons; i++ )
{ {
IOHIDEventStruct hidEvent; IOHIDEventStruct hidEvent;
(*(joy->hidDev))->getElementValue ( joy->hidDev, buttonCookies[i], &hidEvent ); (*(joy->pJoystick.hidDev))->getElementValue ( joy->pJoystick.hidDev, joy->pJoystick.buttonCookies[i], &hidEvent );
if ( hidEvent.value ) if ( hidEvent.value )
*buttons |= 1 << i; *buttons |= 1 << i;
} }
@ -810,7 +810,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
for ( i = 0; i < joy->num_axes; i++ ) for ( i = 0; i < joy->num_axes; i++ )
{ {
IOHIDEventStruct hidEvent; IOHIDEventStruct hidEvent;
(*(joy->hidDev))->getElementValue ( joy->hidDev, axisCookies[i], &hidEvent ); (*(joy->pJoystick.hidDev))->getElementValue ( joy->pJoystick.hidDev, joy->pJoystick.axisCookies[i], &hidEvent );
axes[i] = hidEvent.value; axes[i] = hidEvent.value;
} }
} }
@ -849,18 +849,18 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
pluginResult = ( *plugin )->QueryInterface( pluginResult = ( *plugin )->QueryInterface(
plugin, plugin,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
&( LPVOID )joy->hidDev &( LPVOID )joy->pJoystick.hidDev
); );
if( pluginResult != S_OK ) if( pluginResult != S_OK )
fgWarning ( "QI-ing IO plugin to HID Device interface failed" ); fgWarning ( "QI-ing IO plugin to HID Device interface failed" );
( *plugin )->Release( plugin ); /* don't leak a ref */ ( *plugin )->Release( plugin ); /* don't leak a ref */
if( joy->hidDev == NULL ) if( joy->pJoystick.hidDev == NULL )
return; return;
/* store the interface in this instance */ /* store the interface in this instance */
rv = ( *( joy->hidDev ) )->open( joy->hidDev, 0 ); rv = ( *( joy->pJoystick.hidDev ) )->open( joy->pJoystick.hidDev, 0 );
if( rv != kIOReturnSuccess ) if( rv != kIOReturnSuccess )
{ {
fgWarning( "error opening device interface"); fgWarning( "error opening device interface");
@ -925,8 +925,8 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
void fgPlatformJoystickClose ( int ident ) void fgPlatformJoystickClose ( int ident )
{ {
( *( fgJoystick[ ident ]->hidDev ) )-> ( *( fgJoystick[ ident ]->pJoystick.hidDev ) )->
close( fgJoystick[ ident ]->hidDev ); close( fgJoystick[ ident ]->pJoystick.hidDev );
} }
#endif #endif
@ -940,34 +940,34 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
int len; int len;
if ( joy->os->is_analog ) if ( joy->pJoystick.os->is_analog )
{ {
int status = read ( joy->os->fd, &joy->os->ajs, sizeof(joy->os->ajs) ); int status = read ( joy->pJoystick.os->fd, &joy->pJoystick.os->ajs, sizeof(joy->pJoystick.os->ajs) );
if ( status != sizeof(joy->os->ajs) ) { if ( status != sizeof(joy->pJoystick.os->ajs) ) {
perror ( joy->os->fname ); perror ( joy->pJoystick.os->fname );
joy->error = GL_TRUE; joy->error = GL_TRUE;
return; return;
} }
if ( buttons != NULL ) if ( buttons != NULL )
*buttons = ( joy->os->ajs.b1 ? 1 : 0 ) | ( joy->os->ajs.b2 ? 2 : 0 ); *buttons = ( joy->pJoystick.os->ajs.b1 ? 1 : 0 ) | ( joy->pJoystick.os->ajs.b2 ? 2 : 0 );
if ( axes != NULL ) if ( axes != NULL )
{ {
axes[0] = (float) joy->os->ajs.x; axes[0] = (float) joy->pJoystick.os->ajs.x;
axes[1] = (float) joy->os->ajs.y; axes[1] = (float) joy->pJoystick.os->ajs.y;
} }
return; return;
} }
# ifdef HAVE_USB_JS # ifdef HAVE_USB_JS
while ( ( len = read ( joy->os->fd, joy->os->hid_data_buf, joy->os->hid_dlen ) ) == joy->os->hid_dlen ) while ( ( len = read ( joy->pJoystick.os->fd, joy->pJoystick.os->hid_data_buf, joy->pJoystick.os->hid_dlen ) ) == joy->pJoystick.os->hid_dlen )
{ {
struct hid_item *h; struct hid_item *h;
for ( h = joy->os->hids; h; h = h->next ) for ( h = joy->pJoystick.os->hids; h; h = h->next )
{ {
int d = hid_get_data ( joy->os->hid_data_buf, h ); int d = hid_get_data ( joy->pJoystick.os->hid_data_buf, h );
int page = HID_PAGE ( h->usage ); int page = HID_PAGE ( h->usage );
int usage = HID_USAGE ( h->usage ); int usage = HID_USAGE ( h->usage );
@ -976,18 +976,18 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
{ {
int i; int i;
for ( i = 0; i < joy->num_axes; i++ ) for ( i = 0; i < joy->num_axes; i++ )
if (joy->os->axes_usage[i] == usage) if (joy->pJoystick.os->axes_usage[i] == usage)
{ {
if (usage == HUG_HAT_SWITCH) if (usage == HUG_HAT_SWITCH)
{ {
if (d < 0 || d > 8) if (d < 0 || d > 8)
d = 0; /* safety */ d = 0; /* safety */
joy->os->cache_axes[i] = (float)hatmap_x[d]; joy->pJoystick.os->cache_axes[i] = (float)hatmap_x[d];
joy->os->cache_axes[i + 1] = (float)hatmap_y[d]; joy->pJoystick.os->cache_axes[i + 1] = (float)hatmap_y[d];
} }
else else
{ {
joy->os->cache_axes[i] = (float)d; joy->pJoystick.os->cache_axes[i] = (float)d;
} }
break; break;
} }
@ -997,9 +997,9 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
if (usage > 0 && usage < _JS_MAX_BUTTONS + 1) if (usage > 0 && usage < _JS_MAX_BUTTONS + 1)
{ {
if (d) if (d)
joy->os->cache_buttons |= (1 << ( usage - 1 )); joy->pJoystick.os->cache_buttons |= (1 << ( usage - 1 ));
else else
joy->os->cache_buttons &= ~(1 << ( usage - 1 )); joy->pJoystick.os->cache_buttons &= ~(1 << ( usage - 1 ));
} }
} }
} }
@ -1010,12 +1010,12 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
if ( len < 0 ) if ( len < 0 )
# endif # endif
{ {
perror( joy->os->fname ); perror( joy->pJoystick.os->fname );
joy->error = 1; joy->error = 1;
} }
if ( buttons != NULL ) *buttons = joy->os->cache_buttons; if ( buttons != NULL ) *buttons = joy->pJoystick.os->cache_buttons;
if ( axes != NULL ) if ( axes != NULL )
memcpy ( axes, joy->os->cache_axes, sizeof(float) * joy->num_axes ); memcpy ( axes, joy->pJoystick.os->cache_axes, sizeof(float) * joy->num_axes );
# endif # endif
#endif #endif
@ -1023,7 +1023,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
while ( 1 ) while ( 1 )
{ {
status = read ( joy->fd, &joy->js, sizeof(struct js_event) ); status = read ( joy->pJoystick.fd, &joy->pJoystick.js, sizeof(struct js_event) );
if ( status != sizeof( struct js_event ) ) if ( status != sizeof( struct js_event ) )
{ {
@ -1032,35 +1032,35 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
{ {
/* Use the old values */ /* Use the old values */
if ( buttons ) if ( buttons )
*buttons = joy->tmp_buttons; *buttons = joy->pJoystick.tmp_buttons;
if ( axes ) if ( axes )
memcpy( axes, joy->tmp_axes, memcpy( axes, joy->pJoystick.tmp_axes,
sizeof( float ) * joy->num_axes ); sizeof( float ) * joy->num_axes );
return; return;
} }
# endif # endif
fgWarning ( "%s", joy->fname ); fgWarning ( "%s", joy->pJoystick.fname );
joy->error = GL_TRUE; joy->error = GL_TRUE;
return; return;
} }
switch ( joy->js.type & ~JS_EVENT_INIT ) switch ( joy->pJoystick.js.type & ~JS_EVENT_INIT )
{ {
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
if( joy->js.value == 0 ) /* clear the flag */ if( joy->pJoystick.js.value == 0 ) /* clear the flag */
joy->tmp_buttons &= ~( 1 << joy->js.number ); joy->pJoystick.tmp_buttons &= ~( 1 << joy->pJoystick.js.number );
else else
joy->tmp_buttons |= ( 1 << joy->js.number ); joy->pJoystick.tmp_buttons |= ( 1 << joy->pJoystick.js.number );
break; break;
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
if ( joy->js.number < joy->num_axes ) if ( joy->pJoystick.js.number < joy->num_axes )
{ {
joy->tmp_axes[ joy->js.number ] = ( float )joy->js.value; joy->pJoystick.tmp_axes[ joy->pJoystick.js.number ] = ( float )joy->pJoystick.js.value;
if( axes ) if( axes )
memcpy( axes, joy->tmp_axes, sizeof(float) * joy->num_axes ); memcpy( axes, joy->pJoystick.tmp_axes, sizeof(float) * joy->num_axes );
} }
break; break;
@ -1069,38 +1069,38 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
/* use the old values */ /* use the old values */
if ( buttons != NULL ) *buttons = joy->tmp_buttons; if ( buttons != NULL ) *buttons = joy->pJoystick.tmp_buttons;
if ( axes != NULL ) if ( axes != NULL )
memcpy ( axes, joy->tmp_axes, sizeof(float) * joy->num_axes ); memcpy ( axes, joy->pJoystick.tmp_axes, sizeof(float) * joy->num_axes );
return; return;
} }
if( buttons ) if( buttons )
*buttons = joy->tmp_buttons; *buttons = joy->pJoystick.tmp_buttons;
} }
#else #else
status = read( joy->fd, &joy->js, JS_RETURN ); status = read( joy->pJoystick.fd, &joy->pJoystick.js, JS_RETURN );
if ( status != JS_RETURN ) if ( status != JS_RETURN )
{ {
fgWarning( "%s", joy->fname ); fgWarning( "%s", joy->pJoystick.fname );
joy->error = GL_TRUE; joy->error = GL_TRUE;
return; return;
} }
if ( buttons ) if ( buttons )
# if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) # if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
*buttons = ( joy->js.b1 ? 1 : 0 ) | ( joy->js.b2 ? 2 : 0 ); /* XXX Should not be here -- BSD is handled earlier */ *buttons = ( joy->pJoystick.js.b1 ? 1 : 0 ) | ( joy->pJoystick.js.b2 ? 2 : 0 ); /* XXX Should not be here -- BSD is handled earlier */
# else # else
*buttons = joy->js.buttons; *buttons = joy->pJoystick.js.buttons;
# endif # endif
if ( axes ) if ( axes )
{ {
axes[ 0 ] = (float) joy->js.x; axes[ 0 ] = (float) joy->pJoystick.js.x;
axes[ 1 ] = (float) joy->js.y; axes[ 1 ] = (float) joy->pJoystick.js.y;
} }
#endif #endif
} }
@ -1123,25 +1123,25 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
for( i = 0; i < _JS_MAX_AXES; i++ ) for( i = 0; i < _JS_MAX_AXES; i++ )
joy->os->cache_axes[ i ] = 0.0f; joy->pJoystick.os->cache_axes[ i ] = 0.0f;
joy->os->cache_buttons = 0; joy->pJoystick.os->cache_buttons = 0;
joy->os->fd = open( joy->os->fname, O_RDONLY | O_NONBLOCK); joy->pJoystick.os->fd = open( joy->pJoystick.os->fname, O_RDONLY | O_NONBLOCK);
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
if( joy->os->fd < 0 && errno == EACCES ) if( joy->pJoystick.os->fd < 0 && errno == EACCES )
fgWarning ( "%s exists but is not readable by you", joy->os->fname ); fgWarning ( "%s exists but is not readable by you", joy->pJoystick.os->fname );
#endif #endif
joy->error =( joy->os->fd < 0 ); joy->error =( joy->pJoystick.os->fd < 0 );
if( joy->error ) if( joy->error )
return; return;
joy->num_axes = 0; joy->num_axes = 0;
joy->num_buttons = 0; joy->num_buttons = 0;
if( joy->os->is_analog ) if( joy->pJoystick.os->is_analog )
{ {
FILE *joyfile; FILE *joyfile;
char joyfname[ 1024 ]; char joyfname[ 1024 ];
@ -1183,15 +1183,15 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
} }
# ifdef HAVE_USB_JS # ifdef HAVE_USB_JS
if( ! fghJoystickInitializeHID( joy->os, &joy->num_axes, if( ! fghJoystickInitializeHID( joy->pJoystick.os, &joy->num_axes,
&joy->num_buttons ) ) &joy->num_buttons ) )
{ {
close( joy->os->fd ); close( joy->pJoystick.os->fd );
joy->error = GL_TRUE; joy->error = GL_TRUE;
return; return;
} }
cp = strrchr( joy->os->fname, '/' ); cp = strrchr( joy->pJoystick.os->fname, '/' );
if( cp ) if( cp )
{ {
if( fghJoystickFindUSBdev( &cp[1], joy->name, sizeof( joy->name ) ) == if( fghJoystickFindUSBdev( &cp[1], joy->name, sizeof( joy->name ) ) ==
@ -1208,7 +1208,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
* to be quite unreliable for analog-to-USB converters. Punt for * to be quite unreliable for analog-to-USB converters. Punt for
* now. * now.
*/ */
if( joy->os->axes_usage[ i ] == HUG_HAT_SWITCH ) if( joy->pJoystick.os->axes_usage[ i ] == HUG_HAT_SWITCH )
{ {
joy->max [ i ] = 1.0f; joy->max [ i ] = 1.0f;
joy->center[ i ] = 0.0f; joy->center[ i ] = 0.0f;
@ -1234,14 +1234,14 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
# ifdef JS_NEW # ifdef JS_NEW
for( i = 0; i < _JS_MAX_AXES; i++ ) for( i = 0; i < _JS_MAX_AXES; i++ )
joy->tmp_axes[ i ] = 0.0f; joy->pJoystick.tmp_axes[ i ] = 0.0f;
joy->tmp_buttons = 0; joy->pJoystick.tmp_buttons = 0;
# endif # endif
joy->fd = open( joy->fname, O_RDONLY ); joy->pJoystick.fd = open( joy->pJoystick.fname, O_RDONLY );
joy->error =( joy->fd < 0 ); joy->error =( joy->pJoystick.fd < 0 );
if( joy->error ) if( joy->error )
return; return;
@ -1252,12 +1252,12 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
* to the upper byte of an uninitialized word doesn't work. * to the upper byte of an uninitialized word doesn't work.
* 9 April 2003 * 9 April 2003
*/ */
ioctl( joy->fd, JSIOCGAXES, &u ); ioctl( joy->pJoystick.fd, JSIOCGAXES, &u );
joy->num_axes = u; joy->num_axes = u;
ioctl( joy->fd, JSIOCGBUTTONS, &u ); ioctl( joy->pJoystick.fd, JSIOCGBUTTONS, &u );
joy->num_buttons = u; joy->num_buttons = u;
ioctl( joy->fd, JSIOCGNAME( sizeof( joy->name ) ), joy->name ); ioctl( joy->pJoystick.fd, JSIOCGNAME( sizeof( joy->name ) ), joy->name );
fcntl( joy->fd, F_SETFL, O_NONBLOCK ); fcntl( joy->pJoystick.fd, F_SETFL, O_NONBLOCK );
# endif # endif
/* /*
@ -1307,23 +1307,23 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
fgJoystick[ ident ]->id = ident; fgJoystick[ ident ]->id = ident;
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
fgJoystick[ ident ]->os = calloc( 1, sizeof( struct os_specific_s ) ); fgJoystick[ ident ]->pJoystick.os = calloc( 1, sizeof( struct os_specific_s ) );
memset( fgJoystick[ ident ]->os, 0, sizeof( struct os_specific_s ) ); memset( fgJoystick[ ident ]->pJoystick.os, 0, sizeof( struct os_specific_s ) );
if( ident < USB_IDENT_OFFSET ) if( ident < USB_IDENT_OFFSET )
fgJoystick[ ident ]->os->is_analog = 1; fgJoystick[ ident ]->pJoystick.os->is_analog = 1;
if( fgJoystick[ ident ]->os->is_analog ) if( fgJoystick[ ident ]->pJoystick.os->is_analog )
snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", AJSDEV, ident ); snprintf( fgJoystick[ ident ]->pJoystick.os->fname, sizeof(fgJoystick[ ident ]->pJoystick.os->fname), "%s%d", AJSDEV, ident );
else else
snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", UHIDDEV, snprintf( fgJoystick[ ident ]->pJoystick.os->fname, sizeof(fgJoystick[ ident ]->pJoystick.os->fname), "%s%d", UHIDDEV,
ident - USB_IDENT_OFFSET ); ident - USB_IDENT_OFFSET );
#elif defined( __linux__ ) #elif defined( __linux__ )
fgJoystick[ ident ]->id = ident; fgJoystick[ ident ]->id = ident;
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
snprintf( fgJoystick[ident]->fname, sizeof(fgJoystick[ident]->fname), "/dev/input/js%d", ident ); snprintf( fgJoystick[ident]->pJoystick.fname, sizeof(fgJoystick[ident]->pJoystick.fname), "/dev/input/js%d", ident );
if( access( fgJoystick[ ident ]->fname, F_OK ) != 0 ) if( access( fgJoystick[ ident ]->pJoystick.fname, F_OK ) != 0 )
snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); snprintf( fgJoystick[ ident ]->pJoystick.fname, sizeof(fgJoystick[ ident ]->pJoystick.fname), "/dev/js%d", ident );
#endif #endif
} }
@ -1331,22 +1331,22 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
void fgPlatformJoystickClose ( int ident ) void fgPlatformJoystickClose ( int ident )
{ {
#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
if( fgJoystick[ident]->os ) if( fgJoystick[ident]->pJoystick.os )
{ {
if( ! fgJoystick[ ident ]->error ) if( ! fgJoystick[ ident ]->error )
close( fgJoystick[ ident ]->os->fd ); close( fgJoystick[ ident ]->pJoystick.os->fd );
#ifdef HAVE_USB_JS #ifdef HAVE_USB_JS
if( fgJoystick[ ident ]->os->hids ) if( fgJoystick[ ident ]->pJoystick.os->hids )
free (fgJoystick[ ident ]->os->hids); free (fgJoystick[ ident ]->pJoystick.os->hids);
if( fgJoystick[ ident ]->os->hid_data_buf ) if( fgJoystick[ ident ]->pJoystick.os->hid_data_buf )
free( fgJoystick[ ident ]->os->hid_data_buf ); free( fgJoystick[ ident ]->pJoystick.os->hid_data_buf );
#endif #endif
free( fgJoystick[ident]->os ); free( fgJoystick[ident]->pJoystick.os );
} }
#endif #endif
if( ! fgJoystick[ident]->error ) if( ! fgJoystick[ident]->error )
close( fgJoystick[ ident ]->fd ); close( fgJoystick[ ident ]->pJoystick.fd );
} }
#endif #endif

View File

@ -41,7 +41,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
{ {
MMRESULT status; MMRESULT status;
status = joyGetPosEx( joy->js_id, &joy->js ); status = joyGetPosEx( joy->pJoystick.js_id, &joy->pJoystick.js );
if ( status != JOYERR_NOERROR ) if ( status != JOYERR_NOERROR )
{ {
@ -50,7 +50,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
} }
if ( buttons ) if ( buttons )
*buttons = joy->js.dwButtons; *buttons = joy->pJoystick.js.dwButtons;
if ( axes ) if ( axes )
{ {
@ -64,7 +64,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
* Low 16 bits of js.dwPOV gives heading (clockwise from ahead) in * Low 16 bits of js.dwPOV gives heading (clockwise from ahead) in
* hundredths of a degree, or 0xFFFF when idle. * hundredths of a degree, or 0xFFFF when idle.
*/ */
if ( ( joy->js.dwPOV & 0xFFFF ) == 0xFFFF ) if ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) == 0xFFFF )
{ {
axes [ 6 ] = 0.0; axes [ 6 ] = 0.0;
axes [ 7 ] = 0.0; axes [ 7 ] = 0.0;
@ -77,8 +77,8 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
* But the accuracy of the value of PI is very unimportant at * But the accuracy of the value of PI is very unimportant at
* this point. * this point.
*/ */
float s = (float) sin ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) ); float s = (float) sin ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );
float c = (float) cos ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) ); float c = (float) cos ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );
/* Convert to coordinates on a square so that North-East /* Convert to coordinates on a square so that North-East
* is (1,1) not (.7,.7), etc. * is (1,1) not (.7,.7), etc.
@ -96,12 +96,12 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
} }
} }
case 6: axes[5] = (float) joy->js.dwVpos; case 6: axes[5] = (float) joy->pJoystick.js.dwVpos;
case 5: axes[4] = (float) joy->js.dwUpos; case 5: axes[4] = (float) joy->pJoystick.js.dwUpos;
case 4: axes[3] = (float) joy->js.dwRpos; case 4: axes[3] = (float) joy->pJoystick.js.dwRpos;
case 3: axes[2] = (float) joy->js.dwZpos; case 3: axes[2] = (float) joy->pJoystick.js.dwZpos;
case 2: axes[1] = (float) joy->js.dwYpos; case 2: axes[1] = (float) joy->pJoystick.js.dwYpos;
case 1: axes[0] = (float) joy->js.dwXpos; case 1: axes[0] = (float) joy->pJoystick.js.dwXpos;
} }
} }
} }
@ -130,7 +130,7 @@ static int fghJoystickGetOEMProductName ( SFG_Joystick* joy, char *buf, int buf_
/* Open .. MediaResources\CurrentJoystickSettings */ /* Open .. MediaResources\CurrentJoystickSettings */
_snprintf ( buffer, sizeof(buffer), "%s\\%s\\%s", _snprintf ( buffer, sizeof(buffer), "%s\\%s\\%s",
REGSTR_PATH_JOYCONFIG, joy->jsCaps.szRegKey, REGSTR_PATH_JOYCONFIG, joy->pJoystick.jsCaps.szRegKey,
REGSTR_KEY_JOYCURR ); REGSTR_KEY_JOYCURR );
lr = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey); lr = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey);
@ -141,7 +141,7 @@ static int fghJoystickGetOEMProductName ( SFG_Joystick* joy, char *buf, int buf_
dwcb = sizeof(OEMKey); dwcb = sizeof(OEMKey);
/* JOYSTICKID1-16 is zero-based; registry entries for VJOYD are 1-based. */ /* JOYSTICKID1-16 is zero-based; registry entries for VJOYD are 1-based. */
_snprintf ( buffer, sizeof(buffer), "Joystick%d%s", joy->js_id + 1, REGSTR_VAL_JOYOEMNAME ); _snprintf ( buffer, sizeof(buffer), "Joystick%d%s", joy->pJoystick.js_id + 1, REGSTR_VAL_JOYOEMNAME );
lr = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEMKey, &dwcb); lr = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEMKey, &dwcb);
RegCloseKey ( hKey ); RegCloseKey ( hKey );
@ -172,16 +172,16 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
{ {
int i = 0; int i = 0;
joy->js.dwFlags = JOY_RETURNALL; joy->pJoystick.js.dwFlags = JOY_RETURNALL;
joy->js.dwSize = sizeof( joy->js ); joy->pJoystick.js.dwSize = sizeof( joy->pJoystick.js );
memset( &joy->jsCaps, 0, sizeof( joy->jsCaps ) ); memset( &joy->pJoystick.jsCaps, 0, sizeof( joy->pJoystick.jsCaps ) );
joy->error = joy->error =
( joyGetDevCaps( joy->js_id, &joy->jsCaps, sizeof( joy->jsCaps ) ) != ( joyGetDevCaps( joy->pJoystick.js_id, &joy->pJoystick.jsCaps, sizeof( joy->pJoystick.jsCaps ) ) !=
JOYERR_NOERROR ); JOYERR_NOERROR );
if( joy->jsCaps.wNumAxes == 0 ) if( joy->pJoystick.jsCaps.wNumAxes == 0 )
{ {
joy->num_axes = 0; joy->num_axes = 0;
joy->error = GL_TRUE; joy->error = GL_TRUE;
@ -195,13 +195,13 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
sizeof( joy->name ) ) ) sizeof( joy->name ) ) )
{ {
fgWarning( "JS: Failed to read joystick name from registry" ); fgWarning( "JS: Failed to read joystick name from registry" );
strncpy( joy->name, joy->jsCaps.szPname, sizeof( joy->name ) ); strncpy( joy->name, joy->pJoystick.jsCaps.szPname, sizeof( joy->name ) );
} }
/* Windows joystick drivers may provide any combination of /* Windows joystick drivers may provide any combination of
* X,Y,Z,R,U,V,POV - not necessarily the first n of these. * X,Y,Z,R,U,V,POV - not necessarily the first n of these.
*/ */
if( joy->jsCaps.wCaps & JOYCAPS_HASPOV ) if( joy->pJoystick.jsCaps.wCaps & JOYCAPS_HASPOV )
{ {
joy->num_axes = _JS_MAX_AXES; joy->num_axes = _JS_MAX_AXES;
joy->min[ 7 ] = -1.0; joy->max[ 7 ] = 1.0; /* POV Y */ joy->min[ 7 ] = -1.0; joy->max[ 7 ] = 1.0; /* POV Y */
@ -210,18 +210,18 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
else else
joy->num_axes = 6; joy->num_axes = 6;
joy->min[ 5 ] = ( float )joy->jsCaps.wVmin; joy->min[ 5 ] = ( float )joy->pJoystick.jsCaps.wVmin;
joy->max[ 5 ] = ( float )joy->jsCaps.wVmax; joy->max[ 5 ] = ( float )joy->pJoystick.jsCaps.wVmax;
joy->min[ 4 ] = ( float )joy->jsCaps.wUmin; joy->min[ 4 ] = ( float )joy->pJoystick.jsCaps.wUmin;
joy->max[ 4 ] = ( float )joy->jsCaps.wUmax; joy->max[ 4 ] = ( float )joy->pJoystick.jsCaps.wUmax;
joy->min[ 3 ] = ( float )joy->jsCaps.wRmin; joy->min[ 3 ] = ( float )joy->pJoystick.jsCaps.wRmin;
joy->max[ 3 ] = ( float )joy->jsCaps.wRmax; joy->max[ 3 ] = ( float )joy->pJoystick.jsCaps.wRmax;
joy->min[ 2 ] = ( float )joy->jsCaps.wZmin; joy->min[ 2 ] = ( float )joy->pJoystick.jsCaps.wZmin;
joy->max[ 2 ] = ( float )joy->jsCaps.wZmax; joy->max[ 2 ] = ( float )joy->pJoystick.jsCaps.wZmax;
joy->min[ 1 ] = ( float )joy->jsCaps.wYmin; joy->min[ 1 ] = ( float )joy->pJoystick.jsCaps.wYmin;
joy->max[ 1 ] = ( float )joy->jsCaps.wYmax; joy->max[ 1 ] = ( float )joy->pJoystick.jsCaps.wYmax;
joy->min[ 0 ] = ( float )joy->jsCaps.wXmin; joy->min[ 0 ] = ( float )joy->pJoystick.jsCaps.wXmin;
joy->max[ 0 ] = ( float )joy->jsCaps.wXmax; joy->max[ 0 ] = ( float )joy->pJoystick.jsCaps.wXmax;
} }
/* Guess all the rest judging on the axes extremals */ /* Guess all the rest judging on the axes extremals */
@ -240,11 +240,11 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
switch( ident ) switch( ident )
{ {
case 0: case 0:
fgJoystick[ ident ]->js_id = JOYSTICKID1; fgJoystick[ ident ]->pJoystick.js_id = JOYSTICKID1;
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
break; break;
case 1: case 1:
fgJoystick[ ident ]->js_id = JOYSTICKID2; fgJoystick[ ident ]->pJoystick.js_id = JOYSTICKID2;
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
break; break;
default: default: