aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-12-07 23:43:46 -0500
committerkwolekr <kwolekr@minetest.net>2013-12-08 01:31:06 -0500
commit83cc8823354c1c476498ddf35052f403ea247e80 (patch)
treec7bc33296dd6b5b200d0668028556e8c4b68ab2b /src/mapgen.cpp
parentbbae8eb7514be2fef4d3931c3cec37c04c415786 (diff)
downloadminetest-83cc8823354c1c476498ddf35052f403ea247e80.tar.gz
minetest-83cc8823354c1c476498ddf35052f403ea247e80.tar.bz2
minetest-83cc8823354c1c476498ddf35052f403ea247e80.zip
EmergeManager: Fix Lua mapgen override param handling
Diffstat (limited to 'src/mapgen.cpp')
-rw-r--r--src/mapgen.cpp138
1 files changed, 69 insertions, 69 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index 2be0c1dd2..20fc4459b 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -151,7 +151,7 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
int x0 = pr.range(nmin.X, nmax.X - csize + 1);
int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
-
+
if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
continue;
@@ -241,7 +241,7 @@ Decoration::~Decoration() {
void Decoration::resolveNodeNames(INodeDefManager *ndef) {
this->ndef = ndef;
-
+
if (c_place_on == CONTENT_IGNORE)
c_place_on = ndef->getId(place_on_name);
}
@@ -257,7 +257,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
"sidelen; setting sidelen to " << carea_size << std::endl;
sidelen = carea_size;
}
-
+
s16 divlen = carea_size / sidelen;
int area = sidelen * sidelen;
@@ -287,11 +287,11 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
s16 z = ps.range(p2d_min.Y, p2d_max.Y);
int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);
-
- s16 y = mg->heightmap ?
+
+ s16 y = mg->heightmap ?
mg->heightmap[mapindex] :
mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
-
+
if (y < nmin.Y || y > nmax.Y)
continue;
@@ -309,7 +309,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
if (mg->biomemap) {
std::set<u8>::iterator iter;
-
+
if (biomes.size()) {
iter = biomes.find(mg->biomemap[mapindex]);
if (iter == biomes.end())
@@ -327,7 +327,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
PseudoRandom pr(blockseed + 53);
std::vector<CutoffData> handled_cutoffs;
-
+
// Copy over the cutoffs we're interested in so we don't needlessly hold a lock
{
JMutexAutoLock cutofflock(cutoff_mutex);
@@ -341,37 +341,37 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
continue;
if (p.Y + height < nmin.Y || p.Y > nmax.Y)
continue;
-
+
handled_cutoffs.push_back(cutoff);
}
}
-
+
// Generate the cutoffs
for (size_t i = 0; i != handled_cutoffs.size(); i++) {
v3s16 p = handled_cutoffs[i].p;
s16 height = handled_cutoffs[i].height;
-
+
if (p.Y + height > nmax.Y) {
//printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
}
-
+
generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
}
-
+
// Remove cutoffs that were handled from the cutoff list
{
JMutexAutoLock cutofflock(cutoff_mutex);
for (std::list<CutoffData>::iterator i = cutoffs.begin();
i != cutoffs.end(); ++i) {
-
+
for (size_t j = 0; j != handled_cutoffs.size(); j++) {
CutoffData coff = *i;
if (coff.p == handled_cutoffs[j].p)
i = cutoffs.erase(i);
}
}
- }
+ }
}
#endif
@@ -381,7 +381,7 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
Decoration::resolveNodeNames(ndef);
-
+
if (c_deco == CONTENT_IGNORE && !decolist_names.size()) {
c_deco = ndef->getId(deco_name);
if (c_deco == CONTENT_IGNORE) {
@@ -399,11 +399,11 @@ void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
c_spawnby = CONTENT_AIR;
}
}
-
+
if (c_decolist.size())
return;
-
- for (size_t i = 0; i != decolist_names.size(); i++) {
+
+ for (size_t i = 0; i != decolist_names.size(); i++) {
content_t c = ndef->getId(decolist_names[i]);
if (c == CONTENT_IGNORE) {
errorstream << "DecoSimple::resolveNodeNames: decolist node '"
@@ -422,7 +422,7 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
if (vm->m_data[vi].getContent() != c_place_on &&
c_place_on != CONTENT_IGNORE)
return;
-
+
if (nspawnby != -1) {
int nneighs = 0;
v3s16 dirs[8] = { // a Moore neighborhood
@@ -435,18 +435,18 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
v3s16(-1, 0, -1),
v3s16( 1, 0, -1)
};
-
+
for (int i = 0; i != 8; i++) {
u32 index = vm->m_area.index(p + dirs[i]);
if (vm->m_area.contains(index) &&
vm->m_data[index].getContent() == c_spawnby)
nneighs++;
}
-
+
if (nneighs < nspawnby)
return;
}
-
+
size_t ndecos = c_decolist.size();
content_t c_place = ndecos ? c_decolist[pr->range(0, ndecos - 1)] : c_deco;
@@ -454,15 +454,15 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
pr->range(deco_height, deco_height_max) : deco_height;
height = MYMIN(height, max_y - p.Y);
-
+
v3s16 em = vm->m_area.getExtent();
for (int i = 0; i < height; i++) {
vm->m_area.add_y(em, vi, 1);
-
+
content_t c = vm->m_data[vi].getContent();
if (c != CONTENT_AIR && c != CONTENT_IGNORE)
break;
-
+
vm->m_data[vi] = MapNode(c_place);
}
}
@@ -499,37 +499,37 @@ DecoSchematic::~DecoSchematic() {
void DecoSchematic::resolveNodeNames(INodeDefManager *ndef) {
Decoration::resolveNodeNames(ndef);
-
+
if (filename.empty())
return;
-
+
if (!node_names) {
errorstream << "DecoSchematic::resolveNodeNames: node name list was "
"not created" << std::endl;
return;
}
-
+
for (size_t i = 0; i != node_names->size(); i++) {
std::string name = node_names->at(i);
-
+
std::map<std::string, std::string>::iterator it;
it = replacements.find(name);
if (it != replacements.end())
name = it->second;
-
+
content_t c = ndef->getId(name);
if (c == CONTENT_IGNORE) {
errorstream << "DecoSchematic::resolveNodeNames: node '"
<< name << "' not defined" << std::endl;
c = CONTENT_AIR;
}
-
+
c_nodes.push_back(c);
}
-
+
for (int i = 0; i != size.X * size.Y * size.Z; i++)
schematic[i].setContent(c_nodes[schematic[i].getContent()]);
-
+
delete node_names;
node_names = NULL;
}
@@ -544,15 +544,15 @@ void DecoSchematic::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
p.Y -= (size.Y + 1) / 2;
if (flags & DECO_PLACE_CENTER_Z)
p.Z -= (size.Z + 1) / 2;
-
+
u32 vi = vm->m_area.index(p);
if (vm->m_data[vi].getContent() != c_place_on &&
c_place_on != CONTENT_IGNORE)
return;
-
+
Rotation rot = (rotation == ROTATE_RAND) ?
(Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation;
-
+
blitToVManip(p, vm, rot, false);
}
@@ -649,7 +649,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
Rotation rot = (rotation == ROTATE_RAND) ?
(Rotation)myrand_range(ROTATE_0, ROTATE_270) : rotation;
-
+
v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ?
v3s16(size.Z, size.Y, size.X) : size;
@@ -659,17 +659,17 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
p.Y -= (s.Y + 1) / 2;
if (flags & DECO_PLACE_CENTER_Z)
p.Z -= (s.Z + 1) / 2;
-
+
v3s16 bp1 = getNodeBlockPos(p);
v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
vm->initialEmerge(bp1, bp2);
-
+
blitToVManip(p, vm, rot, true);
-
+
std::map<v3s16, MapBlock *> lighting_modified_blocks;
std::map<v3s16, MapBlock *> modified_blocks;
vm->blitBackAll(&modified_blocks);
-
+
// TODO: Optimize this by using Mapgen::calcLighting() instead
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
map->updateLighting(lighting_modified_blocks, modified_blocks);
@@ -680,7 +680,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
it = modified_blocks.begin();
it != modified_blocks.end(); ++it)
event.modified_blocks.insert(it->first);
-
+
map->dispatchEvent(&event);
}
@@ -688,7 +688,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
bool DecoSchematic::loadSchematicFile() {
content_t cignore = CONTENT_IGNORE;
bool have_cignore = false;
-
+
std::ifstream is(filename.c_str(), std::ios_base::binary);
u32 signature = readU32(is);
@@ -697,7 +697,7 @@ bool DecoSchematic::loadSchematicFile() {
"file" << std::endl;
return false;
}
-
+
u16 version = readU16(is);
if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
errorstream << "loadSchematicFile: unsupported schematic "
@@ -718,9 +718,9 @@ bool DecoSchematic::loadSchematicFile() {
}
int nodecount = size.X * size.Y * size.Z;
-
+
u16 nidmapcount = readU16(is);
-
+
node_names = new std::vector<std::string>;
for (int i = 0; i != nidmapcount; i++) {
std::string name = deSerializeString(is);
@@ -736,7 +736,7 @@ bool DecoSchematic::loadSchematicFile() {
schematic = new MapNode[nodecount];
MapNode::deSerializeBulk(is, SER_FMT_VER_HIGHEST_READ, schematic,
nodecount, 2, 2, true);
-
+
if (version == 1) { // fix up the probability values
for (int i = 0; i != nodecount; i++) {
if (schematic[i].param1 == 0)
@@ -745,7 +745,7 @@ bool DecoSchematic::loadSchematicFile() {
schematic[i].param1 = MTSCHEM_PROB_NEVER;
}
}
-
+
return true;
}
@@ -774,7 +774,7 @@ bool DecoSchematic::loadSchematicFile() {
For each node in schematic:
[u8] param2
}
-
+
Version changes:
1 - Initial version
2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
@@ -792,12 +792,12 @@ void DecoSchematic::saveSchematicFile(INodeDefManager *ndef) {
std::vector<content_t> usednodes;
int nodecount = size.X * size.Y * size.Z;
build_nnlist_and_update_ids(schematic, nodecount, &usednodes);
-
+
u16 numids = usednodes.size();
writeU16(ss, numids); // name count
for (int i = 0; i != numids; i++)
ss << serializeString(ndef->get(usednodes[i]).name); // node names
-
+
// compressed bulk node data
MapNode::serializeBulk(ss, SER_FMT_VER_HIGHEST_WRITE, schematic,
nodecount, 2, 2, true);
@@ -810,7 +810,7 @@ void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
std::vector<content_t> *usednodes) {
std::map<content_t, content_t> nodeidmap;
content_t numids = 0;
-
+
for (u32 i = 0; i != nodecount; i++) {
content_t id;
content_t c = nodes[i].getContent();
@@ -836,7 +836,7 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
v3s16 bp1 = getNodeBlockPos(p1);
v3s16 bp2 = getNodeBlockPos(p2);
vm->initialEmerge(bp1, bp2);
-
+
size = p2 - p1 + 1;
slice_probs = new u8[size.Y];
@@ -844,7 +844,7 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
slice_probs[y] = MTSCHEM_PROB_ALWAYS;
schematic = new MapNode[size.X * size.Y * size.Z];
-
+
u32 i = 0;
for (s16 z = p1.Z; z <= p2.Z; z++)
for (s16 y = p1.Y; y <= p2.Y; y++) {
@@ -870,7 +870,7 @@ void DecoSchematic::applyProbabilities(v3s16 p0,
if (index < size.Z * size.Y * size.X) {
u8 prob = (*plist)[i].second;
schematic[index].param1 = prob;
-
+
// trim unnecessary node names from schematic
if (prob == MTSCHEM_PROB_NEVER)
schematic[index].setContent(CONTENT_AIR);
@@ -906,7 +906,7 @@ s16 Mapgen::findGroundLevelFull(v2s16 p2d) {
s16 y_nodes_min = vm->m_area.MinEdge.Y;
u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
s16 y;
-
+
for (y = y_nodes_max; y >= y_nodes_min; y--) {
MapNode &n = vm->m_data[i];
if (ndef->get(n).walkable)
@@ -922,7 +922,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
v3s16 em = vm->m_area.getExtent();
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
s16 y;
-
+
for (y = ymax; y >= ymin; y--) {
MapNode &n = vm->m_data[i];
if (ndef->get(n).walkable)
@@ -937,7 +937,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
if (!heightmap)
return;
-
+
//TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO);
int index = 0;
for (s16 z = nmin.Z; z <= nmax.Z; z++) {
@@ -949,7 +949,7 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
continue;
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
continue;
-
+
heightmap[index] = y;
}
}
@@ -1040,7 +1040,7 @@ void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) {
continue;
}
vm->m_area.add_y(em, i, -1);
-
+
for (int y = a.MaxEdge.Y; y >= a.MinEdge.Y; y--) {
MapNode &n = vm->m_data[i];
if (!ndef->get(n).sunlight_propagates)
@@ -1103,15 +1103,15 @@ void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) {
vm->spreadLight(bank, light_sources, ndef);
}
}
-
-
+
+
//////////////////////// Mapgen V6 parameter read/write
-
+
bool MapgenV6Params::readParams(Settings *settings) {
freq_desert = settings->getFloat("mgv6_freq_desert");
freq_beach = settings->getFloat("mgv6_freq_beach");
- bool success =
+ bool success =
settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base) &&
settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
settings->getNoiseParams("mgv6_np_steepness", np_steepness) &&
@@ -1125,12 +1125,12 @@ bool MapgenV6Params::readParams(Settings *settings) {
settings->getNoiseParams("mgv6_np_apple_trees", np_apple_trees);
return success;
}
-
-
+
+
void MapgenV6Params::writeParams(Settings *settings) {
settings->setFloat("mgv6_freq_desert", freq_desert);
settings->setFloat("mgv6_freq_beach", freq_beach);
-
+
settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
settings->setNoiseParams("mgv6_np_steepness", np_steepness);
@@ -1146,7 +1146,7 @@ void MapgenV6Params::writeParams(Settings *settings) {
bool MapgenV7Params::readParams(Settings *settings) {
- bool success =
+ bool success =
settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&