com.threerings.media
Class MetaMediaManager

java.lang.Object
  extended by com.threerings.media.MetaMediaManager
All Implemented Interfaces:
MediaConstants, Iterable<AbstractMedia>

public class MetaMediaManager
extends Object
implements MediaConstants, Iterable<AbstractMedia>

Coordinates interaction between a sprite and animation manager and the media host that hosts and renders them. This class is a little fiddly because MediaPanel has been around a long time and is thoroughly out in the wild and now that we need to abstract out a bunch of its functionality, we're constrained by all the extant usages and derivations.


Field Summary
protected  AnimationManager _animmgr
          The animation manager in use by this panel.
protected  int[] _dirty
          Used to keep metrics.
protected  float _dirtyPerTick
          Used to keep metrics.
protected  FrameManager _framemgr
          The frame manager with whom we register.
protected  MediaHost _host
          Our media host, so gracious and accomodating.
protected  boolean _paused
          Whether we're currently paused.
protected  long _pauseTime
          Used to track the clock time at which we were paused.
protected  Label _perfLabel
           
protected  Rectangle _perfRect
           
protected  String _perfStatus
           
protected  RegionManager _remgr
          Used to accumulate and merge dirty regions on each tick.
protected  SpriteManager _spritemgr
          The sprite manager in use by this panel.
protected  int _tick
          Used to keep metrics.
 
Fields inherited from interface com.threerings.media.MediaConstants
ALL, BACK, FRONT
 
Constructor Summary
MetaMediaManager(FrameManager framemgr, MediaHost host)
           
 
Method Summary
 void abortAnimation(Animation anim)
          Aborts a currently running animation and removes it from this panel.
 void addAnimation(Animation anim)
          Adds an animation to this panel.
 void addSprite(Sprite sprite)
          Adds a sprite to this panel.
 void clearAnimations()
          Removes all animations from this panel.
 void clearSprites()
          Removes all sprites from this panel.
 AnimationManager getAnimationManager()
          Returns a reference to the animation manager used by this media panel.
 FrameManager getFrameManager()
          Returns the frame manager with which we are coordinating.
 RegionManager getRegionManager()
          Returns the region manager used to coordinate our dirty regions.
 SpriteManager getSpriteManager()
          Returns a reference to the sprite manager used by this media panel.
 long getTimeStamp()
          Returns a timestamp from the MediaTimer used to track time intervals for this media panel.
 boolean isManaged(Animation anim)
           
 boolean isManaged(Sprite sprite)
           
 boolean isPaused()
          Returns true if we are paused, false if we are running normally.
 Iterator<AbstractMedia> iterator()
           
 boolean needsPaint()
          Our media front end should implement FrameParticipant and call this method in their FrameParticipant.needsPaint() method.
 void noteDirty(int regions)
          Called by the host to coordinate dirty region tracking.
 void paintMedia(Graphics2D gfx, int layer, Rectangle dirty)
          Renders the sprites and animations that intersect the supplied dirty region in the specified layer.
 void paintPerf(Graphics2D gfx)
          Renders our performance debugging information if enabled.
 void removeSprite(Sprite sprite)
          Removes a sprite from this panel.
 void setPaused(boolean paused)
          Pauses the sprites and animations that are currently active on this media panel.
 void tick(long tickStamp)
          Our media front end should implement FrameParticipant and call this method in their FrameParticipant.tick(long) method.
 void viewLocationDidChange(int dx, int dy)
          If our host supports scrolling around in a virtual view, it should call this method when the view origin changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_framemgr

protected FrameManager _framemgr
The frame manager with whom we register.


_host

protected MediaHost _host
Our media host, so gracious and accomodating.


_remgr

protected RegionManager _remgr
Used to accumulate and merge dirty regions on each tick.


_animmgr

protected AnimationManager _animmgr
The animation manager in use by this panel.


_spritemgr

protected SpriteManager _spritemgr
The sprite manager in use by this panel.


_paused

protected boolean _paused
Whether we're currently paused.


_pauseTime

protected long _pauseTime
Used to track the clock time at which we were paused.


_dirty

protected int[] _dirty
Used to keep metrics.


_tick

protected int _tick
Used to keep metrics.


_dirtyPerTick

protected float _dirtyPerTick
Used to keep metrics.


_perfStatus

protected String _perfStatus

_perfLabel

protected Label _perfLabel

_perfRect

protected Rectangle _perfRect
Constructor Detail

MetaMediaManager

public MetaMediaManager(FrameManager framemgr,
                        MediaHost host)
Method Detail

getFrameManager

public FrameManager getFrameManager()
Returns the frame manager with which we are coordinating.


getAnimationManager

public AnimationManager getAnimationManager()
Returns a reference to the animation manager used by this media panel.


getSpriteManager

public SpriteManager getSpriteManager()
Returns a reference to the sprite manager used by this media panel.


getRegionManager

public RegionManager getRegionManager()
Returns the region manager used to coordinate our dirty regions.


isPaused

public boolean isPaused()
Returns true if we are paused, false if we are running normally.


setPaused

public void setPaused(boolean paused)
Pauses the sprites and animations that are currently active on this media panel. Also stops listening to the frame tick while paused.


getTimeStamp

public long getTimeStamp()
Returns a timestamp from the MediaTimer used to track time intervals for this media panel. Note: this should only be called from the AWT thread.


addSprite

public void addSprite(Sprite sprite)
Adds a sprite to this panel.


isManaged

public boolean isManaged(Sprite sprite)
Returns:
true if the sprite is already added to this panel.

removeSprite

public void removeSprite(Sprite sprite)
Removes a sprite from this panel.


clearSprites

public void clearSprites()
Removes all sprites from this panel.


addAnimation

public void addAnimation(Animation anim)
Adds an animation to this panel. Animations are automatically removed when they finish.


isManaged

public boolean isManaged(Animation anim)
Returns:
true if the animation is already added to this panel.

abortAnimation

public void abortAnimation(Animation anim)
Aborts a currently running animation and removes it from this panel. Animations are normally automatically removed when they finish.


clearAnimations

public void clearAnimations()
Removes all animations from this panel.


noteDirty

public void noteDirty(int regions)
Called by the host to coordinate dirty region tracking. This should be supplied with the number of dirty regions being painted on this tick and called just before painting them.


tick

public void tick(long tickStamp)
Our media front end should implement FrameParticipant and call this method in their FrameParticipant.tick(long) method. They must also first check isPaused() and not call this method if we are paused. As they will probably want to have willTick() and didTick() calldown methods, we cannot handle pausedness for them.


needsPaint

public boolean needsPaint()
Our media front end should implement FrameParticipant and call this method in their FrameParticipant.needsPaint() method.


paintMedia

public void paintMedia(Graphics2D gfx,
                       int layer,
                       Rectangle dirty)
Renders the sprites and animations that intersect the supplied dirty region in the specified layer.


paintPerf

public void paintPerf(Graphics2D gfx)
Renders our performance debugging information if enabled.


viewLocationDidChange

public void viewLocationDidChange(int dx,
                                  int dy)
If our host supports scrolling around in a virtual view, it should call this method when the view origin changes.


iterator

public Iterator<AbstractMedia> iterator()
Specified by:
iterator in interface Iterable<AbstractMedia>