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

fix(replication, cave): Fixes an issue in Find() and actually adds the Cluster...

fix(replication, cave): Fixes an issue in Find() and actually adds the Cluster representation to the gamemode's map
parent 2f8bb7d2
Branches
Tags 9.3.6
2 merge requests!107UE5.4-2024.1-rc1,!98Improved join/attachment logic for clusters to support multi-cluster connections at some point
...@@ -29,6 +29,8 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle ...@@ -29,6 +29,8 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
// If not, just ingore all related args. // If not, just ingore all related args.
ARWTHVRPlayerState* State = Cast<ARWTHVRPlayerState>(NewPlayerController->PlayerState); ARWTHVRPlayerState* State = Cast<ARWTHVRPlayerState>(NewPlayerController->PlayerState);
bool bIsClusterNode = false;
if (State != nullptr) if (State != nullptr)
{ {
int32 ClusterId = -1; int32 ClusterId = -1;
...@@ -49,10 +51,12 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle ...@@ -49,10 +51,12 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
const EPlayerType Type = const EPlayerType Type =
NodeName == PrimaryNodeId ? EPlayerType::nDisplayPrimary : EPlayerType::nDisplaySecondary; NodeName == PrimaryNodeId ? EPlayerType::nDisplayPrimary : EPlayerType::nDisplaySecondary;
State->RequestSetPlayerType(Type); State->RequestSetPlayerType(Type);
bIsClusterNode = true;
} }
else if (GetNetMode() == NM_Standalone && URWTHVRUtilities::IsRoomMountedMode()) else if (GetNetMode() == NM_Standalone && URWTHVRUtilities::IsRoomMountedMode())
{ {
ClusterId = 0; ClusterId = 0;
bIsClusterNode = true;
} }
// If we're in none-standalone netmode, this is only executed on the server, as the GM only exists there. // If we're in none-standalone netmode, this is only executed on the server, as the GM only exists there.
...@@ -60,27 +64,35 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle ...@@ -60,27 +64,35 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
State->SetCorrespondingClusterId(ClusterId); State->SetCorrespondingClusterId(ClusterId);
auto* ClusterRepresentation = ConnectedClusters.Find(ClusterId); if (bIsClusterNode)
if (!ClusterRepresentation) {
AClusterRepresentationActor** ClusterRepresentationPtr = ConnectedClusters.Find(ClusterId);
AClusterRepresentationActor* ClusterRepresentation;
if (!ClusterRepresentationPtr)
{ {
// No actor there yet, spawn it // No actor there yet, spawn it
FActorSpawnParameters SpawnParameters; FActorSpawnParameters SpawnParameters;
SpawnParameters.Name = FName(*FString::Printf(TEXT("ClusterRepresentation_%d"), ClusterId)); SpawnParameters.Name = FName(*FString::Printf(TEXT("ClusterRepresentation_%d"), ClusterId));
SpawnParameters.NameMode = FActorSpawnParameters::ESpawnActorNameMode::Requested;
ClusterRepresentation = GetWorld()->SpawnActor<AClusterRepresentationActor>(SpawnParameters); ClusterRepresentation = GetWorld()->SpawnActor<AClusterRepresentationActor>(SpawnParameters);
ClusterRepresentation->ClusterId = ClusterId; ClusterRepresentation->ClusterId = ClusterId;
UE_LOGFMT(Toolkit, Display, UE_LOGFMT(Toolkit, Display,
"ARWTHVRGameModeBase: Spawned ClusterRepresentationActor {Name} for Cluster {Id}", "ARWTHVRGameModeBase: Spawned ClusterRepresentationActor {Name} for Cluster {Id}",
ClusterRepresentation->GetName(), ClusterId); ClusterRepresentation->GetName(), ClusterId);
ConnectedClusters.Add(ClusterId, ClusterRepresentation);
}
else
{
ClusterRepresentation = *ClusterRepresentationPtr;
} }
UE_LOGFMT(Toolkit, Display, "ARWTHVRGameModeBase: Using ClusterRepresentationActor {Name} for Cluster {Id}", UE_LOGFMT(Toolkit, Display, "ARWTHVRGameModeBase: Using ClusterRepresentationActor {Name} for Cluster {Id}",
ClusterRepresentation->GetName(), ClusterId); *ClusterRepresentation->GetName(), ClusterId);
// Double check for sanity // Double check for sanity
check(ClusterId == ClusterRepresentation->ClusterId); check(ClusterId == ClusterRepresentation->ClusterId);
State->SetCorrespondingClusterActor(ClusterRepresentation); State->SetCorrespondingClusterActor(ClusterRepresentation);
State->SetCorrespondingClusterId(ClusterId);
if (State->GetPlayerType() == EPlayerType::nDisplayPrimary) if (State->GetPlayerType() == EPlayerType::nDisplayPrimary)
{ {
...@@ -88,6 +100,7 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle ...@@ -88,6 +100,7 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
ClusterRepresentation->SetOwner(NewPlayerController); ClusterRepresentation->SetOwner(NewPlayerController);
} }
} }
}
return Super::InitNewPlayer(NewPlayerController, UniqueId, Options, Portal); return Super::InitNewPlayer(NewPlayerController, UniqueId, Options, Portal);
} }
......
...@@ -35,5 +35,7 @@ protected: ...@@ -35,5 +35,7 @@ protected:
virtual void PostLogin(APlayerController* NewPlayer) override; virtual void PostLogin(APlayerController* NewPlayer) override;
private: private:
TMap<int32, AClusterRepresentationActor> ConnectedClusters;
UPROPERTY()
TMap<int32, AClusterRepresentationActor*> ConnectedClusters;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment