MCPcopy Create free account
hub / github.com/PCGEx/PCGExtendedToolkit / Sort

Method Sort

Source/PCGExtendedToolkit/Private/PCGExSorting.cpp:19–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void FPCGExCollectionSortingDetails::Sort(const FPCGContext* InContext, const TSharedPtr<PCGExData::FPointIOCollection>& InCollection) const
20{
21 TRACE_CPUPROFILER_EVENT_SCOPE(FPointIOCollection::SortByTag);
22
23 if (!bEnabled) { return; }
24
25 const FString TagNameStr = TagName.ToString();
26 TArray<double> Scores;
27
28 TArray<TSharedPtr<PCGExData::FPointIO>>& Pairs = InCollection->Pairs;
29
30 Scores.SetNumUninitialized(Pairs.Num());
31
32#if WITH_EDITOR
33 if (!bQuietMissingTagWarning)
34 {
35 for (int i = 0; i < Pairs.Num(); i++)
36 {
37 Pairs[i]->IOIndex = i;
38 if (const TSharedPtr<PCGExTags::FTagValue> Value = Pairs[i]->Tags->GetValue(TagNameStr))
39 {
40 Scores[i] = Value->GetValue<double>();
41 }
42 else
43 {
44 PCGE_LOG_C(Warning, GraphAndLog, InContext, FText::Format(FTEXT("Some data is missing the '{0}' value tag."), FText::FromString(TagNameStr)));
45 Scores[i] = (static_cast<double>(i) + FallbackOrderOffset) * FallbackOrderMultiplier;
46 }
47 }
48 }
49 else
50#endif
51 {
52 for (int i = 0; i < Pairs.Num(); i++)
53 {
54 Pairs[i]->IOIndex = i;
55 Scores[i] = Pairs[i]->Tags->GetValue(TagNameStr, (static_cast<double>(i) + FallbackOrderOffset) * FallbackOrderMultiplier);
56 }
57 }
58
59 if (Direction == EPCGExSortDirection::Ascending)
60 {
61 Pairs.Sort([&](const TSharedPtr<PCGExData::FPointIO>& A, const TSharedPtr<PCGExData::FPointIO>& B) { return Scores[A->IOIndex] < Scores[B->IOIndex]; });
62 }
63 else
64 {
65 Pairs.Sort([&](const TSharedPtr<PCGExData::FPointIO>& A, const TSharedPtr<PCGExData::FPointIO>& B) { return Scores[A->IOIndex] > Scores[B->IOIndex]; });
66 }
67
68 for (int i = 0; i < Pairs.Num(); i++) { Pairs[i]->IOIndex = i; }
69}
70
71bool UPCGExSortingRule::RegisterConsumableAttributesWithData(FPCGExContext* InContext, const UPCGData* InData) const
72{

Callers 6

ScopeIndicesFunction · 0.45
GetMedianFunction · 0.45
GetInputFactoriesFunction · 0.45
SortFunction · 0.45

Calls 2

NumMethod · 0.80
GetValueMethod · 0.80

Tested by

no test coverage detected