From 5d5bc97bc01b4f9d4dbc4a01cbdb217c382e5418 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 4 Jun 2003 22:32:48 +0000 Subject: [PATCH] Add IsTextureRegistered, RegisterTexture, AdjustTextureID. --- stepmania/src/RageTextureManager.cpp | 52 +++++++++++++++++++++++----- stepmania/src/RageTextureManager.h | 7 ++-- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index f18ae03f42..5eefc4ee17 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -24,6 +24,16 @@ RageTextureManager* TEXTUREMAN = NULL; +static CString GetExtension(const CString &fn) +{ + CString sDir, sFName, sExt; + splitpath( fn, sDir, sFName, sExt ); + sExt.MakeLower(); + + return sExt; +} + + //----------------------------------------------------------------------------- // constructor/destructor //----------------------------------------------------------------------------- @@ -53,16 +63,42 @@ void RageTextureManager::Update( float fDeltaTime ) } } -//----------------------------------------------------------------------------- -// Load/Unload textures from disk -//----------------------------------------------------------------------------- +void RageTextureManager::AdjustTextureID(RageTextureID &ID) const +{ + 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::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 ) { Checkpoint( ssprintf( "RageTextureManager::LoadTexture(%s).", ID.filename.c_str() ) ); - if( ID.iColorDepth == -1 ) - ID.iColorDepth = m_iTextureColorDepth; - ID.iMaxSize = min( ID.iMaxSize, m_iMaxTextureResolution ); + AdjustTextureID(ID); /* 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". */ @@ -77,9 +113,7 @@ RageTexture* RageTextureManager::LoadTexture( RageTextureID ID ) } // The texture is not already loaded. Load it. - CString sDir, sFName, sExt; - splitpath( ID.filename, sDir, sFName, sExt ); - sExt.MakeLower(); + const CString sExt = GetExtension(ID.filename); RageTexture* pTexture; if( sExt == ".avi" || sExt == ".mpg" || sExt == ".mpeg" ) diff --git a/stepmania/src/RageTextureManager.h b/stepmania/src/RageTextureManager.h index 1dfbd0ecdb..a70eb5a067 100644 --- a/stepmania/src/RageTextureManager.h +++ b/stepmania/src/RageTextureManager.h @@ -26,6 +26,8 @@ public: ~RageTextureManager(); RageTexture* LoadTexture( RageTextureID ID ); + bool IsTextureRegistered( RageTextureID ID ) const; + void RegisterTexture( RageTextureID ID, RageTexture *p ); void CacheTexture( RageTextureID ID ); void UnloadTexture( RageTexture *t ); void ReloadAll(); @@ -42,8 +44,9 @@ public: void DoDelayedDelete() { GarbageCollect(delayed_delete); } void InvalidateTextures(); - - void RageTextureManager::DiagnosticOutput() const; + + void AdjustTextureID(RageTextureID &ID) const; + void DiagnosticOutput() const; protected: void DeleteTexture( RageTexture *t );