Switch remaining CMaps to std::map.

This commit is contained in:
Glenn Maynard
2002-09-07 08:20:10 +00:00
parent 5041ee2159
commit 2e3cde821b
4 changed files with 55 additions and 83 deletions
+22 -37
View File
@@ -32,19 +32,13 @@ FontManager::FontManager()
FontManager::~FontManager()
{
// delete all textures
POSITION pos = m_mapPathToFont.GetStartPosition();
CString sFontFilePath;
Font* pFont;
while( pos != NULL ) // iterate over all k/v pairs in map
for( std::map<CString, Font*>::iterator i = m_mapPathToFont.begin();
i != m_mapPathToFont.end(); ++i)
{
m_mapPathToFont.GetNextAssoc( pos, sFontFilePath, pFont );
LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", sFontFilePath, pFont->m_iRefCount );
Font* pFont = i->second;
LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", i->first, pFont->m_iRefCount );
SAFE_DELETE( pFont );
}
m_mapPathToFont.RemoveAll();
}
@@ -65,9 +59,10 @@ Font* FontManager::LoadFont( CString sFontOrTextureFilePath, CString sChars )
Font* pFont = NULL;
if( m_mapPathToFont.Lookup( sFontOrTextureFilePath, pFont ) ) // if the texture already exists in the map
{
std::map<CString, Font*>::iterator p = m_mapPathToFont.find(sFontOrTextureFilePath);
if(p != m_mapPathToFont.end()) {
// LOG->Trace( ssprintf("FontManager: The Font '%s' now has %d references.", sFontFilePath, pFont->m_iRefCount) );
pFont=p->second;
pFont->m_iRefCount++;
}
else // the texture is not already loaded
@@ -82,7 +77,7 @@ Font* FontManager::LoadFont( CString sFontOrTextureFilePath, CString sChars )
// LOG->Trace( "FontManager: Loading '%s' from disk.", sFontFilePath);
m_mapPathToFont.SetAt( sFontOrTextureFilePath, pFont );
m_mapPathToFont[sFontOrTextureFilePath] = pFont;
}
return pFont;
@@ -93,12 +88,7 @@ bool FontManager::IsFontLoaded( CString sFontFilePath )
{
sFontFilePath.MakeLower();
Font* pFont;
if( m_mapPathToFont.Lookup( sFontFilePath, pFont ) ) // if the texture exists in the map
return true;
else
return false;
return m_mapPathToFont.find(sFontFilePath) != m_mapPathToFont.end();
}
void FontManager::UnloadFont( CString sFontFilePath )
@@ -114,25 +104,20 @@ void FontManager::UnloadFont( CString sFontFilePath )
}
Font* pFont;
if( m_mapPathToFont.Lookup( sFontFilePath, pFont ) ) // if the texture exists in the map
{
pFont->m_iRefCount--;
if( pFont->m_iRefCount == 0 ) // there are no more references to this texture
{
// LOG->Trace( "FontManager: '%s' will be deleted. It has %d references.", sFontFilePath, pFont->m_iRefCount );
SAFE_DELETE( pFont ); // free the texture
m_mapPathToFont.RemoveKey( sFontFilePath ); // and remove the key in the map
}
else
{
// LOG->Trace( ssprintf("FontManager: '%s' will not be deleted. It still has %d references.", sFontFilePath, pFont->m_iRefCount) );
}
}
else // lookup failed
{
std::map<CString, Font*>::iterator p = m_mapPathToFont.find(sFontFilePath);
if(p == m_mapPathToFont.end())
throw RageException( ssprintf("Tried to Unload a font that wasn't loaded. '%s'", sFontFilePath) );
pFont=p->second;
pFont->m_iRefCount--;
if( pFont->m_iRefCount != 0 )
{
// LOG->Trace( ssprintf("FontManager: '%s' will not be deleted. It still has %d references.", sFontFilePath, pFont->m_iRefCount) );
return;
}
// There are no more references to this texture.
// LOG->Trace( "FontManager: '%s' will be deleted. It has %d references.", sFontFilePath, pFont->m_iRefCount );
SAFE_DELETE( pFont ); // free the texture
m_mapPathToFont.erase( p ); // and remove the key in the map
}
+2 -1
View File
@@ -12,6 +12,7 @@
#include "Font.h"
#include <map>
//-----------------------------------------------------------------------------
// FontManager Class Declarations
@@ -28,7 +29,7 @@ public:
protected:
// map from file name to a texture holder
CTypedPtrMap<CMapStringToPtr, CString, Font*> m_mapPathToFont;
std::map<CString, Font*> m_mapPathToFont;
};
extern FontManager* FONT; // global and accessable from anywhere in our program
+29 -44
View File
@@ -21,7 +21,6 @@
#include "RageLog.h"
#include "RageException.h"
RageTextureManager* TEXTUREMAN = NULL;
//-----------------------------------------------------------------------------
@@ -37,20 +36,13 @@ RageTextureManager::RageTextureManager( RageDisplay* pScreen )
RageTextureManager::~RageTextureManager()
{
// delete all textures
POSITION pos = m_mapPathToTexture.GetStartPosition();
while( pos != NULL ) // iterate over all k/v pairs in map
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i)
{
RageTexture* pTexture;
CString sPath;
m_mapPathToTexture.GetNextAssoc( pos, sPath, pTexture );
LOG->Trace( "TEXTUREMAN LEAK: '%s', RefCount = %d.", sPath, pTexture->m_iRefCount );
RageTexture* pTexture = i->second;
LOG->Trace( "TEXTUREMAN LEAK: '%s', RefCount = %d.", i->first, pTexture->m_iRefCount );
SAFE_DELETE( pTexture );
}
m_mapPathToTexture.RemoveAll();
}
@@ -71,8 +63,10 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, bool bForceR
// of the same bitmap if there are equivalent but different paths
// (e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp" ).
if( m_mapPathToTexture.Lookup( sTexturePath, pTexture ) ) // if the texture already exists in the map
{
std::map<CString, RageTexture*>::iterator p = m_mapPathToTexture.find(sTexturePath);
if(p != m_mapPathToTexture.end()) {
pTexture = p->second;
pTexture->m_iRefCount++;
if( bForceReload )
pTexture->Reload( m_iMaxTextureSize, m_iTextureColorDepth, iMipMaps, iAlphaBits, bDither, bStretch );
@@ -93,7 +87,7 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath, bool bForceR
LOG->Trace( "RageTextureManager: Finished loading '%s'.", sTexturePath );
m_mapPathToTexture.SetAt( sTexturePath, pTexture );
m_mapPathToTexture[sTexturePath] = pTexture;
}
// LOG->Trace( "Display: %.2f KB video memory left", DISPLAY->GetDevice()->GetAvailableTextureMem()/1000000.0f );
@@ -106,12 +100,7 @@ bool RageTextureManager::IsTextureLoaded( CString sTexturePath )
{
sTexturePath.MakeLower();
RageTexture* pTexture;
if( m_mapPathToTexture.Lookup( sTexturePath, pTexture ) ) // if the texture exists in the map
return true;
else
return false;
return m_mapPathToTexture.find(sTexturePath) != m_mapPathToTexture.end();
}
void RageTextureManager::UnloadTexture( CString sTexturePath )
@@ -128,36 +117,32 @@ void RageTextureManager::UnloadTexture( CString sTexturePath )
RageTexture* pTexture;
if( m_mapPathToTexture.Lookup( sTexturePath, pTexture ) ) // if the texture exists in the map
{
pTexture->m_iRefCount--;
if( pTexture->m_iRefCount == 0 ) // there are no more references to this texture
{
// LOG->Trace( "RageTextureManager: '%s' will be deleted. It has %d references.", sTexturePath, pTexture->m_iRefCount );
SAFE_DELETE( pTexture ); // free the texture
m_mapPathToTexture.RemoveKey( sTexturePath ); // and remove the key in the map
}
else
{
// LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath, pTexture->m_iRefCount );
}
}
else // texture not found
{
std::map<CString, RageTexture*>::iterator p = m_mapPathToTexture.find(sTexturePath);
if(p == m_mapPathToTexture.end())
throw RageException( "Tried to Unload texture '%s' that wasn't loaded.", sTexturePath );
}
pTexture = p->second;
pTexture->m_iRefCount--;
if( pTexture->m_iRefCount != 0 )
{
// LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath, pTexture->m_iRefCount );
return;
}
// There are no more references to this texture.
// LOG->Trace( "RageTextureManager: '%s' will be deleted. It has %d references.", sTexturePath, pTexture->m_iRefCount );
SAFE_DELETE( pTexture ); // free the texture
m_mapPathToTexture.erase(p); // and remove the key in the map
}
void RageTextureManager::ReloadAll()
{
for( POSITION pos = m_mapPathToTexture.GetStartPosition(); pos != NULL; )
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i)
{
CString sPath;
RageTexture* pTexture;
RageTexture* pTexture = i->second;
m_mapPathToTexture.GetNextAssoc( pos, sPath, pTexture );
pTexture->Reload( m_iMaxTextureSize, m_iTextureColorDepth, 0 ); // this not entirely correct. Hints are lost!
// this is not entirely correct. Hints are lost!
pTexture->Reload( m_iMaxTextureSize, m_iTextureColorDepth, 0 );
}
}
+2 -1
View File
@@ -11,6 +11,7 @@
*/
#include "RageTexture.h"
#include <map>
//-----------------------------------------------------------------------------
// RageTextureManager Class Declarations
@@ -45,7 +46,7 @@ protected:
DWORD m_iTextureColorDepth;
// map from file name to a texture holder
CTypedPtrMap<CMapStringToPtr, CString, RageTexture*> m_mapPathToTexture;
std::map<CString, RageTexture*> m_mapPathToTexture;
};
extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program