Added enumerateSprites() and removeSprites().
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3192 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SpriteManager.java,v 1.43 2004/08/27 02:12:41 mdb Exp $
|
// $Id: SpriteManager.java,v 1.44 2004/10/30 04:33:08 mdb Exp $
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
@@ -26,6 +26,7 @@ import java.awt.Shape;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.threerings.media.AbstractMediaManager;
|
import com.threerings.media.AbstractMediaManager;
|
||||||
import com.threerings.media.RegionManager;
|
import com.threerings.media.RegionManager;
|
||||||
@@ -35,6 +36,14 @@ import com.threerings.media.RegionManager;
|
|||||||
*/
|
*/
|
||||||
public class SpriteManager extends AbstractMediaManager
|
public class SpriteManager extends AbstractMediaManager
|
||||||
{
|
{
|
||||||
|
/** A predicate used to operate on sprites (see {@link #removeSprites}. */
|
||||||
|
public static interface Predicate
|
||||||
|
{
|
||||||
|
/** Returns true if this sprite is to be included by the predicate,
|
||||||
|
* false if it should be excluded. */
|
||||||
|
public boolean evaluate (Sprite sprite);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct and initialize the sprite manager.
|
* Construct and initialize the sprite manager.
|
||||||
*/
|
*/
|
||||||
@@ -52,8 +61,7 @@ public class SpriteManager extends AbstractMediaManager
|
|||||||
* a particular region to the given list.
|
* a particular region to the given list.
|
||||||
*
|
*
|
||||||
* @param list the list to fill with any intersecting sprites.
|
* @param list the list to fill with any intersecting sprites.
|
||||||
* @param bounds the bounds the intersection of which we have
|
* @param shape the shape in which we have interest.
|
||||||
* interest.
|
|
||||||
*/
|
*/
|
||||||
public void getIntersectingSprites (List list, Shape shape)
|
public void getIntersectingSprites (List list, Shape shape)
|
||||||
{
|
{
|
||||||
@@ -111,6 +119,15 @@ public class SpriteManager extends AbstractMediaManager
|
|||||||
return Collections.unmodifiableList(_media);
|
return Collections.unmodifiableList(_media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator over our managed sprites. Do not call
|
||||||
|
* {@link Iterator#remove}.
|
||||||
|
*/
|
||||||
|
public Iterator enumerateSprites ()
|
||||||
|
{
|
||||||
|
return _media.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified sprite from the set of sprites managed by
|
* Removes the specified sprite from the set of sprites managed by
|
||||||
* this manager.
|
* this manager.
|
||||||
@@ -122,6 +139,28 @@ public class SpriteManager extends AbstractMediaManager
|
|||||||
removeMedia(sprite);
|
removeMedia(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all sprites that match the supplied predicate.
|
||||||
|
*/
|
||||||
|
public void removeSprites (Predicate pred)
|
||||||
|
{
|
||||||
|
int idxoff = 0;
|
||||||
|
for (int ii = 0, ll = _media.size(); ii < ll; ii++) {
|
||||||
|
Sprite sprite = (Sprite)_media.get(ii-idxoff);
|
||||||
|
if (pred.evaluate(sprite)) {
|
||||||
|
_media.remove(sprite);
|
||||||
|
sprite.invalidate();
|
||||||
|
sprite.shutdown();
|
||||||
|
// we need to preserve the original "index" relative to the
|
||||||
|
// current tick position, so we don't decrement ii directly
|
||||||
|
idxoff++;
|
||||||
|
if (ii <= _tickpos) {
|
||||||
|
_tickpos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the sprite paths to the given graphics context.
|
* Render the sprite paths to the given graphics context.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user