diff --git a/code/nel/tools/pipeline/max/class_directory_3.cpp b/code/nel/tools/pipeline/max/class_directory_3.cpp index e62676d76..7ed8cfdbb 100644 --- a/code/nel/tools/pipeline/max/class_directory_3.cpp +++ b/code/nel/tools/pipeline/max/class_directory_3.cpp @@ -68,6 +68,7 @@ CClassDirectory3::~CClassDirectory3() } m_ChunkCache.clear(); m_Entries.clear(); + m_ClassIdToIndex.clear(); } std::string CClassDirectory3::getClassName() @@ -140,16 +141,20 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level) switch (id) { case 0x2040: // ClassEntry - if (parsedDllEntry && (lastCached != id)) - throw EStorageParse(); // There were chunks inbetween - if (!parsedDllEntry) { - m_ChunkCache.push_back(TStorageObjectWithId(id, NULL)); // Dummy entry to know the location - lastCached = id; - parsedDllEntry = true; + if (parsedDllEntry && (lastCached != id)) + throw EStorageParse(); // There were chunks inbetween + if (!parsedDllEntry) + { + m_ChunkCache.push_back(TStorageObjectWithId(id, NULL)); // Dummy entry to know the location + lastCached = id; + parsedDllEntry = true; + } + CClassEntry *classEntry = static_cast(it->second); + m_ClassIdToIndex[classEntry->classId()] = m_Entries.size(); + m_Entries.push_back(classEntry); + break; } - m_Entries.push_back(static_cast(it->second)); - break; default: m_ChunkCache.push_back(*it); // Dummy entry to know the location lastCached = id; @@ -222,15 +227,45 @@ void CClassDirectory3::disown() CStorageContainer::disown(); m_ChunkCache.clear(); m_Entries.clear(); + m_ClassIdToIndex.clear(); // Ownership goes back to Chunks ChunksOwnsPointers = true; } // Parallel to CDllDirectory -const CClassEntry *CClassDirectory3::get(std::vector::size_type idx) const +const CClassEntry *CClassDirectory3::get(uint16 index) const { - return m_Entries[idx]; + nlassert(!ChunksOwnsPointers); + return m_Entries[index]; +} + +void CClassDirectory3::reset() +{ + nlassert(!ChunksOwnsPointers); + for (std::vector::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) + { + delete (*subit); + } + m_Entries.clear(); + m_ClassIdToIndex.clear(); +} + +uint16 CClassDirectory3::getOrCreateIndex(const ISceneClassDesc *sceneClassDesc) +{ + nlassert(!ChunksOwnsPointers); + std::map::iterator it = m_ClassIdToIndex.find(sceneClassDesc->classId()); + + // Return existing index + if (it != m_ClassIdToIndex.end()) + return it->second; + + // Create new entry + CClassEntry *classEntry = new CClassEntry(sceneClassDesc); + uint16 index = m_Entries.size(); + m_ClassIdToIndex[classEntry->classId()] = index; + m_Entries.push_back(classEntry); + return index; } IStorageObject *CClassDirectory3::createChunkById(uint16 id, bool container) @@ -261,6 +296,16 @@ CClassEntry::CClassEntry() : m_Header(NULL), m_Name(NULL) } +CClassEntry::CClassEntry(const ISceneClassDesc *sceneClassDesc) : m_Header(new CClassEntryHeader()), m_Name(new CStorageValue()) +{ + Chunks.push_back(TStorageObjectWithId(0x2060, m_Header)); + Chunks.push_back(TStorageObjectWithId(0x2042, m_Name)); + m_Header->DllIndex = -9; // Invalid temporary value + m_Header->ClassId = sceneClassDesc->classId(); + m_Header->SuperClassId = sceneClassDesc->superClassId(); + m_Name->Value = sceneClassDesc->displayName(); +} + CClassEntry::~CClassEntry() { @@ -359,16 +404,16 @@ std::string CClassEntryHeader::getClassName() void CClassEntryHeader::serial(NLMISC::IStream &stream) { stream.serial(DllIndex); - stream.serial(ClassID); - stream.serial(SuperClassID); + stream.serial(ClassId); + stream.serial(SuperClassId); } void CClassEntryHeader::toString(std::ostream &ostream, const std::string &pad) { ostream << "(" << getClassName() << ") { "; ostream << "\n" << pad << "DllIndex: " << DllIndex; - ostream << "\n" << pad << "ClassID: " << NLMISC::toString(ClassID); - ostream << "\n" << pad << "SuperClassID: " << SuperClassID; + ostream << "\n" << pad << "ClassId: " << NLMISC::toString(ClassId); + ostream << "\n" << pad << "SuperClassId: " << SuperClassId; ostream << " } "; } diff --git a/code/nel/tools/pipeline/max/class_directory_3.h b/code/nel/tools/pipeline/max/class_directory_3.h index a1bb5e9ac..78e9b7a17 100644 --- a/code/nel/tools/pipeline/max/class_directory_3.h +++ b/code/nel/tools/pipeline/max/class_directory_3.h @@ -38,6 +38,7 @@ // Project includes #include "storage_object.h" #include "storage_value.h" +#include "scene_class.h" namespace PIPELINE { namespace MAX { @@ -65,7 +66,12 @@ public: virtual void disown(); // public - const CClassEntry *get(std::vector::size_type idx) const; + // Get a class entry corresponding to a chunk index, pointers become invalid after reset + const CClassEntry *get(uint16 index) const; + // Reset the class directory, all class entry pointers become invalid, use class id and scene class registry + void reset(); + // Get or create the chunk index for a class by class description + uint16 getOrCreateIndex(const ISceneClassDesc *sceneClassDesc); protected: virtual IStorageObject *createChunkById(uint16 id, bool container); @@ -73,6 +79,7 @@ protected: private: TStorageObjectContainer m_ChunkCache; std::vector m_Entries; + std::map m_ClassIdToIndex; }; /* class CClassDirectory3 */ @@ -90,8 +97,8 @@ public: // public data sint32 DllIndex; - NLMISC::CClassId ClassID; - uint32 SuperClassID; + NLMISC::CClassId ClassId; + uint32 SuperClassId; // inherited virtual std::string getClassName(); @@ -110,6 +117,7 @@ class CClassEntry : public CStorageContainer { public: CClassEntry(); + CClassEntry(const ISceneClassDesc *sceneClassDesc); virtual ~CClassEntry(); // inherited @@ -122,8 +130,8 @@ public: const ucstring &displayName() const { return m_Name->Value; } sint32 dllIndex() const { return m_Header->DllIndex; } - NLMISC::CClassId cslassId() const { return m_Header->ClassID; } - uint32 superClassId() const { return m_Header->SuperClassID; } + NLMISC::CClassId classId() const { return m_Header->ClassId; } + uint32 superClassId() const { return m_Header->SuperClassId; } protected: virtual IStorageObject *createChunkById(uint16 id, bool container); diff --git a/code/nel/tools/pipeline/max/dll_directory.cpp b/code/nel/tools/pipeline/max/dll_directory.cpp index 3c14d072a..d1cfe2c85 100644 --- a/code/nel/tools/pipeline/max/dll_directory.cpp +++ b/code/nel/tools/pipeline/max/dll_directory.cpp @@ -224,9 +224,9 @@ void CDllDirectory::disown() } // Parallel to CClassDirectory3 -const CDllEntry *CDllDirectory::get(std::vector::size_type idx) const +const CDllEntry *CDllDirectory::get(uint16 index) const { - return m_Entries[idx]; + return m_Entries[index]; } IStorageObject *CDllDirectory::createChunkById(uint16 id, bool container) diff --git a/code/nel/tools/pipeline/max/dll_directory.h b/code/nel/tools/pipeline/max/dll_directory.h index 8db2ab9a5..e02ae45a0 100644 --- a/code/nel/tools/pipeline/max/dll_directory.h +++ b/code/nel/tools/pipeline/max/dll_directory.h @@ -63,7 +63,7 @@ public: virtual void disown(); // public - const CDllEntry *get(std::vector::size_type idx) const; + const CDllEntry *get(uint16 index) const; protected: virtual IStorageObject *createChunkById(uint16 id, bool container); diff --git a/code/nel/tools/pipeline/max/scene.cpp b/code/nel/tools/pipeline/max/scene.cpp index 584e26a54..1409b3ffc 100644 --- a/code/nel/tools/pipeline/max/scene.cpp +++ b/code/nel/tools/pipeline/max/scene.cpp @@ -155,69 +155,6 @@ IStorageObject *CSceneClassContainer::createChunkById(uint16 id, bool container) //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -CSceneClass::CSceneClass() -{ - -} - -CSceneClass::~CSceneClass() -{ - -} - -std::string CSceneClass::getClassName() -{ - return getClassDesc()->getInternalName(); -} - -void CSceneClass::toString(std::ostream &ostream, const std::string &pad) -{ - CStorageContainer::toString(ostream, pad); -} - -void CSceneClass::parse(uint16 version, TParseLevel level) -{ - CStorageContainer::parse(version, level); -} - -void CSceneClass::clean() -{ - CStorageContainer::clean(); -} - -void CSceneClass::build(uint16 version) -{ - CStorageContainer::build(version); -} - -void CSceneClass::disown() -{ - CStorageContainer::disown(); -} - -IStorageObject *CSceneClass::createChunkById(uint16 id, bool container) -{ - return CStorageContainer::createChunkById(id, container); -} - -const ucchar *CSceneClass::DisplayName = ucstring("Unknown Scene Class").c_str(); -const char *CSceneClass::InternalName = "SceneClass"; -const NLMISC::CClassId CSceneClass::ClassId = NLMISC::CClassId::Null; -const TSClassId CSceneClass::SuperClassId = 0x0000; - -namespace { -static const CSceneClassDesc SceneClassDesc; -} /* anonymous namespace */ - -const ISceneClassDesc *CSceneClass::getClassDesc() -{ - return static_cast(&SceneClassDesc); -} - -//////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// - } /* namespace MAX */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/max/scene.h b/code/nel/tools/pipeline/max/scene.h index a01e12380..54e7e1d11 100644 --- a/code/nel/tools/pipeline/max/scene.h +++ b/code/nel/tools/pipeline/max/scene.h @@ -37,13 +37,11 @@ // Project includes #include "storage_object.h" #include "storage_value.h" +#include "scene_class.h" namespace PIPELINE { namespace MAX { -// Don't really care about superclass IDs right now, but we have to. -typedef uint32 TSClassId; - /** * \brief CScene * \date 2012-08-19 19:25GMT @@ -94,97 +92,6 @@ protected: }; /* class CSceneClassContainer */ -class ISceneClassDesc; - -/** - * \brief CSceneClass - * \date 2012-08-19 19:25GMT - * \author Jan Boon (Kaetemi) - * CSceneClass - */ -class CSceneClass : public CStorageContainer -{ -public: - CSceneClass(); - virtual ~CSceneClass(); - - // inherited - 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(); - - // static const - static const ucchar *DisplayName; - static const char *InternalName; - static const NLMISC::CClassId ClassId; - static const TSClassId SuperClassId; - - // virtual - virtual const ISceneClassDesc *getClassDesc(); - -protected: - virtual IStorageObject *createChunkById(uint16 id, bool container); - -}; /* class CSceneClass */ - -/** - * \brief ISceneClassDesc - * \date 2012-08-19 19:25GMT - * \author Jan Boon (Kaetemi) - * ISceneClassDesc - */ -class ISceneClassDesc -{ -public: - virtual CSceneClass *create() const = 0; - virtual void destroy(CSceneClass *sc) const = 0; - virtual const ucchar *getDisplayName() const = 0; - virtual const char *getInternalName() const = 0; - virtual NLMISC::CClassId getClassId() const = 0; - virtual TSClassId getSuperClassId() const = 0; - -}; /* class ISceneClassDesc */ - -/** - * \brief CSceneClassDesc - * \date 2012-08-19 19:25GMT - * \author Jan Boon (Kaetemi) - * CSceneClassDesc - * Use in a cpp when registering the CClassId. - */ -template -class CSceneClassDesc : public ISceneClassDesc -{ -public: - virtual CSceneClass *create() const { return static_cast(new T()); } - virtual void destroy(CSceneClass *sc) const { delete static_cast(sc); } - virtual const ucchar *getDisplayName() const { return T::DisplayName; } - virtual const char *getInternalName() const { return T::InternalName; } - virtual NLMISC::CClassId getClassId() const { return T::ClassId; } - virtual TSClassId getSuperClassId() const { return T::SuperClassId; } - -}; /* class CSceneClassDesc */ - -/** - * \brief CSceneClassRegistry - * \date 2012-08-19 19:25GMT - * \author Jan Boon (Kaetemi) - * CSceneClassRegistry - */ -class CSceneClassRegistry -{ -public: - void add(const NLMISC::CClassId, const ISceneClassDesc *desc); - void remove(const NLMISC::CClassId); - CSceneClass *create(const NLMISC::CClassId classid) const; - void destroy(CSceneClass *sceneClass) const; - const ISceneClassDesc *describe(const NLMISC::CClassId classid) const; - -}; /* class ISceneClassConstructor */ - } /* namespace MAX */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/max/scene_class.cpp b/code/nel/tools/pipeline/max/scene_class.cpp new file mode 100644 index 000000000..6d4acce01 --- /dev/null +++ b/code/nel/tools/pipeline/max/scene_class.cpp @@ -0,0 +1,114 @@ +/** + * \file scene_class.cpp + * \brief CSceneClass + * \date 2012-08-20 09:07GMT + * \author Jan Boon (Kaetemi) + * CSceneClass + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#include +#include "scene_class.h" + +// STL includes + +// NeL includes +// #include + +// Project includes + +using namespace std; +// using namespace NLMISC; + +namespace PIPELINE { +namespace MAX { + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +CSceneClass::CSceneClass() +{ + +} + +CSceneClass::~CSceneClass() +{ + +} + +std::string CSceneClass::getClassName() +{ + return getClassDesc()->internalName(); +} + +void CSceneClass::toString(std::ostream &ostream, const std::string &pad) +{ + CStorageContainer::toString(ostream, pad); +} + +void CSceneClass::parse(uint16 version, TParseLevel level) +{ + CStorageContainer::parse(version, level); +} + +void CSceneClass::clean() +{ + CStorageContainer::clean(); +} + +void CSceneClass::build(uint16 version) +{ + CStorageContainer::build(version); +} + +void CSceneClass::disown() +{ + CStorageContainer::disown(); +} + +IStorageObject *CSceneClass::createChunkById(uint16 id, bool container) +{ + return CStorageContainer::createChunkById(id, container); +} + +const ucchar *CSceneClass::DisplayName = ucstring("Scene Class").c_str(); +const char *CSceneClass::InternalName = "SceneClass"; +const NLMISC::CClassId CSceneClass::ClassId = NLMISC::CClassId::Null; +const TSClassId CSceneClass::SuperClassId = 0x0000; + +namespace { +static const CSceneClassDesc SceneClassDesc; +} /* anonymous namespace */ + +const ISceneClassDesc *CSceneClass::getClassDesc() +{ + return static_cast(&SceneClassDesc); +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +} /* namespace MAX */ +} /* namespace PIPELINE */ + +/* end of file */ diff --git a/code/nel/tools/pipeline/max/scene_class.h b/code/nel/tools/pipeline/max/scene_class.h new file mode 100644 index 000000000..14cc17471 --- /dev/null +++ b/code/nel/tools/pipeline/max/scene_class.h @@ -0,0 +1,143 @@ +/** + * \file scene_class.h + * \brief CSceneClass + * \date 2012-08-20 09:07GMT + * \author Jan Boon (Kaetemi) + * CSceneClass + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#ifndef PIPELINE_SCENE_CLASS_H +#define PIPELINE_SCENE_CLASS_H +#include + +// STL includes + +// NeL includes +#include + +// Project includes +#include "storage_object.h" +#include "storage_value.h" + +namespace PIPELINE { +namespace MAX { + +// Don't really care about superclass IDs right now, but we have to. +typedef uint32 TSClassId; + +class ISceneClassDesc; + +/** + * \brief CSceneClass + * \date 2012-08-19 19:25GMT + * \author Jan Boon (Kaetemi) + * CSceneClass + */ +class CSceneClass : public CStorageContainer +{ +public: + CSceneClass(); + virtual ~CSceneClass(); + + // inherited + 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(); + + // static const + static const ucchar *DisplayName; + static const char *InternalName; + static const NLMISC::CClassId ClassId; + static const TSClassId SuperClassId; + + // virtual + virtual const ISceneClassDesc *getClassDesc(); + +protected: + virtual IStorageObject *createChunkById(uint16 id, bool container); + +}; /* class CSceneClass */ + +/** + * \brief ISceneClassDesc + * \date 2012-08-19 19:25GMT + * \author Jan Boon (Kaetemi) + * ISceneClassDesc + */ +class ISceneClassDesc +{ +public: + virtual CSceneClass *create() const = 0; + virtual void destroy(CSceneClass *sc) const = 0; + virtual const ucchar *displayName() const = 0; + virtual const char *internalName() const = 0; + virtual NLMISC::CClassId classId() const = 0; + virtual TSClassId superClassId() const = 0; + +}; /* class ISceneClassDesc */ + +/** + * \brief CSceneClassDesc + * \date 2012-08-19 19:25GMT + * \author Jan Boon (Kaetemi) + * CSceneClassDesc + * Use in a cpp when registering the CClassId. + */ +template +class CSceneClassDesc : public ISceneClassDesc +{ +public: + virtual CSceneClass *create() const { return static_cast(new T()); } + virtual void destroy(CSceneClass *sc) const { delete static_cast(sc); } + virtual const ucchar *displayName() const { return T::DisplayName; } + virtual const char *internalName() const { return T::InternalName; } + virtual NLMISC::CClassId classId() const { return T::ClassId; } + virtual TSClassId superClassId() const { return T::SuperClassId; } + +}; /* class CSceneClassDesc */ + +/** + * \brief CSceneClassRegistry + * \date 2012-08-19 19:25GMT + * \author Jan Boon (Kaetemi) + * CSceneClassRegistry + */ +class CSceneClassRegistry +{ +public: + void add(const NLMISC::CClassId, const ISceneClassDesc *desc); + void remove(const NLMISC::CClassId); + CSceneClass *create(const NLMISC::CClassId classid) const; + void destroy(CSceneClass *sceneClass) const; + const ISceneClassDesc *describe(const NLMISC::CClassId classid) const; + +}; /* class ISceneClassConstructor */ + +} /* namespace MAX */ +} /* namespace PIPELINE */ + +#endif /* #ifndef PIPELINE_SCENE_CLASS_H */ + +/* end of file */