Added support for obtaining estimated memory usage of a tile; modified
tile cache to be based on memory usage rather than tile count. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2175 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Tile.java,v 1.26 2003/01/13 22:49:46 mdb Exp $
|
||||
// $Id: Tile.java,v 1.27 2003/01/17 02:30:50 mdb Exp $
|
||||
|
||||
package com.threerings.media.tile;
|
||||
|
||||
@@ -39,6 +39,14 @@ public class Tile implements Cloneable
|
||||
return _mirage.getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated memory usage of our underlying tile image.
|
||||
*/
|
||||
public long getEstimatedMemoryUsage ()
|
||||
{
|
||||
return _mirage.getEstimatedMemoryUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the tile image at the specified position in the given
|
||||
* graphics context.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileSet.java,v 1.39 2003/01/15 02:36:18 mdb Exp $
|
||||
// $Id: TileSet.java,v 1.40 2003/01/17 02:30:50 mdb Exp $
|
||||
|
||||
package com.threerings.media.tile;
|
||||
|
||||
@@ -142,8 +142,12 @@ public abstract class TileSet
|
||||
// create our tile cache if necessary
|
||||
if (_tiles == null) {
|
||||
int tcsize = _cacheSize.getValue();
|
||||
Log.debug("Creating tile cache [size=" + tcsize + "].");
|
||||
_tiles = new LRUHashMap(tcsize);
|
||||
Log.debug("Creating tile cache [size=" + tcsize + "k].");
|
||||
_tiles = new LRUHashMap(tcsize*1024, new LRUHashMap.ItemSizer() {
|
||||
public int computeSize (Object value) {
|
||||
return (int)((Tile)value).getEstimatedMemoryUsage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// fetch and cache the tile
|
||||
@@ -305,6 +309,7 @@ public abstract class TileSet
|
||||
* framework. */
|
||||
protected static RuntimeAdjust.IntAdjust _cacheSize =
|
||||
new RuntimeAdjust.IntAdjust(
|
||||
"Size (in tiles) of the tile LRU cache [requires reboot]",
|
||||
"narya.media.tile.cache_size", MediaPrefs.config, 500);
|
||||
"Size (in kb of memory used) of the tile LRU cache " +
|
||||
"[requires restart]", "narya.media.tile.cache_size",
|
||||
MediaPrefs.config, 1024);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user