diff options
author | kwolekr <kwolekr@minetest.net> | 2015-04-17 00:52:48 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-04-17 00:53:05 -0400 |
commit | 406d9ba87b9f6e57b86c6282bf157e3341aa195c (patch) | |
tree | de88e4136a31c3e350a0257301b134555706ae82 /src/mg_schematic.cpp | |
parent | f0a1379e5a9ebc954e95d07c1ad5d71587adc6bc (diff) | |
download | minetest-406d9ba87b9f6e57b86c6282bf157e3341aa195c.tar.gz minetest-406d9ba87b9f6e57b86c6282bf157e3341aa195c.tar.bz2 minetest-406d9ba87b9f6e57b86c6282bf157e3341aa195c.zip |
Schematics: Remove referenced schematics from Decorations on clear
Diffstat (limited to 'src/mg_schematic.cpp')
-rw-r--r-- | src/mg_schematic.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mg_schematic.cpp b/src/mg_schematic.cpp index cb31f640c..6215bce94 100644 --- a/src/mg_schematic.cpp +++ b/src/mg_schematic.cpp @@ -19,7 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <fstream> #include "mg_schematic.h" +#include "gamedef.h" #include "mapgen.h" +#include "emerge.h" #include "map.h" #include "mapblock.h" #include "log.h" @@ -34,6 +36,28 @@ with this program; if not, write to the Free Software Foundation, Inc., SchematicManager::SchematicManager(IGameDef *gamedef) : 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(); } |