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;