From 228b787513ee069ffb2d6a659645fd5afb07dd0a Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 22 Aug 2012 21:42:07 +0200 Subject: [PATCH] Changed: #1440 Take both superclassid and classid into account in the scene class registry --HG-- branch : build_pipeline_v3 --- code/nel/tools/pipeline/max/scene.cpp | 2 +- .../pipeline/max/scene_class_registry.cpp | 66 +++++++++++++++---- .../tools/pipeline/max/scene_class_registry.h | 18 +++-- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/code/nel/tools/pipeline/max/scene.cpp b/code/nel/tools/pipeline/max/scene.cpp index 87fb4f115..377c4485d 100644 --- a/code/nel/tools/pipeline/max/scene.cpp +++ b/code/nel/tools/pipeline/max/scene.cpp @@ -171,7 +171,7 @@ IStorageObject *CSceneClassContainer::createChunkById(uint16 id, bool container) // return static_cast(new CSceneClassUnknown(dllEntry, classEntry)); } const CClassEntry *classEntry = m_ClassDirectory3->get(id); - CSceneClass *sceneClass = m_SceneClassRegistry->create(classEntry->classId()); + CSceneClass *sceneClass = m_SceneClassRegistry->create(classEntry->superClassId(), classEntry->classId()); if (sceneClass) { return static_cast(sceneClass); diff --git a/code/nel/tools/pipeline/max/scene_class_registry.cpp b/code/nel/tools/pipeline/max/scene_class_registry.cpp index d7e780bf2..8f0bb31b1 100644 --- a/code/nel/tools/pipeline/max/scene_class_registry.cpp +++ b/code/nel/tools/pipeline/max/scene_class_registry.cpp @@ -70,14 +70,16 @@ CSceneClassRegistry::~CSceneClassRegistry() void CSceneClassRegistry::add(const ISceneClassDesc *desc) { - if (m_ClassDescriptions.find(desc->classId()) != m_ClassDescriptions.end()) { nlerror("Already added this class to the registry"); return; } - m_ClassDescriptions[desc->classId()] = desc; + TKey key(desc->superClassId(), desc->classId()); + if (m_ClassDescriptions.find(key) != m_ClassDescriptions.end()) { nlerror("Already added this class to the registry"); return; } + m_ClassDescriptions[key] = desc; } -void CSceneClassRegistry::remove(const NLMISC::CClassId classId) +void CSceneClassRegistry::remove(const TSClassId superClassId, const NLMISC::CClassId classId) { - if (m_ClassDescriptions.find(classId) == m_ClassDescriptions.end()) { nlwarning("Try to remove class that is not found"); return; } - m_ClassDescriptions.erase(classId); + TKey key(superClassId, classId); + if (m_ClassDescriptions.find(key) == m_ClassDescriptions.end()) { nlwarning("Try to remove class that is not found"); return; } + m_ClassDescriptions.erase(key); } /// Add a superclass to the registry @@ -96,10 +98,11 @@ void CSceneClassRegistry::remove(const TSClassId superClassId) } /// Create a class by class id -CSceneClass *CSceneClassRegistry::create(const NLMISC::CClassId classId) const +CSceneClass *CSceneClassRegistry::create(const TSClassId superClassId, const NLMISC::CClassId classId) const { - if (m_ClassDescriptions.find(classId) == m_ClassDescriptions.end()) { /* nldebug("Try to create class that does not exist"); */ return NULL; } - return m_ClassDescriptions.find(classId)->second->create(); + TKey key(superClassId, classId); + if (m_ClassDescriptions.find(key) == m_ClassDescriptions.end()) { /* nldebug("Try to create class that does not exist"); */ return NULL; } + return m_ClassDescriptions.find(key)->second->create(); } /// Create an unknown class by superclass id @@ -116,10 +119,51 @@ void CSceneClassRegistry::destroy(CSceneClass *sceneClass) const } /// Return the description of a class by class id -const ISceneClassDesc *CSceneClassRegistry::describe(const NLMISC::CClassId classId) const +const ISceneClassDesc *CSceneClassRegistry::describe(const TSClassId superClassId, const NLMISC::CClassId classId) const { - if (m_ClassDescriptions.find(classId) == m_ClassDescriptions.end()) { nldebug("Try to describe class that does not exist"); return NULL; } - return m_ClassDescriptions.find(classId)->second; + TKey key(superClassId, classId); + if (m_ClassDescriptions.find(key) == m_ClassDescriptions.end()) { nldebug("Try to describe class that does not exist"); return NULL; } + return m_ClassDescriptions.find(key)->second; +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +CSceneClassRegistry::TKey::TKey(TSClassId superClassId, NLMISC::CClassId classId) : SuperClassId(superClassId), ClassId(classId) +{ + +} + +bool CSceneClassRegistry::TKey::operator<(const CSceneClassRegistry::TKey &right) const +{ + if (SuperClassId < right.SuperClassId) + return true; + if (SuperClassId > right.SuperClassId) + return false; + if (ClassId < right.ClassId) + return true; + if (ClassId > right.ClassId) + return false; + return false; +} + +bool CSceneClassRegistry::TKey::operator>(const CSceneClassRegistry::TKey &right) const +{ + if (SuperClassId > right.SuperClassId) + return true; + if (SuperClassId < right.SuperClassId) + return false; + if (ClassId > right.ClassId) + return true; + if (ClassId < right.ClassId) + return false; + return false; +} + +bool CSceneClassRegistry::TKey::operator==(const CSceneClassRegistry::TKey &right) const +{ + return ClassId == right.ClassId && SuperClassId == right.SuperClassId; } //////////////////////////////////////////////////////////////////////// diff --git a/code/nel/tools/pipeline/max/scene_class_registry.h b/code/nel/tools/pipeline/max/scene_class_registry.h index 1833c0723..bff8b658e 100644 --- a/code/nel/tools/pipeline/max/scene_class_registry.h +++ b/code/nel/tools/pipeline/max/scene_class_registry.h @@ -55,7 +55,7 @@ public: /// Add a class to the registry void add(const ISceneClassDesc *desc); /// Remove a class from the registry - void remove(const NLMISC::CClassId classId); + void remove(TSClassId superClassId, const NLMISC::CClassId classId); /// Add a superclass to the registry void add(const ISuperClassDesc *desc); @@ -63,7 +63,7 @@ public: void remove(const TSClassId superClassId); /// Create a class by class id - CSceneClass *create(const NLMISC::CClassId classId) const; + CSceneClass *create(TSClassId superClassId, const NLMISC::CClassId classId) const; /// Create an unknown class by superclass id CSceneClass *createUnknown(TSClassId superClassId, const NLMISC::CClassId classId, const ucstring &displayName, const ucstring &dllFilename, const ucstring &dllDescription) const; @@ -72,10 +72,20 @@ public: void destroy(CSceneClass *sceneClass) const; /// Return the description of a class by class id - const ISceneClassDesc *describe(const NLMISC::CClassId classId) const; + const ISceneClassDesc *describe(TSClassId superClassId, const NLMISC::CClassId classId) const; private: - std::map m_ClassDescriptions; + struct TKey + { + TKey(TSClassId superClassId, NLMISC::CClassId classId); + TSClassId SuperClassId; + NLMISC::CClassId ClassId; + bool operator<(const TKey &right) const; + bool operator>(const TKey &right) const; + bool operator==(const TKey &right) const; + }; + + std::map m_ClassDescriptions; std::map m_SuperClassDescriptions; }; /* class CSceneClassRegistry */