aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2016-06-04 01:35:37 -0400
committerkwolekr <kwolekr@minetest.net>2016-06-04 01:51:44 -0400
commitdfbdb5bcd7bc48efb21d585d5c22454a9d5f0f1e (patch)
tree20f2d5cbb64f1a6bf0ee2638f4396effb42d362b /src
parent2060fd9cbe587d7e8ffe0cecdd67925f13a56c05 (diff)
downloadminetest-dfbdb5bcd7bc48efb21d585d5c22454a9d5f0f1e.tar.gz
minetest-dfbdb5bcd7bc48efb21d585d5c22454a9d5f0f1e.tar.bz2
minetest-dfbdb5bcd7bc48efb21d585d5c22454a9d5f0f1e.zip
Change internal type for seeds to s32
This fixes value truncation (and therefore incompatibility) on platforms with an LP32 data model, such as VAX or MS-DOS.
Diffstat (limited to 'src')
-rw-r--r--src/cavegen.cpp4
-rw-r--r--src/cavegen.h6
-rw-r--r--src/dungeongen.h2
-rw-r--r--src/mapgen.cpp20
-rw-r--r--src/mapgen.h6
-rw-r--r--src/mg_biome.h2
-rw-r--r--src/noise.cpp26
-rw-r--r--src/noise.h32
-rw-r--r--src/script/lua_api/l_env.cpp2
-rw-r--r--src/script/lua_api/l_noise.cpp2
-rw-r--r--src/script/lua_api/l_noise.h4
-rw-r--r--src/treegen.cpp8
-rw-r--r--src/treegen.h8
13 files changed, 68 insertions, 54 deletions
diff --git a/src/cavegen.cpp b/src/cavegen.cpp
index 1c25ce711..dc7355fe0 100644
--- a/src/cavegen.cpp
+++ b/src/cavegen.cpp
@@ -35,7 +35,7 @@ static NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0
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);
@@ -130,7 +130,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
CavesRandomWalk::CavesRandomWalk(
INodeDefManager *ndef,
GenerateNotifier *gennotify,
- int seed,
+ s32 seed,
int water_level,
content_t water_source,
content_t lava_source)
diff --git a/src/cavegen.h b/src/cavegen.h
index da0894635..2bf503d47 100644
--- a/src/cavegen.h
+++ b/src/cavegen.h
@@ -41,7 +41,7 @@ class CavesNoiseIntersection {
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);
@@ -83,7 +83,7 @@ public:
s16 *heightmap;
// configurable parameters
- int seed;
+ s32 seed;
int water_level;
int lava_depth;
NoiseParams *np_caveliquids;
@@ -122,7 +122,7 @@ public:
// 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);
diff --git a/src/dungeongen.h b/src/dungeongen.h
index f0a5e5ba8..898627483 100644
--- a/src/dungeongen.h
+++ b/src/dungeongen.h
@@ -39,7 +39,7 @@ int dir_to_facedir(v3s16 d);
struct DungeonParams {
- int seed;
+ s32 seed;
content_t c_water;
content_t c_river_water;
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index 041356e3d..32f7e29eb 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -89,11 +89,25 @@ Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
{
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;
@@ -107,7 +121,7 @@ Mapgen::~Mapgen()
}
-u32 Mapgen::getBlockSeed(v3s16 p, int seed)
+u32 Mapgen::getBlockSeed(v3s16 p, s32 seed)
{
return (u32)seed +
p.Z * 38134234 +
@@ -116,7 +130,7 @@ u32 Mapgen::getBlockSeed(v3s16 p, int seed)
}
-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;
diff --git a/src/mapgen.h b/src/mapgen.h
index 10595fafc..0342fd46e 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -150,7 +150,7 @@ struct MapgenParams {
*/
class Mapgen {
public:
- int seed;
+ s32 seed;
int water_level;
u32 flags;
bool generating;
@@ -171,8 +171,8 @@ public:
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);
diff --git a/src/mg_biome.h b/src/mg_biome.h
index e78e90e5f..389b7664f 100644
--- a/src/mg_biome.h
+++ b/src/mg_biome.h
@@ -80,7 +80,7 @@ struct BiomeParams {
virtual void writeParams(Settings *settings) const = 0;
virtual ~BiomeParams() {}
- int seed;
+ s32 seed;
};
class BiomeGen {
diff --git a/src/noise.cpp b/src/noise.cpp
index 2ddc3926f..c57c98ccb 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -156,7 +156,7 @@ s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
///////////////////////////////////////////////////////////////////////////////
-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;
@@ -166,7 +166,7 @@ float noise2d(int x, int y, int seed)
}
-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;
@@ -235,7 +235,7 @@ float triLinearInterpolationNoEase(
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);
@@ -256,7 +256,7 @@ float noise2d_gradient(float x, float y, int seed, bool eased)
}
-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);
@@ -290,7 +290,7 @@ float noise3d_gradient(float x, float y, float z, int seed, bool eased)
}
-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;
@@ -306,7 +306,7 @@ float noise2d_perlin(float x, float y, int seed,
}
-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;
@@ -321,7 +321,7 @@ float noise2d_perlin_abs(float x, float y, int seed,
}
-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;
@@ -336,7 +336,7 @@ float noise3d_perlin(float x, float y, float z, int seed,
}
-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;
@@ -363,7 +363,7 @@ float contour(float v)
///////////////////////// [ 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;
@@ -389,7 +389,7 @@ float NoisePerlin2D(NoiseParams *np, float x, float y, int seed)
}
-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;
@@ -416,7 +416,7 @@ float NoisePerlin3D(NoiseParams *np, float x, float y, float z, int seed)
}
-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;
@@ -543,7 +543,7 @@ void Noise::resizeNoiseBuf(bool is3d)
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;
@@ -607,7 +607,7 @@ void Noise::gradientMap2D(
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;
diff --git a/src/noise.h b/src/noise.h
index 0e4252dd4..41b93ae01 100644
--- a/src/noise.h
+++ b/src/noise.h
@@ -148,7 +148,7 @@ struct NoiseParams {
class Noise {
public:
NoiseParams np;
- int seed;
+ s32 seed;
u32 sx;
u32 sy;
u32 sz;
@@ -157,7 +157,7 @@ public:
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);
@@ -167,11 +167,11 @@ public:
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);
@@ -202,11 +202,11 @@ private:
};
-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,
@@ -215,7 +215,7 @@ inline float NoisePerlin2D_PO(NoiseParams *np, float x, float xoff,
}
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,
@@ -225,22 +225,22 @@ inline float NoisePerlin3D_PO(NoiseParams *np, float x, float xoff,
}
// 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)
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 8284c3fcb..ebdea09e4 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -758,7 +758,7 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L)
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");
diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp
index 04dc6048f..e0039371f 100644
--- a/src/script/lua_api/l_noise.cpp
+++ b/src/script/lua_api/l_noise.cpp
@@ -146,7 +146,7 @@ const luaL_reg LuaPerlinNoise::methods[] = {
LuaPerlinNoiseMap
*/
-LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *params, int seed, v3s16 size)
+LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *params, s32 seed, v3s16 size)
{
m_is3d = size.Z > 1;
np = *params;
diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h
index 492eb7550..40bfd1315 100644
--- a/src/script/lua_api/l_noise.h
+++ b/src/script/lua_api/l_noise.h
@@ -79,7 +79,7 @@ class LuaPerlinNoiseMap : public ModApiBase {
static int l_getMapSlice(lua_State *L);
public:
- LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size);
+ LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3s16 size);
~LuaPerlinNoiseMap();
@@ -111,7 +111,7 @@ private:
static int l_next(lua_State *L);
public:
- LuaPseudoRandom(int seed) :
+ LuaPseudoRandom(s32 seed) :
m_pseudo(seed) {}
// LuaPseudoRandom(seed)
diff --git a/src/treegen.cpp b/src/treegen.cpp
index 208f34552..36d387c57 100644
--- a/src/treegen.cpp
+++ b/src/treegen.cpp
@@ -31,7 +31,7 @@ namespace treegen
{
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
@@ -149,7 +149,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
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
@@ -649,7 +649,7 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v)
}
-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
@@ -748,7 +748,7 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed
}
-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
diff --git a/src/treegen.h b/src/treegen.h
index 4b0089d1e..4e6f95e67 100644
--- a/src/treegen.h
+++ b/src/treegen.h
@@ -54,19 +54,19 @@ namespace treegen {
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,