Store images in our mask cache, use the new FringeTile object and

ImageUtil.composeMaskedImage() to create the masked fringe images.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1204 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2002-04-06 03:43:24 +00:00
parent 3474c9c199
commit 91b7065486
@@ -1,18 +1,17 @@
// //
// $Id: AutoFringer.java,v 1.2 2002/04/06 02:07:13 ray Exp $ // $Id: AutoFringer.java,v 1.3 2002/04/06 03:43:24 ray Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.Random; import java.util.Random;
import java.util.HashMap;
import com.samskivert.util.HashIntMap;
import com.threerings.media.Log; import com.threerings.media.Log;
import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.MaskedUniformTileSet;
import com.threerings.media.tile.Tile; import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileLayer; import com.threerings.media.tile.TileLayer;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
@@ -20,6 +19,8 @@ import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileUtil; import com.threerings.media.tile.TileUtil;
import com.threerings.media.tile.UniformTileSet; import com.threerings.media.tile.UniformTileSet;
import com.threerings.media.util.ImageUtil;
import com.threerings.miso.scene.MisoSceneModel; import com.threerings.miso.scene.MisoSceneModel;
/** /**
@@ -55,7 +56,7 @@ public class AutoFringer
// int startx, int starty, int width, int height) // int startx, int starty, int width, int height)
{ {
// create a hash to cache our masks // create a hash to cache our masks
HashIntMap maskcache = new HashIntMap(); HashMap maskcache = new HashMap();
int lastrow = Math.min(r.y + r.height + 1, scene.height); int lastrow = Math.min(r.y + r.height + 1, scene.height);
int lastcol = Math.min(r.x + r.width + 1, scene.width); int lastcol = Math.min(r.x + r.width + 1, scene.width);
@@ -77,7 +78,7 @@ public class AutoFringer
* (0 for no fringe) * (0 for no fringe)
*/ */
protected Tile getFringeTile (MisoSceneModel scene, int row, int col, protected Tile getFringeTile (MisoSceneModel scene, int row, int col,
HashIntMap masks) HashMap masks)
{ {
int hei = scene.height; int hei = scene.height;
int wid = scene.width; int wid = scene.width;
@@ -150,7 +151,7 @@ public class AutoFringer
} }
} }
protected Tile getTile (int baseset, int index, HashIntMap masks) protected Tile getTile (int baseset, int index, HashMap masks)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
FringeConfiguration.FringeTileSetRecord tsr = FringeConfiguration.FringeTileSetRecord tsr =
@@ -164,17 +165,20 @@ public class AutoFringer
} }
// otherwise, it's a mask.. look for it in the cache.. // otherwise, it's a mask.. look for it in the cache..
int maskkey = (baseset << 16) + fringeset; Long maskkey = new Long(
(((long) baseset) << 32) + (fringeset << 16) + index);
TileSet tset = (TileSet) masks.get(maskkey); Tile t = (Tile) masks.get(maskkey);
if (tset == null) { if (t == null) {
tset = new MaskedUniformTileSet(_tmgr.getTile(baseset, 0), t = new FringeTile(ImageUtil.composeMaskedImage(
_tmgr.getTileSet(fringeset)); (BufferedImage) _tmgr.getTile(fringeset, index).getImage(),
masks.put(maskkey, tset); (BufferedImage) _tmgr.getTile(baseset, 0).getImage()));
Log.debug("created cached set");
masks.put(maskkey, t);
Log.debug("created cached fringe image");
} }
return tset.getTile(index); return t;
} }
// fringe bits // fringe bits