OpenXR - Release keys on activation of camera adjust

This commit is contained in:
Lubos 2022-12-10 21:31:39 +01:00
parent abd60a30bc
commit 3cc979859c
3 changed files with 32 additions and 5 deletions

View file

@ -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<int> 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;

View file

@ -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);

View file

@ -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();
}
}