Skip to content

Commit

Permalink
pick writereplaydata savedir based on whether its called from load or…
Browse files Browse the repository at this point in the history
… playerstagestats

write out replaydata during fillinhighscore and purge it from the highscore object if successful
which it wont be because it doesn't work and i have no idea why
  • Loading branch information
MinaciousGrace committed May 1, 2017
1 parent e7602e0 commit 21b82d3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
57 changes: 35 additions & 22 deletions src/HighScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ struct HighScoreImpl
void LoadFromNode( const XNode *pNode );
void LoadFromEttNode(const XNode *pNode);
Grade GetWifeGrade() const;
void UnloadReplayData();

bool WriteReplayData();
bool WriteReplayData(bool duringload);

float RescoreToWifeTS(float ts);

Expand Down Expand Up @@ -101,6 +102,13 @@ bool HighScoreImpl::operator==( const HighScoreImpl& other ) const
return true;
}

void HighScoreImpl::UnloadReplayData() {
vector<int> tmpi;
vector<float> tmpf;
vNoteRowVector.swap(tmpi);
vOffsetVector.swap(tmpf);
}

Grade HighScoreImpl::GetWifeGrade() const {
if (grade == Grade_Failed)
return Grade_Failed;
Expand Down Expand Up @@ -387,15 +395,11 @@ void HighScoreImpl::LoadFromEttNode(const XNode *pNode)
//if (vOffsetVector.size() > 1 && fWifeScore == 0.f)
// fWifeScore = RescoreToWifeTS(fJudgeScale);
if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size()) && fWifeScore > 0.f) {
bool writesuccess = WriteReplayData();
bool writesuccess = WriteReplayData(true);

// ensure data is written out somewhere else before destroying it
if (writesuccess) {
vector<int> itmp;
vector<float> ftmp;
vNoteRowVector.swap(itmp);
vOffsetVector.swap(ftmp);
}
if (writesuccess)
UnloadReplayData();
}
// Validate input.
grade = clamp(grade, Grade_Tier01, Grade_Failed);
Expand Down Expand Up @@ -477,32 +481,34 @@ void HighScoreImpl::LoadFromNode(const XNode *pNode)
//if (vOffsetVector.size() > 1 && fWifeScore == 0.f)
// fWifeScore = RescoreToWifeTS(fJudgeScale);
if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size()) && fWifeScore > 0.f) {
bool writesuccess = WriteReplayData();
bool writesuccess = WriteReplayData(true);

// ensure data is written out somewhere else before destroying it
if (writesuccess) {
vector<int> itmp;
vector<float> ftmp;
vNoteRowVector.swap(itmp);
vOffsetVector.swap(ftmp);
}
if (writesuccess)
UnloadReplayData();
}
// Validate input.
grade = clamp( grade, Grade_Tier01, Grade_Failed );
}

