OpenXR - Resuming renderer fixed, haptics support added

This commit is contained in:
Lubos 2022-08-16 16:47:31 +02:00
parent 382df469c1
commit 92d631966f
5 changed files with 25 additions and 11 deletions

View file

@ -59,18 +59,18 @@ XrTime ToXrTime(const double timeInSeconds) {
return (timeInSeconds * 1e9);
}
void VR_Vibrate( int duration, int chan, float intensity ) {
void INVR_Vibrate( int duration, int chan, float intensity ) {
for (int i = 0; i < 2; ++i) {
int channel = (i + 1) & chan;
int channel = i & chan;
if (channel) {
if (vibration_channel_duration[channel-1] > 0.0f)
if (vibration_channel_duration[channel] > 0.0f)
return;
if (vibration_channel_duration[channel-1] == -1.0f && duration != 0.0f)
if (vibration_channel_duration[channel] == -1.0f && duration != 0.0f)
return;
vibration_channel_duration[channel-1] = duration;
vibration_channel_intensity[channel-1] = intensity;
vibration_channel_duration[channel] = duration;
vibration_channel_intensity[channel] = intensity;
}
}
}

View file

@ -32,3 +32,4 @@ void IN_VRInit( engine_t *engine );
void IN_VRInputFrame( engine_t* engine );
uint32_t IN_VRGetButtonState( int controllerIndex );
XrVector2f IN_VRGetJoystickState( int controllerIndex );
void INVR_Vibrate( int duration, int chan, float intensity );

View file

@ -177,6 +177,10 @@ void VR_Recenter(engine_t* engine) {
}
void VR_InitRenderer( engine_t* engine ) {
if (initialized) {
VR_DestroyRenderer(engine);
}
int eyeW, eyeH;
VR_GetResolution(engine, &eyeW, &eyeH);

View file

@ -721,6 +721,8 @@ void GameSettingsScreen::CreateViews() {
customizeTilt->SetEnabledFunc([] {
return g_Config.iTiltInputType != 0;
});
} else if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_VR) {
controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, co->T("HapticFeedback", "Haptic Feedback (vibration)")));
}
// TVs don't have touch control, at least not yet.

View file

@ -934,6 +934,15 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {
// JavaEGL
extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env, jobject obj) {
#ifdef OPENXR
if (!renderer_inited) {
VR_EnterVR(VR_GetEngine());
IN_VRInit(VR_GetEngine());
}
VR_InitRenderer(VR_GetEngine());
#endif
// We should be running on the render thread here.
std::string errorMessage;
if (renderer_inited) {
@ -990,11 +999,6 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
}, nullptr);
graphicsContext->ThreadStart();
#ifdef OPENXR
VR_EnterVR(VR_GetEngine());
VR_InitRenderer(VR_GetEngine());
IN_VRInit(VR_GetEngine());
#endif
renderer_inited = true;
}
NativeMessageReceived("recreateviews", "");
@ -1131,6 +1135,9 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
keyInput.deviceId = controllerIds[j];
if (m.pressed != pressed) {
if (pressed && g_Config.bHapticFeedback) {
INVR_Vibrate(100, j, 1000);
}
NativeKey(keyInput);
m.pressed = pressed;
m.repeat = 0;