#include "treegen.h"
#include "mapgen_v6.h"
#include "mapgen_v7.h"
+#include "serialization.h"
#include "util/serialize.h"
#include "filesys.h"
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;
void Decoration::resolveNodeNames(INodeDefManager *ndef) {
this->ndef = ndef;
-
+
if (c_place_on == CONTENT_IGNORE)
c_place_on = ndef->getId(place_on_name);
}
"sidelen; setting sidelen to " << carea_size << std::endl;
sidelen = carea_size;
}
-
+
s16 divlen = carea_size / sidelen;
int area = sidelen * sidelen;
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;
if (mg->biomemap) {
std::set<u8>::iterator iter;
-
+
if (biomes.size()) {
iter = biomes.find(mg->biomemap[mapindex]);
if (iter == biomes.end())
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);
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
void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
Decoration::resolveNodeNames(ndef);
-
- if (c_deco == CONTENT_IGNORE) {
+
+ if (c_deco == CONTENT_IGNORE && !decolist_names.size()) {
c_deco = ndef->getId(deco_name);
if (c_deco == CONTENT_IGNORE) {
errorstream << "DecoSimple::resolveNodeNames: decoration node '"
c_spawnby = ndef->getId(spawnby_name);
if (c_spawnby == CONTENT_IGNORE) {
errorstream << "DecoSimple::resolveNodeNames: spawnby node '"
- << deco_name << "' not defined" << std::endl;
+ << spawnby_name << "' not defined" << std::endl;
nspawnby = -1;
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 '"
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
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;
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);
}
}
DecoSchematic::DecoSchematic() {
- node_names = NULL;
- schematic = NULL;
- flags = 0;
- size = v3s16(0, 0, 0);
+ node_names = NULL;
+ schematic = NULL;
+ slice_probs = NULL;
+ flags = 0;
+ size = v3s16(0, 0, 0);
}
DecoSchematic::~DecoSchematic() {
delete node_names;
delete []schematic;
+ delete []slice_probs;
}
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;
}
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);
}
i_step_x = xstride;
i_step_z = zstride;
}
-
- for (s16 z = 0; z != sz; z++)
+
+ s16 y_map = p.Y;
for (s16 y = 0; y != sy; y++) {
- u32 i = z * i_step_z + y * ystride + i_start;
- for (s16 x = 0; x != sx; x++, i += i_step_x) {
- u32 vi = vm->m_area.index(p.X + x, p.Y + y, p.Z + z);
- if (!vm->m_area.contains(vi))
- continue;
-
- if (schematic[i].getContent() == CONTENT_IGNORE)
- continue;
-
- if (schematic[i].param1 == MTSCHEM_PROB_NEVER)
- continue;
+ if (slice_probs[y] != MTSCHEM_PROB_ALWAYS &&
+ myrand_range(1, 255) > slice_probs[y])
+ continue;
+
+ for (s16 z = 0; z != sz; z++) {
+ u32 i = z * i_step_z + y * ystride + i_start;
+ for (s16 x = 0; x != sx; x++, i += i_step_x) {
+ u32 vi = vm->m_area.index(p.X + x, y_map, p.Z + z);
+ if (!vm->m_area.contains(vi))
+ continue;
+
+ if (schematic[i].getContent() == CONTENT_IGNORE)
+ continue;
+
+ if (schematic[i].param1 == MTSCHEM_PROB_NEVER)
+ continue;
- if (!force_placement) {
- content_t c = vm->m_data[vi].getContent();
- if (c != CONTENT_AIR && c != CONTENT_IGNORE)
+ if (!force_placement) {
+ content_t c = vm->m_data[vi].getContent();
+ if (c != CONTENT_AIR && c != CONTENT_IGNORE)
+ continue;
+ }
+
+ if (schematic[i].param1 != MTSCHEM_PROB_ALWAYS &&
+ myrand_range(1, 255) > schematic[i].param1)
continue;
+
+ vm->m_data[vi] = schematic[i];
+ vm->m_data[vi].param1 = 0;
+
+ if (rot)
+ vm->m_data[vi].rotateAlongYAxis(ndef, rot);
}
-
- if (schematic[i].param1 != MTSCHEM_PROB_ALWAYS &&
- myrand_range(1, 255) > schematic[i].param1)
- continue;
-
- vm->m_data[vi] = schematic[i];
- vm->m_data[vi].param1 = 0;
-
- if (rot)
- vm->m_data[vi].rotateAlongYAxis(ndef, rot);
}
+ y_map++;
}
}
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;
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);
it = modified_blocks.begin();
it != modified_blocks.end(); ++it)
event.modified_blocks.insert(it->first);
-
+
map->dispatchEvent(&event);
}
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);
"file" << std::endl;
return false;
}
-
+
u16 version = readU16(is);
- if (version > 2) {
+ if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
errorstream << "loadSchematicFile: unsupported schematic "
"file version" << std::endl;
return false;
}
size = readV3S16(is);
+
+ delete []slice_probs;
+ slice_probs = new u8[size.Y];
+ if (version >= 3) {
+ for (int y = 0; y != size.Y; y++)
+ slice_probs[y] = readU8(is);
+ } else {
+ for (int y = 0; y != size.Y; y++)
+ slice_probs[y] = MTSCHEM_PROB_ALWAYS;
+ }
+
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);
node_names->push_back(name);
}
- delete schematic;
+ delete []schematic;
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)
schematic[i].param1 = MTSCHEM_PROB_NEVER;
}
}
-
+
return true;
}
All values are stored in big-endian byte order.
[u32] signature: 'MTSM'
- [u16] version: 2
+ [u16] version: 3
[u16] size X
[u16] size Y
[u16] size Z
+ For each Y:
+ [u8] slice probability value
[Name-ID table] Name ID Mapping Table
[u16] name-id count
For each name-id mapping:
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
void DecoSchematic::saveSchematicFile(INodeDefManager *ndef) {
std::ostringstream ss(std::ios_base::binary);
- writeU32(ss, MTSCHEM_FILE_SIGNATURE); // signature
- writeU16(ss, 2); // version
- writeV3S16(ss, size); // schematic size
-
+ writeU32(ss, MTSCHEM_FILE_SIGNATURE); // signature
+ writeU16(ss, MTSCHEM_FILE_VER_HIGHEST_WRITE); // version
+ writeV3S16(ss, size); // schematic size
+
+ for (int y = 0; y != size.Y; y++) // Y slice probabilities
+ writeU8(ss, slice_probs[y]);
+
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);
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();
v3s16 bp1 = getNodeBlockPos(p1);
v3s16 bp2 = getNodeBlockPos(p2);
vm->initialEmerge(bp1, bp2);
-
+
size = p2 - p1 + 1;
+
+ slice_probs = new u8[size.Y];
+ for (s16 y = 0; y != size.Y; y++)
+ 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++) {
}
-void DecoSchematic::applyProbabilities(std::vector<std::pair<v3s16, u8> > *plist,
- v3s16 p0) {
+void DecoSchematic::applyProbabilities(v3s16 p0,
+ std::vector<std::pair<v3s16, u8> > *plist,
+ std::vector<std::pair<s16, u8> > *splist) {
+
for (size_t i = 0; i != plist->size(); i++) {
v3s16 p = (*plist)[i].first - p0;
int index = p.Z * (size.Y * size.X) + p.Y * size.X + p.X;
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);
}
}
+
+ for (size_t i = 0; i != splist->size(); i++) {
+ s16 y = (*splist)[i].first - p0.Y;
+ slice_probs[y] = (*splist)[i].second;
+ }
}
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)
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)
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++) {
continue;
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
continue;
-
+
heightmap[index] = y;
}
}
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)
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) &&
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);
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) &&