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() + ".");
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user