Skip to content
Snippets Groups Projects
Commit d71dc0dc authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Merge branch 'refactor/cleanup_virtualrealityutilities' into 'dev/5.3'

refactor(utilities): Cleanup virtual reality utilities

See merge request !53
parents 439d6fa2 aa59f72b
No related branches found
No related tags found
1 merge request!53refactor(utilities): Cleanup virtual reality utilities
Showing
with 78 additions and 109 deletions
......@@ -14,7 +14,7 @@
#include "Logging/StructuredLog.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Pawn/VirtualRealityPawn.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
DEFINE_LOG_CATEGORY(LogCAVEOverlay);
......@@ -160,11 +160,11 @@ void ACAVEOverlayController::BeginPlay()
// Not sure which place would be best...
const bool bValidPC = PC && PC->GetLocalPlayer();
if (!bValidPC || !UVirtualRealityUtilities::IsRoomMountedMode())
if (!bValidPC || !URWTHVRUtilities::IsRoomMountedMode())
return;
//Input config
if (UVirtualRealityUtilities::IsPrimaryNode())
if (URWTHVRUtilities::IsPrimaryNode())
{
if (CycleDoorTypeInputAction == nullptr || IMCCaveOverlayInputMapping == nullptr)
{
......
......@@ -4,7 +4,7 @@
#include "CaveSetup.h"
#include "Logging/StructuredLog.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
// Sets default values
......@@ -22,7 +22,7 @@ void ACaveSetup::BeginPlay()
{
Super::BeginPlay();
if (!UVirtualRealityUtilities::IsRoomMountedMode())
if (!URWTHVRUtilities::IsRoomMountedMode())
{
return;
}
......@@ -41,7 +41,7 @@ void ACaveSetup::BeginPlay()
// Apply the DTrack LiveLink Preset. Only do this if we are the primaryNode
if (UVirtualRealityUtilities::IsPrimaryNode())
if (URWTHVRUtilities::IsPrimaryNode())
{
if (LiveLinkPresetToApplyOnCave && LiveLinkPresetToApplyOnCave->IsValidLowLevelFast())
{
......
......@@ -7,7 +7,7 @@
#include "GameFramework/SpectatorPawn.h"
#include "Kismet/GameplayStatics.h"
#include "Logging/StructuredLog.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId,
......
......@@ -8,7 +8,7 @@
#include "Interaction/Interactors/GrabComponent.h"
#include "Logging/StructuredLog.h"
#include "Misc/Optional.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
UVRWidgetInteractionComponent::UVRWidgetInteractionComponent()
{
......
......@@ -6,7 +6,7 @@
#include "EnhancedInputSubsystems.h"
#include "Engine/LocalPlayer.h"
#include "GameFramework/PlayerController.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
#include "MotionControllerComponent.h"
void UContinuousMovementComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
......@@ -54,7 +54,7 @@ void UContinuousMovementComponent::OnMove(const FInputActionValue& Value)
if (!VRPawn || !VRPawn->Controller)
return;
const bool bGazeDirected = UVirtualRealityUtilities::IsDesktopMode() || SteeringMode ==
const bool bGazeDirected = URWTHVRUtilities::IsDesktopMode() || SteeringMode ==
EVRSteeringModes::STEER_GAZE_DIRECTED;
const FVector ForwardDir = bGazeDirected
......
......@@ -7,7 +7,7 @@
#include "Engine/LocalPlayer.h"
#include "GameFramework/PlayerController.h"
#include "Pawn/VirtualRealityPawn.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
void UMovementComponentBase::SetupPlayerInput(UInputComponent* PlayerInputComponent)
{
......
......@@ -11,7 +11,7 @@
#include "NiagaraFunctionLibrary.h"
#include "Kismet/GameplayStatics.h"
#include "NiagaraDataInterfaceArrayFunctionLibrary.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
#include "MotionControllerComponent.h"
......
......@@ -6,7 +6,7 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Pawn/VirtualRealityPawn.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
void UTurnComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
{
......@@ -34,7 +34,7 @@ void UTurnComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
}
// add Input Mapping context
InputSubsystem->AddMappingContext(UVirtualRealityUtilities::IsDesktopMode() ? IMCDesktopRotation : IMCTurn, 0);
InputSubsystem->AddMappingContext(URWTHVRUtilities::IsDesktopMode() ? IMCDesktopRotation : IMCTurn, 0);
UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(PlayerInputComponent);
......@@ -48,7 +48,7 @@ void UTurnComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
if (bAllowTurning)
{
// no snap turning for desktop mode
if (bSnapTurn && !UVirtualRealityUtilities::IsDesktopMode())
if (bSnapTurn && !URWTHVRUtilities::IsDesktopMode())
{
EI->BindAction(Turn, ETriggerEvent::Started, this, &UTurnComponent::OnBeginSnapTurn);
}
......@@ -59,7 +59,7 @@ void UTurnComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
}
// bind additional functions for desktop rotations
if (UVirtualRealityUtilities::IsDesktopMode())
if (URWTHVRUtilities::IsDesktopMode())
{
EI->BindAction(DesktopRotation, ETriggerEvent::Started, this, &UTurnComponent::StartDesktopRotation);
EI->BindAction(DesktopRotation, ETriggerEvent::Completed, this, &UTurnComponent::EndDesktopRotation);
......@@ -79,7 +79,7 @@ void UTurnComponent::EndDesktopRotation()
void UTurnComponent::OnBeginTurn(const FInputActionValue& Value)
{
if (UVirtualRealityUtilities::IsDesktopMode() && !bApplyDesktopRotation)
if (URWTHVRUtilities::IsDesktopMode() && !bApplyDesktopRotation)
return;
if (!VRPawn || !VRPawn->Controller)
......@@ -89,7 +89,7 @@ void UTurnComponent::OnBeginTurn(const FInputActionValue& Value)
if (TurnValue.X != 0.f)
{
if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation)
if (URWTHVRUtilities::IsDesktopMode() && bApplyDesktopRotation)
{
VRPawn->AddControllerYawInput(TurnRateFactor * TurnValue.X);
}
......@@ -101,7 +101,7 @@ void UTurnComponent::OnBeginTurn(const FInputActionValue& Value)
if (TurnValue.Y != 0.f)
{
if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation)
if (URWTHVRUtilities::IsDesktopMode() && bApplyDesktopRotation)
{
VRPawn->AddControllerPitchInput(TurnRateFactor * -TurnValue.Y);
}
......
......@@ -13,7 +13,7 @@
#include "Pawn/ReplicatedCameraComponent.h"
#include "Pawn/ReplicatedMotionControllerComponent.h"
#include "Roles/LiveLinkTransformTypes.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
......@@ -42,7 +42,7 @@ void AVirtualRealityPawn::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (UVirtualRealityUtilities::IsDesktopMode() && IsLocallyControlled())
if (URWTHVRUtilities::IsDesktopMode() && IsLocallyControlled())
{
SetCameraOffset();
UpdateRightHandForDesktopInteraction();
......@@ -64,7 +64,7 @@ void AVirtualRealityPawn::NotifyControllerChanged()
if (IsLocallyControlled())
{
// Only do this for the primary node or when we're running in standalone
if (UVirtualRealityUtilities::IsRoomMountedMode() && (UVirtualRealityUtilities::IsPrimaryNode() ||
if (URWTHVRUtilities::IsRoomMountedMode() && (URWTHVRUtilities::IsPrimaryNode() ||
GetNetMode() == NM_Standalone))
{
// If we are also the authority (standalone or listen server), directly attach it to us.
......@@ -105,14 +105,14 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput
// Don't do anything with the type if it's been set to clustertype or anything.
const bool bClusterType = Type == EPlayerType::nDisplayPrimary || Type == EPlayerType::nDisplaySecondary;
if (!bClusterType && UVirtualRealityUtilities::IsHeadMountedMode())
if (!bClusterType && URWTHVRUtilities::IsHeadMountedMode())
{
// Could be too early to call this RPC...
State->RequestSetPlayerType(Type);
}
}
if (UVirtualRealityUtilities::IsDesktopMode())
if (URWTHVRUtilities::IsDesktopMode())
{
PlayerController->bShowMouseCursor = true;
PlayerController->bEnableClickEvents = true;
......@@ -129,7 +129,7 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput
void AVirtualRealityPawn::EvaluateLivelink() const
{
if (UVirtualRealityUtilities::IsRoomMountedMode() && IsLocallyControlled())
if (URWTHVRUtilities::IsRoomMountedMode() && IsLocallyControlled())
{
if (bDisableLiveLink || HeadSubjectRepresentation.Subject.IsNone() || HeadSubjectRepresentation.Role == nullptr)
{
......@@ -214,12 +214,12 @@ void AVirtualRealityPawn::SetupMotionControllerSources()
FName MotionControllerSourceLeft = EName::None;
FName MotionControllerSourceRight = EName::None;
if (UVirtualRealityUtilities::IsHeadMountedMode())
if (URWTHVRUtilities::IsHeadMountedMode())
{
MotionControllerSourceLeft = FName("Left");
MotionControllerSourceRight = FName("Right");
}
if (UVirtualRealityUtilities::IsRoomMountedMode())
if (URWTHVRUtilities::IsRoomMountedMode())
{
MotionControllerSourceLeft = LeftSubjectRepresentation.Subject;
MotionControllerSourceRight = RightSubjectRepresentation.Subject;
......
#include "Utility/VirtualRealityUtilities.h"
#include "Utility/RWTHVRUtilities.h"
#if PLATFORM_SUPPORTS_NDISPLAY
#include "DisplayClusterConfigurationTypes.h"
......@@ -20,12 +20,12 @@
DEFINE_LOG_CATEGORY(Toolkit);
bool UVirtualRealityUtilities::IsDesktopMode()
bool URWTHVRUtilities::IsDesktopMode()
{
return !IsRoomMountedMode() && !IsHeadMountedMode();
}
bool UVirtualRealityUtilities::IsRoomMountedMode()
bool URWTHVRUtilities::IsRoomMountedMode()
{
#if PLATFORM_SUPPORTS_NDISPLAY
return IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster;
......@@ -34,17 +34,18 @@ bool UVirtualRealityUtilities::IsRoomMountedMode()
#endif
}
bool UVirtualRealityUtilities::IsHeadMountedMode()
bool URWTHVRUtilities::IsHeadMountedMode()
{
// In editor builds: checks for EdEngine->IsVRPreviewActive()
// In packaged builds: checks for `-vr` in commandline or bStartInVR in UGeneralProjectSettings
return FAudioDevice::CanUseVRAudioDevice();
}
bool UVirtualRealityUtilities::IsCave()
bool URWTHVRUtilities::IsCave()
{
#if PLATFORM_SUPPORTS_NDISPLAY
if (!IsRoomMountedMode()) return false;
if (!IsRoomMountedMode())
return false;
const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig();
return ClusterConfig->CustomParameters.Contains("Hardware_Platform")
......@@ -54,24 +55,11 @@ bool UVirtualRealityUtilities::IsCave()
#endif
}
bool UVirtualRealityUtilities::IsTdw()
bool URWTHVRUtilities::IsRolv()
{
#if PLATFORM_SUPPORTS_NDISPLAY
if (!IsRoomMountedMode()) return false;
const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig();
return ClusterConfig->CustomParameters.Contains("Hardware_Platform")
&& ClusterConfig->CustomParameters.Find("Hardware_Platform")->Equals(
"TiledDisplayWall", ESearchCase::IgnoreCase);
#else
if (!IsRoomMountedMode())
return false;
#endif
}
bool UVirtualRealityUtilities::IsRolv()
{
#if PLATFORM_SUPPORTS_NDISPLAY
if (!IsRoomMountedMode()) return false;
const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig();
return ClusterConfig->CustomParameters.Contains("Hardware_Platform")
......@@ -82,7 +70,7 @@ bool UVirtualRealityUtilities::IsRolv()
}
/* Return true on the Primary in cluster mode and in a normal desktop session. Otherwise false */
bool UVirtualRealityUtilities::IsPrimaryNode()
bool URWTHVRUtilities::IsPrimaryNode()
{
#if PLATFORM_SUPPORTS_NDISPLAY
if (!IDisplayCluster::IsAvailable())
......@@ -100,12 +88,12 @@ bool UVirtualRealityUtilities::IsPrimaryNode()
#endif
}
bool UVirtualRealityUtilities::IsSecondaryNode()
bool URWTHVRUtilities::IsSecondaryNode()
{
return !IsPrimaryNode();
}
FString UVirtualRealityUtilities::GetNodeName()
FString URWTHVRUtilities::GetNodeName()
{
#if PLATFORM_SUPPORTS_NDISPLAY
return IsRoomMountedMode() ? IDisplayCluster::Get().GetClusterMgr()->GetNodeId() : FString(TEXT("Localhost"));
......@@ -114,7 +102,7 @@ FString UVirtualRealityUtilities::GetNodeName()
#endif
}
float UVirtualRealityUtilities::GetEyeDistance()
float URWTHVRUtilities::GetEyeDistance()
{
if (IsHeadMountedMode())
{
......@@ -123,7 +111,7 @@ float UVirtualRealityUtilities::GetEyeDistance()
else
{
#if PLATFORM_SUPPORTS_NDISPLAY
ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor();
const ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor();
return (RootActor) ? RootActor->GetDefaultCamera()->GetInterpupillaryDistance() : 0.0f;
#else
return 0.0f;
......@@ -131,10 +119,10 @@ float UVirtualRealityUtilities::GetEyeDistance()
}
}
EEyeStereoOffset UVirtualRealityUtilities::GetNodeEyeType()
EEyeStereoOffset URWTHVRUtilities::GetNodeEyeType()
{
#if PLATFORM_SUPPORTS_NDISPLAY
ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor();
const ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor();
return static_cast<EEyeStereoOffset>((RootActor)
? RootActor->GetDefaultCamera()->GetStereoOffset()
: EDisplayClusterEyeStereoOffset::None);
......@@ -143,7 +131,7 @@ EEyeStereoOffset UVirtualRealityUtilities::GetNodeEyeType()
#endif
}
USceneComponent* UVirtualRealityUtilities::GetClusterComponent(const FString& Name)
USceneComponent* URWTHVRUtilities::GetClusterComponent(const FString& Name)
{
#if PLATFORM_SUPPORTS_NDISPLAY
const ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor();
......@@ -153,31 +141,41 @@ USceneComponent* UVirtualRealityUtilities::GetClusterComponent(const FString& Na
#endif
}
USceneComponent* UVirtualRealityUtilities::GetNamedClusterComponent(const ENamedClusterComponent& Component)
USceneComponent* URWTHVRUtilities::GetNamedClusterComponent(const ENamedClusterComponent& Component)
{
switch (Component)
{
case ENamedClusterComponent::NCC_CAVE_ORIGIN: return GetClusterComponent("cave_origin");
case ENamedClusterComponent::NCC_CAVE_CENTER: return GetClusterComponent("cave_center");
case ENamedClusterComponent::NCC_CAVE_LHT: return GetClusterComponent("left_hand_target");
case ENamedClusterComponent::NCC_CAVE_RHT: return GetClusterComponent("right_hand_target");
case ENamedClusterComponent::NCC_SHUTTERGLASSES: return GetClusterComponent("shutter_glasses");
case ENamedClusterComponent::NCC_ROLV_ORIGIN: return GetClusterComponent("rolv_origin");
case ENamedClusterComponent::NCC_FLYSTICK: return GetClusterComponent("flystick");
case ENamedClusterComponent::NCC_TDW_ORIGIN: return GetClusterComponent("tdw_origin_floor");
case ENamedClusterComponent::NCC_TDW_CENTER: return GetClusterComponent("tdw_center");
case ENamedClusterComponent::NCC_CALIBRATIO: return GetClusterComponent("calibratio");
case ENamedClusterComponent::NCC_CAVE_ORIGIN:
return GetClusterComponent("cave_origin");
case ENamedClusterComponent::NCC_CAVE_CENTER:
return GetClusterComponent("cave_center");
case ENamedClusterComponent::NCC_CAVE_LHT:
return GetClusterComponent("left_hand_target");
case ENamedClusterComponent::NCC_CAVE_RHT:
return GetClusterComponent("right_hand_target");
case ENamedClusterComponent::NCC_SHUTTERGLASSES:
return GetClusterComponent("shutter_glasses");
case ENamedClusterComponent::NCC_ROLV_ORIGIN:
return GetClusterComponent("rolv_origin");
case ENamedClusterComponent::NCC_FLYSTICK:
return GetClusterComponent("flystick");
case ENamedClusterComponent::NCC_CALIBRATIO:
return GetClusterComponent("calibratio");
case ENamedClusterComponent::NCC_TRACKING_ORIGIN:
USceneComponent* Result;
if ((Result = GetClusterComponent("cave_origin"))) return Result;
if ((Result = GetClusterComponent("rolv_origin"))) return Result;
if ((Result = GetClusterComponent("tdw_origin_floor"))) return Result;
if ((Result = GetClusterComponent("cave_origin")))
return Result;
if ((Result = GetClusterComponent("rolv_origin")))
return Result;
if ((Result = GetClusterComponent("tdw_origin_floor")))
return Result;
return nullptr;
default:
return nullptr;
default: return nullptr;
}
}
void UVirtualRealityUtilities::ShowErrorAndQuit(UWorld* WorldContext, const FString& Message)
void URWTHVRUtilities::ShowErrorAndQuit(UWorld* WorldContext, const FString& Message)
{
UE_LOG(Toolkit, Error, TEXT("%s"), *Message)
#if WITH_EDITOR
......
......@@ -4,7 +4,7 @@
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UObject/ConstructorHelpers.h"
#include "VirtualRealityUtilities.generated.h"
#include "RWTHVRUtilities.generated.h"
/**
......@@ -24,10 +24,6 @@ enum class ENamedClusterComponent : uint8
/* ROLV Specific */
NCC_ROLV_ORIGIN UMETA(DisplayName = "ROLV Origin"),
/* TDW Specific */
NCC_TDW_ORIGIN UMETA(DisplayName = "TDW Origin"),
NCC_TDW_CENTER UMETA(DisplayName = "TDW Center"),
/* Non Specific */
NCC_CALIBRATIO UMETA(DisplayName = "Calibratio Motion to Photon Measurement Device"),
NCC_SHUTTERGLASSES UMETA(DisplayName = "CAVE/ROLV/TDW Shutter Glasses"),
......@@ -44,7 +40,7 @@ enum class EEyeStereoOffset
};
UCLASS()
class RWTHVRTOOLKIT_API UVirtualRealityUtilities : public UBlueprintFunctionLibrary
class RWTHVRTOOLKIT_API URWTHVRUtilities : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
......@@ -58,8 +54,6 @@ public:
UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform")
static bool IsCave();
UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform")
static bool IsTdw();
UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform")
static bool IsRolv();
UFUNCTION(BlueprintPure, Category = "DisplayCluster")
......@@ -77,37 +71,14 @@ public:
static EEyeStereoOffset GetNodeEyeType();
//Get Component of Display Cluster by it's name, which is specified in the nDisplay config
UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster")
UE_DEPRECATED(5.4, "GetClusterComponent has been removed because it is obsolete.")
UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster", meta = (DeprecatedFunction))
static USceneComponent* GetClusterComponent(const FString& Name);
UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster")
static USceneComponent* GetNamedClusterComponent(const ENamedClusterComponent& Component);
/* Load and create an Object from an asset path. This only works in the constructor */
template <class T>
static bool LoadAsset(const FString& Path, T*& Result);
/* Finds and returns a class of an asset. This only works in the constructor */
template <class T>
static bool LoadClass(const FString& Path, TSubclassOf<T>& Result);
UE_DEPRECATED(5.4, "GetNamedClusterComponent has been removed because it is obsolete.")
UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster", meta = (DeprecatedFunction))
static USceneComponent* GetNamedClusterComponent(const ENamedClusterComponent& Component);
UFUNCTION(BlueprintCallable)
static void ShowErrorAndQuit(UWorld* WorldContext, const FString& Message);
};
template <typename T>
bool UVirtualRealityUtilities::LoadAsset(const FString& Path, T* & Result)
{
ConstructorHelpers::FObjectFinder<T> Loader(*Path);
Result = Loader.Object;
if (!Loader.Succeeded()) UE_LOG(LogTemp, Error, TEXT("Could not find %s. Have you renamed it?"), *Path);
return Loader.Succeeded();
}
template <typename T>
bool UVirtualRealityUtilities::LoadClass(const FString& Path, TSubclassOf<T>& Result)
{
ConstructorHelpers::FClassFinder<T> Loader(*Path);
Result = Loader.Class;
if (!Loader.Succeeded()) UE_LOG(LogTemp, Error, TEXT("Could not find %s. Have you renamed it?"), *Path);
return Loader.Succeeded();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment