void TestVoxelAlgorithms::testClearLightAndCollectSources(INodeDefManager *ndef)
{
	VoxelManipulator v;

	for (u16 z = 0; z < 3; z++)
	for (u16 y = 0; y < 3; y++)
	for (u16 x = 0; x < 3; x++) {
		v3s16 p(x,y,z);
		v.setNode(p, MapNode(CONTENT_AIR));
	}

	VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
	v.setNodeNoRef(v3s16(0,0,0), MapNode(t_CONTENT_STONE));
	v.setNodeNoRef(v3s16(1,1,1), MapNode(t_CONTENT_TORCH));

	{
		MapNode n(CONTENT_AIR);
		n.setLight(LIGHTBANK_DAY, 1, ndef);
		v.setNode(v3s16(1,1,2), n);
	}

	{
		std::set<v3s16> light_sources;
		std::map<v3s16, u8> unlight_from;
		voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
				ndef, light_sources, unlight_from);
		//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
		UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef) == 0);
		UASSERT(light_sources.find(v3s16(1,1,1)) != light_sources.end());
		UASSERT(light_sources.size() == 1);
		UASSERT(unlight_from.find(v3s16(1,1,2)) != unlight_from.end());
		UASSERT(unlight_from.size() == 1);
	}
}
Beispiel #2
0
void MapgenFractal::generateCaves(s16 max_stone_y)
{
	if (max_stone_y < node_min.Y)
		return;

	noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
	noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	v3s16 em = vm->m_area.getExtent();
	u32 index2d = 0;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
		bool column_is_open = false;  // Is column open to overground
		u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
		u32 index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
			(x - node_min.X);
		// Biome of column
		Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);

		for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
				y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
			content_t c = vm->m_data[vi].getContent();
			if (c == CONTENT_AIR || c == biome->c_water_top ||
					c == biome->c_water) {
				column_is_open = true;
				continue;
			}
			// Ground
			float d1 = contour(noise_cave1->result[index3d]);
			float d2 = contour(noise_cave2->result[index3d]);
			if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
				// In tunnel and ground content, excavate
				vm->m_data[vi] = MapNode(CONTENT_AIR);
			} else if (column_is_open &&
					(c == biome->c_filler || c == biome->c_stone)) {
				// Tunnel entrance floor
				vm->m_data[vi] = MapNode(biome->c_top);
				column_is_open = false;
			} else {
				column_is_open = false;
			}
		}
	}

	if (node_max.Y > MGFRACTAL_LARGE_CAVE_DEPTH)
		return;

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = ps.range(0, 2);
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV5 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Beispiel #3
0
void MapgenV7::generateTerrain() {
	MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
	MapNode n_stone(c_stone);

	v3s16 em = vm->m_area.getExtent();
	u32 index = 0;
	
	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
		s16 surface_y = heightmap[index];
		Biome *biome = bmgr->biomes[biomemap[index]];
		
		u32 i = vm->m_area.index(x, node_min.Y, z);
		for (s16 y = node_min.Y; y <= node_max.Y; y++) {
			if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
				if (y <= surface_y) {
					vm->m_data[i] = (y > water_level + biome->filler_height) ?
						MapNode(biome->c_filler) : n_stone;
				} else if (y <= water_level) {
					vm->m_data[i] = n_water_source;
				} else {
					vm->m_data[i] = n_air;
				}
			}
			vm->m_area.add_y(em, i, 1);
		}
	}
}
Beispiel #4
0
void MeshMakeData::fillSingleNode(MapNode *node)
{
	m_blockpos = v3s16(0,0,0);

#if !defined(MESH_ZEROCOPY)
	v3s16 blockpos_nodes = v3s16(0,0,0);
	VoxelArea area(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
			blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1));
	s32 volume = area.getVolume();
	s32 our_node_index = area.index(1,1,1);

	// Allocate this block + neighbors
	m_vmanip.clear();
	m_vmanip.addArea(area);

	// Fill in data
	MapNode *data = reinterpret_cast<MapNode*>( ::operator new(volume * sizeof(MapNode)));
	for(s32 i = 0; i < volume; i++)
	{
		if(i == our_node_index)
		{
			data[i] = *node;
		}
		else
		{
			data[i] = MapNode(CONTENT_AIR, LIGHT_MAX, 0);
		}
	}
	m_vmanip.copyFrom(data, area, area.MinEdge, area.MinEdge, area.getExtent());
	delete[] data;
