Implemented a debugging view that shows when scene blocks are being

resolved; adjusted influential bounds based on new strategy for scrolling
around and resolving blocks.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2567 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-05-12 02:03:31 +00:00
parent 48a102de5a
commit 8ca388fb7e
3 changed files with 216 additions and 6 deletions
@@ -1,5 +1,5 @@
//
// $Id: MisoScenePanel.java,v 1.27 2003/05/09 01:12:06 mdb Exp $
// $Id: MisoScenePanel.java,v 1.28 2003/05/12 02:03:31 mdb Exp $
package com.threerings.miso.client;
@@ -26,6 +26,7 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.Icon;
import javax.swing.JFrame;
import java.util.ArrayList;
import java.util.HashMap;
@@ -96,7 +97,7 @@ public class MisoScenePanel extends VirtualMediaPanel
if (_resolver == null) {
_resolver = new SceneBlockResolver();
_resolver.setDaemon(true);
_resolver.setPriority(Thread.currentThread().getPriority()-2);
_resolver.setPriority(Thread.MIN_PRIORITY);
_resolver.start();
}
}
@@ -113,6 +114,9 @@ public class MisoScenePanel extends VirtualMediaPanel
_blocks.clear();
_vizobjs.clear();
_masks.clear();
if (_dpanel != null) {
_dpanel.newScene();
}
centerOnTile(0, 0);
if (isShowing()) {
@@ -268,6 +272,32 @@ public class MisoScenePanel extends VirtualMediaPanel
}
}
// documentation inherited
public void addNotify ()
{
super.addNotify();
if (_resolveDebug.getValue()) {
_dpanel = new ResolutionView(this);
_dframe = new JFrame("Scene block resolver");
_dframe.setContentPane(_dpanel);
_dframe.pack();
_dframe.show();
}
}
// documentation inherited
public void removeNotify ()
{
super.removeNotify();
if (_dpanel != null) {
_dframe.dispose();
_dpanel = null;
_dframe = null;
}
}
// documentation inherited from interface
public void mouseClicked (MouseEvent e)
{
@@ -481,6 +511,16 @@ public class MisoScenePanel extends VirtualMediaPanel
// documentation inherited
public boolean canTraverse (Object traverser, int tx, int ty)
{
// if the tile is not on-screen, no traversy
MisoUtil.tileToScreen(_metrics, tx, ty, _tcoords);
_trect.setLocation(_tcoords);
_trect.width = _metrics.tilewid;
_trect.height = _metrics.tilehei;
if (!_vbounds.intersects(_trect)) {
return false;
}
// if it is on screen, check the tile traversability
SceneBlock block = getBlock(tx, ty);
return (block == null) ? false : block.canTraverse(traverser, tx, ty);
}
@@ -625,6 +665,9 @@ public class MisoScenePanel extends VirtualMediaPanel
key.y = block.getBounds().y;
if (!_rethinkOp.blocks.contains(key)) {
Log.debug("Flushing block " + block + ".");
if (_dpanel != null) {
_dpanel.blockCleared(block);
}
iter.remove();
}
}
@@ -643,6 +686,9 @@ public class MisoScenePanel extends VirtualMediaPanel
// queue the block up to be resolved
_pendingBlocks++;
_resolver.resolveBlock(block);
if (_dpanel != null) {
_dpanel.queuedBlock(block);
}
}
}
_rethinkOp.blocks.clear();
@@ -666,8 +712,8 @@ public class MisoScenePanel extends VirtualMediaPanel
*/
protected void computeInfluentialBounds ()
{
int infborx = _vbounds.width/3;
int infbory = _vbounds.height/3;
int infborx = 3*_vbounds.width/4;
int infbory = _vbounds.height/2;
_ibounds.setBounds(_vbounds.x-infborx, _vbounds.y-infbory,
_vbounds.width+2*infborx,
// we go extra on the height because objects
@@ -675,12 +721,46 @@ public class MisoScenePanel extends VirtualMediaPanel
_vbounds.height+3*infbory);
}
/**
* Returns the bounds for which all intersecting scene blocks are kept
* resolved. Do not modify the rectangle returned by this method.
*/
protected Rectangle getInfluentialBounds ()
{
return _ibounds;
}
/**
* Called by the scene block when it has started its resolution.
*/
protected void blockResolving (SceneBlock block)
{
if (_dpanel != null) {
_dpanel.resolvingBlock(block);
}
}
/**
* Called by the scene block if it has come up for resolution but is
* no longer influential.
*/
protected void blockAbandoned (SceneBlock block)
{
if (_dpanel != null) {
_dpanel.blockCleared(block);
}
}
/**
* Called by a scene block when it has completed its resolution
* process.
*/
protected void blockResolved (SceneBlock block)
{
if (_dpanel != null) {
_dpanel.resolvedBlock(block);
}
Rectangle sbounds = block.getScreenBounds();
if (!_delayRepaint && sbounds != null && sbounds.intersects(_vbounds)) {
Log.warning("Block visible during resolution " + block + ".");
@@ -1395,9 +1475,12 @@ public class MisoScenePanel extends VirtualMediaPanel
/** Used to paint tiles. */
protected PaintTileOp _paintOp = new PaintTileOp();
/** Used when dirtying sprites. */
/** Temporary point used for intermediate calculations. */
protected Point _tcoords = new Point();
/** Temporary rectangle used for intermediate calculations. */
protected Rectangle _trect = new Rectangle();
/** Used to collect the list of sprites "hit" by a particular mouse
* location. */
protected List _hitSprites = new ArrayList();
@@ -1430,6 +1513,10 @@ public class MisoScenePanel extends VirtualMediaPanel
/** A scene block resolver shared by all scene panels. */
protected static SceneBlockResolver _resolver;
// used to display debugging information on scene block resolution
protected JFrame _dframe;
protected ResolutionView _dpanel;
/** A debug hook that toggles debug rendering of traversable tiles. */
protected static RuntimeAdjust.BooleanAdjust _traverseDebug =
new RuntimeAdjust.BooleanAdjust(
@@ -1450,6 +1537,12 @@ public class MisoScenePanel extends VirtualMediaPanel
"Toggles debug rendering of sprite paths in the iso scene view.",
"narya.miso.iso_paths_debug_render", MisoPrefs.config, false);
/** A debug hook that toggles the block resolution display. */
protected static RuntimeAdjust.BooleanAdjust _resolveDebug =
new RuntimeAdjust.BooleanAdjust(
"Enables a view displaying the status of scene block resolution.",
"narya.miso.iso_paths_debug_resolve", MisoPrefs.config, false);
/** The stroke used to draw dirty rectangles. */
protected static final Stroke DIRTY_RECT_STROKE = new BasicStroke(2);
@@ -0,0 +1,115 @@
//
// $Id: ResolutionView.java,v 1.1 2003/05/12 02:03:31 mdb Exp $
package com.threerings.miso.client;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import javax.swing.JPanel;
import java.util.HashMap;
import java.util.Iterator;
import com.samskivert.util.IntTuple;
import com.threerings.media.util.MathUtil;
import com.threerings.miso.util.MisoSceneMetrics;
import com.threerings.miso.util.MisoUtil;
/**
* Used to debug scene block resolution visually.
*/
public class ResolutionView extends JPanel
{
public ResolutionView (MisoScenePanel panel)
{
_panel = panel;
_metrics = panel.getSceneMetrics();
}
public Dimension getPreferredSize ()
{
return new Dimension(TILE_SIZE*MAX_WIDTH, TILE_SIZE*MAX_HEIGHT);
}
public synchronized void queuedBlock (SceneBlock block)
{
_blocks.put(blockKey(block), Color.yellow);
repaint();
}
public synchronized void resolvingBlock (SceneBlock block)
{
IntTuple key = blockKey(block);
if (_blocks.containsKey(key)) {
_blocks.put(key, Color.red);
repaint();
}
}
public synchronized void resolvedBlock (SceneBlock block)
{
IntTuple key = blockKey(block);
if (_blocks.containsKey(key)) {
_blocks.put(key, Color.green);
repaint();
}
}
public synchronized void blockCleared (SceneBlock block)
{
_blocks.remove(blockKey(block));
repaint();
}
public synchronized void newScene ()
{
_blocks.clear();
repaint();
}
public synchronized void paintComponent (Graphics g)
{
super.paintComponent(g);
Graphics2D gfx = (Graphics2D)g;
AffineTransform xform = gfx.getTransform();
gfx.translate(getWidth()/2, getHeight()/2);
gfx.scale(0.25, 0.25);
for (Iterator iter = _blocks.keySet().iterator(); iter.hasNext(); ) {
IntTuple key = (IntTuple)iter.next();
Color color = (Color)_blocks.get(key);
Polygon poly = MisoUtil.getTilePolygon(
_metrics, key.left, key.right);
gfx.setColor(color);
gfx.fill(poly);
gfx.setColor(Color.black);
gfx.draw(poly);
}
gfx.scale(0.25, 0.25);
gfx.draw(_panel.getViewBounds());
gfx.setColor(Color.red);
gfx.draw(_panel.getInfluentialBounds());
gfx.setTransform(xform);
}
protected final IntTuple blockKey (SceneBlock block)
{
Rectangle bounds = block.getBounds();
return new IntTuple(MathUtil.floorDiv(bounds.x, bounds.width),
MathUtil.floorDiv(bounds.y, bounds.height));
}
protected MisoScenePanel _panel;
protected MisoSceneMetrics _metrics;
protected HashMap _blocks = new HashMap();
protected static final int TILE_SIZE = 10;
protected static final int MAX_WIDTH = 30;
protected static final int MAX_HEIGHT = 30;
}
@@ -1,5 +1,5 @@
//
// $Id: SceneBlock.java,v 1.14 2003/04/28 20:41:13 mdb Exp $
// $Id: SceneBlock.java,v 1.15 2003/05/12 02:03:31 mdb Exp $
package com.threerings.miso.client;
@@ -62,8 +62,10 @@ public class SceneBlock
// if we got canned before we were resolved, go ahead and bail now
if (_panel.getBlock(_bounds.x, _bounds.y) != this) {
// Log.info("Not resolving abandoned block " + this + ".");
_panel.blockAbandoned(this);
return false;
}
_panel.blockResolving(this);
// start with the bounds of the footprint polygon
Rectangle sbounds = new Rectangle(_footprint.getBounds());