Просмотр исходного кода

Merge pull request #1574 from seanpaultaylor/next

Finished Android gamepad support
Sean Taylor 11 лет назад
Родитель
Сommit
78870c6a92

+ 7 - 1
gameplay/src/PlatformAndroid.cpp

@@ -1772,7 +1772,13 @@ extern "C"
 
 JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadEventConnectedImpl(JNIEnv* env, jclass clazz, jint deviceId, jint buttonCount, jint joystickCount, jint triggerCount, jint vendorId, jint productId, jstring vendorIdStr, jstring productIdStr)
 {
-	gameplay::Platform::gamepadEventConnectedInternal(deviceId, buttonCount, joystickCount, triggerCount, vendorId, productId, "", "");
+    const char* vendorString = env->GetStringUTFChars(vendorIdStr, JNI_FALSE);
+    const char* productString = env->GetStringUTFChars(productIdStr, JNI_FALSE);
+    
+	gameplay::Platform::gamepadEventConnectedInternal(deviceId, buttonCount, joystickCount, triggerCount, vendorId, productId, vendorString, productString);
+    
+    env->ReleaseStringUTFChars(vendorIdStr, vendorString);
+    env->ReleaseStringUTFChars(productIdStr, productString);
 }
 
 JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadEventDisconnectedImpl(JNIEnv* env, jclass clazz, jint deviceId)

+ 0 - 28
gameplay/src/PlatformMacOSX.mm

@@ -22,8 +22,6 @@
 #define MICROSOFT_XBOX360_PRODUCT_ID    0x028e
 #define STEELSERIES_VENDOR_ID           0x1038
 #define STEELSERIES_FREE_PRODUCT_ID     0x1412
-#define FRUCTEL_VENDOR_ID               0x25B6
-#define FRUCTEL_GAMETEL_PRODUCT_ID      0x0001
 
 using namespace std;
 using namespace gameplay;
@@ -2054,21 +2052,6 @@ void Platform::pollGamepadState(Gamepad* gamepad)
             Gamepad::BUTTON_MENU1
         };
         
-        static const int GametelMapping103[12] = {
-            Gamepad::BUTTON_B,
-            Gamepad::BUTTON_X,
-            Gamepad::BUTTON_Y,
-            Gamepad::BUTTON_A,
-            Gamepad::BUTTON_L1,
-            Gamepad::BUTTON_R1,
-            Gamepad::BUTTON_MENU1,
-            Gamepad::BUTTON_MENU2,
-            Gamepad::BUTTON_RIGHT,
-            Gamepad::BUTTON_LEFT,
-            Gamepad::BUTTON_DOWN,
-            Gamepad::BUTTON_UP
-        };
-        
         const int* mapping = NULL;
         float axisDeadZone = 0.0f;
         if (gamepad->_vendorId == SONY_USB_VENDOR_ID &&
@@ -2089,17 +2072,6 @@ void Platform::pollGamepadState(Gamepad* gamepad)
             mapping = SteelSeriesFreeMapping;
             axisDeadZone = 0.005f;
         }
-        else if (gamepad->_vendorId == FRUCTEL_VENDOR_ID &&
-                 gamepad->_productId == FRUCTEL_GAMETEL_PRODUCT_ID)
-        {
-            int ver = [gp versionNumber];
-            int major = ver >> 8;
-            int minor = ver & 0x00ff;
-            if (major >= 1 && minor > 1)
-            {
-                mapping = GametelMapping103;
-            }
-        }
         
         unsigned int buttons = 0;
         for (int i = 0; i < [gp numberOfButtons]; ++i)

+ 18 - 9
gameplay/src/org/gameplay3d/GameNativeActivity.java

@@ -47,7 +47,6 @@ public class GameNativeActivity extends NativeActivity
     
     @Override
     public void onSaveInstanceState(Bundle outState) {
-        Log.i(TAG, "onSaveInstanceState");
         super.onSaveInstanceState(outState);
     }
     
@@ -58,42 +57,52 @@ public class GameNativeActivity extends NativeActivity
     
     @Override
     protected void onResume() {
-        Log.i(TAG, "onResume");
         super.onResume();
         _inputManager.registerInputDeviceListener(this, null);
         int[] ids = InputDevice.getDeviceIds();
         for (int i = 0; i < ids.length; i++) {
-            Log.i(TAG, "getGamepadDevice: " + ids[i]);
             getGamepadDevice(ids[i]);
         }
     }
     
     @Override
     protected void onPause() {
-        Log.i(TAG, "onPause");
         _inputManager.unregisterInputDeviceListener(this);
         super.onPause();
     }
     
     @Override
     public void onInputDeviceAdded(int deviceId) {
-        Log.i(TAG, "onInputDeviceAdded: " + deviceId);
         getGamepadDevice(deviceId);
     }
 
     @Override
     public void onInputDeviceRemoved(int deviceId) {
-        Log.i(TAG, "onInputDeviceRemoved: " + deviceId);
         InputDevice device = _gamepadDevices.get(deviceId);
         if (device != null) {
             _gamepadDevices.remove(deviceId);
+            Log.v(TAG, "Gamepad disconnected:id=" + deviceId);
             gamepadEventDisconnectedImpl(deviceId);
         }
     }
     
     @Override
     public void onInputDeviceChanged(int deviceId) {
-        Log.i(TAG, "onInputDeviceChanged: " + deviceId);
+    }
+    
+    private void onGamepadConnected(int deviceId, String deviceName) {
+        int buttonCount = 20;
+        int joystickCount = 2;
+        int triggerCount = 2;
+        int vendorId = 0;
+        int productId = 0;
+        String vendorName = "";
+        String productName = deviceName;
+        
+        Log.v(TAG, "Gamepad connected:id=" + deviceId + ", name=" + deviceName);
+        
+        gamepadEventConnectedImpl(deviceId, buttonCount, joystickCount, triggerCount, 
+                                  productId, vendorId, vendorName, productName);
     }
     
     private InputDevice getGamepadDevice(int deviceId) {
@@ -106,8 +115,8 @@ public class GameNativeActivity extends NativeActivity
             if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || 
                 ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
                 _gamepadDevices.put(deviceId, device);
-                Log.i(TAG, "gamepadEventConnectedImpl: " + device.toString());
-                gamepadEventConnectedImpl(deviceId, 26, 2, 2, 0, 0, "", device.getName());
+                
+                onGamepadConnected(deviceId, device.getName());
             }
         }
         return device;

+ 1 - 4
samples/browser/src/GamepadSample.cpp

@@ -30,10 +30,7 @@ void GamepadSample::finalize()
 void GamepadSample::updateGamepad(float elapsedTime, Gamepad* gamepad, unsigned int player)
 {
     char s[128];
-    sprintf(s, "Player: %d - VendorID: %d, %s, Product ID: %d, %s\nButtons: ",
-                player,
-                gamepad->getVendorId(), gamepad->getVendorString(),
-                gamepad->getProductId(), gamepad->getProductString());
+    sprintf(s, "Player: %d - %s\nButtons: ",player, gamepad->getProductString());
     _status += s;
     for (int j = 0; j < 20; ++j)
     {