Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Public/SmartObjectOctree.h
yoan stamant 722ecdcae0 [Smart object] Space partition structure is now configurable
* Created Default SmartObjectOctree
* Created Default SmartObjectHashGrid
* Type of space partition to use can be set in the smartobject config file: [/Script/SmartObjectsModule.SmartObjectSubsystem] SpacePartitionClassName=<ClassPath>
* Created DebugSceneProxy and RenderingComponent to share functionalities between susbystem and testing actor rendering components
#rnx
#rb mieszko.zielinski
#preflight 620fb51dec6f84cdfa3b2772

#ROBOMERGE-OWNER: yoan.stamant
#ROBOMERGE-AUTHOR: yoan.stamant
#ROBOMERGE-SOURCE: CL 19050433 via CL 19050556 via CL 19050564 via CL 19057424
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v918-19018356)

[CL 19066037 by yoan stamant in ue5-main branch]
2022-02-21 01:10:34 -05:00

87 lines
2.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "SmartObjectTypes.h"
#include "Templates/SharedPointer.h"
#include "Math/GenericOctree.h"
#include "SmartObjectOctree.generated.h"
typedef TSharedRef<struct FSmartObjectOctreeID, ESPMode::ThreadSafe> FSmartObjectOctreeIDSharedRef;
struct SMARTOBJECTSMODULE_API FSmartObjectOctreeID : public TSharedFromThis<FSmartObjectOctreeID, ESPMode::ThreadSafe>
{
FOctreeElementId2 ID;
};
struct SMARTOBJECTSMODULE_API FSmartObjectOctreeElement
{
FBoxCenterAndExtent Bounds;
FSmartObjectHandle SmartObjectHandle;
FSmartObjectOctreeIDSharedRef SharedOctreeID;
FSmartObjectOctreeElement(const FBoxCenterAndExtent& Bounds, const FSmartObjectHandle& SmartObjectHandle, const FSmartObjectOctreeIDSharedRef& SharedOctreeID);
};
struct FSmartObjectOctreeSemantics
{
enum { MaxElementsPerLeaf = 16 };
enum { MinInclusiveElementsPerNode = 7 };
enum { MaxNodeDepth = 12 };
typedef TInlineAllocator<MaxElementsPerLeaf> ElementAllocator;
FORCEINLINE static const FBoxCenterAndExtent& GetBoundingBox(const FSmartObjectOctreeElement& Element)
{
return Element.Bounds;
}
FORCEINLINE static bool AreElementsEqual(const FSmartObjectOctreeElement& A, const FSmartObjectOctreeElement& B)
{
return A.SmartObjectHandle == B.SmartObjectHandle;
}
static void SetElementId(const FSmartObjectOctreeElement& Element, FOctreeElementId2 Id);
};
struct FSmartObjectOctree : TOctree2<FSmartObjectOctreeElement, FSmartObjectOctreeSemantics>
{
public:
FSmartObjectOctree();
FSmartObjectOctree(const FVector& Origin, float Radius);
virtual ~FSmartObjectOctree();
/** Add new node and initialize using SmartObject runtime data */
void AddNode(const FBoxCenterAndExtent& Bounds, const FSmartObjectHandle& SmartObjectHandle, const FSmartObjectOctreeIDSharedRef& SharedOctreeID);
/** Updates element bounds remove/add operation */
void UpdateNode(const FOctreeElementId2& Id, const FBox& NewBounds);
/** Remove node */
void RemoveNode(const FOctreeElementId2& Id);
};
USTRUCT()
struct SMARTOBJECTSMODULE_API FSmartObjectOctreeEntryData : public FSmartObjectSpatialEntryData
{
GENERATED_BODY()
FSmartObjectOctreeEntryData() : SharedOctreeID(MakeShareable(new FSmartObjectOctreeID())) {}
FSmartObjectOctreeIDSharedRef SharedOctreeID;
};
UCLASS()
class SMARTOBJECTSMODULE_API USmartObjectOctree : public USmartObjectSpacePartition
{
GENERATED_BODY()
protected:
virtual FInstancedStruct Add(const FSmartObjectHandle& Handle, const FBox& Bounds) override;
virtual void Remove(const FSmartObjectHandle& Handle, const FStructView& EntryData) override;
virtual void Find(const FBox& QueryBox, TArray<FSmartObjectHandle>& OutResults) override;
virtual void SetBounds(const FBox& Bounds) override;
private:
FSmartObjectOctree SmartObjectOctree;
};