Skip to content

Commit

Permalink
Feat[gamepad_direct]: remove unnecessary strings, improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Dec 28, 2024
1 parent f0005fa commit 13d0f97
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ public void handleGamepadInput(int keycode, float value) {
break;
}
}

/**
* Stops the Gamepad and removes all traces of the Gamepad from the view hierarchy.
* After this call, the Gamepad is not recoverable and a new one must be made.
*/
public void removeSelf() {
mRemoved = true;
mMapProvider.detachGrabListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;

import static android.view.MotionEvent.AXIS_HAT_X;
import static android.view.MotionEvent.AXIS_HAT_Y;
import static org.lwjgl.glfw.CallbackBridge.sGamepadAxisBuffer;
import static org.lwjgl.glfw.CallbackBridge.sGamepadButtonBuffer;

import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;

Expand Down Expand Up @@ -38,12 +35,19 @@ public void handleGamepadInput(int keycode, float value) {
case KeyEvent.KEYCODE_DPAD_DOWN: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN; break;
case KeyEvent.KEYCODE_DPAD_LEFT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT; break;
case KeyEvent.KEYCODE_DPAD_RIGHT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT; break;
case KeyEvent.KEYCODE_DPAD_CENTER: break; // TODO
case KeyEvent.KEYCODE_DPAD_CENTER:
// Behave the same way as the Gamepad here, as GLFW doesn't have a keycode
// for the dpad center.
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, GamepadKeycodes.GLFW_RELEASE);
return;
case MotionEvent.AXIS_X: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_X; break;
case MotionEvent.AXIS_Y: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_Y; break;
case MotionEvent.AXIS_Z: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_X; break;
case MotionEvent.AXIS_RZ: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_Y; break;
case AXIS_HAT_X:
case MotionEvent.AXIS_HAT_X:
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT,
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
Expand All @@ -53,7 +57,7 @@ public void handleGamepadInput(int keycode, float value) {
value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
);
return;
case AXIS_HAT_Y:
case MotionEvent.AXIS_HAT_Y:
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP,
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;

/**
* Interface that is called once when the GLFW implementation requests to switch from
* the default gamepad implementation to the direct one. The implementor of this interface
* must take the necessary steps to disable the default gamepad implementation and replace
* it with an instance of DirectGamepad.
* This is useful for switching from default to direct input after the user has already
* interacted with the gamepad.
*/
public interface DirectGamepadEnableHandler {
/**
* Called once when GLFW requests switching the gamepad mode from default to direct.
*/
void onDirectGamepadEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class GamepadKeycodes {
public static final byte GLFW_RELEASE = 0;
public static final byte GLFW_PRESS = 1;
public static int NUM_KEYCODES = 0;

public static final short GLFW_GAMEPAD_BUTTON_A = 0;
public static final short GLFW_GAMEPAD_BUTTON_B = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class CallbackBridge {
public static final Choreographer sChoreographer = Choreographer.getInstance();
private static boolean isGrabbing = false;
private static final ArrayList<GrabListener> grabListeners = new ArrayList<>();
private static WeakReference<DirectGamepadEnableHandler> sDirectGamepadEnableHandler;
// Use a weak reference here to avoid possibly statically referencing a Context.
private static @Nullable WeakReference<DirectGamepadEnableHandler> sDirectGamepadEnableHandler;

public static final int CLIPBOARD_COPY = 2000;
public static final int CLIPBOARD_PASTE = 2001;
Expand Down
2 changes: 0 additions & 2 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,4 @@
<string name="local_login_bad_username_title">Unsuitable username</string>
<string name="local_login_bad_username_text">The username must be between 3–16 characters long, and must only contain latin letters, arabic numerals and underscores.</string>
<string name="quick_setting_title">Quick settings</string>
<string name="preference_direct_controller_title">Use direct controller input</string>
<string name="preference_direct_controller_description">Disables keyboard/mouse emulation and lets the game use gamepad inputs directly.</string>
</resources>

0 comments on commit 13d0f97

Please sign in to comment.