If UTDSeconds is 0, unload unused textures immediately; this makes
sure we don't keep them around for an extra screen anyway.
This commit is contained in:
@@ -105,39 +105,18 @@ bool RageTextureManager::IsTextureLoaded( CString sTexturePath )
|
|||||||
return m_mapPathToTexture.find(sTexturePath) != m_mapPathToTexture.end();
|
return m_mapPathToTexture.find(sTexturePath) != m_mapPathToTexture.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageTextureManager::UnloadTexture( CString sTexturePath )
|
void RageTextureManager::GCTextures()
|
||||||
{
|
{
|
||||||
sTexturePath.MakeLower();
|
/* If m_iSecondsBeforeUnload is 0, then we'll unload textures immediately when
|
||||||
|
* they're no longer needed, to use as little extra memory as possible, so don't
|
||||||
|
* bother checking for expired textures here. */
|
||||||
|
if(!m_iSecondsBeforeUnload) return;
|
||||||
|
|
||||||
// LOG->Trace( "RageTextureManager::UnloadTexture(%s).", sTexturePath );
|
static int timeLastGarbageCollect = time(NULL);
|
||||||
|
if( timeLastGarbageCollect+m_iSecondsBeforeUnload/2 > time(NULL) )
|
||||||
if( sTexturePath == "" )
|
|
||||||
{
|
|
||||||
//LOG->Trace( "RageTextureManager::UnloadTexture(): tried to Unload a blank texture." );
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
RageTexture* pTexture;
|
|
||||||
|
|
||||||
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--;
|
|
||||||
pTexture->m_iTimeOfLastUnload = time(NULL);
|
|
||||||
ASSERT( pTexture->m_iRefCount >= 0 );
|
|
||||||
if( pTexture->m_iRefCount == 0 && pTexture->IsAMovie() ) // always unload if a movie so we don't waste time decoding
|
|
||||||
{
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search for old textures with refcount==0 to unload
|
// Search for old textures with refcount==0 to unload
|
||||||
static int timeLastGarbageCollect = time(NULL);
|
|
||||||
if( timeLastGarbageCollect+m_iSecondsBeforeUnload/2 < time(NULL) )
|
|
||||||
{
|
|
||||||
LOG->Trace("Performing texture garbage collection");
|
LOG->Trace("Performing texture garbage collection");
|
||||||
timeLastGarbageCollect = time(NULL);
|
timeLastGarbageCollect = time(NULL);
|
||||||
|
|
||||||
@@ -150,7 +129,7 @@ void RageTextureManager::UnloadTexture( CString sTexturePath )
|
|||||||
CString sPath = j->first;
|
CString sPath = j->first;
|
||||||
RageTexture* pTexture = j->second;
|
RageTexture* pTexture = j->second;
|
||||||
if( pTexture->m_iRefCount==0 &&
|
if( pTexture->m_iRefCount==0 &&
|
||||||
pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload <= time(NULL) )
|
pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload < time(NULL) )
|
||||||
{
|
{
|
||||||
SAFE_DELETE( pTexture ); // free the texture
|
SAFE_DELETE( pTexture ); // free the texture
|
||||||
m_mapPathToTexture.erase(j); // and remove the key in the map
|
m_mapPathToTexture.erase(j); // and remove the key in the map
|
||||||
@@ -159,6 +138,45 @@ void RageTextureManager::UnloadTexture( CString sTexturePath )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RageTextureManager::UnloadTexture( CString sTexturePath )
|
||||||
|
{
|
||||||
|
sTexturePath.MakeLower();
|
||||||
|
|
||||||
|
// LOG->Trace( "RageTextureManager::UnloadTexture(%s).", sTexturePath );
|
||||||
|
|
||||||
|
if( sTexturePath == "" )
|
||||||
|
{
|
||||||
|
//LOG->Trace( "RageTextureManager::UnloadTexture(): tried to Unload a blank texture." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
RageTexture* pTexture = p->second;
|
||||||
|
pTexture->m_iRefCount--;
|
||||||
|
pTexture->m_iTimeOfLastUnload = time(NULL);
|
||||||
|
ASSERT( pTexture->m_iRefCount >= 0 );
|
||||||
|
|
||||||
|
/* Always unload movies, so we don't waste time decoding.
|
||||||
|
*
|
||||||
|
* Actually, multiple refs to a movie won't work; they should play independently,
|
||||||
|
* but they'll actually share settings. Not worth fixing, since we don't currently
|
||||||
|
* using movies for anything except BGAs (though we could).
|
||||||
|
*
|
||||||
|
* Also, if texture caching is off, just remove it now instead of doing
|
||||||
|
* garbage collection. */
|
||||||
|
if( pTexture->m_iRefCount == 0 &&
|
||||||
|
(pTexture->IsAMovie() || !m_iSecondsBeforeUnload ))
|
||||||
|
{
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
GCTextures();
|
||||||
|
|
||||||
//LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath, pTexture->m_iRefCount );
|
//LOG->Trace( "RageTextureManager: '%s' will not be deleted. It still has %d references.", sTexturePath, pTexture->m_iRefCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +187,14 @@ void RageTextureManager::ReloadAll()
|
|||||||
{
|
{
|
||||||
RageTexture* pTexture = i->second;
|
RageTexture* pTexture = i->second;
|
||||||
|
|
||||||
// this is not entirely correct. Hints are lost!
|
// this is not entirely correct. Hints are lost! XXX
|
||||||
pTexture->Reload( m_iMaxTextureSize, m_iTextureColorDepth, 0 );
|
pTexture->Reload( m_iMaxTextureSize, m_iTextureColorDepth, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageTextureManager::SetPrefs( int iMaxSize, int iTextureColorDepth, int iSecondsBeforeUnload )
|
void RageTextureManager::SetPrefs( int iMaxSize, int iTextureColorDepth, int iSecondsBeforeUnload )
|
||||||
{
|
{
|
||||||
m_iSecondsBeforeUnload = max( iSecondsBeforeUnload, 1 );
|
m_iSecondsBeforeUnload = iSecondsBeforeUnload;
|
||||||
ASSERT( m_iSecondsBeforeUnload > 0 );
|
|
||||||
if( iMaxSize == m_iMaxTextureSize && iTextureColorDepth == m_iTextureColorDepth )
|
if( iMaxSize == m_iMaxTextureSize && iTextureColorDepth == m_iTextureColorDepth )
|
||||||
return;
|
return;
|
||||||
m_iMaxTextureSize = iMaxSize;
|
m_iMaxTextureSize = iMaxSize;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
int GetTextureColorDepth() { return m_iTextureColorDepth; };
|
int GetTextureColorDepth() { return m_iTextureColorDepth; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void GCTextures();
|
||||||
RageDisplay* m_pScreen;
|
RageDisplay* m_pScreen;
|
||||||
|
|
||||||
int m_iMaxTextureSize;
|
int m_iMaxTextureSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user