Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ elseif(APPLE)
set(PLATFORM_NAME "osx")
endif()

find_library(OPENVR_LIB openvr_api HINTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/openvr/lib/${PLATFORM_NAME}${PROCESSOR_ARCH}/" NO_DEFAULT_PATH )

# Protobuf
# Installation:
# Please refer to this readme to install protobuf in your system: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
Expand All @@ -82,7 +80,6 @@ set(DEPS_INCLUDES
"${CMAKE_CURRENT_SOURCE_DIR}/src/"
)
set(DEPS_LIBS
"${OPENVR_LIB}"
protobuf::libprotoc
protobuf::libprotobuf
protobuf::libprotobuf-lite
Expand Down
2 changes: 1 addition & 1 deletion libraries/openvr
Submodule openvr updated 191 files
70 changes: 44 additions & 26 deletions src/VRDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,47 +384,65 @@ SlimeVRDriver::UniverseTranslation SlimeVRDriver::UniverseTranslation::parse(sim
return res;
}

std::optional<SlimeVRDriver::UniverseTranslation> SlimeVRDriver::VRDriver::SearchUniverse(std::string path, uint64_t target) {
try {
auto json = simdjson::padded_string::load(path); // load VR Path Registry
simdjson::ondemand::document doc = json_parser_.iterate(json);
std::optional<SlimeVRDriver::UniverseTranslation> SlimeVRDriver::VRDriver::SearchUniverse(const simdjson::padded_string &json, uint64_t target) {
simdjson::ondemand::document doc = json_parser_.iterate(json);

for (simdjson::ondemand::object uni: doc["universes"]) {
// TODO: universeID comes after the translation, would it be faster to unconditionally parse the translation?
auto elem = uni["universeID"];
uint64_t parsed_universe;
for (simdjson::ondemand::object uni: doc["universes"]) {
// TODO: universeID comes after the translation, would it be faster to unconditionally parse the translation?
auto elem = uni["universeID"];
uint64_t parsed_universe;

auto is_integer = elem.is_integer();
if (!is_integer.error() && is_integer.value_unsafe()) {
parsed_universe = elem.get_uint64();
} else {
parsed_universe = elem.get_uint64_in_string();
}
auto is_integer = elem.is_integer();
if (!is_integer.error() && is_integer.value_unsafe()) {
parsed_universe = elem.get_uint64();
} else {
parsed_universe = elem.get_uint64_in_string();
}

if (parsed_universe == target) {
auto standing_uni = uni["standing"].get_object();
return SlimeVRDriver::UniverseTranslation::parse(standing_uni.value());
}
if (parsed_universe == target) {
auto standing_uni = uni["standing"].get_object();
return SlimeVRDriver::UniverseTranslation::parse(standing_uni.value());
}
} catch (simdjson::simdjson_error& e) {
logger_->Log("Error getting universes from {}: {}", path, e.what());
return std::nullopt;
}

return std::nullopt;
}

std::optional<SlimeVRDriver::UniverseTranslation> SlimeVRDriver::VRDriver::SearchUniverses(uint64_t target) {
auto driver_chap_path = vr::VRProperties()->GetStringProperty(vr::VRProperties()->TrackedDeviceToPropertyContainer(0), vr::Prop_DriverProvidedChaperonePath_String);
vr::PropertyContainerHandle_t hmd_prop_container = vr::VRProperties()->TrackedDeviceToPropertyContainer(vr::k_unTrackedDeviceIndex_Hmd);
auto driver_chap_json = vr::VRProperties()->GetStringProperty(hmd_prop_container, vr::Prop_DriverProvidedChaperoneJson_String);
if (driver_chap_json != "") {
try {
auto driver_res = SearchUniverse(driver_chap_json, target);
if (driver_res.has_value()) {
return driver_res.value();
}
}
catch (simdjson::simdjson_error &e) {
logger_->Log("Error loading driver-provided chaperone JSON: {}", e.what());
}
}

auto driver_chap_path = vr::VRProperties()->GetStringProperty(hmd_prop_container, vr::Prop_DriverProvidedChaperonePath_String);
if (driver_chap_path != "") {
auto driver_res = SearchUniverse(driver_chap_path, target);
if (driver_res.has_value()) {
return driver_res.value();
try {
auto driver_res = SearchUniverse(simdjson::padded_string::load(driver_chap_path).take_value(), target);
if (driver_res.has_value()) {
return driver_res.value();
}
}
catch (simdjson::simdjson_error &e) {
logger_->Log("Error loading chaperone from driver-provided path {}: {}", driver_chap_path, e.what());
}
}

if (default_chap_path_.has_value()) {
return SearchUniverse(default_chap_path_.value(), target);
try {
return SearchUniverse(simdjson::padded_string::load(default_chap_path_.value()).take_value(), target);
}
catch (simdjson::simdjson_error &e) {
logger_->Log("Error loading chaperone from default path {}: {}", default_chap_path_.value(), e.what());
}
}

return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/VRDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace SlimeVRDriver {

vr::ETrackedPropertyError last_universe_error_;
std::optional<std::pair<uint64_t, UniverseTranslation>> current_universe_ = std::nullopt;
std::optional<UniverseTranslation> SearchUniverse(std::string path, uint64_t target);
std::optional<UniverseTranslation> SearchUniverse(const simdjson::padded_string &json, uint64_t target);
std::optional<UniverseTranslation> SearchUniverses(uint64_t target);
};
};