diff options
-rw-r--r-- | common/algorithm.h | 21 | ||||
-rw-r--r-- | engines/parallaction/gfxbase.cpp | 25 |
2 files changed, 26 insertions, 20 deletions
diff --git a/common/algorithm.h b/common/algorithm.h index e2ee653fca..beae34245f 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -131,6 +131,27 @@ void sort(T first, T last) { } } +// Using this with: Common::Less from common/func.h +// will give the same results as the function above. +template<class T, class StrictWeakOrdering> +void sort(T first, T last, StrictWeakOrdering comp) { + if (first == last) + return; + + // Simple selection sort + T i(first); + for (; i != last; ++i) { + T minElem(i); + T j(i); + ++j; + for (; j != last; ++j) + if (comp(*j, *minElem)) + minElem = j; + if (minElem != i) + SWAP(*minElem, *i); + } +} + } // end of namespace Common #endif diff --git a/engines/parallaction/gfxbase.cpp b/engines/parallaction/gfxbase.cpp index fd581cda0e..60f00f10f5 100644 --- a/engines/parallaction/gfxbase.cpp +++ b/engines/parallaction/gfxbase.cpp @@ -27,6 +27,8 @@ #include "graphics.h" #include "disk.h" +#include "common/algorithm.h" + namespace Parallaction { GfxObj::GfxObj(uint objType, Frames *frames, const char* name) : type(objType), _frames(frames), x(0), y(0), z(0), frame(0), layer(3), _flags(0), _keep(true) { @@ -123,32 +125,15 @@ void Gfx::showGfxObj(GfxObj* obj, bool visible) { -int compareAnimationZ(const GfxObj* a1, const GfxObj* a2) { - if (a1->z == a2->z) return 0; - return (a1->z < a2->z ? -1 : 1); +bool compareAnimationZ(const GfxObj* a1, const GfxObj* a2) { + return a1->z < a2->z; } void Gfx::sortAnimations() { - GfxObjList::iterator first = _gfxobjList[kGfxObjTypeAnim].begin(); GfxObjList::iterator last = _gfxobjList[kGfxObjTypeAnim].end(); - if (first == last) - return; - - // Simple selection sort - GfxObjList::iterator i(first); - for (; i != last; ++i) { - GfxObjList::iterator minElem(i); - GfxObjList::iterator j(i); - ++j; - for (; j != last; ++j) - if (compareAnimationZ(*j, *minElem) < 0) - minElem = j; - if (minElem != i) - SWAP(*minElem, *i); - } - + Common::sort(first, last, compareAnimationZ); } void Gfx::drawGfxObjects(Graphics::Surface &surf) { |