From bde568c3c5d278ef00acd88daabd44127b5ddace Mon Sep 17 00:00:00 2001 From: german77 Date: Sat, 4 Mar 2023 21:42:26 -0600 Subject: [PATCH] android: Use the center of the object and reduce draw calls --- .../activities/EmulationActivity.java | 4 ++ .../yuzu/yuzu_emu/overlay/InputOverlay.java | 40 +++++++------ .../overlay/InputOverlayDrawableButton.java | 1 + .../overlay/InputOverlayDrawableDpad.java | 6 +- .../overlay/InputOverlayDrawableJoystick.java | 4 +- .../src/main/res/drawable/joystick_range.xml | 18 +++--- .../main/res/layout/fragment_emulation.xml | 2 +- .../app/src/main/res/values/integers.xml | 60 +++++++++---------- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.java index 41103ec5bd..343bc032b8 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.java @@ -12,6 +12,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManager; import android.widget.SeekBar; import android.widget.TextView; @@ -164,6 +165,9 @@ public final class EmulationActivity extends AppCompatActivity { } private void enableFullscreenImmersive() { + getWindow().getAttributes().layoutInDisplayCutoutMode= + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + // It would be nice to use IMMERSIVE_STICKY, but that doesn't show the toolbar. mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java index 76c437cb91..74119c398c 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java @@ -186,7 +186,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, scale = 0.38f; break; default: - scale = 0.40f; + scale = 0.43f; break; } @@ -215,10 +215,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, // Now set the bounds for the InputOverlayDrawableButton. // This will dictate where on the screen (and the what the size) the InputOverlayDrawableButton will be. - overlayDrawable.setBounds(drawableX, drawableY, drawableX + width, drawableY + height); + overlayDrawable.setBounds(drawableX - (width / 2), drawableY - (height / 2), drawableX + (width / 2), drawableY + (height / 2)); // Need to set the image's position - overlayDrawable.setPosition(drawableX, drawableY); + overlayDrawable.setPosition(drawableX - (width / 2), drawableY - (height / 2)); return overlayDrawable; } @@ -278,10 +278,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, // Now set the bounds for the InputOverlayDrawableDpad. // This will dictate where on the screen (and the what the size) the InputOverlayDrawableDpad will be. - overlayDrawable.setBounds(drawableX, drawableY, drawableX + width, drawableY + height); + overlayDrawable.setBounds(drawableX - (width / 2), drawableY - (height / 2), drawableX + (width / 2), drawableY + (height / 2)); // Need to set the image's position - overlayDrawable.setPosition(drawableX, drawableY); + overlayDrawable.setPosition(drawableX - (width / 2), drawableY - (height / 2)); return overlayDrawable; } @@ -306,7 +306,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); // Decide scale based on user preference - float scale = 0.35f; + float scale = 0.40f; scale *= (sPrefs.getInt("controlScale", 50) + 50); scale /= 100; @@ -320,12 +320,12 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, int drawableX = (int) sPrefs.getFloat(button + orientation + "-X", 0f); int drawableY = (int) sPrefs.getFloat(button + orientation + "-Y", 0f); - float outerScale = 1.3f; + float outerScale = 1.66f; // Now set the bounds for the InputOverlayDrawableJoystick. // This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be. int outerSize = bitmapOuter.getWidth(); - Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize); + Rect outerRect = new Rect(drawableX - (outerSize / 2), drawableY - (outerSize / 2), drawableX + (outerSize / 2), drawableY + (outerSize / 2)); Rect innerRect = new Rect(0, 0, (int) (outerSize / outerScale), (int) (outerSize / outerScale)); // Send the drawableId to the joystick so it can be referenced when saving control position. @@ -362,12 +362,13 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, if (isInEditMode()) { return onTouchWhileEditing(event); } - + boolean should_update_view = false; for (InputOverlayDrawableButton button : overlayButtons) { if (!button.updateStatus(event)) { continue; } NativeLibrary.onGamePadButtonEvent(NativeLibrary.Player1Device, button.getId(), button.getStatus()); + should_update_view = true; } for (InputOverlayDrawableDpad dpad : overlayDpads) { @@ -378,6 +379,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, NativeLibrary.onGamePadButtonEvent(NativeLibrary.Player1Device, dpad.getDownId(), dpad.getDownStatus()); NativeLibrary.onGamePadButtonEvent(NativeLibrary.Player1Device, dpad.getLeftId(), dpad.getLeftStatus()); NativeLibrary.onGamePadButtonEvent(NativeLibrary.Player1Device, dpad.getRightId(), dpad.getRightStatus()); + should_update_view = true; } for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { @@ -387,6 +389,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, int axisID = joystick.getJoystickId(); NativeLibrary.onGamePadJoystickEvent(NativeLibrary.Player1Device, axisID, joystick.getXAxis(), joystick.getYAxis()); NativeLibrary.onGamePadButtonEvent(NativeLibrary.Player1Device, joystick.getButtonId(), joystick.getButtonStatus()); + should_update_view = true; + } + + if (should_update_view) { + invalidate(); } if (!mPreferences.getBoolean("isTouchEnabled", true)) { @@ -420,8 +427,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, NativeLibrary.onTouchReleased(pointerId); } - invalidate(); - return true; } @@ -536,11 +541,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.joystick_range, R.drawable.joystick, R.drawable.joystick_depressed, StickType.STICK_R, ButtonType.STICK_R, orientation)); } - if (mPreferences.getBoolean("buttonToggle13", true)) { + if (mPreferences.getBoolean("buttonToggle13", false)) { overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.facebutton_home, R.drawable.facebutton_home_depressed, ButtonType.BUTTON_HOME, orientation)); } - if (mPreferences.getBoolean("buttonToggle14", true)) { + if (mPreferences.getBoolean("buttonToggle14", false)) { overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.facebutton_screenshot, R.drawable.facebutton_screenshot_depressed, ButtonType.BUTTON_CAPTURE, orientation)); } @@ -580,7 +585,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, if (!mPreferences.getBoolean("OverlayInit", false)) { defaultOverlayLandscape(); } - + resetButtonPlacement(); SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); sPrefsEditor.putBoolean("OverlayInit", true); sPrefsEditor.apply(); @@ -596,7 +601,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, // Get screen size Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); - display.getMetrics(outMetrics); + display.getRealMetrics(outMetrics); float maxX = outMetrics.heightPixels; float maxY = outMetrics.widthPixels; // Height and width changes depending on orientation. Use the larger value for height. @@ -605,6 +610,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, maxX = maxY; maxY = tmp; } + Resources res = getResources(); // Each value is a percent from max X/Y stored as an int. Have to bring that value down @@ -621,8 +627,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener, sPrefsEditor.putFloat(ButtonType.TRIGGER_ZL + "-Y", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_ZL_Y) / 1000) * maxY)); sPrefsEditor.putFloat(ButtonType.TRIGGER_ZR + "-X", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_ZR_X) / 1000) * maxX)); sPrefsEditor.putFloat(ButtonType.TRIGGER_ZR + "-Y", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_ZR_Y) / 1000) * maxY)); - sPrefsEditor.putFloat(ButtonType.DPAD_UP + "-X", (((float) res.getInteger(R.integer.SWITCH_BUTTON_UP_X) / 1000) * maxX)); - sPrefsEditor.putFloat(ButtonType.DPAD_UP + "-Y", (((float) res.getInteger(R.integer.SWITCH_BUTTON_UP_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.DPAD_UP + "-X", (((float) res.getInteger(R.integer.SWITCH_BUTTON_DPAD_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.DPAD_UP + "-Y", (((float) res.getInteger(R.integer.SWITCH_BUTTON_DPAD_Y) / 1000) * maxY)); sPrefsEditor.putFloat(ButtonType.TRIGGER_L + "-X", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_L_X) / 1000) * maxX)); sPrefsEditor.putFloat(ButtonType.TRIGGER_L + "-Y", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_L_Y) / 1000) * maxY)); sPrefsEditor.putFloat(ButtonType.TRIGGER_R + "-X", (((float) res.getInteger(R.integer.SWITCH_TRIGGER_R_X) / 1000) * maxX)); diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableButton.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableButton.java index 15da42f3d6..16a4b96ad0 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableButton.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableButton.java @@ -67,6 +67,7 @@ public final class InputOverlayDrawableButton { int motion_event = event.getAction() & MotionEvent.ACTION_MASK; boolean isActionDown = motion_event == MotionEvent.ACTION_DOWN || motion_event == MotionEvent.ACTION_POINTER_DOWN; boolean isActionUp = motion_event == MotionEvent.ACTION_UP || motion_event == MotionEvent.ACTION_POINTER_UP; + boolean current_state = mPressedState; if (isActionDown) { if (!getBounds().contains(xPosition, yPosition)) { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java index aa3653e098..1d10b1e65e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java @@ -121,12 +121,16 @@ public final class InputOverlayDrawableDpad { maxY -= getBounds().centerY(); final float AxisX = touchX / maxX; final float AxisY = touchY / maxY; + final boolean up_state = mUpButtonState; + final boolean down_state = mDownButtonState; + final boolean left_state = mLeftButtonState; + final boolean right_state = mRightButtonState; mUpButtonState = AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; mDownButtonState = AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; mLeftButtonState = AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; mRightButtonState = AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; - return true; + return up_state != mUpButtonState || down_state != mDownButtonState || left_state != mLeftButtonState || right_state != mRightButtonState; } return false; diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableJoystick.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableJoystick.java index 4a0b9fd86f..f7919e483e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableJoystick.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableJoystick.java @@ -140,6 +140,8 @@ public final class InputOverlayDrawableJoystick { maxY -= getVirtBounds().centerY(); final float AxisX = touchX / maxX; final float AxisY = touchY / maxY; + final float oldXAxis = mXAxis; + final float oldYAxis = mYAxis; // Clamp the circle pad input to a circle final float angle = (float) Math.atan2(AxisY, AxisX); @@ -150,7 +152,7 @@ public final class InputOverlayDrawableJoystick { mXAxis = ((float) Math.cos(angle) * radius); mYAxis = ((float) Math.sin(angle) * radius); SetInnerBounds(); - return true; + return oldXAxis != mXAxis && oldYAxis != mYAxis; } return false; diff --git a/src/android/app/src/main/res/drawable/joystick_range.xml b/src/android/app/src/main/res/drawable/joystick_range.xml index cdd5d2e502..f6282b5c84 100644 --- a/src/android/app/src/main/res/drawable/joystick_range.xml +++ b/src/android/app/src/main/res/drawable/joystick_range.xml @@ -20,17 +20,17 @@ + android:pathData="m18.72,64.82a132.8,132.8 0,1 0,182.06 -46.1,132.8 132.8,0 0,0 -182.06,46.1zM229.98,190.7a113.12,113.12 0,1 1,-39.28 -155.08,113.12 113.12,0 0,1 39.28,155.08z" android:strokeAlpha="0.6"> - + - - - - - - + + + + + + diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xml index 828c5efc4e..729a986dbf 100644 --- a/src/android/app/src/main/res/layout/fragment_emulation.xml +++ b/src/android/app/src/main/res/layout/fragment_emulation.xml @@ -23,7 +23,7 @@ 1 - 930 - 610 - 870 - 720 - 870 - 500 - 810 - 610 - 170 - 740 - 715 - 740 - 13 - 125 - 895 - 125 - 13 - 0 - 895 - 0 - 440 - 850 - 520 - 850 - 600 - 890 - 360 - 890 - 35 - 480 + 760 + 810 + 710 + 920 + 710 + 700 + 660 + 810 + 100 + 670 + 900 + 670 + 70 + 220 + 930 + 220 + 70 + 90 + 930 + 90 + 460 + 955 + 540 + 955 + 620 + 960 + 380 + 960 + 260 + 810