@@ -218,7 +218,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
info.hand_tracking = config.check_feature(feature::hand_tracking);
|
||||
info.eye_gaze = config.check_feature(feature::eye_gaze);
|
||||
info.presence = self->instance.has_extension(XR_EXT_USER_PRESENCE_EXTENSION_NAME) && self->system.user_presence_properties().supportsUserPresence;
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
@@ -1289,6 +1288,11 @@ void scenes::stream::on_xr_event(const xr::event & event)
|
||||
.view_index = uint8_t(event.visibility_mask_changed.viewIndex),
|
||||
});
|
||||
break;
|
||||
case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED:
|
||||
network_session->send_control(from_headset::session_state_changed{
|
||||
.state = event.state_changed.state,
|
||||
});
|
||||
break;
|
||||
case XR_TYPE_EVENT_DATA_USER_PRESENCE_CHANGED_EXT:
|
||||
network_session->send_control(from_headset::user_presence_changed{
|
||||
.present = (bool)event.user_presence_changed.isUserPresent,
|
||||
|
||||
@@ -216,7 +216,6 @@ struct headset_info_packet
|
||||
std::array<XrFovf, 2> fov;
|
||||
bool hand_tracking;
|
||||
bool eye_gaze;
|
||||
bool presence;
|
||||
bool palm_pose;
|
||||
bool passthrough;
|
||||
face_type face_tracking;
|
||||
@@ -410,6 +409,10 @@ struct refresh_rate_changed
|
||||
float to;
|
||||
};
|
||||
|
||||
struct session_state_changed
|
||||
{
|
||||
XrSessionState state;
|
||||
};
|
||||
struct user_presence_changed
|
||||
{
|
||||
bool present;
|
||||
@@ -433,6 +436,7 @@ using packets = std::variant<
|
||||
battery,
|
||||
visibility_mask_changed,
|
||||
refresh_rate_changed,
|
||||
session_state_changed,
|
||||
user_presence_changed>;
|
||||
} // namespace from_headset
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
.supported = {
|
||||
.orientation_tracking = true,
|
||||
.position_tracking = true,
|
||||
.presence = info.presence,
|
||||
.presence = true,
|
||||
.battery_status = true,
|
||||
},
|
||||
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
|
||||
@@ -232,9 +232,28 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
|
||||
m->at(mask.view_index) = mask.data;
|
||||
}
|
||||
|
||||
void wivrn_hmd::update_presence(bool presence)
|
||||
bool wivrn_hmd::update_presence(bool new_presence, bool real)
|
||||
{
|
||||
U_LOG_I("Updating user presence to %s", presence ? "true" : "false");
|
||||
this->presence = presence;
|
||||
// if this presence change comes from headset, always honor it,
|
||||
// otherwise try to keep it in sync with the real presence,
|
||||
// while still changing presence to false when session is not
|
||||
// visible
|
||||
if (real || new_presence == this->real_presence || !new_presence)
|
||||
{
|
||||
if (real && this->real_presence != new_presence)
|
||||
{
|
||||
U_LOG_I("Updating real user presence: %s -> %s", real_presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->real_presence = new_presence;
|
||||
}
|
||||
|
||||
if (this->presence == new_presence)
|
||||
return false;
|
||||
|
||||
U_LOG_I("Updating user presence: %s -> %s", this->presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->presence = new_presence;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -54,6 +54,10 @@ class wivrn_hmd : public xrt_device
|
||||
from_headset::battery battery{};
|
||||
|
||||
std::atomic<bool> presence{true};
|
||||
// last XR_EVENT_DATA_USER_PRESENCE_CHANGED_EXT from headset
|
||||
// we must keep track of this to not go out of sync with headset when
|
||||
// a session state change also triggers presence change
|
||||
std::atomic<bool> real_presence{true};
|
||||
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||
|
||||
wivrn::wivrn_session * cnx;
|
||||
@@ -82,6 +86,7 @@ public:
|
||||
void update_battery(const from_headset::battery &);
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
void update_visibility_mask(const from_headset::visibility_mask_changed &);
|
||||
void update_presence(bool presence);
|
||||
// real if this update comes from a presence changed event
|
||||
bool update_presence(bool new_presence, bool real);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/to_string.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_session.h"
|
||||
#include <algorithm>
|
||||
@@ -576,17 +577,61 @@ void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)
|
||||
auto result = xrt_session_event_sink_push(&xrt_system.broadcast, &event);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
void wivrn_session::operator()(from_headset::session_state_changed && event)
|
||||
{
|
||||
hmd.update_presence(event.present);
|
||||
U_LOG_I("Session state changed: %s", xr::to_string(event.state));
|
||||
bool visible, focused;
|
||||
bool changed = false;
|
||||
switch (event.state)
|
||||
{
|
||||
case XR_SESSION_STATE_SYNCHRONIZED:
|
||||
visible = false;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(false, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_VISIBLE:
|
||||
visible = true;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_FOCUSED:
|
||||
visible = true;
|
||||
focused = true;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
xrt_session_event_user_presence_change event = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
};
|
||||
hmd.get_presence(&event.is_user_present);
|
||||
push_event({.presence_change = event});
|
||||
}
|
||||
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
.is_user_present = event.present,
|
||||
.state = {
|
||||
.type = XRT_SESSION_EVENT_STATE_CHANGE,
|
||||
.visible = visible,
|
||||
.focused = focused,
|
||||
},
|
||||
});
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
{
|
||||
if (hmd.update_presence(event.present, true))
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
.is_user_present = event.present,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
|
||||
{
|
||||
|
||||
@@ -179,6 +179,7 @@ public:
|
||||
void operator()(from_headset::feedback &&);
|
||||
void operator()(from_headset::battery &&);
|
||||
void operator()(from_headset::visibility_mask_changed &&);
|
||||
void operator()(from_headset::session_state_changed &&);
|
||||
void operator()(from_headset::user_presence_changed &&);
|
||||
void operator()(from_headset::refresh_rate_changed &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
Reference in New Issue
Block a user