3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 //#include "serverobject.h"
28 #include "content_sao.h"
30 #include "content_mapnode.h" // For content_mapnode_get_new_name
31 #include "voxelalgorithms.h"
33 #include "settings.h" // For g_settings
34 #include "main.h" // For g_profiler
36 #include "mapgen_v6.h"
38 FlagDesc flagdesc_mapgen[] = {
41 {"dungeons", MG_DUNGEONS},
42 {"v6_forests", MGV6_FORESTS},
43 {"v6_biome_blend", MGV6_BIOME_BLEND},
49 ///////////////////////////////////////////////////////////////////////////////
52 void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax) {
53 bool isliquid, wasliquid;
56 for (s16 z = nmin.Z; z <= nmax.Z; z++) {
57 for (s16 x = nmin.X; x <= nmax.X; x++) {
60 v3s16 em = vm->m_area.getExtent();
61 i = vm->m_area.index(v3s16(p2d.X, nmax.Y, p2d.Y));
63 for (s16 y = nmax.Y; y >= nmin.Y; y--) {
64 isliquid = ndef->get(vm->m_data[i]).isLiquid();
66 // there was a change between liquid and nonliquid, add to queue
67 if (isliquid != wasliquid)
68 trans_liquid->push_back(v3s16(p2d.X, y, p2d.Y));
71 vm->m_area.add_y(em, i, -1);
78 void Mapgen::updateLighting(v3s16 nmin, v3s16 nmax) {
79 enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT};
81 VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE,
82 nmax + v3s16(1,0,1) * MAP_BLOCKSIZE);
83 bool block_is_underground = (water_level > nmax.Y);
84 bool sunlight = !block_is_underground;
86 ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
87 for (int i = 0; i < 2; i++) {
88 enum LightBank bank = banks[i];
89 std::set<v3s16> light_sources;
90 std::map<v3s16, u8> unlight_from;
92 voxalgo::clearLightAndCollectSources(*vm, a, bank, ndef,
93 light_sources, unlight_from);
94 voxalgo::propagateSunlight(*vm, a, sunlight, light_sources, ndef);
95 vm->unspreadLight(bank, unlight_from, light_sources, ndef);
96 vm->spreadLight(bank, light_sources, ndef);
101 //////////////////////// Mapgen V6 parameter read/write
103 bool MapgenV6Params::readParams(Settings *settings) {
104 freq_desert = settings->getFloat("mgv6_freq_desert");
105 freq_beach = settings->getFloat("mgv6_freq_beach");
107 np_terrain_base = settings->getNoiseParams("mgv6_np_terrain_base");
108 np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher");
109 np_steepness = settings->getNoiseParams("mgv6_np_steepness");
110 np_height_select = settings->getNoiseParams("mgv6_np_height_select");
111 np_trees = settings->getNoiseParams("mgv6_np_trees");
112 np_mud = settings->getNoiseParams("mgv6_np_mud");
113 np_beach = settings->getNoiseParams("mgv6_np_beach");
114 np_biome = settings->getNoiseParams("mgv6_np_biome");
115 np_cave = settings->getNoiseParams("mgv6_np_cave");
118 np_terrain_base && np_terrain_higher && np_steepness &&
119 np_height_select && np_trees && np_mud &&
120 np_beach && np_biome && np_cave;
125 void MapgenV6Params::writeParams(Settings *settings) {
126 settings->setFloat("mgv6_freq_desert", freq_desert);
127 settings->setFloat("mgv6_freq_beach", freq_beach);
129 settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
130 settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
131 settings->setNoiseParams("mgv6_np_steepness", np_steepness);
132 settings->setNoiseParams("mgv6_np_height_select", np_height_select);
133 settings->setNoiseParams("mgv6_np_trees", np_trees);
134 settings->setNoiseParams("mgv6_np_mud", np_mud);
135 settings->setNoiseParams("mgv6_np_beach", np_beach);
136 settings->setNoiseParams("mgv6_np_biome", np_biome);
137 settings->setNoiseParams("mgv6_np_cave", np_cave);
141 /////////////////////////////////// legacy static functions for farmesh
144 s16 Mapgen::find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision) {
145 //just need to return something
151 bool Mapgen::get_have_beach(u64 seed, v2s16 p2d) {
152 double sandnoise = noise2d_perlin(
153 0.2+(float)p2d.X/250, 0.7+(float)p2d.Y/250,
154 seed+59420, 3, 0.50);
156 return (sandnoise > 0.15);
160 double Mapgen::tree_amount_2d(u64 seed, v2s16 p) {
161 double noise = noise2d_perlin(
162 0.5+(float)p.X/125, 0.5+(float)p.Y/125,
164 double zeroval = -0.39;
168 return 0.04 * (noise-zeroval) / (1.0-zeroval);