Skip to content

Commit

Permalink
OpenXR: Use got_first_valid_poses instead
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 12, 2023
1 parent b95c99a commit e972951
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
12 changes: 1 addition & 11 deletions src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ void VR::update_hmd_state(bool from_view_extensions, uint32_t frame_count) {
// Update the poses used for the game
// If we used the data directly from the WaitGetPoses call, we would have to lock a different mutex and wait a long time
// This is because the WaitGetPoses call is blocking, and we don't want to block any game logic
if (runtime->wants_reset_origin && runtime->ready() && runtime->got_first_poses) {
if (runtime->wants_reset_origin && runtime->ready() && runtime->got_first_valid_poses) {
std::unique_lock _{ runtime->pose_mtx };
set_rotation_offset(glm::identity<glm::quat>());
m_standing_origin = get_position_unsafe(vr::k_unTrackedDeviceIndex_Hmd);
Expand All @@ -1275,16 +1275,6 @@ void VR::update_hmd_state(bool from_view_extensions, uint32_t frame_count) {

runtime->update_matrices(m_nearz, m_farz);

// On first run, set the standing origin to the headset position
/*if (!runtime->got_first_poses) {
m_standing_origin = get_position(vr::k_unTrackedDeviceIndex_Hmd);
}*/

if (!runtime->got_first_poses && runtime->is_openvr()) {
//std::unique_lock _{m_openvr->pose_mtx};
//m_openvr->pose_queue.clear();
}

runtime->got_first_poses = true;
}

Expand Down
1 change: 1 addition & 0 deletions src/mods/vr/runtimes/OpenVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VRRuntime::Error OpenVR::synchronize_frame(std::optional<uint32_t> frame_count)
auto ret = vr::VRCompositor()->WaitGetPoses(this->real_render_poses.data(), vr::k_unMaxTrackedDeviceCount, this->real_game_poses.data(), vr::k_unMaxTrackedDeviceCount);

if (ret == vr::VRCompositorError_None) {
this->got_first_valid_poses = true;
this->got_first_sync = true;
this->frame_synced = true;
}
Expand Down
5 changes: 3 additions & 2 deletions src/mods/vr/runtimes/OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ VRRuntime::Error OpenXR::update_poses(bool from_view_extensions, uint32_t frame_
this->grip_matrices[i][3] = Vector4f{*(Vector3f*)&hand.grip_location.pose.position, 1.0f};
}

if (!this->got_first_poses) {
this->got_first_poses = (this->view_space_location.locationFlags & (XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)) != 0;
if (!this->got_first_valid_poses) {
this->got_first_valid_poses = (this->view_space_location.locationFlags & (XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)) != 0;
}

this->got_first_poses = true;
this->needs_pose_update = false;
return VRRuntime::Error::SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions src/mods/vr/runtimes/VRRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct VRRuntime {
// will return VRCompositorError_DoNotHaveFocus
bool needs_pose_update{true};
bool got_first_poses{false};
bool got_first_valid_poses{false};
bool got_first_sync{false};
bool frame_synced{false};
bool handle_pause{false};
Expand Down

0 comments on commit e972951

Please sign in to comment.