Skip to content

Commit

Permalink
use a continuous loading window rather than making new ones at points…
Browse files Browse the repository at this point in the history
… and reconcile chartkeys everywhere they're imported from the profile
  • Loading branch information
MinaciousGrace committed Jun 3, 2017
1 parent fd16570 commit 879cf79
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 34 deletions.
39 changes: 34 additions & 5 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void Profile::HandleStatsPrefixChange(RString dir, bool require_signature)
}
}

ProfileLoadResult Profile::LoadAllFromDir( const RString &sDir, bool bRequireSignature )
ProfileLoadResult Profile::LoadAllFromDir( const RString &sDir, bool bRequireSignature, LoadingWindow* ld)
{
FILEMAN->CreateDir(sDir + REPLAY_SUBDIR);
LOG->Trace( "Profile::LoadAllFromDir( %s )", sDir.c_str() );
Expand All @@ -827,7 +827,7 @@ ProfileLoadResult Profile::LoadAllFromDir( const RString &sDir, bool bRequireSig
ImportScoresToEtterna();
}

CalculateStatsFromScores();
CalculateStatsFromScores(ld);
return ProfileLoadResult_Success;
}

Expand Down Expand Up @@ -1046,6 +1046,34 @@ ProfileLoadResult Profile::LoadEttXmlFromNode(const XNode *xml) {
return ProfileLoadResult_Success;
}

void Profile::CalculateStatsFromScores(LoadingWindow* ld) {
LOG->Trace("Calculating stats from scores");
vector<HighScore*> all = SCOREMAN->GetAllScores();
float TotalGameplaySeconds = 0.f;
m_iTotalTapsAndHolds = 0;
m_iTotalHolds = 0;
m_iTotalMines = 0;

for (size_t i = 0; i < all.size(); ++i) {
HighScore* hs = all[i];
TotalGameplaySeconds += hs->GetSurvivalSeconds();
m_iTotalTapsAndHolds += hs->GetTapNoteScore(TNS_W1);
m_iTotalTapsAndHolds += hs->GetTapNoteScore(TNS_W2);
m_iTotalTapsAndHolds += hs->GetTapNoteScore(TNS_W3);
m_iTotalTapsAndHolds += hs->GetTapNoteScore(TNS_W4);
m_iTotalTapsAndHolds += hs->GetTapNoteScore(TNS_W5);
m_iTotalMines += hs->GetTapNoteScore(TNS_HitMine);
hs->GetHoldNoteScore(HNS_Held);
}

m_iNumTotalSongsPlayed = all.size();
m_iTotalDancePoints = m_iTotalTapsAndHolds * 2;
m_iTotalGameplaySeconds = static_cast<int>(TotalGameplaySeconds);

SCOREMAN->RecalculateSSRs(ld);
SCOREMAN->CalcPlayerRating(m_fPlayerRating, m_fPlayerSkillsets);
}

