Skip to content

Commit

Permalink
use sets for favorited charts instead of vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jun 5, 2017
1 parent edb50a6 commit 27b97b2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
31 changes: 13 additions & 18 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,8 @@ XNode* Profile::SaveGeneralDataCreateNode() const

{
XNode* pFavorites = pGeneralDataNode->AppendChild("Favorites");
FOREACH_CONST(string, FavoritedCharts, it)
pFavorites->AppendChild(*it);
FOREACHS_CONST(string, FavoritedCharts, it)
pFavorites->AppendChild(*it);
}

{
Expand Down Expand Up @@ -1416,7 +1416,7 @@ XNode* Profile::SaveFavoritesCreateNode() const {
CHECKPOINT_M("Saving the favorites node.");

XNode* favs = new XNode("Favorites");
FOREACH_CONST(string, FavoritedCharts, it)
FOREACHS_CONST(string, FavoritedCharts, it)
favs->AppendChild(*it);
return favs;
}
Expand All @@ -1425,7 +1425,7 @@ XNode* Profile::SavePermaMirrorCreateNode() const {
CHECKPOINT_M("Saving the permamirror node.");

XNode* pmir = new XNode("PermaMirror");
FOREACH_CONST(string, PermaMirrorCharts, it)
FOREACHS_CONST(string, PermaMirrorCharts, it)
pmir->AppendChild(*it);
return pmir;
}
Expand Down Expand Up @@ -1464,7 +1464,7 @@ void Profile::LoadFavoritesFromNode(const XNode *pNode) {
CHECKPOINT_M("Loading the favorites node.");

FOREACH_CONST_Child(pNode, ck)
FavoritedCharts.emplace_back(SONGMAN->ReconcileBustedKeys(ck->GetName()));
FavoritedCharts.emplace(SONGMAN->ReconcileBustedKeys(ck->GetName()));

SONGMAN->SetFavoritedStatus(FavoritedCharts);
}
Expand All @@ -1473,7 +1473,7 @@ void Profile::LoadPermaMirrorFromNode(const XNode *pNode) {
CHECKPOINT_M("Loading the permamirror node.");

FOREACH_CONST_Child(pNode, ck)
PermaMirrorCharts.emplace_back(SONGMAN->ReconcileBustedKeys(ck->GetName()));
PermaMirrorCharts.emplace(SONGMAN->ReconcileBustedKeys(ck->GetName()));

SONGMAN->SetPermaMirroredStatus(PermaMirrorCharts);
}
Expand Down Expand Up @@ -1670,11 +1670,11 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
FOREACH_CONST_Child(pFavorites, ck) {
RString tmp = ck->GetName(); // handle duplicated entries caused by an oversight - mina
bool duplicated = false;
FOREACH(string, FavoritedCharts, chartkey)
FOREACHS(string, FavoritedCharts, chartkey)
if (*chartkey == tmp)
duplicated = true;
if (!duplicated)
FavoritedCharts.emplace_back(tmp);
FavoritedCharts.emplace(tmp);
}
SONGMAN->SetFavoritedStatus(FavoritedCharts);
}
Expand Down Expand Up @@ -1884,15 +1884,11 @@ XNode* Profile::SaveSongScoresCreateNode() const
}

void Profile::RemoveFromFavorites(const string& ck) {
for (size_t i = 0; i < FavoritedCharts.size(); ++i)
if (FavoritedCharts[i] == ck)
FavoritedCharts.erase(FavoritedCharts.begin() + i);
FavoritedCharts.erase(ck);
}

void Profile::RemoveFromPermaMirror(const string& ck) {
for (size_t i = 0; i < PermaMirrorCharts.size(); ++i)
if (PermaMirrorCharts[i] == ck)
PermaMirrorCharts.erase(PermaMirrorCharts.begin() + i);
PermaMirrorCharts.erase(ck);
}

void Profile::LoadSongScoresFromNode(const XNode* pSongScores)
Expand Down Expand Up @@ -2624,10 +2620,9 @@ class LunaProfile : public Luna<Profile>

static int IsCurrentChartPermamirror(T* p, lua_State *L) {
bool o = false;
const string& cck = GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey();
FOREACH(string, p->PermaMirrorCharts, ck)
if (*ck == cck)
o = true;
const string& ck = GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey();
if (p->PermaMirrorCharts.count(ck));
o = true;

lua_pushboolean(L, o);
return 1;
Expand Down
8 changes: 4 additions & 4 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ class Profile

// if anymore of these are added they should be enum'd to reduce copy pasta -mina
// and also should be sets
void AddToFavorites(const string& ck) { FavoritedCharts.emplace_back(ck); }
void AddToPermaMirror(const string& ck) { PermaMirrorCharts.emplace_back(ck); }
void AddToFavorites(const string& ck) { FavoritedCharts.emplace(ck); }
void AddToPermaMirror(const string& ck) { PermaMirrorCharts.emplace(ck); }
void RemoveFromFavorites(const string& ck);
void RemoveFromPermaMirror(const string& ck);
vector<string> FavoritedCharts;
vector<string> PermaMirrorCharts;
set<string> FavoritedCharts;
set<string> PermaMirrorCharts;

XNode* SaveFavoritesCreateNode() const;
XNode* SavePermaMirrorCreateNode() const;
Expand Down
8 changes: 4 additions & 4 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,22 +722,22 @@ bool SongManager::IsGroupNeverCached(const RString& group) const
return m_GroupsToNeverCache.find(group) != m_GroupsToNeverCache.end();
}

void SongManager::SetFavoritedStatus(vector<string>& favs) {
void SongManager::SetFavoritedStatus(set<string>& favs) {
FOREACH(Song*, m_pSongs, song) {
FOREACH_CONST(Steps*, (*song)->GetAllSteps(), steps) {
RString sck = (*steps)->GetChartKey();
FOREACH(string, favs, ck)
FOREACHS(string, favs, ck)
if (sck == *ck)
(*song)->SetFavorited(true);
}
}
}

void SongManager::SetPermaMirroredStatus(vector<string>& pmir) {
void SongManager::SetPermaMirroredStatus(set<string>& pmir) {
FOREACH(Song*, m_pSongs, song) {
FOREACH_CONST(Steps*, (*song)->GetAllSteps(), steps) {
RString sck = (*steps)->GetChartKey();
FOREACH(string, pmir, ck)
FOREACHS(string, pmir, ck)
if (sck == *ck)
(*song)->SetPermaMirror(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class SongManager
void PreloadSongImages();

bool IsGroupNeverCached(const RString& group) const;
void SetFavoritedStatus(vector<string>& favs);
void SetPermaMirroredStatus(vector<string>& pmir);
void SetFavoritedStatus(set<string>& favs);
void SetPermaMirroredStatus(set<string>& pmir);
void SetHasGoal(map<RString, vector<ScoreGoal>> goalmap);

RString GetSongGroupBannerPath( const RString &sSongGroup ) const;
Expand Down

0 comments on commit 27b97b2

Please sign in to comment.