From 406d9ba87b9f6e57b86c6282bf157e3341aa195c Mon Sep 17 00:00:00 2001 From: kwolekr Date: Fri, 17 Apr 2015 00:52:48 -0400 Subject: Schematics: Remove referenced schematics from Decorations on clear --- src/mg_schematic.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/mg_schematic.cpp') 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 #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(deco); + if (dschem) + dschem->schematic = NULL; + } catch(std::bad_cast) { + } + } + + ObjDefManager::clear(); } -- cgit v1.2.3