Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
with:
submodules: true

- if: matrix.os == 'ubuntu-latest'
name: Install GCC 16
uses: awalsh128/cache-apt-pkgs-action@v1.6.0
with:
add-repository: 'ppa:ubuntu-toolchain-r/test'
packages: g++-16
version: 1.0

- uses: lukka/get-cmake@latest

- name: Get submodule commit hashes
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ jobs:
with:
clang-format-version: '21'
check-path: 'src'
exclude-regex: '^.*_openvr\\..*$'
36 changes: 26 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,37 @@ elseif(APPLE)
set(PLATFORM_NAME "osx")
endif()

# Protobuf
# Installation:
# Please refer to this readme to install protobuf in your system: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
# WARNING: CLang has an arror building protobuf messages, use MSVC 2019
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
find_package(Protobuf CONFIG REQUIRED)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/bridge/ProtobufMessages.proto")
SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE)
set_source_files_properties(${PROTO_SRC} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)

find_package(simdjson CONFIG REQUIRED)

# libuv
find_package(uvw CONFIG REQUIRED)

# Catch2
find_package(Catch2 3 REQUIRED)

find_package(Git)

if (NOT GIT_DESC)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESC
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_DESC}" GIT_DESC)
else()
message(STATUS "Using GIT_DESC ${GIT_DESC} from explicit build flag")
endif()

if (GIT_DESC)
message(STATUS "GIT_DESC: ${GIT_DESC}")
else()
message(FATAL_ERROR "Could not set GIT_DESC")
endif()

