From e0840a9dda6e4f8ac3514d137bd191abafa4f777 Mon Sep 17 00:00:00 2001
From: D-AIRY <admin@ds-servers.com>
Date: Thu, 24 Dec 2020 13:26:37 +0300
Subject: [PATCH] Small improvements

---
 source/anim/DynamicModelProvider.cpp |  2 +-
 source/core/ResourceManager.cpp      | 25 +++++++++++--------------
 source/core/ResourceManager.h        | 10 +++++-----
 source/mtrl/MaterialSystem.cpp       | 17 +++++++----------
 source/mtrl/MaterialSystem.h         |  4 ++--
 5 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/source/anim/DynamicModelProvider.cpp b/source/anim/DynamicModelProvider.cpp
index cc06aaed5..bc5df76e7 100644
--- a/source/anim/DynamicModelProvider.cpp
+++ b/source/anim/DynamicModelProvider.cpp
@@ -300,7 +300,7 @@ void CDynamicModelProvider::onSharedModelReady(CDynamicModelShared *pShared)
 }
 void CDynamicModelProvider::onSharedModelRelease(CDynamicModelShared *pShared)
 {
-	m_mModels[pShared->getResource()] = NULL;
+	m_mModels.erase(pShared->getResource());
 }
 void CDynamicModelProvider::onSharedModelFeaturesChanged(CDynamicModelShared *pShared)
 {
diff --git a/source/core/ResourceManager.cpp b/source/core/ResourceManager.cpp
index 09e48e77e..0ff41aa56 100644
--- a/source/core/ResourceManager.cpp
+++ b/source/core/ResourceManager.cpp
@@ -92,8 +92,8 @@ CResourceManager::CResourceManager(IXCore *pCore):
 
 bool XMETHODCALLTYPE CResourceManager::getModel(const char *szName, IXResourceModel **ppOut, bool bForceReload)
 {
-	const AssotiativeArray<String, IXResourceModel*>::Node *pNode1;
-	if(!bForceReload && m_mpModels.KeyExists(szName, &pNode1) && (*pNode1->Val))
+	const Map<String, IXResourceModel*>::Node *pNode1;
+	if(!bForceReload && m_mpModels.KeyExists(szName, &pNode1))
 	{
 		(*pNode1->Val)->AddRef();
 		*ppOut = *pNode1->Val;
@@ -112,7 +112,7 @@ bool XMETHODCALLTYPE CResourceManager::getModel(const char *szName, IXResourceMo
 	strlwr(szLowcaseExt);
 
 	CResourceModel *pResource = NULL;
-	const AssotiativeArray<AAString, Array<IXModelLoader*>>::Node *pNode;
+	const Map<AAString, Array<IXModelLoader*>>::Node *pNode;
 	if(m_mapModelLoaders.KeyExists(AAString(szLowcaseExt), &pNode))
 	{
 		auto &aLoaders = *pNode->Val;
@@ -284,7 +284,7 @@ bool XMETHODCALLTYPE CResourceManager::getModelInfo(const char *szName, XModelIn
 	char *szLowcaseExt = strdupa(szExt);
 	strlwr(szLowcaseExt);
 
-	const AssotiativeArray<AAString, Array<IXModelLoader*>>::Node *pNode;
+	const Map<AAString, Array<IXModelLoader*>>::Node *pNode;
 	if(m_mapModelLoaders.KeyExists(AAString(szLowcaseExt), &pNode))
 	{
 		auto &aLoaders = *pNode->Val;
@@ -330,7 +330,7 @@ void CResourceManager::onResourceModelRelease(CResourceModel *pResource)
 {
 	if(pResource->getFileName())
 	{
-		m_mpModels[pResource->getFileName()] = NULL;
+		m_mpModels.erase(pResource->getFileName());
 	}
 }
 
@@ -382,16 +382,13 @@ const XFormatName* XMETHODCALLTYPE CResourceManager::getSoundSupportedFormat(UIN
 
 bool XMETHODCALLTYPE CResourceManager::getTexture(const char *szName, IXResourceTexture **ppOut, bool bForceReload)
 {
-	const AssotiativeArray<String, IXResourceTexture*>::Node *pNode1;
+	const Map<String, IXResourceTexture*>::Node *pNode1;
 	if(!bForceReload && m_mpTextures.KeyExists(szName, &pNode1))
 	{
 		IXResourceTexture *pOut = (*pNode1->Val);
-		if(pOut)
-		{
-			*ppOut = pOut;
-			pOut->AddRef();
-			return(true);
-		}
+		*ppOut = pOut;
+		pOut->AddRef();
+		return(true);
 	}
 
 	char *szFileName = strdupa(szName);
@@ -414,7 +411,7 @@ bool XMETHODCALLTYPE CResourceManager::getTexture(const char *szName, IXResource
 	char *szLowcaseExt = strdupa(szExt);
 	strlwr(szLowcaseExt);
 
-	const AssotiativeArray<AAString, Array<IXTextureLoader*>>::Node *pNode;
+	const Map<AAString, Array<IXTextureLoader*>>::Node *pNode;
 	if(m_mapTextureLoaders.KeyExists(AAString(szLowcaseExt), &pNode))
 	{
 		auto &aLoaders = *pNode->Val;
@@ -541,7 +538,7 @@ bool XMETHODCALLTYPE CResourceManager::getTextureInfo(const char *szName, XTextu
 	char *szLowcaseExt = strdupa(szExt);
 	strlwr(szLowcaseExt);
 
-	const AssotiativeArray<AAString, Array<IXTextureLoader*>>::Node *pNode;
+	const Map<AAString, Array<IXTextureLoader*>>::Node *pNode;
 	if(m_mapTextureLoaders.KeyExists(AAString(szLowcaseExt), &pNode))
 	{
 		auto &aLoaders = *pNode->Val;
diff --git a/source/core/ResourceManager.h b/source/core/ResourceManager.h
index b8c4c953c..89642c36c 100644
--- a/source/core/ResourceManager.h
+++ b/source/core/ResourceManager.h
@@ -50,7 +50,7 @@ public:
 		const char *szName = pTexture->getFileName();
 		if(szName)
 		{
-			m_mpTextures[szName] = NULL;
+			m_mpTextures.erase(szName);
 		}
 	}
 
@@ -60,14 +60,14 @@ public:
 protected:
 	IXCore *m_pCore;
 
-	AssotiativeArray<AAString, Array<IXModelLoader*>> m_mapModelLoaders;
-	AssotiativeArray<String, IXResourceModel*> m_mpModels;
+	Map<AAString, Array<IXModelLoader*>> m_mapModelLoaders;
+	Map<String, IXResourceModel*> m_mpModels;
 	
 	Array<XFormatName> m_aModelExts;
 
 
-	AssotiativeArray<AAString, Array<IXTextureLoader*>> m_mapTextureLoaders;
-	AssotiativeArray<String, IXResourceTexture*> m_mpTextures;
+	Map<AAString, Array<IXTextureLoader*>> m_mapTextureLoaders;
+	Map<String, IXResourceTexture*> m_mpTextures;
 
 	Array<XFormatName> m_aTextureExts;
 
diff --git a/source/mtrl/MaterialSystem.cpp b/source/mtrl/MaterialSystem.cpp
index a772e6dd3..6c395b8aa 100644
--- a/source/mtrl/MaterialSystem.cpp
+++ b/source/mtrl/MaterialSystem.cpp
@@ -109,7 +109,7 @@ void XMETHODCALLTYPE CMaterialSystem::loadMaterial(const char *szName, IXMateria
 	String sName(szName);
 
 	const AssotiativeArray<String, CMaterial*>::Node *pNode;
-	if(m_mapMaterials.KeyExists(sName, &pNode) && *(pNode->Val))
+	if(m_mapMaterials.KeyExists(sName, &pNode))
 	{
 		*ppMaterial = *(pNode->Val);
 		(*ppMaterial)->AddRef();
@@ -132,7 +132,7 @@ void XMETHODCALLTYPE CMaterialSystem::loadMaterial(const char *szName, IXMateria
 bool XMETHODCALLTYPE CMaterialSystem::getMaterial(const char *szName, IXMaterial **ppMaterial)
 {
 	const AssotiativeArray<String, CMaterial*>::Node *pNode;
-	if(m_mapMaterials.KeyExists(szName, &pNode) && *(pNode->Val))
+	if(m_mapMaterials.KeyExists(szName, &pNode))
 	{
 		*ppMaterial = *(pNode->Val);
 		(*ppMaterial)->AddRef();
@@ -176,10 +176,7 @@ void XMETHODCALLTYPE CMaterialSystem::reloadAll()
 {
 	for(AssotiativeArray<String, CMaterial*>::Iterator i = m_mapMaterials.begin(); i; ++i)
 	{
-		if(*(i.second))
-		{
-			loadMaterial(i.first->c_str(), *(i.second));
-		}
+		loadMaterial(i.first->c_str(), *(i.second));
 	}
 }
 
@@ -263,7 +260,7 @@ bool XMETHODCALLTYPE CMaterialSystem::loadTexture(const char *szName, IXTexture
 	String sName(szName);
 
 	const AssotiativeArray<String, CTexture*>::Node *pNode;
-	if(m_mpTextures.KeyExists(sName, &pNode) && *(pNode->Val))
+	if(m_mpTextures.KeyExists(sName, &pNode))
 	{
 		*ppTexture = *(pNode->Val);
 		(*ppTexture)->AddRef();
@@ -414,7 +411,7 @@ bool XMETHODCALLTYPE CMaterialSystem::loadTexture(const char *szName, IXTexture
 bool XMETHODCALLTYPE CMaterialSystem::getTexture(const char *szName, IXTexture **ppTexture)
 {
 	const AssotiativeArray<String, CTexture*>::Node *pNode;
-	if(m_mpTextures.KeyExists(szName, &pNode) && *(pNode->Val))
+	if(m_mpTextures.KeyExists(szName, &pNode))
 	{
 		*ppTexture = *(pNode->Val);
 		(*ppTexture)->AddRef();
@@ -660,7 +657,7 @@ void CMaterialSystem::onTextureRelease(CTexture *pTexture)
 {
 	assert(pTexture);
 
-	m_mpTextures[pTexture->getName()] = NULL;
+	m_mpTextures.erase(pTexture->getName());
 
 	m_poolTextures.Delete(pTexture);
 }
@@ -669,7 +666,7 @@ void CMaterialSystem::onMaterialRelease(CMaterial *pMaterial)
 {
 	assert(pMaterial);
 
-	m_mapMaterials[pMaterial->getName()] = NULL;
+	m_mapMaterials.erase(pMaterial->getName());
 }
 
 void CMaterialSystem::queueTextureUpload(CTexture *pTexture)
diff --git a/source/mtrl/MaterialSystem.h b/source/mtrl/MaterialSystem.h
index 445e8bed1..a4c2c4d8b 100644
--- a/source/mtrl/MaterialSystem.h
+++ b/source/mtrl/MaterialSystem.h
@@ -353,7 +353,7 @@ protected:
 	MemAlloc<CTexture> m_poolTextures;
 	Array<IXTextureProxy*> m_aTextureProxies;
 	AssotiativeArray<String, IXTextureFilter*> m_mapTextureFilters;
-	AssotiativeArray<String, CTexture*> m_mpTextures;
+	Map<String, CTexture*> m_mpTextures;
 	CConcurrentQueue<CTexture*> m_queueTextureToLoad;
 	IXTexture *m_pDefaultTexture = NULL;
 
@@ -366,7 +366,7 @@ protected:
 	Array<IXMaterialProxy*> m_aMaterialProxies;
 	AssotiativeArray<AAString, Array<MaterialLoader>> m_mapMaterialLoaders;
 	Array<XFormatName> m_aMaterialExts;
-	AssotiativeArray<String, CMaterial*> m_mapMaterials;
+	Map<String, CMaterial*> m_mapMaterials;
 
 	IEventChannel<XEventMaterialChanged> *m_pNotifyChannel = NULL;
 
-- 
GitLab