CavesNoiseIntersection::CavesNoiseIntersection(
INodeDefManager *nodedef, BiomeManager *biomemgr, v3s16 chunksize,
- NoiseParams *np_cave1, NoiseParams *np_cave2, int seed, float cave_width)
+ NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width)
{
assert(nodedef);
assert(biomemgr);
CavesRandomWalk::CavesRandomWalk(
INodeDefManager *ndef,
GenerateNotifier *gennotify,
- int seed,
+ s32 seed,
int water_level,
content_t water_source,
content_t lava_source)
public:
CavesNoiseIntersection(INodeDefManager *nodedef, BiomeManager *biomemgr,
v3s16 chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2,
- int seed, float cave_width);
+ s32 seed, float cave_width);
~CavesNoiseIntersection();
void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, u8 *biomemap);
s16 *heightmap;
// configurable parameters
- int seed;
+ s32 seed;
int water_level;
int lava_depth;
NoiseParams *np_caveliquids;
// If gennotify is NULL, generation events are not logged.
CavesRandomWalk(INodeDefManager *ndef,
GenerateNotifier *gennotify = NULL,
- int seed = 0,
+ s32 seed = 0,
int water_level = 1,
content_t water_source = CONTENT_IGNORE,
content_t lava_source = CONTENT_IGNORE);
struct DungeonParams {
- int seed;
+ s32 seed;
content_t c_water;
content_t c_river_water;
{
generating = false;
id = mapgenid;
- seed = (int)params->seed;
water_level = params->water_level;
flags = params->flags;
csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
+ /*
+ We are losing half our entropy by doing this, but it is necessary to
+ preserve reverse compatibility. If the top half of our current 64 bit
+ seeds ever starts getting used, existing worlds will break due to a
+ different hash outcome and no way to differentiate between versions.
+
+ A solution could be to add a new bit to designate that the top half of
+ the seed value should be used, essentially a 1-bit version code, but
+ this would require increasing the total size of a seed to 9 bytes (yuck)
+
+ It's probably okay if this never gets fixed. 4.2 billion possibilities
+ ought to be enough for anyone.
+ */
+ seed = (s32)params->seed;
+
vm = NULL;
ndef = emerge->ndef;
biomegen = NULL;
}
-u32 Mapgen::getBlockSeed(v3s16 p, int seed)
+u32 Mapgen::getBlockSeed(v3s16 p, s32 seed)
{
return (u32)seed +
p.Z * 38134234 +
}
-u32 Mapgen::getBlockSeed2(v3s16 p, int seed)
+u32 Mapgen::getBlockSeed2(v3s16 p, s32 seed)
{
u32 n = 1619 * p.X + 31337 * p.Y + 52591 * p.Z + 1013 * seed;
n = (n >> 13) ^ n;
*/
class Mapgen {
public:
- int seed;
+ s32 seed;
int water_level;
u32 flags;
bool generating;
Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
virtual ~Mapgen();
- static u32 getBlockSeed(v3s16 p, int seed);
- static u32 getBlockSeed2(v3s16 p, int seed);
+ static u32 getBlockSeed(v3s16 p, s32 seed);
+ static u32 getBlockSeed2(v3s16 p, s32 seed);
s16 findGroundLevelFull(v2s16 p2d);
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
virtual void writeParams(Settings *settings) const = 0;
virtual ~BiomeParams() {}
- int seed;
+ s32 seed;
};
class BiomeGen {
///////////////////////////////////////////////////////////////////////////////
-float noise2d(int x, int y, int seed)
+float noise2d(int x, int y, s32 seed)
{
unsigned int n = (NOISE_MAGIC_X * x + NOISE_MAGIC_Y * y
+ NOISE_MAGIC_SEED * seed) & 0x7fffffff;
}
-float noise3d(int x, int y, int z, int seed)
+float noise3d(int x, int y, int z, s32 seed)
{
unsigned int n = (NOISE_MAGIC_X * x + NOISE_MAGIC_Y * y + NOISE_MAGIC_Z * z
+ NOISE_MAGIC_SEED * seed) & 0x7fffffff;
return linearInterpolation(u, v, z);
}
-float noise2d_gradient(float x, float y, int seed, bool eased)
+float noise2d_gradient(float x, float y, s32 seed, bool eased)
{
// Calculate the integer coordinates
int x0 = myfloor(x);
}
-float noise3d_gradient(float x, float y, float z, int seed, bool eased)
+float noise3d_gradient(float x, float y, float z, s32 seed, bool eased)
{
// Calculate the integer coordinates
int x0 = myfloor(x);
}
-float noise2d_perlin(float x, float y, int seed,
+float noise2d_perlin(float x, float y, s32 seed,
int octaves, float persistence, bool eased)
{
float a = 0;
}
-float noise2d_perlin_abs(float x, float y, int seed,
+float noise2d_perlin_abs(float x, float y, s32 seed,
int octaves, float persistence, bool eased)
{
float a = 0;
}
-float noise3d_perlin(float x, float y, float z, int seed,
+float noise3d_perlin(float x, float y, float z, s32 seed,
int octaves, float persistence, bool eased)
{
float a = 0;
}
-float noise3d_perlin_abs(float x, float y, float z, int seed,
+float noise3d_perlin_abs(float x, float y, float z, s32 seed,
int octaves, float persistence, bool eased)
{
float a = 0;
///////////////////////// [ New noise ] ////////////////////////////
-float NoisePerlin2D(NoiseParams *np, float x, float y, int seed)
+float NoisePerlin2D(NoiseParams *np, float x, float y, s32 seed)
{
float a = 0;
float f = 1.0;
}
-float NoisePerlin3D(NoiseParams *np, float x, float y, float z, int seed)
+float NoisePerlin3D(NoiseParams *np, float x, float y, float z, s32 seed)
{
float a = 0;
float f = 1.0;
}
-Noise::Noise(NoiseParams *np_, int seed, u32 sx, u32 sy, u32 sz)
+Noise::Noise(NoiseParams *np_, s32 seed, u32 sx, u32 sy, u32 sz)
{
memcpy(&np, np_, sizeof(np));
this->seed = seed;
void Noise::gradientMap2D(
float x, float y,
float step_x, float step_y,
- int seed)
+ s32 seed)
{
float v00, v01, v10, v11, u, v, orig_u;
u32 index, i, j, noisex, noisey;
void Noise::gradientMap3D(
float x, float y, float z,
float step_x, float step_y, float step_z,
- int seed)
+ s32 seed)
{
float v000, v010, v100, v110;
float v001, v011, v101, v111;
class Noise {
public:
NoiseParams np;
- int seed;
+ s32 seed;
u32 sx;
u32 sy;
u32 sz;
float *persist_buf;
float *result;
- Noise(NoiseParams *np, int seed, u32 sx, u32 sy, u32 sz=1);
+ Noise(NoiseParams *np, s32 seed, u32 sx, u32 sy, u32 sz=1);
~Noise();
void setSize(u32 sx, u32 sy, u32 sz=1);
void gradientMap2D(
float x, float y,
float step_x, float step_y,
- int seed);
+ s32 seed);
void gradientMap3D(
float x, float y, float z,
float step_x, float step_y, float step_z,
- int seed);
+ s32 seed);
float *perlinMap2D(float x, float y, float *persistence_map=NULL);
float *perlinMap3D(float x, float y, float z, float *persistence_map=NULL);
};
-float NoisePerlin2D(NoiseParams *np, float x, float y, int seed);
-float NoisePerlin3D(NoiseParams *np, float x, float y, float z, int seed);
+float NoisePerlin2D(NoiseParams *np, float x, float y, s32 seed);
+float NoisePerlin3D(NoiseParams *np, float x, float y, float z, s32 seed);
inline float NoisePerlin2D_PO(NoiseParams *np, float x, float xoff,
- float y, float yoff, int seed)
+ float y, float yoff, s32 seed)
{
return NoisePerlin2D(np,
x + xoff * np->spread.X,
}
inline float NoisePerlin3D_PO(NoiseParams *np, float x, float xoff,
- float y, float yoff, float z, float zoff, int seed)
+ float y, float yoff, float z, float zoff, s32 seed)
{
return NoisePerlin3D(np,
x + xoff * np->spread.X,
}
// Return value: -1 ... 1
-float noise2d(int x, int y, int seed);
-float noise3d(int x, int y, int z, int seed);
+float noise2d(int x, int y, s32 seed);
+float noise3d(int x, int y, int z, s32 seed);
-float noise2d_gradient(float x, float y, int seed, bool eased=true);
-float noise3d_gradient(float x, float y, float z, int seed, bool eased=false);
+float noise2d_gradient(float x, float y, s32 seed, bool eased=true);
+float noise3d_gradient(float x, float y, float z, s32 seed, bool eased=false);
-float noise2d_perlin(float x, float y, int seed,
+float noise2d_perlin(float x, float y, s32 seed,
int octaves, float persistence, bool eased=true);
-float noise2d_perlin_abs(float x, float y, int seed,
+float noise2d_perlin_abs(float x, float y, s32 seed,
int octaves, float persistence, bool eased=true);
-float noise3d_perlin(float x, float y, float z, int seed,
+float noise3d_perlin(float x, float y, float z, s32 seed,
int octaves, float persistence, bool eased=false);
-float noise3d_perlin_abs(float x, float y, float z, int seed,
+float noise3d_perlin_abs(float x, float y, float z, s32 seed,
int octaves, float persistence, bool eased=false);
inline float easeCurve(float t)
return 0;
v3s16 size = read_v3s16(L, 2);
- int seed = (int)(env->getServerMap().getSeed());
+ s32 seed = (s32)(env->getServerMap().getSeed());
LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size);
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
luaL_getmetatable(L, "PerlinNoiseMap");
LuaPerlinNoiseMap
*/
-LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *params, int seed, v3s16 size)
+LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *params, s32 seed, v3s16 size)
{
m_is3d = size.Z > 1;
np = *params;
static int l_getMapSlice(lua_State *L);
public:
- LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size);
+ LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3s16 size);
~LuaPerlinNoiseMap();
static int l_next(lua_State *L);
public:
- LuaPseudoRandom(int seed) :
+ LuaPseudoRandom(s32 seed) :
m_pseudo(seed) {}
// LuaPseudoRandom(seed)
{
void make_tree(MMVManip &vmanip, v3s16 p0,
- bool is_apple_tree, INodeDefManager *ndef, int seed)
+ bool is_apple_tree, INodeDefManager *ndef, s32 seed)
{
/*
NOTE: Tree-placing code is currently duplicated in the engine
INodeDefManager *ndef, TreeDef tree_definition)
{
MapNode dirtnode(ndef->getId("mapgen_dirt"));
- int seed;
+ s32 seed;
if (tree_definition.explicit_seed)
seed = tree_definition.seed + 14002;
else
}
-void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
+void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
{
/*
NOTE: Tree-placing code is currently duplicated in the engine
}
-void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
+void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
{
/*
NOTE: Tree-placing code is currently duplicated in the engine
bool thin_branches;
MapNode fruitnode;
int fruit_chance;
- int seed;
+ s32 seed;
bool explicit_seed;
};
// Add default tree
void make_tree(MMVManip &vmanip, v3s16 p0,
- bool is_apple_tree, INodeDefManager *ndef, int seed);
+ bool is_apple_tree, INodeDefManager *ndef, s32 seed);
// Add jungle tree
void make_jungletree(MMVManip &vmanip, v3s16 p0,
- INodeDefManager *ndef, int seed);
+ INodeDefManager *ndef, s32 seed);
// Add pine tree
void make_pine_tree(MMVManip &vmanip, v3s16 p0,
- INodeDefManager *ndef, int seed);
+ INodeDefManager *ndef, s32 seed);
// Add L-Systems tree (used by engine)
treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef,