Skip to content

Commit 943935a

Browse files
add differential reload to music select screen
1 parent ebad781 commit 943935a

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

src/ScreenSelectMusic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ bool ScreenSelectMusic::Input( const InputEventPlus &input )
511511
m_MusicWheel.ChangeMusic(0);
512512
return true;
513513
}
514+
else if (bHoldingCtrl && c == 'Q' && m_MusicWheel.IsSettled() && input.type == IET_FIRST_PRESS)
515+
{
516+
int newsongs = SONGMAN->DifferentialReload();
517+
m_MusicWheel.ReloadSongList(false, "");
518+
SCREENMAN->SystemMessage(ssprintf("Differential reload of %i songs", newsongs));
519+
return true;
520+
}
514521
else if( input.DeviceI.device == DEVICE_KEYBOARD && bHoldingCtrl && input.DeviceI.button == KEY_BACK && input.type == IET_FIRST_PRESS
515522
&& m_MusicWheel.IsSettled() )
516523
{

src/SongManager.cpp

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,102 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld )
124124
UpdatePreferredSort();
125125
}
126126

127+
// See InitSongsFromDisk for any comment clarification -mina
128+
int SongManager::DifferentialReload() {
129+
int newsongs = 0;
130+
SONGINDEX->delay_save_cache = true;
131+
newsongs += DifferentialReloadDir(SpecialFiles::SONGS_DIR);
132+
133+
const bool bOldVal = PREFSMAN->m_bFastLoad;
134+
PREFSMAN->m_bFastLoad.Set(PREFSMAN->m_bFastLoadAdditionalSongs);
135+
newsongs += DifferentialReloadDir(ADDITIONAL_SONGS_DIR);
136+
PREFSMAN->m_bFastLoad.Set(bOldVal);
137+
LoadEnabledSongsFromPref();
138+
SONGINDEX->SaveCacheIndex();
139+
SONGINDEX->delay_save_cache = false;
140+
141+
return newsongs;
142+
}
143+
144+
// See LoadStepManiaSongDir for any comment clarification -mina
145+
int SongManager::DifferentialReloadDir(string dir) {
146+
if (dir.substr(dir.size()) != "/")
147+
dir += "/";
148+
149+
int newsongs = 0;
150+
151+
vector<RString> arrayGroupDirs;
152+
GetDirListing(dir + "*", arrayGroupDirs, true);
153+
StripCvsAndSvn(arrayGroupDirs);
154+
StripMacResourceForks(arrayGroupDirs);
155+
SortRStringArray(arrayGroupDirs);
156+
157+
vector< vector<RString> > arrayGroupSongDirs;
158+
int groupIndex, songCount, songIndex;
159+
160+
groupIndex = 0;
161+
songCount = 0;
162+
FOREACH_CONST(RString, arrayGroupDirs, s) {
163+
RString sGroupDirName = *s;
164+
SanityCheckGroupDir(dir + sGroupDirName);
165+
166+
vector<RString> arraySongDirs;
167+
GetDirListing(dir + sGroupDirName + "/*", arraySongDirs, true, true);
168+
StripCvsAndSvn(arraySongDirs);
169+
StripMacResourceForks(arraySongDirs);
170+
SortRStringArray(arraySongDirs);
171+
172+
arrayGroupSongDirs.push_back(arraySongDirs);
173+
songCount += arraySongDirs.size();
174+
}
175+
176+
if (songCount == 0) return 0;
177+
178+
groupIndex = 0;
179+
songIndex = 0;
180+
181+
FOREACH_CONST(RString, arrayGroupDirs, s) {
182+
RString sGroupDirName = *s;
183+
vector<RString> &arraySongDirs = arrayGroupSongDirs[groupIndex++];
184+
int loaded = 0;
185+
186+
SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
187+
RString group_base_name = Basename(sGroupDirName);
188+
for (size_t j = 0; j < arraySongDirs.size(); ++j) {
189+
RString sSongDirName = arraySongDirs[j];
190+
191+
// skip any dir we've already loaded -mina
192+
RString hur = sSongDirName + "/";
193+
hur.MakeLower();
194+
if (m_SongsByDir.count(hur))
195+
continue;
196+
197+
Song* pNewSong = new Song;
198+
if (!pNewSong->LoadFromSongDir(sSongDirName)) {
199+
delete pNewSong;
200+
continue;
201+
}
202+
203+
AddSongToList(pNewSong);
204+
AddKeyedPointers(pNewSong);
205+
206+
index_entry.push_back(pNewSong);
207+
208+
loaded++;
209+
songIndex++;
210+
newsongs++;
211+
}
212+
213+
LOG->Trace("Differential load of %i songs from \"%s\"", loaded, (dir + sGroupDirName).c_str());
214+
if (!loaded) continue;
215+
216+
AddGroup(dir, sGroupDirName);
217+
BANNERCACHE->CacheBanner(GetSongGroupBannerPath(sGroupDirName));
218+
LoadGroupSymLinks(dir, sGroupDirName);
219+
}
220+
return newsongs;
221+
}
222+
127223
void SongManager::InitSongsFromDisk( LoadingWindow *ld )
128224
{
129225
RageTimer tm;
@@ -140,7 +236,7 @@ void SongManager::InitSongsFromDisk( LoadingWindow *ld )
140236
SONGINDEX->SaveCacheIndex();
141237
SONGINDEX->delay_save_cache= false;
142238

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

146242
void Chart::FromKey(const string& ck) {

src/SongManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class SongManager
9898

9999
void InitAll( LoadingWindow *ld ); // songs, groups - everything.
100100
void Reload( bool bAllowFastLoad, LoadingWindow *ld=NULL ); // songs, groups - everything.
101+
int DifferentialReload();
102+
int DifferentialReloadDir(string dir);
101103
void PreloadSongImages();
102104

103105
bool IsGroupNeverCached(const RString& group) const;

0 commit comments

Comments
 (0)