Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectOctree.cpp
yoan stamant 478d81a61b [SmartObject] handles for SmartObject and SmartObjectSlot passed by value
#rnx
#rb trivial
#preflight 62322b8c6e25767a218d46b0

#ROBOMERGE-AUTHOR: yoan.stamant
#ROBOMERGE-SOURCE: CL 19410090 via CL 19412659 via CL 19426193 via CL 19426309
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v930-19419903)

[CL 19429514 by yoan stamant in ue5-main branch]
2022-03-17 19:07:54 -04:00

92 lines
3.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SmartObjectOctree.h"
//----------------------------------------------------------------------//
// 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);
});
}