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:
@@ -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 ()
|
||||
{
|
||||
|
||||
@@ -69,25 +69,14 @@ public abstract class Animation extends AbstractMedia
|
||||
return; // no-op
|
||||
}
|
||||
|
||||
// start with our current bounds
|
||||
Rectangle dirty = new Rectangle(_bounds);
|
||||
// make a note of our current bounds
|
||||
Rectangle obounds = new Rectangle(_bounds);
|
||||
|
||||
// move ourselves
|
||||
super.setLocation(x, y);
|
||||
|
||||
// grow the dirty rectangle to incorporate our new bounds and pass
|
||||
// the dirty region to our region manager
|
||||
if (_mgr != null) {
|
||||
// if our new bounds intersect our old bounds, grow a single
|
||||
// dirty rectangle to incorporate them both
|
||||
if (_bounds.intersects(dirty)) {
|
||||
dirty.add(_bounds);
|
||||
} else {
|
||||
// otherwise invalidate our new bounds separately
|
||||
_mgr.getRegionManager().invalidateRegion(_bounds);
|
||||
}
|
||||
_mgr.getRegionManager().addDirtyRegion(dirty);
|
||||
}
|
||||
// this method will invalidate our old and new bounds efficiently
|
||||
invalidateAfterChange(obounds);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
|
||||
@@ -154,8 +154,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
return; // no-op
|
||||
}
|
||||
|
||||
// start with our current bounds
|
||||
Rectangle dirty = new Rectangle(_bounds);
|
||||
// make a note of our current bounds
|
||||
Rectangle obounds = new Rectangle(_bounds);
|
||||
|
||||
// move ourselves
|
||||
_ox = x;
|
||||
@@ -165,19 +165,8 @@ public abstract class Sprite extends AbstractMedia
|
||||
// of our current bounds
|
||||
updateRenderOrigin();
|
||||
|
||||
// grow the dirty rectangle to incorporate our new bounds and pass
|
||||
// the dirty region to our region manager
|
||||
if (_mgr != null) {
|
||||
// if our new bounds intersect our old bounds, grow a single
|
||||
// dirty rectangle to incorporate them both
|
||||
if (_bounds.intersects(dirty)) {
|
||||
dirty.add(_bounds);
|
||||
} else {
|
||||
// otherwise invalidate our new bounds separately
|
||||
_mgr.getRegionManager().invalidateRegion(_bounds);
|
||||
}
|
||||
_mgr.getRegionManager().addDirtyRegion(dirty);
|
||||
}
|
||||
// this method will invalidate our old and new bounds efficiently
|
||||
invalidateAfterChange(obounds);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
|
||||
Reference in New Issue
Block a user