Skip to content

Commit 388f193

Browse files
committed
Expensive fix for messed-up re-order of points when filtering out clusters
1 parent c117a76 commit 388f193

File tree

7 files changed

+64
-67
lines changed

7 files changed

+64
-67
lines changed

PCGExtendedToolkit.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "0.68.4",
4+
"VersionName": "0.68.5",
55
"FriendlyName": "PCGExtendedToolkit",
66
"Description": "A rather large toolset that expand on existing PCG capabilities in unique ways.",
77
"Category": "PCG",

Source/PCGExtendedToolkit/Private/Graph/PCGExGraph.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,6 @@ MACRO(Crossing, bWriteCrossing, Crossing,TEXT("bCrossing"))
291291
if (Edge.IOIndex >= 0) { EdgesInIOIndices.Add(Edge.IOIndex); }
292292
}
293293

294-
void FSubGraph::Invalidate(FGraph* InGraph)
295-
{
296-
for (const int32 EdgeIndex : Edges) { InGraph->Edges[EdgeIndex].bValid = false; }
297-
for (const int32 NodeIndex : Nodes) { InGraph->Nodes[NodeIndex].bValid = false; }
298-
}
299-
300294
void FSubGraph::BuildCluster(const TSharedRef<PCGExCluster::FCluster>& InCluster)
301295
{
302296
// Correct edge IO Index that has been overwritten during subgraph processing
@@ -743,7 +737,7 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
743737
FGraphEdgeMetadata& FGraph::GetOrCreateEdgeMetadata_Unsafe(const int32 EdgeIndex, const FGraphEdgeMetadata* Parent)
744738
{
745739
if (FGraphEdgeMetadata* MetadataPtr = EdgeMetadata.Find(EdgeIndex)) { return *MetadataPtr; }
746-
return EdgeMetadata.Emplace(EdgeIndex, FGraphEdgeMetadata(EdgeIndex, Parent));
740+
return EdgeMetadata.Add(EdgeIndex, FGraphEdgeMetadata(EdgeIndex, Parent));
747741
}
748742

749743
FGraphEdgeMetadata& FGraph::GetOrCreateEdgeMetadata(const int32 EdgeIndex, const FGraphEdgeMetadata* Parent)
@@ -895,14 +889,19 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
895889

896890
for (int i = 0; i < Nodes.Num(); i++)
897891
{
898-
const FNode& CurrentNode = Nodes[i];
892+
FNode& CurrentNode = Nodes[i];
899893

900894
if (VisitedNodes[i]) { continue; }
901895

902896
VisitedNodes[i] = true;
903897
VisitedNum++;
904898

905-
if (!CurrentNode.bValid || CurrentNode.IsEmpty()) { continue; }
899+
if (!CurrentNode.bValid) { continue; }
900+
if (CurrentNode.IsEmpty())
901+
{
902+
CurrentNode.bValid = false;
903+
continue;
904+
}
906905

907906
PCGEX_MAKE_SHARED(SubGraph, FSubGraph)
908907
SubGraph->WeakParentGraph = SharedThis(this);
@@ -944,8 +943,16 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
944943
}
945944
}
946945

947-
if (!Limits.IsValid(SubGraph)) { SubGraph->Invalidate(this); } // Will invalidate isolated points
948-
else if (!SubGraph->Edges.IsEmpty()) { SubGraphs.Add(SubGraph.ToSharedRef()); }
946+
if (!Limits.IsValid(SubGraph))
947+
{
948+
// Invalidate traversed points and edges
949+
for (const int32 j : SubGraph->Nodes) { Nodes[j].bValid = false; }
950+
for (const int32 j : SubGraph->Edges) { Edges[j].bValid = false; }
951+
}
952+
else if (!SubGraph->Edges.IsEmpty())
953+
{
954+
SubGraphs.Add(SubGraph.ToSharedRef());
955+
}
949956
}
950957
}
951958

