diff --git a/src/PrefsManager.cpp b/src/PrefsManager.cpp index 0d6a89dda0..b6387d22ca 100644 --- a/src/PrefsManager.cpp +++ b/src/PrefsManager.cpp @@ -163,10 +163,9 @@ PrefsManager::PrefsManager() : m_bPAL ( "PAL", false ), m_bDelayedTextureDelete ( "DelayedTextureDelete", false ), m_bDelayedModelDelete ( "DelayedModelDelete", false ), - m_ImageCache ( "ImageCache", IMGCACHE_LOW_RES_PRELOAD ), + m_ImageCache ( "ImageCache", IMGCACHE_OFF), m_bFastLoad ( "FastLoad", true ), - m_bFastLoadAdditionalSongs ( "FastLoadAdditionalSongs", true ), - m_bHyperLoad("HyperLoad", false), + m_bShrinkSongCache("RemoveCacheEnriesForDeletedSongs", false), m_NeverCacheList ( "NeverCacheList", ""), m_bOnlyDedicatedMenuButtons ( "OnlyDedicatedMenuButtons", false ), diff --git a/src/PrefsManager.h b/src/PrefsManager.h index 6c66d7dc40..90fdc37b4e 100644 --- a/src/PrefsManager.h +++ b/src/PrefsManager.h @@ -156,8 +156,7 @@ class PrefsManager Preference m_bDelayedModelDelete; Preference m_ImageCache; Preference m_bFastLoad; - Preference m_bHyperLoad; - Preference m_bFastLoadAdditionalSongs; + Preference m_bShrinkSongCache; Preference m_NeverCacheList; Preference m_bOnlyDedicatedMenuButtons; diff --git a/src/Song.cpp b/src/Song.cpp index 87be9191c9..ae8122c1cc 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -378,7 +378,7 @@ void Song::FinalizeLoading() { for( std::string Image : ImageDir ) { - IMAGECACHE->LoadImage( Image, GetCacheFile( Image ) ); + //IMAGECACHE->LoadImage( Image, GetCacheFile( Image ) ); } } diff --git a/src/SongCacheIndex.cpp b/src/SongCacheIndex.cpp index e607fe0041..1b549dcd78 100644 --- a/src/SongCacheIndex.cpp +++ b/src/SongCacheIndex.cpp @@ -612,7 +612,7 @@ void SongCacheIndex::LoadHyperCache(LoadingWindow * ld, map& hyp if (ld) { ld->SetProgress(progress); - ld->SetText(("Loading Cache (" + lastDir + ")").c_str()); + ld->SetText(("Loading Cache\n (" + lastDir + ")").c_str()); progress++; } } @@ -647,7 +647,7 @@ void SongCacheIndex::LoadCache(LoadingWindow * ld, mapSetProgress(progress); - ld->SetText(("Loading Cache (" + lastDir + ")").c_str()); + ld->SetText(("Loading Cache\n(" + lastDir + ")").c_str()); progress++; } } diff --git a/src/SongManager.cpp b/src/SongManager.cpp index eb4af5b1b8..3fb6ebc4de 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -130,17 +130,9 @@ int SongManager::DifferentialReload() { FILEMAN->FlushDirCache(ADDITIONAL_SONGS_DIR); FILEMAN->FlushDirCache(EDIT_SUBDIR); int newsongs = 0; - SONGINDEX->delay_save_cache = true; newsongs += DifferentialReloadDir(SpecialFiles::SONGS_DIR); - - const bool bOldVal = PREFSMAN->m_bFastLoad; - PREFSMAN->m_bFastLoad.Set(PREFSMAN->m_bFastLoadAdditionalSongs); newsongs += DifferentialReloadDir(ADDITIONAL_SONGS_DIR); - PREFSMAN->m_bFastLoad.Set(bOldVal); LoadEnabledSongsFromPref(); - SONGINDEX->SaveCacheIndex(); - SONGINDEX->delay_save_cache = false; - return newsongs; } @@ -227,16 +219,14 @@ 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; + SONGINDEX->delay_save_cache= false; + if(PREFSMAN->m_bFastLoad) + SONGINDEX->LoadCache(ld, cache); 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; + //SONGINDEX->SaveCacheIndex(); + //SONGINDEX->delay_save_cache= false; LOG->Trace( "Found %i songs in %f seconds.", m_pSongs.size(), tm.GetDeltaTime() ); } @@ -478,7 +468,7 @@ void SongManager::SanityCheckGroupDir( const RString &sDir ) const } } -void SongManager::AddGroup( const RString &sDir, const RString &sGroupDirName ) +bool SongManager::AddGroup( const RString &sDir, const RString &sGroupDirName ) { unsigned j; for(j = 0; j < m_sSongGroupNames.size(); ++j) @@ -486,7 +476,7 @@ void SongManager::AddGroup( const RString &sDir, const RString &sGroupDirName ) break; if( j != m_sSongGroupNames.size() ) - return; // the group is already added + return false; // the group is already added // Look for a group banner in this group folder vector arrayGroupBanners; @@ -541,168 +531,101 @@ void SongManager::AddGroup( const RString &sDir, const RString &sGroupDirName ) m_sSongGroupNames.emplace_back( sGroupDirName ); m_sSongGroupBannerPaths.emplace_back( sBannerPath ); //m_sSongGroupBackgroundPaths.emplace_back( sBackgroundPath ); + return true; } static LocalizedString LOADING_SONGS ( "SongManager", "Loading songs..." ); void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ) { - // Compositors and other stuff can impose some overhead on updating the - // loading window, which slows down startup time for some people. - // loading_window_last_update_time provides a timer so the loading window - // isn't updated after every song and course. -Kyz - RageTimer loading_window_last_update_time; - loading_window_last_update_time.Touch(); - // Make sure sDir has a trailing slash. - if( sDir.Right(1) != "/" ) - sDir += "/"; - - // Find all group directories in "Songs" folder + + if( ld ) { + ld->SetIndeterminate( false ); + ld->SetTotalWork( cache.size() ); + } + int cacheIndex = 0; + for (auto& pair : cache) { + cacheIndex++; + ld->SetProgress(cacheIndex); + auto& pNewSong = pair.second; + if (!FILEMAN->IsADirectory(pNewSong->GetSongDir().substr(0, pNewSong->GetSongDir().size() - 1))) { + if (PREFSMAN->m_bShrinkSongCache) + SONGINDEX->DeleteSongFromDB(pair.second); + delete pair.second; + continue; + } + pNewSong->FinalizeLoading(); + AddSongToList(pNewSong); + AddKeyedPointers(pNewSong); + m_mapSongGroupIndex[pNewSong->m_sGroupName].emplace_back(pNewSong); + if (AddGroup(sDir, pNewSong->m_sGroupName)) + IMAGECACHE->CacheImage("Banner", GetSongGroupBannerPath(pNewSong->m_sGroupName)); + } + vector arrayGroupDirs; - GetDirListing( sDir+"*", arrayGroupDirs, true ); - StripCvsAndSvn( arrayGroupDirs ); - StripMacResourceForks( arrayGroupDirs ); + GetDirListing(sDir + "*", arrayGroupDirs, true); + StripCvsAndSvn(arrayGroupDirs); + StripMacResourceForks(arrayGroupDirs); SortRStringArray(arrayGroupDirs); - vector< vector > arrayGroupSongDirs; - int groupIndex, songCount, songIndex; - - groupIndex = 0; - songCount = 0; - if(ld) + int songCount = 0; + if (ld) { ld->SetIndeterminate(false); ld->SetTotalWork(arrayGroupDirs.size()); + ld->SetText("Sanity checking groups"); } - int sanity_index= 0; - FOREACH_CONST( RString, arrayGroupDirs, s ) // foreach dir in /Songs/ - { + int groupsChecked = 0; + FOREACH_CONST(RString, arrayGroupDirs, s) { RString sGroupDirName = *s; - if(ld && loading_window_last_update_time.Ago() > next_loading_window_update) - { - loading_window_last_update_time.Touch(); - ld->SetProgress(sanity_index); - ld->SetText(SANITY_CHECKING_GROUPS.GetValue() + ssprintf("\n%s", - Basename(sGroupDirName).c_str())); - } - // TODO: If this check fails, log a warning instead of crashing. - SanityCheckGroupDir(sDir+sGroupDirName); - - // Find all Song folders in this group directory + SanityCheckGroupDir(sDir + sGroupDirName); vector arraySongDirs; - GetDirListing( sDir+sGroupDirName + "/*", arraySongDirs, true, true ); - StripCvsAndSvn( arraySongDirs ); - StripMacResourceForks( arraySongDirs ); - SortRStringArray( arraySongDirs ); - + GetDirListing(sDir + sGroupDirName + "/*", arraySongDirs, true, true); + StripCvsAndSvn(arraySongDirs); + StripMacResourceForks(arraySongDirs); + SortRStringArray(arraySongDirs); arrayGroupSongDirs.emplace_back(arraySongDirs); songCount += arraySongDirs.size(); - + ld->SetProgress(++groupsChecked); } - if( songCount==0 ) return; - - map, Song*> cache; - map hyperCache; - if (PREFSMAN->m_bHyperLoad) { - SONGINDEX->LoadHyperCache(ld, hyperCache); - } - else { - SONGINDEX->LoadCache(ld, cache); - } - - if( ld ) { - ld->SetIndeterminate( false ); - ld->SetTotalWork( songCount ); - } - - groupIndex = 0; - songIndex = 0; - FOREACH_CONST( RString, arrayGroupDirs, s ) // foreach dir in /Songs/ + if (ld) { - RString sGroupDirName = *s; + ld->SetIndeterminate(false); + ld->SetTotalWork(songCount); + } + int groupIndex = 0; + int songIndex = 0; + FOREACH_CONST(RString, arrayGroupDirs, s) { + RString sGroupDirName = *s; vector &arraySongDirs = arrayGroupSongDirs[groupIndex++]; - - LOG->Trace("Attempting to load %i songs from \"%s\"", static_cast(arraySongDirs.size()), - (sDir+sGroupDirName).c_str() ); int loaded = 0; - SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName]; - RString group_base_name= Basename(sGroupDirName); - for (unsigned j = 0; j < arraySongDirs.size(); ++j) // for each song dir - { + RString group_base_name = Basename(sGroupDirName); + for (size_t j = 0; j < arraySongDirs.size(); ++j) { + songIndex++; RString sSongDirName = arraySongDirs[j]; - - // this is a song directory. Load a new song. - if (ld && loading_window_last_update_time.Ago() > next_loading_window_update) - { - loading_window_last_update_time.Touch(); - ld->SetProgress(songIndex); - ld->SetText(LOADING_SONGS.GetValue() + - ssprintf("\n%s\n%s", - group_base_name.c_str(), - Basename(sSongDirName).c_str() - ) - ); - } - Song* pNewSong = nullptr; - if (sSongDirName.Right(1) != "/") - sSongDirName += "/"; - if (PREFSMAN->m_bHyperLoad) { - if (hyperCache.count(sSongDirName) > 0) { - pNewSong = hyperCache[sSongDirName]; - pNewSong->FinalizeLoading(); - hyperCache.erase(sSongDirName); //Only erases pointer - } - else { - pNewSong = new Song; - if (!pNewSong->LoadFromSongDir(sSongDirName)) - { - // The song failed to load. - delete pNewSong; - continue; - } - } - } - else { - pair songID = { sSongDirName, GetHashForDirectory(sSongDirName) }; - if (cache.count(songID) > 0) { - pNewSong = cache[songID]; - pNewSong->FinalizeLoading(); - cache.erase(songID); //Only erases pointer - } - else { - pNewSong = new Song; - if (!pNewSong->LoadFromSongDir(sSongDirName)) - { - // The song failed to load. - delete pNewSong; - continue; - } - } + RString hur = sSongDirName + "/"; + hur.MakeLower(); + if (m_SongsByDir.count(hur)) + continue; + Song* pNewSong = new Song; + if (!pNewSong->LoadFromSongDir(sSongDirName)) { + delete pNewSong; + continue; } AddSongToList(pNewSong); AddKeyedPointers(pNewSong); - - index_entry.emplace_back( pNewSong ); - + index_entry.emplace_back(pNewSong); loaded++; - songIndex++; } - - LOG->Trace("Loaded %i songs from \"%s\"", loaded, (sDir+sGroupDirName).c_str() ); - - // Don't add the group name if we didn't load any songs in this group. - if(!loaded) continue; - - // Add this group to the group array. + if (ld) { + ld->SetProgress(songIndex); + ld->SetText("Loading Songs From Disk\n (" + sGroupDirName + "()"); + } + if (!loaded) continue; + LOG->Trace("Loaded %i songs from \"%s\"", loaded, (sDir + sGroupDirName).c_str()); AddGroup(sDir, sGroupDirName); - - // Cache and load the group banner. (and background if it has one -aj) - IMAGECACHE->CacheImage( "Banner", GetSongGroupBannerPath(sGroupDirName) ); - } - for (auto& pair : cache) { - //SONGINDEX->DeleteSongFromDB(pair.second); - delete pair.second; + IMAGECACHE->CacheImage("Banner", GetSongGroupBannerPath(sGroupDirName)); } if( ld ) { ld->SetIndeterminate( true ); diff --git a/src/SongManager.h b/src/SongManager.h index 29dd491a8c..c1786eadaa 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -196,13 +196,15 @@ class SongManager void LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ); void LoadDWISongDir( const RString &sDir ); void SanityCheckGroupDir( const RString &sDir ) const; - void AddGroup( const RString &sDir, const RString &sGroupDirName ); + bool AddGroup( const RString &sDir, const RString &sGroupDirName ); void AddSongToList(Song* new_song); /** @brief All of the songs that can be played. */ vector m_pSongs; map m_SongsByDir; + map, Song*> cache; + // Indexed by chartkeys void AddKeyedPointers(Song* new_song); unordered_map SongsByKey;