Added MisoUtil.getTileHash(), made both SceneBlock and AutoFringer use
it to pick random tiles based on x/y location. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2622 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SceneBlock.java,v 1.16 2003/05/23 19:35:11 mdb Exp $
|
// $Id: SceneBlock.java,v 1.17 2003/05/29 01:58:06 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.client;
|
package com.threerings.miso.client;
|
||||||
|
|
||||||
@@ -206,10 +206,8 @@ public class SceneBlock
|
|||||||
{
|
{
|
||||||
BaseTile tile = _base[index(tx, ty)];
|
BaseTile tile = _base[index(tx, ty)];
|
||||||
if (tile == null && _defset != null) {
|
if (tile == null && _defset != null) {
|
||||||
long seed = ((tx^ty) ^ multiplier) & mask;
|
tile = (BaseTile)_defset.getTile(
|
||||||
long hash = (seed * multiplier + addend) & mask;
|
MisoUtil.getTileHash(tx, ty) % _defset.getTileCount());
|
||||||
int tidx = (int)((hash >> 10) % _defset.getTileCount());
|
|
||||||
tile = (BaseTile)_defset.getTile(tidx);
|
|
||||||
}
|
}
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: AutoFringer.java,v 1.23 2003/05/29 01:04:58 ray Exp $
|
// $Id: AutoFringer.java,v 1.24 2003/05/29 01:58:06 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.tile;
|
package com.threerings.miso.tile;
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ import com.threerings.media.image.ImageManager;
|
|||||||
import com.threerings.media.image.Mirage;
|
import com.threerings.media.image.Mirage;
|
||||||
|
|
||||||
import com.threerings.miso.data.MisoSceneModel;
|
import com.threerings.miso.data.MisoSceneModel;
|
||||||
|
import com.threerings.miso.util.MisoUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically fringes a scene according to the rules in the supplied
|
* Automatically fringes a scene according to the rules in the supplied
|
||||||
@@ -110,16 +111,7 @@ public class AutoFringer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return composeFringeTile(frecs, masks, generateHashValue(col, row));
|
return composeFringeTile(frecs, masks, MisoUtil.getTileHash(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: FringeConfiguration.java,v 1.14 2003/05/29 01:04:58 ray Exp $
|
// $Id: FringeConfiguration.java,v 1.15 2003/05/29 01:58:06 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.tile;
|
package com.threerings.miso.tile;
|
||||||
|
|
||||||
@@ -122,10 +122,8 @@ public class FringeConfiguration implements Serializable
|
|||||||
public FringeTileSetRecord getFringe (int baseset, int hashValue)
|
public FringeTileSetRecord getFringe (int baseset, int hashValue)
|
||||||
{
|
{
|
||||||
FringeRecord f = (FringeRecord) _frecs.get(baseset);
|
FringeRecord f = (FringeRecord) _frecs.get(baseset);
|
||||||
|
return (FringeTileSetRecord) f.tilesets.get(
|
||||||
int size = f.tilesets.size();
|
hashValue % f.tilesets.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. */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MisoUtil.java,v 1.21 2003/04/19 22:40:34 mdb Exp $
|
// $Id: MisoUtil.java,v 1.22 2003/05/29 01:58:06 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.util;
|
package com.threerings.miso.util;
|
||||||
|
|
||||||
@@ -156,6 +156,19 @@ public class MisoUtil
|
|||||||
return dir;
|
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.
|
* Returns the tile coordinate of the given full coordinate.
|
||||||
*/
|
*/
|
||||||
@@ -503,4 +516,8 @@ public class MisoUtil
|
|||||||
|
|
||||||
/** Multiplication factor to embed tile coords in full coords. */
|
/** Multiplication factor to embed tile coords in full coords. */
|
||||||
protected static final int FULL_TILE_FACTOR = 100;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user