Changed: #1440 Take both superclassid and classid into account in the scene class registry

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 12690604ee
commit 228b787513

@ -171,7 +171,7 @@ IStorageObject *CSceneClassContainer::createChunkById(uint16 id, bool container)
// return static_cast<IStorageObject *>(new CSceneClassUnknown<CSceneClass>(dllEntry, classEntry)); // return static_cast<IStorageObject *>(new CSceneClassUnknown<CSceneClass>(dllEntry, classEntry));
} }
const CClassEntry *classEntry = m_ClassDirectory3->get(id); 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) if (sceneClass)
{ {
return static_cast<IStorageObject *>(sceneClass); return static_cast<IStorageObject *>(sceneClass);

@ -70,14 +70,16 @@ CSceneClassRegistry::~CSceneClassRegistry()
void CSceneClassRegistry::add(const ISceneClassDesc *desc) void CSceneClassRegistry::add(const ISceneClassDesc *desc)
{ {
if (m_ClassDescriptions.find(desc->classId()) != m_ClassDescriptions.end()) { nlerror("Already added this class to the registry"); return; } TKey key(desc->superClassId(), desc->classId());
m_ClassDescriptions[desc->classId()] = desc; 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; } TKey key(superClassId, classId);
m_ClassDescriptions.erase(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 /// Add a superclass to the registry
@ -96,10 +98,11 @@ void CSceneClassRegistry::remove(const TSClassId superClassId)
} }
/// Create a class by class id /// 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; } TKey key(superClassId, classId);
return m_ClassDescriptions.find(classId)->second->create(); 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 /// 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 /// 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; } TKey key(superClassId, classId);
return m_ClassDescriptions.find(classId)->second; 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;
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

@ -55,7 +55,7 @@ public:
/// Add a class to the registry /// Add a class to the registry
void add(const ISceneClassDesc *desc); void add(const ISceneClassDesc *desc);
/// Remove a class from the registry /// 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 /// Add a superclass to the registry
void add(const ISuperClassDesc *desc); void add(const ISuperClassDesc *desc);
@ -63,7 +63,7 @@ public:
void remove(const TSClassId superClassId); void remove(const TSClassId superClassId);
/// Create a class by class id /// 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 /// 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; 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; void destroy(CSceneClass *sceneClass) const;
/// Return the description of a class by class id /// 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: private:
std::map<NLMISC::CClassId, const ISceneClassDesc *> 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<TKey, const ISceneClassDesc *> m_ClassDescriptions;
std::map<TSClassId, const ISuperClassDesc *> m_SuperClassDescriptions; std::map<TSClassId, const ISuperClassDesc *> m_SuperClassDescriptions;
}; /* class CSceneClassRegistry */ }; /* class CSceneClassRegistry */

Loading…
Cancel
Save