aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapgen')
-rw-r--r--src/mapgen/cavegen.cpp8
-rw-r--r--src/mapgen/cavegen.h8
-rw-r--r--src/mapgen/mapgen.cpp25
-rw-r--r--src/mapgen/mapgen.h23
-rw-r--r--src/mapgen/mapgen_carpathian.cpp3
-rw-r--r--src/mapgen/mapgen_carpathian.h2
-rw-r--r--src/mapgen/mapgen_flat.cpp3
-rw-r--r--src/mapgen/mapgen_flat.h2
-rw-r--r--src/mapgen/mapgen_fractal.cpp3
-rw-r--r--src/mapgen/mapgen_fractal.h2
-rw-r--r--src/mapgen/mapgen_singlenode.cpp2
-rw-r--r--src/mapgen/mapgen_singlenode.h2
-rw-r--r--src/mapgen/mapgen_v5.cpp3
-rw-r--r--src/mapgen/mapgen_v5.h2
-rw-r--r--src/mapgen/mapgen_v6.cpp21
-rw-r--r--src/mapgen/mapgen_v6.h4
-rw-r--r--src/mapgen/mapgen_v7.cpp105
-rw-r--r--src/mapgen/mapgen_v7.h23
-rw-r--r--src/mapgen/mapgen_valleys.cpp2
-rw-r--r--src/mapgen/mapgen_valleys.h2
-rw-r--r--src/mapgen/mg_biome.cpp65
-rw-r--r--src/mapgen/mg_biome.h20
-rw-r--r--src/mapgen/mg_decoration.cpp71
-rw-r--r--src/mapgen/mg_decoration.h18
-rw-r--r--src/mapgen/mg_ore.cpp125
-rw-r--r--src/mapgen/mg_ore.h42
-rw-r--r--src/mapgen/mg_schematic.cpp38
-rw-r--r--src/mapgen/mg_schematic.h11
-rw-r--r--src/mapgen/treegen.cpp51
-rw-r--r--src/mapgen/treegen.h5
30 files changed, 558 insertions, 133 deletions
diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp
index a9df4506f..340079821 100644
--- a/src/mapgen/cavegen.cpp
+++ b/src/mapgen/cavegen.cpp
@@ -1,8 +1,8 @@
/*
Minetest
-Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
-Copyright (C) 2010-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2015-2018 paramat
+Copyright (C) 2010-2020 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2015-2020 paramat
+Copyright (C) 2010-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -69,7 +69,7 @@ CavesNoiseIntersection::~CavesNoiseIntersection()
void CavesNoiseIntersection::generateCaves(MMVManip *vm,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
assert(vm);
assert(biomemap);
diff --git a/src/mapgen/cavegen.h b/src/mapgen/cavegen.h
index ff09f9423..d678d365b 100644
--- a/src/mapgen/cavegen.h
+++ b/src/mapgen/cavegen.h
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2010-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2015-2018 paramat
+Copyright (C) 2015-2020 paramat
+Copyright (C) 2010-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
+typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
+
class GenerateNotifier;
/*
@@ -44,7 +46,7 @@ public:
NoiseParams *np_cave2, s32 seed, float cave_width);
~CavesNoiseIntersection();
- void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, biome_t *biomemap);
private:
const NodeDefManager *m_ndef;
diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp
index 79c429ff6..f57529082 100644
--- a/src/mapgen/mapgen.cpp
+++ b/src/mapgen/mapgen.cpp
@@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "emerge.h"
#include "voxelalgorithms.h"
@@ -107,8 +106,8 @@ STATIC_ASSERT(
//// Mapgen
////
-Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
- gennotify(emerge->gen_notify_on, &emerge->gen_notify_on_deco_ids)
+Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge) :
+ gennotify(emerge->gen_notify_on, emerge->gen_notify_on_deco_ids)
{
id = mapgenid;
water_level = params->water_level;
@@ -157,7 +156,7 @@ const char *Mapgen::getMapgenName(MapgenType mgtype)
Mapgen *Mapgen::createMapgen(MapgenType mgtype, MapgenParams *params,
- EmergeManager *emerge)
+ EmergeParams *emerge)
{
switch (mgtype) {
case MAPGEN_CARPATHIAN:
@@ -586,7 +585,7 @@ void Mapgen::spreadLight(const v3s16 &nmin, const v3s16 &nmax)
//// MapgenBasic
////
-MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge)
+MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge)
: Mapgen(mapgenid, params, emerge)
{
this->m_emerge = emerge;
@@ -629,6 +628,13 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emer
// Lava falls back to water as both are suitable as cave liquids.
if (c_lava_source == CONTENT_IGNORE)
c_lava_source = c_water_source;
+
+ if (c_stone == CONTENT_IGNORE)
+ errorstream << "Mapgen: Mapgen alias 'mapgen_stone' is invalid!" << std::endl;
+ if (c_water_source == CONTENT_IGNORE)
+ errorstream << "Mapgen: Mapgen alias 'mapgen_water_source' is invalid!" << std::endl;
+ if (c_river_water_source == CONTENT_IGNORE)
+ warningstream << "Mapgen: Mapgen alias 'mapgen_river_water_source' is invalid!" << std::endl;
}
@@ -636,6 +642,8 @@ MapgenBasic::~MapgenBasic()
{
delete biomegen;
delete []heightmap;
+
+ delete m_emerge; // destroying EmergeParams is our responsibility
}
@@ -968,7 +976,7 @@ void MapgenBasic::generateDungeons(s16 max_stone_y)
////
GenerateNotifier::GenerateNotifier(u32 notify_on,
- std::set<u32> *notify_on_deco_ids)
+ const std::set<u32> *notify_on_deco_ids)
{
m_notify_on = notify_on;
m_notify_on_deco_ids = notify_on_deco_ids;
@@ -981,7 +989,8 @@ void GenerateNotifier::setNotifyOn(u32 notify_on)
}
-void GenerateNotifier::setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids)
+void GenerateNotifier::setNotifyOnDecoIds(
+ const std::set<u32> *notify_on_deco_ids)
{
m_notify_on_deco_ids = notify_on_deco_ids;
}
@@ -993,7 +1002,7 @@ bool GenerateNotifier::addEvent(GenNotifyType type, v3s16 pos, u32 id)
return false;
if (type == GENNOTIFY_DECORATION &&
- m_notify_on_deco_ids->find(id) == m_notify_on_deco_ids->end())
+ m_notify_on_deco_ids->find(id) == m_notify_on_deco_ids->cend())
return false;
GenNotifyEvent gne;
diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h
index dc325c791..a92b3b0d0 100644
--- a/src/mapgen/mapgen.h
+++ b/src/mapgen/mapgen.h
@@ -1,8 +1,8 @@
/*
Minetest
-Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
-Copyright (C) 2013-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2015-2018 paramat
+Copyright (C) 2010-2020 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2015-2020 paramat
+Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MG_DECORATIONS 0x20
#define MG_BIOMES 0x40
-typedef u8 biome_t; // copy from mg_biome.h to avoid an unnecessary include
+typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
class Settings;
class MMVManip;
@@ -51,6 +51,7 @@ class Biome;
class BiomeGen;
struct BiomeParams;
class BiomeManager;
+class EmergeParams;
class EmergeManager;
class MapBlock;
class VoxelManipulator;
@@ -87,10 +88,10 @@ struct GenNotifyEvent {
class GenerateNotifier {
public:
GenerateNotifier() = default;
- GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
+ GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids);
void setNotifyOn(u32 notify_on);
- void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
+ void setNotifyOnDecoIds(const std::set<u32> *notify_on_deco_ids);
bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
void getEvents(std::map<std::string, std::vector<v3s16> > &event_map);
@@ -98,7 +99,7 @@ public:
private:
u32 m_notify_on = 0;
- std::set<u32> *m_notify_on_deco_ids;
+ const std::set<u32> *m_notify_on_deco_ids;
std::list<GenNotifyEvent> m_notify_events;
};
@@ -176,7 +177,7 @@ public:
GenerateNotifier gennotify;
Mapgen() = default;
- Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
+ Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge);
virtual ~Mapgen() = default;
DISABLE_CLASS_COPY(Mapgen);
@@ -215,7 +216,7 @@ public:
static MapgenType getMapgenType(const std::string &mgname);
static const char *getMapgenName(MapgenType mgtype);
static Mapgen *createMapgen(MapgenType mgtype, MapgenParams *params,
- EmergeManager *emerge);
+ EmergeParams *emerge);
static MapgenParams *createMapgenParams(MapgenType mgtype);
static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
static void setDefaultSettings(Settings *settings);
@@ -243,7 +244,7 @@ private:
*/
class MapgenBasic : public Mapgen {
public:
- MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
+ MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge);
virtual ~MapgenBasic();
virtual void generateBiomes();
@@ -254,7 +255,7 @@ public:
virtual void generateDungeons(s16 max_stone_y);
protected:
- EmergeManager *m_emerge;
+ EmergeParams *m_emerge;
BiomeManager *m_bmgr;
Noise *noise_filler_depth;
diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp
index 0dc1d33be..feb9b428c 100644
--- a/src/mapgen/mapgen_carpathian.cpp
+++ b/src/mapgen/mapgen_carpathian.cpp
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -50,7 +49,7 @@ FlagDesc flagdesc_mapgen_carpathian[] = {
///////////////////////////////////////////////////////////////////////////////
-MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager *emerge)
+MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_CARPATHIAN, params, emerge)
{
base_level = params->base_level;
diff --git a/src/mapgen/mapgen_carpathian.h b/src/mapgen/mapgen_carpathian.h
index acd379958..31b2b91d8 100644
--- a/src/mapgen/mapgen_carpathian.h
+++ b/src/mapgen/mapgen_carpathian.h
@@ -79,7 +79,7 @@ struct MapgenCarpathianParams : public MapgenParams
class MapgenCarpathian : public MapgenBasic
{
public:
- MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager *emerge);
+ MapgenCarpathian(MapgenCarpathianParams *params, EmergeParams *emerge);
~MapgenCarpathian();
virtual MapgenType getType() const { return MAPGEN_CARPATHIAN; }
diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp
index 879435948..369777ad2 100644
--- a/src/mapgen/mapgen_flat.cpp
+++ b/src/mapgen/mapgen_flat.cpp
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -48,7 +47,7 @@ FlagDesc flagdesc_mapgen_flat[] = {
///////////////////////////////////////////////////////////////////////////////////////
-MapgenFlat::MapgenFlat(MapgenFlatParams *params, EmergeManager *emerge)
+MapgenFlat::MapgenFlat(MapgenFlatParams *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_FLAT, params, emerge)
{
spflags = params->spflags;
diff --git a/src/mapgen/mapgen_flat.h b/src/mapgen/mapgen_flat.h
index c314c7605..4902a802c 100644
--- a/src/mapgen/mapgen_flat.h
+++ b/src/mapgen/mapgen_flat.h
@@ -64,7 +64,7 @@ struct MapgenFlatParams : public MapgenParams
class MapgenFlat : public MapgenBasic
{
public:
- MapgenFlat(MapgenFlatParams *params, EmergeManager *emerge);
+ MapgenFlat(MapgenFlatParams *params, EmergeParams *emerge);
~MapgenFlat();
virtual MapgenType getType() const { return MAPGEN_FLAT; }
diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp
index 96febb4f4..cb55bc288 100644
--- a/src/mapgen/mapgen_fractal.cpp
+++ b/src/mapgen/mapgen_fractal.cpp
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -48,7 +47,7 @@ FlagDesc flagdesc_mapgen_fractal[] = {
///////////////////////////////////////////////////////////////////////////////////////
-MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge)
+MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_FRACTAL, params, emerge)
{
spflags = params->spflags;
diff --git a/src/mapgen/mapgen_fractal.h b/src/mapgen/mapgen_fractal.h
index 971dfd822..23af925bc 100644
--- a/src/mapgen/mapgen_fractal.h
+++ b/src/mapgen/mapgen_fractal.h
@@ -72,7 +72,7 @@ struct MapgenFractalParams : public MapgenParams
class MapgenFractal : public MapgenBasic
{
public:
- MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge);
+ MapgenFractal(MapgenFractalParams *params, EmergeParams *emerge);
~MapgenFractal();
virtual MapgenType getType() const { return MAPGEN_FRACTAL; }
diff --git a/src/mapgen/mapgen_singlenode.cpp b/src/mapgen/mapgen_singlenode.cpp
index b64524e1c..cade9e7a8 100644
--- a/src/mapgen/mapgen_singlenode.cpp
+++ b/src/mapgen/mapgen_singlenode.cpp
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "emerge.h"
-MapgenSinglenode::MapgenSinglenode(MapgenParams *params, EmergeManager *emerge)
+MapgenSinglenode::MapgenSinglenode(MapgenParams *params, EmergeParams *emerge)
: Mapgen(MAPGEN_SINGLENODE, params, emerge)
{
const NodeDefManager *ndef = emerge->ndef;
diff --git a/src/mapgen/mapgen_singlenode.h b/src/mapgen/mapgen_singlenode.h
index c21089eda..e056d9ab1 100644
--- a/src/mapgen/mapgen_singlenode.h
+++ b/src/mapgen/mapgen_singlenode.h
@@ -38,7 +38,7 @@ public:
content_t c_node;
u8 set_light;
- MapgenSinglenode(MapgenParams *params, EmergeManager *emerge);
+ MapgenSinglenode(MapgenParams *params, EmergeParams *emerge);
~MapgenSinglenode() = default;
virtual MapgenType getType() const { return MAPGEN_SINGLENODE; }
diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp
index 447fe8c50..124667e5d 100644
--- a/src/mapgen/mapgen_v5.cpp
+++ b/src/mapgen/mapgen_v5.cpp
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -45,7 +44,7 @@ FlagDesc flagdesc_mapgen_v5[] = {
};
-MapgenV5::MapgenV5(MapgenV5Params *params, EmergeManager *emerge)
+MapgenV5::MapgenV5(MapgenV5Params *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_V5, params, emerge)
{
spflags = params->spflags;
diff --git a/src/mapgen/mapgen_v5.h b/src/mapgen/mapgen_v5.h
index 17bc466f0..cf4ee4899 100644
--- a/src/mapgen/mapgen_v5.h
+++ b/src/mapgen/mapgen_v5.h
@@ -64,7 +64,7 @@ struct MapgenV5Params : public MapgenParams
class MapgenV5 : public MapgenBasic
{
public:
- MapgenV5(MapgenV5Params *params, EmergeManager *emerge);
+ MapgenV5(MapgenV5Params *params, EmergeParams *emerge);
~MapgenV5();
virtual MapgenType getType() const { return MAPGEN_V5; }
diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp
index 653adc8ec..e9692246c 100644
--- a/src/mapgen/mapgen_v6.cpp
+++ b/src/mapgen/mapgen_v6.cpp
@@ -27,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-//#include "serverobject.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -56,7 +54,7 @@ FlagDesc flagdesc_mapgen_v6[] = {
/////////////////////////////////////////////////////////////////////////////
-MapgenV6::MapgenV6(MapgenV6Params *params, EmergeManager *emerge)
+MapgenV6::MapgenV6(MapgenV6Params *params, EmergeParams *emerge)
: Mapgen(MAPGEN_V6, params, emerge)
{
m_emerge = emerge;
@@ -132,6 +130,21 @@ MapgenV6::MapgenV6(MapgenV6Params *params, EmergeManager *emerge)
c_stair_cobble = c_cobble;
if (c_stair_desert_stone == CONTENT_IGNORE)
c_stair_desert_stone = c_desert_stone;
+
+ if (c_stone == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_stone' is invalid!" << std::endl;
+ if (c_dirt == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_dirt' is invalid!" << std::endl;
+ if (c_dirt_with_grass == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_dirt_with_grass' is invalid!" << std::endl;
+ if (c_sand == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_sand' is invalid!" << std::endl;
+ if (c_water_source == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_water_source' is invalid!" << std::endl;
+ if (c_lava_source == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_lava_source' is invalid!" << std::endl;
+ if (c_cobble == CONTENT_IGNORE)
+ errorstream << "Mapgen v6: Mapgen alias 'mapgen_cobble' is invalid!" << std::endl;
}
@@ -147,6 +160,8 @@ MapgenV6::~MapgenV6()
delete noise_humidity;
delete[] heightmap;
+
+ delete m_emerge; // our responsibility
}
diff --git a/src/mapgen/mapgen_v6.h b/src/mapgen/mapgen_v6.h
index d8cdcb26f..ff565edec 100644
--- a/src/mapgen/mapgen_v6.h
+++ b/src/mapgen/mapgen_v6.h
@@ -83,7 +83,7 @@ struct MapgenV6Params : public MapgenParams {
class MapgenV6 : public Mapgen {
public:
- EmergeManager *m_emerge;
+ EmergeParams *m_emerge;
int ystride;
u32 spflags;
@@ -133,7 +133,7 @@ public:
content_t c_stair_cobble;
content_t c_stair_desert_stone;
- MapgenV6(MapgenV6Params *params, EmergeManager *emerge);
+ MapgenV6(MapgenV6Params *params, EmergeParams *emerge);
~MapgenV6();
virtual MapgenType getType() const { return MAPGEN_V6; }
diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp
index 325c4957a..e93dc9140 100644
--- a/src/mapgen/mapgen_v7.cpp
+++ b/src/mapgen/mapgen_v7.cpp
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2013-2019 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2014-2019 paramat
+Copyright (C) 2014-2020 paramat
+Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
-#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
@@ -52,11 +51,17 @@ FlagDesc flagdesc_mapgen_v7[] = {
////////////////////////////////////////////////////////////////////////////////
-MapgenV7::MapgenV7(MapgenV7Params *params, EmergeManager *emerge)
+MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_V7, params, emerge)
{
spflags = params->spflags;
mount_zero_level = params->mount_zero_level;
+ floatland_ymin = params->floatland_ymin;
+ floatland_ymax = params->floatland_ymax;
+ floatland_taper = params->floatland_taper;
+ float_taper_exp = params->float_taper_exp;
+ floatland_density = params->floatland_density;
+ floatland_ywater = params->floatland_ywater;
cave_width = params->cave_width;
large_cave_depth = params->large_cave_depth;
@@ -71,6 +76,9 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeManager *emerge)
dungeon_ymin = params->dungeon_ymin;
dungeon_ymax = params->dungeon_ymax;
+ // Allocate floatland noise offset cache
+ this->float_offset_cache = new float[csize.Y + 2];
+
// 2D noise
noise_terrain_base =
new Noise(&params->np_terrain_base, seed, csize.X, csize.Z);
@@ -101,6 +109,12 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeManager *emerge)
new Noise(&params->np_ridge, seed, csize.X, csize.Y + 2, csize.Z);
}
+ if (spflags & MGV7_FLOATLANDS) {
+ // 3D noise, 1 up, 1 down overgeneration
+ noise_floatland =
+ new Noise(&params->np_floatland, seed, csize.X, csize.Y + 2, csize.Z);
+ }
+
// 3D noise, 1 down overgeneration
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
@@ -127,6 +141,12 @@ MapgenV7::~MapgenV7()
delete noise_ridge_uwater;
delete noise_ridge;
}
+
+ if (spflags & MGV7_FLOATLANDS) {
+ delete noise_floatland;
+ }
+
+ delete []float_offset_cache;
}
@@ -140,6 +160,7 @@ MapgenV7Params::MapgenV7Params():
np_ridge_uwater (0.0, 1.0, v3f(1000, 1000, 1000), 85039, 5, 0.6, 2.0),
np_mountain (-0.6, 1.0, v3f(250, 350, 250), 5333, 5, 0.63, 2.0),
np_ridge (0.0, 1.0, v3f(100, 100, 100), 6467, 4, 0.75, 2.0),
+ np_floatland (0.0, 0.7, v3f(384, 96, 384), 1009, 4, 0.75, 1.618),
np_cavern (0.0, 1.0, v3f(384, 128, 384), 723, 5, 0.63, 2.0),
np_cave1 (0.0, 12.0, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0.0, 12.0, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
@@ -152,6 +173,13 @@ void MapgenV7Params::readParams(const Settings *settings)
{
settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
settings->getS16NoEx("mgv7_mount_zero_level", mount_zero_level);
+ settings->getS16NoEx("mgv7_floatland_ymin", floatland_ymin);
+ settings->getS16NoEx("mgv7_floatland_ymax", floatland_ymax);
+ settings->getS16NoEx("mgv7_floatland_taper", floatland_taper);
+ settings->getFloatNoEx("mgv7_float_taper_exp", float_taper_exp);
+ settings->getFloatNoEx("mgv7_floatland_density", floatland_density);
+ settings->getS16NoEx("mgv7_floatland_ywater", floatland_ywater);
+
settings->getFloatNoEx("mgv7_cave_width", cave_width);
settings->getS16NoEx("mgv7_large_cave_depth", large_cave_depth);
settings->getU16NoEx("mgv7_small_cave_num_min", small_cave_num_min);
@@ -174,6 +202,7 @@ void MapgenV7Params::readParams(const Settings *settings)
settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
settings->getNoiseParams("mgv7_np_mountain", np_mountain);
settings->getNoiseParams("mgv7_np_ridge", np_ridge);
+ settings->getNoiseParams("mgv7_np_floatland", np_floatland);
settings->getNoiseParams("mgv7_np_cavern", np_cavern);
settings->getNoiseParams("mgv7_np_cave1", np_cave1);
settings->getNoiseParams("mgv7_np_cave2", np_cave2);
@@ -185,6 +214,13 @@ void MapgenV7Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7);
settings->setS16("mgv7_mount_zero_level", mount_zero_level);
+ settings->setS16("mgv7_floatland_ymin", floatland_ymin);
+ settings->setS16("mgv7_floatland_ymax", floatland_ymax);
+ settings->setS16("mgv7_floatland_taper", floatland_taper);
+ settings->setFloat("mgv7_float_taper_exp", float_taper_exp);
+ settings->setFloat("mgv7_floatland_density", floatland_density);
+ settings->setS16("mgv7_floatland_ywater", floatland_ywater);
+
settings->setFloat("mgv7_cave_width", cave_width);
settings->setS16("mgv7_large_cave_depth", large_cave_depth);
settings->setU16("mgv7_small_cave_num_min", small_cave_num_min);
@@ -207,6 +243,7 @@ void MapgenV7Params::writeParams(Settings *settings) const
settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
settings->setNoiseParams("mgv7_np_mountain", np_mountain);
settings->setNoiseParams("mgv7_np_ridge", np_ridge);
+ settings->setNoiseParams("mgv7_np_floatland", np_floatland);
settings->setNoiseParams("mgv7_np_cavern", np_cavern);
settings->setNoiseParams("mgv7_np_cave1", np_cave1);
settings->setNoiseParams("mgv7_np_cave2", np_cave2);
@@ -358,8 +395,9 @@ void MapgenV7::makeChunk(BlockMakeData *data)
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
// Calculate lighting
- // TODO disable in and just below floatlands
- bool propagate_shadow = true;
+ // Limit floatland shadows
+ bool propagate_shadow = !((spflags & MGV7_FLOATLANDS) &&
+ node_max.Y >= floatland_ymin - csize.Y * 2 && node_min.Y <= floatland_ymax);
if (flags & MG_LIGHT)
calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
@@ -428,6 +466,12 @@ bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y)
}
+bool MapgenV7::getFloatlandTerrainFromMap(int idx_xyz, float float_offset)
+{
+ return noise_floatland->result[idx_xyz] + floatland_density - float_offset >= 0.0f;
+}
+
+
int MapgenV7::generateTerrain()
{
MapNode n_air(CONTENT_AIR);
@@ -447,6 +491,35 @@ int MapgenV7::generateTerrain()
noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
}
+ //// Floatlands
+ // 'Generate floatlands in this mapchunk' bool for
+ // simplification of condition checks in y-loop.
+ bool gen_floatlands = false;
+ u8 cache_index = 0;
+ // Y values where floatland tapering starts
+ s16 float_taper_ymax = floatland_ymax - floatland_taper;
+ s16 float_taper_ymin = floatland_ymin + floatland_taper;
+
+ if ((spflags & MGV7_FLOATLANDS) &&
+ node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax) {
+ gen_floatlands = true;
+ // Calculate noise for floatland generation
+ noise_floatland->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+
+ // Cache floatland noise offset values, for floatland tapering
+ for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) {
+ float float_offset = 0.0f;
+ if (y > float_taper_ymax) {
+ float_offset = std::pow((y - float_taper_ymax) / (float)floatland_taper,
+ float_taper_exp) * 4.0f;
+ } else if (y < float_taper_ymin) {
+ float_offset = std::pow((float_taper_ymin - y) / (float)floatland_taper,
+ float_taper_exp) * 4.0f;
+ }
+ float_offset_cache[cache_index] = float_offset;
+ }
+ }
+
//// Place nodes
const v3s16 &em = vm->m_area.getExtent();
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
@@ -458,13 +531,15 @@ int MapgenV7::generateTerrain()
if (surface_y > stone_surface_max_y)
stone_surface_max_y = surface_y;
+ cache_index = 0;
u32 vi = vm->m_area.index(x, node_min.Y - 1, z);
u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X);
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1;
y++,
index3d += ystride,
- VoxelArea::add_y(em, vi, 1)) {
+ VoxelArea::add_y(em, vi, 1),
+ cache_index++) {
if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
continue;
@@ -475,10 +550,18 @@ int MapgenV7::generateTerrain()
vm->m_data[vi] = n_stone; // Mountain terrain
if (y > stone_surface_max_y)
stone_surface_max_y = y;
- } else if (y <= water_level) {
+ } else if (gen_floatlands &&
+ getFloatlandTerrainFromMap(index3d,
+ float_offset_cache[cache_index])) {
+ vm->m_data[vi] = n_stone; // Floatland terrain
+ if (y > stone_surface_max_y)
+ stone_surface_max_y = y;
+ } else if (y <= water_level) { // Surface water
vm->m_data[vi] = n_water;
+ } else if (gen_floatlands && y >= float_taper_ymax && y <= floatland_ywater) {
+ vm->m_data[vi] = n_water; // Water for solid floatland layer only
} else {
- vm->m_data[vi] = n_air;
+ vm->m_data[vi] = n_air; // Air
}
}
}
@@ -489,8 +572,8 @@ int MapgenV7::generateTerrain()
void MapgenV7::generateRidgeTerrain()
{
- // TODO disable river canyons in floatlands
- if (node_max.Y < water_level - 16)
+ if (node_max.Y < water_level - 16 ||
+ (node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax))
return;
noise_ridge->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h
index 0605c5c97..4020cd935 100644
--- a/src/mapgen/mapgen_v7.h
+++ b/src/mapgen/mapgen_v7.h
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2013-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2014-2018 paramat
+Copyright (C) 2014-2020 paramat
+Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -36,6 +36,12 @@ extern FlagDesc flagdesc_mapgen_v7[];
struct MapgenV7Params : public MapgenParams {
s16 mount_zero_level = 0;
+ s16 floatland_ymin = 1024;
+ s16 floatland_ymax = 4096;
+ s16 floatland_taper = 256;
+ float float_taper_exp = 2.0f;
+ float floatland_density = -0.6f;
+ s16 floatland_ywater = -31000;
float cave_width = 0.09f;
s16 large_cave_depth = -33;
@@ -59,6 +65,7 @@ struct MapgenV7Params : public MapgenParams {
NoiseParams np_ridge_uwater;
NoiseParams np_mountain;
NoiseParams np_ridge;
+ NoiseParams np_floatland;
NoiseParams np_cavern;
NoiseParams np_cave1;
NoiseParams np_cave2;
@@ -75,7 +82,7 @@ struct MapgenV7Params : public MapgenParams {
class MapgenV7 : public MapgenBasic {
public:
- MapgenV7(MapgenV7Params *params, EmergeManager *emerge);
+ MapgenV7(MapgenV7Params *params, EmergeParams *emerge);
~MapgenV7();
virtual MapgenType getType() const { return MAPGEN_V7; }
@@ -87,12 +94,21 @@ public:
float baseTerrainLevelFromMap(int index);
bool getMountainTerrainAtPoint(s16 x, s16 y, s16 z);
bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y);
+ bool getFloatlandTerrainFromMap(int idx_xyz, float float_offset);
int generateTerrain();
void generateRidgeTerrain();
private:
s16 mount_zero_level;
+ s16 floatland_ymin;
+ s16 floatland_ymax;
+ s16 floatland_taper;
+ float float_taper_exp;
+ float floatland_density;
+ s16 floatland_ywater;
+
+ float *float_offset_cache = nullptr;
Noise *noise_terrain_base;
Noise *noise_terrain_alt;
@@ -102,4 +118,5 @@ private:
Noise *noise_ridge_uwater;
Noise *noise_mountain;
Noise *noise_ridge;
+ Noise *noise_floatland;
};
diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp
index ff908b7bb..efcc8ee85 100644
--- a/src/mapgen/mapgen_valleys.cpp
+++ b/src/mapgen/mapgen_valleys.cpp
@@ -54,7 +54,7 @@ FlagDesc flagdesc_mapgen_valleys[] = {
};
-MapgenValleys::MapgenValleys(MapgenValleysParams *params, EmergeManager *emerge)
+MapgenValleys::MapgenValleys(MapgenValleysParams *params, EmergeParams *emerge)
: MapgenBasic(MAPGEN_VALLEYS, params, emerge)
{
// NOTE: MapgenValleys has a hard dependency on BiomeGenOriginal
diff --git a/src/mapgen/mapgen_valleys.h b/src/mapgen/mapgen_valleys.h
index 1aec68842..34a923dfa 100644
--- a/src/mapgen/mapgen_valleys.h
+++ b/src/mapgen/mapgen_valleys.h
@@ -84,7 +84,7 @@ class MapgenValleys : public MapgenBasic {
public:
MapgenValleys(MapgenValleysParams *params,
- EmergeManager *emerge);
+ EmergeParams *emerge);
~MapgenValleys();
virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp
index 345bc8c6a..610c38594 100644
--- a/src/mapgen/mg_biome.cpp
+++ b/src/mapgen/mg_biome.cpp
@@ -78,7 +78,7 @@ void BiomeManager::clear()
EmergeManager *emerge = m_server->getEmergeManager();
// Remove all dangling references in Decorations
- DecorationManager *decomgr = emerge->decomgr;
+ DecorationManager *decomgr = emerge->getWritableDecorationManager();
for (size_t i = 0; i != decomgr->getNumObjects(); i++) {
Decoration *deco = (Decoration *)decomgr->getRaw(i);
deco->biomes.clear();
@@ -92,9 +92,19 @@ void BiomeManager::clear()
}
+BiomeManager *BiomeManager::clone() const
+{
+ auto mgr = new BiomeManager();
+ assert(mgr);
+ ObjDefManager::cloneTo(mgr);
+ mgr->m_server = m_server;
+ return mgr;
+}
+
+
// For BiomeGen type 'BiomeGenOriginal'
float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
- NoiseParams &np_heat_blend, u64 seed)
+ NoiseParams &np_heat_blend, u64 seed) const
{
return
NoisePerlin2D(&np_heat, pos.X, pos.Z, seed) +
@@ -104,7 +114,7 @@ float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
// For BiomeGen type 'BiomeGenOriginal'
float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
- NoiseParams &np_humidity_blend, u64 seed)
+ NoiseParams &np_humidity_blend, u64 seed) const
{
return
NoisePerlin2D(&np_humidity, pos.X, pos.Z, seed) +
@@ -113,7 +123,8 @@ float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity
// For BiomeGen type 'BiomeGenOriginal'
-Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos)
+const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat,
+ float humidity, v3s16 pos) const
{
Biome *biome_closest = nullptr;
Biome *biome_closest_blend = nullptr;
@@ -143,9 +154,11 @@ Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16
}
}
- mysrand(pos.Y + (heat + humidity) * 0.9f);
+ const u64 seed = pos.Y + (heat + humidity) * 0.9f;
+ PcgRandom rng(seed);
+
if (biome_closest_blend && dist_min_blend <= dist_min &&
- myrand_range(0, biome_closest_blend->vertical_blend) >=
+ rng.range(0, biome_closest_blend->vertical_blend) >=
pos.Y - biome_closest_blend->max_pos.Y)
return biome_closest_blend;
@@ -308,10 +321,11 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
// Carefully tune pseudorandom seed variation to avoid single node dither
// and create larger scale blending patterns similar to horizontal biome
// blend.
- mysrand(pos.Y + (heat + humidity) * 0.9f);
+ const u64 seed = pos.Y + (heat + humidity) * 0.9f;
+ PcgRandom rng(seed);
if (biome_closest_blend && dist_min_blend <= dist_min &&
- myrand_range(0, biome_closest_blend->vertical_blend) >=
+ rng.range(0, biome_closest_blend->vertical_blend) >=
pos.Y - biome_closest_blend->max_pos.Y)
return biome_closest_blend;
@@ -321,6 +335,41 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
////////////////////////////////////////////////////////////////////////////////
+ObjDef *Biome::clone() const
+{
+ auto obj = new Biome();
+ ObjDef::cloneTo(obj);
+ NodeResolver::cloneTo(obj);
+
+ obj->flags = flags;
+
+ obj->c_top = c_top;
+ obj->c_filler = c_filler;
+ obj->c_stone = c_stone;
+ obj->c_water_top = c_water_top;
+ obj->c_water = c_water;
+ obj->c_river_water = c_river_water;
+ obj->c_riverbed = c_riverbed;
+ obj->c_dust = c_dust;
+ obj->c_cave_liquid = c_cave_liquid;
+ obj->c_dungeon = c_dungeon;
+ obj->c_dungeon_alt = c_dungeon_alt;
+ obj->c_dungeon_stair = c_dungeon_stair;
+
+ obj->depth_top = depth_top;
+ obj->depth_filler = depth_filler;
+ obj->depth_water_top = depth_water_top;
+ obj->depth_riverbed = depth_riverbed;
+
+ obj->min_pos = min_pos;
+ obj->max_pos = max_pos;
+ obj->heat_point = heat_point;
+ obj->humidity_point = humidity_point;
+ obj->vertical_blend = vertical_blend;
+
+ return obj;
+}
+
void Biome::resolveNodeNames()
{
getIdFromNrBacklog(&c_top, "mapgen_stone", CONTENT_AIR, false);
diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h
index ee148adbc..be4cfea4d 100644
--- a/src/mapgen/mg_biome.h
+++ b/src/mapgen/mg_biome.h
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2014-2018 paramat
+Copyright (C) 2014-2020 paramat
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -32,7 +32,7 @@ class BiomeManager;
//// Biome
////
-typedef u8 biome_t;
+typedef u16 biome_t;
#define BIOME_NONE ((biome_t)0)
@@ -42,6 +42,8 @@ enum BiomeType {
class Biome : public ObjDef, public NodeResolver {
public:
+ ObjDef *clone() const;
+
u32 flags;
content_t c_top;
@@ -88,6 +90,7 @@ struct BiomeParams {
s32 seed;
};
+// WARNING: this class is not thread-safe
class BiomeGen {
public:
virtual ~BiomeGen() = default;
@@ -191,6 +194,8 @@ public:
BiomeManager(Server *server);
virtual ~BiomeManager() = default;
+ BiomeManager *clone() const;
+
const char *getObjectTitle() const
{
return "biome";
@@ -226,12 +231,15 @@ public:
// For BiomeGen type 'BiomeGenOriginal'
float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
- NoiseParams &np_heat_blend, u64 seed);
+ NoiseParams &np_heat_blend, u64 seed) const;
float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
- NoiseParams &np_humidity_blend, u64 seed);
- Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos);
+ NoiseParams &np_humidity_blend, u64 seed) const;
+ const Biome *getBiomeFromNoiseOriginal(float heat, float humidity,
+ v3s16 pos) const;
private:
+ BiomeManager() {};
+
Server *m_server;
};
diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp
index 28dde0209..a4cada396 100644
--- a/src/mapgen/mg_decoration.cpp
+++ b/src/mapgen/mg_decoration.cpp
@@ -67,6 +67,13 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed,
return nplaced;
}
+DecorationManager *DecorationManager::clone() const
+{
+ auto mgr = new DecorationManager();
+ ObjDefManager::cloneTo(mgr);
+ return mgr;
+}
+
///////////////////////////////////////////////////////////////////////////////
@@ -199,8 +206,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
// All-surfaces decorations
// Check biome of column
if (mg->biomemap && !biomes.empty()) {
- std::unordered_set<u8>::const_iterator iter =
- biomes.find(mg->biomemap[mapindex]);
+ auto iter = biomes.find(mg->biomemap[mapindex]);
if (iter == biomes.end())
continue;
}
@@ -252,8 +258,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
continue;
if (mg->biomemap && !biomes.empty()) {
- std::unordered_set<u8>::const_iterator iter =
- biomes.find(mg->biomemap[mapindex]);
+ auto iter = biomes.find(mg->biomemap[mapindex]);
if (iter == biomes.end())
continue;
}
@@ -269,9 +274,42 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
}
+void Decoration::cloneTo(Decoration *def) const
+{
+ ObjDef::cloneTo(def);
+ def->flags = flags;
+ def->mapseed = mapseed;
+ def->c_place_on = c_place_on;
+ def->sidelen = sidelen;
+ def->y_min = y_min;
+ def->y_max = y_max;
+ def->fill_ratio = fill_ratio;
+ def->np = np;
+ def->c_spawnby = c_spawnby;
+ def->nspawnby = nspawnby;
+ def->place_offset_y = place_offset_y;
+ def->biomes = biomes;
+}
+
+
///////////////////////////////////////////////////////////////////////////////
+ObjDef *DecoSimple::clone() const
+{
+ auto def = new DecoSimple();
+ Decoration::cloneTo(def);
+
+ def->c_decos = c_decos;
+ def->deco_height = deco_height;
+ def->deco_height_max = deco_height_max;
+ def->deco_param2 = deco_param2;
+ def->deco_param2_max = deco_param2_max;
+
+ return def;
+}
+
+
void DecoSimple::resolveNodeNames()
{
Decoration::resolveNodeNames();
@@ -351,6 +389,31 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
///////////////////////////////////////////////////////////////////////////////
+DecoSchematic::~DecoSchematic()
+{
+ if (was_cloned)
+ delete schematic;
+}
+
+
+ObjDef *DecoSchematic::clone() const
+{
+ auto def = new DecoSchematic();
+ Decoration::cloneTo(def);
+ NodeResolver::cloneTo(def);
+
+ def->rotation = rotation;
+ /* FIXME: We do not own this schematic, yet we only have a pointer to it
+ * and not a handle. We are left with no option but to clone it ourselves.
+ * This is a waste of memory and should be replaced with an alternative
+ * approach sometime. */
+ def->schematic = dynamic_cast<Schematic*>(schematic->clone());
+ def->was_cloned = true;
+
+ return def;
+}
+
+
size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
{
// Schematic could have been unloaded but not the decoration
diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h
index 03fec04fd..1ea02a527 100644
--- a/src/mapgen/mg_decoration.h
+++ b/src/mapgen/mg_decoration.h
@@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "noise.h"
#include "nodedef.h"
+typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
+
class Mapgen;
class MMVManip;
class PcgRandom;
@@ -72,12 +74,17 @@ public:
s16 nspawnby;
s16 place_offset_y = 0;
- std::unordered_set<u8> biomes;
+ std::unordered_set<biome_t> biomes;
+
+protected:
+ void cloneTo(Decoration *def) const;
};
class DecoSimple : public Decoration {
public:
+ ObjDef *clone() const;
+
virtual void resolveNodeNames();
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
@@ -91,12 +98,16 @@ public:
class DecoSchematic : public Decoration {
public:
+ ObjDef *clone() const;
+
DecoSchematic() = default;
+ virtual ~DecoSchematic();
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
Rotation rotation;
Schematic *schematic = nullptr;
+ bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
};
@@ -113,6 +124,8 @@ public:
DecorationManager(IGameDef *gamedef);
virtual ~DecorationManager() = default;
+ DecorationManager *clone() const;
+
const char *getObjectTitle() const
{
return "decoration";
@@ -133,4 +146,7 @@ public:
}
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+
+private:
+ DecorationManager() {};
};
diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp
index c36249cb9..b50ed6a32 100644
--- a/src/mapgen/mg_ore.cpp
+++ b/src/mapgen/mg_ore.cpp
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2015-2018 paramat
+Copyright (C) 2015-2020 paramat
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -72,6 +72,14 @@ void OreManager::clear()
}
+OreManager *OreManager::clone() const
+{
+ auto mgr = new OreManager();
+ ObjDefManager::cloneTo(mgr);
+ return mgr;
+}
+
+
///////////////////////////////////////////////////////////////////////////////
@@ -106,11 +114,39 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
}
+void Ore::cloneTo(Ore *def) const
+{
+ ObjDef::cloneTo(def);
+ NodeResolver::cloneTo(def);
+ def->c_ore = c_ore;
+ def->c_wherein = c_wherein;
+ def->clust_scarcity = clust_scarcity;
+ def->clust_num_ores = clust_num_ores;
+ def->clust_size = clust_size;
+ def->y_min = y_min;
+ def->y_max = y_max;
+ def->ore_param2 = ore_param2;
+ def->flags = flags;
+ def->nthresh = nthresh;
+ def->np = np;
+ def->noise = nullptr; // cannot be shared! so created on demand
+ def->biomes = biomes;
+}
+
+
///////////////////////////////////////////////////////////////////////////////
+ObjDef *OreScatter::clone() const
+{
+ auto def = new OreScatter();
+ Ore::cloneTo(def);
+ return def;
+}
+
+
void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -134,7 +170,7 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
if (biomemap && !biomes.empty()) {
u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
+ auto it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
@@ -158,8 +194,21 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
///////////////////////////////////////////////////////////////////////////////
+ObjDef *OreSheet::clone() const
+{
+ auto def = new OreSheet();
+ Ore::cloneTo(def);
+
+ def->column_height_max = column_height_max;
+ def->column_height_min = column_height_min;
+ def->column_midpoint_factor = column_midpoint_factor;
+
+ return def;
+}
+
+
void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -188,7 +237,7 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
continue;
if (biomemap && !biomes.empty()) {
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
+ auto it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
@@ -221,8 +270,22 @@ OrePuff::~OrePuff()
}
+ObjDef *OrePuff::clone() const
+{
+ auto def = new OrePuff();
+ Ore::cloneTo(def);
+
+ def->np_puff_top = np_puff_top;
+ def->np_puff_bottom = np_puff_bottom;
+ def->noise_puff_top = nullptr; // cannot be shared, on-demand
+ def->noise_puff_bottom = nullptr;
+
+ return def;
+}
+
+
void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -249,7 +312,7 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
continue;
if (biomemap && !biomes.empty()) {
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
+ auto it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
@@ -294,8 +357,16 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
///////////////////////////////////////////////////////////////////////////////
+ObjDef *OreBlob::clone() const
+{
+ auto def = new OreBlob();
+ Ore::cloneTo(def);
+ return def;
+}
+
+
void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed + 2404);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -317,7 +388,7 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
+ auto it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}
@@ -366,8 +437,21 @@ OreVein::~OreVein()
}
+ObjDef *OreVein::clone() const
+{
+ auto def = new OreVein();
+ Ore::cloneTo(def);
+
+ def->random_factor = random_factor;
+ def->noise2 = nullptr; // cannot be shared, on-demand
+ def->sizey_prev = sizey_prev;
+
+ return def;
+}
+
+
void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed + 520);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -401,7 +485,7 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
+ auto it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}
@@ -434,8 +518,21 @@ OreStratum::~OreStratum()
}
+ObjDef *OreStratum::clone() const
+{
+ auto def = new OreStratum();
+ Ore::cloneTo(def);
+
+ def->np_stratum_thickness = np_stratum_thickness;
+ def->noise_stratum_thickness = nullptr; // cannot be shared, on-demand
+ def->stratum_thickness = stratum_thickness;
+
+ return def;
+}
+
+
void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap)
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap)
{
PcgRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2);
@@ -463,7 +560,7 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
for (int z = nmin.Z; z <= nmax.Z; z++)
for (int x = nmin.X; x <= nmax.X; x++, index++) {
if (biomemap && !biomes.empty()) {
- std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
+ auto it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h
index d89360c3c..76420fab4 100644
--- a/src/mapgen/mg_ore.h
+++ b/src/mapgen/mg_ore.h
@@ -1,7 +1,7 @@
/*
Minetest
-Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2015-2018 paramat
+Copyright (C) 2015-2020 paramat
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "noise.h"
#include "nodedef.h"
+typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
+
class Noise;
class Mapgen;
class MMVManip;
@@ -64,7 +66,7 @@ public:
float nthresh; // threshold for noise at which an ore is placed
NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering)
Noise *noise = nullptr;
- std::unordered_set<u8> biomes;
+ std::unordered_set<biome_t> biomes;
Ore() = default;;
virtual ~Ore();
@@ -73,33 +75,42 @@ public:
size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap) = 0;
+
+protected:
+ void cloneTo(Ore *def) const;
};
class OreScatter : public Ore {
public:
static const bool NEEDS_NOISE = false;
+ ObjDef *clone() const;
+
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OreSheet : public Ore {
public:
static const bool NEEDS_NOISE = true;
+ ObjDef *clone() const;
+
u16 column_height_min;
u16 column_height_max;
float column_midpoint_factor;
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OrePuff : public Ore {
public:
static const bool NEEDS_NOISE = true;
+ ObjDef *clone() const;
+
NoiseParams np_puff_top;
NoiseParams np_puff_bottom;
Noise *noise_puff_top = nullptr;
@@ -109,21 +120,25 @@ public:
virtual ~OrePuff();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OreBlob : public Ore {
public:
static const bool NEEDS_NOISE = true;
+ ObjDef *clone() const;
+
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OreVein : public Ore {
public:
static const bool NEEDS_NOISE = true;
+ ObjDef *clone() const;
+
float random_factor;
Noise *noise2 = nullptr;
int sizey_prev = 0;
@@ -132,13 +147,15 @@ public:
virtual ~OreVein();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OreStratum : public Ore {
public:
static const bool NEEDS_NOISE = false;
+ ObjDef *clone() const;
+
NoiseParams np_stratum_thickness;
Noise *noise_stratum_thickness = nullptr;
u16 stratum_thickness;
@@ -147,7 +164,7 @@ public:
virtual ~OreStratum();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
- v3s16 nmin, v3s16 nmax, u8 *biomemap);
+ v3s16 nmin, v3s16 nmax, biome_t *biomemap);
};
class OreManager : public ObjDefManager {
@@ -155,6 +172,8 @@ public:
OreManager(IGameDef *gamedef);
virtual ~OreManager() = default;
+ OreManager *clone() const;
+
const char *getObjectTitle() const
{
return "ore";
@@ -183,4 +202,7 @@ public:
void clear();
size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+
+private:
+ OreManager() {};
};
diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp
index c1acbfd9d..ba102d997 100644
--- a/src/mapgen/mg_schematic.cpp
+++ b/src/mapgen/mg_schematic.cpp
@@ -43,12 +43,21 @@ SchematicManager::SchematicManager(Server *server) :
}
+SchematicManager *SchematicManager::clone() const
+{
+ auto mgr = new SchematicManager();
+ assert(mgr);
+ ObjDefManager::cloneTo(mgr);
+ return mgr;
+}
+
+
void SchematicManager::clear()
{
EmergeManager *emerge = m_server->getEmergeManager();
// Remove all dangling references in Decorations
- DecorationManager *decomgr = emerge->decomgr;
+ DecorationManager *decomgr = emerge->getWritableDecorationManager();
for (size_t i = 0; i != decomgr->getNumObjects(); i++) {
Decoration *deco = (Decoration *)decomgr->getRaw(i);
@@ -77,6 +86,25 @@ Schematic::~Schematic()
delete []slice_probs;
}
+ObjDef *Schematic::clone() const
+{
+ auto def = new Schematic();
+ ObjDef::cloneTo(def);
+ NodeResolver::cloneTo(def);
+
+ def->c_nodes = c_nodes;
+ def->flags = flags;
+ def->size = size;
+ FATAL_ERROR_IF(!schemdata, "Schematic can only be cloned after loading");
+ u32 nodecount = size.X * size.Y * size.Z;
+ def->schemdata = new MapNode[nodecount];
+ memcpy(def->schemdata, schemdata, sizeof(MapNode) * nodecount);
+ def->slice_probs = new u8[size.Y];
+ memcpy(def->slice_probs, slice_probs, sizeof(u8) * size.Y);
+
+ return def;
+}
+
void Schematic::resolveNodeNames()
{
@@ -93,6 +121,7 @@ void Schematic::resolveNodeNames()
void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place)
{
+ assert(schemdata && slice_probs);
sanity_check(m_ndef != NULL);
int xstride = 1;
@@ -177,7 +206,7 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags,
Rotation rot, bool force_place)
{
assert(vm != NULL);
- assert(schemdata != NULL);
+ assert(schemdata && slice_probs);
sanity_check(m_ndef != NULL);
//// Determine effective rotation and effective schematic dimensions
@@ -330,7 +359,7 @@ bool Schematic::deserializeFromMts(std::istream *is,
bool Schematic::serializeToMts(std::ostream *os,
- const std::vector<std::string> &names)
+ const std::vector<std::string> &names) const
{
std::ostream &ss = *os;
@@ -354,7 +383,8 @@ bool Schematic::serializeToMts(std::ostream *os,
bool Schematic::serializeToLua(std::ostream *os,
- const std::vector<std::string> &names, bool use_comments, u32 indent_spaces)
+ const std::vector<std::string> &names, bool use_comments,
+ u32 indent_spaces) const
{
std::ostream &ss = *os;
diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h
index 371b37557..6b31251b6 100644
--- a/src/mapgen/mg_schematic.h
+++ b/src/mapgen/mg_schematic.h
@@ -95,6 +95,8 @@ public:
Schematic();
virtual ~Schematic();
+ ObjDef *clone() const;
+
virtual void resolveNodeNames();
bool loadSchematicFromFile(const std::string &filename,
@@ -104,9 +106,10 @@ public:
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
- bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
+ bool serializeToMts(std::ostream *os,
+ const std::vector<std::string> &names) const;
bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
- bool use_comments, u32 indent_spaces);
+ bool use_comments, u32 indent_spaces) const;
void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
@@ -128,6 +131,8 @@ public:
SchematicManager(Server *server);
virtual ~SchematicManager() = default;
+ SchematicManager *clone() const;
+
virtual void clear();
const char *getObjectTitle() const
@@ -141,6 +146,8 @@ public:
}
private:
+ SchematicManager() {};
+
Server *m_server;
};
diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp
index 0d8af2851..e7e30c880 100644
--- a/src/mapgen/treegen.cpp
+++ b/src/mapgen/treegen.cpp
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"
#include "map.h"
#include "mapblock.h"
-#include "serverenvironment.h"
#include "nodedef.h"
#include "treegen.h"
#include "voxelalgorithms.h"
@@ -44,6 +43,12 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
MapNode treenode(ndef->getId("mapgen_tree"));
MapNode leavesnode(ndef->getId("mapgen_leaves"));
MapNode applenode(ndef->getId("mapgen_apple"));
+ if (treenode == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_tree' is invalid!" << std::endl;
+ if (leavesnode == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_leaves' is invalid!" << std::endl;
+ if (applenode == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_apple' is invalid!" << std::endl;
PseudoRandom pr(seed);
s16 trunk_h = pr.range(4, 5);
@@ -114,10 +119,9 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
// L-System tree LUA spawner
-treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
+treegen::error spawn_ltree(ServerMap *map, v3s16 p0,
const NodeDefManager *ndef, const TreeDef &tree_definition)
{
- ServerMap *map = &env->getServerMap();
std::map<v3s16, MapBlock*> modified_blocks;
MMVManip vmanip(map);
v3s16 tree_blockp = getNodeBlockPos(p0);
@@ -144,7 +148,6 @@ treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
const NodeDefManager *ndef, TreeDef tree_definition)
{
- MapNode dirtnode(ndef->getId("mapgen_dirt"));
s32 seed;
if (tree_definition.explicit_seed)
seed = tree_definition.seed + 14002;
@@ -222,43 +225,43 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
axiom = temp;
}
- //make sure tree is not floating in the air
+ // Add trunk nodes below a wide trunk to avoid gaps when tree is on sloping ground
if (tree_definition.trunk_type == "double") {
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X + 1, position.Y - 1, position.Z),
- dirtnode
+ tree_definition
);
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X, position.Y - 1, position.Z + 1),
- dirtnode
+ tree_definition
);
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X + 1, position.Y - 1, position.Z + 1),
- dirtnode
+ tree_definition
);
} else if (tree_definition.trunk_type == "crossed") {
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X + 1, position.Y - 1, position.Z),
- dirtnode
+ tree_definition
);
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X - 1, position.Y - 1, position.Z),
- dirtnode
+ tree_definition
);
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X, position.Y - 1, position.Z + 1),
- dirtnode
+ tree_definition
);
- tree_node_placement(
+ tree_trunk_placement(
vmanip,
v3f(position.X, position.Y - 1, position.Z - 1),
- dirtnode
+ tree_definition
);
}
@@ -365,7 +368,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
!tree_definition.thin_branches)) {
tree_trunk_placement(
vmanip,
- v3f(position.X +1 , position.Y, position.Z),
+ v3f(position.X + 1, position.Y, position.Z),
tree_definition
);
tree_trunk_placement(
@@ -662,6 +665,10 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
c_tree = ndef->getId("mapgen_tree");
if (c_leaves == CONTENT_IGNORE)
c_leaves = ndef->getId("mapgen_leaves");
+ if (c_tree == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_jungletree' is invalid!" << std::endl;
+ if (c_leaves == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_jungleleaves' is invalid!" << std::endl;
MapNode treenode(c_tree);
MapNode leavesnode(c_leaves);
@@ -765,6 +772,10 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
c_leaves = ndef->getId("mapgen_leaves");
if (c_snow == CONTENT_IGNORE)
c_snow = CONTENT_AIR;
+ if (c_tree == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_pine_tree' is invalid!" << std::endl;
+ if (c_leaves == CONTENT_IGNORE)
+ errorstream << "Treegen: Mapgen alias 'mapgen_pine_needles' is invalid!" << std::endl;
MapNode treenode(c_tree);
MapNode leavesnode(c_leaves);
diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h
index 5ab79f428..447baabb3 100644
--- a/src/mapgen/treegen.h
+++ b/src/mapgen/treegen.h
@@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class MMVManip;
class NodeDefManager;
-class ServerEnvironment;
-
+class ServerMap;
namespace treegen {
@@ -73,7 +72,7 @@ namespace treegen {
treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
const NodeDefManager *ndef, TreeDef tree_definition);
// Spawn L-systems tree from LUA
- treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0,
+ treegen::error spawn_ltree (ServerMap *map, v3s16 p0,
const NodeDefManager *ndef, const TreeDef &tree_definition);
// L-System tree gen helper functions