mirror of
https://github.com/leozide/leocad
synced 2024-11-17 07:47:55 +01:00
Faster parts list sorting.
This commit is contained in:
parent
bd25c7f31a
commit
33fe9cfac2
3 changed files with 10 additions and 39 deletions
|
@ -4,8 +4,6 @@ template <class T>
|
|||
class lcArray
|
||||
{
|
||||
public:
|
||||
typedef int (*lcArrayCompareFunc)(const T& a, const T& b);
|
||||
|
||||
lcArray(int Size = 0, int Grow = 16)
|
||||
{
|
||||
mData = nullptr;
|
||||
|
@ -207,34 +205,6 @@ public:
|
|||
return -1;
|
||||
}
|
||||
|
||||
void Sort(lcArrayCompareFunc CompareFunc)
|
||||
{
|
||||
if (mLength <= 1)
|
||||
return;
|
||||
|
||||
int i = 1;
|
||||
bool Flipped;
|
||||
|
||||
do
|
||||
{
|
||||
Flipped = false;
|
||||
|
||||
for (int j = mLength - 1; j >= i; --j)
|
||||
{
|
||||
T& a = mData[j];
|
||||
T& b = mData[j - 1];
|
||||
|
||||
if (CompareFunc(b, a) > 0)
|
||||
{
|
||||
T Tmp = b;
|
||||
mData[j - 1] = a;
|
||||
mData[j] = Tmp;
|
||||
Flipped = true;
|
||||
}
|
||||
}
|
||||
} while ((++i < mLength) && Flipped);
|
||||
}
|
||||
|
||||
protected:
|
||||
T* mData;
|
||||
int mLength;
|
||||
|
|
|
@ -844,7 +844,7 @@ struct lcMergeSection
|
|||
lcLibraryMeshSection* Lod;
|
||||
};
|
||||
|
||||
static int LibraryMeshSectionCompare(lcMergeSection const& First, lcMergeSection const& Second)
|
||||
static bool lcLibraryMeshSectionCompare(const lcMergeSection& First, const lcMergeSection& Second)
|
||||
{
|
||||
lcLibraryMeshSection* a = First.Lod ? First.Lod : First.Shared;
|
||||
lcLibraryMeshSection* b = Second.Lod ? Second.Lod : Second.Shared;
|
||||
|
@ -864,10 +864,10 @@ static int LibraryMeshSectionCompare(lcMergeSection const& First, lcMergeSection
|
|||
int Primitive = PrimitiveOrder[PrimitiveType];
|
||||
|
||||
if (a->mPrimitiveType == Primitive)
|
||||
return -1;
|
||||
return true;
|
||||
|
||||
if (b->mPrimitiveType == Primitive)
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,9 +875,9 @@ static int LibraryMeshSectionCompare(lcMergeSection const& First, lcMergeSection
|
|||
bool TranslucentB = lcIsColorTranslucent(b->mColor);
|
||||
|
||||
if (TranslucentA != TranslucentB)
|
||||
return TranslucentA ? 1 : -1;
|
||||
return !TranslucentA;
|
||||
|
||||
return a->mColor > b->mColor ? -1 : 1;
|
||||
return a->mColor > b->mColor;
|
||||
}
|
||||
|
||||
lcMesh* lcLibraryMeshData::CreateMesh()
|
||||
|
@ -994,7 +994,7 @@ lcMesh* lcLibraryMeshData::CreateMesh()
|
|||
}
|
||||
|
||||
NumSections[LodIdx] = MergeSections[LodIdx].GetSize();
|
||||
MergeSections[LodIdx].Sort(LibraryMeshSectionCompare);
|
||||
std::sort(MergeSections[LodIdx].begin(), MergeSections[LodIdx].end(), lcLibraryMeshSectionCompare);
|
||||
}
|
||||
|
||||
Mesh->Create(NumSections, NumVertices, NumTexturedVertices, NumIndices);
|
||||
|
|
|
@ -144,12 +144,13 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
|
|||
}
|
||||
}
|
||||
|
||||
auto lcPartSortFunc=[](PieceInfo* const& a, PieceInfo* const& b)
|
||||
auto lcPartSortFunc=[](const PieceInfo* a, const PieceInfo* b)
|
||||
{
|
||||
return strcmp(a->m_strDescription, b->m_strDescription);
|
||||
return strcmp(a->m_strDescription, b->m_strDescription) < 0;
|
||||
};
|
||||
|
||||
SingleParts.Sort(lcPartSortFunc);
|
||||
std::sort(SingleParts.begin(), SingleParts.end(), lcPartSortFunc);
|
||||
|
||||
mParts.resize(SingleParts.GetSize());
|
||||
|
||||
for (int PartIdx = 0; PartIdx < SingleParts.GetSize(); PartIdx++)
|
||||
|
|
Loading…
Reference in a new issue