@@ -41,7 +41,7 @@ ScoresAtRate::ScoresAtRate() {
41
41
noccPBptr = nullptr ;
42
42
}
43
43
44
- void ScoresAtRate::AddScore (HighScore& hs) {
44
+ HighScore* ScoresAtRate::AddScore (HighScore& hs) {
45
45
const string& key = hs.GetScoreKey ();
46
46
bestGrade = min (hs.GetWifeGrade (), bestGrade);
47
47
scores.emplace (key, hs);
@@ -56,6 +56,7 @@ void ScoresAtRate::AddScore(HighScore& hs) {
56
56
57
57
SCOREMAN->RegisterScore (&scores.find (key)->second );
58
58
SCOREMAN->AddToKeyedIndex (&scores.find (key)->second );
59
+ return &(scores.find (key)->second );
59
60
}
60
61
61
62
vector<string> ScoresAtRate::GetSortedKeys () {
@@ -92,34 +93,55 @@ void ScoreManager::PurgeScores() {
92
93
pscores.clear ();
93
94
}
94
95
95
- void ScoreManager::RatingOverTime () {
96
+ void ScoreManager::PurgeProfileScores (const string& profileID) {
97
+ TopSSRs.clear ();
98
+ TopSSRs.shrink_to_fit ();
99
+ for (auto & score : AllProfileScores[profileID]) {
100
+ {
101
+ auto & it = find (AllScores.begin (), AllScores.end (), score);
102
+ if (it != AllScores.end ())
103
+ AllScores.erase (it);
104
+ }
105
+ auto & it = ScoresByKey.find (score->GetChartKey ());
106
+ if (it != ScoresByKey.end ())
107
+ ScoresByKey.erase (it);
108
+ }
109
+ AllScores.shrink_to_fit ();
110
+ AllProfileScores[profileID].clear ();
111
+ AllProfileScores[profileID].shrink_to_fit ();
112
+
113
+ pscores[profileID].clear ();
114
+ }
115
+
116
+ void ScoreManager::RatingOverTime (const string& profileID) {
96
117
auto compdate = [](HighScore* a, HighScore* b) { return (a->GetDateTime () < b->GetDateTime ()); };
97
118
119
+ auto & scores = AllProfileScores[profileID];
98
120
99
121
vector<bool > wasvalid;
100
- sort (AllScores .begin (), AllScores .end (), compdate);
122
+ sort (scores .begin (), scores .end (), compdate);
101
123
102
- for (auto & n : AllScores ) {
124
+ for (auto & n : scores ) {
103
125
wasvalid.push_back (n->GetEtternaValid ());
104
126
n->SetEtternaValid (false );
105
127
}
106
128
107
129
float doot = 10 .f ;
108
130
float doot2[8 ];
109
131
LOG->Warn (" wer" );
110
- if (AllScores .empty ())
132
+ if (scores .empty ())
111
133
return ;
112
134
113
- DateTime lastvalidday = AllScores .front ()->GetDateTime ();
135
+ DateTime lastvalidday = AllProfileScores[profileID] .front ()->GetDateTime ();
114
136
lastvalidday.StripTime ();
115
137
116
- CalcPlayerRating (doot, doot2);
138
+ CalcPlayerRating (doot, doot2, profileID );
117
139
LOG->Warn (lastvalidday.GetString ());
118
140
119
- DateTime finalvalidday = AllScores .back ()->GetDateTime ();
141
+ DateTime finalvalidday = scores .back ()->GetDateTime ();
120
142
finalvalidday.StripTime ();
121
143
while (lastvalidday != finalvalidday) {
122
- for (auto & n : AllScores ) {
144
+ for (auto & n : scores ) {
123
145
DateTime date = n->GetDateTime ();
124
146
date.StripTime ();
125
147
@@ -130,7 +152,7 @@ void ScoreManager::RatingOverTime() {
130
152
131
153
n->SetEtternaValid (true );
132
154
}
133
- CalcPlayerRating (doot, doot2);
155
+ CalcPlayerRating (doot, doot2, profileID );
134
156
LOG->Trace (" %f" , doot);
135
157
}
136
158
}
@@ -156,15 +178,16 @@ HighScore* ScoresForChart::GetPBUpTo(float& rate) {
156
178
return NULL ;
157
179
}
158
180
159
- void ScoresForChart::AddScore (HighScore& hs) {
181
+ HighScore* ScoresForChart::AddScore (HighScore& hs) {
160
182
bestGrade = min (hs.GetWifeGrade (), bestGrade);
161
183
162
184
float rate = hs.GetMusicRate ();
163
185
int key = RateToKey (rate);
164
- ScoresByRate[key].AddScore (hs);
186
+ auto hsPtr = ScoresByRate[key].AddScore (hs);
165
187
// ok let's try this --lurker
166
188
SetTopScores ();
167
- hs.SetTopScore (ScoresByRate[key].scores [hs.GetScoreKey ()].GetTopScore ());
189
+ hs.SetTopScore (hsPtr->GetTopScore ());
190
+ return hsPtr;
168
191
}
169
192
170
193
vector<float > ScoresForChart::GetPlayedRates () {
@@ -235,30 +258,32 @@ vector<HighScore*> ScoresForChart::GetAllPBPtrs() {
235
258
return o;
236
259
}
237
260
238
- vector<vector<HighScore*>> ScoreManager::GetAllPBPtrs () {
261
+ vector<vector<HighScore*>> ScoreManager::GetAllPBPtrs (const string& profileID ) {
239
262
vector<vector<HighScore*>> vec;
240
- FOREACHUM (string, ScoresForChart, pscores, i) {
263
+ FOREACHUM (string, ScoresForChart, pscores[profileID] , i) {
241
264
if (!SONGMAN->IsChartLoaded (i->first ))
242
265
continue ;
243
266
vec.emplace_back (i->second .GetAllPBPtrs ());
244
267
}
245
268
return vec;
246
269
}
247
270
248
- HighScore* ScoreManager::GetChartPBAt (const string& ck, float & rate) {
271
+
272
+ HighScore* ScoreManager::GetChartPBAt (const string& ck, float & rate, const string& profileID) {
249
273
if (pscores.count (ck))
250
- return pscores.at (ck).GetPBAt (rate);
274
+ return pscores[profileID] .at (ck).GetPBAt (rate);
251
275
return NULL ;
252
276
}
253
277
254
- HighScore* ScoreManager::GetChartPBUpTo (const string& ck, float & rate) {
278
+ HighScore* ScoreManager::GetChartPBUpTo (const string& ck, float & rate, const string& profileID ) {
255
279
if (pscores.count (ck))
256
- return pscores.at (ck).GetPBUpTo (rate);
280
+ return pscores[profileID] .at (ck).GetPBUpTo (rate);
257
281
return NULL ;
258
282
}
259
283
260
- void ScoreManager::SetAllTopScores () {
261
- FOREACHUM (string, ScoresForChart, pscores, i) {
284
+
285
+ void ScoreManager::SetAllTopScores (const string& profileID) {
286
+ FOREACHUM (string, ScoresForChart, pscores[profileID], i) {
262
287
if (!SONGMAN->IsChartLoaded (i->first ))
263
288
continue ;
264
289
i->second .SetTopScores ();
@@ -285,24 +310,25 @@ bool ScoresAtRate::HandleNoCCPB(HighScore& hs) {
285
310
return false ;
286
311
}
287
312
static const float ld_update = 0 .02f ;
288
- void ScoreManager::RecalculateSSRs (LoadingWindow *ld) {
313
+ void ScoreManager::RecalculateSSRs (LoadingWindow *ld, const string& profileID ) {
289
314
RageTimer ld_timer;
315
+ auto & scores = AllProfileScores[profileID];
290
316
if (ld) {
291
317
ld_timer.Touch ();
292
318
ld->SetIndeterminate (false );
293
- ld->SetTotalWork (AllScores .size ());
319
+ ld->SetTotalWork (scores .size ());
294
320
ld->SetText (" Updating SSR Calculations for Scores..." );
295
321
}
296
322
297
323
int scoreindex = 0 ;
298
- for (size_t i = 0 ; i < AllScores .size (); ++i) {
324
+ for (size_t i = 0 ; i < scores .size (); ++i) {
299
325
if (ld && ld_timer.Ago () > ld_update) {
300
326
ld_timer.Touch ();
301
327
ld->SetProgress (scoreindex);
302
328
}
303
329
++scoreindex;
304
330
305
- HighScore* hs = AllScores [i];
331
+ HighScore* hs = scores [i];
306
332
if (hs->GetSSRCalcVersion () == GetCalcVersion ())
307
333
continue ;
308
334
@@ -371,16 +397,16 @@ void ScoreManager::EnableAllScores() {
371
397
return ;
372
398
}
373
399
374
- void ScoreManager::CalcPlayerRating (float & prating, float * pskillsets) {
375
- SetAllTopScores ();
400
+ void ScoreManager::CalcPlayerRating (float & prating, float * pskillsets, const string& profileID ) {
401
+ SetAllTopScores (profileID );
376
402
377
403
vector<float > skillz;
378
404
FOREACH_ENUM (Skillset, ss) {
379
405
// actually skip overall, and jack stamina for now
380
406
if (ss == Skill_Overall)
381
407
continue ;
382
408
383
- SortTopSSRPtrs (ss);
409
+ SortTopSSRPtrs (ss, profileID );
384
410
pskillsets[ss] = AggregateSSRs (ss, 0 .f , 10 .24f , 1 ) * 1 .04f ;
385
411
CLAMP (pskillsets[ss], 0 .f , 100 .f );
386
412
skillz.push_back (pskillsets[ss]);
@@ -411,9 +437,9 @@ float ScoreManager::AggregateSSRs(Skillset ss, float rating, float res, int iter
411
437
return AggregateSSRs (ss, rating - res, res / 2 .f , iter + 1 );
412
438
}
413
439
414
- void ScoreManager::SortTopSSRPtrs (Skillset ss) {
440
+ void ScoreManager::SortTopSSRPtrs (Skillset ss, const string& profileID ) {
415
441
TopSSRs.clear ();
416
- FOREACHUM (string, ScoresForChart, pscores, i) {
442
+ FOREACHUM (string, ScoresForChart, pscores[profileID] , i) {
417
443
if (!SONGMAN->IsChartLoaded (i->first ))
418
444
continue ;
419
445
vector<HighScore*> pbs = i->second .GetAllPBPtrs ();
@@ -436,18 +462,20 @@ HighScore* ScoreManager::GetTopSSRHighScore(unsigned int rank, int ss) {
436
462
return NULL ;
437
463
}
438
464
439
- void ScoreManager::ImportScore (const HighScore& hs_) {
465
+ void ScoreManager::ImportScore (const HighScore& hs_, const string& profileID ) {
440
466
HighScore hs = hs_;
441
467
442
468
// don't import duplicated scores
443
469
// this may have strange ramifications - mina
444
470
// actually i'll just disable this for the time being and give myself time to test it later
445
471
// if(!ScoresByKey.count(hs.GetScoreKey()))
446
472
447
- pscores[hs.GetChartKey ()].AddScore (hs);
473
+ RegisterScoreInProfile ( pscores[profileID][ hs.GetChartKey ()].AddScore (hs), profileID );
448
474
}
449
475
450
-
476
+ void ScoreManager::RegisterScoreInProfile (HighScore* hs_, const string& profileID) {
477
+ AllProfileScores[profileID].emplace_back (hs_);
478
+ }
451
479
452
480
453
481
@@ -497,9 +525,9 @@ XNode * ScoresForChart::CreateNode(const string& ck) const {
497
525
return o;
498
526
}
499
527
500
- XNode * ScoreManager::CreateNode () const {
528
+ XNode * ScoreManager::CreateNode (const string& profileID ) const {
501
529
XNode* o = new XNode (" PlayerScores" );
502
- FOREACHUM_CONST (string, ScoresForChart, pscores, ch) {
530
+ FOREACHUM_CONST (string, ScoresForChart, pscores. find (profileID)-> second , ch) {
503
531
auto node = ch->second .CreateNode (ch->first );
504
532
if (!node->ChildrenEmpty ())
505
533
o->AppendChild (node);
@@ -510,7 +538,7 @@ XNode * ScoreManager::CreateNode() const {
510
538
511
539
512
540
// Read scores from xml
513
- void ScoresAtRate::LoadFromNode (const XNode* node, const string& ck, const float & rate) {
541
+ void ScoresAtRate::LoadFromNode (const XNode* node, const string& ck, const float & rate, const string& profileID ) {
514
542
RString sk;
515
543
FOREACH_CONST_Child (node, p) {
516
544
p->GetAttrValue (" Key" , sk);
@@ -537,10 +565,11 @@ void ScoresAtRate::LoadFromNode(const XNode* node, const string& ck, const float
537
565
// Very awkward, need to figure this out better so there isn't unnecessary redundancy between loading and adding
538
566
SCOREMAN->RegisterScore (&scores.find (sk)->second );
539
567
SCOREMAN->AddToKeyedIndex (&scores.find (sk)->second );
568
+ SCOREMAN->RegisterScoreInProfile (&scores.find (sk)->second , profileID);
540
569
}
541
570
}
542
571
543
- void ScoresForChart::LoadFromNode (const XNode* node, const string& ck) {
572
+ void ScoresForChart::LoadFromNode (const XNode* node, const string& ck, const string& profileID ) {
544
573
RString rs = " " ;
545
574
int rate;
546
575
@@ -558,19 +587,19 @@ void ScoresForChart::LoadFromNode(const XNode* node, const string& ck) {
558
587
ASSERT (p->GetName () == " ScoresAt" );
559
588
p->GetAttrValue (" Rate" , rs);
560
589
rate = 10 * StringToInt (rs.substr (0 , 1 ) + rs.substr (2 , 4 ));
561
- ScoresByRate[rate].LoadFromNode (p, ck, KeyToRate (rate));
590
+ ScoresByRate[rate].LoadFromNode (p, ck, KeyToRate (rate), profileID );
562
591
bestGrade = min (ScoresByRate[rate].bestGrade , bestGrade);
563
592
}
564
593
}
565
594
566
- void ScoreManager::LoadFromNode (const XNode * node) {
595
+ void ScoreManager::LoadFromNode (const XNode * node, const string& profileID ) {
567
596
FOREACH_CONST_Child (node, p) {
568
597
// ASSERT(p->GetName() == "Chart");
569
598
RString tmp;
570
599
p->GetAttrValue (" Key" , tmp);
571
600
string doot = SONGMAN->ReconcileBustedKeys (tmp);
572
601
const string ck = doot;
573
- pscores[ck].LoadFromNode (p, ck);
602
+ pscores[profileID][ ck].LoadFromNode (p, ck, profileID );
574
603
}
575
604
}
576
605
@@ -583,9 +612,9 @@ ScoresAtRate* ScoresForChart::GetScoresAtRate(const int& rate) {
583
612
return NULL ;
584
613
}
585
614
586
- ScoresForChart* ScoreManager::GetScoresForChart (const string& ck) {
587
- auto it = pscores.find (ck);
588
- if (it != pscores.end ())
615
+ ScoresForChart* ScoreManager::GetScoresForChart (const string& ck, const string& profileID ) {
616
+ auto it = ( pscores[profileID]) .find (ck);
617
+ if (it != ( pscores[profileID]) .end ())
589
618
return &it->second ;
590
619
return NULL ;
591
620
}
0 commit comments