From 209fbfceaf86826228c8411606ce3502cea6f142 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Thu, 22 Apr 2010 00:48:03 +0000 Subject: [PATCH] There's pretty clearly a larger issue here, but this seems to solve the immediate issue - ties in the sort are Really Bad as they lead to inconsistent ordering later on. But note that it's still very possible to end up with ties even with this change. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@916 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/miso/client/DirtyItemList.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/miso/client/DirtyItemList.java b/src/java/com/threerings/miso/client/DirtyItemList.java index 8dc9d748..fd067316 100644 --- a/src/java/com/threerings/miso/client/DirtyItemList.java +++ b/src/java/com/threerings/miso/client/DirtyItemList.java @@ -119,6 +119,10 @@ public class DirtyItemList // sort the items according to the depth of the rear-most tile _ditems.addAll(_items); _ditems.sort(REAR_DEPTH_COMP); + if (DEBUG_SORT) { + log.info("Sorted by rear-depth " + + "[items=" + toString(_ditems) + "]."); + } // now insertion sort the items from back to front into the // render-sorted array @@ -689,7 +693,22 @@ public class DirtyItemList * order. */ protected static final Comparator REAR_DEPTH_COMP = new Comparator() { public int compare (DirtyItem o1, DirtyItem o2) { - return (o1.getRearDepth() - o2.getRearDepth()); + int depthDiff = (o1.getRearDepth() - o2.getRearDepth()); + if (depthDiff != 0) { + return depthDiff; + } else { + // If there's a priority difference, break our tie on that. + if (o1.obj instanceof SceneObject && o2.obj instanceof SceneObject) { + int priDiff = ((SceneObject)o1.obj).getPriority() - + ((SceneObject)o2.obj).getPriority(); + if (priDiff != 0) { + return priDiff; + } + } + + // Couldn't break the tie, fallback to the original result. + return depthDiff; + } } }; }