From 0bba86b5c39d6f029bc76fc986dcfa63992c0c52 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 30 Dec 2003 03:40:29 +0000 Subject: [PATCH] cache HasMusic() and HasBanner() results --- stepmania/src/NotesLoaderSM.cpp | 20 +++++++++++++------- stepmania/src/NotesWriterSM.cpp | 2 ++ stepmania/src/Song.cpp | 14 +++++++++++--- stepmania/src/song.h | 2 ++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/stepmania/src/NotesLoaderSM.cpp b/stepmania/src/NotesLoaderSM.cpp index 215429a96a..86068d8b45 100644 --- a/stepmania/src/NotesLoaderSM.cpp +++ b/stepmania/src/NotesLoaderSM.cpp @@ -216,14 +216,20 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out ) } else if( 0==stricmp(sValueName,"SONGFILENAME") ) { - if(!FromCache) - { - LOG->Trace("Ignored #SONGFILENAME (cache only)"); - continue; - } - out.m_sSongFileName = sParams[1]; + if( FromCache ) + out.m_sSongFileName = sParams[1]; } - + else if( 0==stricmp(sValueName,"HASMUSIC") ) + { + if( FromCache ) + out.m_bHasMusic = atoi( sParams[1] ) != 0; + } + else if( 0==stricmp(sValueName,"HASBANNER") ) + { + if( FromCache ) + out.m_bHasBanner = atoi( sParams[1] ) != 0; + } + else if( 0==stricmp(sValueName,"SAMPLESTART") ) out.m_fMusicSampleStartSeconds = TimeToSeconds( sParams[1] ); diff --git a/stepmania/src/NotesWriterSM.cpp b/stepmania/src/NotesWriterSM.cpp index 282ace87df..572df017fc 100644 --- a/stepmania/src/NotesWriterSM.cpp +++ b/stepmania/src/NotesWriterSM.cpp @@ -172,6 +172,8 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache) f.PutLine( ssprintf( "#FIRSTBEAT:%.3f;\n", out.m_fFirstBeat ) ); f.PutLine( ssprintf( "#LASTBEAT:%.3f;\n", out.m_fLastBeat ) ); f.PutLine( ssprintf( "#SONGFILENAME:%s;\n", out.m_sSongFileName.c_str() ) ); + f.PutLine( ssprintf( "#HASMUSIC:%i;\n", out.m_bHasMusic ) ); + f.PutLine( ssprintf( "#HASBANNER:%i;\n", out.m_bHasBanner ) ); } // diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 4436485f2c..8825f4ea4a 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -50,7 +50,7 @@ #define CACHE_DIR "Cache/" -const int FILE_CACHE_VERSION = 132; // increment this when Song or Steps changes to invalidate cache +const int FILE_CACHE_VERSION = 133; // increment this when Song or Steps changes to invalidate cache const float DEFAULT_MUSIC_SAMPLE_LENGTH = 12.f; @@ -83,6 +83,8 @@ Song::Song() m_fSpecifiedBPMMin = 0; m_fSpecifiedBPMMax = 0; m_bIsSymLink = false; + m_bHasMusic = false; + m_bHasBanner = false; } Song::~Song() @@ -246,13 +248,13 @@ bool Song::LoadFromSongDir( CString sDir, bool bAllowCache ) } /* Load the cached banners, if it's not loaded already. */ - if( HasBanner() ) + if( m_bHasBanner ) BANNERCACHE->LoadBanner( GetBannerPath() ); /* Add AutoGen pointers. (These aren't cached.) */ AddAutoGenNotes(); - if( !HasMusic() ) + if( !m_bHasMusic ) return false; // don't load this song else return true; // do load this song @@ -538,6 +540,8 @@ void Song::TidyUpData() // 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 @@ -672,6 +676,10 @@ void Song::TidyUpData() } } + /* These will be written to cache, for Song::LoadFromSongDir to use later. */ + m_bHasMusic = HasMusic(); + m_bHasBanner = HasBanner(); + if( HasBanner() ) BANNERCACHE->CacheBanner( GetBannerPath() ); diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 89c3f9df50..6329d27d41 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -140,6 +140,8 @@ public: CString GetBackgroundPath() const; CString GetCDTitlePath() const; + /* For loading only: */ + bool m_bHasMusic, m_bHasBanner; bool HasMusic() const; bool HasBanner() const;