diff --git a/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset b/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset index 0388b9b..a18dfb2 100644 Binary files a/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset and b/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index f09713c..a2b4085 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 9d9db60..6549fb3 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -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) { diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 2b744f5..df5911c 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -6,6 +6,8 @@ #include "GameFramework/PlayerController.h" #include "BlasterPlayerController.generated.h" +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHighPingDelegate, bool, bPingTooHigh); + /** * */ @@ -46,6 +48,8 @@ public: void HandleCooldown(); float SingleTripTime = 0.f; + + FHighPingDelegate HighPingDelegate; protected: @@ -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; }; diff --git a/Source/Blaster/Weapon/Weapon.cpp b/Source/Blaster/Weapon/Weapon.cpp index 21c3eef..adff03e 100644 --- a/Source/Blaster/Weapon/Weapon.cpp +++ b/Source/Blaster/Weapon/Weapon.cpp @@ -45,6 +45,7 @@ void AWeapon::GetLifetimeReplicatedProps(TArray& 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(GetOwner()) : OwnerCharacter; + if (OwnerCharacter && bUseServerSideRewind) + { + OwnerController = OwnerController == nullptr ? Cast(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(GetOwner()) : OwnerCharacter; + if (OwnerCharacter && bUseServerSideRewind) + { + OwnerController = OwnerController == nullptr ? Cast(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(GetOwner()) : OwnerCharacter; + if (OwnerCharacter && bUseServerSideRewind) + { + OwnerController = OwnerController == nullptr ? Cast(OwnerCharacter->Controller) : OwnerController; + if (OwnerController && HasAuthority() && OwnerController->HighPingDelegate.IsBound()) + { + OwnerController->HighPingDelegate.RemoveDynamic(this, &AWeapon::OnPingTooHigh); + } + } } diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index 12f4049..61b83c9 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -127,7 +127,7 @@ protected: UPROPERTY(EditAnywhere) float Damage = 20.f; - UPROPERTY(EditAnywhere) + UPROPERTY(Replicated, EditAnywhere) bool bUseServerSideRewind = false; UPROPERTY() @@ -135,6 +135,9 @@ protected: UPROPERTY() class ABlasterPlayerController* OwnerController; + + UFUNCTION() + void OnPingTooHigh(bool bPingTooHigh); private: UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")