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.
This commit is contained in:
+3
-29
@@ -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; i<asCacheFileNames.GetSize(); i++ )
|
||||
DeleteFile( "Cache\\" + asCacheFileNames[i] );
|
||||
goto load_without_cache;
|
||||
}
|
||||
|
||||
int iDirHash;
|
||||
ini.GetValueI( "Cache", m_sSongDir, iDirHash );
|
||||
int iDirHash = SONGINDEX->GetCacheHash(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() );
|
||||
}
|
||||
|
||||
|
||||
@@ -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<asCacheFileNames.GetSize(); i++ )
|
||||
DeleteFile( "Cache/" + asCacheFileNames[i] );
|
||||
CacheIndex.Reset();
|
||||
}
|
||||
|
||||
void SongCacheIndex::AddCacheIndex(const CString &path, int hash)
|
||||
{
|
||||
CacheIndex.SetValueI( "Cache", "CacheVersion", FILE_CACHE_VERSION );
|
||||
CacheIndex.SetValueI( "Cache", path, hash );
|
||||
CacheIndex.WriteFile();
|
||||
}
|
||||
|
||||
int SongCacheIndex::GetCacheHash( const CString &path )
|
||||
{
|
||||
int iDirHash;
|
||||
CacheIndex.GetValueI( "Cache", path, iDirHash );
|
||||
return iDirHash;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef SONG_CACHE_INDEX_H
|
||||
#define SONG_CACHE_INDEX_H
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "IniFile.h"
|
||||
|
||||
class SongCacheIndex {
|
||||
IniFile CacheIndex;
|
||||
public:
|
||||
SongCacheIndex();
|
||||
~SongCacheIndex();
|
||||
|
||||
void ReadCacheIndex();
|
||||
void AddCacheIndex( const CString &path, int hash );
|
||||
int GetCacheHash( const CString &path );
|
||||
};
|
||||
|
||||
extern SongCacheIndex *SONGINDEX; // global and accessable from anywhere in our program
|
||||
|
||||
#endif
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "InputFilter.h"
|
||||
#include "InputMapper.h"
|
||||
#include "InputQueue.h"
|
||||
#include "SongCacheIndex.h"
|
||||
|
||||
//
|
||||
// StepMania common classes
|
||||
@@ -666,6 +667,8 @@ HRESULT CreateObjects( HWND hWnd )
|
||||
INPUTFILTER = new InputFilter();
|
||||
INPUTMAPPER = new InputMapper();
|
||||
INPUTQUEUE = new InputQueue();
|
||||
SONGINDEX = new SongCacheIndex();
|
||||
/* depends on SONGINDEX: */
|
||||
SONGMAN = new SongManager( PaintLoadingWindow ); // this takes a long time to load
|
||||
DISPLAY = new RageDisplay( hWnd );
|
||||
|
||||
@@ -714,6 +717,7 @@ void DestroyObjects()
|
||||
SAFE_DELETE( INPUTMAPPER );
|
||||
SAFE_DELETE( INPUTFILTER );
|
||||
SAFE_DELETE( SONGMAN );
|
||||
SAFE_DELETE( SONGINDEX );
|
||||
SAFE_DELETE( PREFSMAN );
|
||||
SAFE_DELETE( GAMESTATE );
|
||||
SAFE_DELETE( GAMEMAN );
|
||||
|
||||
@@ -344,6 +344,14 @@ SOURCE=.\song.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SongCacheIndex.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SongCacheIndex.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SongOptions.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "RageUtil.h"
|
||||
|
||||
extern const int FILE_CACHE_VERSION;
|
||||
|
||||
struct BPMSegment
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user