diff --git a/code/nel/tools/pipeline/max/scene.cpp b/code/nel/tools/pipeline/max/scene.cpp index 1409b3ffc..9b803a03c 100644 --- a/code/nel/tools/pipeline/max/scene.cpp +++ b/code/nel/tools/pipeline/max/scene.cpp @@ -35,6 +35,10 @@ #include // Project includes +#include "dll_directory.h" +#include "class_directory_3.h" +#include "scene_class_registry.h" +#include "scene_class_unknown.h" using namespace std; // using namespace NLMISC; @@ -46,7 +50,7 @@ namespace MAX { //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -CScene::CScene() +CScene::CScene(const CSceneClassRegistry *sceneClassRegistry, CDllDirectory *dllDirectory, CClassDirectory3 *classDirectory3) : m_SceneClassRegistry(sceneClassRegistry), m_DllDirectory(dllDirectory), m_ClassDirectory3(classDirectory3) { } @@ -69,6 +73,7 @@ void CScene::toString(std::ostream &ostream, const std::string &pad) void CScene::parse(uint16 version, TParseLevel level) { CStorageContainer::parse(version, level); + nlassert(Chunks.size() == 1); } void CScene::clean() @@ -78,6 +83,7 @@ void CScene::clean() void CScene::build(uint16 version) { + nlassert(Chunks.size() == 1); CStorageContainer::build(version); } @@ -86,12 +92,24 @@ void CScene::disown() CStorageContainer::disown(); } +uint16 CScene::version() +{ + nlassert(Chunks.size() == 1); + return Chunks.begin()->first; +} + +CSceneClassContainer *CScene::container() +{ + nlassert(Chunks.size() == 1); + return static_cast(Chunks.begin()->second); +} + IStorageObject *CScene::createChunkById(uint16 id, bool container) { if (container) { // Return the scene class container. There can be only one. - return new CSceneClassContainer(); + return new CSceneClassContainer(m_SceneClassRegistry, m_DllDirectory, m_ClassDirectory3); } return CStorageContainer::createChunkById(id, container); } @@ -100,7 +118,7 @@ IStorageObject *CScene::createChunkById(uint16 id, bool container) //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -CSceneClassContainer::CSceneClassContainer() +CSceneClassContainer::CSceneClassContainer(const CSceneClassRegistry *sceneClassRegistry, CDllDirectory *dllDirectory, CClassDirectory3 *classDirectory3) : m_SceneClassRegistry(sceneClassRegistry), m_DllDirectory(dllDirectory), m_ClassDirectory3(classDirectory3) { } @@ -142,13 +160,20 @@ void CSceneClassContainer::disown() IStorageObject *CSceneClassContainer::createChunkById(uint16 id, bool container) { - if (container) + nldebug("Scene class id %x (%i)", (uint32)id, (uint32)id); + const CClassEntry *classEntry = m_ClassDirectory3->get(id); + CSceneClass *sceneClass = m_SceneClassRegistry->create(classEntry->classId()); + if (sceneClass) { - // TODO: Check the class registry. - // Return default unknown scene class. - return new CSceneClass(); + return static_cast(sceneClass); } - return CStorageContainer::createChunkById(id, container); + else + { + // Create an unknown scene class + const CDllEntry *dllEntry = m_DllDirectory->get(classEntry->dllIndex()); + return static_cast(new CSceneClassUnknown(dllEntry, classEntry)); + } + throw EStorage("Bad scene class id"); } //////////////////////////////////////////////////////////////////////// diff --git a/code/nel/tools/pipeline/max/scene.h b/code/nel/tools/pipeline/max/scene.h index 54e7e1d11..e699eb12f 100644 --- a/code/nel/tools/pipeline/max/scene.h +++ b/code/nel/tools/pipeline/max/scene.h @@ -42,6 +42,14 @@ namespace PIPELINE { namespace MAX { +// Registry containing available scene classes +class CSceneClassRegistry; + +// Storage +class CDllDirectory; +class CClassDirectory3; +class CSceneClassContainer; + /** * \brief CScene * \date 2012-08-19 19:25GMT @@ -51,7 +59,7 @@ namespace MAX { class CScene : public CStorageContainer { public: - CScene(); + CScene(const CSceneClassRegistry *sceneClassRegistry, CDllDirectory *dllDirectory, CClassDirectory3 *classDirectory3); virtual ~CScene(); // inherited @@ -62,9 +70,18 @@ public: virtual void build(uint16 version); virtual void disown(); + // public + uint16 version(); + CSceneClassContainer *container(); + protected: virtual IStorageObject *createChunkById(uint16 id, bool container); +private: + const CSceneClassRegistry *m_SceneClassRegistry; + CDllDirectory *m_DllDirectory; + CClassDirectory3 *m_ClassDirectory3; + }; /* class CScene */ /** @@ -76,7 +93,7 @@ protected: class CSceneClassContainer : public CStorageContainer { public: - CSceneClassContainer(); + CSceneClassContainer(const CSceneClassRegistry *sceneClassRegistry, CDllDirectory *dllDirectory, CClassDirectory3 *classDirectory3); virtual ~CSceneClassContainer(); // inherited @@ -90,6 +107,11 @@ public: protected: virtual IStorageObject *createChunkById(uint16 id, bool container); +private: + const CSceneClassRegistry *m_SceneClassRegistry; + CDllDirectory *m_DllDirectory; + CClassDirectory3 *m_ClassDirectory3; + }; /* class CSceneClassContainer */ } /* namespace MAX */ diff --git a/code/nel/tools/pipeline/max/scene_class_registry.cpp b/code/nel/tools/pipeline/max/scene_class_registry.cpp index 922f8afeb..16e3a71a5 100644 --- a/code/nel/tools/pipeline/max/scene_class_registry.cpp +++ b/code/nel/tools/pipeline/max/scene_class_registry.cpp @@ -51,6 +51,17 @@ CSceneClassRegistry::~CSceneClassRegistry() } +//void CSceneClassRegistry::add(const NLMISC::CClassId, const ISceneClassDesc *desc); +//void CSceneClassRegistry::remove(const NLMISC::CClassId); + +CSceneClass *CSceneClassRegistry::create(const NLMISC::CClassId classid) const +{ + return NULL; // TODO +} + +//void CSceneClassRegistry::destroy(CSceneClass *sceneClass) const; +//const CSceneClassRegistry::ISceneClassDesc *describe(const NLMISC::CClassId classid) const; + } /* namespace MAX */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/max_dump/main.cpp b/code/nel/tools/pipeline/max_dump/main.cpp index 4a1cca04a..6d46f3d2c 100644 --- a/code/nel/tools/pipeline/max_dump/main.cpp +++ b/code/nel/tools/pipeline/max_dump/main.cpp @@ -25,6 +25,7 @@ #include "../max/class_data.h" #include "../max/config.h" #include "../max/scene.h" +#include "../max/scene_class_registry.h" //static const char *filename = "/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max"; static const char *filename = "/home/kaetemi/source/minimax/GE_Acc_MikotoBaniere.max"; @@ -41,6 +42,10 @@ int main(int argc, char **argv) g_set_prgname(me); gsf_init(); + + PIPELINE::MAX::CSceneClassRegistry sceneClassRegistry; + + GsfInfile *infile; GError *error = NULL; GsfInput *src; @@ -132,6 +137,28 @@ int main(int argc, char **argv) //std::cout << "\n"; + std::cout << "\n"; + + + PIPELINE::MAX::CScene scene(&sceneClassRegistry, &dllDirectory, &classDirectory3); + input = gsf_infile_child_by_name(infile, "Scene"); + { + PIPELINE::MAX::CStorageStream instream(input); + scene.serial(instream); + } + 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.clean(); // cleanup unused file structure + scene.toString(std::cout); + std::cout << "\n"; + //classDirectory3.build(PIPELINE::MAX::VersionUnknown); + //classDirectory3.disown(); + //classDirectory3.toString(std::cout); + //std::cout << "\n"; + + /* GsfInput *input = gsf_infile_child_by_name(infile, streamname);