200 - Limiting Server-Side Rewind

This commit is contained in:
Kingsmedia 2022-05-28 11:16:42 +02:00
parent 6acf090c07
commit 9e64e70607
6 changed files with 56 additions and 1 deletions

Binary file not shown.

View File

@ -75,6 +75,10 @@ void ABlasterPlayerController::CheckPing(float DeltaTime)
{
HighPingWarning();
PingAnimationRunningTime = 0.f;
ServerReportPingStatus(true);
} else
{
ServerReportPingStatus(false);
}
}
}
@ -95,6 +99,11 @@ void ABlasterPlayerController::CheckPing(float DeltaTime)
}
}
// Is the ping to high?
void ABlasterPlayerController::ServerReportPingStatus_Implementation(bool bHighPing)
{
HighPingDelegate.Broadcast(bHighPing);
}
void ABlasterPlayerController::SetDebugMsg2(FString Key, FString Value)
{

View File

@ -6,6 +6,8 @@
#include "GameFramework/PlayerController.h"
#include "BlasterPlayerController.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHighPingDelegate, bool, bPingTooHigh);
/**
*
*/
@ -47,6 +49,8 @@ public:
float SingleTripTime = 0.f;
FHighPingDelegate HighPingDelegate;
protected:
virtual void BeginPlay() override;
@ -139,6 +143,10 @@ private:
float PingAnimationRunningTime = 0.f;
UPROPERTY(EditAnywhere)
float CheckPingFrequency = 20.f;
UFUNCTION(Server, Reliable)
void ServerReportPingStatus(bool bHighPing);
UPROPERTY(EditAnywhere)
float HighPingThreshold = 50.f;
};

View File

@ -45,6 +45,7 @@ void AWeapon::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeP
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AWeapon, WeaponState);
DOREPLIFETIME_CONDITION(AWeapon, bUseServerSideRewind, COND_OwnerOnly);
}
void AWeapon::EnableCustomDepth(bool bEnabled)
@ -190,6 +191,11 @@ void AWeapon::OnWeaponStateSet()
}
}
void AWeapon::OnPingTooHigh(bool bPingTooHigh)
{
bUseServerSideRewind = !bPingTooHigh;
}
void AWeapon::OnRep_WeaponState()
{
OnWeaponStateSet();
@ -209,6 +215,16 @@ void AWeapon::OnEquipped()
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
}
EnableCustomDepth(false);
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : OwnerCharacter;
if (OwnerCharacter && bUseServerSideRewind)
{
OwnerController = OwnerController == nullptr ? Cast<ABlasterPlayerController>(OwnerCharacter->Controller) : OwnerController;
if (OwnerController && HasAuthority() && !OwnerController->HighPingDelegate.IsBound())
{
OwnerController->HighPingDelegate.AddDynamic(this, &AWeapon::OnPingTooHigh);
}
}
}
void AWeapon::OnEquippedSecondary()
@ -230,6 +246,15 @@ void AWeapon::OnEquippedSecondary()
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_TAN);
WeaponMesh->MarkRenderStateDirty();
}
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : OwnerCharacter;
if (OwnerCharacter && bUseServerSideRewind)
{
OwnerController = OwnerController == nullptr ? Cast<ABlasterPlayerController>(OwnerCharacter->Controller) : OwnerController;
if (OwnerController && HasAuthority() && OwnerController->HighPingDelegate.IsBound())
{
OwnerController->HighPingDelegate.RemoveDynamic(this, &AWeapon::OnPingTooHigh);
}
}
}
void AWeapon::OnDropped()
@ -247,6 +272,16 @@ void AWeapon::OnDropped()
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_BLUE);
WeaponMesh->MarkRenderStateDirty();
EnableCustomDepth(true);
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : OwnerCharacter;
if (OwnerCharacter && bUseServerSideRewind)
{
OwnerController = OwnerController == nullptr ? Cast<ABlasterPlayerController>(OwnerCharacter->Controller) : OwnerController;
if (OwnerController && HasAuthority() && OwnerController->HighPingDelegate.IsBound())
{
OwnerController->HighPingDelegate.RemoveDynamic(this, &AWeapon::OnPingTooHigh);
}
}
}

View File

@ -127,7 +127,7 @@ protected:
UPROPERTY(EditAnywhere)
float Damage = 20.f;
UPROPERTY(EditAnywhere)
UPROPERTY(Replicated, EditAnywhere)
bool bUseServerSideRewind = false;
UPROPERTY()
@ -136,6 +136,9 @@ protected:
UPROPERTY()
class ABlasterPlayerController* OwnerController;
UFUNCTION()
void OnPingTooHigh(bool bPingTooHigh);
private:
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
USkeletalMeshComponent* WeaponMesh;