Advertisement
naf456

Gameplay3DHelper : Java (090913)

Sep 9th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package org.community.combat.engine;
  2. import tv.ouya.console.api.OuyaController;
  3. import android.content.Context;
  4. import android.hardware.input.InputManager;
  5. import android.util.Log;
  6.  
  7. public class Gameplay3DHelper {
  8.  
  9.     static
  10.     {
  11.         System.loadLibrary("gameplay");
  12.     }
  13.    
  14.     private native void registerGamepad(int deviceId, int controllerNumber);
  15.     private native void unregisterGamepad(int deviceId, int controllerNumber);
  16.    
  17.     public void setupControllerAgent(Context context)
  18.     {  
  19.         Log.d("GAMEPLAY3D", "We're Inside the Java Bean!");
  20.         /*
  21.          * Controllers have to be "Connected" to gameplay.
  22.          * This is done through the Gamepad.add() function,
  23.          * to call this function, we must first know what controller's
  24.          * are connected to the console. This is where this next for block comes
  25.          * in handy.
  26.          * We also set up a listener to add any new controllers to are engine too.
  27.          */
  28.        
  29.         for(int i = 1; i < OuyaController.MAX_CONTROLLERS ; i++)
  30.         {
  31.             OuyaController controller = OuyaController.getControllerByPlayer(i);
  32.            
  33.             if(controller != null)
  34.             {
  35.                 registerGamepad(controller.getDeviceId(), i);
  36.             }
  37.         }
  38.        
  39.        
  40.         //Now lets register that handler and it's functionality.
  41.         InputManager inputMan = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
  42.        
  43.         inputMan.registerInputDeviceListener(new InputManager.InputDeviceListener()
  44.         {
  45.             @Override
  46.             public void onInputDeviceRemoved(int deviceId) {
  47.                
  48.                 int controllerNumber = OuyaController.getPlayerNumByDeviceId(deviceId);
  49.                
  50.                 if(controllerNumber != -1)
  51.                 {
  52.                     //Is Controller! lets tell ENGINE3D!
  53.                     unregisterGamepad(deviceId , controllerNumber);
  54.                 }
  55.                 else if(controllerNumber == -1)
  56.                 {
  57.                     Log.v("GAMEPLAY3D", "Old, Non Controller disconnected!");
  58.                 }
  59.                
  60.             }
  61.            
  62.             @Override
  63.             public void onInputDeviceChanged(int deviceId) {
  64.                 // Don't really do anything really...
  65.             }
  66.            
  67.             @Override
  68.             public void onInputDeviceAdded(int deviceId) {
  69.                
  70.                 int controllerNumber = OuyaController.getPlayerNumByDeviceId(deviceId);
  71.                
  72.                 if(controllerNumber > 0)
  73.                 {
  74.                     //Controller OK! lets tell ENGINE3D!
  75.                     registerGamepad(deviceId , controllerNumber);
  76.                 }
  77.                 else
  78.                 {
  79.                     Log.v("GAMEPLAY3D", "New, Non OUYA Controller Connected!");
  80.                 }
  81.             }
  82.         },null);
  83.     }
  84.    
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement