Skip to content

Commit

Permalink
Update the loading window less
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jul 26, 2018
1 parent 5a757e7 commit 9863e31
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,10 @@ ProfileLoadResult Profile::LoadAllFromDir( const RString &sDir, bool bRequireSig
ld->SetText("Migrating replay data to new folder...");
}
int replayindex = 0;
int onePercent = std::max(replays.size(), 1u);

for (auto r : replays) {
if (ld && ld_timer.Ago() > ld_update) {
if (ld && replayindex%onePercent==0 && ld_timer.Ago() > ld_update) {
ld_timer.Touch();
ld->SetProgress(replayindex);
++replayindex;
Expand Down
3 changes: 2 additions & 1 deletion src/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ void ScoreManager::RecalculateSSRs(LoadingWindow *ld, const string& profileID) {
ld->SetText("\nUpdating Ratings");
}

int onePercent = std::max(scores.size()/100, 1u);
int scoreindex = 0;
for(size_t i = 0; i < scores.size(); ++i) {
if (ld && ld_timer.Ago() > ld_update) {
if (ld && scoreindex%onePercent==0 && ld_timer.Ago() > ld_update) {
ld_timer.Touch();
ld->SetProgress(i);
}
Expand Down
13 changes: 9 additions & 4 deletions src/SongCacheIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "CommonMetrics.h"
#include "Steps.h"
#include "NotesLoaderSSC.h"
#include <algorithm>
#include "NotesWriterSSC.h"

#include <SQLiteCpp/SQLiteCpp.h>
Expand Down Expand Up @@ -607,10 +608,12 @@ void SongCacheIndex::LoadHyperCache(LoadingWindow * ld, map<RString, Song*>& hyp
int count = db->execAndGet("SELECT COUNT(*) FROM songs");
if (ld && count > 0) {
ld->SetIndeterminate(false);
ld->SetProgress(0);
ld->SetTotalWork(count);
}
RString lastDir;
int progress = 0;
int onePercent = std::max(count / 100, 1);
try {
SQLite::Statement query(*db, "SELECT * FROM songs");

Expand All @@ -620,11 +623,11 @@ void SongCacheIndex::LoadHyperCache(LoadingWindow * ld, map<RString, Song*>& hyp
hyperCache[songID.first] = s;
lastDir = songID.first;
// this is a song directory. Load a new song.
if (ld)
progress++;
if (ld && progress%onePercent==0)
{
ld->SetProgress(progress);
ld->SetText(("Loading Cache\n (" + lastDir + ")").c_str());
progress++;
}
}

Expand All @@ -642,10 +645,12 @@ void SongCacheIndex::LoadCache(LoadingWindow * ld, map<pair<RString, unsigned in
int count = db->execAndGet("SELECT COUNT(*) FROM songs");
if (ld && count > 0) {
ld->SetIndeterminate(false);
ld->SetProgress(0);
ld->SetTotalWork(count);
}
RString lastDir;
int progress = 0;
int onePercent = std::max(count / 100, 1);
try {
SQLite::Statement query(*db, "SELECT * FROM songs");

Expand All @@ -655,11 +660,11 @@ void SongCacheIndex::LoadCache(LoadingWindow * ld, map<pair<RString, unsigned in
cache[songID] = s;
lastDir = songID.first;
// this is a song directory. Load a new song.
if (ld)
progress++;
if (ld && progress % onePercent == 0)
{
ld->SetProgress(progress);
ld->SetText(("Loading Cache\n(" + lastDir + ")").c_str());
progress++;
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LocalizedString.h"
#include "MsdFile.h"
#include "NoteSkinManager.h"
#include <algorithm>
#include "NotesLoaderDWI.h"
#include "NotesLoaderSM.h"
#include "NotesLoaderSSC.h"
Expand Down Expand Up @@ -211,10 +212,11 @@ void SongManager::InitSongsFromDisk( LoadingWindow *ld )
ld->SetTotalWork( cache.size() );
ld->SetText("Loading songs from cache");
}
int onePercent = std::max(cache.size() / 100, 1u);
int cacheIndex = 0;
for (auto& pair : cache) {
cacheIndex++;
if(ld && cacheIndex%4 ==0)
if(ld && cacheIndex%onePercent ==0)
ld->SetProgress(cacheIndex);
auto& pNewSong = pair.second;
const RString& dir = pNewSong->GetSongDir();
Expand Down Expand Up @@ -288,11 +290,6 @@ void Playlist::AddChart(const string & ck) {
Chart ch;
ch.FromKey(ck);
ch.rate = rate;

if (!chartlist.empty())
if (chartlist[0].stepsptr->m_StepsType != ch.stepsptr->m_StepsType)
return;

chartlist.emplace_back(ch);
}

Expand Down Expand Up @@ -593,6 +590,7 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
ld->SetText("Sanity checking groups");
}
int groupsChecked = 0;
int onePercent = std::max(arrayGroupDirs.size()/ 100, 1u);
FOREACH_CONST(RString, arrayGroupDirs, s) {
RString sGroupDirName = *s;
SanityCheckGroupDir(sDir + sGroupDirName);
Expand All @@ -603,7 +601,7 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
SortRStringArray(arraySongDirs);
arrayGroupSongDirs.emplace_back(arraySongDirs);
songCount += arraySongDirs.size();
if(ld != nullptr)
if(ld != nullptr && groupsChecked%onePercent ==0)
ld->SetProgress(++groupsChecked);
}

Expand All @@ -613,19 +611,18 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld )
ld->SetTotalWork(arrayGroupDirs.size());
}
int groupIndex = 0;
int songIndex = 0;
onePercent = std::max(arrayGroupDirs.size() / 100, 1u);
FOREACH_CONST(RString, arrayGroupDirs, s) {
RString sGroupDirName = *s;
vector<RString> &arraySongDirs = arrayGroupSongDirs[groupIndex++];
if (ld) {
if (ld && groupIndex&onePercent==0) {
ld->SetProgress(groupIndex);
ld->SetText("Loading Songs From Disk\n" + sGroupDirName);
}
int loaded = 0;
SongPointerVector& index_entry = m_mapSongGroupIndex[sGroupDirName];
RString group_base_name = Basename(sGroupDirName);
for (size_t j = 0; j < arraySongDirs.size(); ++j) {
songIndex++;
RString sSongDirName = arraySongDirs[j];
RString hur = sSongDirName + "/";
hur.MakeLower();
Expand Down

0 comments on commit 9863e31

Please sign in to comment.