Refactor OpenVR init code to separate class
The OpenVR init code is currently being run in the OverlayController constructor. Member objects that are initialized before the OverlayController (ideally all of them) can't use OpenVR APIs before the first line of the OverlayController constructor. Implementing the OpenVR Init code as a class means that it is able to initialize before all the other objects and allow them to use OpenVR APIs in their constructors. The class has been placed in a folder called "overlaycontroller" to signify that it should only be used by the OverlayController. openvr_init.h uses #pragma once despite it being unofficial since it is supported on all modern compilers. The copy constructor, copy assignment operator, move constructor and move assignment operator have been explicitly deleted in order to make sure nobody tries to use the object in an unintended way, and to document that these functions should not be automatically created. The version error messages have been replaced with a single lambda, since they were all identical. The version error text should maybe tell the user to update Advanced Settings instead of OpenVR, since Advanced Settings contains the version strings in the binary. No other exit functions were documented on the official docs besides VR_Shutdown().
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
/*!
|
||||
Initializes OpenVR and checks validity of interface versions. Shuts down OpenVR
|
||||
when destroyed.
|
||||
|
||||
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();
|
||||
~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;
|
||||
};
|
||||
Reference in New Issue
Block a user