Skip to content

Commit

Permalink
actually make top grades sort internally by wife%
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jul 8, 2020
1 parent 6bdbf98 commit 42ffff0
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 160 deletions.
6 changes: 2 additions & 4 deletions src/Etterna/Actor/Menus/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ MusicWheel::BuildWheelItemDatas(
SongUtil::SortSongPointerArrayByBPM(arraySongs);
break;
case SORT_TOP_GRADES:
SongUtil::SortSongPointerArrayByGrades(arraySongs, true);
SongUtil::SortSongPointerArrayByWifeScore(arraySongs);
break;
case SORT_ARTIST:
SongUtil::SortSongPointerArrayByArtist(arraySongs);
Expand Down Expand Up @@ -887,11 +887,9 @@ MusicWheel::BuildWheelItemDatas(
* sort. */
switch (so) {
case SORT_FAVORITES:
case SORT_TOP_GRADES:
case SORT_BPM:
break; // don't sort by section
case SORT_TOP_GRADES:
SongUtil::SortSongPointerArrayByWifeScore(arraySongs, so);
break;
default:
SongUtil::SortSongPointerArrayBySectionName(arraySongs, so);
break;
Expand Down
32 changes: 12 additions & 20 deletions src/Etterna/Models/Misc/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,14 @@ Profile::SetDefaultModifiers(const Game* pGameType,
}

auto
Profile::GetBestGrade(const Song* pSong, StepsType st) const -> Grade
Profile::GetBestGrade(const Song* song, const StepsType st) const -> Grade
{
auto gradeBest = Grade_Invalid;
if (pSong != nullptr) {
auto hasCurrentStyleSteps = false;
FOREACH_ENUM_N(Difficulty, 6, i)
{
auto* pSteps = SongUtil::GetStepsByDifficulty(pSong, st, i);
if (pSteps != nullptr) {
hasCurrentStyleSteps = true;
if (song != nullptr) {
for (const auto& s : song->GetAllSteps()) {
if (s != nullptr && s->m_StepsType == st) {
const auto dcg =
SCOREMAN->GetBestGradeFor(pSteps->GetChartKey());
SCOREMAN->GetBestGradeFor(s->GetChartKey(), m_sProfileID);
if (gradeBest >= dcg) {
gradeBest = dcg;
}
Expand All @@ -187,19 +183,15 @@ Profile::GetBestGrade(const Song* pSong, StepsType st) const -> Grade
}

auto
Profile::GetBestWifeScore(const Song* pSong, StepsType st) const -> float
Profile::GetBestWifeScore(const Song* song, const StepsType st) const -> float
{
auto scorebest = 0.F;
if (pSong != nullptr) {
auto hasCurrentStyleSteps = false;
FOREACH_ENUM_N(Difficulty, 6, i)
{
auto* pSteps = SongUtil::GetStepsByDifficulty(pSong, st, i);
if (pSteps != nullptr) {
hasCurrentStyleSteps = true;
if (song != nullptr) {
for (const auto& s : song->GetAllSteps()) {
if (s != nullptr && s->m_StepsType == st) {
const auto wsb =
SCOREMAN->GetBestWifeScoreFor(pSteps->GetChartKey());
if (scorebest >= wsb) {
SCOREMAN->GetBestWifeScoreFor(s->GetChartKey(), m_sProfileID);
if (wsb >= scorebest) {
scorebest = wsb;
}
}
Expand Down Expand Up @@ -393,7 +385,7 @@ Profile::CalculateStatsFromScores(LoadingWindow* ld)
m_iTotalDancePoints = m_iTotalTapsAndHolds * 2;
m_iTotalGameplaySeconds = static_cast<int>(TotalGameplaySeconds);

SCOREMAN->RecalculateSSRs(ld, m_sProfileID);
SCOREMAN->RecalculateSSRs(ld);
SCOREMAN->CalcPlayerRating(
m_fPlayerRating, m_fPlayerSkillsets, m_sProfileID);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Etterna/Models/Misc/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class Profile
LuaTable m_UserTable;

// this actually does use scoreman atm
auto GetBestGrade(const Song* pSong, StepsType st) const -> Grade;
auto GetBestWifeScore(const Song* pSong, StepsType st) const -> float;
auto GetBestGrade(const Song* song, StepsType st) const -> Grade;
auto GetBestWifeScore(const Song* song, StepsType st) const -> float;

// Screenshot Data
std::vector<Screenshot> m_vScreenshots;
Expand Down
70 changes: 16 additions & 54 deletions src/Etterna/Models/Songs/SongUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,67 +468,29 @@ AppendOctal(int n, int digits, std::string& out)
}
}

static bool
CompDescending(const pair<Song*, int>& a, const pair<Song*, int>& b)
static auto
get_best_wife_score_for_song_and_profile(const Song* song, const Profile* p)
-> float
{
return a.second < b.second;
assert(p != nullptr);
return p->GetBestWifeScore(
song,
GAMESTATE->GetCurrentStyle(GAMESTATE->GetMasterPlayerNumber())
->m_StepsType);
}

static bool
CompAscending(const pair<Song*, int>& a, const pair<Song*, int>& b)
static int
CompareSongPointersByBestWifeScore(const Song* a, const Song* b)
{
return a.second > b.second;
const auto* p = PROFILEMAN->GetProfile(PLAYER_1);
return get_best_wife_score_for_song_and_profile(a, p) >
get_best_wife_score_for_song_and_profile(b, p);
}

void
SongUtil::SortSongPointerArrayByGrades(vector<Song*>& vpSongsInOut,
bool bDescending)
{
typedef pair<Song*, int> val;
vector<val> vals;
vals.reserve(vpSongsInOut.size());
const Profile* pProfile = PROFILEMAN->GetProfile(PLAYER_1);

for (auto* pSong : vpSongsInOut) {
ASSERT(pProfile != nullptr);
auto g = static_cast<int>(pProfile->GetBestGrade(
pSong,
GAMESTATE->GetCurrentStyle(GAMESTATE->GetMasterPlayerNumber())
->m_StepsType));
vals.emplace_back(val(pSong, g));
}

sort(
vals.begin(), vals.end(), bDescending ? CompDescending : CompAscending);

for (unsigned i = 0; i < vpSongsInOut.size(); ++i)
vpSongsInOut[i] = vals[i].first;
}

// do not know why this doesn't work
void
SongUtil::SortSongPointerArrayByWifeScore(vector<Song*>& vpSongsInOut,
bool bDescending)
{
typedef pair<Song*, float> val;
vector<val> vals;
vals.reserve(vpSongsInOut.size());
const Profile* pProfile = PROFILEMAN->GetProfile(PLAYER_1);

for (auto* pSong : vpSongsInOut) {
ASSERT(pProfile != nullptr);
auto g = static_cast<int>(pProfile->GetBestWifeScore(
pSong,
GAMESTATE->GetCurrentStyle(GAMESTATE->GetMasterPlayerNumber())
->m_StepsType));
vals.emplace_back(val(pSong, g));
}

sort(
vals.begin(), vals.end(), bDescending ? CompDescending : CompAscending);

for (unsigned i = 0; i < vpSongsInOut.size(); ++i)
vpSongsInOut[i] = vals[i].first;
SongUtil::SortSongPointerArrayByWifeScore(vector<Song*>& v)
{
sort(v.begin(), v.end(), CompareSongPointersByBestWifeScore);
}

void
Expand Down
4 changes: 1 addition & 3 deletions src/Etterna/Models/Songs/SongUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ SortSongPointerArrayByTitle(vector<Song*>& vpSongsInOut);
void
SortSongPointerArrayByBPM(vector<Song*>& vpSongsInOut);
void
SortSongPointerArrayByGrades(vector<Song*>& vpSongsInOut, bool bDescending);
void
SortSongPointerArrayByWifeScore(vector<Song*>& vpSongsInOut, bool bDescending);
SortSongPointerArrayByWifeScore(vector<Song*>& v);
void
SortSongPointerArrayByArtist(vector<Song*>& vpSongsInOut);
void
Expand Down
Loading

0 comments on commit 42ffff0

Please sign in to comment.