void Profile::CalculateStatsFromScores() {
LOG->Trace("Calculating stats from scores");
vector<HighScore*> all = SCOREMAN->GetAllScores();
Expand All @@ -1070,7 +1098,7 @@ void Profile::CalculateStatsFromScores() {
m_iTotalDancePoints = m_iTotalTapsAndHolds * 2;
m_iTotalGameplaySeconds = static_cast<int>(TotalGameplaySeconds);

SCOREMAN->RecalculateSSRs();
SCOREMAN->RecalculateSSRs(NULL);
SCOREMAN->CalcPlayerRating(m_fPlayerRating, m_fPlayerSkillsets);
}

Expand Down Expand Up @@ -1426,14 +1454,14 @@ XNode* Profile::SavePlaylistsCreateNode() const {

void Profile::LoadFavoritesFromNode(const XNode *pNode) {
FOREACH_CONST_Child(pNode, ck)
FavoritedCharts.emplace_back(ck->GetName());
FavoritedCharts.emplace_back(SONGMAN->ReconcileBustedKeys(ck->GetName()));

SONGMAN->SetFavoritedStatus(FavoritedCharts);
}

void Profile::LoadPermaMirrorFromNode(const XNode *pNode) {
FOREACH_CONST_Child(pNode, ck)
PermaMirrorCharts.emplace_back(ck->GetName());
PermaMirrorCharts.emplace_back(SONGMAN->ReconcileBustedKeys(ck->GetName()));

SONGMAN->SetPermaMirroredStatus(PermaMirrorCharts);
}
Expand All @@ -1450,6 +1478,7 @@ void Profile::LoadScoreGoalsFromNode(const XNode *pNode) {
RString ck;
FOREACH_CONST_Child(pNode, chgoals) {
chgoals->GetAttrValue("Key", ck);
ck = SONGMAN->ReconcileBustedKeys(ck);
goalmap[ck].LoadFromNode(chgoals);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "StepsUtil.h" // for StepsID
#include "StyleUtil.h" // for StyleID
#include "LuaReference.h"
#include "arch/LoadingWindow/LoadingWindow.h"

#include <unordered_map>

Expand Down Expand Up @@ -351,7 +352,7 @@ class Profile

// Loading and saving
void HandleStatsPrefixChange(RString dir, bool require_signature);
ProfileLoadResult LoadAllFromDir( const RString &sDir, bool bRequireSignature );
ProfileLoadResult LoadAllFromDir( const RString &sDir, bool bRequireSignature, LoadingWindow* ld);
ProfileLoadResult LoadStatsFromDir(RString dir, bool require_signature);
void LoadTypeFromDir(const RString &dir);
void LoadCustomFunction( const RString &sDir );
Expand Down Expand Up @@ -390,6 +391,7 @@ class Profile
XNode* SaveEttScoresCreateNode() const;
XNode* SaveEttXmlCreateNode() const;

void CalculateStatsFromScores(LoadingWindow* ld);
void CalculateStatsFromScores();

// For converting to etterna from stats.xml
Expand Down
13 changes: 6 additions & 7 deletions src/ProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "Character.h"
#include "CharacterManager.h"


ProfileManager* PROFILEMAN = NULL; // global and accessible from anywhere in our program

#define ID_DIGITS 8
Expand Down Expand Up @@ -84,7 +83,7 @@ ProfileManager::~ProfileManager()
LUA->UnsetGlobal( "PROFILEMAN" );
}

void ProfileManager::Init()
void ProfileManager::Init(LoadingWindow* ld)
{

FOREACH_PlayerNumber( p )
Expand All @@ -95,7 +94,7 @@ void ProfileManager::Init()
m_bNewProfile[p] = false;
}

RefreshLocalProfilesFromDisk();
RefreshLocalProfilesFromDisk(ld);

if( FIXED_PROFILES )
{
Expand Down Expand Up @@ -142,7 +141,7 @@ ProfileLoadResult ProfileManager::LoadProfile( PlayerNumber pn, const RString &s
m_bNeedToBackUpLastLoad[pn] = false;

// Try to load the original, non-backup data.
ProfileLoadResult lr = GetProfile(pn)->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
ProfileLoadResult lr = GetProfile(pn)->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData, NULL);

RString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_SUBDIR;

Expand All @@ -159,7 +158,7 @@ ProfileLoadResult ProfileManager::LoadProfile( PlayerNumber pn, const RString &s
//
if( lr == ProfileLoadResult_FailedTampered )
{
lr = GetProfile(pn)->LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData );
lr = GetProfile(pn)->LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData, NULL);
m_bLastLoadWasFromLastGood[pn] = lr == ProfileLoadResult_Success;

/* If the LastGood profile doesn't exist at all, and the actual profile was failed_tampered,
Expand Down Expand Up @@ -304,7 +303,7 @@ static void add_category_to_global_list(vector<DirAndProfile>& cat)
g_vLocalProfile.insert(g_vLocalProfile.end(), cat.begin(), cat.end());
}

void ProfileManager::RefreshLocalProfilesFromDisk()
void ProfileManager::RefreshLocalProfilesFromDisk(LoadingWindow* ld)
{
UnloadAllLocalProfiles();

Expand Down Expand Up @@ -358,7 +357,7 @@ void ProfileManager::RefreshLocalProfilesFromDisk()
FOREACH(DirAndProfile, g_vLocalProfile, curr)
{
currentlyloadingprofile = curr->sDir.substr(1);
curr->profile.LoadAllFromDir(curr->sDir, PREFSMAN->m_bSignProfileData);
curr->profile.LoadAllFromDir(curr->sDir, PREFSMAN->m_bSignProfileData, ld);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/ProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Preference.h"
#include "Grade.h"
#include "Profile.h"
#include "arch/LoadingWindow/LoadingWindow.h"

class Song;
class Steps;
Expand All @@ -19,13 +20,14 @@ class ProfileManager
ProfileManager();
~ProfileManager();

void Init();
void Init(LoadingWindow* ld);

bool FixedProfiles() const; // If true, profiles shouldn't be added/deleted

// local profiles
void UnloadAllLocalProfiles();
void RefreshLocalProfilesFromDisk();
void RefreshLocalProfilesFromDisk(LoadingWindow* ld);
const Profile *GetLocalProfile( const RString &sProfileID ) const;
Profile *GetLocalProfile( const RString &sProfileID ) { return (Profile*) ((const ProfileManager *) this)->GetLocalProfile(sProfileID); }
Profile *GetLocalProfileFromIndex( int iIndex );
Expand Down
19 changes: 9 additions & 10 deletions src/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,14 @@ HighScore* ScoreManager::GetChartPBUpTo(const string& ck, float& rate) {


static const float ld_update = 0.02f;
void ScoreManager::RecalculateSSRs() {
LoadingWindow *ld = LoadingWindow::Create();

void ScoreManager::RecalculateSSRs(LoadingWindow *ld) {
RageTimer ld_timer;
ld_timer.Touch();

ld->SetIndeterminate(false);
ld->SetTotalWork(AllScores.size());
ld->SetText("Updating SSR Calculations for Scores...");
if (ld) {
ld_timer.Touch();
ld->SetIndeterminate(false);
ld->SetTotalWork(AllScores.size());
ld->SetText("Updating SSR Calculations for Scores...");
}

int scoreindex = 0;
for(size_t i = 0; i < AllScores.size(); ++i) {
Expand Down Expand Up @@ -217,7 +216,6 @@ void ScoreManager::RecalculateSSRs() {
nd.UnsetSerializedNoteData();
steps->Compress();
}
ld->~LoadingWindow();
return;
}

Expand Down Expand Up @@ -421,7 +419,8 @@ void ScoreManager::LoadFromNode(const XNode * node) {
//ASSERT(p->GetName() == "Chart");
RString tmp;
p->GetAttrValue("Key", tmp);
const string ck = tmp;
string doot = SONGMAN->ReconcileBustedKeys(tmp);
const string ck = doot;
pscores[ck].LoadFromNode(p, ck);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ScoreManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ScoreManager

// Player Rating and SSR functions
void SortTopSSRPtrs(Skillset ss);
void RecalculateSSRs();
void RecalculateSSRs(LoadingWindow *ld);
void EnableAllScores();
void CalcPlayerRating(float& prating, float* pskillsets);
float AggregateSSRs(Skillset ss, float rating, float res, int iter) const;
Expand Down
16 changes: 9 additions & 7 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ void SongManager::InitAll( LoadingWindow *ld )
m_GroupsToNeverCache.insert(*group);
}
InitSongsFromDisk( ld );
SAFE_DELETE(ld); // Destroy this before the scoremanager loading window is created
}

static LocalizedString RELOADING ( "SongManager", "Reloading..." );
Expand Down Expand Up @@ -280,6 +279,7 @@ void Chart::LoadFromNode(const XNode* node) {
node->GetAttrValue("Key", s); key = s;

// check if this chart is loaded and overwrite any last-seen values with updated ones
key = SONGMAN->ReconcileBustedKeys(key);
FromKey(key);
}

Expand Down Expand Up @@ -357,15 +357,17 @@ vector<string> Playlist::GetKeys() {
return o;
}

void SongManager::ReconcileBustedKeys(string& ck) {
string SongManager::ReconcileBustedKeys(const string& ck) {
if (StepsByKey.count(ck))
return;
return ck;

FOREACHUM(string, Steps*, StepsByKey, i) {
FOREACHUM(string, Steps*, StepsByKey, i)
for (auto& n : i->second->bustedkeys)
if (ck == n)
ck = n;
}
if (ck == n) {
LOG->Trace("Reconciled key for %s to %s", ck.c_str(), i->second->GetChartKey().c_str());
return i->second->GetChartKey();
}
return ck;
}

// Only store 1 steps/song pointer per key -Mina
Expand Down
2 changes: 1 addition & 1 deletion src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class SongManager
map<string, Playlist> allplaylists;
string activeplaylist;
string playlistcourse;
void ReconcileBustedKeys(string& ck);
string ReconcileBustedKeys(const string& ck);

map<string, vector<Song*>> groupderps;
protected:
Expand Down
4 changes: 3 additions & 1 deletion src/StepMania.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,8 @@ int sm_main(int argc, char* argv[])
CHARMAN = new CharacterManager;
SCOREMAN = new ScoreManager;
PROFILEMAN = new ProfileManager;
PROFILEMAN->Init(); // must load after SONGMAN
PROFILEMAN->Init(pLoadingWindow); // must load after SONGMAN

SONGMAN->UpdatePopular();
SONGMAN->UpdatePreferredSort();
NSMAN = new NetworkSyncManager( NULL );
Expand All @@ -1179,6 +1180,7 @@ int sm_main(int argc, char* argv[])
return 0;
}

SAFE_DELETE(pLoadingWindow);
StartDisplay();

StoreActualGraphicOptions();
Expand Down

0 comments on commit 879cf79

Please sign in to comment.