Add IsTextureRegistered, RegisterTexture, AdjustTextureID.

This commit is contained in:
Glenn Maynard
2003-06-04 22:32:48 +00:00
parent 09cf46a91e
commit 5d5bc97bc0
2 changed files with 48 additions and 11 deletions
+43 -9
View File
@@ -24,6 +24,16 @@
RageTextureManager* TEXTUREMAN = NULL; RageTextureManager* TEXTUREMAN = NULL;
static CString GetExtension(const CString &fn)
{
CString sDir, sFName, sExt;
splitpath( fn, sDir, sFName, sExt );
sExt.MakeLower();
return sExt;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// constructor/destructor // constructor/destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -53,16 +63,42 @@ void RageTextureManager::Update( float fDeltaTime )
} }
} }
//----------------------------------------------------------------------------- void RageTextureManager::AdjustTextureID(RageTextureID &ID) const
// Load/Unload textures from disk {
//----------------------------------------------------------------------------- if( ID.iColorDepth == -1 )
ID.iColorDepth = m_iTextureColorDepth;
ID.iMaxSize = min( ID.iMaxSize, m_iMaxTextureResolution );
}
/* If you've set up a texture yourself, register it here so it can be referenced
* and deleted by an ID. This takes ownership. They're kept around until the
* ne*/
bool RageTextureManager::IsTextureRegistered( RageTextureID ID ) const
{
AdjustTextureID(ID);
return m_mapPathToTexture.find(ID) != m_mapPathToTexture.end();
}
void RageTextureManager::RegisterTexture( RageTextureID ID, RageTexture *pTexture )
{
AdjustTextureID(ID);
/* Make sure we don't already have a texture with this ID. If we do, the
* caller should have used it. */
std::map<RageTextureID, RageTexture*>::iterator p = m_mapPathToTexture.find(ID);
if(p != m_mapPathToTexture.end())
/* Oops, found the texture. */
RageException::Throw("Custom texture \"%s\" already registered!", ID.filename.c_str());
m_mapPathToTexture[ID] = pTexture;
}
// Load and unload textures from disk.
RageTexture* RageTextureManager::LoadTexture( RageTextureID ID ) RageTexture* RageTextureManager::LoadTexture( RageTextureID ID )
{ {
Checkpoint( ssprintf( "RageTextureManager::LoadTexture(%s).", ID.filename.c_str() ) ); Checkpoint( ssprintf( "RageTextureManager::LoadTexture(%s).", ID.filename.c_str() ) );
if( ID.iColorDepth == -1 ) AdjustTextureID(ID);
ID.iColorDepth = m_iTextureColorDepth;
ID.iMaxSize = min( ID.iMaxSize, m_iMaxTextureResolution );
/* We could have two copies of the same bitmap if there are equivalent but /* We could have two copies of the same bitmap if there are equivalent but
* different paths, e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp". */ * different paths, e.g. "Bitmaps\me.bmp" and "..\Rage PC Edition\Bitmaps\me.bmp". */
@@ -77,9 +113,7 @@ RageTexture* RageTextureManager::LoadTexture( RageTextureID ID )
} }
// The texture is not already loaded. Load it. // The texture is not already loaded. Load it.
CString sDir, sFName, sExt; const CString sExt = GetExtension(ID.filename);
splitpath( ID.filename, sDir, sFName, sExt );
sExt.MakeLower();
RageTexture* pTexture; RageTexture* pTexture;
if( sExt == ".avi" || sExt == ".mpg" || sExt == ".mpeg" ) if( sExt == ".avi" || sExt == ".mpg" || sExt == ".mpeg" )
+4 -1
View File
@@ -26,6 +26,8 @@ public:
~RageTextureManager(); ~RageTextureManager();
RageTexture* LoadTexture( RageTextureID ID ); RageTexture* LoadTexture( RageTextureID ID );
bool IsTextureRegistered( RageTextureID ID ) const;
void RegisterTexture( RageTextureID ID, RageTexture *p );
void CacheTexture( RageTextureID ID ); void CacheTexture( RageTextureID ID );
void UnloadTexture( RageTexture *t ); void UnloadTexture( RageTexture *t );
void ReloadAll(); void ReloadAll();
@@ -43,7 +45,8 @@ public:
void InvalidateTextures(); void InvalidateTextures();
void RageTextureManager::DiagnosticOutput() const; void AdjustTextureID(RageTextureID &ID) const;
void DiagnosticOutput() const;
protected: protected:
void DeleteTexture( RageTexture *t ); void DeleteTexture( RageTexture *t );