The AutoFringer picks which fringe tile to use next by querying a

Random, instead it relies on a duplicatable hashing method.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2621 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2003-05-29 01:04:58 +00:00
parent 5f8309f118
commit bace19ea71
3 changed files with 22 additions and 16 deletions
@@ -1,5 +1,5 @@
// //
// $Id: MisoScenePanel.java,v 1.39 2003/05/28 18:15:26 ray Exp $ // $Id: MisoScenePanel.java,v 1.40 2003/05/29 01:04:58 ray Exp $
package com.threerings.miso.client; package com.threerings.miso.client;
@@ -33,7 +33,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random;
import com.samskivert.swing.Controller; import com.samskivert.swing.Controller;
import com.samskivert.swing.RadialMenu; import com.samskivert.swing.RadialMenu;
@@ -1335,7 +1334,7 @@ public class MisoScenePanel extends VirtualMediaPanel
protected Tile computeFringeTile (int tx, int ty) protected Tile computeFringeTile (int tx, int ty)
{ {
return _ctx.getTileManager().getAutoFringer().getFringeTile( return _ctx.getTileManager().getAutoFringer().getFringeTile(
_model, tx, ty, _masks, _rando); _model, tx, ty, _masks);
} }
/** /**
@@ -1512,9 +1511,6 @@ public class MisoScenePanel extends VirtualMediaPanel
/** For computing fringe tiles. */ /** For computing fringe tiles. */
protected HashMap _masks = new HashMap(); protected HashMap _masks = new HashMap();
/** For computing fringe tiles. */
protected Random _rando = new Random();
/** The dirty sprites and objects that need to be re-painted. */ /** The dirty sprites and objects that need to be re-painted. */
protected DirtyItemList _dirtyItems = new DirtyItemList(); protected DirtyItemList _dirtyItems = new DirtyItemList();
@@ -1,5 +1,5 @@
// //
// $Id: AutoFringer.java,v 1.22 2003/05/02 23:33:30 mdb Exp $ // $Id: AutoFringer.java,v 1.23 2003/05/29 01:04:58 ray Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
@@ -57,7 +57,7 @@ public class AutoFringer
* location. * location.
*/ */
public Tile getFringeTile (MisoSceneModel scene, int col, int row, public Tile getFringeTile (MisoSceneModel scene, int col, int row,
HashMap masks, Random rando) HashMap masks)
{ {
// get the tileset id of the base tile we are considering // get the tileset id of the base tile we are considering
int underset = scene.getBaseTileId(col, row) >> 16; int underset = scene.getBaseTileId(col, row) >> 16;
@@ -110,14 +110,23 @@ public class AutoFringer
} }
} }
return composeFringeTile(frecs, masks, rando); return composeFringeTile(frecs, masks, generateHashValue(col, row));
}
/**
* Create a hash value for picking which fringe to use for a particular
* tile.
*/
protected int generateHashValue (int col, int row)
{
return col ^ row;
} }
/** /**
* Compose a FringeTile out of the various fringe images needed. * Compose a FringeTile out of the various fringe images needed.
*/ */
protected Tile composeFringeTile ( protected Tile composeFringeTile (
FringerRec[] fringers, HashMap masks, Random rando) FringerRec[] fringers, HashMap masks, int hashValue)
{ {
// sort the array so that higher priority fringers get drawn first // sort the array so that higher priority fringers get drawn first
QuickSort.sort(fringers); QuickSort.sort(fringers);
@@ -128,7 +137,7 @@ public class AutoFringer
for (int jj = 0; jj < indexes.length; jj++) { for (int jj = 0; jj < indexes.length; jj++) {
try { try {
ftimg = getTileImage(ftimg, fringers[ii].baseset, ftimg = getTileImage(ftimg, fringers[ii].baseset,
indexes[jj], masks, rando); indexes[jj], masks, hashValue);
} catch (NoSuchTileException nste) { } catch (NoSuchTileException nste) {
Log.warning("Autofringer couldn't find a needed tile " + Log.warning("Autofringer couldn't find a needed tile " +
"[error=" + nste + "]."); "[error=" + nste + "].");
@@ -147,11 +156,11 @@ public class AutoFringer
*/ */
protected BufferedImage getTileImage ( protected BufferedImage getTileImage (
BufferedImage ftimg, int baseset, int index, BufferedImage ftimg, int baseset, int index,
HashMap masks, Random rando) HashMap masks, int hashValue)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
FringeConfiguration.FringeTileSetRecord tsr = FringeConfiguration.FringeTileSetRecord tsr =
_fringeconf.getRandomFringe(baseset, rando); _fringeconf.getFringe(baseset, hashValue);
int fringeset = tsr.fringe_tsid; int fringeset = tsr.fringe_tsid;
TileSet fset = _tmgr.getTileSet(fringeset); TileSet fset = _tmgr.getTileSet(fringeset);
@@ -1,5 +1,5 @@
// //
// $Id: FringeConfiguration.java,v 1.13 2002/08/19 22:58:15 mdb Exp $ // $Id: FringeConfiguration.java,v 1.14 2003/05/29 01:04:58 ray Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
@@ -119,12 +119,13 @@ public class FringeConfiguration implements Serializable
* Get a random FringeTileSetRecord from amongst the ones * Get a random FringeTileSetRecord from amongst the ones
* listed for the specified base tileset. * listed for the specified base tileset.
*/ */
public FringeTileSetRecord getRandomFringe (int baseset, Random rando) public FringeTileSetRecord getFringe (int baseset, int hashValue)
{ {
FringeRecord f = (FringeRecord) _frecs.get(baseset); FringeRecord f = (FringeRecord) _frecs.get(baseset);
int size = f.tilesets.size(); int size = f.tilesets.size();
return (FringeTileSetRecord) f.tilesets.get(rando.nextInt(size)); int pick = Math.abs(hashValue) % size;
return (FringeTileSetRecord) f.tilesets.get(pick);
} }
/** The mapping from base tileset id to fringerecord. */ /** The mapping from base tileset id to fringerecord. */