#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"
#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}
};
};
-///////////////////////////////////////////////////////////////////////////////
-
+////
+//// Mapgen
+////
Mapgen::Mapgen()
{
}
+// 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)
}
-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);
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);
}
-
void Mapgen::spreadLight(v3s16 nmin, v3s16 nmax)
{
//TimeTaker t("spreadLight");
}
-
-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<v3s16> light_sources;
- std::map<v3s16, u8> 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()
{
m_notify_events.clear();
}
-///////////////////////////////////////////////////////////////////////////////
+
+////
+//// MapgenParams
+////
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);
+ }
}
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);