Schematics: Remove referenced schematics from Decorations on clear
parent
f0a1379e5a
commit
406d9ba87b
|
@ -61,7 +61,7 @@ public:
|
||||||
static const char *OBJECT_TITLE;
|
static const char *OBJECT_TITLE;
|
||||||
|
|
||||||
BiomeManager(IGameDef *gamedef);
|
BiomeManager(IGameDef *gamedef);
|
||||||
~BiomeManager();
|
virtual ~BiomeManager();
|
||||||
|
|
||||||
const char *getObjectTitle() const
|
const char *getObjectTitle() const
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,7 @@ public:
|
||||||
return new Biome;
|
return new Biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear();
|
virtual void clear();
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -61,16 +61,6 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DecorationManager::clear()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < m_objects.size(); i++) {
|
|
||||||
Decoration *deco = (Decoration *)m_objects[i];
|
|
||||||
delete deco;
|
|
||||||
}
|
|
||||||
m_objects.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -320,8 +310,20 @@ int DecoSimple::getHeight()
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
DecoSchematic::DecoSchematic() :
|
||||||
|
Decoration::Decoration()
|
||||||
|
{
|
||||||
|
schematic = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t DecoSchematic::generate(MMVManip *vm, PseudoRandom *pr, v3s16 p)
|
size_t DecoSchematic::generate(MMVManip *vm, PseudoRandom *pr, v3s16 p)
|
||||||
{
|
{
|
||||||
|
// Schematic could have been unloaded but not the decoration
|
||||||
|
// In this case generate() does nothing (but doesn't *fail*)
|
||||||
|
if (schematic == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (flags & DECO_PLACE_CENTER_X)
|
if (flags & DECO_PLACE_CENTER_X)
|
||||||
p.X -= (schematic->size.X + 1) / 2;
|
p.X -= (schematic->size.X + 1) / 2;
|
||||||
if (flags & DECO_PLACE_CENTER_Y)
|
if (flags & DECO_PLACE_CENTER_Y)
|
||||||
|
|
|
@ -61,7 +61,16 @@ struct CutoffData {
|
||||||
|
|
||||||
class Decoration : public ObjDef, public NodeResolver {
|
class Decoration : public ObjDef, public NodeResolver {
|
||||||
public:
|
public:
|
||||||
INodeDefManager *ndef;
|
Decoration();
|
||||||
|
virtual ~Decoration();
|
||||||
|
|
||||||
|
virtual void resolveNodeNames();
|
||||||
|
|
||||||
|
size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
|
//size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
|
|
||||||
|
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p) = 0;
|
||||||
|
virtual int getHeight() = 0;
|
||||||
|
|
||||||
u32 flags;
|
u32 flags;
|
||||||
int mapseed;
|
int mapseed;
|
||||||
|
@ -75,42 +84,32 @@ public:
|
||||||
std::set<u8> biomes;
|
std::set<u8> biomes;
|
||||||
//std::list<CutoffData> cutoffs;
|
//std::list<CutoffData> cutoffs;
|
||||||
//JMutex cutoff_mutex;
|
//JMutex cutoff_mutex;
|
||||||
|
|
||||||
Decoration();
|
|
||||||
virtual ~Decoration();
|
|
||||||
|
|
||||||
virtual void resolveNodeNames();
|
|
||||||
|
|
||||||
size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
|
||||||
//size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
|
||||||
|
|
||||||
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p) = 0;
|
|
||||||
virtual int getHeight() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DecoSimple : public Decoration {
|
class DecoSimple : public Decoration {
|
||||||
public:
|
public:
|
||||||
|
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
|
||||||
|
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
|
||||||
|
virtual int getHeight();
|
||||||
|
|
||||||
|
virtual void resolveNodeNames();
|
||||||
|
|
||||||
std::vector<content_t> c_decos;
|
std::vector<content_t> c_decos;
|
||||||
std::vector<content_t> c_spawnby;
|
std::vector<content_t> c_spawnby;
|
||||||
s16 deco_height;
|
s16 deco_height;
|
||||||
s16 deco_height_max;
|
s16 deco_height_max;
|
||||||
s16 nspawnby;
|
s16 nspawnby;
|
||||||
|
|
||||||
virtual void resolveNodeNames();
|
|
||||||
|
|
||||||
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
|
|
||||||
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
|
|
||||||
virtual int getHeight();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DecoSchematic : public Decoration {
|
class DecoSchematic : public Decoration {
|
||||||
public:
|
public:
|
||||||
Rotation rotation;
|
DecoSchematic();
|
||||||
Schematic *schematic;
|
|
||||||
std::string filename;
|
|
||||||
|
|
||||||
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
|
virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
|
||||||
virtual int getHeight();
|
virtual int getHeight();
|
||||||
|
|
||||||
|
Rotation rotation;
|
||||||
|
Schematic *schematic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ public:
|
||||||
class DecorationManager : public ObjDefManager {
|
class DecorationManager : public ObjDefManager {
|
||||||
public:
|
public:
|
||||||
DecorationManager(IGameDef *gamedef);
|
DecorationManager(IGameDef *gamedef);
|
||||||
~DecorationManager() {}
|
virtual ~DecorationManager() {}
|
||||||
|
|
||||||
const char *getObjectTitle() const
|
const char *getObjectTitle() const
|
||||||
{
|
{
|
||||||
|
@ -145,8 +144,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ public:
|
||||||
class OreManager : public ObjDefManager {
|
class OreManager : public ObjDefManager {
|
||||||
public:
|
public:
|
||||||
OreManager(IGameDef *gamedef);
|
OreManager(IGameDef *gamedef);
|
||||||
~OreManager() {}
|
virtual ~OreManager() {}
|
||||||
|
|
||||||
const char *getObjectTitle() const
|
const char *getObjectTitle() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "mg_schematic.h"
|
#include "mg_schematic.h"
|
||||||
|
#include "gamedef.h"
|
||||||
#include "mapgen.h"
|
#include "mapgen.h"
|
||||||
|
#include "emerge.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "mapblock.h"
|
#include "mapblock.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -34,6 +36,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
SchematicManager::SchematicManager(IGameDef *gamedef) :
|
SchematicManager::SchematicManager(IGameDef *gamedef) :
|
||||||
ObjDefManager(gamedef, OBJDEF_SCHEMATIC)
|
ObjDefManager(gamedef, OBJDEF_SCHEMATIC)
|
||||||
{
|
{
|
||||||
|
m_gamedef = gamedef;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SchematicManager::clear()
|
||||||
|
{
|
||||||
|
EmergeManager *emerge = m_gamedef->getEmergeManager();
|
||||||
|
|
||||||
|
// Remove all dangling references in Decorations
|
||||||
|
DecorationManager *decomgr = emerge->decomgr;
|
||||||
|
for (size_t i = 0; i != decomgr->getNumObjects(); i++) {
|
||||||
|
Decoration *deco = (Decoration *)decomgr->getRaw(i);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DecoSchematic *dschem = dynamic_cast<DecoSchematic *>(deco);
|
||||||
|
if (dschem)
|
||||||
|
dschem->schematic = NULL;
|
||||||
|
} catch(std::bad_cast) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjDefManager::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Mapgen;
|
||||||
class MMVManip;
|
class MMVManip;
|
||||||
class PseudoRandom;
|
class PseudoRandom;
|
||||||
class NodeResolver;
|
class NodeResolver;
|
||||||
|
class IGameDef;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Minetest Schematic File Format
|
Minetest Schematic File Format
|
||||||
|
@ -121,7 +122,9 @@ public:
|
||||||
class SchematicManager : public ObjDefManager {
|
class SchematicManager : public ObjDefManager {
|
||||||
public:
|
public:
|
||||||
SchematicManager(IGameDef *gamedef);
|
SchematicManager(IGameDef *gamedef);
|
||||||
~SchematicManager() {}
|
virtual ~SchematicManager() {}
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
const char *getObjectTitle() const
|
const char *getObjectTitle() const
|
||||||
{
|
{
|
||||||
|
@ -132,6 +135,9 @@ public:
|
||||||
{
|
{
|
||||||
return new Schematic;
|
return new Schematic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
IGameDef *m_gamedef;
|
||||||
};
|
};
|
||||||
|
|
||||||
void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
|
void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
|
||||||
|
|
Loading…
Reference in New Issue