Moved the platform-specific variables in the Joystick structure into their own platfo...
authorJohn F. Fay <johnffay@nettally.com>
Sun, 29 Jan 2012 05:25:10 +0000 (05:25 +0000)
committerJohn F. Fay <johnffay@nettally.com>
Sun, 29 Jan 2012 05:25:10 +0000 (05:25 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1025 7f0cb862-5218-0410-a997-914c9d46530a

src/Common/freeglut_internal.h
src/Common/freeglut_joystick.c
src/mswin/freeglut_joystick_mswin.c

index 1d0a5b6..68466c4 100644 (file)
@@ -788,50 +788,47 @@ struct tagSFG_StrokeFont
 \r
 #if TARGET_HOST_MACINTOSH\r
 #    define _JS_MAX_AXES  9\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-#    define _JS_MAX_AXES 16\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-#    define _JS_MAX_AXES  8\r
-#endif\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-#    define _JS_MAX_AXES 16\r
-#endif\r
-\r
-/*\r
- * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.\r
- * See "js.h" lines 80-178.\r
- */\r
-typedef struct tagSFG_Joystick SFG_Joystick;\r
-struct tagSFG_Joystick\r
+typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;\r
+struct tagSFG_PlatformJoystick\r
 {\r
-#if TARGET_HOST_MACINTOSH\r
 #define  ISP_NUM_AXIS    9\r
 #define  ISP_NUM_NEEDS  41\r
     ISpElementReference isp_elem  [ ISP_NUM_NEEDS ];\r
     ISpNeed             isp_needs [ ISP_NUM_NEEDS ];\r
+};\r
 #endif\r
 \r
 #if TARGET_HOST_MAC_OSX\r
+#    define _JS_MAX_AXES 16\r
+typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;\r
+struct tagSFG_PlatformJoystick\r
+{\r
     IOHIDDeviceInterface ** hidDev;\r
     IOHIDElementCookie buttonCookies[41];\r
     IOHIDElementCookie axisCookies[_JS_MAX_AXES];\r
-    long minReport[_JS_MAX_AXES],\r
-         maxReport[_JS_MAX_AXES];\r
+/* The next two variables are not used anywhere */\r
+/*    long minReport[_JS_MAX_AXES],\r
+ *         maxReport[_JS_MAX_AXES];\r
+ */\r
+};\r
 #endif\r
 \r
 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
+#    define _JS_MAX_AXES  8\r
+typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;\r
+struct tagSFG_PlatformJoystick\r
+{\r
     JOYCAPS     jsCaps;\r
     JOYINFOEX   js;\r
     UINT        js_id;\r
+};\r
 #endif\r
 \r
-\r
 #if TARGET_HOST_POSIX_X11\r
+#    define _JS_MAX_AXES 16\r
+typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;\r
+struct tagSFG_PlatformJoystick\r
+{\r
 #   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
        struct os_specific_s *os;\r
 #   endif\r
@@ -846,8 +843,18 @@ struct tagSFG_Joystick
 \r
     char         fname [ 128 ];\r
     int          fd;\r
+};\r
 #endif\r
 \r
+/*\r
+ * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.\r
+ * See "js.h" lines 80-178.\r
+ */\r
+typedef struct tagSFG_Joystick SFG_Joystick;\r
+struct tagSFG_Joystick\r
+{\r
+       SFG_PlatformJoystick pJoystick;\r
+\r
     int          id;\r
     GLboolean    error;\r
     char         name [ 128 ];\r
index 021870f..dc5e973 100644 (file)
@@ -594,7 +594,7 @@ static void fghJoystickAddAxisElement ( SFG_Joystick *joy, CFDictionaryRef axis
         CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementCookieKey) ),\r
         kCFNumberLongType, &cookie);\r
 \r
-    axisCookies[index] = (IOHIDElementCookie) cookie;\r
+    joy->pJoystick.axisCookies[index] = (IOHIDElementCookie) cookie;\r
 \r
     CFNumberGetValue ((CFNumberRef)\r
         CFDictionaryGetValue ( axis, CFSTR(kIOHIDElementMinKey) ),\r
@@ -618,7 +618,7 @@ static void fghJoystickAddButtonElement ( SFG_Joystick *joy, CFDictionaryRef but
             CFDictionaryGetValue ( button, CFSTR(kIOHIDElementCookieKey) ),\r
             kCFNumberLongType, &cookie);\r
 \r
-    joy->buttonCookies[num_buttons++] = (IOHIDElementCookie) cookie;\r
+    joy->pJoystick.buttonCookies[num_buttons++] = (IOHIDElementCookie) cookie;\r
     /* anything else for buttons? */\r
 }\r
 \r