#endif
}
Beispiel #5
0
void MapgenV7::dustTopNodes()
{
	v3s16 em = vm->m_area.getExtent();
	u32 index = 0;

	if (water_level > node_max.Y)
		return;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
		Biome *biome = (Biome *)bmgr->get(biomemap[index]);

		if (biome->c_dust == CONTENT_IGNORE)
			continue;

		s16 y = node_max.Y;
		u32 vi = vm->m_area.index(x, y, z);
		for (; y >= node_min.Y; y--) {
			if (vm->m_data[vi].getContent() != CONTENT_AIR)
				break;

			vm->m_area.add_y(em, vi, -1);
		}

		content_t c = vm->m_data[vi].getContent();
		if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
			if (y == node_max.Y)
				continue;

			vm->m_area.add_y(em, vi, 1);
			vm->m_data[vi] = MapNode(biome->c_dust);
		}
	}
}
Beispiel #6
0
void Mapgen_features::layers_init(EmergeManager *emerge, const Json::Value & paramsj) {
    const auto & layersj = paramsj["layers"];
    INodeDefManager *ndef = emerge->ndef;
    auto layer_default_thickness = paramsj.get("layer_default_thickness", 1).asInt();
    auto layer_thickness_multiplier = paramsj.get("layer_thickness_multiplier", 1).asInt();
    if (!layersj.empty())
        for (unsigned int i = 0; i < layersj.size(); ++i) {
            if (layersj[i].empty())
                continue;
            const auto & layerj = layersj[i];
            const auto & name = layerj["name"].asString();
            if (name.empty())
                continue;
            auto content = ndef->getId(name);
            if (content == CONTENT_IGNORE)
                continue;

            auto layer = layer_data{ content, MapNode(content, layerj["param1"].asInt(), layerj["param2"].asInt()) };
            layer.height_min = layerj.get("y_min", layerj.get("height_min", -MAX_MAP_GENERATION_LIMIT).asInt()).asInt();
            layer.height_max = layerj.get("y_max", layerj.get("height_max", +MAX_MAP_GENERATION_LIMIT).asInt()).asInt();
            layer.thickness  = layerj.get("thickness", layer_default_thickness).asInt() * layer_thickness_multiplier;

            //layer.name = name; //dev
            layers.emplace_back(layer);
        }
    if (layers.empty())
        infostream << "layers empty, using only default:stone mg_params="<<paramsj<<std::endl;
    else
        verbosestream << "layers size=" << layers.size() << std::endl;
}
Beispiel #7
0
void TestVoxelManipulator::testVoxelManipulator(INodeDefManager *nodedef)
{
	VoxelManipulator v;

	v.print(infostream, nodedef);

	infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl;
	v.setNodeNoRef(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS));

	v.print(infostream, nodedef);
	UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS);

	infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl;

	EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
	v.print(infostream, nodedef);

	infostream << "*** Adding area ***" << std::endl;

	VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
	v.addArea(a);
	v.print(infostream, nodedef);

	UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS);
	EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
}
Beispiel #8
0
void MapgenV7::generateCaves(s16 max_stone_y)
{
	if (max_stone_y >= node_min.Y) {
		u32 index   = 0;

		for (s16 z = node_min.Z; z <= node_max.Z; z++)
		for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
			u32 i = vm->m_area.index(node_min.X, y, z);
			for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) {
				float d1 = contour(noise_cave1->result[index]);
				float d2 = contour(noise_cave2->result[index]);
				if (d1 * d2 > 0.3) {
					content_t c = vm->m_data[i].getContent();
					if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
						continue;

					vm->m_data[i] = MapNode(CONTENT_AIR);
				}
			}
		}
	}

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0;
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV7 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
void TestSchematic::testLuaTableSerialize(INodeDefManager *ndef)
{
	static const v3s16 size(3, 3, 3);
	static const u32 volume = size.X * size.Y * size.Z;

	Schematic schem;

	schem.flags       = 0;
	schem.size        = size;
	schem.schemdata   = new MapNode[volume];
	schem.slice_probs = new u8[size.Y];
	for (size_t i = 0; i != volume; i++)
		schem.schemdata[i] = MapNode(test_schem2_data[i], test_schem2_prob[i], 0);
	for (s16 y = 0; y != size.Y; y++)
		schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;

	std::vector<std::string> names;
	names.push_back("air");
	names.push_back("default:lava_source");
	names.push_back("default:glass");

	std::ostringstream ss(std::ios_base::binary);

	UASSERT(schem.serializeToLua(&ss, names, false, 0));
	UASSERTEQ(std::string, ss.str(), expected_lua_output);
}
Beispiel #10
0
void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p)
{
	ManualMapVoxelManipulator *vm = mg->vm;

	if (!canPlaceDecoration(vm, p))
		return;

	content_t c_place = c_decos[pr->range(0, c_decos.size() - 1)];

	s16 height = (deco_height_max > 0) ?
		pr->range(deco_height, deco_height_max) : deco_height;

	height = MYMIN(height, max_y - p.Y);

	v3s16 em = vm->m_area.getExtent();
	u32 vi = vm->m_area.index(p);
	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);
	}
}
Beispiel #11
0
void MeshMakeData::fillSingleNode(MapNode *node)
{
	m_blockpos = v3s16(0,0,0);
	
	v3s16 blockpos_nodes = v3s16(0,0,0);
	VoxelArea area(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
			blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1));
	s32 volume = area.getVolume();
	s32 our_node_index = area.index(1,1,1);

	// Allocate this block + neighbors
	m_vmanip.clear();
	m_vmanip.addArea(area);

	// Fill in data
	MapNode *data = new MapNode[volume];
	for(s32 i = 0; i < volume; i++)
	{
		if(i == our_node_index)
		{
			data[i] = *node;
		}
		else
		{
			data[i] = MapNode(CONTENT_AIR, LIGHT_MAX, 0);
		}
	}
	m_vmanip.copyFrom(data, area, area.MinEdge, area.MinEdge, area.getExtent());
	delete[] data;
}
void TestSchematic::testFileSerializeDeserialize(INodeDefManager *ndef)
{
	static const v3s16 size(3, 3, 3);
	static const u32 volume = size.X * size.Y * size.Z;
	static const content_t content_map[] = {
		CONTENT_AIR,
		t_CONTENT_STONE,
		t_CONTENT_LAVA,
	};
	static const content_t content_map2[] = {
		CONTENT_AIR,
		t_CONTENT_STONE,
		t_CONTENT_WATER,
	};
	StringMap replace_names;
	replace_names["default:lava"] = "default:water";

	Schematic schem1, schem2;

	//// Construct the schematic to save
	schem1.flags          = 0;
	schem1.size           = size;
	schem1.schemdata      = new MapNode[volume];
	schem1.slice_probs    = new u8[size.Y];
	schem1.slice_probs[0] = 80;
	schem1.slice_probs[1] = 160;
	schem1.slice_probs[2] = 240;

	for (size_t i = 0; i != volume; i++) {
		content_t c = content_map[test_schem2_data[i]];
		schem1.schemdata[i] = MapNode(c, test_schem2_prob[i], 0);
	}

	std::string temp_file = getTestTempFile();
	UASSERT(schem1.saveSchematicToFile(temp_file, ndef));
	UASSERT(schem2.loadSchematicFromFile(temp_file, ndef, &replace_names));

	UASSERT(schem2.size == size);
	UASSERT(schem2.slice_probs[0] == 80);
	UASSERT(schem2.slice_probs[1] == 160);
	UASSERT(schem2.slice_probs[2] == 240);

	for (size_t i = 0; i != volume; i++) {
		content_t c = content_map2[test_schem2_data[i]];
		UASSERT(schem2.schemdata[i] == MapNode(c, test_schem2_prob[i], 0));
	}
}
Beispiel #13
0
int MapgenV5::generateBaseTerrain()
{
    u32 index = 0;
    u32 index2d = 0;
    int stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;

    noise_factor->perlinMap2D(node_min.X, node_min.Z);
    noise_height->perlinMap2D(node_min.X, node_min.Z);
    noise_ground->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

    for (s16 z=node_min.Z; z<=node_max.Z; z++) {
        for (s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) {
            u32 vi = vm->m_area.index(node_min.X, y, z);
            for (s16 x=node_min.X; x<=node_max.X; x++, vi++, index++, index2d++) {
                if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
                    continue;

                float f = 0.55 + noise_factor->result[index2d];
                if (f < 0.01)
                    f = 0.01;
                else if (f >= 1.0)
                    f *= 1.6;
                float h = noise_height->result[index2d];

                if (noise_ground->result[index] * f < y - h) {
                    if (y <= water_level) {
                        vm->m_data[vi] = MapNode(c_water_source);
                        if (liquid_pressure && y <= 0)
                            vm->m_data[vi].addLevel(m_emerge->ndef, water_level - y, 1);
                    }
                    else
                        vm->m_data[vi] = MapNode(CONTENT_AIR);
                } else {
                    vm->m_data[vi] = layers_get(index);
                    if (y > stone_surface_max_y)
                        stone_surface_max_y = y;
                }
            }
            index2d -= ystride;
        }
        index2d += ystride;
    }

    return stone_surface_max_y;
}
Beispiel #14
0
void DungeonGen::makeDoor(v3s16 doorplace, v3s16 doordir)
{
	makeHole(doorplace);

#ifdef DGEN_USE_TORCHES
	// Place torch (for testing)
	vm->m_data[vm->m_area.index(doorplace)] = MapNode(c_torch);
#endif
}
Beispiel #15
0
MapNode Map::getNodeTry(v3POS p) {
#ifndef NDEBUG
	ScopeProfiler sp(g_profiler, "Map: getNodeTry");
#endif
	auto blockpos = getNodeBlockPos(p);
	auto block = getBlockNoCreateNoEx(blockpos, true);
	if(!block)
		return MapNode(CONTENT_IGNORE);
	auto relpos = p - blockpos * MAP_BLOCKSIZE;
	return block->getNodeTry(relpos);
}
Beispiel #16
0
/**
 * Helper function for Client Side Modding
 * Flavour is applied there, this should not be used for core engine
 * @param p
 * @param is_valid_position
 * @return
 */
