From 9e9e01231091319b254468160af529f7b968da54 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 21 Aug 2002 02:13:08 +0000 Subject: [PATCH] Move cache indexing into a global object. Only load the cache file once, instead of for each song loaded. (Speedup, and simplifies Song.cpp.) It's still written over for each file; this way, if a file load crashes, the earlier files will still be written to cache. --- stepmania/src/Song.cpp | 32 ++------------------- stepmania/src/SongCacheIndex.cpp | 48 ++++++++++++++++++++++++++++++++ stepmania/src/SongCacheIndex.h | 20 +++++++++++++ stepmania/src/StepMania.cpp | 4 +++ stepmania/src/StepMania.dsp | 8 ++++++ stepmania/src/song.h | 1 + 6 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 stepmania/src/SongCacheIndex.cpp create mode 100644 stepmania/src/SongCacheIndex.h diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 50b744ca9a..d577e0a4d2 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -20,6 +20,7 @@ #include "MsdFile.h" #include "RageSoundStream.h" #include "RageException.h" +#include "SongCacheIndex.h" const int FILE_CACHE_VERSION = 61; // increment this when Song or Notes changes to invalidate cache @@ -292,25 +293,7 @@ bool Song::LoadFromSongDir( CString sDir ) // // First look in the cache for this song (without loading NoteData) // - IniFile ini; - ini.SetPath( "Cache\\index.cache" ); - if( !ini.ReadFile() ) - goto load_without_cache; - - int iCacheVersion; - ini.GetValueI( "Cache", "CacheVersion", iCacheVersion ); - if( iCacheVersion != FILE_CACHE_VERSION ) - { - LOG->Trace( "Cache format is out of date. Deleting all cache files." ); - CStringArray asCacheFileNames; - GetDirListing( "Cache\\*.*", asCacheFileNames ); - for( int i=0; iGetCacheHash(m_sSongDir); if( GetHashForDirectory(m_sSongDir) == iDirHash ) // this cache is up to date { if( !DoesFileExist(GetCacheFilePath()) ) @@ -1237,16 +1220,7 @@ void Song::SaveToCacheFile() { LOG->Trace( "Song::SaveToCacheFile()" ); - // - // First look in the cache for this song (without loading NoteData) - // - IniFile ini; - ini.SetPath( "Cache\\index.cache" ); - ini.ReadFile(); // don't care if this fails - - ini.SetValueI( "Cache", "CacheVersion", FILE_CACHE_VERSION ); - ini.SetValueI( "Cache", m_sSongDir, GetHashForDirectory(m_sSongDir) ); - ini.WriteFile(); + SONGINDEX->AddCacheIndex(m_sSongDir, GetHashForDirectory(m_sSongDir)); SaveToSMFile( GetCacheFilePath() ); } diff --git a/stepmania/src/SongCacheIndex.cpp b/stepmania/src/SongCacheIndex.cpp new file mode 100644 index 0000000000..ce31771dc3 --- /dev/null +++ b/stepmania/src/SongCacheIndex.cpp @@ -0,0 +1,48 @@ +#include "SongCacheIndex.h" +#include "RageLog.h" +#include "RageUtil.h" +#include "Song.h" + +SongCacheIndex *SONGINDEX; + +SongCacheIndex::SongCacheIndex() +{ + CacheIndex.SetPath( "Cache\\index.cache" ); + ReadCacheIndex(); +} + +SongCacheIndex::~SongCacheIndex() +{ + +} + +void SongCacheIndex::ReadCacheIndex() +{ + CacheIndex.ReadFile(); // don't care if this fails + + int iCacheVersion; + CacheIndex.GetValueI( "Cache", "CacheVersion", iCacheVersion ); + if( iCacheVersion == FILE_CACHE_VERSION ) + return; /* OK */ + + LOG->Trace( "Cache format is out of date. Deleting all cache files." ); + CStringArray asCacheFileNames; + GetDirListing( "Cache/*.*", asCacheFileNames ); + for( int i=0; i