diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mapgen_v5.cpp | 4 | ||||
-rw-r--r-- | src/mapgen_v6.cpp | 6 | ||||
-rw-r--r-- | src/mapgen_v7.cpp | 8 | ||||
-rw-r--r-- | src/noise.cpp | 23 | ||||
-rw-r--r-- | src/noise.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_noise.cpp | 24 |
6 files changed, 21 insertions, 46 deletions
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index f2cb79179..0ec19ebda 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -299,14 +299,10 @@ void MapgenV5::calculateNoise() { noise_filler_depth->perlinMap2D(x, z); noise_factor->perlinMap2D(x, z); noise_height->perlinMap2D(x, z); - noise_height->transformNoiseMap(); noise_cave1->perlinMap3D(x, y, z); - noise_cave1->transformNoiseMap(); noise_cave2->perlinMap3D(x, y, z); - noise_cave2->transformNoiseMap(); noise_ground->perlinMap3D(x, y, z); - noise_ground->transformNoiseMap(); if (spflags & MGV5_BLOBS) { noise_crumble->perlinMap3D(x, y, z); diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 04c3b147e..004aef8c7 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -125,7 +125,7 @@ MapgenV6Params::MapgenV6Params() { np_terrain_base = NoiseParams(-4, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6, 2.0); np_terrain_higher = NoiseParams(20, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6, 2.0); np_steepness = NoiseParams(0.85,0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7, 2.0); - np_height_select = NoiseParams(0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69, 2.0); + np_height_select = NoiseParams(0, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69, 2.0); np_mud = NoiseParams(4, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55, 2.0); np_beach = NoiseParams(0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50, 2.0); np_biome = NoiseParams(0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50, 2.0); @@ -552,17 +552,14 @@ void MapgenV6::calculateNoise() { noise_terrain_base->perlinMap2D( x + 0.5 * noise_terrain_base->np.spread.X, z + 0.5 * noise_terrain_base->np.spread.Z); - noise_terrain_base->transformNoiseMap(); noise_terrain_higher->perlinMap2D( x + 0.5 * noise_terrain_higher->np.spread.X, z + 0.5 * noise_terrain_higher->np.spread.Z); - noise_terrain_higher->transformNoiseMap(); noise_steepness->perlinMap2D( x + 0.5 * noise_steepness->np.spread.X, z + 0.5 * noise_steepness->np.spread.Z); - noise_steepness->transformNoiseMap(); noise_height_select->perlinMap2D( x + 0.5 * noise_height_select->np.spread.X, @@ -571,7 +568,6 @@ void MapgenV6::calculateNoise() { noise_mud->perlinMap2D( x + 0.5 * noise_mud->np.spread.X, z + 0.5 * noise_mud->np.spread.Z); - noise_mud->transformNoiseMap(); } noise_beach->perlinMap2D( diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index be60a2c98..097e70934 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -270,26 +270,18 @@ void MapgenV7::calculateNoise() { int z = node_min.Z; noise_height_select->perlinMap2D(x, z); - noise_height_select->transformNoiseMap(); - noise_terrain_persist->perlinMap2D(x, z); - noise_terrain_persist->transformNoiseMap(); float *persistmap = noise_terrain_persist->result; for (int i = 0; i != csize.X * csize.Z; i++) persistmap[i] = rangelim(persistmap[i], 0.4, 0.9); noise_terrain_base->perlinMap2D(x, z, persistmap); - noise_terrain_base->transformNoiseMap(); - noise_terrain_alt->perlinMap2D(x, z, persistmap); - noise_terrain_alt->transformNoiseMap(); - noise_filler_depth->perlinMap2D(x, z); if (spflags & MGV7_MOUNTAINS) { noise_mountain->perlinMap3D(x, y, z); noise_mount_height->perlinMap2D(x, z); - noise_mount_height->transformNoiseMap(); } if (spflags & MGV7_RIDGES) { diff --git a/src/noise.cpp b/src/noise.cpp index 0d8b118aa..069c60d44 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -611,6 +611,11 @@ float *Noise::perlinMap2D(float x, float y, float *persistence_map) g *= np.persist; } + if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) { + for (size_t i = 0; i != bufsize; i++) + result[i] = result[i] * np.scale + np.offset; + } + return result; } @@ -644,6 +649,11 @@ float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map) g *= np.persist; } + if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) { + for (size_t i = 0; i != bufsize; i++) + result[i] = result[i] * np.scale + np.offset; + } + return result; } @@ -675,16 +685,3 @@ void Noise::updateResults(float g, float *gmap, } } } - - -void Noise::transformNoiseMap() -{ - // Because sx, sy, and sz are object members whose values may conceivably be - // modified in other threads. gcc (at least) will consider the buffer size - // computation as invalidated between loop comparisons, resulting in a ~2x - // slowdown even with -O2. To prevent this, store the value in a local. - size_t bufsize = sx * sy * sz; - for (size_t i = 0; i != bufsize; i++) - result[i] = result[i] * np.scale + np.offset; -} - diff --git a/src/noise.h b/src/noise.h index 66be8db93..2cdf4203d 100644 --- a/src/noise.h +++ b/src/noise.h @@ -151,8 +151,6 @@ public: float *perlinMap2D(float x, float y, float *persistence_map=NULL); float *perlinMap3D(float x, float y, float z, float *persistence_map=NULL); - void transformNoiseMap(); - private: void allocBuffers(); void resizeNoiseBuf(bool is3d); diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index c66f54e6f..6c6b35358 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -149,7 +149,7 @@ int LuaPerlinNoiseMap::gc_object(lua_State *L) int LuaPerlinNoiseMap::l_get2dMap(lua_State *L) { NO_MAP_LOCK_REQUIRED; - int i = 0; + size_t i = 0; LuaPerlinNoiseMap *o = checkobject(L, 1); v2f p = read_v2f(L, 2); @@ -161,8 +161,7 @@ int LuaPerlinNoiseMap::l_get2dMap(lua_State *L) for (int y = 0; y != n->sy; y++) { lua_newtable(L); for (int x = 0; x != n->sx; x++) { - float noiseval = n->np.offset + n->np.scale * n->result[i++]; - lua_pushnumber(L, noiseval); + lua_pushnumber(L, n->result[i++]); lua_rawseti(L, -2, x + 1); } lua_rawseti(L, -2, y + 1); @@ -181,12 +180,11 @@ int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L) Noise *n = o->noise; n->perlinMap2D(p.X, p.Y); - int maplen = n->sx * n->sy; + size_t maplen = n->sx * n->sy; lua_newtable(L); - for (int i = 0; i != maplen; i++) { - float noiseval = n->np.offset + n->np.scale * n->result[i]; - lua_pushnumber(L, noiseval); + for (size_t i = 0; i != maplen; i++) { + lua_pushnumber(L, n->result[i]); lua_rawseti(L, -2, i + 1); } return 1; @@ -196,7 +194,7 @@ int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L) int LuaPerlinNoiseMap::l_get3dMap(lua_State *L) { NO_MAP_LOCK_REQUIRED; - int i = 0; + size_t i = 0; LuaPerlinNoiseMap *o = checkobject(L, 1); v3f p = read_v3f(L, 2); @@ -210,7 +208,7 @@ int LuaPerlinNoiseMap::l_get3dMap(lua_State *L) for (int y = 0; y != n->sy; y++) { lua_newtable(L); for (int x = 0; x != n->sx; x++) { - lua_pushnumber(L, n->np.offset + n->np.scale * n->result[i++]); + lua_pushnumber(L, n->result[i++]); lua_rawseti(L, -2, x + 1); } lua_rawseti(L, -2, y + 1); @@ -231,13 +229,11 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L) Noise *n = o->noise; n->perlinMap3D(p.X, p.Y, p.Z); - - int maplen = n->sx * n->sy * n->sz; + size_t maplen = n->sx * n->sy * n->sz; lua_newtable(L); - for (int i = 0; i != maplen; i++) { - float noiseval = n->np.offset + n->np.scale * n->result[i]; - lua_pushnumber(L, noiseval); + for (size_t i = 0; i != maplen; i++) { + lua_pushnumber(L, n->result[i]); lua_rawseti(L, -2, i + 1); } return 1; |