Files
UnrealEngineUWP/Engine/Source/Developer/GameplayDebugger/Private/GameplayDebuggerCategory.cpp
Yoan StAmant ebc9ea62e4 [GameplayDebugger] viewer can now provide view location and direction to the replicator so detaching camera from controller is supported properly for actor picking and culling tests
added view distance and angle to config and updated actor picking + culling
#rb maxime.mercier, mieszko.zielinski
#preflight 61a917f61a368fd603a10e4f
#robomerge 5.0

[CL 18355593 by Yoan StAmant in ue5-main branch]
2021-12-02 14:36:54 -05:00

181 lines
4.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "GameplayDebuggerCategory.h"
#include "Engine/World.h"
#include "GameFramework/PlayerController.h"
#include "GameplayDebuggerCategoryReplicator.h"
#include "GameplayDebuggerConfig.h"
#include "GameplayDebuggerPlayerManager.h"
FGameplayDebuggerCategory::FGameplayDebuggerCategory() :
CollectDataInterval(0.0f),
bShowDataPackReplication(false),
bShowUpdateTimer(false),
bShowCategoryName(true),
bShowOnlyWithDebugActor(true),
bIsLocal(false),
bHasAuthority(true),
bIsEnabled(true),
CategoryId(INDEX_NONE),
LastCollectDataTime(-FLT_MAX)
{
}
FGameplayDebuggerCategory::~FGameplayDebuggerCategory()
{
}
void FGameplayDebuggerCategory::CollectData(APlayerController* OwnerPC, AActor* DebugActor)
{
// empty in base class
}
void FGameplayDebuggerCategory::DrawData(APlayerController* OwnerPC, FGameplayDebuggerCanvasContext& CanvasContext)
{
// empty in base class
}
FDebugRenderSceneProxy* FGameplayDebuggerCategory::CreateDebugSceneProxy(const UPrimitiveComponent* InComponent, FDebugDrawDelegateHelper*& OutDelegateHelper)
{
OutDelegateHelper = nullptr;
// empty in base class
return nullptr;
}
void FGameplayDebuggerCategory::OnDataPackReplicated(int32 DataPackId)
{
// empty in base class
}
void FGameplayDebuggerCategory::AddTextLine(const FString& TextLine)
{
if (bHasAuthority)
{
ReplicatedLines.Add(TextLine);
}
}
void FGameplayDebuggerCategory::AddShape(const FGameplayDebuggerShape& Shape)
{
if (bHasAuthority)
{
ReplicatedShapes.Add(Shape);
}
}
void FGameplayDebuggerCategory::DrawCategory(APlayerController* OwnerPC, FGameplayDebuggerCanvasContext& CanvasContext)
{
// note that we prefer OwnerPC's world here since if it's given then that's the end user of the data
UWorld* World = CanvasContext.GetWorld();
if (!ensure(World))
{
return;
}
FString CategoryPrefix;
if (!bShowCategoryName)
{
CategoryPrefix = FString::Printf(TEXT("{green}[%s]{white} "), *CategoryName.ToString());
}
if (bShowUpdateTimer && bHasAuthority)
{
const float GameTime = World->GetTimeSeconds();
CanvasContext.Printf(TEXT("%sNext update in: {yellow}%.0fs"), *CategoryPrefix, CollectDataInterval - (GameTime - LastCollectDataTime));
}
if (bShowDataPackReplication)
{
for (int32 Idx = 0; Idx < ReplicatedDataPacks.Num(); Idx++)
{
FGameplayDebuggerDataPack& DataPack = ReplicatedDataPacks[Idx];
if (DataPack.IsInProgress())
{
const FString DataPackMessage = (ReplicatedDataPacks.Num() == 1) ?
FString::Printf(TEXT("%sReplicating: {red}%.0f%% {white}(ver:%d)"), *CategoryPrefix, DataPack.GetProgress() * 100.0f, DataPack.Header.DataVersion) :
FString::Printf(TEXT("%sReplicating data[%d]: {red}%.0f%% {white}(ver:%d)"), *CategoryPrefix, Idx, DataPack.GetProgress() * 100.0f, DataPack.Header.DataVersion);
CanvasContext.Print(DataPackMessage);
}
}
}
for (int32 Idx = 0; Idx < ReplicatedLines.Num(); Idx++)
{
CanvasContext.Print(ReplicatedLines[Idx]);
}
for (int32 Idx = 0; Idx < ReplicatedShapes.Num(); Idx++)
{
ReplicatedShapes[Idx].Draw(World, CanvasContext);
}
DrawData(OwnerPC, CanvasContext);
}
bool FGameplayDebuggerCategory::GetViewPoint(const APlayerController* OwnerPC, FVector& OutViewLocation, FVector& OutViewDirection) const
{
if (const AGameplayDebuggerCategoryReplicator* Replicator = GetReplicator())
{
if (Replicator->GetViewPoint(OutViewLocation, OutViewDirection))
{
return true;
}
}
if (OwnerPC != nullptr)
{
AGameplayDebuggerPlayerManager::GetViewPoint(*OwnerPC, OutViewLocation, OutViewDirection);
return true;
}
return false;
}
bool FGameplayDebuggerCategory::IsLocationInViewCone(const FVector& ViewLocation, const FVector& ViewDirection, const FVector& TargetLocation)
{
const UGameplayDebuggerUserSettings* Settings = GetDefault<UGameplayDebuggerUserSettings>();
const FVector DirToEntity = TargetLocation - ViewLocation;
const float DistanceToEntitySq = DirToEntity.SquaredLength();
if (DistanceToEntitySq > FMath::Square(Settings->MaxViewDistance))
{
return false;
}
const float ViewDot = FVector::DotProduct(DirToEntity.GetSafeNormal(), ViewDirection);
const float MinViewDirDot = FMath::Cos(FMath::DegreesToRadians(Settings->MaxViewAngle));
if (ViewDot < MinViewDirDot)
{
return false;
}
return true;
}
void FGameplayDebuggerCategory::MarkDataPackDirty(int32 DataPackId)
{
if (ReplicatedDataPacks.IsValidIndex(DataPackId))
{
ReplicatedDataPacks[DataPackId].bIsDirty = true;
}
}
void FGameplayDebuggerCategory::MarkRenderStateDirty()
{
if (bIsLocal)
{
AGameplayDebuggerCategoryReplicator* RepOwnerOb = GetReplicator();
if (RepOwnerOb)
{
RepOwnerOb->MarkComponentsRenderStateDirty();
}
}
}
FString FGameplayDebuggerCategory::GetSceneProxyViewFlag() const
{
const bool bIsSimulate = FGameplayDebuggerAddonBase::IsSimulateInEditor();
return bIsSimulate ? TEXT("DebugAI") : TEXT("Game");
}