Factored some duplicated code into a shared method that can be used to easily

and efficiently dirty old and new bounds when our bounds change.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@88 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2006-12-05 06:51:41 +00:00
parent 8286ef88c4
commit 7850123988
3 changed files with 43 additions and 32 deletions
@@ -271,10 +271,43 @@ public abstract class AbstractMedia
_firstTick = tickStamp;
}
/**
* If this media's size or location are changing, it should create a new
* rectangle from its old boudns (new Rectangle(_bounds)), then effect the
* bounds changes and then call this method with the old bounds and this
* method will either merge the new bounds with the old to create a single
* dirty rectangle or dirty them separately depending on which is more
* appropriate. It will also behave properly if this media is not currently
* managed (not being rendered) by NOOPing.
*
* <em>Do not</em> pass {@link #_bounds} to this method. The rectangle
* passed in will be modified and then passed on to the region manager
* which will modify it further.
*/
protected void invalidateAfterChange (Rectangle obounds)
{
// if we're not added we need not dirty
if (_mgr == null) {
return;
}
// if our new bounds intersect our old bounds, grow a single dirty
// rectangle to incorporate them both
if (_bounds.intersects(obounds)) {
obounds.add(_bounds);
} else {
// otherwise invalidate our new bounds separately
_mgr.getRegionManager().invalidateRegion(_bounds);
}
// finally invalidate the original/merged bounds
_mgr.getRegionManager().addDirtyRegion(obounds);
}
/**
* Called by the media manager after the media is removed from service.
* Derived classes may override this method, but should be sure to
* call <code>super.shutdown()</code>.
* Derived classes may override this method, but should be sure to call
* <code>super.shutdown()</code>.
*/
protected void shutdown ()
{