aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2003-07-02 11:32:32 +0000
committerMax Horn2003-07-02 11:32:32 +0000
commit4a3da1a2b74bf9b421ab78005887b33b6191d6ba (patch)
treedacab98c160cc33ca6c49a4d8e81110b04eb1c96 /scumm
parent302f67e43f2d1f8a5755b77d0cc79daf4dec58c4 (diff)
downloadscummvm-rg350-4a3da1a2b74bf9b421ab78005887b33b6191d6ba.tar.gz
scummvm-rg350-4a3da1a2b74bf9b421ab78005887b33b6191d6ba.tar.bz2
scummvm-rg350-4a3da1a2b74bf9b421ab78005887b33b6191d6ba.zip
cleaned up the actor ordering code a bit - it should be now somewhat clearer what it does exactly
svn-id: r8709
Diffstat (limited to 'scumm')
-rw-r--r--scumm/actor.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/scumm/actor.cpp b/scumm/actor.cpp
index 3002df55f5..08e2be16f3 100644
--- a/scumm/actor.cpp
+++ b/scumm/actor.cpp
@@ -810,24 +810,32 @@ void Scumm::playActorSounds() {
}
}
-inline int32 drawOrder (const Actor* x) { return (x)->y - ((x)->layer << 11); }
-
-int sortByDrawOrder (const void* a, const void* b)
+static int compareDrawOrder(const void* a, const void* b)
{
const Actor* actor1 = *(const Actor *const*)a;
const Actor* actor2 = *(const Actor *const*)b;
- int32 order1 = drawOrder(actor1);
- int32 order2 = drawOrder(actor2);
+ int diff;
+
+ // The actor in the higher layer is ordered lower
+ diff = actor1->layer - actor2->layer;
+ if (diff < 0)
+ return +1;
+ if (diff > 0)
+ return -1;
- // The qsort() function is apparently not guaranteed to be stable (i.e.
- // it may re-order actors with the same draw order value). Use the
+ // The actor with higher y value is ordered higher
+ diff = actor1->y - actor2->y;
+ if (diff < 0)
+ return -1;
+ if (diff > 0)
+ return +1;
+
+ // The qsort() function is not guaranteed to be stable (i.e. it may
+ // re-order "equal" elements in an array it sorts). Hence we use the
// actor number as tie-breaker. This is needed for the Sam & Max intro,
// and possibly other cases as well. See bug #758167.
- if (order1 == order2)
- return actor1->number - actor2->number;
-
- return order1 - order2;
+ return actor1->number - actor2->number;
}
void Scumm::processActors() {
@@ -851,10 +859,7 @@ void Scumm::processActors() {
// Sort actors by position before we draw them (to ensure that actors in
// front are drawn after those "behind" them).
- // Bertrand TODO : Put a std::sort with a inlined comparison operator?
- // I suppose only STL containers are not allowed, not algorithms, but I prefered leaving a good old qsort
- // (Which might be slower that the previous code but just fits on one line)
- qsort(actors, numactors, sizeof (Actor*), sortByDrawOrder);
+ qsort(actors, numactors, sizeof (Actor*), compareDrawOrder);
Actor** end = actors + numactors;