OpenXR do not call stop haptics every frame

This commit is contained in:
Lubos 2022-05-10 19:34:18 +02:00
parent 437e3829aa
commit 244b8344ff

View file

@ -228,6 +228,7 @@ void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out) {
//0 = left, 1 = right //0 = left, 1 = right
float vibration_channel_duration[2] = {0.0f, 0.0f}; float vibration_channel_duration[2] = {0.0f, 0.0f};
float vibration_channel_intensity[2] = {0.0f, 0.0f}; float vibration_channel_intensity[2] = {0.0f, 0.0f};
qboolean vibration_stopped[2] = {qtrue, qtrue};
void VR_Vibrate( int duration, int chan, float intensity ) void VR_Vibrate( int duration, int chan, float intensity )
{ {
@ -271,6 +272,7 @@ static void VR_processHaptics() {
hapticActionInfo.next = NULL; hapticActionInfo.next = NULL;
hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback; hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback;
OXR(xrApplyHapticFeedback(VR_GetEngine()->appState.Session, &hapticActionInfo, (const XrHapticBaseHeader*)&vibration)); OXR(xrApplyHapticFeedback(VR_GetEngine()->appState.Session, &hapticActionInfo, (const XrHapticBaseHeader*)&vibration));
vibration_stopped[i] = qfalse;
if (vibration_channel_duration[i] != -1.0f) { if (vibration_channel_duration[i] != -1.0f) {
vibration_channel_duration[i] -= frametime; vibration_channel_duration[i] -= frametime;
@ -280,13 +282,14 @@ static void VR_processHaptics() {
vibration_channel_intensity[i] = 0.0f; vibration_channel_intensity[i] = 0.0f;
} }
} }
} else { } else if (!vibration_stopped[i]) {
// Stop haptics // Stop haptics
XrHapticActionInfo hapticActionInfo = {}; XrHapticActionInfo hapticActionInfo = {};
hapticActionInfo.type = XR_TYPE_HAPTIC_ACTION_INFO; hapticActionInfo.type = XR_TYPE_HAPTIC_ACTION_INFO;
hapticActionInfo.next = NULL; hapticActionInfo.next = NULL;
hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback; hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback;
OXR(xrStopHapticFeedback(VR_GetEngine()->appState.Session, &hapticActionInfo)); OXR(xrStopHapticFeedback(VR_GetEngine()->appState.Session, &hapticActionInfo));
vibration_stopped[i] = qtrue;
} }
} }
} }