diff --git a/code/nel/tools/pipeline/max/class_data.cpp b/code/nel/tools/pipeline/max/class_data.cpp index dae0a4b6d..3e6baca26 100644 --- a/code/nel/tools/pipeline/max/class_data.cpp +++ b/code/nel/tools/pipeline/max/class_data.cpp @@ -70,6 +70,11 @@ void CClassData::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CClassData::clean() +{ + CStorageContainer::clean(); +} + void CClassData::build(uint16 version) { CStorageContainer::build(version); @@ -122,6 +127,11 @@ void CClassDataEntry::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CClassDataEntry::clean() +{ + CStorageContainer::clean(); +} + void CClassDataEntry::build(uint16 version) { CStorageContainer::build(version); diff --git a/code/nel/tools/pipeline/max/class_data.h b/code/nel/tools/pipeline/max/class_data.h index 3e7b6a354..afad16c75 100644 --- a/code/nel/tools/pipeline/max/class_data.h +++ b/code/nel/tools/pipeline/max/class_data.h @@ -57,6 +57,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -81,6 +82,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); diff --git a/code/nel/tools/pipeline/max/class_directory_3.cpp b/code/nel/tools/pipeline/max/class_directory_3.cpp index b90c52ec2..b5639c570 100644 --- a/code/nel/tools/pipeline/max/class_directory_3.cpp +++ b/code/nel/tools/pipeline/max/class_directory_3.cpp @@ -70,6 +70,11 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CClassDirectory3::clean() +{ + CStorageContainer::clean(); +} + void CClassDirectory3::build(uint16 version) { CStorageContainer::build(version); @@ -122,6 +127,11 @@ void CClassEntry::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CClassEntry::clean() +{ + CStorageContainer::clean(); +} + void CClassEntry::build(uint16 version) { CStorageContainer::build(version); diff --git a/code/nel/tools/pipeline/max/class_directory_3.h b/code/nel/tools/pipeline/max/class_directory_3.h index b052af8a0..404d90df1 100644 --- a/code/nel/tools/pipeline/max/class_directory_3.h +++ b/code/nel/tools/pipeline/max/class_directory_3.h @@ -57,6 +57,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -81,6 +82,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); diff --git a/code/nel/tools/pipeline/max/config.cpp b/code/nel/tools/pipeline/max/config.cpp index 8aef081cc..dceafb8ac 100644 --- a/code/nel/tools/pipeline/max/config.cpp +++ b/code/nel/tools/pipeline/max/config.cpp @@ -71,6 +71,11 @@ void CConfig::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfig::clean() +{ + CStorageContainer::clean(); +} + void CConfig::build(uint16 version) { CStorageContainer::build(version); @@ -133,6 +138,11 @@ void CConfig20a0::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfig20a0::clean() +{ + CStorageContainer::clean(); +} + void CConfig20a0::build(uint16 version) { CStorageContainer::build(version); @@ -193,6 +203,11 @@ void CConfig20a0Entry::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfig20a0Entry::clean() +{ + CStorageContainer::clean(); +} + void CConfig20a0Entry::build(uint16 version) { CStorageContainer::build(version); @@ -280,6 +295,11 @@ void CConfigScript::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfigScript::clean() +{ + CStorageContainer::clean(); +} + void CConfigScript::build(uint16 version) { CStorageContainer::build(version); @@ -332,6 +352,11 @@ void CConfigScriptEntry::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfigScriptEntry::clean() +{ + CStorageContainer::clean(); +} + void CConfigScriptEntry::build(uint16 version) { CStorageContainer::build(version); @@ -425,6 +450,11 @@ void CConfigScriptMetaContainer::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CConfigScriptMetaContainer::clean() +{ + CStorageContainer::clean(); +} + void CConfigScriptMetaContainer::build(uint16 version) { CStorageContainer::build(version); diff --git a/code/nel/tools/pipeline/max/config.h b/code/nel/tools/pipeline/max/config.h index f8a78a906..37e0650ff 100644 --- a/code/nel/tools/pipeline/max/config.h +++ b/code/nel/tools/pipeline/max/config.h @@ -57,6 +57,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -81,6 +82,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -105,6 +107,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -129,6 +132,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -153,6 +157,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -201,6 +206,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); diff --git a/code/nel/tools/pipeline/max/dll_directory.cpp b/code/nel/tools/pipeline/max/dll_directory.cpp index 432cdd4b5..6a2861089 100644 --- a/code/nel/tools/pipeline/max/dll_directory.cpp +++ b/code/nel/tools/pipeline/max/dll_directory.cpp @@ -48,7 +48,20 @@ CDllDirectory::CDllDirectory() CDllDirectory::~CDllDirectory() { - // TODO: Delete m_ChunkCache and m_Entries when !ChunksOwnsPointers + // Delete m_ChunkCache and m_Entries when !ChunksOwnsPointers + if (!ChunksOwnsPointers) + { + for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) + { + delete it->second; + } + for (std::vector::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) + { + delete (*subit); + } + } + m_ChunkCache.clear(); + m_Entries.clear(); } std::string CDllDirectory::getClassName() @@ -141,13 +154,35 @@ void CDllDirectory::parse(uint16 version, TParseLevel level) } } +void CDllDirectory::clean() +{ + // Ensure parsed + nlassert(!ChunksOwnsPointers); + + // Clear Chunks + Chunks.clear(); + + // Clean chunks + for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) + { + if (it->second != NULL && it->second->isContainer()) + { + static_cast(it->second)->clean(); + } + } + for (std::vector::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) + { + (*subit)->clean(); + } +} + void CDllDirectory::build(uint16 version) { // Ensure parsed nlassert(!ChunksOwnsPointers); // Initialize - Chunks.clear(); + nlassert(Chunks.empty()); // Set up the Chunks list, when (CDllEntry::ID, NULL) is found write out all of the entries. for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) @@ -165,7 +200,7 @@ void CDllDirectory::build(uint16 version) } } - // Build the entries last + // Build the entries last (after Chunks is built) CStorageContainer::build(version); // NOTE: Ownership remains with m_ChunkCache and m_Entries @@ -251,6 +286,12 @@ void CDllEntry::parse(uint16 version, TParseLevel level) // ++it; } +void CDllEntry::clean() +{ + // Nothing to do here! (Chunks retains ownership) + // CStorageContainer::clean(); +} + void CDllEntry::build(uint16 version) { // Nothing to do here! diff --git a/code/nel/tools/pipeline/max/dll_directory.h b/code/nel/tools/pipeline/max/dll_directory.h index 1b03f3e10..c4f43f00f 100644 --- a/code/nel/tools/pipeline/max/dll_directory.h +++ b/code/nel/tools/pipeline/max/dll_directory.h @@ -59,6 +59,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -90,6 +91,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); diff --git a/code/nel/tools/pipeline/max/scene.cpp b/code/nel/tools/pipeline/max/scene.cpp index 9a6a24fcc..584e26a54 100644 --- a/code/nel/tools/pipeline/max/scene.cpp +++ b/code/nel/tools/pipeline/max/scene.cpp @@ -71,6 +71,11 @@ void CScene::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CScene::clean() +{ + CStorageContainer::clean(); +} + void CScene::build(uint16 version) { CStorageContainer::build(version); @@ -120,6 +125,11 @@ void CSceneClassContainer::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CSceneClassContainer::clean() +{ + CStorageContainer::clean(); +} + void CSceneClassContainer::build(uint16 version) { CStorageContainer::build(version); @@ -170,6 +180,11 @@ void CSceneClass::parse(uint16 version, TParseLevel level) CStorageContainer::parse(version, level); } +void CSceneClass::clean() +{ + CStorageContainer::clean(); +} + void CSceneClass::build(uint16 version) { CStorageContainer::build(version); diff --git a/code/nel/tools/pipeline/max/scene.h b/code/nel/tools/pipeline/max/scene.h index 1ab5958dd..a01e12380 100644 --- a/code/nel/tools/pipeline/max/scene.h +++ b/code/nel/tools/pipeline/max/scene.h @@ -60,6 +60,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -84,6 +85,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); @@ -110,6 +112,7 @@ public: virtual std::string getClassName(); virtual void toString(std::ostream &ostream, const std::string &pad = ""); virtual void parse(uint16 version, TParseLevel level); + virtual void clean(); virtual void build(uint16 version); virtual void disown(); diff --git a/code/nel/tools/pipeline/max/storage_object.cpp b/code/nel/tools/pipeline/max/storage_object.cpp index 22278a862..8bc95960d 100644 --- a/code/nel/tools/pipeline/max/storage_object.cpp +++ b/code/nel/tools/pipeline/max/storage_object.cpp @@ -95,8 +95,12 @@ CStorageContainer::~CStorageContainer() { if (ChunksOwnsPointers) { - + for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) + { + delete it->second; + } } + Chunks.clear(); } std::string CStorageContainer::getClassName() // why is this not const in IClassable? @@ -180,6 +184,18 @@ void CStorageContainer::parse(uint16 version, TParseLevel level) } } +void CStorageContainer::clean() +{ + nlassert(ChunksOwnsPointers); // Can only use the default when Chunks retains ownership. + for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) + { + if (it->second->isContainer()) + { + static_cast(it->second)->clean(); + } + } +} + void CStorageContainer::build(uint16 version) { for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) diff --git a/code/nel/tools/pipeline/max/storage_object.h b/code/nel/tools/pipeline/max/storage_object.h index 03b1f775c..2a870e3de 100644 --- a/code/nel/tools/pipeline/max/storage_object.h +++ b/code/nel/tools/pipeline/max/storage_object.h @@ -120,9 +120,11 @@ public: // virtual // Parse this class with given version and parse level filter virtual void parse(uint16 version, TParseLevel level); + // Clean up built data or duplicate unparsed source data, call after serializing build and after parse + virtual void clean(); // Build the storage structure needed to store the parsed data back virtual void build(uint16 version); - // Give ownership of the chunks back to the Chunks, must build first + // Give ownership of the chunks back to the Chunks, must call build first, call instead of clean, reduces the parse level back to 0 virtual void disown(); public: // should be protected but that doesn't compile, nice c++! diff --git a/code/nel/tools/pipeline/max_dump/main.cpp b/code/nel/tools/pipeline/max_dump/main.cpp index 1d2949efc..26190f9f6 100644 --- a/code/nel/tools/pipeline/max_dump/main.cpp +++ b/code/nel/tools/pipeline/max_dump/main.cpp @@ -86,6 +86,7 @@ int main(int argc, char **argv) dllDirectory.toString(std::cout); std::cout << "\n"; dllDirectory.parse(PIPELINE::MAX::VersionUnknown, PIPELINE::MAX::PARSE_INTERNAL); + dllDirectory.clean(); dllDirectory.toString(std::cout); std::cout << "\n"; dllDirectory.build(PIPELINE::MAX::VersionUnknown);