Skip to content
Permalink
Browse files

Allow ObjDefManager instances to be cloned

  • Loading branch information
sfan5 authored and nerzhul committed May 5, 2020
1 parent d1c6cc7 commit 2062c80e21b657fed8e68aa48523fa12ad5ef095
@@ -92,6 +92,16 @@ 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)
@@ -321,6 +331,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);
@@ -42,6 +42,8 @@ enum BiomeType {

class Biome : public ObjDef, public NodeResolver {
public:
ObjDef *clone() const;

u32 flags;

content_t c_top;
@@ -191,6 +193,8 @@ class BiomeManager : public ObjDefManager {
BiomeManager(Server *server);
virtual ~BiomeManager() = default;

BiomeManager *clone() const;

const char *getObjectTitle() const
{
return "biome";
@@ -232,6 +236,8 @@ class BiomeManager : public ObjDefManager {
Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos);

private:
BiomeManager() {};

Server *m_server;

};
@@ -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;
}


///////////////////////////////////////////////////////////////////////////////

@@ -269,9 +276,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 +391,21 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
///////////////////////////////////////////////////////////////////////////////


ObjDef *DecoSchematic::clone() const
{
auto def = new DecoSchematic();
Decoration::cloneTo(def);
NodeResolver::cloneTo(def);

def->rotation = rotation;
/* FIXME: This is not ideal, we only have a pointer to the schematic despite
* not owning it. Optimally this would be a handle. */
def->schematic = schematic; // not cloned

return def;
}


size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
{
// Schematic could have been unloaded but not the decoration
@@ -73,11 +73,16 @@ class Decoration : public ObjDef, public NodeResolver {
s16 place_offset_y = 0;

std::unordered_set<u8> 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,6 +96,8 @@ class DecoSimple : public Decoration {

class DecoSchematic : public Decoration {
public:
ObjDef *clone() const;

DecoSchematic() = default;

virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
@@ -113,6 +120,8 @@ class DecorationManager : public ObjDefManager {
DecorationManager(IGameDef *gamedef);
virtual ~DecorationManager() = default;

DecorationManager *clone() const;

const char *getObjectTitle() const
{
return "decoration";
@@ -133,4 +142,7 @@ class DecorationManager : public ObjDefManager {
}

size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);

private:
DecorationManager() {};
};
@@ -72,6 +72,14 @@ void OreManager::clear()
}


OreManager *OreManager::clone() const
{
auto mgr = new OreManager();
ObjDefManager::cloneTo(mgr);
return mgr;
}


///////////////////////////////////////////////////////////////////////////////


@@ -106,9 +114,37 @@ 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)
{
@@ -158,6 +194,19 @@ 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)
{
@@ -221,6 +270,20 @@ 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)
{
@@ -294,6 +357,14 @@ 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)
{
@@ -366,6 +437,19 @@ 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)
{
@@ -434,6 +518,19 @@ 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)
{

0 comments on commit 2062c80

Please sign in to comment.
You can’t perform that action at this time.