From f876862d12698c7c3da38d125f71fa89db66d69c Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Tue, 31 Oct 2023 00:44:59 -0400 Subject: [PATCH] CogCommon: Better debug formating CogSample: Projectile Progress CogSample: Disable Character Mesh collision on dedicated server --- .../Cog/Source/CogCommon/Public/CogCommon.h | 6 +- Source/CogSample/CogSampleCharacter.cpp | 7 ++ .../CogSampleProjectileComponent.cpp | 86 ++++++++++++------- .../CogSample/CogSampleProjectileComponent.h | 6 +- 4 files changed, 70 insertions(+), 35 deletions(-) diff --git a/Plugins/Cog/Source/CogCommon/Public/CogCommon.h b/Plugins/Cog/Source/CogCommon/Public/CogCommon.h index 3c2e407..e1d8b52 100644 --- a/Plugins/Cog/Source/CogCommon/Public/CogCommon.h +++ b/Plugins/Cog/Source/CogCommon/Public/CogCommon.h @@ -29,13 +29,13 @@ //-------------------------------------------------------------------------------------------------------------------------- #define COG_LOG_FUNC(LogCategory, Verbosity, Format, ...) \ - COG_LOG(LogCategory, Verbosity, TEXT("%s - %s"), ANSI_TO_TCHAR(__FUNCTION__), *FString::Printf(Format, ##__VA_ARGS__)); \ + COG_LOG(LogCategory, Verbosity, TEXT("%s | %s"), ANSI_TO_TCHAR(__FUNCTION__), *FString::Printf(Format, ##__VA_ARGS__)); \ //-------------------------------------------------------------------------------------------------------------------------- #define COG_LOG_OBJECT(LogCategory, Verbosity, Object, Format, ...) \ if (COG_LOG_ACTIVE_FOR_OBJECT(Object) || (int32)Verbosity <= (int32)ELogVerbosity::Warning) \ { \ - COG_LOG(LogCategory, Verbosity, TEXT("%s - %s - %s"), \ + COG_LOG(LogCategory, Verbosity, TEXT("%s | %s | %s"), \ *GetNameSafe(Object), \ ANSI_TO_TCHAR(__FUNCTION__), \ *FString::Printf(Format, ##__VA_ARGS__)); \ @@ -45,7 +45,7 @@ #define COG_LOG_OBJECT_NO_CONTEXT(LogCategory, Verbosity, Object, Format, ...) \ if (COG_LOG_ACTIVE_FOR_OBJECT(Object) || (int32)Verbosity <= (int32)ELogVerbosity::Warning) \ { \ - COG_LOG(LogCategory, Verbosity, TEXT("%s - %s"), *GetNameSafe(Object), *FString::Printf(Format, ##__VA_ARGS__)); \ + COG_LOG(LogCategory, Verbosity, TEXT("%s | %s"), *GetNameSafe(Object), *FString::Printf(Format, ##__VA_ARGS__)); \ } \ #else //ENABLE_COG diff --git a/Source/CogSample/CogSampleCharacter.cpp b/Source/CogSample/CogSampleCharacter.cpp index 1ea0ecf..c0485cd 100644 --- a/Source/CogSample/CogSampleCharacter.cpp +++ b/Source/CogSample/CogSampleCharacter.cpp @@ -14,6 +14,7 @@ #include "CogSampleRootMotionParams.h" #include "Components/CapsuleComponent.h" #include "Components/InputComponent.h" +#include "Engine/CollisionProfile.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" #include "GameFramework/CharacterMovementComponent.h" @@ -108,6 +109,12 @@ void ACogSampleCharacter::BeginPlay() } } + if (GetWorld()->GetNetMode() == NM_DedicatedServer) + { + GetMesh()->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); + } + + TryFinishInitialize(); RefreshServerAnimTickOption(); } diff --git a/Source/CogSample/CogSampleProjectileComponent.cpp b/Source/CogSample/CogSampleProjectileComponent.cpp index 339bfd2..7733684 100644 --- a/Source/CogSample/CogSampleProjectileComponent.cpp +++ b/Source/CogSample/CogSampleProjectileComponent.cpp @@ -82,7 +82,7 @@ void UCogSampleProjectileComponent::BeginPlay() Creator = UCogSampleFunctionLibrary_Gameplay::GetCreator(GetOwner()); SpawnPrediction = GetOwner()->FindComponentByClass(); - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - IsActive:%d"), *GetNameSafe(GetOwner()), *GetRoleName(), IsActive()); + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | IsActive:%d"), *GetNameSafe(GetOwner()), *GetRoleName(), IsActive()); RegisterAllEffects(); @@ -110,7 +110,7 @@ void UCogSampleProjectileComponent::BeginPlay() //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::Activate(bool bReset) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - bReset:%d"), *GetNameSafe(GetOwner()), *GetRoleName(), bReset); + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | bReset:%d"), *GetNameSafe(GetOwner()), *GetRoleName(), bReset); //------------------------------------------------------------------------------------------------ // Save the spawn location and rotation and get them replicated because, we want remote clients @@ -210,7 +210,7 @@ void UCogSampleProjectileComponent::TickComponent(float DeltaTime, enum ELevelTi //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::Catchup(float CatchupDuration) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - CatchupDuration:%dms"), *GetNameSafe(GetOwner()), *GetRoleName(), (int32)(CatchupDuration * 1000)); + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | CatchupDuration:%dms"), *GetNameSafe(GetOwner()), *GetRoleName(), (int32)(CatchupDuration * 1000)); IsCatchingUp = true; TickComponent(CatchupDuration, LEVELTICK_All, nullptr); @@ -240,6 +240,17 @@ void UCogSampleProjectileComponent::DrawDebugCurrentState(const FColor& Color, b } } } + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogSampleProjectileComponent::DrawDebugHitResult(const FHitResult& HitResult) +{ + FCogDebugDraw::Arrow(LogCogProjectile, GetOwner(), HitResult.Location, HitResult.Location + HitResult.Normal * 50.0f, FColor::Red, true, 0); + FCogDebugDraw::Box(LogCogProjectile, GetOwner(), HitResult.Location, FVector(0.0f, 5.0f, 5.0f), FRotationMatrix::MakeFromX(HitResult.Normal).ToQuat(), FColor::Red, true, 0); + FCogDebugDraw::Arrow(LogCogProjectile, GetOwner(), HitResult.ImpactPoint, HitResult.ImpactPoint + HitResult.ImpactNormal * 50.0f, FColor::Yellow, true, 0); + FCogDebugDraw::Box(LogCogProjectile, GetOwner(), HitResult.ImpactPoint, FVector(0.0f, 5.0f, 5.0f), FRotationMatrix::MakeFromX(HitResult.ImpactNormal).ToQuat(), FColor::Yellow, true, 0); +} + + #endif //ENABLE_COG //-------------------------------------------------------------------------------------------------------------------------- @@ -268,11 +279,11 @@ bool UCogSampleProjectileComponent::ShouldProcessOverlap(AActor* OtherActor, UPr return false; } - if (GetOwner()->GetLocalRole() != ROLE_Authority) - { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Skipped:NotAuthority")); - return false; - } + //if (GetOwner()->GetLocalRole() == ROLE_Authority) + //{ + // COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Skipped:NotAuthority")); + // return false; + //} //if (IsStopped) //{ @@ -323,7 +334,7 @@ bool UCogSampleProjectileComponent::ShouldProcessOverlap(AActor* OtherActor, UPr //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::OnCollisionOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool IsFromSweep, const FHitResult& SweepHit) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - Other:%s - Comp:%s"), + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | Other:%s | Comp:%s"), *GetNameSafe(GetOwner()), *GetRoleName(), *GetNameSafe(OtherActor), @@ -383,7 +394,7 @@ void UCogSampleProjectileComponent::OnCollisionOverlapBegin(UPrimitiveComponent* //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::OnAssistanceOverlapBegin(UPrimitiveComponent* overlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool IsFromSweep, const FHitResult& Hit) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - Other:%s - Comp:%s"), + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | Other:%s | Comp:%s"), *GetNameSafe(GetOwner()), *GetRoleName(), *GetNameSafe(OtherActor), @@ -436,7 +447,7 @@ void UCogSampleProjectileComponent::OnAssistanceOverlapBegin(UPrimitiveComponent //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::TryHit(const FHitResult& HitResult) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - Other:%s - Comp:%s - Bone:%s"), + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | Other:%s | Comp:%s | Bone:%s"), *GetNameSafe(GetOwner()), *GetRoleName(), *GetNameSafe(HitResult.GetActor()), @@ -469,7 +480,7 @@ void UCogSampleProjectileComponent::TryHit(const FHitResult& HitResult) //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::StopSimulating(const FHitResult& HitResult) { - COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s - Role:%s - Other:%s - Comp:%s - Bone:%s"), + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | Other:%s | Comp:%s | Bone:%s"), *GetNameSafe(GetOwner()), *GetRoleName(), *GetNameSafe(HitResult.GetActor()), @@ -494,16 +505,42 @@ bool UCogSampleProjectileComponent::ShouldHit_Implementation(const FHitResult& H //-------------------------------------------------------------------------------------------------------------------------- void UCogSampleProjectileComponent::Hit_Implementation(const FHitResult& HitResult, FCogSampleHitConsequence& HitConsequence) { - AActor* HitActor = HitResult.GetActor(); +#if ENABLE_COG + DrawDebugCurrentState(FColor::White, false); + DrawDebugHitResult(HitResult); +#endif //ENABLE_COG + + Server_Hit(HitResult); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FString UCogSampleProjectileComponent::GetRoleName() const +{ + if (SpawnPrediction == nullptr) + { + return TEXT("No Prediction"); + } + + return SpawnPrediction->GetRoleName(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogSampleProjectileComponent::Server_Hit_Implementation(const FHitResult& HitResult) +{ + COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | Other:%s | Comp:%s | Bone:%s"), + *GetNameSafe(GetOwner()), + *GetRoleName(), + *GetNameSafe(HitResult.GetActor()), + *GetNameSafe(HitResult.GetComponent()), + *HitResult.BoneName.ToString()); #if ENABLE_COG DrawDebugCurrentState(FColor::White, false); - FCogDebugDraw::Arrow(LogCogProjectile, GetOwner(), HitResult.Location, HitResult.Location + HitResult.Normal * 50.0f, FColor::Red, true, 0); - FCogDebugDraw::Box(LogCogProjectile, GetOwner(), HitResult.Location, FVector(0.0f, 5.0f, 5.0f), FRotationMatrix::MakeFromX(HitResult.Normal).ToQuat(), FColor::Red, true, 0); - FCogDebugDraw::Arrow(LogCogProjectile, GetOwner(), HitResult.ImpactPoint, HitResult.ImpactPoint + HitResult.ImpactNormal * 50.0f, FColor::Yellow, true, 0); - FCogDebugDraw::Box(LogCogProjectile, GetOwner(), HitResult.ImpactPoint, FVector(0.0f, 5.0f, 5.0f), FRotationMatrix::MakeFromX(HitResult.ImpactNormal).ToQuat(), FColor::Yellow, true, 0); + DrawDebugHitResult(HitResult); #endif //ENABLE_COG + AActor* HitActor = HitResult.GetActor(); + UAbilitySystemComponent* TargetAbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(HitActor); if (TargetAbilitySystem == nullptr) { @@ -540,17 +577,4 @@ void UCogSampleProjectileComponent::Hit_Implementation(const FHitResult& HitResu TargetAbilitySystem->ApplyGameplayEffectSpecToSelf(*Spec); } } -} - -//-------------------------------------------------------------------------------------------------------------------------- -FString UCogSampleProjectileComponent::GetRoleName() const -{ - if (SpawnPrediction == nullptr) - { - return TEXT("No Prediction"); - } - - return SpawnPrediction->GetRoleName(); -} - - +} \ No newline at end of file diff --git a/Source/CogSample/CogSampleProjectileComponent.h b/Source/CogSample/CogSampleProjectileComponent.h index b408bf0..c3a775b 100644 --- a/Source/CogSample/CogSampleProjectileComponent.h +++ b/Source/CogSample/CogSampleProjectileComponent.h @@ -79,6 +79,9 @@ protected: virtual void TryHit(const FHitResult& Hit); + UFUNCTION(Server, Reliable) + virtual void Server_Hit(const FHitResult& Hit); + UFUNCTION() virtual void OnCollisionOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool IsFromSweep, const FHitResult& SweepHit); @@ -86,7 +89,7 @@ protected: virtual void OnAssistanceOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool IsFromSweep, const FHitResult& SweepHit); UFUNCTION(BlueprintNativeEvent, BlueprintCallable) - bool ShouldHit(const FHitResult& hit); + bool ShouldHit(const FHitResult& Hit); /** Blueprint hook called when projectile hits something */ UFUNCTION(BlueprintNativeEvent, BlueprintCallable) @@ -140,6 +143,7 @@ protected: #if ENABLE_COG void DrawDebugCurrentState(const FColor& Color, bool DrawVelocity = true); + void DrawDebugHitResult(const FHitResult& HitResult); FVector LastDebugLocation = FVector::ZeroVector; #endif //ENABLE_COG