wrap the probing part with if( !duringCache ), speeds up loading from cache.

From my benchmark with around 1600 songs, it goes from 30 seconds to less than 10 seconds.
This commit is contained in:
Thai Pangsakulyanont
2012-01-08 13:23:38 +07:00
parent 7bd3d75e04
commit 6eed983329
+171 -166
View File
@@ -588,203 +588,208 @@ void Song::TidyUpData( bool fromCache, bool duringCache )
// is the CDTitle.
CHECKPOINT_M( "Looking for images..." );
if( !duringCache )
{
// First, check the file name for hints.
if( !HasBanner() )
{
/* If a nonexistant banner file is specified, and we can't find a
* replacement, don't wipe out the old value. */
// m_sBannerFile = "";
// First, check the file name for hints.
if( !HasBanner() )
{
/* If a nonexistant banner file is specified, and we can't find a
* replacement, don't wipe out the old value. */
// m_sBannerFile = "";
// find an image with "banner" in the file name
vector<RString> arrayPossibleBanners;
GetImageDirListing( m_sSongDir + "*banner*", arrayPossibleBanners );
// find an image with "banner" in the file name
vector<RString> arrayPossibleBanners;
GetImageDirListing( m_sSongDir + "*banner*", arrayPossibleBanners );
/* Some people do things differently for the sake of being different.
* Don't match eg. abnormal, numbness. */
GetImageDirListing( m_sSongDir + "* BN", arrayPossibleBanners );
/* Some people do things differently for the sake of being different.
* Don't match eg. abnormal, numbness. */
GetImageDirListing( m_sSongDir + "* BN", arrayPossibleBanners );
if( !arrayPossibleBanners.empty() )
m_sBannerFile = arrayPossibleBanners[0];
}
if( !arrayPossibleBanners.empty() )
m_sBannerFile = arrayPossibleBanners[0];
}
if( !HasBackground() )
{
// m_sBackgroundFile = "";
if( !HasBackground() )
{
// m_sBackgroundFile = "";
// find an image with "bg" or "background" in the file name
vector<RString> arrayPossibleBGs;
GetImageDirListing( m_sSongDir + "*background*", arrayPossibleBGs );
// don't match e.g. "subgroup", "hobgoblin", etc.
GetImageDirListing( m_sSongDir + "*bg", arrayPossibleBGs );
if( !arrayPossibleBGs.empty() )
m_sBackgroundFile = arrayPossibleBGs[0];
}
// find an image with "bg" or "background" in the file name
vector<RString> arrayPossibleBGs;
GetImageDirListing( m_sSongDir + "*background*", arrayPossibleBGs );
// don't match e.g. "subgroup", "hobgoblin", etc.
GetImageDirListing( m_sSongDir + "*bg", arrayPossibleBGs );
if( !arrayPossibleBGs.empty() )
m_sBackgroundFile = arrayPossibleBGs[0];
}
if( !HasJacket() )
{
// find an image with "jacket" or "albumart" in the filename.
vector<RString> arrayPossibleJackets;
GetImageDirListing( m_sSongDir + "jk_*", arrayPossibleJackets );
GetImageDirListing( m_sSongDir + "*jacket*", arrayPossibleJackets );
GetImageDirListing( m_sSongDir + "*albumart*", arrayPossibleJackets );
if( !arrayPossibleJackets.empty() )
m_sJacketFile = arrayPossibleJackets[0];
}
if( !HasJacket() )
{
// find an image with "jacket" or "albumart" in the filename.
vector<RString> arrayPossibleJackets;
GetImageDirListing( m_sSongDir + "jk_*", arrayPossibleJackets );
GetImageDirListing( m_sSongDir + "*jacket*", arrayPossibleJackets );
GetImageDirListing( m_sSongDir + "*albumart*", arrayPossibleJackets );
if( !arrayPossibleJackets.empty() )
m_sJacketFile = arrayPossibleJackets[0];
}
if( !HasCDImage() )
{
// CD image, a la ddr 1st-3rd (not to be confused with CDTitles)
// find an image with "-cd" at the end of the filename.
vector<RString> arrayPossibleCDImages;
GetImageDirListing( m_sSongDir + "*-cd", arrayPossibleCDImages );
if( !arrayPossibleCDImages.empty() )
m_sCDFile = arrayPossibleCDImages[0];
}
if( !HasCDImage() )
{
// CD image, a la ddr 1st-3rd (not to be confused with CDTitles)
// find an image with "-cd" at the end of the filename.
vector<RString> arrayPossibleCDImages;
GetImageDirListing( m_sSongDir + "*-cd", arrayPossibleCDImages );
if( !arrayPossibleCDImages.empty() )
m_sCDFile = arrayPossibleCDImages[0];
}
if( !HasDisc() )
{
// a rectangular graphic, not to be confused with CDImage above.
vector<RString> arrayPossibleDiscImages;
GetImageDirListing( m_sSongDir + "* disc", arrayPossibleDiscImages );
GetImageDirListing( m_sSongDir + "* title", arrayPossibleDiscImages );
if( !arrayPossibleDiscImages.empty() )
m_sDiscFile = arrayPossibleDiscImages[0];
}
if( !HasDisc() )
{
// a rectangular graphic, not to be confused with CDImage above.
vector<RString> arrayPossibleDiscImages;
GetImageDirListing( m_sSongDir + "* disc", arrayPossibleDiscImages );
GetImageDirListing( m_sSongDir + "* title", arrayPossibleDiscImages );
if( !arrayPossibleDiscImages.empty() )
m_sDiscFile = arrayPossibleDiscImages[0];
}
if( !HasCDTitle() )
{
// find an image with "cdtitle" in the file name
vector<RString> arrayPossibleCDTitles;
GetImageDirListing( m_sSongDir + "*cdtitle*", arrayPossibleCDTitles );
if( !arrayPossibleCDTitles.empty() )
m_sCDTitleFile = arrayPossibleCDTitles[0];
}
if( !HasCDTitle() )
{
// find an image with "cdtitle" in the file name
vector<RString> arrayPossibleCDTitles;
GetImageDirListing( m_sSongDir + "*cdtitle*", arrayPossibleCDTitles );
if( !arrayPossibleCDTitles.empty() )
m_sCDTitleFile = arrayPossibleCDTitles[0];
}
if( !HasLyrics() )
{
// Check if there is a lyric file in here
vector<RString> arrayLyricFiles;
GetDirListing(m_sSongDir + RString("*.lrc"), arrayLyricFiles );
if( !arrayLyricFiles.empty() )
m_sLyricsFile = arrayLyricFiles[0];
}
if( !HasLyrics() )
{
// Check if there is a lyric file in here
vector<RString> arrayLyricFiles;
GetDirListing(m_sSongDir + RString("*.lrc"), arrayLyricFiles );
if( !arrayLyricFiles.empty() )
m_sLyricsFile = arrayLyricFiles[0];
}
/* Now, For the images we still haven't found,
* look at the image dimensions of the remaining unclassified images. */
vector<RString> arrayImages;
GetImageDirListing( m_sSongDir + "*", arrayImages );
/* Now, For the images we still haven't found,
* look at the image dimensions of the remaining unclassified images. */
vector<RString> arrayImages;
GetImageDirListing( m_sSongDir + "*", arrayImages );
for( unsigned i=0; i<arrayImages.size(); i++ ) // foreach image
{
if( HasBanner() && HasCDTitle() && HasBackground() )
break; // done
for( unsigned i=0; i<arrayImages.size(); i++ ) // foreach image
{
if( HasBanner() && HasCDTitle() && HasBackground() )
break; // done
// ignore DWI "-char" graphics
RString sLower = arrayImages[i];
sLower.MakeLower();
if( BlacklistedImages.find(sLower) != BlacklistedImages.end() )
continue; // skip
// ignore DWI "-char" graphics
RString sLower = arrayImages[i];
sLower.MakeLower();
if( BlacklistedImages.find(sLower) != BlacklistedImages.end() )
continue; // skip
// Skip any image that we've already classified
// Skip any image that we've already classified
if( HasBanner() && m_sBannerFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasBanner() && m_sBannerFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasBackground() && m_sBackgroundFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasBackground() && m_sBackgroundFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasCDTitle() && m_sCDTitleFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasCDTitle() && m_sCDTitleFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasJacket() && m_sJacketFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasJacket() && m_sJacketFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasDisc() && m_sDiscFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasDisc() && m_sDiscFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasCDImage() && m_sCDFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
if( HasCDImage() && m_sCDFile.EqualsNoCase(arrayImages[i]) )
continue; // skip
RString sPath = m_sSongDir + arrayImages[i];
RString sPath = m_sSongDir + arrayImages[i];
// We only care about the dimensions.
RString error;
RageSurface *img = RageSurfaceUtils::LoadFile( sPath, error, true );
if( !img )
{
LOG->UserLog( "Graphic file", sPath, "couldn't be loaded: %s", error.c_str() );
continue;
}
// We only care about the dimensions.
RString error;
RageSurface *img = RageSurfaceUtils::LoadFile( sPath, error, true );
if( !img )
{
LOG->UserLog( "Graphic file", sPath, "couldn't be loaded: %s", error.c_str() );
continue;
}
const int width = img->w;
const int height = img->h;
delete img;
const int width = img->w;
const int height = img->h;
delete img;
if( !HasBackground() && width >= 320 && height >= 240 )
{
m_sBackgroundFile = arrayImages[i];
continue;
}
if( !HasBackground() && width >= 320 && height >= 240 )
{
m_sBackgroundFile = arrayImages[i];
continue;
}
if( !HasBanner() && 100<=width && width<=320 && 50<=height && height<=240 )
{
m_sBannerFile = arrayImages[i];
continue;
}
if( !HasBanner() && 100<=width && width<=320 && 50<=height && height<=240 )
{
m_sBannerFile = arrayImages[i];
continue;
}
/* Some songs have overlarge banners. Check if the ratio is reasonable
* (over 2:1; usually over 3:1), and large (not a cdtitle). */
if( !HasBanner() && width > 200 && float(width) / height > 2.0f )
{
m_sBannerFile = arrayImages[i];
continue;
}
/* Some songs have overlarge banners. Check if the ratio is reasonable
* (over 2:1; usually over 3:1), and large (not a cdtitle). */
if( !HasBanner() && width > 200 && float(width) / height > 2.0f )
{
m_sBannerFile = arrayImages[i];
continue;
}
/* Agh. DWI's inline title images are triggering this, resulting in
* kanji, etc., being used as a CDTitle for songs with none. Some
* sample data from random incarnations:
* 42x50 35x50 50x50 144x49
* It looks like ~50 height is what people use to align to DWI's font.
*
* My tallest CDTitle is 44. Let's cut off in the middle and hope for
* the best. -(who? -aj) */
/* The proper size of a CDTitle is 64x48 or sometihng. Simfile artists
* typically don't give a shit about this (see Cetaka's fucking banner
* -sized CDTitle). This is also subverted in certain designs (beta
* Mungyodance 3 simfiles, for instance, used the CDTitle to hold
* various information about the song in question). As it stands,
* I'm keeping this code until I figure out wtf to do -aj
*/
if( !HasCDTitle() && width<=100 && height<=48 )
{
m_sCDTitleFile = arrayImages[i];
continue;
}
/* Agh. DWI's inline title images are triggering this, resulting in
* kanji, etc., being used as a CDTitle for songs with none. Some
* sample data from random incarnations:
* 42x50 35x50 50x50 144x49
* It looks like ~50 height is what people use to align to DWI's font.
*
* My tallest CDTitle is 44. Let's cut off in the middle and hope for
* the best. -(who? -aj) */
/* The proper size of a CDTitle is 64x48 or sometihng. Simfile artists
* typically don't give a shit about this (see Cetaka's fucking banner
* -sized CDTitle). This is also subverted in certain designs (beta
* Mungyodance 3 simfiles, for instance, used the CDTitle to hold
* various information about the song in question). As it stands,
* I'm keeping this code until I figure out wtf to do -aj
*/
if( !HasCDTitle() && width<=100 && height<=48 )
{
m_sCDTitleFile = arrayImages[i];
continue;
}
// Jacket files typically have the same width and height.
if( !HasJacket() && width == height )
{
m_sJacketFile = arrayImages[i];
continue;
}
// Jacket files typically have the same width and height.
if( !HasJacket() && width == height )
{
m_sJacketFile = arrayImages[i];
continue;
}
// Disc images are typically rectangular; make sure we have a banner already.
if( !HasDisc() && (width > height) && HasBanner() )
{
if( arrayImages[i] != m_sBannerFile )
m_sDiscFile = arrayImages[i];
continue;
}
// Disc images are typically rectangular; make sure we have a banner already.
if( !HasDisc() && (width > height) && HasBanner() )
{
if( arrayImages[i] != m_sBannerFile )
m_sDiscFile = arrayImages[i];
continue;
}
// CD images are the same as Jackets, typically the same width and height
if( !HasCDImage() && width == height )
{
m_sCDFile = arrayImages[i];
continue;
}
}
// CD images are the same as Jackets, typically the same width and height
if( !HasCDImage() && width == height )
{
m_sCDFile = arrayImages[i];
continue;
}
}
}
// These will be written to cache, for Song::LoadFromSongDir to use later.
m_bHasMusic = HasMusic();
m_bHasBanner = HasBanner();
@@ -799,7 +804,7 @@ void Song::TidyUpData( bool fromCache, bool duringCache )
// If no BGChanges are specified and there are movies in the song directory, then assume
// they are DWI style where the movie begins at beat 0.
if( !HasBGChanges() )
if( !HasBGChanges() && !duringCache )
{
vector<RString> arrayPossibleMovies;
GetDirListing( m_sSongDir + RString("*.ogv"), arrayPossibleMovies );