From 492a1701cb8c2d4273391ce2360a3e0d9ca18a28 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 21 Aug 2012 15:25:59 +0200 Subject: [PATCH] Added: #1440 Extended parser for AppData entries --HG-- branch : build_pipeline_v3 --- .../tools/pipeline/max/builtin/app_data.cpp | 95 +++++++++++++++++-- .../nel/tools/pipeline/max/builtin/app_data.h | 13 ++- code/nel/tools/pipeline/max/storage_object.h | 2 +- code/nel/tools/pipeline/max_dump/main.cpp | 4 +- 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/code/nel/tools/pipeline/max/builtin/app_data.cpp b/code/nel/tools/pipeline/max/builtin/app_data.cpp index f466f5e26..71e7bfdc7 100644 --- a/code/nel/tools/pipeline/max/builtin/app_data.cpp +++ b/code/nel/tools/pipeline/max/builtin/app_data.cpp @@ -142,6 +142,40 @@ void CAppData::disown() CStorageContainer::disown(); } +const uint8 *CAppData::read(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 &size) const +{ + if (ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; } + TKey key(classId, superClassId, subId); + TMap::const_iterator it = m_Entries.find(key); + if (it == m_Entries.end()) return NULL; + size = it->second->value()->Value.size(); + return &it->second->value()->Value[0]; +} + +uint8 *CAppData::lock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 capacity) +{ + if (ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; } + TKey key(classId, superClassId, subId); +} + +void CAppData::unlock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 size) +{ + if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } + TKey key(classId, superClassId, subId); +} + +void CAppData::fill(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint8 *buffer, uint32 size) +{ + if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } + TKey key(classId, superClassId, subId); +} + +void CAppData::erase(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId) +{ + if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } + TKey key(classId, superClassId, subId); +} + IStorageObject *CAppData::createChunkById(uint16 id, bool container) { switch (id) @@ -199,7 +233,7 @@ void CAppDataEntryKey::toString(std::ostream &ostream, const std::string &pad) //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -CAppDataEntry::CAppDataEntry() +CAppDataEntry::CAppDataEntry() : m_Key(NULL), m_Value(NULL) { } @@ -216,27 +250,76 @@ std::string CAppDataEntry::getClassName() void CAppDataEntry::toString(std::ostream &ostream, const std::string &pad) { - CStorageContainer::toString(ostream, pad); + if (m_Key && m_Value) + { + ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; + std::string padpad = pad + "\t"; + ostream << "\n" << pad << "Key: "; + m_Key->toString(ostream, padpad); + ostream << "\n" << pad << "Value: "; + m_Value->toString(ostream, padpad); + ostream << "} "; + } + else + { + CStorageContainer::toString(ostream, pad); + } } void CAppDataEntry::parse(uint16 version, TParseLevel level) { - CStorageContainer::parse(version, level); + if (level & PARSE_BUILTIN) + { + // CStorageContainer::parse(version, level); + // if (!ChunksOwnsPointers) { nlwarning("Already parsed"); return; } + if (Chunks.size() != 2) { nlwarning("Bad container size"); disown(); return; } + + TStorageObjectContainer::iterator it = Chunks.begin(); + if (it->first != NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID); disown(); return; } + m_Key = static_cast(it->second); + + ++it; + if (it->first != NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID); disown(); return; } + m_Value = static_cast(it->second); + + // ChunksOwnsPointers = false; + } + } void CAppDataEntry::clean() { - CStorageContainer::clean(); + // CStorageContainer::clean(); + // if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } + // Nothing to do here! } void CAppDataEntry::build(uint16 version) { - CStorageContainer::build(version); + // if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } + // Nothing to do here! + // CStorageContainer::build(version); } void CAppDataEntry::disown() { - CStorageContainer::disown(); + // CStorageContainer::disown(); + m_Key = NULL; + m_Value = NULL; +} + +void CAppDataEntry::init() +{ + nlassert(Chunks.size() == 0); + m_Key = new CAppDataEntryKey(); + Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID, m_Key)); + m_Value = new CStorageRaw(); + Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID, m_Value)); +} + +CStorageRaw *CAppDataEntry::value() +{ + return m_Value; } IStorageObject *CAppDataEntry::createChunkById(uint16 id, bool container) diff --git a/code/nel/tools/pipeline/max/builtin/app_data.h b/code/nel/tools/pipeline/max/builtin/app_data.h index 98e5d461e..0df203aaa 100644 --- a/code/nel/tools/pipeline/max/builtin/app_data.h +++ b/code/nel/tools/pipeline/max/builtin/app_data.h @@ -65,6 +65,7 @@ private: bool operator>(const TKey &right) const; bool operator==(const TKey &right) const; }; + typedef std::map TMap; public: CAppData(); @@ -94,7 +95,7 @@ protected: virtual IStorageObject *createChunkById(uint16 id, bool container); private: - std::map m_Entries; + TMap m_Entries; }; /* class CAppData */ @@ -143,9 +144,19 @@ public: virtual void build(uint16 version); virtual void disown(); + // public + // Initializes a new entry + void init(); + // Returns the blob + CStorageRaw *value(); + protected: virtual IStorageObject *createChunkById(uint16 id, bool container); +private: + CAppDataEntryKey *m_Key; + CStorageRaw *m_Value; + }; /* class CAppDataEntry */ } /* namespace MAX */ diff --git a/code/nel/tools/pipeline/max/storage_object.h b/code/nel/tools/pipeline/max/storage_object.h index 73c40bd59..4363b20da 100644 --- a/code/nel/tools/pipeline/max/storage_object.h +++ b/code/nel/tools/pipeline/max/storage_object.h @@ -58,7 +58,7 @@ struct EStorageParse : public EStorage enum TParseLevel { PARSE_INTERNAL = 0x00000001, // Directly parse basic class formats - // PARSE_BUILTIN = 0x00000002; // Parse all builtin classes - reserved + PARSE_BUILTIN = 0x00000002, // Parse all builtin classes // PARSE_NELDATA = 0x00000004, // Parse all structures related to nel specific data (nel material, node properties, etcetera) // PARSE_NEL3D = 0x00000008, // Parse classes to initialize their nel3d equivalent classes }; diff --git a/code/nel/tools/pipeline/max_dump/main.cpp b/code/nel/tools/pipeline/max_dump/main.cpp index 813f8c81f..9c874106e 100644 --- a/code/nel/tools/pipeline/max_dump/main.cpp +++ b/code/nel/tools/pipeline/max_dump/main.cpp @@ -150,7 +150,9 @@ int main(int argc, char **argv) g_object_unref(input); //classDirectory3.toString(std::cout); //std::cout << "\n"; - scene.parse(PIPELINE::MAX::VersionUnknown, PIPELINE::MAX::PARSE_INTERNAL); // parse the structure to readable data + scene.parse(PIPELINE::MAX::VersionUnknown, (PIPELINE::MAX::TParseLevel)( + PIPELINE::MAX::PARSE_INTERNAL + | PIPELINE::MAX::PARSE_BUILTIN)); // parse the structure to readable data scene.clean(); // cleanup unused file structure scene.toString(std::cout); std::cout << "\n";