Files
OpenVR-AdvancedSettings-frame/src/openvr/openvr_init.cpp
T
Chelsea Jaggiandykeara 1cfd9ff104 Option to gently fade chaperone to disabled below a certain height (#622)
* Option to fade out chaperone when HMD goes below a configured height

Useful for setups in which you have a seat just outside your VR space,
or like to sit in the middle of your space for any amount of time. Will
fade out the boundaries to 0% opacity over 5 seconds, 5 seconds after
you sit down. Standing back up to the configured height will make them
pop back in immediately.

Can be found under Chaperone -> Additional Settings.

* Update format.sh to require clang-format v10

* Use fade distance instead of opacity, opacity inconsistently applied

* Bugfixes (#624)

* stop crashing on HMD Init Errors, as well as bypass force quit on all steamvr Init Errors

* add qtc clang to gitignore

* add app volume adjustment

* adjust app volume placement in menu

* fix type error

* increment version

* fix version number

---------

Co-authored-by: ykeara <ykeara1@gmail.com>
2023-05-17 14:21:59 -05:00

113 lines
4.1 KiB
C++

#include <string>
#include <openvr.h>
#include <QMessageBox>
#include "openvr_init.h"
#include <easylogging++.h>
#include "../openvr/ivrinput_manifest.h"
namespace openvr_init
{
void initializeProperly( const OpenVrInitializationType initType )
{
auto initializationType = vr::EVRApplicationType::VRApplication_Other;
if ( initType == OpenVrInitializationType::Overlay )
{
initializationType = vr::EVRApplicationType::VRApplication_Overlay;
}
else if ( initType == OpenVrInitializationType::Utility )
{
initializationType = vr::EVRApplicationType::VRApplication_Utility;
}
auto initError = vr::VRInitError_None;
vr::VR_Init( &initError, initializationType );
if ( initError != vr::VRInitError_None )
{
if ( initError == vr::VRInitError_Init_HmdNotFound
|| initError == vr::VRInitError_Init_HmdNotFoundPresenceFailed )
{
// In particular in some setups these errors are thrown while
// nothing is wrong with their setup presumably this is some sort of
// race condition
LOG( WARNING ) << "HMD not Found During Startup";
LOG( WARNING ) << "steamvr error: "
+ std::string(
vr::VR_GetVRInitErrorAsEnglishDescription(
initError ) );
return;
}
LOG( ERROR ) << "Failed to initialize OpenVR: "
+ std::string(
vr::VR_GetVRInitErrorAsEnglishDescription(
initError ) );
// Going to stop Exiting App, This may lead to crashes if OpenVR
// actually fails to start, HOWEVER based on the HMD errors we are
// probably pre-maturely killing ourselves from some sort of OpenVR race
// condition
// exit( EXIT_FAILURE );
}
else
{
LOG( INFO ) << "OpenVR initialized successfully.";
}
}
void initializeOpenVR( const OpenVrInitializationType initType )
{
initializeProperly( initType );
// The function call and error message was the same for all version checks.
// Specific error messages are unlikely to be necessary since both the type
// and version are in the string and will be output.
auto reportVersionError = []( const char* const interfaceAndVersion ) {
QMessageBox::critical(
nullptr,
"OpenVR Advanced Settings Overlay",
"OpenVR version is too outdated. Please update OpenVR." );
throw std::runtime_error(
std::string( "OpenVR version is too outdated: Interface version " )
+ std::string( interfaceAndVersion )
+ std::string( " not found." ) );
};
// Check whether OpenVR is too outdated
if ( !vr::VR_IsInterfaceVersionValid( vr::IVRSystem_Version ) )
{
reportVersionError( vr::IVRSystem_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRSettings_Version ) )
{
reportVersionError( vr::IVRSettings_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVROverlay_Version ) )
{
reportVersionError( vr::IVROverlay_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRApplications_Version ) )
{
reportVersionError( vr::IVRApplications_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRChaperone_Version ) )
{
reportVersionError( vr::IVRChaperone_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRChaperoneSetup_Version ) )
{
reportVersionError( vr::IVRChaperoneSetup_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRCompositor_Version ) )
{
reportVersionError( vr::IVRCompositor_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRNotifications_Version ) )
{
reportVersionError( vr::IVRNotifications_Version );
}
else if ( !vr::VR_IsInterfaceVersionValid( vr::IVRInput_Version ) )
{
reportVersionError( vr::IVRInput_Version );
}
}
} // namespace openvr_init