From f2c3211534393045a026e0d72a9006f63d3ee0a3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 17 Jan 2003 02:30:50 +0000 Subject: [PATCH] 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 --- src/java/com/threerings/media/tile/Tile.java | 10 +++++++++- src/java/com/threerings/media/tile/TileSet.java | 15 ++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/media/tile/Tile.java b/src/java/com/threerings/media/tile/Tile.java index 37b581c76..07e737963 100644 --- a/src/java/com/threerings/media/tile/Tile.java +++ b/src/java/com/threerings/media/tile/Tile.java @@ -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. diff --git a/src/java/com/threerings/media/tile/TileSet.java b/src/java/com/threerings/media/tile/TileSet.java index 01aaf22c5..583a4ff70 100644 --- a/src/java/com/threerings/media/tile/TileSet.java +++ b/src/java/com/threerings/media/tile/TileSet.java @@ -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); }