From 057386420635172bd007b08c0b4849bc41668b49 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 15 Jun 2003 01:53:51 +0000 Subject: [PATCH] banner cache for group banners --- stepmania/src/BannerCache.cpp | 24 ++++++++++++--- stepmania/src/BannerCache.h | 1 + stepmania/src/FadingBanner.cpp | 54 +++++++++++++++++++--------------- stepmania/src/FadingBanner.h | 2 +- stepmania/src/Song.cpp | 2 +- stepmania/src/SongManager.cpp | 4 +++ 6 files changed, 58 insertions(+), 29 deletions(-) diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index 55880f6e63..bcf33508a2 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -65,7 +65,9 @@ void BannerCache::LoadBanner( CString BannerPath ) /* The file doesn't exist. It's possible that the banner cache file is * missing, so try to create it. Don't do this first, for efficiency. */ LOG->Trace( "Cached banner load of '%s' ('%s') failed, trying to cache ...", BannerPath.c_str(), CachePath.c_str() ); - CacheBanner( BannerPath ); + /* Skip the up-to-date check; it failed to load, so it can't be up + * to date. */ + CacheBannerInternal( BannerPath ); continue; } else @@ -279,22 +281,35 @@ void BannerCache::UncacheBanner( CString BannerPath ) } #endif + /* We write the cache even if we won't use it, so we don't have to recache everything * if the memory or settings change. */ void BannerCache::CacheBanner( CString BannerPath ) { + if( !DoesFileExist(BannerPath) ) + return; + const CString CachePath = GetBannerCachePath(BannerPath); - /* Check the full file hash. If it's the same, don't recache. */ - const unsigned FullHash = GetHashForFile( BannerPath ); + /* Check the full file hash. If it's the loaded and identical, don't recache. */ if( DoesFileExist(CachePath) ) { unsigned CurFullHash; + const unsigned FullHash = GetHashForFile( BannerPath ); if( BannerData.GetValueU( BannerPath, "FullHash", CurFullHash ) && CurFullHash == FullHash ) + { + /* It's identical. Just load it. */ + LoadBanner( BannerPath ); return; + } } + CacheBannerInternal( BannerPath ); +} + +void BannerCache::CacheBannerInternal( CString BannerPath ) +{ SDL_Surface *img = IMG_Load( BannerPath ); if(img == NULL) RageException::Throw( "BannerCache::CacheBanner: Couldn't load %s: %s", BannerPath.c_str(), SDL_GetError() ); @@ -386,6 +401,7 @@ void BannerCache::CacheBanner( CString BannerPath ) img = dst; } + const CString CachePath = GetBannerCachePath(BannerPath); mySDL_SaveSurface( img, CachePath ); if( PREFSMAN->m_bBannerCache ) @@ -408,7 +424,7 @@ void BannerCache::CacheBanner( CString BannerPath ) BannerData.SetValue ( BannerPath, "Path", CachePath ); BannerData.SetValueI( BannerPath, "Width", src_width ); BannerData.SetValueI( BannerPath, "Height", src_height ); - BannerData.SetValueU( BannerPath, "FullHash", FullHash ); + BannerData.SetValueU( BannerPath, "FullHash", GetHashForFile( BannerPath ) ); /* Remember this, so we can hint CroppedSprite. */ BannerData.SetValueB( BannerPath, "Rotated", WasRotatedBanner ); BannerData.WriteFile(); diff --git a/stepmania/src/BannerCache.h b/stepmania/src/BannerCache.h index 966e74d681..a96472d341 100644 --- a/stepmania/src/BannerCache.h +++ b/stepmania/src/BannerCache.h @@ -13,6 +13,7 @@ class BannerCache static CString GetBannerCachePath( CString BannerPath ); void UnloadAllBanners(); + void CacheBannerInternal( CString BannerPath ); public: BannerCache(); diff --git a/stepmania/src/FadingBanner.cpp b/stepmania/src/FadingBanner.cpp index e67a9cbde7..81b019cba5 100644 --- a/stepmania/src/FadingBanner.cpp +++ b/stepmania/src/FadingBanner.cpp @@ -85,7 +85,7 @@ void FadingBanner::BeforeChange() } /* If this returns false, the banner couldn't be loaded. */ -bool FadingBanner::LoadFromCachedBanner( const CString &path ) +void FadingBanner::LoadFromCachedBanner( const CString &path ) { /* No matter what we load, ensure we don't fade to a stale path. */ m_sPendingBanner = ""; @@ -95,25 +95,12 @@ bool FadingBanner::LoadFromCachedBanner( const CString &path ) /* The actual file is already cached. Use it. */ BeforeChange(); m_Banner[GetBackIndex()].Load( Banner::BannerTex(path) ); - return true; + return; } /* It's not loaded. Try to load the low quality version. */ RageTextureID ID = BANNERCACHE->LoadCachedBanner( path ); if( !TEXTUREMAN->IsTextureRegistered(ID) ) - return false; - - BeforeChange(); - m_Banner[GetBackIndex()].Load( ID ); - m_sPendingBanner = path; - m_PendingTimer.GetDeltaTime(); /* reset */ - - return true; -} - -void FadingBanner::LoadFromSong( Song* pSong ) -{ - if( !LoadFromCachedBanner(pSong->GetBannerPath()) ) { /* Oops. We couldn't load a banner quickly. We can load the actual * banner, but that's slow, so we don't want to do that when we're moving @@ -121,12 +108,30 @@ void FadingBanner::LoadFromSong( Song* pSong ) * that's there (or load a "moving fast" banner). Once we settle down, * we'll get called again and load the real banner. */ - if( !m_bMovingFast ) - { - BeforeChange(); - m_Banner[GetBackIndex()].LoadFromSong( pSong ); - } + if( m_bMovingFast ) + return; + + BeforeChange(); +// FIXME m_Banner[GetBackIndex()].LoadFromSong( pSong ); + if( DoesFileExist(path) ) + m_Banner[GetBackIndex()].Load( path ); + else + m_Banner[GetBackIndex()].LoadFallback(); + + return; } + + BeforeChange(); + m_Banner[GetBackIndex()].Load( ID ); + m_sPendingBanner = path; + m_PendingTimer.GetDeltaTime(); /* reset */ + + return; +} + +void FadingBanner::LoadFromSong( Song* pSong ) +{ + LoadFromCachedBanner( pSong->GetBannerPath() ); } void FadingBanner::LoadAllMusic() @@ -134,15 +139,18 @@ void FadingBanner::LoadAllMusic() BeforeChange(); m_Banner[GetBackIndex()].LoadAllMusic(); } - +#include "SongManager.h" void FadingBanner::LoadFromGroup( CString sGroupName ) { - BeforeChange(); - m_Banner[GetBackIndex()].LoadFromGroup( sGroupName ); + const CString sGroupBannerPath = SONGMAN->GetGroupBannerPath( sGroupName ); + LoadFromCachedBanner( sGroupBannerPath ); +// BeforeChange(); +// m_Banner[GetBackIndex()].LoadFromGroup( sGroupName ); } void FadingBanner::LoadFromCourse( Course* pCourse ) { +// LoadFromCachedBanner( pCourse->GetBannerPath() ); BeforeChange(); m_Banner[GetBackIndex()].LoadFromCourse( pCourse ); } diff --git a/stepmania/src/FadingBanner.h b/stepmania/src/FadingBanner.h index 524eeedcc2..dd29eb3d18 100644 --- a/stepmania/src/FadingBanner.h +++ b/stepmania/src/FadingBanner.h @@ -42,7 +42,7 @@ protected: int m_iIndexFront; int GetBackIndex() { return m_iIndexFront==0 ? 1 : 0; } - bool LoadFromCachedBanner( const CString &path ); + void LoadFromCachedBanner( const CString &path ); CString m_sPendingBanner; RageTimer m_PendingTimer; diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index ab590e1925..6b82037388 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -374,7 +374,7 @@ bool Song::LoadFromSongDir( CString sDir ) return false; } - /* Load the cached banner, if it's not loaded already. */ + /* Load the cached banners, if it's not loaded already. */ if( HasBanner() ) BANNERCACHE->LoadBanner( GetBannerPath() ); diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 5636aab698..1f82e4e698 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -14,6 +14,7 @@ #include "IniFile.h" #include "RageLog.h" #include "NotesLoaderDWI.h" +#include "BannerCache.h" #include "GameState.h" #include "PrefsManager.h" @@ -199,6 +200,9 @@ void SongManager::LoadStepManiaSongDir( CString sDir, LoadingWindow *ld ) /* Add this group to the group array. */ AddGroup(sDir, sGroupDirName); + + /* Cache and load the group banner. */ + BANNERCACHE->CacheBanner( GetGroupBannerPath(sGroupDirName) ); } if( ld ) {