diff --git a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp index bab074a49f..336db76b9e 100644 --- a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp +++ b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp @@ -13,7 +13,7 @@ using namespace alvr_chaperone; std::mutex chaperone_mutex; -void InitChaperoneClient() { +void InitOpenvrClient() { #ifndef __APPLE__ std::unique_lock lock(chaperone_mutex); @@ -21,13 +21,13 @@ void InitChaperoneClient() { vr::VR_Init(&error, vr::VRApplication_Utility); if (error != vr::VRInitError_None) { - Warn("Failed to init OpenVR client to update Chaperone boundary! Error: %d", error); + Warn("Failed to init OpenVR client! Error: %d", error); return; } #endif } -void ShutdownChaperoneClient() { +void ShutdownOpenvrClient() { #ifndef __APPLE__ std::unique_lock lock(chaperone_mutex); @@ -35,7 +35,7 @@ void ShutdownChaperoneClient() { #endif } -void SetChaperoneArea(float areaWidth, float areaHeight) { +void _SetChaperoneArea(float areaWidth, float areaHeight) { #ifndef __APPLE__ std::unique_lock lock(chaperone_mutex); @@ -69,16 +69,6 @@ void SetChaperoneArea(float areaWidth, float areaHeight) { #ifdef __linux__ vr::HmdMatrix34_t GetRawZeroPose() { - vr::HmdMatrix34_t out = {}; - std::unique_lock lock(chaperone_mutex); - vr::EVRInitError error; - vr::VR_Init(&error, vr::VRApplication_Utility); - if (error != vr::VRInitError_None) { - Warn("Failed to init OpenVR client to get raw zero pose! Error: %d", error); - return out; - } - out = vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose(); - vr::VR_Shutdown(); - return out; + return vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose(); } #endif \ No newline at end of file diff --git a/alvr/server/cpp/alvr_server/alvr_server.cpp b/alvr/server/cpp/alvr_server/alvr_server.cpp index 6083ae3a5c..30bd13c120 100644 --- a/alvr/server/cpp/alvr_server/alvr_server.cpp +++ b/alvr/server/cpp/alvr_server/alvr_server.cpp @@ -22,6 +22,7 @@ #include #include +void _SetChaperoneArea(float areaWidth, float areaHeight); #ifdef __linux__ vr::HmdMatrix34_t GetRawZeroPose(); #endif @@ -140,8 +141,10 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider { #ifdef __linux__ else if (event.eventType == vr::VREvent_ChaperoneUniverseHasChanged) { if (hmd && hmd->m_poseHistory) { + InitOpenvrClient(); hmd->m_poseHistory->SetTransformUpdating(); hmd->m_poseHistory->SetTransform(GetRawZeroPose()); + ShutdownOpenvrClient(); } } #endif @@ -320,6 +323,17 @@ void SetButton(unsigned long long buttonID, FfiButtonValue value) { } } +void SetChaperoneArea(float areaWidth, float areaHeight) { + _SetChaperoneArea(areaWidth, areaHeight); + +#ifdef __linux__ + if (g_driver_provider.hmd && g_driver_provider.hmd->m_poseHistory) { + g_driver_provider.hmd->m_poseHistory->SetTransformUpdating(); + g_driver_provider.hmd->m_poseHistory->SetTransform(GetRawZeroPose()); + } +#endif +} + void CaptureFrame() { #ifndef __APPLE__ if (g_driver_provider.hmd && g_driver_provider.hmd->m_encoder) { diff --git a/alvr/server/cpp/alvr_server/bindings.h b/alvr/server/cpp/alvr_server/bindings.h index 69a67b6315..e79c000f84 100644 --- a/alvr/server/cpp/alvr_server/bindings.h +++ b/alvr/server/cpp/alvr_server/bindings.h @@ -146,8 +146,8 @@ extern "C" void SetViewsConfig(FfiViewsConfig config); extern "C" void SetBattery(unsigned long long deviceID, float gauge_value, bool is_plugged); extern "C" void SetButton(unsigned long long buttonID, FfiButtonValue value); -extern "C" void InitChaperoneClient(); -extern "C" void ShutdownChaperoneClient(); +extern "C" void InitOpenvrClient(); +extern "C" void ShutdownOpenvrClient(); extern "C" void SetChaperoneArea(float areaWidth, float areaHeight); extern "C" void CaptureFrame(); diff --git a/alvr/server/src/connection.rs b/alvr/server/src/connection.rs index ae7744c4e5..e758f53e03 100644 --- a/alvr/server/src/connection.rs +++ b/alvr/server/src/connection.rs @@ -925,7 +925,7 @@ fn try_connect(mut client_ips: HashMap) -> ConResult { let control_sender = Arc::clone(&control_sender); let client_hostname = client_hostname.clone(); move || { - unsafe { crate::InitChaperoneClient() }; + unsafe { crate::InitOpenvrClient() }; let mut disconnection_deadline = Instant::now() + KEEPALIVE_TIMEOUT; while IS_STREAMING.value() { @@ -1061,7 +1061,7 @@ fn try_connect(mut client_ips: HashMap) -> ConResult { disconnection_deadline = Instant::now() + KEEPALIVE_TIMEOUT; } - unsafe { crate::ShutdownChaperoneClient() }; + unsafe { crate::ShutdownOpenvrClient() }; SERVER_DATA_MANAGER.write().update_client_list( client_hostname, diff --git a/alvr/server/src/lib.rs b/alvr/server/src/lib.rs index e6686b2153..94c8c533cf 100644 --- a/alvr/server/src/lib.rs +++ b/alvr/server/src/lib.rs @@ -359,9 +359,9 @@ pub unsafe extern "C" fn HmdDriverFactory( // call this when inside a new thread. Calling this on the parent thread will crash // SteamVR unsafe { - InitChaperoneClient(); + InitOpenvrClient(); SetChaperoneArea(2.0, 2.0); - ShutdownChaperoneClient(); + ShutdownOpenvrClient(); } }