Add minetest.clear_registered_decorations() and clear_registered_ores()

master
kwolekr 2014-12-12 14:07:49 -05:00
parent cec141adc1
commit cf8213ea82
12 changed files with 97 additions and 11 deletions

View File

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h" #include "mapgen.h"
#include "voxel.h" #include "voxel.h"
#include "noise.h" #include "noise.h"
#include "gamedef.h"
#include "mg_biome.h" #include "mg_biome.h"
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
@ -381,6 +382,12 @@ void GenerateNotifier::getEvents(
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
GenElementManager::GenElementManager(IGameDef *gamedef)
{
m_resolver = gamedef->getNodeDefManager()->getResolver();
}
GenElementManager::~GenElementManager() GenElementManager::~GenElementManager()
{ {
for (size_t i = 0; i != m_elements.size(); i++) for (size_t i = 0; i != m_elements.size(); i++)

View File

@ -178,7 +178,7 @@ public:
static const char *ELEMENT_TITLE; static const char *ELEMENT_TITLE;
static const size_t ELEMENT_LIMIT = -1; static const size_t ELEMENT_LIMIT = -1;
GenElementManager() {} GenElementManager(IGameDef *gamedef);
virtual ~GenElementManager(); virtual ~GenElementManager();
virtual GenElement *create(int type) = 0; virtual GenElement *create(int type) = 0;
@ -192,6 +192,7 @@ public:
virtual GenElement *getByName(const std::string &name); virtual GenElement *getByName(const std::string &name);
protected: protected:
NodeResolver *m_resolver;
std::vector<GenElement *> m_elements; std::vector<GenElement *> m_elements;
}; };

View File

@ -32,10 +32,9 @@ const char *BiomeManager::ELEMENT_TITLE = "biome";
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
BiomeManager::BiomeManager(IGameDef *gamedef) BiomeManager::BiomeManager(IGameDef *gamedef) :
GenElementManager(gamedef)
{ {
m_resolver = gamedef->getNodeDefManager()->getResolver();
// Create default biome to be used in case none exist // Create default biome to be used in case none exist
Biome *b = new Biome; Biome *b = new Biome;

View File

@ -71,9 +71,6 @@ public:
void calcBiomes(s16 sx, s16 sy, float *heat_map, float *humidity_map, void calcBiomes(s16 sx, s16 sy, float *heat_map, float *humidity_map,
s16 *height_map, u8 *biomeid_map); s16 *height_map, u8 *biomeid_map);
Biome *getBiome(float heat, float humidity, s16 y); Biome *getBiome(float heat, float humidity, s16 y);
private:
NodeResolver *m_resolver;
}; };
#endif #endif

View File

@ -38,6 +38,12 @@ FlagDesc flagdesc_deco[] = {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
DecorationManager::DecorationManager(IGameDef *gamedef) :
GenElementManager(gamedef)
{
}
size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax) size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
{ {
size_t nplaced = 0; size_t nplaced = 0;
@ -55,6 +61,19 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16
} }
void DecorationManager::clear()
{
for (size_t i = 0; i < m_elements.size(); i++) {
Decoration *deco = (Decoration *)m_elements[i];
if (!deco)
continue;
deco->dropResolverEntries(m_resolver);
}
m_elements.clear();
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -291,6 +310,13 @@ int DecoSimple::getHeight()
} }
void DecoSimple::dropResolverEntries(NodeResolver *resolver)
{
resolver->cancelNodeList(&c_decos);
resolver->cancelNodeList(&c_spawnby);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -81,6 +81,7 @@ public:
virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0; virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
virtual int getHeight() = 0; virtual int getHeight() = 0;
virtual void dropResolverEntries(NodeResolver *resolver) {}
}; };
class DecoSimple : public Decoration { class DecoSimple : public Decoration {
@ -96,6 +97,7 @@ public:
bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p); bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p); virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
virtual int getHeight(); virtual int getHeight();
virtual void dropResolverEntries(NodeResolver *resolver);
}; };
class DecoSchematic : public Decoration { class DecoSchematic : public Decoration {
@ -123,7 +125,7 @@ public:
static const char *ELEMENT_TITLE; static const char *ELEMENT_TITLE;
static const size_t ELEMENT_LIMIT = 0x10000; static const size_t ELEMENT_LIMIT = 0x10000;
DecorationManager(IGameDef *gamedef) {} DecorationManager(IGameDef *gamedef);
~DecorationManager() {} ~DecorationManager() {}
Decoration *create(int type) Decoration *create(int type)
@ -140,6 +142,8 @@ public:
} }
} }
void clear();
size_t placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax); size_t placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
}; };

