Add support for incremental updates to ScreenReloadSongs

This commit is contained in:
Martin Natano
2022-06-10 19:33:23 +02:00
parent 49127f6a92
commit f60707b506
7 changed files with 103 additions and 24 deletions
+1
View File
@@ -3241,6 +3241,7 @@ TimerOnCommand=visible,false
Class="ScreenReloadSongs" Class="ScreenReloadSongs"
Fallback="Screen" Fallback="Screen"
NextScreen=Branch.TitleMenu() NextScreen=Branch.TitleMenu()
OnlyLoadAdditions=false
[ScreenPlayerOptions] [ScreenPlayerOptions]
Fallback="ScreenOptions" Fallback="ScreenOptions"
+1
View File
@@ -85,6 +85,7 @@ public:
XNode* CreateNode() const; XNode* CreateNode() const;
void LoadFromNode( const XNode* pNode ); void LoadFromNode( const XNode* pNode );
void FromPath( RString _sPath ) { sPath = _sPath; }
RString ToString() const; RString ToString() const;
bool IsValid() const; bool IsValid() const;
+1 -1
View File
@@ -177,7 +177,7 @@ void ScreenInstallOverlay::Update( float fDeltaTime )
playAfterLaunchInfo.OverlayWith( pali2 ); playAfterLaunchInfo.OverlayWith( pali2 );
} }
if( playAfterLaunchInfo.bAnySongChanged ) if( playAfterLaunchInfo.bAnySongChanged )
SONGMAN->Reload( nullptr ); SONGMAN->Reload();
if( !playAfterLaunchInfo.sSongDir.empty() ) if( !playAfterLaunchInfo.sSongDir.empty() )
{ {
+8
View File
@@ -77,7 +77,15 @@ void ScreenReloadSongs::Update( float fDeltaTime )
ASSERT( !IsFirstUpdate() ); ASSERT( !IsFirstUpdate() );
bool onlyLoadAdditions = THEME->GetMetricB(m_sName, "OnlyLoadAdditions");
if (onlyLoadAdditions)
{
SONGMAN->LoadAdditions( m_pLoadingWindow );
}
else
{
SONGMAN->Reload( m_pLoadingWindow ); SONGMAN->Reload( m_pLoadingWindow );
}
SCREENMAN->PostMessageToTopScreen( SM_GoToNextScreen, 0 ); SCREENMAN->PostMessageToTopScreen( SM_GoToNextScreen, 0 );
} }
+50 -8
View File
@@ -93,7 +93,7 @@ SongManager::~SongManager()
FreeSongs(); FreeSongs();
} }
void SongManager::InitAll( LoadingWindow *ld ) void SongManager::InitAll( LoadingWindow *ld, bool onlyAdditions )
{ {
vector<RString> never_cache; vector<RString> never_cache;
split(PREFSMAN->m_NeverCacheList, ",", never_cache); split(PREFSMAN->m_NeverCacheList, ",", never_cache);
@@ -102,8 +102,12 @@ void SongManager::InitAll( LoadingWindow *ld )
{ {
m_GroupsToNeverCache.insert(*group); m_GroupsToNeverCache.insert(*group);
} }
InitSongsFromDisk( ld ); InitSongsFromDisk( ld, onlyAdditions );
InitCoursesFromDisk( ld ); InitCoursesFromDisk( ld, onlyAdditions );
if (onlyAdditions)
{
DeleteAutogenCourses();
}
InitAutogenCourses(); InitAutogenCourses();
InitRandomAttacks(); InitRandomAttacks();
} }
@@ -168,7 +172,7 @@ void SongManager::Reload( LoadingWindow *ld )
FreeSongs(); FreeSongs();
InitAll( ld ); InitAll( ld, /*onlyAdditions=*/false );
// reload scores and unlocks afterward // reload scores and unlocks afterward
PROFILEMAN->LoadMachineProfile(); PROFILEMAN->LoadMachineProfile();
@@ -202,14 +206,27 @@ void SongManager::Reload( LoadingWindow *ld )
UpdatePreferredSort(); UpdatePreferredSort();
} }
void SongManager::InitSongsFromDisk( LoadingWindow *ld ) void SongManager::LoadAdditions( LoadingWindow *ld )
{
FILEMAN->FlushDirCache( SpecialFiles::SONGS_DIR );
FILEMAN->FlushDirCache( SpecialFiles::COURSES_DIR );
FILEMAN->FlushDirCache( EDIT_SUBDIR );
InitAll( ld, /*onlyAdditions=*/true );
UNLOCKMAN->Reload();
UpdatePreferredSort();
}
void SongManager::InitSongsFromDisk( LoadingWindow *ld, bool onlyAdditions )
{ {
RageTimer tm; RageTimer tm;
// Tell SONGINDEX to not write the cache index file every time a song adds // Tell SONGINDEX to not write the cache index file every time a song adds
// an entry. -Kyz // an entry. -Kyz
SONGINDEX->delay_save_cache = true; SONGINDEX->delay_save_cache = true;
IMAGECACHE->delay_save_cache = true; IMAGECACHE->delay_save_cache = true;
LoadStepManiaSongDir( SpecialFiles::SONGS_DIR, ld ); LoadSongDir( SpecialFiles::SONGS_DIR, ld, onlyAdditions );
LoadEnabledSongsFromPref(); LoadEnabledSongsFromPref();
SONGINDEX->SaveCacheIndex(); SONGINDEX->SaveCacheIndex();
SONGINDEX->delay_save_cache = false; SONGINDEX->delay_save_cache = false;
@@ -312,8 +329,11 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName )
} }
static LocalizedString LOADING_SONGS ( "SongManager", "Loading songs..." ); static LocalizedString LOADING_SONGS ( "SongManager", "Loading songs..." );
void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ) void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditions )
{ {
if( ld )
ld->SetText( LOADING_SONGS );
// Compositors and other stuff can impose some overhead on updating the // Compositors and other stuff can impose some overhead on updating the
// loading window, which slows down startup time for some people. // loading window, which slows down startup time for some people.
// loading_window_last_update_time provides a timer so the loading window // loading_window_last_update_time provides a timer so the loading window
@@ -389,6 +409,15 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
{ {
RString sSongDirName = arraySongDirs[j]; RString sSongDirName = arraySongDirs[j];
// Skip already loaded songs if onlyAdditions is set.
if (onlyAdditions)
{
SongID songID;
songID.FromString(sSongDirName);
if (songID.ToSong() != nullptr)
continue;
}
// this is a song directory. Load a new song. // this is a song directory. Load a new song.
if(ld && loading_window_last_update_time.Ago() > next_loading_window_update) if(ld && loading_window_last_update_time.Ago() > next_loading_window_update)
{ {
@@ -401,6 +430,7 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
) )
); );
} }
Song* pNewSong = new Song; Song* pNewSong = new Song;
if( !pNewSong->LoadFromSongDir( sSongDirName ) ) if( !pNewSong->LoadFromSongDir( sSongDirName ) )
{ {
@@ -869,9 +899,12 @@ RString SongManager::ShortenGroupName( RString sLongGroupName )
} }
static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." ); static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." );
void SongManager::InitCoursesFromDisk( LoadingWindow *ld ) void SongManager::InitCoursesFromDisk( LoadingWindow *ld, bool onlyAdditions )
{ {
LOG->Trace( "Loading courses." ); LOG->Trace( "Loading courses." );
if( ld )
ld->SetText( LOADING_COURSES );
RageTimer loading_window_last_update_time; RageTimer loading_window_last_update_time;
loading_window_last_update_time.Touch(); loading_window_last_update_time.Touch();
@@ -902,6 +935,15 @@ void SongManager::InitCoursesFromDisk( LoadingWindow *ld )
RString base_course_group= Basename(sCourseGroup); RString base_course_group= Basename(sCourseGroup);
for (RString const &sCoursePath : vsCoursePaths) for (RString const &sCoursePath : vsCoursePaths)
{ {
// Skip already loaded courses if onlyAdditions is set.
if (onlyAdditions)
{
CourseID courseID;
courseID.FromPath(sCoursePath);
if (courseID.ToCourse() != nullptr)
continue;
}
if(ld && loading_window_last_update_time.Ago() > next_loading_window_update) if(ld && loading_window_last_update_time.Ago() > next_loading_window_update)
{ {
loading_window_last_update_time.Touch(); loading_window_last_update_time.Touch();
+34 -7
View File
@@ -35,7 +35,13 @@ public:
SongManager(); SongManager();
~SongManager(); ~SongManager();
void InitSongsFromDisk( LoadingWindow *ld ); /**
* @brief Initialize all songs from disk
* @param ld the loading window to be updated, or nullptr
* @param onlyAdditions only load songs added after the last
* invocation of this function
*/
void InitSongsFromDisk( LoadingWindow *ld, bool onlyAdditions );
void FreeSongs(); void FreeSongs();
void UnlistSong(Song *song); void UnlistSong(Song *song);
void Cleanup(); void Cleanup();
@@ -54,7 +60,13 @@ public:
void LoadGroupSymLinks( RString sDir, RString sGroupFolder ); void LoadGroupSymLinks( RString sDir, RString sGroupFolder );
void InitCoursesFromDisk( LoadingWindow *ld ); /**
* @brief Initialize all courses from disk
* @param ld the loading window to be updated, or nullptr
* @param onlyAdditions only load courses added after the last
* invocation of this function
*/
void InitCoursesFromDisk( LoadingWindow *ld, bool onlyAdditions );
void InitAutogenCourses(); void InitAutogenCourses();
void InitRandomAttacks(); void InitRandomAttacks();
void FreeCourses(); void FreeCourses();
@@ -64,8 +76,16 @@ public:
void DeleteAutogenCourses(); void DeleteAutogenCourses();
void InvalidateCachedTrails(); void InvalidateCachedTrails();
void InitAll( LoadingWindow *ld ); // songs, courses, groups - everything. /**
void Reload( LoadingWindow *ld=nullptr ); // songs, courses, groups - everything. * @brief Initialize all songs and courses from disk, and update
* autogenerated courses afterwards
* @param ld the loading window to be updated, or nullptr
* @param onlyAdditions only load songs and courses added after the
* last invocation of this function
*/
void InitAll( LoadingWindow *ld, bool onlyAdditions );
void Reload( LoadingWindow *ld=nullptr );
void LoadAdditions( LoadingWindow *ld=nullptr );
void PreloadSongImages(); void PreloadSongImages();
bool IsGroupNeverCached(const RString& group) const; bool IsGroupNeverCached(const RString& group) const;
@@ -169,8 +189,14 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
protected: protected:
void LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ); /**
void LoadDWISongDir( RString sDir ); * @brief Load all songs from a directory
* @param sDir the directory to be loaded
* @param ld the loading window to be updated, or nullptr
* @param onlyAdditions only load songs added after the last
* invocation of this function
*/
void LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditions );
bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut, StepsType stype ); bool GetExtraStageInfoFromCourse( bool bExtra2, RString sPreferredGroup, Song*& pSongOut, Steps*& pStepsOut, StepsType stype );
void SanityCheckGroupDir( RString sDir ) const; void SanityCheckGroupDir( RString sDir ) const;
void AddGroup( RString sDir, RString sGroupDirName ); void AddGroup( RString sDir, RString sGroupDirName );
@@ -181,11 +207,12 @@ protected:
vector<Song*> m_pSongs; vector<Song*> m_pSongs;
map<RString, Song*> m_SongsByDir; map<RString, Song*> m_SongsByDir;
set<RString> m_GroupsToNeverCache; set<RString> m_GroupsToNeverCache;
/** @brief Hold pointers to all the songs that have been deleted from disk but must at least be kept temporarily alive for smooth audio transitions. */ /** @brief Hold pointers to all the songs that have been deleted from disk but must at least be kept temporarily alive for smooth audio transitions. */
vector<Song*> m_pDeletedSongs; vector<Song*> m_pDeletedSongs;
/** @brief The most popular songs ranked by number of plays. */ /** @brief The most popular songs ranked by number of plays. */
vector<Song*> m_pPopularSongs; vector<Song*> m_pPopularSongs;
//vector<Song*> m_pRecentSongs; // songs recently played on the machine
vector<Song*> m_pShuffledSongs; // used by GetRandomSong vector<Song*> m_pShuffledSongs; // used by GetRandomSong
struct PreferredSortSection struct PreferredSortSection
{ {
+1 -1
View File
@@ -1123,7 +1123,7 @@ int sm_main(int argc, char* argv[])
// depends on SONGINDEX: // depends on SONGINDEX:
SONGMAN = new SongManager; SONGMAN = new SongManager;
SONGMAN->InitAll( pLoadingWindow ); // this takes a long time SONGMAN->InitAll( pLoadingWindow, /*onlyAdditions=*/false ); // this takes a long time
CRYPTMAN = new CryptManager; // need to do this before ProfileMan CRYPTMAN = new CryptManager; // need to do this before ProfileMan
if( PREFSMAN->m_bSignProfileData ) if( PREFSMAN->m_bSignProfileData )
CRYPTMAN->GenerateGlobalKeys(); CRYPTMAN->GenerateGlobalKeys();