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;
}