diff --git a/src/java/com/threerings/media/AbstractMediaManager.java b/src/java/com/threerings/media/AbstractMediaManager.java index b24c71ca6..6977454d2 100644 --- a/src/java/com/threerings/media/AbstractMediaManager.java +++ b/src/java/com/threerings/media/AbstractMediaManager.java @@ -1,5 +1,5 @@ // -// $Id: AbstractMediaManager.java,v 1.9 2003/04/30 00:43:54 mdb Exp $ +// $Id: AbstractMediaManager.java,v 1.10 2003/04/30 20:48:38 mdb Exp $ package com.threerings.media; @@ -36,6 +36,33 @@ public abstract class AbstractMediaManager return _remgr; } + /** + * Must be called every frame so that the media can be properly + * updated. + */ + public void tick (long tickStamp) + { + _tickStamp = tickStamp; + tickAllMedia(tickStamp); + dispatchNotifications(); + // we clear our tick stamp when we're about to be painted, this + // lets us handle situations when yet more media is slipped in + // between our being ticked and our being painted + } + + /** + * This will always be called prior to the {@link #paint} calls for a + * particular tick. Because it is possible that there will be no dirty + * regions and thus no calls to {@link #paint} this method exists so + * that the media manager can guarantee that it will be notified when + * all ticking is complete and the painting phase has begun. + */ + public void willPaint () + { + // now that we're done ticking, we can safely clear this + _tickStamp = 0; + } + /** * Renders all registered media in the given layer that intersect * the supplied clipping rectangle to the given graphics context. @@ -45,11 +72,8 @@ public abstract class AbstractMediaManager * with a positive render order; the back layer contains all * animations with a negative render order; all, both. */ - public void renderMedia (Graphics2D gfx, int layer, Shape clip) + public void paint (Graphics2D gfx, int layer, Shape clip) { - // now that we're rendering, we can safely clear this; see tick() - _tickStamp = 0; - for (int ii = 0, nn = _media.size(); ii < nn; ii++) { AbstractMedia media = (AbstractMedia)_media.get(ii); int order = media.getRenderOrder(); @@ -69,20 +93,6 @@ public abstract class AbstractMediaManager } } - /** - * Must be called every frame so that the media can be properly - * updated. - */ - public void tick (long tickStamp) - { - _tickStamp = tickStamp; - tickAllMedia(tickStamp); - dispatchNotifications(); - // we clear our tick stamp when we've been painted, this lets us - // handle situations when yet more media is slipped in between our - // being ticked and our being painted - } - /** * If the manager is paused for some length of time, it should * be fast forwarded by the appropriate number of milliseconds. This diff --git a/src/java/com/threerings/media/MediaPanel.java b/src/java/com/threerings/media/MediaPanel.java index 8a49f40d0..93a27ae26 100644 --- a/src/java/com/threerings/media/MediaPanel.java +++ b/src/java/com/threerings/media/MediaPanel.java @@ -1,5 +1,5 @@ // -// $Id: MediaPanel.java,v 1.34 2003/04/30 06:34:55 mdb Exp $ +// $Id: MediaPanel.java,v 1.35 2003/04/30 20:48:38 mdb Exp $ package com.threerings.media; @@ -300,6 +300,14 @@ public class MediaPanel extends JComponent { Graphics2D gfx = (Graphics2D)g; + // regardless of whether or not we paint, we need to let our + // abstract media managers know that we've gotten to the point of + // painting because they need to remain prepared to deal with + // media changes that happen any time between the tick() and the + // paint() and thus need to know when paint() happens + _animmgr.willPaint(); + _spritemgr.willPaint(); + // no use in painting if we're not showing or if we've not yet // been validated if (!isValid() || !isShowing()) { @@ -474,8 +482,8 @@ public class MediaPanel extends JComponent */ protected void paintBits (Graphics2D gfx, int layer, Rectangle dirty) { - _animmgr.renderMedia(gfx, layer, dirty); - _spritemgr.renderMedia(gfx, layer, dirty); + _animmgr.paint(gfx, layer, dirty); + _spritemgr.paint(gfx, layer, dirty); } /** The frame manager with whom we register. */