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);
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);
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,
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(
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) {
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;
}
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;
}
}
}
}
-
-
-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;
-}
-
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);
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);
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);
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;
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);
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);
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;