2022-02-21 01:10:34 -05:00
|
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
|
|
#include "SmartObjectHashGrid.h"
|
|
|
|
|
|
#include "DebugRenderSceneProxy.h"
|
2023-01-19 00:48:07 -05:00
|
|
|
|
#include "Math/ColorList.h"
|
2022-02-21 01:10:34 -05:00
|
|
|
|
|
2022-09-28 01:06:15 -04:00
|
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(SmartObjectHashGrid)
|
|
|
|
|
|
|
2022-03-17 19:07:54 -04:00
|
|
|
|
FInstancedStruct USmartObjectHashGrid::Add(const FSmartObjectHandle Handle, const FBox& Bounds)
|
2022-02-21 01:10:34 -05:00
|
|
|
|
{
|
|
|
|
|
|
FSmartObjectHashGridEntryData GridEntryData;
|
|
|
|
|
|
GridEntryData.CellLoc = HashGrid.Add(Handle, Bounds);
|
|
|
|
|
|
return FInstancedStruct::Make(GridEntryData);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-12 09:01:21 -05:00
|
|
|
|
void USmartObjectHashGrid::Remove(const FSmartObjectHandle Handle, FStructView EntryData)
|
2022-02-21 01:10:34 -05:00
|
|
|
|
{
|
2023-02-13 20:06:02 -05:00
|
|
|
|
FSmartObjectHashGridEntryData& GridEntryData = EntryData.Get<FSmartObjectHashGridEntryData>();
|
2022-02-21 01:10:34 -05:00
|
|
|
|
HashGrid.Remove(Handle, GridEntryData.CellLoc);
|
|
|
|
|
|
GridEntryData.CellLoc = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void USmartObjectHashGrid::Find(const FBox& QueryBox, TArray<FSmartObjectHandle>& OutResults)
|
|
|
|
|
|
{
|
|
|
|
|
|
HashGrid.QuerySmall(QueryBox, OutResults);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if UE_ENABLE_DEBUG_DRAWING
|
|
|
|
|
|
void USmartObjectHashGrid::Draw(FDebugRenderSceneProxy* DebugProxy)
|
|
|
|
|
|
{
|
|
|
|
|
|
const TSet<FSmartObjectHashGrid2D::FCell>& AllCells = HashGrid.GetCells();
|
|
|
|
|
|
for (auto It(AllCells.CreateConstIterator()); It; ++It)
|
|
|
|
|
|
{
|
|
|
|
|
|
FBox CellBounds = HashGrid.CalcCellBounds(FSmartObjectHashGrid2D::FCellLocation(It->X, It->Y, It->Level));
|
|
|
|
|
|
DebugProxy->Boxes.Emplace(CellBounds, GColorList.GetFColorByIndex(It->Level));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif //UE_ENABLE_DEBUG_DRAWING
|
2022-09-28 01:06:15 -04:00
|
|
|
|
|