Revamped iso scene rendering yet again to remove unnecessary dirty
rectangle propagation and to only render the dirty portions of dirty objects and sprites. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@509 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
//
|
||||
// $Id: DirtyItemList.java,v 1.2 2001/10/17 22:13:53 shaper Exp $
|
||||
// $Id: DirtyItemList.java,v 1.3 2001/10/19 23:26:31 shaper Exp $
|
||||
|
||||
package com.threerings.media.sprite;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
@@ -14,98 +13,68 @@ 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.
|
||||
* in a scene.
|
||||
*/
|
||||
public class DirtyItemList extends ArrayList
|
||||
{
|
||||
/**
|
||||
* Appends the dirty sprite at the given coordinates to the dirty
|
||||
* item list if no item already exists at those coordinates.
|
||||
* Returns whether the item was added to the list.
|
||||
* item list.
|
||||
*/
|
||||
public boolean appendDirtySprite (Sprite sprite, int x, int y)
|
||||
public void appendDirtySprite (
|
||||
Sprite sprite, int x, int y, Rectangle dirtyRect)
|
||||
{
|
||||
if (!contains(x, y)) {
|
||||
add(new DirtyItem(sprite, null, x, y));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
add(new DirtyItem(sprite, null, x, y, dirtyRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the dirty object tile at the given coordinates to the
|
||||
* dirty item list if no item already exists at those coordinates.
|
||||
* Returns whether the item was added to the list.
|
||||
* dirty item list.
|
||||
*/
|
||||
public boolean appendDirtyObject (
|
||||
ObjectTile tile, Shape bounds, int x, int y)
|
||||
public void appendDirtyObject (
|
||||
ObjectTile tile, Shape bounds, int x, int y, Rectangle dirtyRect)
|
||||
{
|
||||
if (!contains(x, y)) {
|
||||
add(new DirtyItem(tile, bounds, x, y));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
add(new DirtyItem(tile, bounds, x, y, dirtyRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* A class to hold the items inserted in the dirty list along with
|
||||
* all of the information necessary to render their dirty regions
|
||||
* to the target graphics context when the time comes to do so.
|
||||
*/
|
||||
public class DirtyItem
|
||||
{
|
||||
public Object obj;
|
||||
public Shape bounds;
|
||||
public int x, y;
|
||||
public Rectangle dirtyRect;
|
||||
|
||||
public DirtyItem (Object obj, Shape bounds, int x, int y)
|
||||
/**
|
||||
* Constructs a dirty item.
|
||||
*/
|
||||
public DirtyItem (
|
||||
Object obj, Shape bounds, int x, int y, Rectangle dirtyRect)
|
||||
{
|
||||
this.obj = obj;
|
||||
this.bounds = bounds;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.dirtyRect = dirtyRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the dirty item to the given graphics context. Only
|
||||
* the dirty rectangle of the item is question is actually
|
||||
* drawn.
|
||||
*/
|
||||
public void paint (Graphics2D gfx)
|
||||
{
|
||||
// clip the draw region to the dirty portion of the item
|
||||
gfx.setClip(dirtyRect);
|
||||
|
||||
// paint the item
|
||||
if (obj instanceof Sprite) {
|
||||
((Sprite)obj).paint(gfx);
|
||||
|
||||
} else {
|
||||
((ObjectTile)obj).paint(gfx, bounds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user