Let the tile data pack cache images so we aren't reloading them for various individual tiles within the image. Also, a couple minor efficiency improvements elsewhere.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@949 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2010-07-13 22:40:07 +00:00
parent faa16baed2
commit 6987d008e2
4 changed files with 19 additions and 4 deletions
@@ -36,7 +36,10 @@ import nochump.util.zip.ZipFile;
import com.threerings.media.image.PngRecolorUtil;
import com.threerings.util.DataPack;
import com.threerings.util.Map;
import com.threerings.util.Maps;
import com.threerings.util.MultiLoader;
import com.threerings.util.StringUtil;
/**
* Like a normal data pack, but we don't deal with any data, and all our filenames are a direct
@@ -86,7 +89,17 @@ public class TileDataPack extends DataPack
public function getTileSetImage (path :String, zations :Array, callback :Function) :void
{
MultiLoader.getContents(PngRecolorUtil.recolorPNG(getFile(path), zations), callback);
var key :String = zations == null ? path : path + ":" + StringUtil.toString(zations);
if (_cache.containsKey(key)) {
callback(_cache.get(key));
} else {
MultiLoader.getContents(PngRecolorUtil.recolorPNG(getFile(path), zations),
function(result :Bitmap) :void {
_cache.put(key, result);
callback(result);
});
}
}
public function getTileImage (path :String, bounds :Rectangle, zations :Array,
@@ -99,5 +112,8 @@ public class TileDataPack extends DataPack
callback(new Bitmap(data));
});
}
/** Cache of images loaded from this data pack. */
protected var _cache :Map = Maps.newMapOf(String);
}
}
+1 -1
View File
@@ -166,7 +166,7 @@ public /* abstract */ class TileSet
// if it's not in the active set, it's not in memory; so load it
if (tile == null) {
tile = createTile();
tile.key = new Tile_Key(this, tileIndex, zations);
tile.key = key;
initTile(tile, tileIndex, zations);
_atiles.put(tile.key, tile);
}
@@ -272,8 +272,6 @@ public class MisoScenePanel extends Sprite
_objScene.layoutRenderer = new ClassFactory(PrioritizedSceneLayoutRenderer);
refreshBaseBlockScenes();
_isoView.addScene(_objScene);
}
/**
@@ -73,6 +73,7 @@ public class SceneBlock
var y :int = getBlockY(_key);
_baseScene = new IsoScene();
_baseScene.layoutEnabled = false;
for (var ii :int = x; ii < x + BLOCK_SIZE; ii++) {
for (var jj :int = y; jj < y + BLOCK_SIZE; jj++) {
var tileId :int = model.getBaseTileId(ii, jj);