Various changes to speed up start up time:

Added delay_save_cache to SongCacheIndex so that it doesn't write the entire cache index file after every song is loaded when loading songs.
Added m_SongsByDir to SongManager so that GetSongFromDir doesn't have to walk the entire list of songs.
Minor changes to when LoadEnabledSongsFromPref occurs and how SanityCheckGroupDir works to speed up loading.
Song::ReloadFromSongDir removes cache file to force an actual reload from the song dir instead of reloading from the cache.  ReloadFromSongDir exposed to lua.
Reordered Actor::LoadFromNode to put Command first because that case is more common.
Course::GetTrailUnsorted reserves entries before starting to save time reallocating.
join in RageUtil calculates the final size of the concatenated strings reserves it to save time reallocating.
Added time log file to RageLog for profiling.
This commit is contained in:
Kyzentun
2015-03-30 17:45:52 -06:00
parent 3c70b13fcf
commit 8b09da8e64
12 changed files with 133 additions and 37 deletions
+44 -23
View File
@@ -1,6 +1,7 @@
#include "global.h"
#include "SongManager.h"
#include "arch/LoadingWindow/LoadingWindow.h"
#include "ActorUtil.h"
#include "AnnouncerManager.h"
#include "BackgroundUtil.h"
#include "BannerCache.h"
@@ -24,6 +25,7 @@
#include "RageFileManager.h"
#include "RageLog.h"
#include "Song.h"
#include "SongCacheIndex.h"
#include "SongUtil.h"
#include "Sprite.h"
#include "StatsManager.h"
@@ -142,12 +144,18 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld )
void SongManager::InitSongsFromDisk( LoadingWindow *ld )
{
RageTimer tm;
// Tell SONGINDEX to not write the cache index file every time a song adds
// an entry. -Kyz
SONGINDEX->delay_save_cache= true;
LoadStepManiaSongDir( SpecialFiles::SONGS_DIR, ld );
const bool bOldVal = PREFSMAN->m_bFastLoad;
PREFSMAN->m_bFastLoad.Set( PREFSMAN->m_bFastLoadAdditionalSongs );
LoadStepManiaSongDir( ADDITIONAL_SONGS_DIR, ld );
PREFSMAN->m_bFastLoad.Set( bOldVal );
LoadEnabledSongsFromPref();
SONGINDEX->SaveCacheIndex();
SONGINDEX->delay_save_cache= false;
LOG->Trace( "Found %d songs in %f seconds.", (int)m_pSongs.size(), tm.GetDeltaTime() );
}
@@ -157,12 +165,20 @@ void SongManager::SanityCheckGroupDir( RString sDir ) const
{
// Check to see if they put a song directly inside the group folder.
vector<RString> arrayFiles;
GetDirListing( sDir + "/*.mp3", arrayFiles );
GetDirListing( sDir + "/*.oga", arrayFiles );
GetDirListing( sDir + "/*.ogg", arrayFiles );
GetDirListing( sDir + "/*.wav", arrayFiles );
if( !arrayFiles.empty() )
RageException::Throw( FOLDER_CONTAINS_MUSIC_FILES.GetValue(), sDir.c_str() );
GetDirListing( sDir + "/*", arrayFiles );
const vector<RString>& audio_exts= ActorUtil::GetTypeExtensionList(FT_Sound);
FOREACH(RString, arrayFiles, fname)
{
const RString ext= GetExtension(*fname);
FOREACH_CONST(RString, audio_exts, aud)
{
if(ext == *aud)
{
RageException::Throw(
FOLDER_CONTAINS_MUSIC_FILES.GetValue(), sDir.c_str());
}
}
}
}
void SongManager::AddGroup( RString sDir, RString sGroupDirName )
@@ -309,14 +325,13 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
);
}
Song* pNewSong = new Song;
m_pSongs.push_back( pNewSong );
if( !pNewSong->LoadFromSongDir( sSongDirName ) )
{
// The song failed to load.
m_pSongs.pop_back();
delete pNewSong;
continue;
}
AddSongToList(pNewSong);
index_entry.push_back( pNewSong );
loaded++;
@@ -341,8 +356,6 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
if( ld ) {
ld->SetIndeterminate( true );
}
LoadEnabledSongsFromPref();
}
// Instead of "symlinks", songs should have membership in multiple groups. -Chris
@@ -375,7 +388,7 @@ void SongManager::LoadGroupSymLinks(RString sDir, RString sGroupFolder)
pNewSong->m_bIsSymLink = true; // Very important so we don't double-parse later
pNewSong->m_sGroupName = sGroupFolder;
m_pSongs.push_back( pNewSong );
AddSongToList(pNewSong);
index_entry.push_back( pNewSong );
}
}
@@ -423,6 +436,7 @@ void SongManager::FreeSongs()
for( unsigned i=0; i<m_pSongs.size(); i++ )
SAFE_DELETE( m_pSongs[i] );
m_pSongs.clear();
m_SongsByDir.clear();
// also free the songs that have been deleted from disk
for ( unsigned i=0; i<m_pDeletedSongs.size(); ++i )
@@ -1124,9 +1138,6 @@ void SongManager::SaveEnabledSongsToPref()
void SongManager::LoadEnabledSongsFromPref()
{
FOREACH( Song *, m_pSongs, s )
(*s)->SetEnabled( true );
vector<RString> asDisabledSongs;
split( g_sDisabledSongs, ";", asDisabledSongs, true );
@@ -1355,17 +1366,18 @@ Course* SongManager::GetRandomCourse()
return NULL;
}
Song* SongManager::GetSongFromDir( RString sDir ) const
Song* SongManager::GetSongFromDir(RString dir) const
{
if( sDir.Right(1) != "/" )
sDir += "/";
sDir.Replace( '\\', '/' );
FOREACH_CONST( Song*, m_pSongs, s )
if( sDir.EqualsNoCase((*s)->GetSongDir()) )
return *s;
if(dir.Right(1) != "/")
{ dir += "/"; }
dir.Replace('\\', '/');
dir.MakeLower();
map<RString, Song*>::const_iterator entry= m_SongsByDir.find(dir);
if(entry != m_SongsByDir.end())
{
return entry->second;
}
return NULL;
}
@@ -1849,6 +1861,15 @@ int SongManager::GetNumEditsLoadedFromProfile( ProfileSlot slot ) const
return iCount;
}
void SongManager::AddSongToList(Song* new_song)
{
new_song->SetEnabled(true);
m_pSongs.push_back(new_song);
RString dir= new_song->GetSongDir();
dir.MakeLower();
m_SongsByDir.insert(make_pair(dir, new_song));
}
void SongManager::FreeAllLoadedFromProfile( ProfileSlot slot )
{
// Profile courses may refer to profile steps, so free profile courses first.