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 "MsdFile.h"
|
||||||
#include "RageSoundStream.h"
|
#include "RageSoundStream.h"
|
||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
|
#include "SongCacheIndex.h"
|
||||||
|
|
||||||
|
|
||||||
const int FILE_CACHE_VERSION = 61; // increment this when Song or Notes changes to invalidate cache
|
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)
|
// First look in the cache for this song (without loading NoteData)
|
||||||
//
|
//
|
||||||
IniFile ini;
|
int iDirHash = SONGINDEX->GetCacheHash(m_sSongDir);
|
||||||
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 );
|
|
||||||
if( GetHashForDirectory(m_sSongDir) == iDirHash ) // this cache is up to date
|
if( GetHashForDirectory(m_sSongDir) == iDirHash ) // this cache is up to date
|
||||||
{
|
{
|
||||||
if( !DoesFileExist(GetCacheFilePath()) )
|
if( !DoesFileExist(GetCacheFilePath()) )
|
||||||
@@ -1237,16 +1220,7 @@ void Song::SaveToCacheFile()
|
|||||||
{
|
{
|
||||||
LOG->Trace( "Song::SaveToCacheFile()" );
|
LOG->Trace( "Song::SaveToCacheFile()" );
|
||||||
|
|
||||||
//
|
SONGINDEX->AddCacheIndex(m_sSongDir, GetHashForDirectory(m_sSongDir));
|
||||||
// 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();
|
|
||||||
SaveToSMFile( GetCacheFilePath() );
|
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 "InputFilter.h"
|
||||||
#include "InputMapper.h"
|
#include "InputMapper.h"
|
||||||
#include "InputQueue.h"
|
#include "InputQueue.h"
|
||||||
|
#include "SongCacheIndex.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// StepMania common classes
|
// StepMania common classes
|
||||||
@@ -666,6 +667,8 @@ HRESULT CreateObjects( HWND hWnd )
|
|||||||
INPUTFILTER = new InputFilter();
|
INPUTFILTER = new InputFilter();
|
||||||
INPUTMAPPER = new InputMapper();
|
INPUTMAPPER = new InputMapper();
|
||||||
INPUTQUEUE = new InputQueue();
|
INPUTQUEUE = new InputQueue();
|
||||||
|
SONGINDEX = new SongCacheIndex();
|
||||||
|
/* depends on SONGINDEX: */
|
||||||
SONGMAN = new SongManager( PaintLoadingWindow ); // this takes a long time to load
|
SONGMAN = new SongManager( PaintLoadingWindow ); // this takes a long time to load
|
||||||
DISPLAY = new RageDisplay( hWnd );
|
DISPLAY = new RageDisplay( hWnd );
|
||||||
|
|
||||||
@@ -714,6 +717,7 @@ void DestroyObjects()
|
|||||||
SAFE_DELETE( INPUTMAPPER );
|
SAFE_DELETE( INPUTMAPPER );
|
||||||
SAFE_DELETE( INPUTFILTER );
|
SAFE_DELETE( INPUTFILTER );
|
||||||
SAFE_DELETE( SONGMAN );
|
SAFE_DELETE( SONGMAN );
|
||||||
|
SAFE_DELETE( SONGINDEX );
|
||||||
SAFE_DELETE( PREFSMAN );
|
SAFE_DELETE( PREFSMAN );
|
||||||
SAFE_DELETE( GAMESTATE );
|
SAFE_DELETE( GAMESTATE );
|
||||||
SAFE_DELETE( GAMEMAN );
|
SAFE_DELETE( GAMEMAN );
|
||||||
|
|||||||
@@ -344,6 +344,14 @@ SOURCE=.\song.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin 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
|
SOURCE=.\SongOptions.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "GameConstantsAndTypes.h"
|
#include "GameConstantsAndTypes.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
|
|
||||||
|
extern const int FILE_CACHE_VERSION;
|
||||||
|
|
||||||
struct BPMSegment
|
struct BPMSegment
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user