You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Update registration flow since CreateRenderState_Concurrent can't be used to register our delegate since it needs to be initialized first (CreateSceneProxy) and in some code paths for loaded actors the call order might be different since primitive registration gets deferred (i.e. FRegisterComponentContext != nullptr). In that case initialization won't called and an ensure will fire in UnregisterDebugDrawDelegate since registration failed (was not initialized). Case 1: FRegisterComponentContext == nullptr ==> Super::CreateRenderState_Concurrent + sync CreateSceneProxy (init) + RegisterDebugDrawDelegate ==> works fine Case 2: FRegisterComponentContext != nullptr ==> Super::CreateRenderState_Concurrent + deferred CreateSceneProxy + RegisterDebugDrawDelegate (skipped since not init) + CreateSceneProxy ==> ensures in UnregisterDebugDrawDelegate Bonus: - some code analysis fixes - removed some 'CoreMinimal.h' includes - exported log category 'LogVisual' - fixed some uninitialized properties (FNavTestDebugDrawDelegateHelper, UNavMeshRenderingComponent, FNavMeshSceneProxyData) - fixed some methods hiding non-virtual from base class (GetAllocatedSize) - fixed FGameplayDebuggerCompositeSceneProxy::GetMemoryFootprint that was not considering base class allocations #rnx #jira UE-125097 #preflight 614362684778fa00016a8cad #rb mieszko.zielinski [CL 17544171 by Yoan StAmant in ue5-main branch]
184 lines
5.3 KiB
C++
184 lines
5.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "GameplayDebuggerRenderingComponent.h"
|
|
#include "GameplayDebuggerCategoryReplicator.h"
|
|
#include "GameplayDebuggerCategory.h"
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// FGameplayDebuggerCompositeSceneProxy
|
|
|
|
class FGameplayDebuggerCompositeSceneProxy : public FDebugRenderSceneProxy
|
|
{
|
|
friend class FGameplayDebuggerDebugDrawDelegateHelper;
|
|
public:
|
|
FGameplayDebuggerCompositeSceneProxy(const UPrimitiveComponent* InComponent) : FDebugRenderSceneProxy(InComponent) { }
|
|
|
|
virtual ~FGameplayDebuggerCompositeSceneProxy() override
|
|
{
|
|
for (int32 Idx = 0; Idx < ChildProxies.Num(); Idx++)
|
|
{
|
|
delete ChildProxies[Idx];
|
|
}
|
|
}
|
|
|
|
virtual void DrawStaticElements(FStaticPrimitiveDrawInterface* PDI) override
|
|
{
|
|
for (int32 Idx = 0; Idx < ChildProxies.Num(); Idx++)
|
|
{
|
|
ChildProxies[Idx]->DrawStaticElements(PDI);
|
|
}
|
|
}
|
|
|
|
virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
|
|
{
|
|
for (int32 Idx = 0; Idx < ChildProxies.Num(); Idx++)
|
|
{
|
|
ChildProxies[Idx]->GetDynamicMeshElements(Views, ViewFamily, VisibilityMap, Collector);
|
|
}
|
|
}
|
|
|
|
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
|
|
{
|
|
FPrimitiveViewRelevance Result;
|
|
for (int32 Idx = 0; Idx < ChildProxies.Num(); Idx++)
|
|
{
|
|
Result |= ChildProxies[Idx]->GetViewRelevance(View);
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
virtual uint32 GetMemoryFootprint(void) const override
|
|
{
|
|
return sizeof(*this) + GetAllocatedSizeInternal();
|
|
}
|
|
|
|
void AddChild(FDebugRenderSceneProxy* NewChild)
|
|
{
|
|
ChildProxies.AddUnique(NewChild);
|
|
}
|
|
|
|
void AddRange(TArray<FDebugRenderSceneProxy*> Children)
|
|
{
|
|
ChildProxies.Append(Children);
|
|
}
|
|
|
|
private:
|
|
uint32 GetAllocatedSizeInternal(void) const
|
|
{
|
|
uint32 Size = FDebugRenderSceneProxy::GetAllocatedSize() + ChildProxies.GetAllocatedSize();
|
|
for (int32 Idx = 0; Idx < ChildProxies.Num(); Idx++)
|
|
{
|
|
Size += ChildProxies[Idx]->GetMemoryFootprint();
|
|
}
|
|
|
|
return Size;
|
|
}
|
|
|
|
protected:
|
|
TArray<FDebugRenderSceneProxy*> ChildProxies;
|
|
};
|
|
|
|
void FGameplayDebuggerDebugDrawDelegateHelper::RegisterDebugDrawDelegate()
|
|
{
|
|
ensureMsgf(State != RegisteredState, TEXT("RegisterDebugDrawDelegate is already Registered!"));
|
|
if (State == InitializedState)
|
|
{
|
|
for (int32 Idx = 0; Idx < DebugDrawDelegateHelpers.Num(); Idx++)
|
|
{
|
|
DebugDrawDelegateHelpers[Idx]->RegisterDebugDrawDelegate();
|
|
}
|
|
State = RegisteredState;
|
|
}
|
|
}
|
|
|
|
void FGameplayDebuggerDebugDrawDelegateHelper::UnregisterDebugDrawDelegate()
|
|
{
|
|
ensureMsgf(State != InitializedState, TEXT("UnregisterDebugDrawDelegate is in an invalid State: %i !"), State);
|
|
if (State == RegisteredState)
|
|
{
|
|
for (int32 Idx = 0; Idx < DebugDrawDelegateHelpers.Num(); Idx++)
|
|
{
|
|
DebugDrawDelegateHelpers[Idx]->UnregisterDebugDrawDelegate();
|
|
}
|
|
State = InitializedState;
|
|
}
|
|
}
|
|
|
|
void FGameplayDebuggerDebugDrawDelegateHelper::Reset()
|
|
{
|
|
for (int32 Idx = 0; Idx < DebugDrawDelegateHelpers.Num(); Idx++)
|
|
{
|
|
delete DebugDrawDelegateHelpers[Idx];
|
|
}
|
|
DebugDrawDelegateHelpers.Reset();
|
|
}
|
|
|
|
void FGameplayDebuggerDebugDrawDelegateHelper::AddDelegateHelper(FDebugDrawDelegateHelper* InDebugDrawDelegateHelper)
|
|
{
|
|
check(InDebugDrawDelegateHelper);
|
|
DebugDrawDelegateHelpers.Add(InDebugDrawDelegateHelper);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// UGameplayDebuggerRenderingComponent
|
|
|
|
UGameplayDebuggerRenderingComponent::UGameplayDebuggerRenderingComponent(const FObjectInitializer& ObjInitializer) : Super(ObjInitializer)
|
|
{
|
|
}
|
|
|
|
FPrimitiveSceneProxy* UGameplayDebuggerRenderingComponent::CreateSceneProxy()
|
|
{
|
|
GameplayDebuggerDebugDrawDelegateHelper.Reset();
|
|
|
|
FGameplayDebuggerCompositeSceneProxy* CompositeProxy = nullptr;
|
|
|
|
AGameplayDebuggerCategoryReplicator* OwnerReplicator = Cast<AGameplayDebuggerCategoryReplicator>(GetOwner());
|
|
if (OwnerReplicator && OwnerReplicator->IsEnabled())
|
|
{
|
|
TArray<FDebugRenderSceneProxy*> SceneProxies;
|
|
for (int32 Idx = 0; Idx < OwnerReplicator->GetNumCategories(); Idx++)
|
|
{
|
|
const TSharedRef<FGameplayDebuggerCategory> Category = OwnerReplicator->GetCategory(Idx);
|
|
if (Category->IsCategoryEnabled())
|
|
{
|
|
FDebugDrawDelegateHelper* DebugDrawDelegateHelper = nullptr;
|
|
FDebugRenderSceneProxy* CategorySceneProxy = Category->CreateDebugSceneProxy(this, DebugDrawDelegateHelper);
|
|
if (CategorySceneProxy)
|
|
{
|
|
SceneProxies.Add(CategorySceneProxy);
|
|
}
|
|
|
|
if (DebugDrawDelegateHelper)
|
|
{
|
|
GameplayDebuggerDebugDrawDelegateHelper.AddDelegateHelper(DebugDrawDelegateHelper);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (SceneProxies.Num())
|
|
{
|
|
CompositeProxy = new FGameplayDebuggerCompositeSceneProxy(this);
|
|
CompositeProxy->AddRange(SceneProxies);
|
|
}
|
|
}
|
|
|
|
if (CompositeProxy)
|
|
{
|
|
GameplayDebuggerDebugDrawDelegateHelper.InitDelegateHelper(CompositeProxy);
|
|
GameplayDebuggerDebugDrawDelegateHelper.RegisterDebugDrawDelegate();
|
|
}
|
|
return CompositeProxy;
|
|
}
|
|
|
|
FBoxSphereBounds UGameplayDebuggerRenderingComponent::CalcBounds(const FTransform &LocalToWorld) const
|
|
{
|
|
return FBoxSphereBounds(FBox::BuildAABB(FVector::ZeroVector, FVector(1000000.0f, 1000000.0f, 1000000.0f)));
|
|
}
|
|
|
|
void UGameplayDebuggerRenderingComponent::DestroyRenderState_Concurrent()
|
|
{
|
|
GameplayDebuggerDebugDrawDelegateHelper.UnregisterDebugDrawDelegate();
|
|
|
|
Super::DestroyRenderState_Concurrent();
|
|
}
|