# Project
set(DEPS_INCLUDES
"${OPENVR_INCLUDE_DIR}"
Expand All @@ -87,13 +101,15 @@ set(DEPS_LIBS
uvw::uvw
)

configure_file(src/Consts.hpp.in src/Consts.hpp @ONLY)

# compile into a static lib
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp")
add_library("${PROJECT_NAME}_static" STATIC ${SOURCES} ${PROTO_HEADER} ${PROTO_SRC})
target_link_libraries("${PROJECT_NAME}_static" PUBLIC ${DEPS_LIBS})
set_property(TARGET "${PROJECT_NAME}_static" PROPERTY CXX_STANDARD 20)
include_directories("${PROJECT_NAME}_static" PUBLIC ${DEPS_INCLUDES} ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
set_property(TARGET "${PROJECT_NAME}_static" PROPERTY CXX_STANDARD 23)
include_directories("${PROJECT_NAME}_static" PUBLIC ${DEPS_INCLUDES} ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/src")
if(UNIX)
target_compile_options("${PROJECT_NAME}_static" PRIVATE "-fPIC")
target_link_libraries("${PROJECT_NAME}_static" PUBLIC atomic)
Expand All @@ -103,15 +119,15 @@ endif()
file(GLOB_RECURSE DRIVER_MAIN "${CMAKE_CURRENT_SOURCE_DIR}/src/DriverFactory.cpp")
add_library("${PROJECT_NAME}" SHARED ${DRIVER_MAIN} ${HEADERS} ${PROTO_HEADER})
target_link_libraries("${PROJECT_NAME}" PUBLIC "${PROJECT_NAME}_static")
set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 20)
set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 23)

# compile tests
function(build_tests target_name test_dir)
file(GLOB TESTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/*.hpp")
file(GLOB TESTS_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/test/common/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/common/*.hpp")
add_executable(${target_name} ${TESTS} ${TESTS_COMMON} ${HEADERS} ${PROTO_HEADER})
target_link_libraries(${target_name} PUBLIC "${PROJECT_NAME}_static" Catch2::Catch2WithMain)
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD 20)
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD 23)
endfunction()
build_tests(tests "test")
build_tests(tests_integration "test/integration")
Expand Down
2 changes: 1 addition & 1 deletion fmt.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if ((Get-Command "clang-format" -ErrorAction SilentlyContinue) -eq $null) {
throw $errorObj
}

$SourceFiles = Get-ChildItem -Path '.\src\','.\test\' -Recurse -Include "*.cpp","*.hpp","*.proto" -Exclude "*_openvr.*"
$SourceFiles = Get-ChildItem -Path '.\src\','.\test\' -Recurse -Include "*.cpp","*.hpp","*.proto"
foreach ($file in $SourceFiles) {
Write-Output "Formatting $(Resolve-Path -Relative $file.FullName)"
clang-format -i "$($file.FullName)"
Expand Down
6 changes: 3 additions & 3 deletions fmt.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ find src/ test/ \( \
-iname '*.cpp' \
-or -iname '*.hpp' \
-or -iname '*.proto' \
\) -and -not -iname '*_openvr.*' \
-exec echo Formatting {} \; \
-exec clang-format -i {} \;
\) \
-exec echo Formatting {} \; \
-exec clang-format -i {} \;
3 changes: 3 additions & 0 deletions src/Consts.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#cmakedefine GIT_DESC "@GIT_DESC@"
7 changes: 2 additions & 5 deletions src/DriverFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "DriverFactory.hpp"
#include <VRDriver.hpp>
#include <sstream>
#include <thread>

static std::shared_ptr<SlimeVRDriver::IVRDriver> driver;
static std::shared_ptr<SlimeVRDriver::VRDriver> driver;

void* HmdDriverFactory(const char* interface_name, int* return_code) {
if (std::strcmp(interface_name, vr::IServerTrackedDeviceProvider_Version) == 0) {
Expand All @@ -22,6 +19,6 @@ void* HmdDriverFactory(const char* interface_name, int* return_code) {
return nullptr;
}

std::shared_ptr<SlimeVRDriver::IVRDriver> SlimeVRDriver::GetDriver() {
std::shared_ptr<SlimeVRDriver::VRDriver> SlimeVRDriver::GetDriver() {
return driver;
}
5 changes: 2 additions & 3 deletions src/DriverFactory.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <cstdlib>
#include <memory>

#include <openvr_driver.h>

#include <IVRDriver.hpp>
#include "VRDriver.hpp"

#ifdef WIN32
extern "C" __declspec(dllexport) void* HmdDriverFactory(const char* interface_name, int* return_code);
Expand All @@ -14,5 +13,5 @@ extern "C" void* HmdDriverFactory(const char* interface_name, int* return_code);
#endif

namespace SlimeVRDriver {
std::shared_ptr<SlimeVRDriver::IVRDriver> GetDriver();
std::shared_ptr<SlimeVRDriver::VRDriver> GetDriver();
}
30 changes: 18 additions & 12 deletions src/IVRDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "ProtobufMessages.pb.h"
#include <DeviceType.hpp>
#include <openvr_driver.h>
#include <variant>

namespace SlimeVRDriver {

Expand Down Expand Up @@ -42,17 +41,24 @@ class IVRDevice : public vr::ITrackedDeviceServerDriver {
*
* @returns Default initialised pose.
*/
static inline vr::DriverPose_t MakeDefaultPose(bool connected = true, bool tracking = true) {
vr::DriverPose_t out_pose = { 0 };

out_pose.deviceIsConnected = connected;
out_pose.poseIsValid = tracking;
out_pose.result = tracking ? vr::ETrackingResult::TrackingResult_Running_OK : vr::ETrackingResult::TrackingResult_Running_OutOfRange;
out_pose.willDriftInYaw = false;
out_pose.shouldApplyHeadModel = false;
out_pose.qDriverFromHeadRotation.w = out_pose.qWorldFromDriverRotation.w = out_pose.qRotation.w = 1.0;

return out_pose;
static constexpr vr::DriverPose_t MakeDefaultPose(bool connected = false, bool tracking = false) {
return {
.poseTimeOffset = 0,
.qWorldFromDriverRotation = {
.w = 1.0,
},
.qDriverFromHeadRotation = {
.w = 1.0,
},
.qRotation = {
.w = 1.0,
},
.result = tracking ? vr::ETrackingResult::TrackingResult_Running_OK : vr::ETrackingResult::TrackingResult_Running_OutOfRange,
.poseIsValid = tracking,
.willDriftInYaw = true,
.shouldApplyHeadModel = false,
.deviceIsConnected = connected,
};
}

/**
Expand Down
96 changes: 0 additions & 96 deletions src/IVRDriver.hpp

This file was deleted.

6 changes: 5 additions & 1 deletion src/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
#include <mutex>
#include <openvr_driver.h>
#include <string>
#include <thread>

class Logger {
public:
Logger()
: name_("") { }
Logger(const std::string& name)
: name_(name) { }

void Log(const std::string& str) {
LogImpl(str.c_str());
}

template <typename... Args>
void Log(const std::format_string<Args...> format_str, Args&&... args) {
std::string message = std::vformat(format_str.get(), std::make_format_args(args...));
Expand Down
32 changes: 32 additions & 0 deletions src/Paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "Paths.hpp"
#include <stdexcept>

namespace fs = std::filesystem;

static fs::path getOpenVRConfigFolder() {
#if defined(_WIN32)
const char* appData = getenv("LOCALAPPDATA");
if (!appData) {
throw std::runtime_error("LOCALAPPDATA is unset");
}

return appData;
#elif defined(__linux__)
if (const char* dataHome = getenv("XDG_CONFIG_HOME")) {
return dataHome;
}

const char* home = getenv("HOME");
if (!home) {
throw std::runtime_error("HOME is unset");
}

return fs::path(home) / ".config";
#else
#error "Unsupported platform"
#endif
}

std::filesystem::path Paths::GetOpenVRConfigPath() {
return getOpenVRConfigFolder() / "openvr" / "openvrpaths.vrpath";
}
7 changes: 7 additions & 0 deletions src/Paths.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <filesystem>

namespace Paths {
std::filesystem::path GetOpenVRConfigPath();
} // namespace Paths
Loading
Loading