banner cache for group banners
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -13,6 +13,7 @@ class BannerCache
|
||||
|
||||
static CString GetBannerCachePath( CString BannerPath );
|
||||
void UnloadAllBanners();
|
||||
void CacheBannerInternal( CString BannerPath );
|
||||
|
||||
public:
|
||||
BannerCache();
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user