bool oculusAvailable() { static std::once_flag once; static bool result { false }; std::call_once(once, [&] { static const QString DEBUG_FLAG("HIFI_DEBUG_OPENVR"); static bool enableDebugOpenVR = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); if (enableDebugOpenVR) { return; } ovrDetectResult detect = ovr_Detect(0); if (!detect.IsOculusServiceRunning || !detect.IsOculusHMDConnected) { return; } DWORD searchResult = SearchPathW(NULL, REQUIRED_OCULUS_DLL, NULL, MAX_PATH, FOUND_PATH, NULL); if (searchResult <= 0) { return; } result = true; }); return result; }
FOculusInput::FOculusInput( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler ) : MessageHandler( InMessageHandler ) , ControllerPairs() { PreInit(); // @TODO: call it sooner to avoid 'Warning InputKey Event specifies invalid' when loading a map using the custom keys // take care of backward compatibility of Remote with Gamepad if (bRemoteKeysMappedToGamepad) { Remote.ReinitButtonsForGamepadCompat(); } // Only initialize plug-in when not running a dedicated server, and Oculus service is running if(!IsRunningDedicatedServer() && ovr_Detect(0).IsOculusServiceRunning) { // Initializes LibOVR. ovrInitParams initParams; FMemory::Memset(initParams, 0); initParams.Flags = ovrInit_RequestVersion; initParams.RequestedMinorVersion = OVR_MINOR_VERSION; #if !UE_BUILD_SHIPPING // initParams.LogCallback = OvrLogCallback; #endif ovrResult initStatus = ovr_Initialize(&initParams); if (!OVR_SUCCESS(initStatus) && initStatus == ovrError_LibLoad) { // fatal errors: can't load library UE_LOG(LogOcInput, Log, TEXT("Can't find Oculus library %s: is proper Runtime installed? Version: %s"), TEXT(OVR_FILE_DESCRIPTION_STRING), TEXT(OVR_VERSION_STRING)); return; } FOculusTouchControllerPair& ControllerPair = *new(ControllerPairs) FOculusTouchControllerPair(); // @todo: Unreal controller index should be assigned to us by the engine to ensure we don't contest with other devices ControllerPair.UnrealControllerIndex = 0; //???? NextUnrealControllerIndex++; IModularFeatures::Get().RegisterModularFeature( GetModularFeatureName(), this ); GEngine->MotionControllerDevices.AddUnique(this); UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString()))); } }