Skip to content

Commit

Permalink
Try fixing lag state on recentering on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
zarik5 committed Nov 8, 2023
1 parent 63c668e commit 92e4791
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
20 changes: 5 additions & 15 deletions alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ using namespace alvr_chaperone;

std::mutex chaperone_mutex;

void InitChaperoneClient() {
void InitOpenvrClient() {
#ifndef __APPLE__
std::unique_lock<std::mutex> 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 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<std::mutex> lock(chaperone_mutex);

vr::VR_Shutdown();
#endif
}

void SetChaperoneArea(float areaWidth, float areaHeight) {
void _SetChaperoneArea(float areaWidth, float areaHeight) {
#ifndef __APPLE__
std::unique_lock<std::mutex> lock(chaperone_mutex);

Expand Down Expand Up @@ -69,16 +69,6 @@ void SetChaperoneArea(float areaWidth, float areaHeight) {

#ifdef __linux__
vr::HmdMatrix34_t GetRawZeroPose() {
vr::HmdMatrix34_t out = {};
std::unique_lock<std::mutex> 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
14 changes: 14 additions & 0 deletions alvr/server/cpp/alvr_server/alvr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <map>
#include <optional>

void _SetChaperoneArea(float areaWidth, float areaHeight);
#ifdef __linux__
vr::HmdMatrix34_t GetRawZeroPose();
#endif
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions alvr/server/cpp/alvr_server/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> 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() {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {

disconnection_deadline = Instant::now() + KEEPALIVE_TIMEOUT;
}
unsafe { crate::ShutdownChaperoneClient() };
unsafe { crate::ShutdownOpenvrClient() };

SERVER_DATA_MANAGER.write().update_client_list(
client_hostname,
Expand Down
4 changes: 2 additions & 2 deletions alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 92e4791

Please sign in to comment.