@@ -1066,7 +1073,7 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
10661073
// Filter all valid nodes
10671074
for (FNode& Node : Nodes)
10681075
{
1069-
if (!Node.bValid || Node.IsEmpty())
1076+
if (!Node.bValid)
10701077
{
10711078
bHasInvalidNodes = true;
10721079
continue;
@@ -1133,7 +1140,6 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
11331140
// Init array of indice as a valid order range first, will be truncated later.
11341141
// We save a bit of memory by re-using it
11351142
PCGEx::ArrayOfIndices(ReadIndices, OutNodeData->GetNumPoints());
1136-
ReadIndices.SetNumUninitialized(OutNodeData->GetNumPoints());
11371143

11381144
// Sort valid nodes based on outgoing transforms
11391145
ValidNodes.Sort(
@@ -1158,7 +1164,6 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
11581164
PCGEx::ReorderPointArrayData(OutNodeData, ReadIndices);
11591165

11601166
// Truncate output to the number of nodes
1161-
ReadIndices.SetNum(NumValidNodes);
11621167
OutNodeData->SetNumPoints(NumValidNodes);
11631168
}
11641169
}

Source/PCGExtendedToolkit/Private/Graph/PCGExIntersections.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,21 @@ namespace PCGExGraph
762762

763763
NodeIndex = Crossing.NodeIndex;
764764

765-
Graph->InsertEdge_Unsafe(PrevIndex, NodeIndex, NewEdge, SplitEdge.IOIndex); //BUG: this is the wrong edge IOIndex
766-
Graph->AddNodeAndEdgeMetadata_Unsafe(NodeIndex, NewEdge.Index, ParentEdgeMeta, EPCGExIntersectionType::EdgeEdge);
765+
//BUG: this is the wrong edge IOIndex
766+
767+
if (Graph->InsertEdge_Unsafe(PrevIndex, NodeIndex, NewEdge, SplitEdge.IOIndex))
768+
{
769+
Graph->AddNodeAndEdgeMetadata_Unsafe(NodeIndex, NewEdge.Index, ParentEdgeMeta, EPCGExIntersectionType::EdgeEdge);
770+
}
767771

768772
PrevIndex = NodeIndex;
769773
}
770774

771-
Graph->InsertEdge_Unsafe(PrevIndex, SplitEdge.End, NewEdge, SplitEdge.IOIndex); // Insert last edge
772-
Graph->AddEdgeMetadata_Unsafe(NewEdge.Index, ParentEdgeMeta, EPCGExIntersectionType::EdgeEdge);
775+
// Insert last edge
776+
if (Graph->InsertEdge_Unsafe(PrevIndex, SplitEdge.End, NewEdge, SplitEdge.IOIndex))
777+
{
778+
Graph->AddEdgeMetadata_Unsafe(NewEdge.Index, ParentEdgeMeta, EPCGExIntersectionType::EdgeEdge);
779+
}
773780
}
774781
}
775782

Source/PCGExtendedToolkit/Private/PCGExHelpers.cpp

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -422,61 +422,38 @@ namespace PCGEx
422422
return false;
423423
}
424424

425-
void ReorderPointArrayData(UPCGBasePointData* InData, const TArray<int32>& InOrder)
425+
template <typename T>
426+
void ReorderValueRange(TPCGValueRange<T>& InRange, const TArray<int32>& InOrder)
426427
{
427-
TRACE_CPUPROFILER_EVENT_SCOPE(PCGExHelpers::ReorderPointArrayData);
428+
TRACE_CPUPROFILER_EVENT_SCOPE(PCGExHelpers::ReorderValueRange);
429+
430+
const int32 NumIndices = InOrder.Num();
431+
TArray<T> ValuesCopy;
432+
ValuesCopy.Reserve(NumIndices);
433+
for (int i = 0; i < NumIndices; i++){ ValuesCopy.Emplace(InRange[InOrder[i]]); }
434+
for (int i = 0; i < NumIndices; i++){ InRange[i] = ValuesCopy[i]; }
435+
}
428436

429-
const int32 NumElements = InOrder.Num();
430-
check(NumElements == InData->GetNumPoints());
437+
#define PCGEX_TPL(_TYPE, _NAME, ...) \
438+
template PCGEXTENDEDTOOLKIT_API void ReorderValueRange<_TYPE>(TPCGValueRange<_TYPE>& InRange, const TArray<int32>& InOrder);
431439

432-
TBitArray<> Visited;
433-
Visited.Init(false, NumElements);
440+
PCGEX_FOREACH_SUPPORTEDTYPES(PCGEX_TPL)
441+
#undef PCGEX_TPL
434442

