More work on object tiles. Revamped isometric scene rendering to

gather dirty sprites and objects and render after base and fringe tile
layers.  Add shadow tiles in the footprint of objects to make them
impassable.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@460 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-13 01:08:59 +00:00
parent eb3bc62083
commit 3773da79a6
10 changed files with 439 additions and 152 deletions
@@ -0,0 +1,90 @@
//
// $Id: DirtyItemList.java,v 1.1 2001/10/13 01:08:59 shaper Exp $
package com.threerings.media.sprite;
import java.util.*;
import com.threerings.media.sprite.Sprite;
import com.threerings.media.tile.ObjectTile;
import com.threerings.media.Log;
/**
* The dirty item list keeps track of dirty sprites and object tiles
* in a scene. Since scenes can only ever have one of either item at
* any given coordinate, dirty items are stored and checked for
* equality based solely on their coordinate, and each coordinate can
* exist in the list only once.
*/
public class DirtyItemList extends ArrayList
{
/**
* Append the dirty item at the given coordinates to the dirty
* item list.
*/
public boolean appendDirtyItem (Object item, int x, int y)
{
// only allow appending sprites and object tiles
if (!(item instanceof Sprite) && !(item instanceof ObjectTile)) {
return false;
}
// only add the item if there are no existing items
if (!contains(x, y)) {
add(new DirtyItem(item, x, y));
return true;
}
return false;
}
/**
* Sort the items in the list using the given comparator.
*/
public void sort (Comparator comp)
{
Object[] items = new Object[size()];
toArray(items);
Arrays.sort(items, comp);
clear();
for (int ii = 0; ii < items.length; ii++) {
add(items[ii]);
}
}
/**
* Returns whether the list contains a dirty item at the given
* coordinates.
*/
protected boolean contains (int x, int y)
{
int size = size();
for (int ii = 0; ii < size; ii++) {
Object o = get(ii);
if (o instanceof DirtyItem) {
DirtyItem di = (DirtyItem)o;
return (x == di.x && y == di.y);
}
}
return false;
}
/**
* A wrapper class to hold the items inserted in the dirty list
* along with their coordinates in the scene.
*/
public class DirtyItem
{
public Object obj;
public int x, y;
public DirtyItem (Object obj, int x, int y)
{
this.obj = obj;
this.x = x;
this.y = y;
}
}
}
@@ -1,5 +1,5 @@
//
// $Id: DirtyRectList.java,v 1.1 2001/08/22 02:14:57 mdb Exp $
// $Id: DirtyRectList.java,v 1.2 2001/10/13 01:08:59 shaper Exp $
package com.threerings.media.sprite;
@@ -16,7 +16,8 @@ public class DirtyRectList extends ArrayList
{
/**
* Appends the specified dirty rectangle to the list only if a
* rectangle of the same size is not already in the list.
* rectangle of the same position and size is not already in the
* list.
*
* @return true if the rectangle were appended, false if she weren't.
* Har!
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.24 2001/10/12 00:36:03 shaper Exp $
// $Id: Sprite.java,v 1.25 2001/10/13 01:08:59 shaper Exp $
package com.threerings.media.sprite;
@@ -209,29 +209,21 @@ public class Sprite
}
/**
* Returns whether the sprite is inside the given polygon in
* Returns whether the sprite is inside the given shape in
* pixel coordinates.
*
* @param bounds the bounding polygon.
*
* @return whether the sprite is inside the polygon.
*/
public boolean inside (Polygon bounds)
public boolean inside (Shape shape)
{
return bounds.contains(_x, _y);
return shape.contains(_x, _y);
}
/**
* Returns whether the sprite's drawn rectangle intersects the given
* polygon in pixel coordinates.
*
* @param bounds the bounding polygon.
*
* @return whether the sprite intersects polygon.
* shape in pixel coordinates.
*/
public boolean intersects (Polygon bounds)
public boolean intersects (Shape shape)
{
return bounds.intersects(_rbounds);
return shape.intersects(_rbounds);
}
/**
@@ -1,10 +1,11 @@
//
// $Id: SpriteManager.java,v 1.14 2001/09/13 19:36:20 mdb Exp $
// $Id: SpriteManager.java,v 1.15 2001/10/13 01:08:59 shaper Exp $
package com.threerings.media.sprite;
import java.awt.*;
import java.util.*;
import java.util.List;
import com.samskivert.util.Tuple;
import com.threerings.media.Log;
@@ -36,29 +37,23 @@ public class SpriteManager
/**
* 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.
* 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 sprites that intersect
* a particular region to the given list.
*
* @param rects the dirty rectangle list being processed by the
* animated view.
* @param list the list to fill with any intersecting sprites.
* @param bounds the bounds the intersection of which we have
* interest.
*/
public void invalidateIntersectingSprites (
DirtyRectList rects, Polygon bounds)
public void getIntersectingSprites (List list, Shape shape)
{
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);
}
if (sprite.intersects(shape)) {
list.add(sprite);
}
}
}