Files

311 lines
7.4 KiB
C++
Raw Permalink Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "CollisionAnalyzer.h"
#include "HAL/FileManager.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Engine/GameViewportClient.h"
#include "Engine/HitResult.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "DrawDebugHelpers.h"
#include "SCollisionAnalyzer.h"
#include "CollisionAnalyzerLog.h"
#include "CollisionDebugDrawingPublic.h"
/** Magic value, determining that file is a collision analyzer file. */
#define COLLISION_ANALYZER_MAGIC 0x2DFF34FC
/** Version of collision analyzer. Incremented on serialization changes. */
#define COLLISION_ANALYZER_VERSION 0
FCAQuery::FCAQuery() :
Params(NAME_None, FCollisionQueryParams::GetUnknownStatId())
{
}
FCAQuery::~FCAQuery() = default;
/** Util for serializing an FHitResult struct */
void SerializeHitResult(FArchive& Ar, FHitResult& Result)
{
bool bTempBlocking = Result.bBlockingHit;
Ar << bTempBlocking;
Result.bBlockingHit = bTempBlocking;
bool bTempPenetrating = Result.bStartPenetrating;
Ar << bTempPenetrating;
Result.bStartPenetrating = bTempPenetrating;
Ar << Result.Time;
Ar << Result.Distance;
Ar << Result.Location;
Ar << Result.ImpactPoint;
Ar << Result.Normal;
Ar << Result.ImpactNormal;
Ar << Result.TraceStart;
Ar << Result.TraceEnd;
Ar << Result.PenetrationDepth;
Ar << Result.BoneName;
Ar << Result.PhysMaterial;
Ar << Result.HitObjectHandle;
Ar << Result.Component;
Ar << Result.FaceIndex;
}
FArchive& operator << (FArchive& Ar, FCAQuery& Query)
{
Ar << Query.Start;
Ar << Query.End;
Ar << Query.Rot;
Ar << (int32&)Query.Type;
Ar << (int32&)Query.Shape;
Ar << (int32&)Query.Mode;
Ar << Query.Dims;
Ar << (int32&)Query.Channel;
Ar << Query.Params.TraceTag;
Ar << Query.Params.OwnerTag;
bool bTraceAsyncDeprecated = false;
Ar << bTraceAsyncDeprecated;
Ar << Query.Params.bTraceComplex;
Ar << Query.Params.bFindInitialOverlaps;
Ar << Query.Params.bReturnFaceIndex;
Ar << Query.Params.bReturnPhysicalMaterial;
int32 NumResults = 0;
if (Ar.IsLoading())
{
// Load array.
Ar << NumResults;
Query.Results.SetNum(NumResults);
}
else if(Ar.IsSaving())
{
// Save array.
NumResults = Query.Results.Num();
Ar << NumResults;
}
for (int32 i = 0; i < NumResults; i++)
{
SerializeHitResult(Ar, Query.Results[i]);
}
Ar << Query.FrameNum;
Ar << Query.CPUTime;
Ar << Query.ID;
return Ar;
}
//////////////////////////////////////////////////////////////////////////
void FCollisionAnalyzer::CaptureQuery( const FVector& Start,
const FVector& End,
const FQuat& Rot,
ECAQueryType::Type QueryType,
ECAQueryShape::Type QueryShape,
ECAQueryMode::Type QueryMode,
const FVector& Dims,
ECollisionChannel TraceChannel,
const struct FCollisionQueryParams& Params,
const FCollisionResponseParams& ResponseParams,
const FCollisionObjectQueryParams& ObjectParams,
const TArray<FHitResult>& Results,
const TArray<FHitResult>& TouchAllResults,
double CPUTime)
{
if(bIsRecording)
{
int32 NewQueryId = Queries.AddZeroed();
FCAQuery& NewQuery = Queries[NewQueryId];
NewQuery.Start = Start;
NewQuery.End = End;
NewQuery.Rot = Rot;
NewQuery.Type = QueryType;
NewQuery.Shape = QueryShape;
NewQuery.Mode = QueryMode;
NewQuery.Dims = Dims;
NewQuery.Channel = TraceChannel;
NewQuery.Params = Params;
NewQuery.ResponseParams = ResponseParams;
NewQuery.ObjectParams = ObjectParams;
NewQuery.Results = Results;
NewQuery.TouchAllResults = TouchAllResults;
NewQuery.FrameNum = CurrentFrameNum;
NewQuery.CPUTime = CPUTime * 1000.f;
NewQuery.ID = NewQueryId;
QueryAddedEvent.Broadcast();
}
}
TSharedPtr<SWidget> FCollisionAnalyzer::SummonUI()
{
TSharedPtr<SWidget> ReturnWidget;
UE_LOG(LogCollisionAnalyzer, Log, TEXT("Opening CollisionAnalyzer..."));
if( IsInGameThread() )
{
// Make a window
ReturnWidget = SNew(SCollisionAnalyzer, this);
}
else
{
UE_LOG(LogCollisionAnalyzer, Warning, TEXT("FCollisionAnalyzer::DisplayUI: Not in game thread."));
}
return ReturnWidget;
}
bool FCollisionAnalyzer::IsRecording()
{
return bIsRecording;
}
void FCollisionAnalyzer::TickAnalyzer(UWorld* World)
{
if(bIsRecording)
{
// Increment frame number
CurrentFrameNum++;
}
// Draw any queries requested
for(int32 DrawIdx=0; DrawIdx<DrawQueryIndices.Num(); DrawIdx++)
{
int32 QueryIdx = DrawQueryIndices[DrawIdx];
if(QueryIdx < Queries.Num())
{
FCAQuery& DrawQuery = Queries[QueryIdx];
if(DrawQuery.Type == ECAQueryType::Raycast)
{
DrawLineTraces(World, DrawQuery.Start, DrawQuery.End, DrawQuery.Results, 0.f);
}
else if(DrawQuery.Type == ECAQueryType::GeomSweep)
{
if (DrawQuery.Shape == ECAQueryShape::Sphere)
{
DrawSphereSweeps(World, DrawQuery.Start, DrawQuery.End, DrawQuery.Dims.X, DrawQuery.Results, 0.f);
}
else if (DrawQuery.Shape == ECAQueryShape::Box)
{
DrawBoxSweeps(World, DrawQuery.Start, DrawQuery.End, DrawQuery.Dims, DrawQuery.Rot, DrawQuery.Results, 0.f);
}
else if (DrawQuery.Shape == ECAQueryShape::Capsule)
{
DrawCapsuleSweeps(World, DrawQuery.Start, DrawQuery.End, DrawQuery.Dims.Z, DrawQuery.Dims.X, DrawQuery.Rot, DrawQuery.Results, 0.f);
}
}
}
}
// Draw debug box if desired
if(DrawBox.IsValid)
{
DrawDebugBox(World, DrawBox.GetCenter(), DrawBox.GetExtent(), FColor::White);
}
}
void FCollisionAnalyzer::SetIsRecording(bool bNewRecording)
{
if(bNewRecording != bIsRecording)
{
// If starting recording, reset queries and zero frame counter.
if(bNewRecording)
{
Queries.Reset();
DrawQueryIndices.Empty();
CurrentFrameNum = 0;
QueriesChangedEvent.Broadcast();
}
bIsRecording = bNewRecording;
}
}
int32 FCollisionAnalyzer::GetNumFramesOfRecording()
{
return CurrentFrameNum+1;
}
void FCollisionAnalyzer::SaveCollisionProfileData(FString ProfileFileName)
{
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*ProfileFileName);
if(FileWriter != nullptr)
{
FCollisionAnalyzerProxyArchive Ar(*FileWriter);
int32 Magic = COLLISION_ANALYZER_MAGIC;
int32 Version = COLLISION_ANALYZER_VERSION;
Ar << Magic;
Ar << Version;
Ar << Queries;
FileWriter->Close();
delete FileWriter;
FileWriter = NULL;
UE_LOG(LogCollisionAnalyzer, Log, TEXT("Saved collision analyzer data to file '%s'."), *ProfileFileName);
}
else
{
UE_LOG(LogCollisionAnalyzer, Warning, TEXT("Unable to save collision analyzer data to file '%s'."), *ProfileFileName);
}
}
void FCollisionAnalyzer::LoadCollisionProfileData(FString ProfileFileName)
{
FArchive* FileReader = IFileManager::Get().CreateFileReader(*ProfileFileName);
bool bSuccess = false;
if (FileReader != nullptr)
{
FCollisionAnalyzerProxyArchive Ar(*FileReader);
int32 Magic;
Ar << Magic;
if(Magic == COLLISION_ANALYZER_MAGIC)
{
int32 Version;
Ar << Version;
if(Version == COLLISION_ANALYZER_VERSION)
{
// First clear old data
Queries.Reset();
DrawQueryIndices.Empty();
CurrentFrameNum = 0;
// Load data from file
Ar << Queries;
// Invoke event that data has changed
QueriesChangedEvent.Broadcast();
UE_LOG(LogCollisionAnalyzer, Log, TEXT("Loaded collision analyzer data from file '%s'."), *ProfileFileName);
bSuccess = true;
}
}
// Close file
FileReader->Close();
delete FileReader;
FileReader = NULL;
}
if(!bSuccess)
{
UE_LOG(LogCollisionAnalyzer, Warning, TEXT("Unable to load collision analyzer data from file '%s'."), *ProfileFileName);
}
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
}