Skip to content

Commit

Permalink
switch to returning pointers in playerscore setup
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 2, 2017
1 parent 30aecac commit aa5a8cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
20 changes: 10 additions & 10 deletions src/ChartScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ vector<string> ScoresAtRate::GetSortedKeys() {
return o;
}

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

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

return HighScore();
return NULL;
}

void ScoresForChart::AddScore(HighScore& hs) {
Expand Down Expand Up @@ -72,16 +72,16 @@ vector<HighScore*> ScoresForChart::GetAllPBPtrs() {
return o;
}

HighScore& PlayerScores::GetChartPBAt(string& ck, float& rate) {
HighScore* PlayerScores::GetChartPBAt(string& ck, float& rate) {
if (pscores.count(ck))
return pscores.at(ck).GetPBAt(rate);
return HighScore();
return NULL;
}

HighScore& PlayerScores::GetChartPBUpTo(string& ck, float& rate) {
HighScore* PlayerScores::GetChartPBUpTo(string& ck, float& rate) {
if (pscores.count(ck))
return pscores.at(ck).GetPBUpTo(rate);
return HighScore();
return NULL;
}


Expand Down
13 changes: 4 additions & 9 deletions src/ChartScores.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
struct ScoresAtRate
{
public:
string pbKey = "";
float pbScore = 0.f;

HighScore* PBptr;

HighScore** GetPBPtr() { return (&PBptr); }

// -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);

vector<string> GetSortedKeys();
Expand All @@ -36,8 +31,8 @@ struct ScoresForChart
public:
Grade bestGrade = Grade_Invalid; // best grade for any rate

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

vector<HighScore*> GetAllPBPtrs();

Expand Down Expand Up @@ -65,10 +60,10 @@ class PlayerScores
public:

// at what? rate. Duh. -mina
HighScore& GetChartPBAt(string& ck, float& rate);
HighScore* GetChartPBAt(string& ck, float& rate);

// technically "up to and including rate: x" but that's a mouthful -mina
HighScore& GetChartPBUpTo(string& ck, float& rate);
HighScore* GetChartPBUpTo(string& ck, float& rate);

// for scores achieved during this session
void AddScore(const HighScore& hs_) { HighScore hs = hs_; pscores[hs.GetHistoricChartKey()].AddScore(hs); }
Expand Down
8 changes: 4 additions & 4 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ void ScoreGoal::LoadFromNode(const XNode *pNode) {
pNode->GetChildValue("Comment", comment);
}

HighScore& ScoreGoal::GetPBUpTo() {
HighScore* ScoreGoal::GetPBUpTo() {
auto& scores = PROFILEMAN->GetProfile(PLAYER_1)->pscores;
return scores.GetChartPBUpTo(chartkey, rate);
}
Expand Down Expand Up @@ -3713,11 +3713,11 @@ class LunaScoreGoal : public Luna<ScoreGoal>
}

static int GetPBUpTo(T* p, lua_State *L) {
HighScore& pb = p->GetPBUpTo();
if (pb.IsEmpty())
HighScore* pb = p->GetPBUpTo();
if (!pb)
lua_pushnil(L);
else
pb.PushSelf(L);
pb->PushSelf(L);
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ScoreGoal
XNode* CreateNode() const;
void LoadFromNode(const XNode *pNode);

HighScore& GetPBUpTo();
HighScore* GetPBUpTo();

void PushSelf(lua_State *L);
};
Expand Down

0 comments on commit aa5a8cb

Please sign in to comment.