Skip to content

Commit 9644be2

Browse files
committed
Try fixing lag state on recentering on Linux
1 parent 63c668e commit 9644be2

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ using namespace alvr_chaperone;
1313

1414
std::mutex chaperone_mutex;
1515

16-
void InitChaperoneClient() {
16+
void InitOpenvrClient() {
1717
#ifndef __APPLE__
1818
std::unique_lock<std::mutex> lock(chaperone_mutex);
1919

2020
vr::EVRInitError error;
2121
vr::VR_Init(&error, vr::VRApplication_Utility);
2222

2323
if (error != vr::VRInitError_None) {
24-
Warn("Failed to init OpenVR client to update Chaperone boundary! Error: %d", error);
24+
Warn("Failed to init OpenVR client! Error: %d", error);
2525
return;
2626
}
2727
#endif
2828
}
2929

30-
void ShutdownChaperoneClient() {
30+
void ShutdownOpenvrClient() {
3131
#ifndef __APPLE__
3232
std::unique_lock<std::mutex> lock(chaperone_mutex);
3333

3434
vr::VR_Shutdown();
3535
#endif
3636
}
3737

38-
void SetChaperoneArea(float areaWidth, float areaHeight) {
38+
void _SetChaperoneArea(float areaWidth, float areaHeight) {
3939
#ifndef __APPLE__
4040
std::unique_lock<std::mutex> lock(chaperone_mutex);
4141

@@ -69,16 +69,6 @@ void SetChaperoneArea(float areaWidth, float areaHeight) {
6969

7070
#ifdef __linux__
7171
vr::HmdMatrix34_t GetRawZeroPose() {
72-
vr::HmdMatrix34_t out = {};
73-
std::unique_lock<std::mutex> lock(chaperone_mutex);
74-
vr::EVRInitError error;
75-
vr::VR_Init(&error, vr::VRApplication_Utility);
76-
if (error != vr::VRInitError_None) {
77-
Warn("Failed to init OpenVR client to get raw zero pose! Error: %d", error);
78-
return out;
79-
}
80-
out = vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose();
81-
vr::VR_Shutdown();
82-
return out;
72+
return vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose();
8373
}
8474
#endif

alvr/server/cpp/alvr_server/alvr_server.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <map>
2323
#include <optional>
2424

25+
void _SetChaperoneArea(float areaWidth, float areaHeight);
2526
#ifdef __linux__
2627
vr::HmdMatrix34_t GetRawZeroPose();
2728
#endif
@@ -140,8 +141,10 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider {
140141
#ifdef __linux__
141142
else if (event.eventType == vr::VREvent_ChaperoneUniverseHasChanged) {
142143
if (hmd && hmd->m_poseHistory) {
144+
InitOpenvrClient();
143145
hmd->m_poseHistory->SetTransformUpdating();
144146
hmd->m_poseHistory->SetTransform(GetRawZeroPose());
147+
ShutdownOpenvrClient();
145148
}
146149
}
147150
#endif
@@ -320,6 +323,19 @@ void SetButton(unsigned long long buttonID, FfiButtonValue value) {
320323
}
321324
}
322325

326+
void SetChaperoneArea(float areaWidth, float areaHeight) {
327+
_SetChaperoneArea(areaWidth, areaHeight);
328+
329+
#ifdef __linux__
330+
auto pose = vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose();
331+
if (g_driver_provider.hmd && g_driver_provider.hmd->m_poseHistory) {
332+
g_driver_provider.hmd->m_poseHistory->SetTransformUpdating();
333+
g_driver_provider.hmd->m_poseHistory->SetTransform(pose);
334+
}
335+
#endif
336+
337+
}
338+
323339
void CaptureFrame() {
324340
#ifndef __APPLE__
325341
if (g_driver_provider.hmd && g_driver_provider.hmd->m_encoder) {

alvr/server/cpp/alvr_server/bindings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ extern "C" void SetViewsConfig(FfiViewsConfig config);
146146
extern "C" void SetBattery(unsigned long long deviceID, float gauge_value, bool is_plugged);
147147
extern "C" void SetButton(unsigned long long buttonID, FfiButtonValue value);
148148

149-
extern "C" void InitChaperoneClient();
150-
extern "C" void ShutdownChaperoneClient();
149+
extern "C" void InitOpenvrClient();
150+
extern "C" void ShutdownOpenvrClient();
151151
extern "C" void SetChaperoneArea(float areaWidth, float areaHeight);
152152

153153
extern "C" void CaptureFrame();

alvr/server/src/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
925925
let control_sender = Arc::clone(&control_sender);
926926
let client_hostname = client_hostname.clone();
927927
move || {
928-
unsafe { crate::InitChaperoneClient() };
928+
unsafe { crate::InitOpenvrClient() };
929929

930930
let mut disconnection_deadline = Instant::now() + KEEPALIVE_TIMEOUT;
931931
while IS_STREAMING.value() {
@@ -1061,7 +1061,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
10611061

10621062
disconnection_deadline = Instant::now() + KEEPALIVE_TIMEOUT;
10631063
}
1064-
unsafe { crate::ShutdownChaperoneClient() };
1064+
unsafe { crate::ShutdownOpenvrClient() };
10651065

10661066
SERVER_DATA_MANAGER.write().update_client_list(
10671067
client_hostname,

alvr/server/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ pub unsafe extern "C" fn HmdDriverFactory(
359359
// call this when inside a new thread. Calling this on the parent thread will crash
360360
// SteamVR
361361
unsafe {
362-
InitChaperoneClient();
362+
InitOpenvrClient();
363363
SetChaperoneArea(2.0, 2.0);
364-
ShutdownChaperoneClient();
364+
ShutdownOpenvrClient();
365365
}
366366
}
367367

0 commit comments

Comments
 (0)