bool HighScoreImpl::WriteReplayData() {
bool HighScoreImpl::WriteReplayData(bool duringload) {
RString append;
RString profiledir;

//open file
RString profiledir = PROFILEMAN->currentlyloadingprofile;
ofstream fileStream(profiledir + "ReplayData/" + ScoreKey, ios::binary);
if (duringload)
profiledir = PROFILEMAN->currentlyloadingprofile;
else
profiledir = PROFILEMAN->GetProfileDir(ProfileSlot_Player1);

RString path = profiledir + "ReplayData/" + ScoreKey;
ofstream fileStream(path, ios::binary);
//check file
if (!fileStream) {
LOG->Warn("Failed to create replay file");
LOG->Warn("Failed to create replay file at %s", path);
return false;
}


unsigned int idx = vNoteRowVector.size() - 1;
//loop for writing both vectors side by side
for (unsigned int i = 0; i < idx; i++) {
Expand All @@ -512,6 +518,8 @@ bool HighScoreImpl::WriteReplayData() {
append = to_string(vNoteRowVector[idx]) + " " + to_string(vOffsetVector[idx]);
fileStream.write(append.c_str(), append.size());
fileStream.close();

LOG->Warn("Created replay file at %s", path);
return true;
}

Expand Down Expand Up @@ -635,6 +643,7 @@ void HighScore::SetChordCohesion(bool b) { m_Impl->bNoChordCohesion = b; }
void HighScore::SetEtternaValid(bool b) { m_Impl->bEtternaValid = b; }
void HighScore::SetOffsetVector(const vector<float>& v) { m_Impl->vOffsetVector = v; }
void HighScore::SetNoteRowVector(const vector<int>& v) { m_Impl->vNoteRowVector = v; }
void HighScore::SetScoreKey(RString sk) { m_Impl->ScoreKey = sk; }
void HighScore::SetRescoreJudgeVector(const vector<int>& v) { m_Impl->vRescoreJudgeVector = v; }
void HighScore::SetAliveSeconds( float f ) { m_Impl->fSurviveSeconds = f; }
void HighScore::SetModifiers( const RString &s ) { m_Impl->sModifiers = s; }
Expand All @@ -649,6 +658,10 @@ void HighScore::SetRadarValues( const RadarValues &rv ) { m_Impl->radarValues =
void HighScore::SetLifeRemainingSeconds( float f ) { m_Impl->fLifeRemainingSeconds = f; }
void HighScore::SetDisqualified( bool b ) { m_Impl->bDisqualified = b; }

void HighScore::UnloadReplayData() {
m_Impl->UnloadReplayData();
}

/* We normally don't give direct access to the members. We need this one
* for NameToFillIn; use a special accessor so it's easy to find where this
* is used. */
Expand Down Expand Up @@ -988,8 +1001,8 @@ Grade HighScore::GetWifeGrade() {
return m_Impl->GetWifeGrade();
}

bool HighScore::WriteReplayData() {
return m_Impl->WriteReplayData();
bool HighScore::WriteReplayData(bool duringload) {
return m_Impl->WriteReplayData(duringload);
}

// Ok I guess we can be more lenient and convert by midwindow values, but we still have to assume j4 - mina
Expand Down
5 changes: 4 additions & 1 deletion src/HighScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct HighScore
void SetEtternaValid(bool b);
void SetOffsetVector(const vector<float>& v);
void SetNoteRowVector(const vector<int>& v);
void SetScoreKey(RString ck);
void SetRescoreJudgeVector(const vector<int>& v);
void SetAliveSeconds( float f );
void SetMaxCombo( unsigned int i );
Expand Down Expand Up @@ -121,7 +122,9 @@ struct HighScore
XNode* CreateEttNode() const;
void LoadFromNode( const XNode* pNode );
void LoadFromEttNode(const XNode* pNode);
bool WriteReplayData();

bool WriteReplayData(bool duringload);
void UnloadReplayData();

RString GetDisplayName() const;

Expand Down
27 changes: 22 additions & 5 deletions src/StageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "Style.h"
#include "Profile.h"
#include "ProfileManager.h"
#include <fstream>
#include <sstream>
#include "CryptManager.h"

/* Arcade: for the current stage (one song).
* Nonstop/Oni/Endless: for current course (which usually contains multiple songs)
Expand Down Expand Up @@ -132,13 +135,10 @@ float StageStats::GetTotalPossibleStepsSeconds() const
return fSecs / m_fMusicRate;
}

static HighScore FillInHighScore( const PlayerStageStats &pss, const PlayerState &ps, RString sRankingToFillInMarker, RString sPlayerGuid )
static HighScore FillInHighScore(const PlayerStageStats &pss, const PlayerState &ps, RString sRankingToFillInMarker, RString sPlayerGuid)
{
HighScore hs;
hs.SetName( sRankingToFillInMarker );

hs.SetOffsetVector(pss.GetOffsetVector());
hs.SetNoteRowVector(pss.GetNoteRowVector());
hs.SetName(sRankingToFillInMarker);

auto chartKey = GAMESTATE->m_pCurSteps[ps.m_PlayerNumber]->GetChartKey();
hs.SetHistoricChartKey(chartKey);
Expand Down Expand Up @@ -201,6 +201,23 @@ static HighScore FillInHighScore( const PlayerStageStats &pss, const PlayerState
hs.SetLifeRemainingSeconds( pss.m_fLifeRemainingSeconds );
hs.SetDisqualified( pss.IsDisqualified() );


// should maybe just make the setscorekey function do this internally rather than recalling the datetime object -mina
RString ScoreKey = "S" + BinaryToHex(CryptManager::GetSHA1ForString(hs.GetDateTime().GetString()));
hs.SetScoreKey(ScoreKey);

// DOES NOT WORK NEEDS FIX -mina
// the vectors stored in pss are what are accessed by evaluation so we can write
// them to the replay file instead of the highscore object (if successful) -mina
// this is kinda messy meh -mina
if (pss.m_fWifeScore > 0.f) {
hs.SetOffsetVector(pss.GetOffsetVector());
hs.SetNoteRowVector(pss.GetNoteRowVector());
bool writesuccess = hs.WriteReplayData(false);
if (writesuccess)
hs.UnloadReplayData();
}

return hs;
}

Expand Down

0 comments on commit 21b82d3

Please sign in to comment.