[Scummvm-cvs-logs] SF.net SVN: scummvm: [30692] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Mon Jan 28 23:05:23 CET 2008


Revision: 30692
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30692&view=rev
Author:   lordhoto
Date:     2008-01-28 14:05:23 -0800 (Mon, 28 Jan 2008)

Log Message:
-----------
- make Common::sort supporting a function object to compare two entries instead of operator <
- adapt parallaction to use the new Common::sort function

Modified Paths:
--------------
    scummvm/trunk/common/algorithm.h
    scummvm/trunk/engines/parallaction/gfxbase.cpp

Modified: scummvm/trunk/common/algorithm.h
===================================================================
--- scummvm/trunk/common/algorithm.h	2008-01-28 21:54:44 UTC (rev 30691)
+++ scummvm/trunk/common/algorithm.h	2008-01-28 22:05:23 UTC (rev 30692)
@@ -131,6 +131,27 @@
 	}
 }
 
+// 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
 

Modified: scummvm/trunk/engines/parallaction/gfxbase.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gfxbase.cpp	2008-01-28 21:54:44 UTC (rev 30691)
+++ scummvm/trunk/engines/parallaction/gfxbase.cpp	2008-01-28 22:05:23 UTC (rev 30692)
@@ -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 @@
 
 
 
-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) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list