Skip to content

Commit

Permalink
add differential reload to music select screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 22, 2017
1 parent ebad781 commit 943935a
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ bool ScreenSelectMusic::Input( const InputEventPlus &input )
m_MusicWheel.ChangeMusic(0);
return true;
}
else if (bHoldingCtrl && c == 'Q' && m_MusicWheel.IsSettled() && input.type == IET_FIRST_PRESS)
{
int newsongs = SONGMAN->DifferentialReload();
m_MusicWheel.ReloadSongList(false, "");
SCREENMAN->SystemMessage(ssprintf("Differential reload of %i songs", newsongs));
return true;
}
else if( input.DeviceI.device == DEVICE_KEYBOARD && bHoldingCtrl && input.DeviceI.button == KEY_BACK && input.type == IET_FIRST_PRESS
&& m_MusicWheel.IsSettled() )
{
Expand Down
98 changes: 97 additions & 1 deletion src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,102 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld )
UpdatePreferredSort();
}

// See InitSongsFromDisk for any comment clarification -mina
int SongManager::DifferentialReload() {
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;
}

// See LoadStepManiaSongDir for any comment clarification -mina
int SongManager::DifferentialReloadDir(string dir) {
if (dir.substr(dir.size()) != "/")
dir += "/";

int newsongs = 0;

vector<RString> arrayGroupDirs;
GetDirListing(dir + "*", arrayGroupDirs, true);
StripCvsAndSvn(arrayGroupDirs);
StripMacResourceForks(arrayGroupDirs);
SortRStringArray(arrayGroupDirs);

vector< vector<RString> > arrayGroupSongDirs;
int groupIndex, songCount, songIndex;

groupIndex = 0;
songCount = 0;
FOREACH_CONST(RString, arrayGroupDirs, s) {
RString sGroupDirName = *s;
SanityCheckGroupDir(dir + sGroupDirName);

vector<RString> arraySongDirs;
GetDirListing(dir + sGroupDirName + "/*", arraySongDirs, true, true);
StripCvsAndSvn(arraySongDirs);
StripMacResourceForks(arraySongDirs);
SortRStringArray(arraySongDirs);

arrayGroupSongDirs.push_back(arraySongDirs);
songCount += arraySongDirs.size();
}

if (songCount == 0) return 0;

groupIndex = 0;
songIndex = 0;

FOREACH_CONST(RString, arrayGroupDirs, s) {
RString sGroupDirName = *s;
vector<RString> &arraySongDirs = arrayGroupSongDirs[groupIndex++];
int loaded = 0;

SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
RString group_base_name = Basename(sGroupDirName);
for (size_t j = 0; j < arraySongDirs.size(); ++j) {
RString sSongDirName = arraySongDirs[j];

// skip any dir we've already loaded -mina
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.push_back(pNewSong);

loaded++;
songIndex++;
newsongs++;
}

LOG->Trace("Differential load of %i songs from \"%s\"", loaded, (dir + sGroupDirName).c_str());
if (!loaded) continue;

AddGroup(dir, sGroupDirName);
BANNERCACHE->CacheBanner(GetSongGroupBannerPath(sGroupDirName));
LoadGroupSymLinks(dir, sGroupDirName);
}
return newsongs;
}

void SongManager::InitSongsFromDisk( LoadingWindow *ld )
{
RageTimer tm;
Expand All @@ -140,7 +236,7 @@ void SongManager::InitSongsFromDisk( LoadingWindow *ld )
SONGINDEX->SaveCacheIndex();
SONGINDEX->delay_save_cache= false;

LOG->Trace( "Found %d songs in %f seconds.", (int)m_pSongs.size(), tm.GetDeltaTime() );
LOG->Trace( "Found %i songs in %f seconds.", m_pSongs.size(), tm.GetDeltaTime() );
}

void Chart::FromKey(const string& ck) {
Expand Down
2 changes: 2 additions & 0 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class SongManager

void InitAll( LoadingWindow *ld ); // songs, groups - everything.
void Reload( bool bAllowFastLoad, LoadingWindow *ld=NULL ); // songs, groups - everything.
int DifferentialReload();
int DifferentialReloadDir(string dir);
void PreloadSongImages();

bool IsGroupNeverCached(const RString& group) const;
Expand Down

0 comments on commit 943935a

Please sign in to comment.