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
No related tags found
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
// If not, just ingore all related args.
ARWTHVRPlayerState* State = Cast<ARWTHVRPlayerState>(NewPlayerController->PlayerState);
bool bIsClusterNode = false;
if (State != nullptr)
{
int32 ClusterId = -1;
......@@ -49,10 +51,12 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
const EPlayerType Type =
NodeName == PrimaryNodeId ? EPlayerType::nDisplayPrimary : EPlayerType::nDisplaySecondary;
State->RequestSetPlayerType(Type);
bIsClusterNode = true;
}
else if (GetNetMode() == NM_Standalone && URWTHVRUtilities::IsRoomMountedMode())
{
ClusterId = 0;
bIsClusterNode = true;
}
// 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
State->SetCorrespondingClusterId(ClusterId);
auto* ClusterRepresentation = ConnectedClusters.Find(ClusterId);
if (!ClusterRepresentation)
if (bIsClusterNode)
{
AClusterRepresentationActor** ClusterRepresentationPtr = ConnectedClusters.Find(ClusterId);
AClusterRepresentationActor* ClusterRepresentation;
if (!ClusterRepresentationPtr)
{
// No actor there yet, spawn it
FActorSpawnParameters SpawnParameters;
SpawnParameters.Name = FName(*FString::Printf(TEXT("ClusterRepresentation_%d"), ClusterId));
SpawnParameters.NameMode = FActorSpawnParameters::ESpawnActorNameMode::Requested;
ClusterRepresentation = GetWorld()->SpawnActor<AClusterRepresentationActor>(SpawnParameters);
ClusterRepresentation->ClusterId = ClusterId;
UE_LOGFMT(Toolkit, Display,
"ARWTHVRGameModeBase: Spawned ClusterRepresentationActor {Name} for Cluster {Id}",
ClusterRepresentation->GetName(), ClusterId);
ConnectedClusters.Add(ClusterId, ClusterRepresentation);
}
else
{
ClusterRepresentation = *ClusterRepresentationPtr;
}
UE_LOGFMT(Toolkit, Display, "ARWTHVRGameModeBase: Using ClusterRepresentationActor {Name} for Cluster {Id}",
ClusterRepresentation->GetName(), ClusterId);
*ClusterRepresentation->GetName(), ClusterId);
// Double check for sanity
check(ClusterId == ClusterRepresentation->ClusterId);
State->SetCorrespondingClusterActor(ClusterRepresentation);
State->SetCorrespondingClusterId(ClusterId);
if (State->GetPlayerType() == EPlayerType::nDisplayPrimary)
{
......@@ -88,6 +100,7 @@ FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerControlle
ClusterRepresentation->SetOwner(NewPlayerController);
}
}
}
return Super::InitNewPlayer(NewPlayerController, UniqueId, Options, Portal);
}
......
......@@ -35,5 +35,7 @@ protected:
virtual void PostLogin(APlayerController* NewPlayer) override;
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