clang-format

This commit is contained in:
Guillaume Meunier
2024-03-30 17:00:34 +01:00
parent bb660cfb3f
commit 9cceaac648
122 changed files with 2904 additions and 2783 deletions
+191 -186
View File
@@ -18,38 +18,38 @@
*/
#include "lobby.h"
#include "version.h"
#include "application.h"
#include "glm/geometric.hpp"
#include "hardware.h"
#include "imgui.h"
#include "input_profile.h"
#include "openxr/openxr.h"
#include "render/scene_data.h"
#include "render/scene_renderer.h"
#include "stream.h"
#include "hardware.h"
#include "utils/contains.h"
#include "version.h"
#include "wivrn_client.h"
#include "xr/passthrough.h"
#include <glm/gtc/matrix_access.hpp>
#include "wivrn_discover.h"
#include <cstdint>
#include <fstream>
#include <glm/gtc/quaternion.hpp>
#include <ios>
#include <magic_enum.hpp>
#include <simdjson.h>
#include <spdlog/spdlog.h>
#include <sstream>
#include <string>
#include <utils/ranges.h>
#include <vulkan/vulkan_raii.hpp>
#include <simdjson.h>
#include <fstream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
static const std::string discover_service = "_wivrn._tcp.local.";
static bool force_autoconnect = false;
@@ -68,7 +68,7 @@ static std::string choose_webxr_profile()
return controller;
#endif
switch(guess_model())
switch (guess_model())
{
case model::oculus_quest:
return "oculus-touch-v2";
@@ -92,16 +92,16 @@ static std::string choose_webxr_profile()
__builtin_unreachable();
}
static std::string json_string(const std::string& in)
static std::string json_string(const std::string & in)
{
std::string out;
out.reserve(in.size() + 2);
out += '"';
for(char c: in)
for (char c: in)
{
switch(c)
switch (c)
{
case '\b':
out += "\\b";
@@ -143,10 +143,9 @@ static std::string json_string(const std::string& in)
}
static const std::array supported_formats =
{
vk::Format::eR8G8B8A8Srgb,
vk::Format::eB8G8R8A8Srgb
};
{
vk::Format::eR8G8B8A8Srgb,
vk::Format::eB8G8R8A8Srgb};
void scenes::lobby::move_gui(glm::vec3 position, glm::quat orientation, XrTime predicted_display_time)
{
@@ -175,7 +174,7 @@ void scenes::lobby::move_gui(glm::vec3 position, glm::quat orientation, XrTime p
gui_yaw += gui_yaw_error;
imgui_ctx->position() += gui_position_error;
imgui_ctx->orientation() = glm::quat(cos(gui_yaw/2), 0, sin(gui_yaw/2), 0) * glm::quat(cos(gui_target_pitch/2), sin(gui_target_pitch/2), 0, 0);
imgui_ctx->orientation() = glm::quat(cos(gui_yaw / 2), 0, sin(gui_yaw / 2), 0) * glm::quat(cos(gui_target_pitch / 2), sin(gui_target_pitch / 2), 0, 0);
}
}
@@ -191,21 +190,20 @@ scenes::lobby::lobby()
{
simdjson::dom::parser parser;
simdjson::dom::element root = parser.load(application::get_config_path() / "client.json");
for(simdjson::dom::object i: simdjson::dom::array(root["servers"]))
for (simdjson::dom::object i: simdjson::dom::array(root["servers"]))
{
server_data data{
.autoconnect = i["autoconnect"].get_bool(),
.manual = i["manual"].get_bool(),
.visible = false,
.compatible = true,
.service = {
.name = (std::string)i["pretty_name"],
.hostname = (std::string)i["hostname"],
.port = (int)i["port"].get_int64(),
.txt = {{"cookie", (std::string)i["cookie"]}}
.autoconnect = i["autoconnect"].get_bool(),
.manual = i["manual"].get_bool(),
.visible = false,
.compatible = true,
.service = {
.name = (std::string)i["pretty_name"],
.hostname = (std::string)i["hostname"],
.port = (int)i["port"].get_int64(),
.txt = {{"cookie", (std::string)i["cookie"]}}
}
};
}};
servers.emplace(data.service.txt["cookie"], data);
}
@@ -228,7 +226,7 @@ scenes::lobby::lobby()
if (passthrough.is_bool())
passthrough_enabled = passthrough.get_bool();
}
catch(std::exception& e)
catch (std::exception & e)
{
spdlog::warn("Cannot read configuration: {}", e.what());
servers.clear();
@@ -236,7 +234,7 @@ scenes::lobby::lobby()
}
spdlog::info("{} known server(s):", servers.size());
for(auto& i: servers)
for (auto & i: servers)
{
spdlog::info(" {}", i.second.service.name);
}
@@ -270,7 +268,7 @@ void scenes::lobby::save_config()
{
std::stringstream ss;
for (auto& [cookie, server_data]: servers)
for (auto & [cookie, server_data]: servers)
{
if (server_data.autoconnect || server_data.manual)
{
@@ -294,20 +292,20 @@ void scenes::lobby::save_config()
json << "{\"servers\":[" << servers_str << "],"
<< "\"show_performance_metrics\":" << std::boolalpha << show_performance_metrics;
if (preferred_refresh_rate != 0.)
json << ",\"preferred_refresh_rate\":" << preferred_refresh_rate ;
json << ",\"preferred_refresh_rate\":" << preferred_refresh_rate;
json << ",\"microphone\":" << std::boolalpha << microphone;
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
json << "}";
}
static std::string ip_address_to_string(const in_addr& addr)
static std::string ip_address_to_string(const in_addr & addr)
{
char buf[100];
inet_ntop(AF_INET, &addr, buf, sizeof(buf));
return buf;
}
static std::string ip_address_to_string(const in6_addr& addr)
static std::string ip_address_to_string(const in6_addr & addr)
{
char buf[100];
inet_ntop(AF_INET6, &addr, buf, sizeof(buf));
@@ -323,7 +321,7 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
spdlog::debug("Client protocol version: {}", protocol_string);
spdlog::debug("Server TXT:");
for(auto& [i,j]: service.txt)
for (auto & [i, j]: service.txt)
{
spdlog::debug(" {}=\"{}\"", i, j);
}
@@ -339,11 +337,10 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
// Only the automatically discovered servers already have their IP addresses available
if (manual_connection)
{
addrinfo hint
{
.ai_flags = AI_ADDRCONFIG,
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
addrinfo hint{
.ai_flags = AI_ADDRCONFIG,
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
};
addrinfo * addresses;
if (int err = getaddrinfo(service.hostname.c_str(), nullptr, &hint, &addresses))
@@ -352,15 +349,15 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
throw std::runtime_error("Cannot resolve hostname: " + std::string(gai_strerror(err)));
}
for(auto i = addresses; i; i = i->ai_next)
for (auto i = addresses; i; i = i->ai_next)
{
switch (i->ai_family)
{
case AF_INET:
service.addresses.push_back(((sockaddr_in*)i->ai_addr)->sin_addr);
service.addresses.push_back(((sockaddr_in *)i->ai_addr)->sin_addr);
break;
case AF_INET6:
service.addresses.push_back(((sockaddr_in6*)i->ai_addr)->sin6_addr);
service.addresses.push_back(((sockaddr_in6 *)i->ai_addr)->sin6_addr);
break;
}
}
@@ -372,7 +369,8 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
{
std::string address_string = std::visit([](auto & address) {
return ip_address_to_string(address);
}, address);
},
address);
try
{
@@ -381,7 +379,7 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
return std::visit([port = service.port](auto & address) {
return std::make_unique<wivrn_session>(address, port);
},
address);
address);
}
catch (std::exception & e)
{
@@ -434,7 +432,7 @@ void scenes::lobby::update_server_list()
std::vector<wivrn_discover::service> discovered_services = discover->get_services();
// TODO: only if discovered_services changed
for(auto& [cookie, data]: servers)
for (auto & [cookie, data]: servers)
{
data.visible = false;
}
@@ -442,7 +440,7 @@ void scenes::lobby::update_server_list()
char protocol_string[17];
sprintf(protocol_string, "%016lx", xrt::drivers::wivrn::protocol_version);
for(auto& service: discovered_services)
for (auto & service: discovered_services)
{
std::string cookie;
bool compatible = true;
@@ -467,13 +465,15 @@ void scenes::lobby::update_server_list()
if (server == servers.end())
{
// Newly discovered server: add it to the list
servers.emplace(cookie, server_data{
.autoconnect = false,
.manual = false,
.visible = true,
.compatible = compatible,
.service = service
});
servers.emplace(
cookie,
server_data{
.autoconnect = false,
.manual = false,
.visible = true,
.compatible = compatible,
.service = service,
});
}
else
{
@@ -484,19 +484,21 @@ void scenes::lobby::update_server_list()
}
}
void scenes::lobby::connect(server_data& data)
void scenes::lobby::connect(server_data & data)
{
server_name = data.service.name;
async_error.reset();
async_session = utils::async<std::unique_ptr<wivrn_session>, std::string>([](auto token, wivrn_discover::service service, bool manual)
{
token.set_progress("Waiting for connection");
return connect_to_session(service, manual);
}, data.service, data.manual);
async_session = utils::async<std::unique_ptr<wivrn_session>, std::string>(
[](auto token, wivrn_discover::service service, bool manual) {
token.set_progress("Waiting for connection");
return connect_to_session(service, manual);
},
data.service,
data.manual);
}
static std::vector<XrCompositionLayerProjectionView> render_layer(std::vector<XrView>& views, std::vector<xr::swapchain>& swapchains, scene_renderer& renderer, scene_data& data, const std::array<float, 4>& clear_color)
static std::vector<XrCompositionLayerProjectionView> render_layer(std::vector<XrView> & views, std::vector<xr::swapchain> & swapchains, scene_renderer & renderer, scene_data & data, const std::array<float, 4> & clear_color)
{
std::vector<scene_renderer::frame_info> frames;
frames.reserve(views.size());
@@ -509,19 +511,23 @@ static std::vector<XrCompositionLayerProjectionView> render_layer(std::vector<Xr
int image_index = swapchain.acquire();
swapchain.wait();
frames.push_back({.destination = swapchain.images()[image_index].image,
.projection = projection_matrix(view.fov),
.view = view_matrix(view.pose)});
frames.push_back({
.destination = swapchain.images()[image_index].image,
.projection = projection_matrix(view.fov),
.view = view_matrix(view.pose),
});
layer_views.push_back({
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,
.pose = view.pose,
.fov = view.fov,
.subImage = {
.swapchain = swapchain,
.imageRect = {
.offset = {0, 0},
.extent = swapchain.extent()}},
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,
.pose = view.pose,
.fov = view.fov,
.subImage = {
.swapchain = swapchain,
.imageRect = {
.offset = {0, 0},
.extent = swapchain.extent(),
},
},
});
}
@@ -542,7 +548,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
async_session.reset();
}
catch(std::exception& e)
catch (std::exception & e)
{
spdlog::error("Error connecting to server: {}", e.what());
async_session.cancel();
@@ -563,12 +569,10 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
imgui_ctx->set_current();
if (!async_session.valid() && !next_scene && !ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup))
{
for(auto&& [cookie, data]: servers)
for (auto && [cookie, data]: servers)
{
if (data.visible && (data.autoconnect || force_autoconnect) && data.compatible)
{
connect(data);
}
}
}
@@ -591,7 +595,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
{
if (left_hand)
{
auto& hand = application::get_left_hand();
auto & hand = application::get_left_hand();
auto joints = hand.locate(world_space, predicted_display_time);
left_hand->apply(joints);
@@ -601,7 +605,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
if (right_hand)
{
auto& hand = application::get_right_hand();
auto & hand = application::get_right_hand();
auto joints = hand.locate(world_space, predicted_display_time);
right_hand->apply(joints);
@@ -653,9 +657,11 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
if (passthrough_enabled)
{
std::visit([&](auto& p){
layers_base.push_back(p.layer());
}, passthrough);
std::visit(
[&](auto & p) {
layers_base.push_back(p.layer());
},
passthrough);
}
else
{
@@ -708,25 +714,25 @@ void scenes::lobby::on_focused()
if (application::get_hand_tracking_supported())
{
left_hand.emplace( "left-hand.glb", loader, *controllers_scene);
left_hand.emplace("left-hand.glb", loader, *controllers_scene);
right_hand.emplace("right-hand.glb", loader, *controllers_scene);
}
std::array imgui_inputs{
imgui_context::controller{
.aim = get_action_space("left_aim"),
.trigger = get_action("left_trigger").first,
.squeeze = get_action("left_squeeze").first,
.scroll = get_action("left_scroll").first,
.hand = application::get_left_hand(),
},
imgui_context::controller{
.aim = get_action_space("right_aim"),
.trigger = get_action("right_trigger").first,
.squeeze = get_action("right_squeeze").first,
.scroll = get_action("right_scroll").first,
.hand = application::get_right_hand(),
},
imgui_context::controller{
.aim = get_action_space("left_aim"),
.trigger = get_action("left_trigger").first,
.squeeze = get_action("left_squeeze").first,
.scroll = get_action("left_scroll").first,
.hand = application::get_left_hand(),
},
imgui_context::controller{
.aim = get_action_space("right_aim"),
.trigger = get_action("right_trigger").first,
.squeeze = get_action("right_squeeze").first,
.scroll = get_action("right_scroll").first,
.hand = application::get_right_hand(),
},
};
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 1500, 1000);
@@ -736,7 +742,7 @@ void scenes::lobby::on_focused()
{
about_picture = imgui_ctx->load_texture("wivrn.ktx2");
}
catch(...)
catch (...)
{
about_picture = imgui_ctx->load_texture("wivrn.png");
}
@@ -752,7 +758,7 @@ void scenes::lobby::on_focused()
passthrough.emplace<xr::passthrough_htc>(instance, session);
}
std::visit([](auto& p) {p.start();}, passthrough);
std::visit([](auto & p) { p.start(); }, passthrough);
}
}
@@ -784,96 +790,95 @@ void scenes::lobby::on_session_state_changed(XrSessionState state)
discover.reset();
}
scene::meta& scenes::lobby::get_meta_scene()
scene::meta & scenes::lobby::get_meta_scene()
{
static meta m{
.name = "Lobby",
.actions = {
{"left_aim", XR_ACTION_TYPE_POSE_INPUT},
{"left_trigger", XR_ACTION_TYPE_FLOAT_INPUT},
{"left_squeeze", XR_ACTION_TYPE_FLOAT_INPUT},
{"left_scroll", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"left_haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"right_aim", XR_ACTION_TYPE_POSE_INPUT},
{"right_trigger", XR_ACTION_TYPE_FLOAT_INPUT},
{"right_squeeze", XR_ACTION_TYPE_FLOAT_INPUT},
{"right_scroll", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"right_haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
},
.bindings = {
suggested_binding{
"/interaction_profiles/oculus/touch_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
}
},
suggested_binding{
"/interaction_profiles/bytedance/pico_neo3_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
}
},
suggested_binding{
"/interaction_profiles/bytedance/pico4_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
}
},
suggested_binding{
"/interaction_profiles/htc/vive_focus3_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
}
},
suggested_binding{
"/interaction_profiles/khr/simple_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/select/click"},
{"left_squeeze", "/user/hand/left/input/menu/click"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/select/click"},
{"right_squeeze", "/user/hand/right/input/menu/click"},
}
},
}
};
.name = "Lobby",
.actions = {
{"left_aim", XR_ACTION_TYPE_POSE_INPUT},
{"left_trigger", XR_ACTION_TYPE_FLOAT_INPUT},
{"left_squeeze", XR_ACTION_TYPE_FLOAT_INPUT},
{"left_scroll", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"left_haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"right_aim", XR_ACTION_TYPE_POSE_INPUT},
{"right_trigger", XR_ACTION_TYPE_FLOAT_INPUT},
{"right_squeeze", XR_ACTION_TYPE_FLOAT_INPUT},
{"right_scroll", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"right_haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
},
.bindings = {
suggested_binding{
"/interaction_profiles/oculus/touch_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
},
},
suggested_binding{
"/interaction_profiles/bytedance/pico_neo3_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
},
},
suggested_binding{
"/interaction_profiles/bytedance/pico4_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
},
},
suggested_binding{
"/interaction_profiles/htc/vive_focus3_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/trigger/value"},
{"left_squeeze", "/user/hand/left/input/squeeze/value"},
{"left_scroll", "/user/hand/left/input/thumbstick"},
{"left_haptic", "/user/hand/left/output/haptic"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/trigger/value"},
{"right_squeeze", "/user/hand/right/input/squeeze/value"},
{"right_scroll", "/user/hand/right/input/thumbstick"},
{"right_haptic", "/user/hand/right/output/haptic"},
},
},
suggested_binding{
"/interaction_profiles/khr/simple_controller",
{
{"left_aim", "/user/hand/left/input/aim/pose"},
{"left_trigger", "/user/hand/left/input/select/click"},
{"left_squeeze", "/user/hand/left/input/menu/click"},
{"right_aim", "/user/hand/right/input/aim/pose"},
{"right_trigger", "/user/hand/right/input/select/click"},
{"right_squeeze", "/user/hand/right/input/menu/click"},
},
},
}};
return m;
}