From 3cc979859c57d95986c8f6b84ff223eea0d72c02 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 10 Dec 2022 21:31:39 +0100 Subject: [PATCH] OpenXR - Release keys on activation of camera adjust --- Common/VR/PPSSPPVR.cpp | 30 ++++++++++++++++++++++++++++-- Common/VR/PPSSPPVR.h | 4 ++-- android/jni/app-android.cpp | 3 ++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 98e2ee7ec0..a6a7d0c0e3 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -46,6 +46,10 @@ static bool vrFlatGame = false; static float vrMatrix[VR_MATRIX_COUNT][16]; static bool vrMirroring[VR_MIRRORING_COUNT]; +static bool(*NativeAxis)(const AxisInput &axis); +static bool(*NativeKey)(const KeyInput &key); +static bool(*NativeTouch)(const TouchInput &touch); + /* ================================================================================ @@ -185,6 +189,12 @@ void GetVRResolutionPerEye(int* width, int* height) { } } +void SetVRCallbacks(bool(*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), bool(*touch)(const TouchInput &touch)) { + NativeAxis = axis; + NativeKey = key; + NativeTouch = touch; +} + /* ================================================================================ @@ -197,8 +207,7 @@ void SetVRAppMode(VRAppMode mode) { appMode = mode; } -void UpdateVRInput(bool(*NativeAxis)(const AxisInput &axis), bool(*NativeKey)(const KeyInput &key), - bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale) { +void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) { //axis if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) { AxisInput axis = {}; @@ -405,6 +414,7 @@ bool UpdateVRAxis(const AxisInput &axis) { bool UpdateVRKeys(const KeyInput &key) { //store key value std::vector nativeKeys; + bool wasCameraAdjustOn = pspKeys[VIRTKEY_VR_CAMERA_ADJUST]; if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) { for (int& nativeKey : nativeKeys) { pspKeys[nativeKey] = key.flags & KEY_DOWN; @@ -425,6 +435,22 @@ bool UpdateVRKeys(const KeyInput &key) { } } + // Release keys on enabling camera adjust + if (!wasCameraAdjustOn && pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) { + KeyInput keyUp; + keyUp.deviceId = key.deviceId; + keyUp.flags = KEY_UP; + + pspKeys[VIRTKEY_VR_CAMERA_ADJUST] = false; + for (auto& pspKey : pspKeys) { + if (pspKey.second) { + keyUp.keyCode = pspKey.first; + NativeKey(keyUp); + } + } + pspKeys[VIRTKEY_VR_CAMERA_ADJUST] = true; + } + // Reset camera adjust if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST] && pspKeys[VIRTKEY_VR_CAMERA_RESET]) { g_Config.fCameraHeight = 0; diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index dec2daaffa..009726a948 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -29,11 +29,11 @@ bool IsVREnabled(); void InitVROnAndroid(void* vm, void* activity, const char* system, int version, const char* name); void EnterVR(bool firstStart, void* vulkanContext); void GetVRResolutionPerEye(int* width, int* height); +void SetVRCallbacks(bool(*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), bool(*touch)(const TouchInput &touch)); // VR input integration void SetVRAppMode(VRAppMode mode); -void UpdateVRInput(bool(*NativeAxis)(const AxisInput &axis), bool(*NativeKey)(const KeyInput &key), - bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); +void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale); bool UpdateVRAxis(const AxisInput &axis); bool UpdateVRKeys(const KeyInput &key); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index b144bc8dcd..ee0cf4c198 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -770,6 +770,7 @@ retry: if (IsVREnabled()) { Version gitVer(PPSSPP_GIT_VERSION); InitVROnAndroid(gJvm, nativeActivity, systemName.c_str(), gitVer.ToInteger(), "PPSSPP"); + SetVRCallbacks(NativeAxis, NativeKey, NativeTouch); } } @@ -1079,7 +1080,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env, } if (IsVREnabled()) { - UpdateVRInput(NativeAxis, NativeKey, NativeTouch, g_Config.bHapticFeedback, dp_xscale, dp_yscale); + UpdateVRInput(g_Config.bHapticFeedback, dp_xscale, dp_yscale); FinishVRRender(); } }