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

Added comments

parent ba93e864
No related branches found
No related tags found
1 merge request!31Initial Pawn Replication
// Fill out your copyright notice in the Description page of Project Settings.
#include "Core/ClientTransformReplication.h"
#include "Net/UnrealNetwork.h"
......@@ -18,7 +17,6 @@ UClientTransformReplication::UClientTransformReplication()
}
// Naive direct transform replication (replace with input rep?)
void UClientTransformReplication::UpdateState(float DeltaTime)
{
const auto* OwningActor = GetOwner();
......
......@@ -11,9 +11,13 @@
FString ARWTHVRGameModeBase::InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId,
const FString& Options, const FString& Portal)
{
// Used by the DisplayClusterNetDriver/Connection to handshake nodes. Could use their types directly
// but I don't really want to introduce a hard dependency here.
const FString NodeNameKey = "node";
const FString PrimaryNodeIdKey = "PrimaryNodeId";
// Check if we're using our custom PlayerState so that we can save the player type there.
// If not, just ingore all related args.
ARWTHVRPlayerState* State = Cast<ARWTHVRPlayerState>(NewPlayerController->PlayerState);
if (State != nullptr)
......
......@@ -3,10 +3,10 @@
#include "Core/RWTHVRPlayerState.h"
#include "Logging/StructuredLog.h"
#include "Net/UnrealNetwork.h"
#include "Net/Core/PushModel/PushModel.h"
// Boilerplate, copies properties to new state
void ARWTHVRPlayerState::CopyProperties(class APlayerState* PlayerState)
{
Super::CopyProperties(PlayerState);
......@@ -21,6 +21,7 @@ void ARWTHVRPlayerState::CopyProperties(class APlayerState* PlayerState)
}
}
// Boilerplate
void ARWTHVRPlayerState::OverrideWith(class APlayerState* PlayerState)
{
Super::OverrideWith(PlayerState);
......@@ -35,6 +36,7 @@ void ARWTHVRPlayerState::OverrideWith(class APlayerState* PlayerState)
}
}
// Replicate our property similar to the other state properties
void ARWTHVRPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
......
......@@ -3,6 +3,7 @@
#include "CoreMinimal.h"
#include "VRTransformRep.generated.h"
// Simple custom transform struct for more efficient repliation, from VRE Plugin
USTRUCT()
struct RWTHVRTOOLKIT_API FVRTransformRep
{
......
......@@ -2,6 +2,7 @@
#include "Pawn/ReplicatedCameraComponent.h"
#include "Net/UnrealNetwork.h"
UReplicatedCameraComponent::UReplicatedCameraComponent()
......
......@@ -8,13 +8,16 @@
#include "ClientTransformReplication.generated.h"
/*
* Simple Client Transform Replication Component. Replicates the owning actor's root transform from owning client to server,
* from there to all other clients.
*/
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UClientTransformReplication : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UClientTransformReplication();
protected:
......@@ -39,26 +42,28 @@ protected:
// Accumulates time until next send
float ControllerNetUpdateCount;
// Replicated transform property - used to replicate from server to all non-owning clients
UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedTransform, Category = "Networking")
FVRTransformRep ReplicatedTransform;
void UpdateState(float DeltaTime);
// Called whenever ReplicatedTransform is replicated to clients. Not called on Server/Owning client
UFUNCTION()
virtual void OnRep_ReplicatedTransform()
{
// Modify pawn position - how does this work in movement components?
// Modify owner position - how does this work in movement components?
// For now, directly apply the transforms:
auto* OwningActor = GetOwner();
if (OwningActor && OwningActor->HasValidRootComponent())
OwningActor->SetActorLocationAndRotation(ReplicatedTransform.Position, ReplicatedTransform.Rotation);
}
// Unreliable Server RPC that sends the transform from owning client to the server
UFUNCTION(Unreliable, Server, WithValidation)
void SendControllerTransform_ServerRpc(FVRTransformRep NewTransform);
void UpdateState(float DeltaTime);
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
};
......@@ -7,7 +7,9 @@
#include "RWTHVRGameModeBase.generated.h"
/**
*
* Simple GameModeBase extension that checks for join options such that we can distinguish between primary
* and secondary nodes in clusters. Could be moved to a different place as well, but quite reasonable here for now.
* Keep in mind that GameMode only exists on the server!
*/
UCLASS()
class RWTHVRTOOLKIT_API ARWTHVRGameModeBase : public AGameModeBase
......
......@@ -4,11 +4,11 @@
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Core/VRTransformRep.h"
#include "ReplicatedCameraComponent.generated.h"
/**
*
* Simple CameraComponent with added client-side transform replication.
*/
UCLASS()
class RWTHVRTOOLKIT_API UReplicatedCameraComponent : public UCameraComponent
......
......@@ -4,10 +4,12 @@
#include "CoreMinimal.h"
#include "MotionControllerComponent.h"
#include "Utility/VirtualRealityUtilities.h"
#include "Core/VRTransformRep.h"
#include "ReplicatedMotionControllerComponent.generated.h"
/**
* Simple MotionControllerComponent with added client-side transform replication.
*/
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UReplicatedMotionControllerComponent : public UMotionControllerComponent
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment