Skip to content

Commit

Permalink
add top2 score assignment for charts
Browse files Browse the repository at this point in the history
set top scores on load and on save
  • Loading branch information
MinaciousGrace committed Nov 4, 2017
1 parent f2216ac commit 5df2fc0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ void Profile::CalculateStatsFromScores(LoadingWindow* ld) {
m_iTotalGameplaySeconds = static_cast<int>(TotalGameplaySeconds);

SCOREMAN->RecalculateSSRs(ld);
SCOREMAN->SetAllTopScores();
SCOREMAN->CalcPlayerRating(m_fPlayerRating, m_fPlayerSkillsets);
//SCOREMAN->RatingOverTime();
}
Expand Down Expand Up @@ -2136,6 +2137,8 @@ XNode* Profile::SaveEttScoresCreateNode() const {

const Profile* pProfile = this;
ASSERT(pProfile != NULL);

SCOREMAN->SetAllTopScores();
XNode* pNode = SCOREMAN->CreateNode();
return pNode;
}
Expand Down
34 changes: 33 additions & 1 deletion src/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,32 @@ string ScoresForChart::RateKeyToDisplayString(float rate) {
return rs;
}

// seems like this could be handled more elegantly by splitting operations up -mina
void ScoresForChart::SetTopScores() {
vector<HighScore*> eligiblescores;
FOREACHM(int, ScoresAtRate, ScoresByRate, i) {
auto& hs = i->second.noccPBptr;
if (hs && hs->GetSSRCalcVersion() == GetCalcVersion() && hs->GetEtternaValid() && hs->GetChordCohesion() == 0 && hs->GetGrade() != Grade_Failed)
eligiblescores.emplace_back(hs);
}

if (eligiblescores.empty())
return;

if (eligiblescores.size() == 1) {
eligiblescores[0]->SetTopScore(1);
return;
}

auto ssrcomp = [](HighScore* a, HighScore* b) { return (a->GetSkillsetSSR(Skill_Overall) > b->GetSkillsetSSR(Skill_Overall)); };
sort(eligiblescores.begin(), eligiblescores.end(), ssrcomp);

for (auto hs : eligiblescores)
hs->SetTopScore(0);

eligiblescores[0]->SetTopScore(1);
eligiblescores[1]->SetTopScore(2);
}

vector<HighScore*> ScoresForChart::GetAllPBPtrs() {
vector<HighScore*> o;
Expand All @@ -204,7 +230,13 @@ HighScore* ScoreManager::GetChartPBUpTo(const string& ck, float& rate) {
return NULL;
}


void ScoreManager::SetAllTopScores() {
FOREACHUM(string, ScoresForChart, pscores, i) {
if (!SONGMAN->IsChartLoaded(i->first))
continue;
i->second.SetTopScores();
}
}

static const float ld_update = 0.02f;
void ScoreManager::RecalculateSSRs(LoadingWindow *ld) {
Expand Down
5 changes: 5 additions & 0 deletions src/ScoreManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct ScoresForChart

ScoresAtRate operator[](const int rate) { return ScoresByRate.at(rate); }
map<int, ScoresAtRate, greater<int>> ScoresByRate;

// Sets rate indepdendent topscore tags inside highscores. 1 = best. 2 = 2nd. 0 = the rest. -mina
void SetTopScores();
private:
/* It makes sense internally to have the map keys sorted highest rate to lowest
however my experience in lua is that it tends to be more friendly to approach things
Expand Down Expand Up @@ -127,6 +130,8 @@ class ScoreManager
vector<HighScore*> GetAllScores() { return AllScores; }
void RegisterScore(HighScore* hs) { AllScores.emplace_back(hs); }
void AddToKeyedIndex(HighScore* hs) { ScoresByKey.emplace(hs->GetScoreKey(), hs); }

void SetAllTopScores();
private:
unordered_map<string, ScoresForChart> pscores; // Profile scores

Expand Down

0 comments on commit 5df2fc0

Please sign in to comment.