Obtain our images through the image manager. We may be back later to have

the image manager cache them as well.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@718 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-11-30 02:34:58 +00:00
parent 783e3d9799
commit 9a02d456e5
6 changed files with 61 additions and 27 deletions
@@ -1,5 +1,5 @@
//
// $Id: BundleUtil.java,v 1.1 2001/11/29 21:57:31 mdb Exp $
// $Id: BundleUtil.java,v 1.2 2001/11/30 02:34:57 mdb Exp $
package com.threerings.media.tile.bundle;
@@ -20,8 +20,8 @@ public class BundleUtil
public static final String METADATA_PATH = "tsbundles.dat";
/**
* Extracts and initializes a serialized tileset bundle instance from
* the supplied resource bundle.
* Extracts, but does not initialize, a serialized tileset bundle
* instance from the supplied resource bundle.
*/
public static TileSetBundle extractBundle (ResourceBundle bundle)
throws IOException, ClassNotFoundException
@@ -31,8 +31,6 @@ public class BundleUtil
ObjectInputStream oin = new ObjectInputStream(
new BufferedInputStream(tbin));
TileSetBundle tsb = (TileSetBundle)oin.readObject();
// initialize the bundle and add it to the list
tsb.init(bundle);
return tsb;
}
}
@@ -1,5 +1,5 @@
//
// $Id: BundledTileSetRepository.java,v 1.4 2001/11/29 21:57:31 mdb Exp $
// $Id: BundledTileSetRepository.java,v 1.5 2001/11/30 02:34:57 mdb Exp $
package com.threerings.media.tile.bundle;
@@ -16,6 +16,7 @@ import com.threerings.resource.ResourceBundle;
import com.threerings.resource.ResourceManager;
import com.threerings.media.Log;
import com.threerings.media.ImageManager;
import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileSetRepository;
@@ -34,10 +35,13 @@ public class BundledTileSetRepository
*
* @param rmgr the resource manager from which to obtain our resource
* set.
* @param imgr the image manager that we'll use to decode and cache
* images.
* @param name the name of the resource set from which we will be
* loading our tile data.
*/
public BundledTileSetRepository (ResourceManager rmgr, String name)
public BundledTileSetRepository (
ResourceManager rmgr, ImageManager imgr, String name)
{
// first we obtain the resource set from which we will load up our
// tileset bundles
@@ -57,7 +61,12 @@ public class BundledTileSetRepository
ArrayList tbundles = new ArrayList();;
for (int i = 0; i < rbundles.length; i++) {
try {
tbundles.add(BundleUtil.extractBundle(rbundles[i]));
// unserialize our tileset bundle
TileSetBundle tsb = BundleUtil.extractBundle(rbundles[i]);
// initialize it and add it to the list
tsb.init(rbundles[i], imgr);
tbundles.add(tsb);
} catch (Exception e) {
Log.warning("Unable to load tileset bundle from resource " +
"bundle [rbundle=" + rbundles[i] +
@@ -1,10 +1,9 @@
//
// $Id: TileSetBundle.java,v 1.3 2001/11/29 00:13:42 mdb Exp $
// $Id: TileSetBundle.java,v 1.4 2001/11/30 02:34:57 mdb Exp $
package com.threerings.media.tile.bundle;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -18,6 +17,7 @@ import java.util.Iterator;
import com.samskivert.util.HashIntMap;
import com.threerings.resource.ResourceBundle;
import com.threerings.media.ImageManager;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.ImageProvider;
@@ -31,11 +31,13 @@ public class TileSetBundle
{
/**
* Initializes this resource bundle with a reference to the jarfile
* from which it was loaded and from which it can load image data.
* from which it was loaded and from which it can load image data. The
* image manager will be used to decode the images.
*/
public void init (ResourceBundle bundle)
public void init (ResourceBundle bundle, ImageManager imgr)
{
_bundle = bundle;
_imgr = imgr;
}
/**
@@ -81,7 +83,7 @@ public class TileSetBundle
"[bundle=" + _bundle + ", path=" + path + "].";
throw new FileNotFoundException(errmsg);
}
return ImageIO.read(imgin);
return _imgr.createImage(imgin);
}
// custom serialization process
@@ -114,4 +116,7 @@ public class TileSetBundle
/** That from which we load our tile images. */
protected ResourceBundle _bundle;
/** We use the image manager to decode our images. */
protected ImageManager _imgr;
}
@@ -1,13 +1,16 @@
//
// $Id: DumpBundle.java,v 1.2 2001/11/29 23:07:38 mdb Exp $
// $Id: DumpBundle.java,v 1.3 2001/11/30 02:34:58 mdb Exp $
package com.threerings.media.tools.tile.bundle;
import java.io.File;
import java.util.Iterator;
import com.threerings.resource.ResourceManager;
import com.threerings.resource.ResourceBundle;
import com.threerings.media.ImageManager;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.bundle.BundleUtil;
import com.threerings.media.tile.bundle.TileSetBundle;
@@ -28,6 +31,11 @@ public class DumpBundle
System.exit(-1);
}
// create a resource and image manager in case they want to dump
// the tiles
ResourceManager rmgr = new ResourceManager(null, "rsrc");
ImageManager imgr = new ImageManager(rmgr);
for (int i = 0; i < args.length; i++) {
// oh the hackery
if (args[i].equals("-tiles")) {
@@ -39,6 +47,8 @@ public class DumpBundle
try {
ResourceBundle bundle = new ResourceBundle(file);
TileSetBundle tsb = BundleUtil.extractBundle(bundle);
tsb.init(bundle, imgr);
Iterator tsids = tsb.enumerateTileSetIds();
while (tsids.hasNext()) {
Integer tsid = (Integer)tsids.next();