diff --git a/src/java/com/threerings/media/animation/Animation.java b/src/java/com/threerings/media/animation/Animation.java index 5aea759f3..1275e57c6 100644 --- a/src/java/com/threerings/media/animation/Animation.java +++ b/src/java/com/threerings/media/animation/Animation.java @@ -1,5 +1,5 @@ // -// $Id: Animation.java,v 1.7 2002/09/17 20:06:58 mdb Exp $ +// $Id: Animation.java,v 1.8 2002/09/20 21:28:20 mdb Exp $ package com.threerings.media.animation; @@ -40,8 +40,16 @@ public abstract class Animation /** * Sets the render order associated with this animation. Animations * can be rendered in two layers; those with negative render order and - * those with positive render order. Someday animations will be - * rendered in each layer according to render order. + * those with positive render order. In the same layer, animations + * will be rendered according to their render order's cardinal value + * (least to greatest). Those with the same render order value will be + * rendered in arbitrary order. + * + *
This must be set before the animation is handed to the + * {@link AnimationManager} and must not change while the {@link + * AnimationManager} is managing the animation. If you wish to change + * the render order, remove the animation from the manager, change the + * order and add it back again. */ public void setRenderOrder (int value) { diff --git a/src/java/com/threerings/media/animation/AnimationManager.java b/src/java/com/threerings/media/animation/AnimationManager.java index a05ab6662..9bc5b84d0 100644 --- a/src/java/com/threerings/media/animation/AnimationManager.java +++ b/src/java/com/threerings/media/animation/AnimationManager.java @@ -1,12 +1,14 @@ // -// $Id: AnimationManager.java,v 1.12 2002/08/15 20:56:08 shaper Exp $ +// $Id: AnimationManager.java,v 1.13 2002/09/20 21:28:20 mdb Exp $ package com.threerings.media.animation; import java.awt.Graphics2D; import java.awt.Shape; -import java.util.ArrayList; +import java.util.Comparator; + +import com.samskivert.util.SortableArrayList; import com.threerings.media.Log; import com.threerings.media.MediaConstants; @@ -42,7 +44,7 @@ public class AnimationManager } anim.setAnimationManager(this); - _anims.add(anim); + _anims.insertSorted(anim, RENDER_ORDER); } /** @@ -129,6 +131,7 @@ public class AnimationManager */ public void renderAnimations (Graphics2D gfx, int layer, Shape clip) { + // now paint them int size = _anims.size(); for (int ii = 0; ii < size; ii++) { Animation anim = (Animation)_anims.get(ii); @@ -153,5 +156,16 @@ public class AnimationManager protected RegionManager _remgr; /** The list of animations. */ - protected ArrayList _anims = new ArrayList(); + protected SortableArrayList _anims = new SortableArrayList(); + + /** Used to sort animations prior to painting. */ + protected static final Comparator RENDER_ORDER = new Comparator() { + public int compare (Object o1, Object o2) { + return (((Animation)o1)._renderOrder - + ((Animation)o2)._renderOrder); + } + public boolean equals (Object obj) { + return this == obj; + } + }; }