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"
Fallback="Screen"
NextScreen=Branch.TitleMenu()
OnlyLoadAdditions=false
[ScreenPlayerOptions]
Fallback="ScreenOptions"
+1
View File
@@ -85,6 +85,7 @@ public:
XNode* CreateNode() const;
void LoadFromNode( const XNode* pNode );
void FromPath( RString _sPath ) { sPath = _sPath; }
RString ToString() const;
bool IsValid() const;
+1 -1
View File
@@ -177,7 +177,7 @@ void ScreenInstallOverlay::Update( float fDeltaTime )
playAfterLaunchInfo.OverlayWith( pali2 );
}
if( playAfterLaunchInfo.bAnySongChanged )
SONGMAN->Reload( nullptr );
SONGMAN->Reload();
if( !playAfterLaunchInfo.sSongDir.empty() )
{
+9 -1
View File
@@ -77,7 +77,15 @@ void ScreenReloadSongs::Update( float fDeltaTime )
ASSERT( !IsFirstUpdate() );
SONGMAN->Reload( m_pLoadingWindow );
bool onlyLoadAdditions = THEME->GetMetricB(m_sName, "OnlyLoadAdditions");
if (onlyLoadAdditions)
{
SONGMAN->LoadAdditions( m_pLoadingWindow );
}
else
{
SONGMAN->Reload( m_pLoadingWindow );
}
SCREENMAN->PostMessageToTopScreen( SM_GoToNextScreen, 0 );
}
+53 -11
View File
@@ -93,7 +93,7 @@ SongManager::~SongManager()
FreeSongs();
}
void SongManager::InitAll( LoadingWindow *ld )
void SongManager::InitAll( LoadingWindow *ld, bool onlyAdditions )
{
vector<RString> never_cache;
split(PREFSMAN->m_NeverCacheList, ",", never_cache);
@@ -102,8 +102,12 @@ void SongManager::InitAll( LoadingWindow *ld )
{
m_GroupsToNeverCache.insert(*group);
}
InitSongsFromDisk( ld );
InitCoursesFromDisk( ld );
InitSongsFromDisk( ld, onlyAdditions );
InitCoursesFromDisk( ld, onlyAdditions );
if (onlyAdditions)
{
DeleteAutogenCourses();
}
InitAutogenCourses();
InitRandomAttacks();
}
@@ -168,7 +172,7 @@ void SongManager::Reload( LoadingWindow *ld )
FreeSongs();
InitAll( ld );
InitAll( ld, /*onlyAdditions=*/false );
// reload scores and unlocks afterward
PROFILEMAN->LoadMachineProfile();
@@ -202,17 +206,30 @@ void SongManager::Reload( LoadingWindow *ld )
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;
// Tell SONGINDEX to not write the cache index file every time a song adds
// an entry. -Kyz
SONGINDEX->delay_save_cache = true;
IMAGECACHE->delay_save_cache = true;
LoadStepManiaSongDir( SpecialFiles::SONGS_DIR, ld );
LoadSongDir( SpecialFiles::SONGS_DIR, ld, onlyAdditions );
LoadEnabledSongsFromPref();
SONGINDEX->SaveCacheIndex();
SONGINDEX->delay_save_cache= false;
SONGINDEX->delay_save_cache = false;
IMAGECACHE->WriteToDisk();
IMAGECACHE->delay_save_cache = false;
@@ -312,8 +329,11 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName )
}
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
// loading window, which slows down startup time for some people.
// 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];
// 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.
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;
if( !pNewSong->LoadFromSongDir( sSongDirName ) )
{
@@ -754,9 +784,9 @@ void SongManager::ResetGroupColors()
COURSE_GROUP_COLOR.Clear();
NUM_SONG_GROUP_COLORS .Load( "SongManager", "NumSongGroupColors" );
SONG_GROUP_COLOR .Load( "SongManager", SONG_GROUP_COLOR_NAME, NUM_SONG_GROUP_COLORS );
SONG_GROUP_COLOR .Load( "SongManager", SONG_GROUP_COLOR_NAME, NUM_SONG_GROUP_COLORS );
NUM_COURSE_GROUP_COLORS .Load( "SongManager", "NumCourseGroupColors" );
COURSE_GROUP_COLOR .Load( "SongManager", COURSE_GROUP_COLOR_NAME, NUM_COURSE_GROUP_COLORS );
COURSE_GROUP_COLOR .Load( "SongManager", COURSE_GROUP_COLOR_NAME, NUM_COURSE_GROUP_COLORS );
}
const vector<Song*> &SongManager::GetSongs( const RString &sGroupName ) const
@@ -869,9 +899,12 @@ RString SongManager::ShortenGroupName( RString sLongGroupName )
}
static LocalizedString LOADING_COURSES ( "SongManager", "Loading courses..." );
void SongManager::InitCoursesFromDisk( LoadingWindow *ld )
void SongManager::InitCoursesFromDisk( LoadingWindow *ld, bool onlyAdditions )
{
LOG->Trace( "Loading courses." );
if( ld )
ld->SetText( LOADING_COURSES );
RageTimer loading_window_last_update_time;
loading_window_last_update_time.Touch();
@@ -902,6 +935,15 @@ void SongManager::InitCoursesFromDisk( LoadingWindow *ld )
RString base_course_group= Basename(sCourseGroup);
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)
{
loading_window_last_update_time.Touch();
+37 -10
View File
@@ -35,7 +35,13 @@ public:
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 UnlistSong(Song *song);
void Cleanup();
@@ -54,7 +60,13 @@ public:
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 InitRandomAttacks();
void FreeCourses();
@@ -64,8 +76,16 @@ public:
void DeleteAutogenCourses();
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();
bool IsGroupNeverCached(const RString& group) const;
@@ -169,8 +189,14 @@ public:
void PushSelf( lua_State *L );
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 );
void SanityCheckGroupDir( RString sDir ) const;
void AddGroup( RString sDir, RString sGroupDirName );
@@ -181,12 +207,13 @@ protected:
vector<Song*> m_pSongs;
map<RString, Song*> m_SongsByDir;
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. */
vector<Song*> m_pDeletedSongs;
vector<Song*> m_pDeletedSongs;
/** @brief The most popular songs ranked by number of plays. */
vector<Song*> m_pPopularSongs;
//vector<Song*> m_pRecentSongs; // songs recently played on the machine
vector<Song*> m_pShuffledSongs; // used by GetRandomSong
vector<Song*> m_pPopularSongs;
vector<Song*> m_pShuffledSongs; // used by GetRandomSong
struct PreferredSortSection
{
RString sName;
+1 -1
View File
@@ -1123,7 +1123,7 @@ int sm_main(int argc, char* argv[])
// depends on SONGINDEX:
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
if( PREFSMAN->m_bSignProfileData )
CRYPTMAN->GenerateGlobalKeys();