Skip to content

Commit

Permalink
making naming a little more descriptive and add miscellaneous things
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 2, 2017
1 parent 08568eb commit 4402e2e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
40 changes: 22 additions & 18 deletions src/ChartScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
#include "ChartScores.h"


void ScoreMap::AddScore(HighScore& hs) {
void ScoresAtRate::AddScore(HighScore& hs) {
string& key = hs.GetScoreKey();
if (float newpb = hs.GetWifeScore() > pbScore) {
pbScore = newpb;
pbKey = key;
}

bestGrade = min(hs.GetWifeGrade(), bestGrade);
scores.emplace(key, hs);
}

vector<string> ScoreMap::GetSortedKeys() {
vector<string> ScoresAtRate::GetSortedKeys() {
map<float, string, greater<float>> tmp;
vector<string> o;
FOREACHM(string, HighScore, scores, i)
Expand All @@ -25,38 +27,40 @@ vector<string> ScoreMap::GetSortedKeys() {
return o;
}

HighScore& ChartScores::GetPBAt(float& rate) {
HighScore& ScoresForChart::GetPBAt(float& rate) {
int key = RateToKey(rate);
if(ScoresByRate.count(key))
return ScoresByRate.at(key).GetPB();
return HighScore();
}

HighScore& ChartScores::GetPBUpTo(float& rate) {
HighScore& ScoresForChart::GetPBUpTo(float& rate) {
int key = RateToKey(rate);
FOREACHM(int, ScoreMap, ScoresByRate, i)
FOREACHM(int, ScoresAtRate, ScoresByRate, i)
if (i->first <= key)
return i->second.GetPB();

return HighScore();
}

void ChartScores::AddScore(HighScore& hs) {
void ScoresForChart::AddScore(HighScore& hs) {
bestGrade = min(hs.GetWifeGrade(), bestGrade);

float rate = hs.GetMusicRate();
int key = RateToKey(rate);
ScoresByRate[key].AddScore(hs);
}

vector<float> ChartScores::GetPlayedRates() {
vector<float> ScoresForChart::GetPlayedRates() {
vector<float> o;
FOREACHM(int, ScoreMap, ScoresByRate, i)
FOREACHM(int, ScoresAtRate, ScoresByRate, i)
o.emplace_back(KeyToRate(i->first));
return o;
}

vector<int> ChartScores::GetPlayedRateKeys() {
vector<int> ScoresForChart::GetPlayedRateKeys() {
vector<int> o;
FOREACHM(int, ScoreMap, ScoresByRate, i)
FOREACHM(int, ScoresAtRate, ScoresByRate, i)
o.emplace_back(i->first);
return o;
}
Expand All @@ -77,7 +81,7 @@ HighScore& PlayerScores::GetChartPBUpTo(string& ck, float& rate) {

#include "LuaBinding.h"

class LunaScoreMap: public Luna<ScoreMap>
class LunaScoresAtRate: public Luna<ScoresAtRate>
{
public:
static int GetScores(T* p, lua_State *L) {
Expand All @@ -92,18 +96,18 @@ class LunaScoreMap: public Luna<ScoreMap>
return 1;
}

LunaScoreMap()
LunaScoresAtRate()
{
ADD_METHOD(GetScores);
}
};

LUA_REGISTER_CLASS(ScoreMap)
LUA_REGISTER_CLASS(ScoresAtRate)

class LunaChartScores : public Luna<ChartScores>
class LunaScoresForChart : public Luna<ScoresForChart>
{
public:
static int GetScoreMaps(T* p, lua_State *L) {
static int GetScoresAtRates(T* p, lua_State *L) {
lua_newtable(L);
vector<float> rates = p->GetPlayedRates();
for (size_t i = 0; i < rates.size(); ++i) {
Expand All @@ -115,10 +119,10 @@ class LunaChartScores : public Luna<ChartScores>
}


LunaChartScores()
LunaScoresForChart()
{
ADD_METHOD(GetScoreMaps);
ADD_METHOD(GetScoresAtRates);
}
};

LUA_REGISTER_CLASS(ChartScores)
LUA_REGISTER_CLASS(ScoresForChart)
29 changes: 24 additions & 5 deletions src/ChartScores.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#include <map>


struct ScoreMap

// Scores for a specific rate for a specific chart
struct ScoresAtRate
{
public:
string pbKey = "";
float pbScore = 0.f;

// -technically- your pb could be a fail grade so use "bestgrade" -mina
Grade bestGrade = Grade_Invalid;

HighScore& GetPB() { return scores.at(pbKey); }
void AddScore(HighScore& hs);

Expand All @@ -19,13 +25,18 @@ struct ScoreMap

};

struct ChartScores

// All scores for a specific chart
struct ScoresForChart
{
public:
Grade bestGrade = Grade_Invalid; // best grade for any rate

HighScore& GetPBAt(float& rate);
HighScore & GetPBUpTo(float& rate);

void AddScore(HighScore& hs);

vector<float> GetPlayedRates();
vector<int> GetPlayedRateKeys();
int RateToKey(float& rate) { return lround(rate * 10000.f); }
Expand All @@ -36,7 +47,7 @@ struct ChartScores
/* 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
in the reverse -mina */
map<int, ScoreMap, greater<int>> ScoresByRate;
map<int, ScoresAtRate, greater<int>> ScoresByRate;
private:


Expand All @@ -56,9 +67,17 @@ class PlayerScores

// the loading process should actually really be done by constructing scores in place -mina
// and any internal sorting should occur after all scores ares loaded
void AddScore(string& ck, ChartScores& cs) { pscores.emplace(ck, cs); }
void AddScore(string& ck, ScoresForChart& cs) { pscores.emplace(ck, cs); }



// Top SSRs





map<string, ChartScores> pscores;
map<string, ScoresForChart> pscores;
map<string, HighScore&> AllScores;
private:

Expand Down
2 changes: 1 addition & 1 deletion src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ void Profile::LoadEttScoresFromNode(const XNode* pSongScores) {

const XNode *pRateScores = pChart->GetChild("RateScores");
HighScoreRateMap hsrm;
ChartScores wot;
ScoresForChart wot;

FOREACH_CONST_Child(pRateScores, pRate) {
float rate = StringToFloat(pRate->GetName());
Expand Down
2 changes: 1 addition & 1 deletion src/StageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void StageStats::FinalizeScores( bool bSummary )
// new score structure -mina
PROFILEMAN->AddScoreByKey(p, hs);
Profile* zzz = PROFILEMAN->GetProfile(PLAYER_1);
zzz->pscores.AddScore(GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey(), hs);
zzz->pscores.AddScore(hs);
zzz->SetAnyAchievedGoals(GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey(), GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate, hs);
}
}
Expand Down

0 comments on commit 4402e2e

Please sign in to comment.