Skip to content
Snippets Groups Projects
Commit 7554bfc3 authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

Merge branch 'feature/removeVRPawn' into '4.26'

remove VRPawn reference from HUDHelper

See merge request !9
parents 1c810c00 04b4bbc4
No related branches found
No related tags found
1 merge request!9remove VRPawn reference from HUDHelper
Showing with 94 additions and 25 deletions
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "Engine/Canvas.h" #include "Engine/Canvas.h"
#include "HUD/SFMasterHUD.h" #include "HUD/SFMasterHUD.h"
#include "Utility/VirtualRealityUtilities.h"
// Link to the Tutorial of the manual Viewport Client // Link to the Tutorial of the manual Viewport Client
// https://nerivec.github.io/old-ue4-wiki/pages/global-fade-in-out.html // https://nerivec.github.io/old-ue4-wiki/pages/global-fade-in-out.html
...@@ -77,7 +76,7 @@ void USFGlobalFadeGameViewportClient::DrawScreenFade(UCanvas* Canvas) ...@@ -77,7 +76,7 @@ void USFGlobalFadeGameViewportClient::DrawScreenFade(UCanvas* Canvas)
MasterHUD = Cast<ASFMasterHUD>(PlayerController->GetHUD()); MasterHUD = Cast<ASFMasterHUD>(PlayerController->GetHUD());
} }
if (MasterHUD && UVirtualRealityUtilities::IsMaster()) if (MasterHUD && FSFUtils::IsPrimary())
{ {
//if we use the HUD let it do the fading, so it can still be seen when faded out //if we use the HUD let it do the fading, so it can still be seen when faded out
MasterHUD->SetBackgroundAlpha(FadeColorTmp.A); MasterHUD->SetBackgroundAlpha(FadeColorTmp.A);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "IXRTrackingSystem.h" #include "IXRTrackingSystem.h"
#include "HUD/SFHUDWidget.h" #include "HUD/SFHUDWidget.h"
#include "Pawn/VirtualRealityPawn.h"
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "Slate/SceneViewport.h" #include "Slate/SceneViewport.h"
...@@ -58,15 +57,15 @@ void ASFHMDSpectatorHUDHelp::Tick(float DeltaSeconds) ...@@ -58,15 +57,15 @@ void ASFHMDSpectatorHUDHelp::Tick(float DeltaSeconds)
//the widget needs to be always be facing away, so we do not see it in the HMD view //the widget needs to be always be facing away, so we do not see it in the HMD view
//we also move it down 10m so it does not get in our way when interacting etc. //we also move it down 10m so it does not get in our way when interacting etc.
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); const APlayerCameraManager* CamManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
AVirtualRealityPawn* Pawn = Cast<AVirtualRealityPawn>(PlayerController->AcknowledgedPawn); FVector HeadPos = CamManager->GetCameraLocation();
FVector HeadPos = Pawn->Head->GetComponentLocation();
SetActorLocation(HeadPos + 1000 * FVector::DownVector); SetActorLocation(HeadPos + 1000 * FVector::DownVector);
SetActorRotation(FQuat::FindBetweenNormals(FVector(0,0,1),(GetActorLocation()-HeadPos).GetSafeNormal()).Rotator()); SetActorRotation(FQuat::FindBetweenNormals(FVector(0,0,1),(GetActorLocation()-HeadPos).GetSafeNormal()).Rotator());
//Set cursor to the right place //Set cursor to the right place
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
USFHUDWidget* HUDWidget = Cast<USFHUDWidget>(WidgetComponent->GetWidget()); USFHUDWidget* HUDWidget = Cast<USFHUDWidget>(WidgetComponent->GetWidget());
FVector2D CursorPos = GetAbsoluteLocationForCursorWidgetFromMousePosition(PlayerController, DrawSize); FVector2D CursorPos = GetAbsoluteLocationForCursorWidgetFromMousePosition(PlayerController, DrawSize);
HUDWidget->SetCursorWidgetPosition(CursorPos); HUDWidget->SetCursorWidgetPosition(CursorPos);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "SFPlugin.h" #include "SFPlugin.h"
#include "Help/SFUtils.h" #include "Help/SFUtils.h"
#include "Utility/VirtualRealityUtilities.h"
#include "HeadMountedDisplayFunctionLibrary.h" #include "HeadMountedDisplayFunctionLibrary.h"
...@@ -18,7 +17,7 @@ ASFMasterHUD::ASFMasterHUD() ...@@ -18,7 +17,7 @@ ASFMasterHUD::ASFMasterHUD()
void ASFMasterHUD::DrawHUD() void ASFMasterHUD::DrawHUD()
{ {
if (UVirtualRealityUtilities::IsMaster()) if (FSFUtils::IsPrimary())
{ {
DrawBackground(); DrawBackground();
} }
...@@ -49,13 +48,13 @@ void ASFMasterHUD::BeginPlay() ...@@ -49,13 +48,13 @@ void ASFMasterHUD::BeginPlay()
} }
HMDHUDHelper = nullptr; HMDHUDHelper = nullptr;
if (UVirtualRealityUtilities::IsHeadMountedMode()) if (FSFUtils::IsHMD())
{ {
HMDHUDHelper = Cast<ASFHMDSpectatorHUDHelp>( HMDHUDHelper = Cast<ASFHMDSpectatorHUDHelp>(
GetWorld()->SpawnActor(ASFHMDSpectatorHUDHelp::StaticClass())); GetWorld()->SpawnActor(ASFHMDSpectatorHUDHelp::StaticClass()));
HUDWidget = Cast<USFHUDWidget>(HMDHUDHelper->CreateWidget(SFWidgetClass)); HUDWidget = Cast<USFHUDWidget>(HMDHUDHelper->CreateWidget(SFWidgetClass));
} }
else if (UVirtualRealityUtilities::IsMaster()) else if (FSFUtils::IsPrimary())
{ {
HUDWidget = CreateWidget<USFHUDWidget>(GetWorld(), SFWidgetClass); HUDWidget = CreateWidget<USFHUDWidget>(GetWorld(), SFWidgetClass);
} }
......
...@@ -6,18 +6,19 @@ ...@@ -6,18 +6,19 @@
#include "Misc/MessageDialog.h" #include "Misc/MessageDialog.h"
#include "Misc/FileHelper.h" #include "Misc/FileHelper.h"
#include "AudioDevice.h"
#include "Json.h" #include "Json.h"
#include "SFPlugin.h" #include "SFPlugin.h"
#include "SFGameInstance.h" #include "SFGameInstance.h"
#include "Utility/VirtualRealityUtilities.h"
#include "IUniversalLogging.h" #include "IUniversalLogging.h"
void FSFUtils::OpenMessageBox(const FString Text, const bool bError/*=false*/) void FSFUtils::OpenMessageBox(const FString Text, const bool bError/*=false*/)
{ {
if (!UVirtualRealityUtilities::IsMaster()) if (!IsPrimary())
{ {
return; return;
} }
...@@ -119,3 +120,24 @@ FString FSFUtils::GetStudyFrameworkPath() ...@@ -119,3 +120,24 @@ FString FSFUtils::GetStudyFrameworkPath()
{ {
return FPaths::ProjectDir() + "StudyFramework/"; return FPaths::ProjectDir() + "StudyFramework/";
} }
bool FSFUtils::IsPrimary()
{
if (!IDisplayCluster::IsAvailable())
{
return true;
}
IDisplayClusterClusterManager* Manager = IDisplayCluster::Get().GetClusterMgr();
if (Manager == nullptr)
{
return true; // if we are not in cluster mode, we are always the master
}
return Manager->IsMaster() || !Manager->IsSlave();
}
bool FSFUtils::IsHMD()
{
// In editor builds: checks for EdEngine->IsVRPreviewActive()
// In packaged builds: checks for `-vr` in commandline or bStartInVR in UGeneralProjectSettings
return FAudioDevice::CanUseVRAudioDevice();
}
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "SFGameInstance.h" #include "SFGameInstance.h"
#include "Utility/VirtualRealityUtilities.h"
#include "IUniversalLogging.h" #include "IUniversalLogging.h"
#include "Help/SFUtils.h" #include "Help/SFUtils.h"
......
...@@ -26,7 +26,13 @@ void USFGameInstance::Init() ...@@ -26,7 +26,13 @@ void USFGameInstance::Init()
GEngine->GameViewportClientClass = USFGlobalFadeGameViewportClient::StaticClass(); GEngine->GameViewportClientClass = USFGlobalFadeGameViewportClient::StaticClass();
GoToConditionSyncedEvent.Attach(this); IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr();
if (ClusterManager && !ClusterEventListenerDelegate.IsBound())
{
ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject(this, &USFGameInstance::HandleClusterEvent);
ClusterManager->AddClusterEventJsonListener(ClusterEventListenerDelegate);
}
Instance = this; Instance = this;
LogObject = NewObject<USFLogObject>(); LogObject = NewObject<USFLogObject>();
...@@ -53,7 +59,14 @@ void USFGameInstance::Init() ...@@ -53,7 +59,14 @@ void USFGameInstance::Init()
void USFGameInstance::Shutdown() void USFGameInstance::Shutdown()
{ {
GoToConditionSyncedEvent.Detach();
IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr();
if (ClusterManager && ClusterEventListenerDelegate.IsBound())
{
ClusterManager->RemoveClusterEventJsonListener(ClusterEventListenerDelegate);
}
if(ExperimenterWindow) if(ExperimenterWindow)
{ {
ExperimenterWindow->DestroyWindow(); ExperimenterWindow->DestroyWindow();
...@@ -432,11 +445,47 @@ bool USFGameInstance::GoToCondition(const USFCondition* Condition, bool bForced ...@@ -432,11 +445,47 @@ bool USFGameInstance::GoToCondition(const USFCondition* Condition, bool bForced
FSFLoggingUtils::Log("[USFGameInstance::GoToCondition()]: Could not load next condition.", true); FSFLoggingUtils::Log("[USFGameInstance::GoToCondition()]: Could not load next condition.", true);
return false; return false;
} }
GoToConditionSyncedEvent.Send(Condition->UniqueName, bForced); GoToConditionSynced(Condition->UniqueName, bForced);
return true; return true;
} }
void USFGameInstance::GoToConditionSynced(FString ConditionName, bool bForced) void USFGameInstance::GoToConditionSynced(FString ConditionName, bool bForced)
{
const EDisplayClusterOperationMode OperationMode = IDisplayCluster::Get().GetOperationMode();
if (OperationMode != EDisplayClusterOperationMode::Cluster)
{
HandleGoToConditionSynced(ConditionName, bForced);
}
else
{
IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr();
check(ClusterManager != nullptr);
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Type = "SFGameInstanceEvent";
ClusterEvent.Name = "GoToConditionSynced";
TMap<FString, FString> Params;
Params.Add("ConditionName", ConditionName);
Params.Add("bForced", bForced ?"true":"false");
ClusterEvent.Parameters = Params;
ClusterEvent.bShouldDiscardOnRepeat = true;
ClusterManager->EmitClusterEventJson(ClusterEvent, true);
}
}
void USFGameInstance::HandleClusterEvent(const FDisplayClusterClusterEventJson& Event) {
if (Event.Type == "SFGameInstanceEvent") {
//now we actually react on all cluster nodes:
if(Event.Name == "GoToConditionSynced")
{
HandleGoToConditionSynced(Event.Parameters["ConditionName"], Event.Parameters["bForced"] == "true");
}
}
}
void USFGameInstance::HandleGoToConditionSynced(FString ConditionName, bool bForced)
{ {
USFCondition* NextCondition = nullptr; USFCondition* NextCondition = nullptr;
for (USFCondition* Condition : Participant->GetAllConditions()) for (USFCondition* Condition : Participant->GetAllConditions())
......
...@@ -28,4 +28,7 @@ public: ...@@ -28,4 +28,7 @@ public:
static UWorld* GetWorld(); static UWorld* GetWorld();
static FString GetStudyFrameworkPath(); static FString GetStudyFrameworkPath();
static bool IsPrimary();
static bool IsHMD();
}; };
\ No newline at end of file
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "HUD/SFMasterHUD.h" #include "HUD/SFMasterHUD.h"
#include "GazeTracking/SFGazeTracker.h" #include "GazeTracking/SFGazeTracker.h"
#include "Events/DisplayClusterEventWrapper.h" #include "Cluster/IDisplayClusterClusterManager.h"
#include "Cluster/DisplayClusterClusterEvent.h"
#include "Widgets/SWindow.h" #include "Widgets/SWindow.h"
...@@ -171,8 +172,12 @@ protected: ...@@ -171,8 +172,12 @@ protected:
void EndStudy(); void EndStudy();
void GoToConditionSynced(FString ConditionName, bool bForced); //we use cluster events so GoToConditionSynced can not run out of sync when using nDisplay in cluster mode
DECLARE_DISPLAY_CLUSTER_EVENT(USFGameInstance, GoToConditionSynced); void GoToConditionSynced(FString ConditionName, bool bForced); //send the cluster event
void HandleGoToConditionSynced(FString ConditionName, bool bForced); //process the cluter event
FOnClusterEventJsonListener ClusterEventListenerDelegate;
void HandleClusterEvent(const FDisplayClusterClusterEventJson& Event);
void RestoreLastParticipantForDebugStart(USFCondition* InStartCondition); void RestoreLastParticipantForDebugStart(USFCondition* InStartCondition);
//method called by a timer if we want to directly fade in on startup //method called by a timer if we want to directly fade in on startup
......
...@@ -35,8 +35,6 @@ public class StudyFrameworkPlugin : ModuleRules ...@@ -35,8 +35,6 @@ public class StudyFrameworkPlugin : ModuleRules
"CoreUObject", "CoreUObject",
"Engine", "Engine",
"DisplayCluster", "DisplayCluster",
"RWTHVRToolkit",
"RWTHVRCluster",
"InputCore", "InputCore",
"Sockets", "Sockets",
"Json", "Json",
......
...@@ -25,10 +25,6 @@ ...@@ -25,10 +25,6 @@
"Name": "nDisplay", "Name": "nDisplay",
"Enabled": true "Enabled": true
}, },
{
"Name": "RWTHVRToolkit",
"Enabled": true
},
{ {
"Name": "UniversalLogging", "Name": "UniversalLogging",
"Enabled": true "Enabled": true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment