Changed the tileset cache to use soft references. We want the cache

because we'd like to use the same TileSet over again when possible, but
we don't want to forevermore hold onto a TileSet if it could be gc'd.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3392 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2005-03-10 01:30:34 +00:00
parent 51e8ef3687
commit fea80fdb2b
@@ -1,5 +1,5 @@
//
// $Id: TileManager.java,v 1.37 2004/10/28 17:49:02 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,6 +21,8 @@
package com.threerings.media.tile;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import com.samskivert.io.PersistenceException;
@@ -107,14 +109,16 @@ public class TileManager
String bundle, String imgPath, int width, int height)
{
String key = bundle + "::" + imgPath;
UniformTileSet uts = (UniformTileSet)_handcache.get(key);
SoftReference ref = (SoftReference) _handcache.get(key);
UniformTileSet uts = (ref == null) ? null
: (UniformTileSet) ref.get();
if (uts == null) {
uts = new UniformTileSet();
uts.setImageProvider(_defaultProvider);
uts.setImagePath(imgPath);
uts.setWidth(width);
uts.setHeight(height);
_handcache.put(key, uts);
_handcache.put(key, new SoftReference(uts));
}
return uts;
}