Animation manager now takes into account fine grained render order when

rendering animations.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1728 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-09-20 21:28:20 +00:00
parent 487bbec942
commit c1667c3782
2 changed files with 29 additions and 7 deletions
@@ -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; package com.threerings.media.animation;
@@ -40,8 +40,16 @@ public abstract class Animation
/** /**
* Sets the render order associated with this animation. Animations * Sets the render order associated with this animation. Animations
* can be rendered in two layers; those with negative render order and * can be rendered in two layers; those with negative render order and
* those with positive render order. Someday animations will be * those with positive render order. In the same layer, animations
* rendered in each layer according to render order. * 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.
*
* <p> This must be set <em>before</em> 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) public void setRenderOrder (int value)
{ {
@@ -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; package com.threerings.media.animation;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Shape; 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.Log;
import com.threerings.media.MediaConstants; import com.threerings.media.MediaConstants;
@@ -42,7 +44,7 @@ public class AnimationManager
} }
anim.setAnimationManager(this); 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) public void renderAnimations (Graphics2D gfx, int layer, Shape clip)
{ {
// now paint them
int size = _anims.size(); int size = _anims.size();
for (int ii = 0; ii < size; ii++) { for (int ii = 0; ii < size; ii++) {
Animation anim = (Animation)_anims.get(ii); Animation anim = (Animation)_anims.get(ii);
@@ -153,5 +156,16 @@ public class AnimationManager
protected RegionManager _remgr; protected RegionManager _remgr;
/** The list of animations. */ /** 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;
}
};
} }