com.threerings.miso.client
Class DirtyItemList

java.lang.Object
  extended by com.threerings.miso.client.DirtyItemList

public class DirtyItemList
extends Object

The dirty item list keeps track of dirty sprites and object tiles in a scene.


Nested Class Summary
 class DirtyItemList.DirtyItem
          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.
protected static class DirtyItemList.OriginComparator
          A comparator class for use in sorting dirty items in ascending origin x- or y-axis coordinate order.
protected  class DirtyItemList.RenderComparator
          A comparator class for use in sorting the dirty sprites and objects in a scene in ascending x- and y-coordinate order suitable for rendering in the isometric view with proper visual results.
 
Field Summary
protected  SortableArrayList<DirtyItemList.DirtyItem> _ditems
          The list of dirty items sorted by rear-depth.
protected  ArrayList<DirtyItemList.DirtyItem> _freelist
          Unused dirty items.
protected  SortableArrayList<DirtyItemList.DirtyItem> _items
          The list of dirty items.
protected  Comparator<DirtyItemList.DirtyItem> _rcomp
          The render comparator we'll use for our final, magical sort.
protected  SortableArrayList<DirtyItemList.DirtyItem> _xitems
          The list of dirty items sorted by x-position.
protected  SortableArrayList<DirtyItemList.DirtyItem> _yitems
          The list of dirty items sorted by y-position.
protected static boolean DEBUG_COMPARE
          Whether to log debug info when comparing pairs of dirty items.
protected static boolean DEBUG_SORT
          Whether to log debug info for the main dirty item sorting algorithm.
protected static Comparator<DirtyItemList.DirtyItem> ORIGIN_X_COMP
          The comparator used to sort dirty items in ascending origin x-coordinate order.
protected static Comparator<DirtyItemList.DirtyItem> ORIGIN_Y_COMP
          The comparator used to sort dirty items in ascending origin y-coordinate order.
protected static Comparator<DirtyItemList.DirtyItem> REAR_DEPTH_COMP
          The comparator used to sort dirty items in ascending "rear-depth" order.
protected static int X_AXIS
          Constants used to denote axis sorting constraints.
protected static int Y_AXIS
           
 
Constructor Summary
DirtyItemList()
          Creates a dirt item list that will handle dirty items for the specified view.
 
Method Summary
 void appendDirtyObject(SceneObject scobj)
          Appends the dirty object tile at the given coordinates to the dirty item list.
 void appendDirtySprite(Sprite sprite, int tx, int ty)
          Appends the dirty sprite at the given coordinates to the dirty item list.
 void clear()
          Clears out any items that were in this list.
 DirtyItemList.DirtyItem get(int idx)
          Returns the dirty item at the given index in the list.
protected  DirtyItemList.DirtyItem getDirtyItem()
          Obtains a new dirty item instance, reusing an old one if possible or creating a new one otherwise.
 void paintAndClear(Graphics2D gfx)
          Paints all the dirty items in this list using the supplied graphics context.
 int size()
          Returns the number of items in the dirty item list.
 void sort()
          Returns an array of the DirtyItemList.DirtyItem objects in the list sorted in proper rendering order.
protected static String toString(DirtyItemList.DirtyItem a)
          Returns an abbreviated string representation of the given dirty item describing only its origin coordinates and render priority.
protected static String toString(DirtyItemList.DirtyItem a, DirtyItemList.DirtyItem b)
          Returns an abbreviated string representation of the two given dirty items.
protected static String toString(SortableArrayList<DirtyItemList.DirtyItem> items)
          Returns an abbreviated string representation of the given dirty items.
protected static void toString(StringBuilder buf, DirtyItemList.DirtyItem item)
          Helper function for toString(DirtyItem).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_items

protected SortableArrayList<DirtyItemList.DirtyItem> _items
The list of dirty items.


_xitems

protected SortableArrayList<DirtyItemList.DirtyItem> _xitems
The list of dirty items sorted by x-position.


_yitems

protected SortableArrayList<DirtyItemList.DirtyItem> _yitems
The list of dirty items sorted by y-position.


_ditems

protected SortableArrayList<DirtyItemList.DirtyItem> _ditems
The list of dirty items sorted by rear-depth.


_rcomp

protected Comparator<DirtyItemList.DirtyItem> _rcomp
The render comparator we'll use for our final, magical sort.


_freelist

protected ArrayList<DirtyItemList.DirtyItem> _freelist
Unused dirty items.


DEBUG_COMPARE

protected static final boolean DEBUG_COMPARE
Whether to log debug info when comparing pairs of dirty items.

See Also:
Constant Field Values

DEBUG_SORT

protected static final boolean DEBUG_SORT
Whether to log debug info for the main dirty item sorting algorithm.

See Also:
Constant Field Values

X_AXIS

protected static final int X_AXIS
Constants used to denote axis sorting constraints.

See Also:
Constant Field Values

Y_AXIS

protected static final int Y_AXIS
See Also:
Constant Field Values

ORIGIN_X_COMP

protected static final Comparator<DirtyItemList.DirtyItem> ORIGIN_X_COMP
The comparator used to sort dirty items in ascending origin x-coordinate order.


ORIGIN_Y_COMP

protected static final Comparator<DirtyItemList.DirtyItem> ORIGIN_Y_COMP
The comparator used to sort dirty items in ascending origin y-coordinate order.


REAR_DEPTH_COMP

protected static final Comparator<DirtyItemList.DirtyItem> REAR_DEPTH_COMP
The comparator used to sort dirty items in ascending "rear-depth" order.

Constructor Detail

DirtyItemList

public DirtyItemList()
Creates a dirt item list that will handle dirty items for the specified view.

Method Detail

appendDirtySprite

public void appendDirtySprite(Sprite sprite,
                              int tx,
                              int ty)
Appends the dirty sprite at the given coordinates to the dirty item list.

Parameters:
sprite - the dirty sprite itself.
tx - the sprite's x tile position.
ty - the sprite's y tile position.

appendDirtyObject

public void appendDirtyObject(SceneObject scobj)
Appends the dirty object tile at the given coordinates to the dirty item list.

Parameters:
scobj - the scene object that is dirty.

get

public DirtyItemList.DirtyItem get(int idx)
Returns the dirty item at the given index in the list.


sort

public void sort()
Returns an array of the DirtyItemList.DirtyItem objects in the list sorted in proper rendering order.


paintAndClear

public void paintAndClear(Graphics2D gfx)
Paints all the dirty items in this list using the supplied graphics context. The items are removed from the dirty list after being painted and the dirty list ends up empty.


clear

public void clear()
Clears out any items that were in this list.


size

public int size()
Returns the number of items in the dirty item list.


getDirtyItem

protected DirtyItemList.DirtyItem getDirtyItem()
Obtains a new dirty item instance, reusing an old one if possible or creating a new one otherwise.


toString

protected static String toString(DirtyItemList.DirtyItem a)
Returns an abbreviated string representation of the given dirty item describing only its origin coordinates and render priority. Intended for debugging purposes.


toString

protected static String toString(DirtyItemList.DirtyItem a,
                                 DirtyItemList.DirtyItem b)
Returns an abbreviated string representation of the two given dirty items. See toString(DirtyItem).


toString

protected static String toString(SortableArrayList<DirtyItemList.DirtyItem> items)
Returns an abbreviated string representation of the given dirty items. See toString(DirtyItem).


toString

protected static void toString(StringBuilder buf,
                               DirtyItemList.DirtyItem item)
Helper function for toString(DirtyItem).