Here The semantics (type traits) for Octree2 (second template parametr) element should define a
SetElementId
method, however I can’t call GetWorld from there to stick the id into my subsystem, from this it is unclear how I can store these id’s to remove unnecessary objects from Octree2?
Code:
// element type
struct FEntityOctreeElement
{
FMassEntityHandle Entity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Octree Element Struct")
FBoxSphereBounds BoxSphereBounds;
FEntityOctreeElement(FMassEntityHandle InEntity, const FVector& InLocation)
: Entity(InEntity)
{}
FEntityOctreeElement()
{
BoxSphereBounds = FBoxSphereBounds(FVector(0.0f, 0.0f, 0.0f), FVector(1.0f, 1.0f, 1.0f), 1.0f);
}
FEntityOctreeElement(FMassEntityHandle aEntityHandle, FBoxSphereBounds aInBoxSphereBounds)
{
Entity = aEntityHandle;
BoxSphereBounds = aInBoxSphereBounds;
}
FBoxSphereBounds GetBounds() const
{
return BoxSphereBounds;
}
};
// semantic
struct FEntityOctreeSemantics
{
enum { MaxElementsPerLeaf = 2 }; // 16
enum { MinInclusiveElementsPerNode = 7 };
enum { MaxNodeDepth = 12 };
typedef TInlineAllocator<MaxElementsPerLeaf> ElementAllocator;
/**
* Get the bounding box of the provided octree element. In this case, the box
* is merely the point specified by the element.
*
* @param Element Octree element to get the bounding box for
*
* @return Bounding box of the provided octree element
*/
FORCEINLINE static FBoxSphereBounds GetBoundingBox(const FEntityOctreeElement& Element)
{
return Element.GetBounds();
}
FORCEINLINE static bool AreElementsEqual(const FEntityOctreeElement& A, const FEntityOctreeElement& B)
{
return A.Entity == B.Entity;
}
FORCEINLINE static void SetElementId(const FEntityOctreeElement& Element, FOctreeElementId2 Id)
{
// how to impl it?????
}
FORCEINLINE static void ApplyOffset(FEntityOctreeElement& Element, FVector Offset)
{
FVector NewPostion = Element.BoxSphereBounds.Origin + Offset;
Element.BoxSphereBounds.Origin = NewPostion;
}
};
typedef TOctree2<FEntityOctreeElement, FEntityOctreeSemantics> FEntityOctree; // Octree type