@@ -645,7 +645,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
         for ( i = 0; i < joy->num_buttons; i++ )\r
         {\r
             UInt32 state;\r
-            int err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state);\r
+            int err = ISpElement_GetSimpleState ( joy->pJoystick.isp_elem [ i + ISP_NUM_AXIS ], &state);\r
             ISP_CHECK_ERR(err)\r
 \r
             *buttons |= state << i;\r
@@ -657,7 +657,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
         for ( i = 0; i < joy->num_axes; i++ )\r
         {\r
             UInt32 state;\r
-            int err = ISpElement_GetSimpleState ( isp_elem [ i ], &state );\r
+            int err = ISpElement_GetSimpleState ( joy->pJoystick.isp_elem [ i ], &state );\r
             ISP_CHECK_ERR(err)\r
 \r
             axes [i] = (float) state;\r
@@ -682,7 +682,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
         joy->error = GL_TRUE;\r
 \r
         /* initialize the needs structure */\r
-        ISpNeed temp_isp_needs[ isp_num_needs ] =\r
+        ISpNeed temp_isp_needs[ ISP_NUM_NEEDS ] =\r
         {\r
           { "\pX-Axis",  128, 0, 0, kISpElementKind_Axis,   kISpElementLabel_None, 0, 0, 0, 0 },\r
           { "\pY-Axis",  128, 0, 0, kISpElementKind_Axis,   kISpElementLabel_None, 0, 0, 0, 0 },\r
@@ -728,7 +728,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
           { "\pButton 31", 128, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_Select, 0, 0, 0, 0 },\r
         };\r
 \r
-        memcpy( joy->isp_needs, temp_isp_needs, sizeof (temp_isp_needs ) );\r
+        memcpy( joy->pJoystick.isp_needs, temp_isp_needs, sizeof (temp_isp_needs ) );\r
 \r
 \r
         /* next two calls allow keyboard and mouse to emulate other input\r
@@ -743,17 +743,17 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
           ISP_CHECK_ERR(err)\r
         */\r
 \r
-        err = ISpElement_NewVirtualFromNeeds( joy->isp_num_needs,\r
-                                              joy->isp_needs, joy->isp_elem,\r
+        err = ISpElement_NewVirtualFromNeeds( ISP_NUM_NEEDS,\r
+                                              joy->pJoystick.isp_needs, joy->pJoystick.isp_elem,\r
                                               0 );\r
         ISP_CHECK_ERR( err )\r
 \r
-        err = ISpInit( joy->isp_num_needs, joy->isp_needs, joy->isp_elem,\r
+        err = ISpInit( ISP_NUM_NEEDS, joy->pJoystick.isp_needs, joy->pJoystick.isp_elem,\r
                        'freeglut', nil, 0, 128, 0 );\r
         ISP_CHECK_ERR( err )\r
 \r
-        joy->num_buttons = joy->isp_num_needs - joy->isp_num_axis;\r
-        joy->num_axes    = joy->isp_num_axis;\r
+        joy->num_buttons = ISP_NUM_NEEDS - ISP_NUM_AXIS;\r
+        joy->num_axes    = ISP_NUM_AXIS;\r
 \r
         for( i = 0; i < joy->num_axes; i++ )\r
         {\r
@@ -774,7 +774,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
 void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )\r
 {\r
     fgJoystick[ ident ]->id = ident;\r
-    snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */\r
+    snprintf( fgJoystick[ ident ]->pJoystick.fname, sizeof(fgJoystick[ ident ]->pJoystick.fname), "/dev/js%d", ident ); /* FIXME */\r
     fgJoystick[ ident ]->error = GL_FALSE;\r
 }\r
 \r
@@ -799,7 +799,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
         for ( i = 0; i < joy->num_buttons; i++ )\r
         {\r
             IOHIDEventStruct hidEvent;\r
-            (*(joy->hidDev))->getElementValue ( joy->hidDev, buttonCookies[i], &hidEvent );\r
+            (*(joy->pJoystick.hidDev))->getElementValue ( joy->pJoystick.hidDev, joy->pJoystick.buttonCookies[i], &hidEvent );\r
             if ( hidEvent.value )\r
                 *buttons |= 1 << i;\r
         }\r
@@ -810,7 +810,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
         for ( i = 0; i < joy->num_axes; i++ )\r
         {\r
             IOHIDEventStruct hidEvent;\r
-            (*(joy->hidDev))->getElementValue ( joy->hidDev, axisCookies[i], &hidEvent );\r
+            (*(joy->pJoystick.hidDev))->getElementValue ( joy->pJoystick.hidDev, joy->pJoystick.axisCookies[i], &hidEvent );\r
             axes[i] = hidEvent.value;\r
         }\r
     }\r
@@ -849,18 +849,18 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
     pluginResult = ( *plugin )->QueryInterface(\r
         plugin,\r
         CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),\r
-        &( LPVOID )joy->hidDev\r
+        &( LPVOID )joy->pJoystick.hidDev\r
     );\r
 \r
     if( pluginResult != S_OK )\r
         fgWarning ( "QI-ing IO plugin to HID Device interface failed" );\r
 \r
     ( *plugin )->Release( plugin ); /* don't leak a ref */\r
-    if( joy->hidDev == NULL )\r
+    if( joy->pJoystick.hidDev == NULL )\r
         return;\r
 \r
     /* store the interface in this instance */\r
-    rv = ( *( joy->hidDev ) )->open( joy->hidDev, 0 );\r
+    rv = ( *( joy->pJoystick.hidDev ) )->open( joy->pJoystick.hidDev, 0 );\r
     if( rv != kIOReturnSuccess )\r
     {\r
         fgWarning( "error opening device interface");\r
@@ -925,8 +925,8 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
 \r
 void fgPlatformJoystickClose ( int ident )\r
 {\r
-    ( *( fgJoystick[ ident ]->hidDev ) )->\r
-        close( fgJoystick[ ident ]->hidDev );\r
+    ( *( fgJoystick[ ident ]->pJoystick.hidDev ) )->\r
+        close( fgJoystick[ ident ]->pJoystick.hidDev );\r
 }\r
 #endif\r
 \r
@@ -940,34 +940,34 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
     int len;\r
 \r
-    if ( joy->os->is_analog )\r
+    if ( joy->pJoystick.os->is_analog )\r
     {\r
-        int status = read ( joy->os->fd, &joy->os->ajs, sizeof(joy->os->ajs) );\r
-        if ( status != sizeof(joy->os->ajs) ) {\r
-            perror ( joy->os->fname );\r
+        int status = read ( joy->pJoystick.os->fd, &joy->pJoystick.os->ajs, sizeof(joy->pJoystick.os->ajs) );\r
+        if ( status != sizeof(joy->pJoystick.os->ajs) ) {\r
+            perror ( joy->pJoystick.os->fname );\r
             joy->error = GL_TRUE;\r
             return;\r
         }\r
         if ( buttons != NULL )\r
-            *buttons = ( joy->os->ajs.b1 ? 1 : 0 ) | ( joy->os->ajs.b2 ? 2 : 0 );\r
+            *buttons = ( joy->pJoystick.os->ajs.b1 ? 1 : 0 ) | ( joy->pJoystick.os->ajs.b2 ? 2 : 0 );\r
 \r
         if ( axes != NULL )\r
         {\r
-            axes[0] = (float) joy->os->ajs.x;\r
-            axes[1] = (float) joy->os->ajs.y;\r
+            axes[0] = (float) joy->pJoystick.os->ajs.x;\r
+            axes[1] = (float) joy->pJoystick.os->ajs.y;\r
         }\r
 \r
         return;\r
     }\r
 \r
 #  ifdef HAVE_USB_JS\r
-    while ( ( len = read ( joy->os->fd, joy->os->hid_data_buf, joy->os->hid_dlen ) ) == joy->os->hid_dlen )\r
+    while ( ( len = read ( joy->pJoystick.os->fd, joy->pJoystick.os->hid_data_buf, joy->pJoystick.os->hid_dlen ) ) == joy->pJoystick.os->hid_dlen )\r
     {\r
         struct hid_item *h;\r
 \r
-        for  ( h = joy->os->hids; h; h = h->next )\r
+        for  ( h = joy->pJoystick.os->hids; h; h = h->next )\r
         {\r
-            int d = hid_get_data ( joy->os->hid_data_buf, h );\r
+            int d = hid_get_data ( joy->pJoystick.os->hid_data_buf, h );\r
 \r
             int page = HID_PAGE ( h->usage );\r
             int usage = HID_USAGE ( h->usage );\r
@@ -976,18 +976,18 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
             {\r
                 int i;\r
                 for ( i = 0; i < joy->num_axes; i++ )\r
-                    if (joy->os->axes_usage[i] == usage)\r
+                    if (joy->pJoystick.os->axes_usage[i] == usage)\r
                     {\r
                         if (usage == HUG_HAT_SWITCH)\r
                         {\r
                             if (d < 0 || d > 8)\r
                                 d = 0;  /* safety */\r
-                            joy->os->cache_axes[i] = (float)hatmap_x[d];\r
-                            joy->os->cache_axes[i + 1] = (float)hatmap_y[d];\r
+                            joy->pJoystick.os->cache_axes[i] = (float)hatmap_x[d];\r
+                            joy->pJoystick.os->cache_axes[i + 1] = (float)hatmap_y[d];\r
                         }\r
                         else\r
                         {\r
-                            joy->os->cache_axes[i] = (float)d;\r
+                            joy->pJoystick.os->cache_axes[i] = (float)d;\r
                         }\r
                         break;\r
                     }\r
@@ -997,9 +997,9 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
                if (usage > 0 && usage < _JS_MAX_BUTTONS + 1)\r
                {\r
                    if (d)\r
-                       joy->os->cache_buttons |=  (1 << ( usage - 1 ));\r
+                       joy->pJoystick.os->cache_buttons |=  (1 << ( usage - 1 ));\r
                    else\r
-                       joy->os->cache_buttons &= ~(1 << ( usage - 1 ));\r
+                       joy->pJoystick.os->cache_buttons &= ~(1 << ( usage - 1 ));\r
                }\r
             }\r
         }\r
@@ -1010,12 +1010,12 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
     if ( len < 0 )\r
 #    endif\r
     {\r
-        perror( joy->os->fname );\r
+        perror( joy->pJoystick.os->fname );\r
         joy->error = 1;\r
     }\r
-    if ( buttons != NULL ) *buttons = joy->os->cache_buttons;\r
+    if ( buttons != NULL ) *buttons = joy->pJoystick.os->cache_buttons;\r
     if ( axes    != NULL )\r
-        memcpy ( axes, joy->os->cache_axes, sizeof(float) * joy->num_axes );\r
+        memcpy ( axes, joy->pJoystick.os->cache_axes, sizeof(float) * joy->num_axes );\r
 #  endif\r
 #endif\r
 \r
@@ -1023,7 +1023,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
 \r
     while ( 1 )\r
     {\r
-        status = read ( joy->fd, &joy->js, sizeof(struct js_event) );\r
+        status = read ( joy->pJoystick.fd, &joy->pJoystick.js, sizeof(struct js_event) );\r
 \r
         if ( status != sizeof( struct js_event ) )\r
         {\r
@@ -1032,35 +1032,35 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
             {\r
                 /* Use the old values */\r
                 if ( buttons )\r
-                    *buttons = joy->tmp_buttons;\r
+                    *buttons = joy->pJoystick.tmp_buttons;\r
                 if ( axes )\r
-                    memcpy( axes, joy->tmp_axes,\r
+                    memcpy( axes, joy->pJoystick.tmp_axes,\r
                             sizeof( float ) * joy->num_axes );\r
                 return;\r
             }\r
 #  endif\r
 \r
-            fgWarning ( "%s", joy->fname );\r
+            fgWarning ( "%s", joy->pJoystick.fname );\r
             joy->error = GL_TRUE;\r
             return;\r
         }\r
 \r
-        switch ( joy->js.type & ~JS_EVENT_INIT )\r
+        switch ( joy->pJoystick.js.type & ~JS_EVENT_INIT )\r
         {\r
         case JS_EVENT_BUTTON:\r
-            if( joy->js.value == 0 ) /* clear the flag */\r
-                joy->tmp_buttons &= ~( 1 << joy->js.number );\r
+            if( joy->pJoystick.js.value == 0 ) /* clear the flag */\r
+                joy->pJoystick.tmp_buttons &= ~( 1 << joy->pJoystick.js.number );\r
             else\r
-                joy->tmp_buttons |= ( 1 << joy->js.number );\r
+                joy->pJoystick.tmp_buttons |= ( 1 << joy->pJoystick.js.number );\r
             break;\r
 \r
         case JS_EVENT_AXIS:\r
-            if ( joy->js.number < joy->num_axes )\r
+            if ( joy->pJoystick.js.number < joy->num_axes )\r
             {\r
-                joy->tmp_axes[ joy->js.number ] = ( float )joy->js.value;\r
+                joy->pJoystick.tmp_axes[ joy->pJoystick.js.number ] = ( float )joy->pJoystick.js.value;\r
 \r
                 if( axes )\r
-                    memcpy( axes, joy->tmp_axes, sizeof(float) * joy->num_axes );\r
+                    memcpy( axes, joy->pJoystick.tmp_axes, sizeof(float) * joy->num_axes );\r
             }\r
             break;\r
 \r
@@ -1069,38 +1069,38 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
 \r
             /* use the old values */\r
 \r
-            if ( buttons != NULL ) *buttons = joy->tmp_buttons;\r
+            if ( buttons != NULL ) *buttons = joy->pJoystick.tmp_buttons;\r
             if ( axes    != NULL )\r
-                memcpy ( axes, joy->tmp_axes, sizeof(float) * joy->num_axes );\r
+                memcpy ( axes, joy->pJoystick.tmp_axes, sizeof(float) * joy->num_axes );\r
 \r
             return;\r
         }\r
 \r
         if( buttons )\r
-            *buttons = joy->tmp_buttons;\r
+            *buttons = joy->pJoystick.tmp_buttons;\r
     }\r
 #else\r
 \r
-    status = read( joy->fd, &joy->js, JS_RETURN );\r
+    status = read( joy->pJoystick.fd, &joy->pJoystick.js, JS_RETURN );\r
 \r
     if ( status != JS_RETURN )\r
     {\r
-        fgWarning( "%s", joy->fname );\r
+        fgWarning( "%s", joy->pJoystick.fname );\r
         joy->error = GL_TRUE;\r
         return;\r
     }\r
 \r
     if ( buttons )\r
 #    if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
-        *buttons = ( joy->js.b1 ? 1 : 0 ) | ( joy->js.b2 ? 2 : 0 );  /* XXX Should not be here -- BSD is handled earlier */\r
+        *buttons = ( joy->pJoystick.js.b1 ? 1 : 0 ) | ( joy->pJoystick.js.b2 ? 2 : 0 );  /* XXX Should not be here -- BSD is handled earlier */\r
 #    else\r
-        *buttons = joy->js.buttons;\r
+        *buttons = joy->pJoystick.js.buttons;\r
 #    endif\r
 \r
     if ( axes )\r
     {\r
-        axes[ 0 ] = (float) joy->js.x;\r
-        axes[ 1 ] = (float) joy->js.y;\r
+        axes[ 0 ] = (float) joy->pJoystick.js.x;\r
+        axes[ 1 ] = (float) joy->pJoystick.js.y;\r
     }\r
 #endif\r
 }\r
@@ -1123,25 +1123,25 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
 \r
 #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
     for( i = 0; i < _JS_MAX_AXES; i++ )\r
-        joy->os->cache_axes[ i ] = 0.0f;\r
+        joy->pJoystick.os->cache_axes[ i ] = 0.0f;\r
 \r
-    joy->os->cache_buttons = 0;\r
+    joy->pJoystick.os->cache_buttons = 0;\r
 \r
-    joy->os->fd = open( joy->os->fname, O_RDONLY | O_NONBLOCK);\r
+    joy->pJoystick.os->fd = open( joy->pJoystick.os->fname, O_RDONLY | O_NONBLOCK);\r
 \r
 #ifdef HAVE_ERRNO_H\r
-    if( joy->os->fd < 0 && errno == EACCES )\r
-        fgWarning ( "%s exists but is not readable by you", joy->os->fname );\r
+    if( joy->pJoystick.os->fd < 0 && errno == EACCES )\r
+        fgWarning ( "%s exists but is not readable by you", joy->pJoystick.os->fname );\r
 #endif\r
 \r
-    joy->error =( joy->os->fd < 0 );\r
+    joy->error =( joy->pJoystick.os->fd < 0 );\r
 \r
     if( joy->error )\r
         return;\r
 \r
     joy->num_axes = 0;\r
     joy->num_buttons = 0;\r
-    if( joy->os->is_analog )\r
+    if( joy->pJoystick.os->is_analog )\r
     {\r
         FILE *joyfile;\r
         char joyfname[ 1024 ];\r
@@ -1183,15 +1183,15 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
     }\r
 \r
 #    ifdef HAVE_USB_JS\r
-    if( ! fghJoystickInitializeHID( joy->os, &joy->num_axes,\r
+    if( ! fghJoystickInitializeHID( joy->pJoystick.os, &joy->num_axes,\r
                                     &joy->num_buttons ) )\r
     {\r
-        close( joy->os->fd );\r
+        close( joy->pJoystick.os->fd );\r
         joy->error = GL_TRUE;\r
         return;\r
     }\r
 \r
-    cp = strrchr( joy->os->fname, '/' );\r
+    cp = strrchr( joy->pJoystick.os->fname, '/' );\r
     if( cp )\r
     {\r
         if( fghJoystickFindUSBdev( &cp[1], joy->name, sizeof( joy->name ) ) ==\r
@@ -1208,7 +1208,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
          * to be quite unreliable for analog-to-USB converters. Punt for\r
          * now.\r
          */\r
-        if( joy->os->axes_usage[ i ] == HUG_HAT_SWITCH )\r
+        if( joy->pJoystick.os->axes_usage[ i ] == HUG_HAT_SWITCH )\r
         {\r
             joy->max   [ i ] = 1.0f;\r
             joy->center[ i ] = 0.0f;\r
@@ -1234,14 +1234,14 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
 \r
 #    ifdef JS_NEW\r
     for( i = 0; i < _JS_MAX_AXES; i++ )\r
-        joy->tmp_axes[ i ] = 0.0f;\r
+        joy->pJoystick.tmp_axes[ i ] = 0.0f;\r
 \r
-    joy->tmp_buttons = 0;\r
+    joy->pJoystick.tmp_buttons = 0;\r
 #    endif\r
 \r
-    joy->fd = open( joy->fname, O_RDONLY );\r
+    joy->pJoystick.fd = open( joy->pJoystick.fname, O_RDONLY );\r
 \r
-    joy->error =( joy->fd < 0 );\r
+    joy->error =( joy->pJoystick.fd < 0 );\r
 \r
     if( joy->error )\r
         return;\r
@@ -1252,12 +1252,12 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
      *  to the upper byte of an uninitialized word doesn't work.\r
      *  9 April 2003\r
      */\r
-    ioctl( joy->fd, JSIOCGAXES, &u );\r
+    ioctl( joy->pJoystick.fd, JSIOCGAXES, &u );\r
     joy->num_axes = u;\r
-    ioctl( joy->fd, JSIOCGBUTTONS, &u );\r
+    ioctl( joy->pJoystick.fd, JSIOCGBUTTONS, &u );\r
     joy->num_buttons = u;\r
-    ioctl( joy->fd, JSIOCGNAME( sizeof( joy->name ) ), joy->name );\r
-    fcntl( joy->fd, F_SETFL, O_NONBLOCK );\r
+    ioctl( joy->pJoystick.fd, JSIOCGNAME( sizeof( joy->name ) ), joy->name );\r
+    fcntl( joy->pJoystick.fd, F_SETFL, O_NONBLOCK );\r
 #    endif\r
 \r
     /*\r
@@ -1307,23 +1307,23 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
     fgJoystick[ ident ]->id = ident;\r
     fgJoystick[ ident ]->error = GL_FALSE;\r
 \r
-    fgJoystick[ ident ]->os = calloc( 1, sizeof( struct os_specific_s ) );\r
-    memset( fgJoystick[ ident ]->os, 0, sizeof( struct os_specific_s ) );\r
+    fgJoystick[ ident ]->pJoystick.os = calloc( 1, sizeof( struct os_specific_s ) );\r
+    memset( fgJoystick[ ident ]->pJoystick.os, 0, sizeof( struct os_specific_s ) );\r
     if( ident < USB_IDENT_OFFSET )\r
-        fgJoystick[ ident ]->os->is_analog = 1;\r
-    if( fgJoystick[ ident ]->os->is_analog )\r
-        snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", AJSDEV, ident );\r
+        fgJoystick[ ident ]->pJoystick.os->is_analog = 1;\r
+    if( fgJoystick[ ident ]->pJoystick.os->is_analog )\r
+        snprintf( fgJoystick[ ident ]->pJoystick.os->fname, sizeof(fgJoystick[ ident ]->pJoystick.os->fname), "%s%d", AJSDEV, ident );\r
     else\r
-        snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", UHIDDEV,\r
+        snprintf( fgJoystick[ ident ]->pJoystick.os->fname, sizeof(fgJoystick[ ident ]->pJoystick.os->fname), "%s%d", UHIDDEV,\r
                  ident - USB_IDENT_OFFSET );\r
 #elif defined( __linux__ )\r
     fgJoystick[ ident ]->id = ident;\r
     fgJoystick[ ident ]->error = GL_FALSE;\r
 \r
-    snprintf( fgJoystick[ident]->fname, sizeof(fgJoystick[ident]->fname), "/dev/input/js%d", ident );\r
+    snprintf( fgJoystick[ident]->pJoystick.fname, sizeof(fgJoystick[ident]->pJoystick.fname), "/dev/input/js%d", ident );\r
 \r
-    if( access( fgJoystick[ ident ]->fname, F_OK ) != 0 )\r
-        snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident );\r
+    if( access( fgJoystick[ ident ]->pJoystick.fname, F_OK ) != 0 )\r
+        snprintf( fgJoystick[ ident ]->pJoystick.fname, sizeof(fgJoystick[ ident ]->pJoystick.fname), "/dev/js%d", ident );\r
 #endif\r
 }\r
 \r
@@ -1331,22 +1331,22 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
 void fgPlatformJoystickClose ( int ident )\r
 {\r
 #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
-    if( fgJoystick[ident]->os )\r
+    if( fgJoystick[ident]->pJoystick.os )\r
     {\r
         if( ! fgJoystick[ ident ]->error )\r
-            close( fgJoystick[ ident ]->os->fd );\r
+            close( fgJoystick[ ident ]->pJoystick.os->fd );\r
 #ifdef HAVE_USB_JS\r
-        if( fgJoystick[ ident ]->os->hids )\r
-            free (fgJoystick[ ident ]->os->hids);\r
-        if( fgJoystick[ ident ]->os->hid_data_buf )\r
-            free( fgJoystick[ ident ]->os->hid_data_buf );\r
+        if( fgJoystick[ ident ]->pJoystick.os->hids )\r
+            free (fgJoystick[ ident ]->pJoystick.os->hids);\r
+        if( fgJoystick[ ident ]->pJoystick.os->hid_data_buf )\r
+            free( fgJoystick[ ident ]->pJoystick.os->hid_data_buf );\r
 #endif\r
-        free( fgJoystick[ident]->os );\r
+        free( fgJoystick[ident]->pJoystick.os );\r
        }\r
 #endif\r
 \r
     if( ! fgJoystick[ident]->error )\r
-         close( fgJoystick[ ident ]->fd );\r
+         close( fgJoystick[ ident ]->pJoystick.fd );\r
 }\r
 #endif\r
 \r
index 7d85ade..50dbf1e 100644 (file)
@@ -41,7 +41,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
 {\r
     MMRESULT status;\r
 \r
-    status = joyGetPosEx( joy->js_id, &joy->js );\r
+    status = joyGetPosEx( joy->pJoystick.js_id, &joy->pJoystick.js );\r
 \r
     if ( status != JOYERR_NOERROR )\r
     {\r
@@ -50,7 +50,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
     }\r
 \r
     if ( buttons )\r
-        *buttons = joy->js.dwButtons;\r
+        *buttons = joy->pJoystick.js.dwButtons;\r
 \r
     if ( axes )\r
     {\r
@@ -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\r
              *   hundredths of a degree, or 0xFFFF when idle.\r
              */\r
-            if ( ( joy->js.dwPOV & 0xFFFF ) == 0xFFFF )\r
+            if ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) == 0xFFFF )\r
             {\r
               axes [ 6 ] = 0.0;\r
               axes [ 7 ] = 0.0;\r
@@ -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\r
                * this point.\r
                */\r
-              float s = (float) sin ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
-              float c = (float) cos ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
+              float s = (float) sin ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
+              float c = (float) cos ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
 \r
               /* Convert to coordinates on a square so that North-East\r
                * is (1,1) not (.7,.7), etc.\r
@@ -96,12 +96,12 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
               }\r
             }\r
 \r
-        case 6: axes[5] = (float) joy->js.dwVpos;\r
-        case 5: axes[4] = (float) joy->js.dwUpos;\r
-        case 4: axes[3] = (float) joy->js.dwRpos;\r
-        case 3: axes[2] = (float) joy->js.dwZpos;\r
-        case 2: axes[1] = (float) joy->js.dwYpos;\r
-        case 1: axes[0] = (float) joy->js.dwXpos;\r
+        case 6: axes[5] = (float) joy->pJoystick.js.dwVpos;\r
+        case 5: axes[4] = (float) joy->pJoystick.js.dwUpos;\r
+        case 4: axes[3] = (float) joy->pJoystick.js.dwRpos;\r
+        case 3: axes[2] = (float) joy->pJoystick.js.dwZpos;\r
+        case 2: axes[1] = (float) joy->pJoystick.js.dwYpos;\r
+        case 1: axes[0] = (float) joy->pJoystick.js.dwXpos;\r
         }\r
     }\r
 }\r
@@ -130,7 +130,7 @@ static int fghJoystickGetOEMProductName ( SFG_Joystick* joy, char *buf, int buf_
 \r
     /* Open .. MediaResources\CurrentJoystickSettings */\r
     _snprintf ( buffer, sizeof(buffer), "%s\\%s\\%s",\r
-                REGSTR_PATH_JOYCONFIG, joy->jsCaps.szRegKey,\r
+                REGSTR_PATH_JOYCONFIG, joy->pJoystick.jsCaps.szRegKey,\r
                 REGSTR_KEY_JOYCURR );\r
 \r
     lr = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey);\r
@@ -141,7 +141,7 @@ static int fghJoystickGetOEMProductName ( SFG_Joystick* joy, char *buf, int buf_
     dwcb = sizeof(OEMKey);\r
 \r
     /* JOYSTICKID1-16 is zero-based; registry entries for VJOYD are 1-based. */\r
-    _snprintf ( buffer, sizeof(buffer), "Joystick%d%s", joy->js_id + 1, REGSTR_VAL_JOYOEMNAME );\r
+    _snprintf ( buffer, sizeof(buffer), "Joystick%d%s", joy->pJoystick.js_id + 1, REGSTR_VAL_JOYOEMNAME );\r
 \r
     lr = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEMKey, &dwcb);\r
     RegCloseKey ( hKey );\r
@@ -172,16 +172,16 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
 {\r
        int i = 0;\r
 \r
-    joy->js.dwFlags = JOY_RETURNALL;\r
-    joy->js.dwSize  = sizeof( joy->js );\r
+    joy->pJoystick.js.dwFlags = JOY_RETURNALL;\r
+    joy->pJoystick.js.dwSize  = sizeof( joy->pJoystick.js );\r
 \r
-    memset( &joy->jsCaps, 0, sizeof( joy->jsCaps ) );\r
+    memset( &joy->pJoystick.jsCaps, 0, sizeof( joy->pJoystick.jsCaps ) );\r
 \r
     joy->error =\r
-        ( joyGetDevCaps( joy->js_id, &joy->jsCaps, sizeof( joy->jsCaps ) ) !=\r
+        ( joyGetDevCaps( joy->pJoystick.js_id, &joy->pJoystick.jsCaps, sizeof( joy->pJoystick.jsCaps ) ) !=\r
           JOYERR_NOERROR );\r
 \r
-    if( joy->jsCaps.wNumAxes == 0 )\r
+    if( joy->pJoystick.jsCaps.wNumAxes == 0 )\r
     {\r
         joy->num_axes = 0;\r
         joy->error = GL_TRUE;\r
@@ -195,13 +195,13 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
                                              sizeof( joy->name ) ) )\r
         {\r
             fgWarning( "JS: Failed to read joystick name from registry" );\r
-            strncpy( joy->name, joy->jsCaps.szPname, sizeof( joy->name ) );\r
+            strncpy( joy->name, joy->pJoystick.jsCaps.szPname, sizeof( joy->name ) );\r
         }\r
 \r
         /* Windows joystick drivers may provide any combination of\r
          * X,Y,Z,R,U,V,POV - not necessarily the first n of these.\r
          */\r
-        if( joy->jsCaps.wCaps & JOYCAPS_HASPOV )\r
+        if( joy->pJoystick.jsCaps.wCaps & JOYCAPS_HASPOV )\r
         {\r
             joy->num_axes = _JS_MAX_AXES;\r
             joy->min[ 7 ] = -1.0; joy->max[ 7 ] = 1.0;  /* POV Y */\r
@@ -210,18 +210,18 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
         else\r
             joy->num_axes = 6;\r
 \r
-        joy->min[ 5 ] = ( float )joy->jsCaps.wVmin;\r
-        joy->max[ 5 ] = ( float )joy->jsCaps.wVmax;\r
-        joy->min[ 4 ] = ( float )joy->jsCaps.wUmin;\r
-        joy->max[ 4 ] = ( float )joy->jsCaps.wUmax;\r
-        joy->min[ 3 ] = ( float )joy->jsCaps.wRmin;\r
-        joy->max[ 3 ] = ( float )joy->jsCaps.wRmax;\r
-        joy->min[ 2 ] = ( float )joy->jsCaps.wZmin;\r
-        joy->max[ 2 ] = ( float )joy->jsCaps.wZmax;\r
-        joy->min[ 1 ] = ( float )joy->jsCaps.wYmin;\r
-        joy->max[ 1 ] = ( float )joy->jsCaps.wYmax;\r
-        joy->min[ 0 ] = ( float )joy->jsCaps.wXmin;\r
-        joy->max[ 0 ] = ( float )joy->jsCaps.wXmax;\r
+        joy->min[ 5 ] = ( float )joy->pJoystick.jsCaps.wVmin;\r
+        joy->max[ 5 ] = ( float )joy->pJoystick.jsCaps.wVmax;\r
+        joy->min[ 4 ] = ( float )joy->pJoystick.jsCaps.wUmin;\r
+        joy->max[ 4 ] = ( float )joy->pJoystick.jsCaps.wUmax;\r
+        joy->min[ 3 ] = ( float )joy->pJoystick.jsCaps.wRmin;\r
+        joy->max[ 3 ] = ( float )joy->pJoystick.jsCaps.wRmax;\r
+        joy->min[ 2 ] = ( float )joy->pJoystick.jsCaps.wZmin;\r
+        joy->max[ 2 ] = ( float )joy->pJoystick.jsCaps.wZmax;\r
+        joy->min[ 1 ] = ( float )joy->pJoystick.jsCaps.wYmin;\r
+        joy->max[ 1 ] = ( float )joy->pJoystick.jsCaps.wYmax;\r
+        joy->min[ 0 ] = ( float )joy->pJoystick.jsCaps.wXmin;\r
+        joy->max[ 0 ] = ( float )joy->pJoystick.jsCaps.wXmax;\r
     }\r
 \r
     /* Guess all the rest judging on the axes extremals */\r
@@ -240,11 +240,11 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
     switch( ident )\r
     {\r
     case 0:\r
-        fgJoystick[ ident ]->js_id = JOYSTICKID1;\r
+        fgJoystick[ ident ]->pJoystick.js_id = JOYSTICKID1;\r
         fgJoystick[ ident ]->error = GL_FALSE;\r
         break;\r
     case 1:\r
-        fgJoystick[ ident ]->js_id = JOYSTICKID2;\r
+        fgJoystick[ ident ]->pJoystick.js_id = JOYSTICKID2;\r
         fgJoystick[ ident ]->error = GL_FALSE;\r
         break;\r
     default:\r