Skip to content

Commit

Permalink
Add an additional Highscore pointer vector for filtered scores by game
Browse files Browse the repository at this point in the history
just in case efficiency becomes really necessary
also it got just a little confusing when not doing this, causing the player overall calculation to use only solo scores or so on, breaking it
  • Loading branch information
poco0317 committed Jul 6, 2020
1 parent 41c5f6f commit 8c2f738
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Etterna/Singletons/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,25 @@ ScoreManager::SortTopSSRPtrs(Skillset ss, const string& profileID)
sort(TopSSRs.begin(), TopSSRs.end(), ssrcomp);
}

void
ScoreManager::SortTopSSRPtrsForGame(Skillset ss, const string& profileID)
{
TopSSRsForGame.clear();
for (auto& i : pscores[profileID]) {
if (!SONGMAN->IsChartLoaded(i.first) || !SONGMAN->GetStepsByChartkey(i.first)->IsPlayableForCurrentGame()) {
continue;
}
for (auto& hs : i.second.GetAllPBPtrs()) {
TopSSRsForGame.emplace_back(hs);
}
}

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

auto
ScoreManager::GetTopSSRHighScore(unsigned int rank, int ss) -> HighScore*
{
Expand All @@ -823,6 +842,16 @@ ScoreManager::GetTopSSRHighScore(unsigned int rank, int ss) -> HighScore*
return nullptr;
}

auto
ScoreManager::GetTopSSRHighScoreForGame(unsigned int rank, int ss) -> HighScore*
{
if (ss >= 0 && ss < NUM_Skillset && rank < TopSSRsForGame.size()) {
return TopSSRsForGame[rank];
}

return nullptr;
}

void
ScoreManager::ImportScore(const HighScore& hs_, const string& profileID)
{
Expand Down Expand Up @@ -1098,6 +1127,12 @@ class LunaScoreManager : public Luna<ScoreManager>
return 1;
}

static auto SortSSRsForGame(T* p, lua_State* L) -> int
{
p->SortTopSSRPtrsForGame(Enum::Check<Skillset>(L, 1));
return 1;
}

static auto GetTopSSRHighScore(T* p, lua_State* L) -> int
{
HighScore* ths =
Expand All @@ -1110,6 +1145,18 @@ class LunaScoreManager : public Luna<ScoreManager>
return 1;
}

static auto GetTopSSRHighScoreForGame(T* p, lua_State* L) -> int
{
HighScore* ths =
p->GetTopSSRHighScoreForGame(IArg(1) - 1, Enum::Check<Skillset>(L, 2));
if (ths != nullptr) {
ths->PushSelf(L);
} else {
lua_pushnil(L);
}
return 1;
}

static auto GetMostRecentScore(T* p, lua_State* L) -> int
{
// this _should_ always be viable if only called from eval
Expand All @@ -1129,7 +1176,9 @@ class LunaScoreManager : public Luna<ScoreManager>
{
ADD_METHOD(GetScoresByKey);
ADD_METHOD(SortSSRs);
ADD_METHOD(SortSSRsForGame);
ADD_METHOD(GetTopSSRHighScore);
ADD_METHOD(GetTopSSRHighScoreForGame);
ADD_METHOD(GetMostRecentScore);
ADD_METHOD(GetTempReplayScore);
ADD_METHOD(GetTotalNumberOfScores);
Expand Down
6 changes: 6 additions & 0 deletions src/Etterna/Singletons/ScoreManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class ScoreManager
void SortTopSSRPtrs(Skillset ss,
const std::string& profileID =
PROFILEMAN->GetProfile(PLAYER_1)->m_sProfileID);
void SortTopSSRPtrsForGame(
Skillset ss,
const string& profileID = PROFILEMAN->GetProfile(PLAYER_1)->m_sProfileID);
void RecalculateSSRs(LoadingWindow* ld, const std::string& profileID);
void RecalculateSSRs(const std::string& profileID);
void UnInvalidateAllScores(const string& profileID);
Expand All @@ -172,6 +175,8 @@ class ScoreManager
auto GetTopSSRValue(unsigned int rank, int ss) -> float;

auto GetTopSSRHighScore(unsigned int rank, int ss) -> HighScore*;
auto GetTopSSRHighScoreForGame(unsigned int rank, int ss) -> HighScore*;


[[nodiscard]] auto KeyHasScores(
const std::string& ck,
Expand Down Expand Up @@ -264,6 +269,7 @@ class ScoreManager
// Instead of storing pointers for each skillset just reshuffle the same set
// of pointers it's inexpensive and not called often
vector<HighScore*> TopSSRs;
vector<HighScore*> TopSSRsForGame;
vector<HighScore*> AllScores;
unordered_map<std::string, vector<HighScore*>> AllProfileScores;

Expand Down

0 comments on commit 8c2f738

Please sign in to comment.