Skip to content
Snippets Groups Projects

feature(replication, pawn): Adds (initial) different way to attach DCRA to...

Merged David Gilbert requested to merge feature/replication_improvements into dev/5.4
2 files
+ 27
37
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,6 +6,7 @@
#include "Engine/LocalPlayer.h"
#include "GameFramework/PlayerController.h"
#include "ILiveLinkClient.h"
#include "InputMappingContext.h"
#include "Core/RWTHVRPlayerState.h"
#include "Kismet/GameplayStatics.h"
#include "Logging/StructuredLog.h"
@@ -65,34 +66,23 @@ void ARWTHVRPawn::NotifyControllerChanged()
{
Super::NotifyControllerChanged();
UE_LOG(Toolkit, Display,
TEXT("ARWTHVRPawn: Player Controller has changed, trying to change DCRA attachment if possible..."));
// Try and use PlayerType for this:
// Only do this for all local controlled pawns
if (IsLocallyControlled())
if (HasAuthority())
{
UE_LOG(Toolkit, Display,
TEXT("ARWTHVRPawn: Player Controller has changed for local pawn, trying to change DCRA attachment if "
"possible..."));
// Only do this for the primary node or when we're running in standalone
if (URWTHVRUtilities::IsRoomMountedMode() &&
(URWTHVRUtilities::IsPrimaryNode() || GetNetMode() == NM_Standalone))
TEXT("ARWTHVRPawn: Player Controller has changed, trying to change DCRA attachment if possible..."));
if (const ARWTHVRPlayerState* State = GetPlayerState<ARWTHVRPlayerState>())
{
UE_LOG(Toolkit, Display,
TEXT("ARWTHVRPawn: We're the primary node, we want the DCRA attached to our pawn."));
// If we are also the authority (standalone or listen server), directly attach it to us.
// If we are not (client), ask the server to do it.
if (HasAuthority())
const EPlayerType Type = State->GetPlayerType();
// Only cluster types are valid here as they are set on connection.
// For all other player types this is a race condition
if (Type == EPlayerType::nDisplayPrimary || GetNetMode() == NM_Standalone)
{
UE_LOG(Toolkit, Display, TEXT("ARWTHVRPawn: We have authority, do the attachment."));
UE_LOGFMT(Toolkit, Display, "ARWTHVRPawn: Attaching DCRA to Pawn {Pawn}.", GetName());
AttachDCRAtoPawn();
}
else
{
UE_LOG(Toolkit, Display, TEXT("ARWTHVRPawn: We don't have authority, ask the sercer to attach."));
ServerAttachDCRAtoPawnRpc();
}
}
}
}
@@ -110,6 +100,10 @@ void ARWTHVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
return;
}
UE_LOGFMT(Toolkit, Display, "SetupPlayerInputComponent: Player Controller is valid, setting up input for {Pawn}",
GetName());
// Set the control rotation of the PC to zero again. There is a small period of 2 frames where, when the pawn gets
// possessed, the PC takes on the rotation of the VR Headset ONLY WHEN SPAWNING ON A CLIENT. Reset the rotation here
// such that bUseControllerRotationYaw=true does not pass the wrong yaw value to the pawn initially. There is
@@ -125,6 +119,7 @@ void ARWTHVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
const EPlayerType Type = State->GetPlayerType();
// Don't do anything with the type if it's been set to clustertype or anything.
// This is already being done when connecting to the server.
const bool bClusterType = Type == EPlayerType::nDisplayPrimary || Type == EPlayerType::nDisplaySecondary;
if (!bClusterType && URWTHVRUtilities::IsHeadMountedMode())
@@ -149,9 +144,16 @@ void ARWTHVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
}
// bind the current mapping contexts
for (const auto& Mapping : InputMappingContexts)
for (const auto Mapping : InputMappingContexts)
{
AddInputMappingContext(PlayerController, Mapping);
if (Mapping && IsValid(Mapping))
{
AddInputMappingContext(PlayerController, Mapping);
}
else
{
UE_LOGFMT(Toolkit, Warning, "ARWTHVRPawn::SetupPlayerInputComponent: InputMappingContext was invalid!");
}
}
}
@@ -257,7 +259,6 @@ void ARWTHVRPawn::MulticastAddDCSyncComponent_Implementation()
#endif
}
// Todo rewrite this in some other way or attach it differently, this is horrible
// Executed on the server only: Finds and attaches the CaveSetup Actor, which contains the DCRA to the Pawn.
// It is only executed on the server because attachments are synced to all clients, but not from client to server.
void ARWTHVRPawn::AttachDCRAtoPawn()
@@ -285,8 +286,8 @@ void ARWTHVRPawn::AttachDCRAtoPawn()
"No CaveSetup Actor found which can be attached to the Pawn! This won't work on the Cave.");
}
if (HasAuthority()) // Should always be the case here, but double check
MulticastAddDCSyncComponent();
// if (HasAuthority()) // Should always be the case here, but double check
// MulticastAddDCSyncComponent();
}
void ARWTHVRPawn::SetupMotionControllerSources()
@@ -309,13 +310,6 @@ void ARWTHVRPawn::SetupMotionControllerSources()
RightHand->SetTrackingMotionSource(MotionControllerSourceRight);
}
// Requests the server to perform the attachment, as only the server can sync this to all the other clients.
void ARWTHVRPawn::ServerAttachDCRAtoPawnRpc_Implementation()
{
// We're on the server here - attach the actor to the pawn.
AttachDCRAtoPawn();
}
void ARWTHVRPawn::SetCameraOffset() const
{
// this also incorporates the BaseEyeHeight, if set as static offset,
Loading