From d5098c84ce23c857167603d621414d4de460ea4f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 26 Mar 2004 10:15:18 +0000 Subject: [PATCH] move texture load policy into RageTextureID, so it can be set to volatile consistently for banners/backgrounds --- stepmania/src/Background.cpp | 4 ++-- stepmania/src/BannerCache.cpp | 2 +- stepmania/src/RageTexture.cpp | 1 - stepmania/src/RageTexture.h | 3 ++- stepmania/src/RageTextureID.cpp | 4 ++++ stepmania/src/RageTextureID.h | 6 ++++++ stepmania/src/RageTextureManager.cpp | 18 +++++++++--------- stepmania/src/RageTextureManager.h | 6 +++--- stepmania/src/Sprite.cpp | 7 +++++++ 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index 808871f41c..3ef2de496b 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -320,8 +320,8 @@ void Background::LoadFromSong( const Song* pSong ) /* Song backgrounds (even just background stills) can get very big; never keep them * in memory. */ - RageTexture::TexPolicy OldPolicy = TEXTUREMAN->GetDefaultTexturePolicy(); - TEXTUREMAN->SetDefaultTexturePolicy( RageTexture::TEX_VOLATILE ); + RageTextureID::TexPolicy OldPolicy = TEXTUREMAN->GetDefaultTexturePolicy(); + TEXTUREMAN->SetDefaultTexturePolicy( RageTextureID::TEX_VOLATILE ); TEXTUREMAN->DisableOddDimensionWarning(); diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index 6e218746c0..df04d4c852 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -261,8 +261,8 @@ RageTextureID BannerCache::LoadCachedBanner( CString BannerPath ) ID.filename.c_str(), src_width, src_height, img->w, img->h ); RageTexture *pTexture = new BannerTexture( ID, img, src_width, src_height ); + ID.Policy = RageTextureID::TEX_VOLATILE; TEXTUREMAN->RegisterTexture( ID, pTexture ); - pTexture->m_Policy = RageTexture::TEX_VOLATILE; TEXTUREMAN->UnloadTexture( pTexture ); return ID; diff --git a/stepmania/src/RageTexture.cpp b/stepmania/src/RageTexture.cpp index dc1bbab758..55412b1161 100644 --- a/stepmania/src/RageTexture.cpp +++ b/stepmania/src/RageTexture.cpp @@ -21,7 +21,6 @@ RageTexture::RageTexture( RageTextureID name ): // LOG->Trace( "RageTexture::RageTexture()" ); m_iRefCount = 1; - m_Policy = TEXTUREMAN->GetDefaultTexturePolicy(); m_bWasUsed = false; // SetActualID(); diff --git a/stepmania/src/RageTexture.h b/stepmania/src/RageTexture.h index 51857ee1b6..fdf518588e 100644 --- a/stepmania/src/RageTexture.h +++ b/stepmania/src/RageTexture.h @@ -64,7 +64,8 @@ public: int GetNumFrames() const { return m_iFramesWide*m_iFramesHigh; } /* Used by RageTextureManager. Order is important; see RageTextureManager.cpp. */ - enum TexPolicy { TEX_CACHED, TEX_VOLATILE, TEX_DEFAULT } m_Policy; + const RageTextureID::TexPolicy &GetPolicy() const { return m_ID.Policy; } + RageTextureID::TexPolicy &GetPolicy() { return m_ID.Policy; } int m_iRefCount; bool m_bWasUsed; diff --git a/stepmania/src/RageTextureID.cpp b/stepmania/src/RageTextureID.cpp index 8ac3aa5908..489e86f856 100644 --- a/stepmania/src/RageTextureID.cpp +++ b/stepmania/src/RageTextureID.cpp @@ -1,5 +1,6 @@ #include "global.h" #include "RageTextureID.h" +#include "RageTextureManager.h" void RageTextureID::Init() { @@ -12,6 +13,7 @@ void RageTextureID::Init() iColorDepth = -1; /* default */ bHotPinkColorKey = false; AdditionalTextureHints = ""; + Policy = TEXTUREMAN->GetDefaultTexturePolicy(); } bool RageTextureID::operator<(const RageTextureID &rhs) const @@ -27,6 +29,7 @@ bool RageTextureID::operator<(const RageTextureID &rhs) const COMP(bStretch); COMP(bHotPinkColorKey); COMP(AdditionalTextureHints); + // COMP(Policy); // don't do this #undef COMP return false; } @@ -45,5 +48,6 @@ bool RageTextureID::operator==(const RageTextureID &rhs) const EQUAL(bStretch) && EQUAL(bHotPinkColorKey) && EQUAL(AdditionalTextureHints); + // EQUAL(Policy); // don't do this } diff --git a/stepmania/src/RageTextureID.h b/stepmania/src/RageTextureID.h index c362200ac7..8c1988ac84 100644 --- a/stepmania/src/RageTextureID.h +++ b/stepmania/src/RageTextureID.h @@ -49,6 +49,12 @@ struct RageTextureID bool operator< (const RageTextureID &rhs) const; bool operator== (const RageTextureID &rhs) const; + /* Used by RageTextureManager. Order is important; see RageTextureManager.cpp. + * Note that this property is not considered for ordering/equality. Loading + * a texture with a different loading policy will reuse the same texture with + * a different policy. */ + enum TexPolicy { TEX_CACHED, TEX_VOLATILE, TEX_DEFAULT } Policy; + void Init(); RageTextureID() { Init(); } diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index b5a640a7e4..0f4cac7802 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -52,7 +52,7 @@ RageTextureManager* TEXTUREMAN = NULL; RageTextureManager::RageTextureManager() { m_iNoWarnAboutOddDimensions = 0; - m_TexturePolicy = RageTexture::TEX_DEFAULT; + m_TexturePolicy = RageTextureID::TEX_DEFAULT; m_bDelayedDelete = false; m_iMovieColorDepth = 16; m_iTextureColorDepth = 16; @@ -156,14 +156,14 @@ RageTexture* RageTextureManager::LoadTexture( RageTextureID ID ) void RageTextureManager::CacheTexture( RageTextureID ID ) { RageTexture* pTexture = LoadTextureInternal( ID ); - pTexture->m_Policy = min( pTexture->m_Policy, RageTexture::TEX_CACHED ); + pTexture->GetPolicy() = min( pTexture->GetPolicy(), RageTextureID::TEX_CACHED ); UnloadTexture( pTexture ); } void RageTextureManager::VolatileTexture( RageTextureID ID ) { RageTexture* pTexture = LoadTextureInternal( ID ); - pTexture->m_Policy = min( pTexture->m_Policy, RageTexture::TEX_VOLATILE ); + pTexture->GetPolicy() = min( pTexture->GetPolicy(), RageTextureID::TEX_VOLATILE ); UnloadTexture( pTexture ); } @@ -187,11 +187,11 @@ void RageTextureManager::UnloadTexture( RageTexture *t ) bDeleteThis = true; /* Delete normal textures immediately unless m_bDelayedDelete is is on. */ - if( t->m_Policy == RageTexture::TEX_DEFAULT && !m_bDelayedDelete ) + if( t->GetPolicy() == RageTextureID::TEX_DEFAULT && !m_bDelayedDelete ) bDeleteThis = true; /* Delete volatile textures after they've been used at least once. */ - if( t->m_Policy == RageTexture::TEX_VOLATILE && t->m_bWasUsed ) + if( t->GetPolicy() == RageTextureID::TEX_VOLATILE && t->m_bWasUsed ) bDeleteThis = true; if( bDeleteThis ) @@ -237,20 +237,20 @@ void RageTextureManager::GarbageCollect( GCType type ) bool bDeleteThis = false; if( type==screen_changed ) { - switch( t->m_Policy ) + switch( t->GetPolicy() ) { - case RageTexture::TEX_DEFAULT: + case RageTextureID::TEX_DEFAULT: /* If m_bDelayedDelete, wait until delayed_delete. If !m_bDelayedDelete, * it should have been deleted when it reached no references, but we * might have just changed the preference. */ if( !m_bDelayedDelete ) bDeleteThis = true; break; - case RageTexture::TEX_CACHED: + case RageTextureID::TEX_CACHED: if( !m_bDelayedDelete ) bDeleteThis = true; break; - case RageTexture::TEX_VOLATILE: + case RageTextureID::TEX_VOLATILE: bDeleteThis = true; break; default: ASSERT(0); diff --git a/stepmania/src/RageTextureManager.h b/stepmania/src/RageTextureManager.h index 1522ebc385..24b5c4c257 100644 --- a/stepmania/src/RageTextureManager.h +++ b/stepmania/src/RageTextureManager.h @@ -36,8 +36,8 @@ public: bool GetDelayedDelete() { return m_bDelayedDelete; }; int GetMaxTextureResolution() { return m_iMaxTextureResolution; }; - RageTexture::TexPolicy GetDefaultTexturePolicy() const { return m_TexturePolicy; } - void SetDefaultTexturePolicy( RageTexture::TexPolicy p ) { m_TexturePolicy = p; } + RageTextureID::TexPolicy GetDefaultTexturePolicy() const { return m_TexturePolicy; } + void SetDefaultTexturePolicy( RageTextureID::TexPolicy p ) { m_TexturePolicy = p; } // call this between Screens void DeleteCachedTextures() { GarbageCollect(screen_changed); } @@ -68,7 +68,7 @@ protected: std::map m_mapPathToTexture; int m_iNoWarnAboutOddDimensions; - RageTexture::TexPolicy m_TexturePolicy; + RageTextureID::TexPolicy m_TexturePolicy; }; extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index 86ca44347a..b7c758424d 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -54,6 +54,11 @@ RageTextureID Sprite::SongBGTexture( RageTextureID ID ) /* Song backgrounds are, by definition, in the background, so there's no need to keep alpha. */ ID.iAlphaBits = 0; + /* By default, song graphics are volatile: they're removed after one use. This + * is because some screens iteratively load and display lots of them (eg. ScreenSelectMusic,, + * ScreenEditMenu) one at a time, and we don't want to have hundreds of banners loaded at once. */ + ID.Policy = RageTextureID::TEX_VOLATILE; + // Don't we want to dither 16 bit textures at least? // ID.bDither = true; @@ -65,6 +70,8 @@ RageTextureID Sprite::SongBannerTexture( RageTextureID ID ) /* Song banners often have HOT PINK color keys. */ ID.bHotPinkColorKey = true; ID.bDither = true; + ID.Policy = RageTextureID::TEX_VOLATILE; + return ID; }