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
This commit is contained in:
Mike Thomas
2010-04-22 00:48:03 +00:00
parent aaddc866e8
commit 209fbfceaf
@@ -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<DirtyItem> REAR_DEPTH_COMP = new Comparator<DirtyItem>() {
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;
}
}
};
}