View File

@ -37,6 +37,12 @@ FlagDesc flagdesc_ore[] = {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
OreManager::OreManager(IGameDef *gamedef) :
GenElementManager(gamedef)
{
}
size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax) size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
{ {
size_t nplaced = 0; size_t nplaced = 0;
@ -54,6 +60,20 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
} }
void OreManager::clear()
{
for (size_t i = 0; i < m_elements.size(); i++) {
Ore *ore = (Ore *)m_elements[i];
if (!ore)
continue;
m_resolver->cancelNodeList(&ore->c_wherein);
m_resolver->cancelNode(&ore->c_ore);
}
m_elements.clear();
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -169,4 +189,3 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
} }
} }
} }

View File

@ -99,7 +99,7 @@ public:
static const char *ELEMENT_TITLE; static const char *ELEMENT_TITLE;
static const size_t ELEMENT_LIMIT = 0x10000; static const size_t ELEMENT_LIMIT = 0x10000;
OreManager(IGameDef *gamedef) {} OreManager(IGameDef *gamedef);
~OreManager() {} ~OreManager() {}
Ore *create(int type) Ore *create(int type)
@ -116,6 +116,8 @@ public:
} }
} }
void clear();
size_t placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax); size_t placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
}; };

View File

@ -30,6 +30,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
const char *SchematicManager::ELEMENT_TITLE = "schematic"; const char *SchematicManager::ELEMENT_TITLE = "schematic";
///////////////////////////////////////////////////////////////////////////////
SchematicManager::SchematicManager(IGameDef *gamedef) :
GenElementManager(gamedef)
{
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -76,7 +76,7 @@ public:
static const char *ELEMENT_TITLE; static const char *ELEMENT_TITLE;
static const size_t ELEMENT_LIMIT = 0x10000; static const size_t ELEMENT_LIMIT = 0x10000;
SchematicManager(IGameDef *gamedef) {} SchematicManager(IGameDef *gamedef);
~SchematicManager() {} ~SchematicManager() {}
Schematic *create(int type) Schematic *create(int type)

View File

@ -464,6 +464,20 @@ int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
return 0; return 0;
} }
int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
{
DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr;
dmgr->clear();
return 0;
}
int ModApiMapgen::l_clear_registered_ores(lua_State *L)
{
OreManager *omgr = getServer(L)->getEmergeManager()->oremgr;
omgr->clear();
return 0;
}
// register_decoration({lots of stuff}) // register_decoration({lots of stuff})
int ModApiMapgen::l_register_decoration(lua_State *L) int ModApiMapgen::l_register_decoration(lua_State *L)
{ {
@ -789,7 +803,10 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
API_FCT(register_biome); API_FCT(register_biome);
API_FCT(register_decoration); API_FCT(register_decoration);
API_FCT(register_ore); API_FCT(register_ore);
API_FCT(clear_registered_biomes); API_FCT(clear_registered_biomes);
API_FCT(clear_registered_decorations);
API_FCT(clear_registered_ores);
API_FCT(create_schematic); API_FCT(create_schematic);
API_FCT(place_schematic); API_FCT(place_schematic);

View File

@ -55,6 +55,12 @@ private:
// clear_registered_biomes() // clear_registered_biomes()
static int l_clear_registered_biomes(lua_State *L); static int l_clear_registered_biomes(lua_State *L);
// clear_registered_decorations()
static int l_clear_registered_decorations(lua_State *L);
// clear_registered_ores
static int l_clear_registered_ores(lua_State *L);
// create_schematic(p1, p2, probability_list, filename) // create_schematic(p1, p2, probability_list, filename)
static int l_create_schematic(lua_State *L); static int l_create_schematic(lua_State *L);