From 2b2d4c712f50aafe385cf60ea79670a20bbc4717 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 8 Jan 2025 03:52:45 +0100 Subject: [PATCH] exorcise another sneaky case of bubble sort --- BBGE/SkeletalSprite.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 989a365..5c33ab9 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -654,21 +654,14 @@ SkeletalKeyframe *Animation::getFirstKeyframe() return 0; } -void Animation::reorderKeyframes() +inline static bool keyframeCmp(const SkeletalKeyframe& a, const SkeletalKeyframe& b) { + return a.t < b.t; +} - for (size_t i = 0; i < keyframes.size(); i++) - { - for (size_t j = 0; j < keyframes.size()-1; j++) - { - if (keyframes[j].t > keyframes[j+1].t) - { - SkeletalKeyframe temp = keyframes[j+1]; - keyframes[j+1] = keyframes[j]; - keyframes[j] = temp; - } - } - } +void Animation::reorderKeyframes() +{ + std::sort(keyframes.begin(), keyframes.end(), keyframeCmp); } void Animation::cloneKey(size_t key, float toffset)