Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectOctree.cpp
bryan sefcik 50d4fac9e0 Updated ../Engine/Plugins/... to inline gen.cpp files
Before:
3548 unity files
Total CPU Time: 47343.578125 s
Total time in Parallel executor: 494.60 seconds

After:
3445 unity files
Total CPU Time: 46044.671875 s
Total time in Parallel executor: 468.51 seconds

#jira
#preflight 63336159b20e73a098b7f24f

[CL 22218213 by bryan sefcik in ue5-main branch]
2022-09-28 01:06:15 -04:00

95 lines
3.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SmartObjectOctree.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(SmartObjectOctree)
//----------------------------------------------------------------------//
// FSmartObjectOctreeElement
//----------------------------------------------------------------------//
FSmartObjectOctreeElement::FSmartObjectOctreeElement(const FBoxCenterAndExtent& InBounds, const FSmartObjectHandle InSmartObjectHandle, const FSmartObjectOctreeIDSharedRef& InSharedOctreeID)
: Bounds(InBounds)
, SmartObjectHandle(InSmartObjectHandle)
, SharedOctreeID(InSharedOctreeID)
{
}
//----------------------------------------------------------------------//
// FSmartObjectOctree
//----------------------------------------------------------------------//
FSmartObjectOctree::FSmartObjectOctree()
: FSmartObjectOctree(FVector::ZeroVector, 0)
{
}
FSmartObjectOctree::FSmartObjectOctree(const FVector& Origin, const float Radius)
: TOctree2<FSmartObjectOctreeElement, FSmartObjectOctreeSemantics>(Origin, Radius)
{
}
FSmartObjectOctree::~FSmartObjectOctree()
{
}
void FSmartObjectOctree::AddNode(const FBoxCenterAndExtent& Bounds, const FSmartObjectHandle SmartObjectHandle, const FSmartObjectOctreeIDSharedRef& SharedOctreeID)
{
AddElement(FSmartObjectOctreeElement(Bounds, SmartObjectHandle, SharedOctreeID));
}
void FSmartObjectOctree::UpdateNode(const FOctreeElementId2& Id, const FBox& NewBounds)
{
FSmartObjectOctreeElement ElementCopy = GetElementById(Id);
RemoveElement(Id);
ElementCopy.Bounds = NewBounds;
AddElement(ElementCopy);
}
void FSmartObjectOctree::RemoveNode(const FOctreeElementId2& Id)
{
RemoveElement(Id);
}
//----------------------------------------------------------------------//
// FSmartObjectOctreeSemantics
//----------------------------------------------------------------------//
void FSmartObjectOctreeSemantics::SetElementId(const FSmartObjectOctreeElement& Element, const FOctreeElementId2 Id)
{
Element.SharedOctreeID->ID = Id;
}
//----------------------------------------------------------------------//
// USmartObjectOctree
//----------------------------------------------------------------------//
void USmartObjectOctree::SetBounds(const FBox& Bounds)
{
new(&SmartObjectOctree) FSmartObjectOctree(Bounds.GetCenter(), Bounds.GetExtent().Size2D());
}
FInstancedStruct USmartObjectOctree::Add(const FSmartObjectHandle Handle, const FBox& Bounds)
{
const FSmartObjectOctreeEntryData EntryData;
SmartObjectOctree.AddNode(Bounds, Handle, EntryData.SharedOctreeID);
return FInstancedStruct::Make(EntryData);
}
void USmartObjectOctree::Remove(const FSmartObjectHandle Handle, const FStructView& EntryData)
{
const FSmartObjectOctreeEntryData& OctreeEntryData = EntryData.GetMutable<FSmartObjectOctreeEntryData>();
FSmartObjectOctreeID& SharedOctreeID = OctreeEntryData.SharedOctreeID.Get();
if (SharedOctreeID.ID.IsValidId())
{
SmartObjectOctree.RemoveNode(SharedOctreeID.ID);
SharedOctreeID.ID = {};
}
}
void USmartObjectOctree::Find(const FBox& QueryBox, TArray<FSmartObjectHandle>& OutResults)
{
SmartObjectOctree.FindElementsWithBoundsTest(QueryBox,
[&OutResults](const FSmartObjectOctreeElement& Element)
{
OutResults.Add(Element.SmartObjectHandle);
});
}