Moved getTileHash() into TileUtil.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3628 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-06-28 17:42:55 +00:00
parent b52e20864d
commit 7428f885cf
4 changed files with 24 additions and 23 deletions
@@ -1,5 +1,5 @@
//
// $Id: TileUtil.java,v 1.6 2004/08/27 02:12:41 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -50,4 +50,21 @@ public class TileUtil
{
return (fqTileId & 0xFFFF);
}
/**
* Compute some hash value for "randomizing" tileset picks
* based on x and y coordinates.
*
* @return a positive, seemingly random number based on x and y.
*/
public static int getTileHash (int x, int y)
{
long seed = ((x ^ y) ^ MULTIPLIER) & MASK;
long hash = (seed * MULTIPLIER + ADDEND) & MASK;
return (int) (hash >>> 30);
}
protected static final long MULTIPLIER = 0x5DEECE66DL;
protected static final long ADDEND = 0xBL;
protected static final long MASK = (1L << 48) - 1;
}
@@ -1,5 +1,5 @@
//
// $Id: SceneBlock.java,v 1.26 2004/10/28 17:49:02 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -36,6 +36,7 @@ import com.threerings.geom.GeomUtil;
import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.ObjectTile;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileUtil;
import com.threerings.media.util.MathUtil;
import com.threerings.miso.Log;
@@ -258,7 +259,7 @@ public class SceneBlock
BaseTile tile = _base[index(tx, ty)];
if (tile == null && _defset != null) {
tile = (BaseTile)_defset.getTile(
MisoUtil.getTileHash(tx, ty) % _defset.getTileCount());
TileUtil.getTileHash(tx, ty) % _defset.getTileCount());
}
return tile;
}
@@ -1,5 +1,5 @@
//
// $Id: AutoFringer.java,v 1.30 2004/10/28 17:49:02 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -38,10 +38,10 @@ import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileManager;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileUtil;
import com.threerings.miso.Log;
import com.threerings.miso.data.MisoSceneModel;
import com.threerings.miso.util.MisoUtil;
/**
* Automatically fringes a scene according to the rules in the supplied
@@ -136,7 +136,7 @@ public class AutoFringer
BaseTile frTile = new BaseTile();
frTile.setPassable(passable);
composeFringeTile(frTile, frecs, masks, MisoUtil.getTileHash(col, row));
composeFringeTile(frTile, frecs, masks, TileUtil.getTileHash(col, row));
return frTile;
}
@@ -168,19 +168,6 @@ public class MisoUtil
return dir;
}
/**
* Compute some hash value for "randomizing" tileset picks
* based on x and y coordinates.
*
* @return a positive, seemingly random number based on x and y.
*/
public static int getTileHash (int x, int y)
{
long seed = ((x ^ y) ^ MULTIPLIER) & MASK;
long hash = (seed * MULTIPLIER + ADDEND) & MASK;
return (int) (hash >>> 30);
}
/**
* Returns the tile coordinate of the given full coordinate.
*/
@@ -528,8 +515,4 @@ public class MisoUtil
/** Multiplication factor to embed tile coords in full coords. */
protected static final int FULL_TILE_FACTOR = 100;
protected static final long MULTIPLIER = 0x5DEECE66DL;
protected static final long ADDEND = 0xBL;
protected static final long MASK = (1L << 48) - 1;
}