A few substantial changes:
- Tiles are initialized after being constructed which makes life simpler for custom tiles which no longer have to have their own constructor that passes Tile's stuff down to it. - Tiles are no longer LRU cached (because we blow through that cache instantly on all but the smallest of scenes), and are now tracked by weak references so that we guarantee that only one instance of a tile is ever in memory. - Added code to track and report memory usage of weak cached tiles as well as "stray" tiles which are created through other means than asking a TileSet for a tile (fringe tiles being the most prolific example). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2628 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MisoScenePanel.java,v 1.40 2003/05/29 01:04:58 ray Exp $
|
||||
// $Id: MisoScenePanel.java,v 1.41 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.client;
|
||||
|
||||
@@ -280,6 +280,27 @@ public class MisoScenePanel extends VirtualMediaPanel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the memory usage of the resolved tiles in the current scene
|
||||
* block.
|
||||
*/
|
||||
public void reportMemoryUsage ()
|
||||
{
|
||||
HashMap base = new HashMap();
|
||||
HashSet fringe = new HashSet();
|
||||
HashMap object = new HashMap();
|
||||
long[] usage = new long[3];
|
||||
for (Iterator iter = _blocks.values().iterator(); iter.hasNext(); ) {
|
||||
SceneBlock block = (SceneBlock)iter.next();
|
||||
block.computeMemoryUsage(base, fringe, object, usage);
|
||||
}
|
||||
Log.info("Scene tile memory usage [base=" + base.size() +
|
||||
"->" + (usage[0] / 1024) + "k" +
|
||||
", fringe=" + fringe.size() + "->" + (usage[1] / 1024) + "k" +
|
||||
", fmasks=" + _masks.size() + ", obj=" + object.size() +
|
||||
"->" + (usage[2] / 1024) + "k" + "].");
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void addNotify ()
|
||||
{
|
||||
@@ -803,6 +824,7 @@ public class MisoScenePanel extends VirtualMediaPanel
|
||||
if (_pendingBlocks == 0) {
|
||||
Log.info("Finished resolving pending blocks " +
|
||||
"[view=" + StringUtil.toString(_vbounds) + "].");
|
||||
reportMemoryUsage();
|
||||
}
|
||||
|
||||
// once all the visible pending blocks have completed their
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
//
|
||||
// $Id: SceneBlock.java,v 1.18 2003/05/29 01:59:17 ray Exp $
|
||||
// $Id: SceneBlock.java,v 1.19 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.client;
|
||||
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
@@ -14,6 +16,7 @@ import com.samskivert.util.StringUtil;
|
||||
import com.threerings.geom.GeomUtil;
|
||||
import com.threerings.media.tile.NoSuchTileException;
|
||||
import com.threerings.media.tile.NoSuchTileSetException;
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
@@ -335,6 +338,64 @@ public class SceneBlock
|
||||
return !_covered[index(tx, ty)] && (base != null && base.isPassable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the memory usage of the base and object tiles in this
|
||||
* scene block; registering counted tiles in the hash map so that
|
||||
* other blocks can be sure not to double count them. Base tile usage
|
||||
* is placed into the zeroth array element, fringe tile usage into the
|
||||
* first and object tile usage into the second.
|
||||
*/
|
||||
public void computeMemoryUsage (
|
||||
HashMap bases, HashSet fringes, HashMap objects, long[] usage)
|
||||
{
|
||||
// account for our base tiles
|
||||
MisoSceneModel model = _panel.getSceneModel();
|
||||
for (int yy = 0; yy < _bounds.height; yy++) {
|
||||
for (int xx = 0; xx < _bounds.width; xx++) {
|
||||
int x = _bounds.x + xx, y = _bounds.y + yy;
|
||||
int tidx = index(x, y);
|
||||
BaseTile base = _base[tidx];
|
||||
if (base == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BaseTile sbase = (BaseTile)bases.get(base.key);
|
||||
if (sbase == null) {
|
||||
bases.put(base.key, base);
|
||||
usage[0] += base.getEstimatedMemoryUsage();
|
||||
} else if (base != _base[tidx]) {
|
||||
Log.warning("Multiple instances of same base tile " +
|
||||
"[base=" + base +
|
||||
", x=" + xx + ", y=" + yy + "].");
|
||||
usage[0] += base.getEstimatedMemoryUsage();
|
||||
}
|
||||
|
||||
// now account for the fringe
|
||||
if (_fringe[tidx] == null) {
|
||||
continue;
|
||||
} else if (!fringes.contains(_fringe[tidx])) {
|
||||
fringes.add(_fringe[tidx]);
|
||||
usage[1] += _fringe[tidx].getEstimatedMemoryUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now get the object tiles
|
||||
int ocount = (_objects == null) ? 0 : _objects.length;
|
||||
for (int ii = 0; ii < ocount; ii++) {
|
||||
SceneObject scobj = _objects[ii];
|
||||
ObjectTile tile = (ObjectTile)objects.get(scobj.tile.key);
|
||||
if (tile == null) {
|
||||
objects.put(scobj.tile.key, scobj.tile);
|
||||
usage[2] += scobj.tile.getEstimatedMemoryUsage();
|
||||
} else if (tile != scobj.tile) {
|
||||
Log.warning("Multiple instances of same object tile: " +
|
||||
scobj.info + ".");
|
||||
usage[2] += scobj.tile.getEstimatedMemoryUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this instance.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneBlockResolver.java,v 1.8 2003/05/23 19:35:11 mdb Exp $
|
||||
// $Id: SceneBlockResolver.java,v 1.9 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.client;
|
||||
|
||||
@@ -93,10 +93,10 @@ public class SceneBlockResolver extends LoopingThread
|
||||
// let the block's panel know that it is resolved
|
||||
block.wasResolved();
|
||||
// report statistics
|
||||
if (report) {
|
||||
Log.info("Resolution histogram " +
|
||||
_histo.summarize() + ".");
|
||||
}
|
||||
// if (report) {
|
||||
// Log.info("Resolution histogram " +
|
||||
// _histo.summarize() + ".");
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: AutoFringer.java,v 1.24 2003/05/29 01:58:06 ray Exp $
|
||||
// $Id: AutoFringer.java,v 1.25 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -140,7 +140,9 @@ public class AutoFringer
|
||||
}
|
||||
}
|
||||
|
||||
return new Tile(new BufferedMirage(ftimg));
|
||||
Tile tile = new Tile();
|
||||
tile.setImage(new BufferedMirage(ftimg));
|
||||
return tile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
//
|
||||
// $Id: BaseTile.java,v 1.7 2003/01/13 22:55:12 mdb Exp $
|
||||
// $Id: BaseTile.java,v 1.8 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.image.Mirage;
|
||||
import com.threerings.media.tile.Tile;
|
||||
|
||||
/**
|
||||
@@ -13,24 +12,6 @@ import com.threerings.media.tile.Tile;
|
||||
*/
|
||||
public class BaseTile extends Tile
|
||||
{
|
||||
/**
|
||||
* Constructs a new base tile with the specified image. Passability
|
||||
* will be assumed to be true.
|
||||
*/
|
||||
public BaseTile (Mirage image)
|
||||
{
|
||||
this(image, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new base tile with the specified passability.
|
||||
*/
|
||||
public BaseTile (Mirage image, boolean passable)
|
||||
{
|
||||
super(image);
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this tile can be walked upon by character
|
||||
* sprites.
|
||||
@@ -40,6 +21,14 @@ public class BaseTile extends Tile
|
||||
return _passable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures this base tile as passable or impassable.
|
||||
*/
|
||||
public void setPassable (boolean passable)
|
||||
{
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
/** Whether the tile is passable. */
|
||||
protected boolean _passable = true;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//
|
||||
// $Id: BaseTileSet.java,v 1.12 2003/01/15 09:11:37 mdb Exp $
|
||||
// $Id: BaseTileSet.java,v 1.13 2003/05/31 00:56:38 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.image.Mirage;
|
||||
import com.threerings.media.image.Colorization;
|
||||
import com.threerings.media.tile.SwissArmyTileSet;
|
||||
import com.threerings.media.tile.Tile;
|
||||
|
||||
@@ -35,9 +35,16 @@ public class BaseTileSet extends SwissArmyTileSet
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Tile createTile (int tileIndex, Mirage tileImage)
|
||||
protected Tile createTile ()
|
||||
{
|
||||
return new BaseTile(tileImage, _passable[tileIndex]);
|
||||
return new BaseTile();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void initTile (Tile tile, int tileIndex, Colorization[] zations)
|
||||
{
|
||||
super.initTile(tile, tileIndex, zations);
|
||||
((BaseTile)tile).setPassable(_passable[tileIndex]);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// $Id: FringeTile.java,v 1.4 2003/01/13 22:55:12 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.image.Mirage;
|
||||
|
||||
/**
|
||||
* A fringe tile may be composed of multiple images.
|
||||
*/
|
||||
public class FringeTile extends Tile
|
||||
{
|
||||
/**
|
||||
* Construct a fringe tile with the specified image.
|
||||
*/
|
||||
public FringeTile (Mirage mirage)
|
||||
{
|
||||
super(mirage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add another image to this fringe tile.
|
||||
*/
|
||||
public void addExtraImage (Mirage mirage)
|
||||
{
|
||||
if (_extras == null) {
|
||||
_extras = new ArrayList();
|
||||
}
|
||||
_extras.add(mirage);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void paint (Graphics2D gfx, int x, int y)
|
||||
{
|
||||
// paint our main image
|
||||
super.paint(gfx, x, y);
|
||||
|
||||
if (_extras != null) {
|
||||
int size = _extras.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Mirage image = (Mirage)_extras.get(ii);
|
||||
image.paint(gfx, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Extra fringe images beyond the one stored in our superclass. */
|
||||
protected ArrayList _extras = null;
|
||||
}
|
||||
Reference in New Issue
Block a user