X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmapgen.cpp;h=36d19bfa74f96f6f09fc0960ac7f9028d973ea10;hb=65c09a96f41705bb8e75fc5ff4276342be91ed11;hp=1843e953da70f1e3e878f4360fec5995f19d986a;hpb=ec796b8e814864b433aea75119c307f44b2b33e8;p=minetest.git diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 1843e953d..36d19bfa7 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_sao.h" #include "nodedef.h" #include "emerge.h" -#include "content_mapnode.h" // For content_mapnode_get_new_name #include "voxelalgorithms.h" #include "porting.h" #include "profiler.h" @@ -42,11 +41,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" FlagDesc flagdesc_mapgen[] = { - {"trees", MG_TREES}, - {"caves", MG_CAVES}, - {"dungeons", MG_DUNGEONS}, - {"flat", MG_FLAT}, - {"light", MG_LIGHT}, + {"trees", MG_TREES}, + {"caves", MG_CAVES}, + {"dungeons", MG_DUNGEONS}, + {"flat", MG_FLAT}, + {"light", MG_LIGHT}, + {"decorations", MG_DECORATIONS}, {NULL, 0} }; @@ -62,8 +62,9 @@ FlagDesc flagdesc_gennotify[] = { }; -/////////////////////////////////////////////////////////////////////////////// - +//// +//// Mapgen +//// Mapgen::Mapgen() { @@ -161,6 +162,26 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) } +// Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first +s16 Mapgen::findLiquidSurface(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) + return -MAX_MAP_GENERATION_LIMIT; + else if (ndef->get(n).isLiquid()) + break; + + vm->m_area.add_y(em, i, -1); + } + return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT; +} + + void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) { if (!heightmap) @@ -243,37 +264,20 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light) } -void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax) +void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, + bool propagate_shadow) { ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); //TimeTaker t("updateLighting"); - propagateSunlight(nmin, nmax); + propagateSunlight(nmin, nmax, propagate_shadow); spreadLight(full_nmin, full_nmax); //printf("updateLighting: %dms\n", t.stop()); } - -void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) -{ - ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); - //TimeTaker t("updateLighting"); - - propagateSunlight( - nmin - v3s16(1, 1, 1) * MAP_BLOCKSIZE, - nmax + v3s16(1, 0, 1) * MAP_BLOCKSIZE); - - spreadLight( - nmin - v3s16(1, 1, 1) * MAP_BLOCKSIZE, - nmax + v3s16(1, 1, 1) * MAP_BLOCKSIZE); - - //printf("updateLighting: %dms\n", t.stop()); -} - - -void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax) +void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow) { //TimeTaker t("propagateSunlight"); VoxelArea a(nmin, nmax); @@ -287,7 +291,8 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax) if (vm->m_data[i].getContent() == CONTENT_IGNORE) { if (block_is_underground) continue; - } else if ((vm->m_data[i].param1 & 0x0F) != LIGHT_SUN) { + } else if ((vm->m_data[i].param1 & 0x0F) != LIGHT_SUN && + propagate_shadow) { continue; } vm->m_area.add_y(em, i, -1); @@ -305,7 +310,6 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax) } - void Mapgen::spreadLight(v3s16 nmin, v3s16 nmax) { //TimeTaker t("spreadLight"); @@ -341,32 +345,9 @@ void Mapgen::spreadLight(v3s16 nmin, v3s16 nmax) } - -void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) -{ - enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT}; - VoxelArea a(nmin, nmax); - bool block_is_underground = (water_level > nmax.Y); - bool sunlight = !block_is_underground; - - ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); - - for (int i = 0; i < 2; i++) { - enum LightBank bank = banks[i]; - std::set light_sources; - std::map unlight_from; - - voxalgo::clearLightAndCollectSources(*vm, a, bank, ndef, - light_sources, unlight_from); - voxalgo::propagateSunlight(*vm, a, sunlight, light_sources, ndef); - - vm->unspreadLight(bank, unlight_from, light_sources, ndef); - vm->spreadLight(bank, light_sources, ndef); - } -} - - -/////////////////////////////////////////////////////////////////////////////// +//// +//// GenerateNotifier +//// GenerateNotifier::GenerateNotifier() { @@ -432,7 +413,10 @@ void GenerateNotifier::getEvents( m_notify_events.clear(); } -/////////////////////////////////////////////////////////////////////////////// + +//// +//// MapgenParams +//// void MapgenParams::load(const Settings &settings) { @@ -454,9 +438,11 @@ void MapgenParams::load(const Settings &settings) settings.getNoiseParams("mg_biome_np_humidity_blend", np_biome_humidity_blend); delete sparams; - sparams = EmergeManager::createMapgenParams(mg_name); - if (sparams) + MapgenFactory *mgfactory = EmergeManager::getMapgenFactory(mg_name); + if (mgfactory) { + sparams = mgfactory->createMapgenParams(); sparams->readParams(&settings); + } } @@ -466,7 +452,7 @@ void MapgenParams::save(Settings &settings) const settings.setU64("seed", seed); settings.setS16("water_level", water_level); settings.setS16("chunksize", chunksize); - settings.setFlagStr("mg_flags", flags, flagdesc_mapgen, (u32)-1); + settings.setFlagStr("mg_flags", flags, flagdesc_mapgen, U32_MAX); settings.setNoiseParams("mg_biome_np_heat", np_biome_heat); settings.setNoiseParams("mg_biome_np_heat_blend", np_biome_heat_blend); settings.setNoiseParams("mg_biome_np_humidity", np_biome_humidity);