MapNode Client::getNode(v3s16 p, bool *is_valid_position)
{
	if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOOKUP_NODES)) {
		v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS);
		if ((u32) ppos.getDistanceFrom(p) > m_csm_noderange_limit) {
			*is_valid_position = false;
			return MapNode();
		}
	}
	return m_env.getMap().getNodeNoEx(p, is_valid_position);
}
Beispiel #17
0
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
	if (isValidPosition(p) == false)
		return m_parent->getNodeTry(getPosRelative() + p);

	if (data == NULL) {
		if (is_valid_position)
			*is_valid_position = false;
		return MapNode(CONTENT_IGNORE);
	}
	auto lock = try_lock_shared_rec();
	if (!lock->owns_lock()) {
		if (is_valid_position)
			*is_valid_position = false;
		return MapNode(CONTENT_IGNORE);
	}

	if (is_valid_position)
		*is_valid_position = true;
	return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
}
Beispiel #18
0
MapNode MapBlock::getNodeParentNoEx(v3s16 p)
{
	if(isValidPosition(p) == false)
	{
		try{
			return m_parent->getNode(getPosRelative() + p);
		}
		catch(InvalidPositionException &e)
		{
			return MapNode(CONTENT_IGNORE);
		}
	}
	else
	{
		if(data == NULL)
		{
			return MapNode(CONTENT_IGNORE);
		}
		return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
	}
}
Beispiel #19
0
void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
	ManualMapVoxelManipulator *vm = mg->vm;

	u32 vi = vm->m_area.index(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
			v3s16( 0, 0,  1),
			v3s16( 0, 0, -1),
			v3s16( 1, 0,  0),
			v3s16(-1, 0,  0),
			v3s16( 1, 0,  1),
			v3s16(-1, 0,  1),
			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;

	s16 height = (deco_height_max > 0) ?
		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);
	}
}
Beispiel #20
0
int MapgenV5::generateBaseTerrain()
{
	u32 index = 0;
	u32 index2d = 0;
	int stone_surface_max_y = -MAP_GENERATION_LIMIT;

	for (s16 z=node_min.Z; z<=node_max.Z; z++) {
		for (s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) {
			u32 i = vm->m_area.index(node_min.X, y, z);
			for (s16 x=node_min.X; x<=node_max.X; x++, i++, index++, index2d++) {
				if (vm->m_data[i].getContent() != CONTENT_IGNORE)
					continue;

				float f = 0.55 + noise_factor->result[index2d];
				if (f < 0.01)
					f = 0.01;
				else if (f >= 1.0)
					f *= 1.6;
				float h = noise_height->result[index2d];

				if (noise_ground->result[index] * f < y - h) {
					if (y <= water_level)
						vm->m_data[i] = MapNode(c_water_source);
					else
						vm->m_data[i] = MapNode(CONTENT_AIR);
				} else {
					vm->m_data[i] = MapNode(c_stone);
					if (y > stone_surface_max_y)
						stone_surface_max_y = y;
				}
			}
			index2d -= ystride;
		}
		index2d += ystride;
	}

	return stone_surface_max_y;
}
Beispiel #21
0
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
    if (isValidPosition(p) == false)
        return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);

    if (data == NULL) {
        if (is_valid_position)
            *is_valid_position = false;
        return MapNode(CONTENT_IGNORE);
    }
    if (is_valid_position)
        *is_valid_position = true;
    return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
}
Beispiel #22
0
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
	if (isValidPosition(p) == false)
		return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);

	if (!data) {
		if (is_valid_position)
			*is_valid_position = false;
		return MapNode(CONTENT_IGNORE);
	}
	if (is_valid_position)
		*is_valid_position = true;
	return data[p.Z * zstride + p.Y * ystride + p.X];
}
Beispiel #23
0
void MapgenV7::dustTopNodes()
{
	if (node_max.Y < water_level)
		return;

	v3s16 em = vm->m_area.getExtent();
	u32 index = 0;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
		Biome *biome = (Biome *)bmgr->getRaw(biomemap[index]);

		if (biome->c_dust == CONTENT_IGNORE)
			continue;

		u32 vi = vm->m_area.index(x, full_node_max.Y, z);
		content_t c_full_max = vm->m_data[vi].getContent();
		s16 y_start;

		if (c_full_max == CONTENT_AIR) {
			y_start = full_node_max.Y - 1;
		} else if (c_full_max == CONTENT_IGNORE) {
			vi = vm->m_area.index(x, node_max.Y + 1, z);
			content_t c_max = vm->m_data[vi].getContent();

			if (c_max == CONTENT_AIR)
				y_start = node_max.Y;
			else
				continue;
		} else {
			continue;
		}

		vi = vm->m_area.index(x, y_start, z);
		for (s16 y = y_start; y >= node_min.Y - 1; y--) {
			if (vm->m_data[vi].getContent() != CONTENT_AIR)
				break;

			vm->m_area.add_y(em, vi, -1);
		}

		content_t c = vm->m_data[vi].getContent();
		if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE && c != biome->c_dust) {
			vm->m_area.add_y(em, vi, 1);
			vm->m_data[vi] = MapNode(biome->c_dust);
		}
	}
}
Beispiel #24
0
Mapgen_features::Mapgen_features(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
    noise_layers(nullptr),
    layers_node_size(0),
    noise_float_islands1(nullptr),
    noise_float_islands2(nullptr),
    noise_float_islands3(nullptr),
    noise_cave_indev(nullptr)
{
    y_offset = 0;

    auto ndef = emerge->ndef;
    n_stone = MapNode(ndef->getId("mapgen_stone"));

    //noise_cave_indev = nullptr;
    cave_noise_threshold = 0;
}
Beispiel #25
0
GameMap& GameMap::operator=(const GameMap &gameMap)
{
	this->size = gameMap.getSize();
	this->nodeSet.clear();
	for (int y = 0; y < this->size.height; ++y)
		this->nodeSet.push_back(std::vector<MapNode>(
		this->size.width,
		MapNode()
		));
	for (int y = 0; y < this->size.height; ++y)
		for (int x = 0; x < this->size.width; ++x)
		{
			this->nodeSet[y][x] = gameMap.getMapNodeSet()[y][x];
		}
	return *this;
}
void TestSchematic::testMtsSerializeDeserialize(INodeDefManager *ndef)
{
	static const v3s16 size(7, 6, 4);
	static const u32 volume = size.X * size.Y * size.Z;

	std::stringstream ss(std::ios_base::binary |
		std::ios_base::in | std::ios_base::out);

	std::vector<std::string> names;
	names.push_back("foo");
	names.push_back("bar");
	names.push_back("baz");
	names.push_back("qux");

	Schematic schem, schem2;

	schem.flags       = 0;
	schem.size        = size;
	schem.schemdata   = new MapNode[volume];
	schem.slice_probs = new u8[size.Y];
	for (size_t i = 0; i != volume; i++)
		schem.schemdata[i] = MapNode(test_schem1_data[i], MTSCHEM_PROB_ALWAYS, 0);
	for (s16 y = 0; y != size.Y; y++)
		schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;

	UASSERT(schem.serializeToMts(&ss, names));

	ss.seekg(0);
	names.clear();

	UASSERT(schem2.deserializeFromMts(&ss, &names));

	UASSERTEQ(size_t, names.size(), 4);
	UASSERTEQ(std::string, names[0], "foo");
	UASSERTEQ(std::string, names[1], "bar");
	UASSERTEQ(std::string, names[2], "baz");
	UASSERTEQ(std::string, names[3], "qux");

	UASSERT(schem2.size == size);
	for (size_t i = 0; i != volume; i++)
		UASSERT(schem2.schemdata[i] == schem.schemdata[i]);
	for (s16 y = 0; y != size.Y; y++)
		UASSERTEQ(u8, schem2.slice_probs[y], schem.slice_probs[y]);
}
Beispiel #27
0
void MapgenV5::generateCaves(int max_stone_y)
{
	if (max_stone_y < node_min.Y)
		return;

	noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
	noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	u32 index = 0;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
		u32 vi = vm->m_area.index(node_min.X, y, z);
		for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) {
			// Don't excavate the overgenerated stone at node_max.Y + 1,
			// this creates a 'roof' over the tunnel, preventing light in
			// tunnels at mapchunk borders when generating mapchunks upwards.
			if (y > node_max.Y)
				continue;

			float d1 = contour(noise_cave1->result[index]);
			float d2 = contour(noise_cave2->result[index]);
			if (d1 * d2 > 0.125f) {
				content_t c = vm->m_data[vi].getContent();
				if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
					continue;

				vm->m_data[vi] = MapNode(CONTENT_AIR);
			}
		}
	}

	if (node_max.Y > MGV5_LARGE_CAVE_DEPTH)
		return;

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = ps.range(0, 2);
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV5 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Beispiel #28
0
/* minetest specific types */
MapNode readnode(lua_State *L, int index, INodeDefManager *ndef)
{
	lua_getfield(L, index, "name");
	const char *name = luaL_checkstring(L, -1);
	lua_pop(L, 1);
	u8 param1;
	lua_getfield(L, index, "param1");
	if(lua_isnil(L, -1))
		param1 = 0;
	else
		param1 = lua_tonumber(L, -1);
	lua_pop(L, 1);
	u8 param2;
	lua_getfield(L, index, "param2");
	if(lua_isnil(L, -1))
		param2 = 0;
	else
		param2 = lua_tonumber(L, -1);
	lua_pop(L, 1);
	return MapNode(ndef, name, param1, param2);
}
Beispiel #29
0
void MapgenV7::generateCaves(int max_stone_y)
{
	if (max_stone_y >= node_min.Y) {
		u32 index   = 0;
		u32 index2d = 0;

		for (s16 z = node_min.Z; z <= node_max.Z; z++) {
			for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
				u32 i = vm->m_area.index(node_min.X, y, z);
				for (s16 x = node_min.X; x <= node_max.X;
						x++, i++, index++, index2d++) {
					float d1 = contour(noise_cave1->result[index]);
					float d2 = contour(noise_cave2->result[index]);
					if (d1 * d2 > 0.3) {
						Biome *biome = (Biome *)bmgr->
									getRaw(biomemap[index2d]);
						content_t c = vm->m_data[i].getContent();
						if (!ndef->get(c).is_ground_content ||
								c == CONTENT_AIR ||
								(y <= water_level &&
								c != biome->c_stone &&
								c != c_stone))
							continue;

						vm->m_data[i] = MapNode(CONTENT_AIR);
					}
				}
				index2d -= ystride;
			}
			index2d += ystride;
		}
	}

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0;
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV7 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
MapNode readnode(lua_State *L, int index, INodeDefManager *ndef)
{
	lua_getfield(L, index, "name");
	if (!lua_isstring(L, -1))
		throw LuaError("Node name is not set or is not a string!");
	const char *name = lua_tostring(L, -1);
	lua_pop(L, 1);

	u8 param1 = 0;
	lua_getfield(L, index, "param1");
	if (!lua_isnil(L, -1))
		param1 = lua_tonumber(L, -1);
	lua_pop(L, 1);

	u8 param2 = 0;
	lua_getfield(L, index, "param2");
	if (!lua_isnil(L, -1))
		param2 = lua_tonumber(L, -1);
	lua_pop(L, 1);

	return MapNode(ndef, name, param1, param2);
}