Rebase almost everything to Master

This commit is contained in:
Vindicus999
2025-09-25 09:16:54 -04:00
parent 492ed88ae2
commit cf3c364b42
129 changed files with 13067 additions and 4431 deletions
+74 -33
View File
@@ -28,6 +28,7 @@
#include "util/u_builders.h"
#include "util/u_logging.h"
#include "util/u_system.h"
#include "utils/load_icon.h"
#include "utils/scoped_lock.h"
#include "audio/audio_setup.h"
@@ -57,7 +58,7 @@
#endif
#if WIVRN_FEATURE_SOLARXR
#include "solarxr_interface.h"
#include "solarxr_device.h"
#endif
namespace wivrn
@@ -171,6 +172,12 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
throw;
}
(*this)(from_headset::get_application_list{
.language = get_info().language,
.country = get_info().country,
.variant = get_info().variant,
});
static_roles.head = xdevs[xdev_count++] = &hmd;
if (hmd.supported.face_tracking)
@@ -233,35 +240,44 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
xdevs[xdev_count++] = htc_face_tracker.get();
}
num_generic_trackers = get_info().num_generic_trackers;
enabled_trackers.fill(false);
auto num_generic_trackers = get_info().num_generic_trackers;
generic_trackers.reserve(num_generic_trackers);
if (num_generic_trackers > 0)
{
if (num_generic_trackers > from_headset::body_tracking::max_tracked_poses)
{
U_LOG_W("reported generic trackers %d larger than maximum %lu",
num_generic_trackers,
from_headset::body_tracking::max_tracked_poses);
num_generic_trackers = from_headset::body_tracking::max_tracked_poses;
}
if (num_generic_trackers + xdev_count > std::size(xdevs))
{
U_LOG_W("Too many generic trackers: %d, only %lu will be active",
num_generic_trackers,
std::size(xdevs) - xdev_count);
num_generic_trackers = std::size(xdevs) - xdev_count;
}
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
if (num_generic_trackers > generic_trackers.size())
throw std::out_of_range(
std::format("{} generic trackers is larger than maximum {}",
num_generic_trackers,
generic_trackers.size()));
for (int i = 0; i < num_generic_trackers; ++i)
{
auto dev = std::make_unique<wivrn_generic_tracker>(i, &hmd, *this);
xdevs[xdev_count++] = dev.get();
generic_trackers[i] = std::move(dev);
enabled_trackers[i] = true;
generic_trackers.push_back(std::move(dev));
}
}
#if WIVRN_FEATURE_SOLARXR
uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count);
if (num_devs != 0)
xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES];
uint32_t solar_devs_cap = XRT_SYSTEM_MAX_DEVICES - xdev_count;
uint32_t num_devs = solarxr_device_create_xdevs(&hmd, solar_devs, XRT_SYSTEM_MAX_DEVICES - xdev_count);
for (int i = 0; i < num_devs; i++)
{
static_roles.body = xdevs[xdev_count];
solarxr_device_set_feeder_devices(static_roles.body, xdevs, xdev_count);
xdevs[xdev_count++] = solar_devs[i];
if (i == 0)
static_roles.body = solar_devs[i];
}
xdev_count += num_devs;
#endif
if (roles.left >= 0)
@@ -280,10 +296,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
wivrn_session::~wivrn_session()
{
#if WIVRN_FEATURE_SOLARXR
solarxr_device_set_feeder_devices(static_roles.body, nullptr, 0);
#endif
for (size_t i = 0; i < ARRAY_SIZE(xdevs); i++)
{
xrt_device_destroy(&xdevs[i]);
@@ -535,12 +547,10 @@ void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
{
auto offset = offset_est.get_offset();
for (int i = 0; i < num_generic_trackers; i++)
assert(generic_trackers.size() <= from_headset::body_tracking::max_tracked_poses);
for (int i = 0; i < generic_trackers.size(); i++)
{
auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{
.pose = {},
.flags = 0,
};
auto pose = body_tracking.poses ? (*body_tracking.poses)[i] : from_headset::body_tracking::pose{};
generic_trackers[i]->update_tracking(body_tracking, pose, offset);
}
}
@@ -605,12 +615,10 @@ void wivrn_session::set_enabled(device_id id, bool enabled)
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
tracking_control.send(*connection, true);
}
void wivrn_session::set_tracker_enabled(int index, bool enabled)
void wivrn_session::update_tracker_enabled()
{
assert(index < std::size(enabled_trackers));
enabled_trackers[index] = enabled;
bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; });
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active))
bool active = std::ranges::any_of(generic_trackers, [](auto & t) { return t->is_active(); });
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, active) and active)
tracking_control.send(*connection, true);
}
@@ -736,15 +744,48 @@ void wivrn_session::operator()(from_headset::get_application_list && request)
.country = std::move(request.country),
.variant = std::move(request.variant),
};
for (auto && [id, app]: list_applications())
auto apps = list_applications();
for (const auto & [id, app]: apps)
{
response.applications.emplace_back(
std::move(id),
// FIXME: use locale
app.name.at(""),
app.image);
app.name.at(""));
}
send_control(std::move(response));
for (const auto & [id, app]: apps)
{
if (app.icon_path)
{
try
{
const auto & icons = load_icon(*app.icon_path);
if (icons.empty())
continue;
const auto & largest_icon = std::ranges::max(icons, [](const wivrn::icon & a, const wivrn::icon & b) {
if (a.bpp < b.bpp)
return true;
if (a.bpp > b.bpp)
return false;
return a.width * a.height < b.width * b.height;
});
send_control(to_headset::application_icon{
.id = id,
.image = largest_icon.png_data,
});
}
catch (std::exception & e)
{
U_LOG_W("Error loading icon %s: %s", app.icon_path->c_str(), e.what());
}
}
}
}
void wivrn_session::operator()(const from_headset::start_app & request)