443+
void ReorderPointArrayData(UPCGBasePointData* InData, const TArray<int32>& InOrder)
444+
{
445+
TRACE_CPUPROFILER_EVENT_SCOPE(PCGExHelpers::ReorderPointArrayData);
446+
435447
EPCGPointNativeProperties AllocatedProperties = InData->GetAllocatedProperties();
436448

437-
#define PCGEX_REORDER_RANGE_DECL(_NAME, _TYPE, ...)\
438-
const bool bProcess##_NAME = EnumHasAnyFlags(AllocatedProperties, EPCGPointNativeProperties::_NAME);\
439-
TPCGValueRange<_TYPE> _NAME##Range = InData->Get##_NAME##ValueRange(bProcess##_NAME);
449+
#define PCGEX_REORDER_RANGE_DECL(_NAME, _TYPE, ...) \
450+
if(EnumHasAnyFlags(AllocatedProperties, EPCGPointNativeProperties::_NAME)){ \
451+
TPCGValueRange<_TYPE> Range = InData->Get##_NAME##ValueRange(true); \
452+
ReorderValueRange<_TYPE>(Range, InOrder);}
453+
440454
PCGEX_FOREACH_POINT_NATIVE_PROPERTY(PCGEX_REORDER_RANGE_DECL)
441455
#undef PCGEX_REORDER_RANGE_DECL
442456

443-
for (int32 i = 0; i < NumElements; ++i)
444-
{
445-
if (Visited[i])
446-
{
447-
continue;
448-
}
449-
450-
int32 Current = i;
451-
int32 Next = InOrder[Current];
452-
453-
if (Next == Current)
454-
{
455-
Visited[Current] = true;
456-
continue;
457-
}
458-
459-
#define PCGEX_REORDER_MOVE_TEMP(_NAME, _TYPE, ...) _TYPE Temp##_NAME = bProcess##_NAME ? MoveTemp(_NAME##Range[Current]) : _TYPE{};
460-
PCGEX_FOREACH_POINT_NATIVE_PROPERTY(PCGEX_REORDER_MOVE_TEMP)
461-
#undef PCGEX_REORDER_MOVE_TEMP
462-
463-
while (!Visited[Next])
464-
{
465-
#define PCGEX_REORDER_MOVE_FORWARD(_NAME, _TYPE, ...) if(bProcess##_NAME){ _NAME##Range[Current] = MoveTemp(_NAME##Range[Next]); };
466-
PCGEX_FOREACH_POINT_NATIVE_PROPERTY(PCGEX_REORDER_MOVE_FORWARD)
467-
#undef PCGEX_REORDER_MOVE_FORWARD
468-
469-
Visited[Current] = true;
470-
Current = Next;
471-
Next = InOrder[Current];
472-
}
473-
474-
#define PCGEX_REORDER_MOVE_BACK(_NAME, _TYPE, ...) if(bProcess##_NAME){ _NAME##Range[Current] = MoveTemp(Temp##_NAME); }
475-
PCGEX_FOREACH_POINT_NATIVE_PROPERTY(PCGEX_REORDER_MOVE_BACK)
476-
#undef PCGEX_REORDER_MOVE_BACK
477-
478-
Visited[Current] = true;
479-
}
480457
}
481458

482459
FString GetSelectorDisplayName(const FPCGAttributePropertyInputSelector& InSelector)

Source/PCGExtendedToolkit/Private/Paths/PCGExBevelPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ namespace PCGExBevelPath
529529
{
530530
constexpr EPCGPointNativeProperties CarryOverProperties =
531531
static_cast<EPCGPointNativeProperties>(static_cast<uint8>(EPCGPointNativeProperties::All) &
532-
~static_cast<uint8>(EPCGPointNativeProperties::Transform | EPCGPointNativeProperties::Seed | EPCGPointNativeProperties::MetadataEntry));
532+
~static_cast<uint8>(EPCGPointNativeProperties::Transform | EPCGPointNativeProperties::MetadataEntry));
533533

534534
PointDataFacade->Source->ConsumeIdxMapping(CarryOverProperties);
535535
}

Source/PCGExtendedToolkit/Public/Graph/PCGExGraph.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ namespace PCGExGraph
365365

366366
void Add(const FEdge& Edge, FGraph* InGraph);
367367

368-
void Invalidate(FGraph* InGraph);
369368
void BuildCluster(const TSharedRef<PCGExCluster::FCluster>& InCluster);
370369
int32 GetFirstInIOIndex();
371370

Source/PCGExtendedToolkit/Public/PCGExHelpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,15 @@ namespace PCGEx
787787
}
788788
};
789789

790+
template <typename T>
791+
void ReorderValueRange(TPCGValueRange<T>& InRange, const TArray<int32>& InOrder);
792+
793+
#define PCGEX_TPL(_TYPE, _NAME, ...) \
794+
extern template void ReorderValueRange<_TYPE>(TPCGValueRange<_TYPE>& InRange, const TArray<int32>& InOrder);
795+
796+
PCGEX_FOREACH_SUPPORTEDTYPES(PCGEX_TPL)
797+
#undef PCGEX_TPL
798+
790799
PCGEXTENDEDTOOLKIT_API
791800
void ReorderPointArrayData(UPCGBasePointData* InData, const TArray<int32>& InOrder);
792801

0 commit comments

Comments
 (0)