Small changes: render object spots; handle ObjectList changes; other
business. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2270 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
//
|
//
|
||||||
// $Id: DirtyItemList.java,v 1.21 2003/02/11 05:47:28 mdb Exp $
|
// $Id: DirtyItemList.java,v 1.22 2003/02/12 05:46:05 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.client;
|
package com.threerings.miso.client;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Polygon;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
|
||||||
@@ -25,6 +27,15 @@ import com.threerings.miso.client.util.IsoUtil;
|
|||||||
*/
|
*/
|
||||||
public class DirtyItemList
|
public class DirtyItemList
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates a dirt item list that will handle dirty items for the
|
||||||
|
* specified view.
|
||||||
|
*/
|
||||||
|
public DirtyItemList (IsoSceneView view)
|
||||||
|
{
|
||||||
|
_view = view;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends the dirty sprite at the given coordinates to the dirty item
|
* Appends the dirty sprite at the given coordinates to the dirty item
|
||||||
* list.
|
* list.
|
||||||
@@ -196,7 +207,7 @@ public class DirtyItemList
|
|||||||
* all of the information necessary to render their dirty regions
|
* all of the information necessary to render their dirty regions
|
||||||
* to the target graphics context when the time comes to do so.
|
* to the target graphics context when the time comes to do so.
|
||||||
*/
|
*/
|
||||||
public static class DirtyItem
|
public class DirtyItem
|
||||||
{
|
{
|
||||||
/** The dirtied object; one of either a sprite or an object tile. */
|
/** The dirtied object; one of either a sprite or an object tile. */
|
||||||
public Object obj;
|
public Object obj;
|
||||||
@@ -260,6 +271,36 @@ public class DirtyItemList
|
|||||||
} else {
|
} else {
|
||||||
((DisplayObjectInfo)obj).tile.paint(gfx, bounds.x, bounds.y);
|
((DisplayObjectInfo)obj).tile.paint(gfx, bounds.x, bounds.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// and paint the object's spot if it has one
|
||||||
|
if (footprint != null && obj instanceof DisplayObjectInfo) {
|
||||||
|
DisplayObjectInfo info = (DisplayObjectInfo)obj;
|
||||||
|
if (info.tile.hasSpot()) {
|
||||||
|
// get the spot's center coordinate
|
||||||
|
Point fpos = _view.getObjectSpot(info);
|
||||||
|
Point spos = _view.getScreenCoords(fpos.x, fpos.y);
|
||||||
|
|
||||||
|
// translate the origin to center on the portal
|
||||||
|
gfx.translate(spos.x, spos.y);
|
||||||
|
|
||||||
|
// rotate to reflect the spot orientation
|
||||||
|
double rot = (Math.PI / 4.0f) *
|
||||||
|
info.tile.getSpotOrient();
|
||||||
|
gfx.rotate(rot);
|
||||||
|
|
||||||
|
// draw the spot triangle
|
||||||
|
gfx.setColor(Color.green);
|
||||||
|
gfx.fill(_spotTri);
|
||||||
|
|
||||||
|
// outline the triangle in black
|
||||||
|
gfx.setColor(Color.black);
|
||||||
|
gfx.draw(_spotTri);
|
||||||
|
|
||||||
|
// restore the original transform
|
||||||
|
gfx.rotate(-rot);
|
||||||
|
gfx.translate(-spos.x, -spos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -571,6 +612,34 @@ public class DirtyItemList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The view for which we're managing dirty items. */
|
||||||
|
protected IsoSceneView _view;
|
||||||
|
|
||||||
|
/** The list of dirty items. */
|
||||||
|
protected SortableArrayList _items = new SortableArrayList();
|
||||||
|
|
||||||
|
/** The list of dirty items sorted by x-position. */
|
||||||
|
protected SortableArrayList _xitems = new SortableArrayList();
|
||||||
|
|
||||||
|
/** The list of dirty items sorted by y-position. */
|
||||||
|
protected SortableArrayList _yitems = new SortableArrayList();
|
||||||
|
|
||||||
|
/** The render comparator we'll use for our final, magical sort. */
|
||||||
|
protected Comparator _rcomp = new RenderComparator();
|
||||||
|
|
||||||
|
/** Unused dirty items. */
|
||||||
|
protected ArrayList _freelist = new ArrayList();
|
||||||
|
|
||||||
|
/** The triangle used to render an object's spot. */
|
||||||
|
protected static Polygon _spotTri;
|
||||||
|
|
||||||
|
static {
|
||||||
|
_spotTri = new Polygon();
|
||||||
|
_spotTri.addPoint(-3, -3);
|
||||||
|
_spotTri.addPoint(3, -3);
|
||||||
|
_spotTri.addPoint(0, 3);
|
||||||
|
};
|
||||||
|
|
||||||
/** Whether to log debug info when comparing pairs of dirty items. */
|
/** Whether to log debug info when comparing pairs of dirty items. */
|
||||||
protected static final boolean DEBUG_COMPARE = false;
|
protected static final boolean DEBUG_COMPARE = false;
|
||||||
|
|
||||||
@@ -590,19 +659,4 @@ public class DirtyItemList
|
|||||||
* y-coordinate order. */
|
* y-coordinate order. */
|
||||||
protected static final Comparator ORIGIN_Y_COMP =
|
protected static final Comparator ORIGIN_Y_COMP =
|
||||||
new OriginComparator(Y_AXIS);
|
new OriginComparator(Y_AXIS);
|
||||||
|
|
||||||
/** The list of dirty items. */
|
|
||||||
protected SortableArrayList _items = new SortableArrayList();
|
|
||||||
|
|
||||||
/** The list of dirty items sorted by x-position. */
|
|
||||||
protected SortableArrayList _xitems = new SortableArrayList();
|
|
||||||
|
|
||||||
/** The list of dirty items sorted by y-position. */
|
|
||||||
protected SortableArrayList _yitems = new SortableArrayList();
|
|
||||||
|
|
||||||
/** The render comparator we'll use for our final, magical sort. */
|
|
||||||
protected Comparator _rcomp = new RenderComparator();
|
|
||||||
|
|
||||||
/** Unused dirty items. */
|
|
||||||
protected ArrayList _freelist = new ArrayList();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.131 2003/01/31 23:10:45 mdb Exp $
|
// $Id: IsoSceneView.java,v 1.132 2003/02/12 05:46:05 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.client;
|
package com.threerings.miso.client;
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ import java.awt.AlphaComposite;
|
|||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
import java.awt.Composite;
|
||||||
|
import java.awt.EventQueue;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -110,8 +111,17 @@ public class IsoSceneView implements SceneView
|
|||||||
// for each of them that contain precomputed metrics
|
// for each of them that contain precomputed metrics
|
||||||
prepareObjectList();
|
prepareObjectList();
|
||||||
|
|
||||||
// invalidate the entire screen as there's a new scene in town
|
// invalidate the entire screen as there's a new scene in town;
|
||||||
invalidate();
|
// making sure we're on the AWT thread
|
||||||
|
if (EventQueue.isDispatchThread()) {
|
||||||
|
invalidate();
|
||||||
|
} else {
|
||||||
|
EventQueue.invokeLater(new Runnable() {
|
||||||
|
public void run () {
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,7 +139,7 @@ public class IsoSceneView implements SceneView
|
|||||||
// and fill in the new objects' bounds
|
// and fill in the new objects' bounds
|
||||||
int ocount = _objects.size();
|
int ocount = _objects.size();
|
||||||
for (int ii = 0; ii < ocount; ii++) {
|
for (int ii = 0; ii < ocount; ii++) {
|
||||||
DisplayObjectInfo scobj = _objects.get(ii);
|
DisplayObjectInfo scobj = (DisplayObjectInfo)_objects.get(ii);
|
||||||
if (scobj.bounds == null) {
|
if (scobj.bounds == null) {
|
||||||
scobj.bounds = IsoUtil.getObjectBounds(_model, scobj);
|
scobj.bounds = IsoUtil.getObjectBounds(_model, scobj);
|
||||||
}
|
}
|
||||||
@@ -150,6 +160,21 @@ public class IsoSceneView implements SceneView
|
|||||||
_remgr.invalidateRegion(_model.bounds);
|
_remgr.invalidateRegion(_model.bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the location associated with the specified object's "spot"
|
||||||
|
* in fine coordinates or null if the object has no spot.
|
||||||
|
*/
|
||||||
|
public Point getObjectSpot (DisplayObjectInfo info)
|
||||||
|
{
|
||||||
|
if (info.tile.hasSpot()) {
|
||||||
|
return IsoUtil.tilePlusFineToFull(
|
||||||
|
_model, info.x, info.y, info.tile.getSpotX(),
|
||||||
|
info.tile.getSpotY(), new Point());
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public void paint (Graphics2D gfx, Rectangle dirtyRect)
|
public void paint (Graphics2D gfx, Rectangle dirtyRect)
|
||||||
{
|
{
|
||||||
@@ -421,7 +446,7 @@ public class IsoSceneView implements SceneView
|
|||||||
// add any objects impacted by the dirty rectangle
|
// add any objects impacted by the dirty rectangle
|
||||||
int ocount = _objects.size();
|
int ocount = _objects.size();
|
||||||
for (int ii = 0; ii < ocount; ii++) {
|
for (int ii = 0; ii < ocount; ii++) {
|
||||||
DisplayObjectInfo scobj = _objects.get(ii);
|
DisplayObjectInfo scobj = (DisplayObjectInfo)_objects.get(ii);
|
||||||
if (!scobj.bounds.intersects(clip)) {
|
if (!scobj.bounds.intersects(clip)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -473,7 +498,7 @@ public class IsoSceneView implements SceneView
|
|||||||
// and fill in those objects' bounds
|
// and fill in those objects' bounds
|
||||||
int ocount = _objects.size();
|
int ocount = _objects.size();
|
||||||
for (int ii = 0; ii < ocount; ii++) {
|
for (int ii = 0; ii < ocount; ii++) {
|
||||||
DisplayObjectInfo scobj = _objects.get(ii);
|
DisplayObjectInfo scobj = (DisplayObjectInfo)_objects.get(ii);
|
||||||
scobj.bounds = IsoUtil.getObjectBounds(_model, scobj);
|
scobj.bounds = IsoUtil.getObjectBounds(_model, scobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -522,6 +547,12 @@ public class IsoSceneView implements SceneView
|
|||||||
return IsoUtil.screenToFull(_model, x, y, new Point());
|
return IsoUtil.screenToFull(_model, x, y, new Point());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public Point getTileCoords (int x, int y)
|
||||||
|
{
|
||||||
|
return IsoUtil.screenToTile(_model, x, y, new Point());
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public boolean mouseMoved (MouseEvent e)
|
public boolean mouseMoved (MouseEvent e)
|
||||||
{
|
{
|
||||||
@@ -703,7 +734,7 @@ public class IsoSceneView implements SceneView
|
|||||||
protected ObjectSet _objects = new ObjectSet();
|
protected ObjectSet _objects = new ObjectSet();
|
||||||
|
|
||||||
/** The dirty sprites and objects that need to be re-painted. */
|
/** The dirty sprites and objects that need to be re-painted. */
|
||||||
protected DirtyItemList _dirtyItems = new DirtyItemList();
|
protected DirtyItemList _dirtyItems = new DirtyItemList(this);
|
||||||
|
|
||||||
/** The working sprites list used when calculating dirty regions. */
|
/** The working sprites list used when calculating dirty regions. */
|
||||||
protected ArrayList _dirtySprites = new ArrayList();
|
protected ArrayList _dirtySprites = new ArrayList();
|
||||||
@@ -720,7 +751,7 @@ public class IsoSceneView implements SceneView
|
|||||||
|
|
||||||
/** The list that we use to track and sort the items over which the
|
/** The list that we use to track and sort the items over which the
|
||||||
* mouse is hovering. */
|
* mouse is hovering. */
|
||||||
protected DirtyItemList _hitList = new DirtyItemList();
|
protected DirtyItemList _hitList = new DirtyItemList(this);
|
||||||
|
|
||||||
/** The highlight mode. */
|
/** The highlight mode. */
|
||||||
protected int _hmode = HIGHLIGHT_NEVER;
|
protected int _hmode = HIGHLIGHT_NEVER;
|
||||||
|
|||||||
Reference in New Issue
Block a user