Modified sprite management so that if in the course of processing its

dirty rectangles, an animated view has to expand the dirty region, it can
call back to the sprite manager to determine whether this new, expanded
dirty region includes sprites that weren't previously considered to be
dirty. If so, those sprites' rendered bounds are added to the dirty
rectangle list being processed so that they will be properly redrawn
(which may trigger more sprites to be included and so on).

Also modified sprite internals in a cleany uppy sort of way.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@309 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-22 02:14:57 +00:00
parent 5eb0afaace
commit c2fd4ed6c3
8 changed files with 182 additions and 60 deletions
@@ -1,5 +1,5 @@
//
// $Id: SpriteManager.java,v 1.9 2001/08/21 19:40:30 mdb Exp $
// $Id: SpriteManager.java,v 1.10 2001/08/22 02:14:57 mdb Exp $
package com.threerings.media.sprite;
@@ -19,7 +19,7 @@ public class SpriteManager
public SpriteManager ()
{
_sprites = new ArrayList();
_dirty = new ArrayList();
_dirty = new DirtyRectList();
}
/**
@@ -32,6 +32,35 @@ public class SpriteManager
_dirty.add(rect);
}
/**
* When an animated view processes its dirty rectangles, it may
* require an expansion of the dirty region which may in turn require
* the invalidation of more sprites than were originally invalid. In
* such cases, the animated view can call back to the sprite manager,
* asking it to append the rectangles of the sprites that intersect a
* particular region to the dirty rectangle list that it's processing.
* A sprite's rectangle will only be appended if it's not already in
* the list.
*
* @param rects the dirty rectangle list being processed by the
* animated view.
* @param bounds the bounds the intersection of which we have
* interest.
*/
public void invalidateIntersectingSprites (
DirtyRectList rects, Polygon bounds)
{
int size = _sprites.size();
for (int ii = 0; ii < size; ii++) {
Sprite sprite = (Sprite)_sprites.get(ii);
if (sprite.intersects(bounds)) {
if (rects.appendDirtyRect(sprite.getRenderedBounds())) {
Log.info("Expanded for: " + sprite);
}
}
}
}
/**
* Add a sprite to the set of sprites managed by this manager.
*
@@ -70,10 +99,10 @@ public class SpriteManager
*
* @return the list of dirty rects.
*/
public ArrayList getDirtyRects ()
public DirtyRectList getDirtyRects ()
{
// create a copy of the dirty rectangles
ArrayList dirty = (ArrayList)_dirty.clone();
DirtyRectList dirty = (DirtyRectList)_dirty.clone();
// clear out the list
_dirty.clear();
@@ -83,8 +112,8 @@ public class SpriteManager
}
/**
* Render the sprites residing within the given polygon to the
* given graphics context.
* Render the sprites residing within the given polygon to the given
* graphics context.
*
* @param gfx the graphics context.
* @param bounds the bounding polygon.
@@ -136,5 +165,5 @@ public class SpriteManager
protected ArrayList _sprites;
/** The dirty rectangles created by sprites. */
protected ArrayList _dirty;
protected DirtyRectList _dirty;
}