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,11 +1,10 @@
//
// $Id: BundledComponentRepository.java,v 1.2 2001/11/29 00:15:06 mdb Exp $
// $Id: BundledComponentRepository.java,v 1.3 2001/11/30 02:34:57 mdb Exp $
package com.threerings.cast.bundle;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.FileNotFoundException;
@@ -25,6 +24,8 @@ import org.apache.commons.collections.Predicate;
import com.threerings.resource.ResourceBundle;
import com.threerings.resource.ResourceManager;
import com.threerings.media.ImageManager;
import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.sprite.Sprite;
@@ -54,15 +55,21 @@ public class BundledComponentRepository
*
* @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 component data.
*
* @exception IOException thrown if an I/O error occurs while reading
* our metadata from the resource bundles.
*/
public BundledComponentRepository (ResourceManager rmgr, String name)
public BundledComponentRepository (
ResourceManager rmgr, ImageManager imgr, String name)
throws IOException
{
// keep this guy around
_imgr = imgr;
// first we obtain the resource set from whence will come our
// bundles
ResourceBundle[] rbundles = rmgr.getResourceSet(name);
@@ -199,7 +206,7 @@ public class BundledComponentRepository
"[bundle=" + _bundle + ", path=" + path + "].";
throw new FileNotFoundException(errmsg);
}
return ImageIO.read(imgin);
return _imgr.createImage(imgin);
}
// documentation inherited
@@ -289,6 +296,9 @@ public class BundledComponentRepository
protected int _orient;
}
/** We use the image manager to decode and cache images. */
protected ImageManager _imgr;
/** A table of action sequences. */
protected HashMap _actions;
@@ -1,17 +1,16 @@
//
// $Id: TileManager.java,v 1.21 2001/11/18 04:09:21 mdb Exp $
// $Id: TileManager.java,v 1.22 2001/11/30 02:34:57 mdb Exp $
package com.threerings.media.tile;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.HashIntMap;
import com.threerings.resource.ResourceManager;
import com.threerings.media.Log;
import com.threerings.media.ImageManager;
/**
* The tile manager provides a simplified interface for retrieving and
@@ -42,12 +41,15 @@ public class TileManager implements ImageProvider
{
/**
* Creates a tile manager and provides it with a reference to the
* resource manager from which it will load tileset image data.
* image manager from which it will load tileset images.
*
* @param imgr the image manager via which the tile manager will
* decode and cache images.
*/
public TileManager (ResourceManager rmgr)
public TileManager (ImageManager imgr)
{
// keep this guy around for later
_rmgr = rmgr;
_imgr = imgr;
}
/**
@@ -138,11 +140,11 @@ public class TileManager implements ImageProvider
throws IOException
{
// load up the image data from the resource manager
return ImageIO.read(_rmgr.getResource(path));
return _imgr.getImage(path);
}
/** The entity through which we load image data. */
protected ResourceManager _rmgr;
/** The entity through which we decode and cache images. */
protected ImageManager _imgr;
/** Cache of tilesets that have been requested thus far. */
protected HashIntMap _cache = new HashIntMap();
@@ -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();