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:
@@ -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
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
|
import java.lang.ref.SoftReference;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.samskivert.io.PersistenceException;
|
import com.samskivert.io.PersistenceException;
|
||||||
@@ -107,14 +109,16 @@ public class TileManager
|
|||||||
String bundle, String imgPath, int width, int height)
|
String bundle, String imgPath, int width, int height)
|
||||||
{
|
{
|
||||||
String key = bundle + "::" + imgPath;
|
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) {
|
if (uts == null) {
|
||||||
uts = new UniformTileSet();
|
uts = new UniformTileSet();
|
||||||
uts.setImageProvider(_defaultProvider);
|
uts.setImageProvider(_defaultProvider);
|
||||||
uts.setImagePath(imgPath);
|
uts.setImagePath(imgPath);
|
||||||
uts.setWidth(width);
|
uts.setWidth(width);
|
||||||
uts.setHeight(height);
|
uts.setHeight(height);
|
||||||
_handcache.put(key, uts);
|
_handcache.put(key, new SoftReference(uts));
|
||||||
}
|
}
|
||||||
return uts;
|
return uts;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user