From 293ca21af5a287973a19ecad7ece4dab8b81e92c Mon Sep 17 00:00:00 2001 From: Vasily Date: Mon, 4 Mar 2019 20:39:15 +0100 Subject: [PATCH] Convert openvr_init from class to function Since the OpenVR initialization code is no longer inside the overlaycontroller there is no need for it to be available during object construction. Therefore it doesn't make sense to have it be an object. The shutdown call was completely removed because shutdowns are handled by an OpenVR event that calls the relevant shutdown code. The destructor for the old object was never called, removing it adds clarity to the actual operation of the code and also removes unnecessary code. --- src/main.cpp | 2 +- src/overlaycontroller/openvr_init.cpp | 6 +---- src/overlaycontroller/openvr_init.h | 33 +-------------------------- src/utils/setup.h | 2 +- 4 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5a54943..79c9d50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,7 @@ int main( int argc, char* argv[] ) commandLineArgs.forceRemoveManifest ); } - openvr_init::OpenVR_Init openvr_init( + openvr_init::initializeOpenVR( openvr_init::OpenVrInitializationType::Overlay ); try diff --git a/src/overlaycontroller/openvr_init.cpp b/src/overlaycontroller/openvr_init.cpp index de5d33d..97fbaa4 100644 --- a/src/overlaycontroller/openvr_init.cpp +++ b/src/overlaycontroller/openvr_init.cpp @@ -42,7 +42,7 @@ void initializeProperly( const OpenVrInitializationType initType ) } } -OpenVR_Init::OpenVR_Init( const OpenVrInitializationType initType ) +void initializeOpenVR( const OpenVrInitializationType initType ) { initializeProperly( initType ); @@ -99,8 +99,4 @@ OpenVR_Init::OpenVR_Init( const OpenVrInitializationType initType ) } } -OpenVR_Init::~OpenVR_Init() -{ - vr::VR_Shutdown(); -} } // namespace openvr_init diff --git a/src/overlaycontroller/openvr_init.h b/src/overlaycontroller/openvr_init.h index 5b454b3..efa5685 100644 --- a/src/overlaycontroller/openvr_init.h +++ b/src/overlaycontroller/openvr_init.h @@ -8,37 +8,6 @@ enum class OpenVrInitializationType Utility, }; -/*! -Initializes OpenVR and checks validity of interface versions. Shuts down OpenVR -when destroyed. +void initializeOpenVR( const OpenVrInitializationType initType ); -This object should be declared above all other objects in the class file that -use OpenVR calls, since the order of declaration decides which objects are -initialized first. - -The comment/tooltips have not been provided for the constructor/destructor since -they do not need explanation due to the straightforward nature of their -implementation. -*/ -class OpenVR_Init -{ -public: - OpenVR_Init( const OpenVrInitializationType initType ); - ~OpenVR_Init(); - - // As per the Rule of Five, the following constructors and assignments can - // be created by the compiler automatically if they are used in the code. - // The compiler will not be able to correctly create this class and it - // wouldn't make sense to copy a class that just starts OpenVR. - // They are explicitly deleted to make sure they aren't used, and to - // document that they shouldn't be used. - // Copy constructor - OpenVR_Init( const OpenVR_Init& ) = delete; - // Copy assignment - const OpenVR_Init& operator=( const OpenVR_Init& ) = delete; - // Move constructor - OpenVR_Init( OpenVR_Init&& ) = delete; - // Move assignment - const OpenVR_Init operator=( OpenVR_Init&& ) = delete; -}; } // namespace openvr_init diff --git a/src/utils/setup.h b/src/utils/setup.h index 796d04f..314d598 100644 --- a/src/utils/setup.h +++ b/src/utils/setup.h @@ -295,7 +295,7 @@ void reinstallApplicationManifest( const QString manifestPath ) [[noreturn]] void handleManifests( const bool installManifest, const bool removeManifest ) { - openvr_init::OpenVR_Init openvr_init( + openvr_init::initializeOpenVR( openvr_init::OpenVrInitializationType::Utility ); int exit_code = ReturnErrorCode::SUCCESS;