Skip to content

Commit

Permalink
Experimental changes to replay data storage
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jun 30, 2018
1 parent def24bc commit 198c255
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
64 changes: 56 additions & 8 deletions src/HighScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RadarValues.h"
#include "RageLog.h"
#include "XmlFile.h"
#include "NoteTypes.h"
#include <algorithm>
#include <fstream>
#include <sstream>
Expand All @@ -17,7 +18,7 @@

ThemeMetric<string> EMPTY_NAME("HighScore","EmptyName");

const string REPLAY_DIR = "Save/Replays/";
const string REPLAY_DIR = "Save/ReplaysV2/";

struct HighScoreImpl
{
Expand All @@ -43,6 +44,9 @@ struct HighScoreImpl
vector<string> uploaded;
vector<float> vOffsetVector;
vector<int> vNoteRowVector;
vector<int> vTrackVector;
vector<TapNoteType> vTapNoteTypeVector;
vector<TapNoteSubType> vTapNoteSubTypeVector;
vector<int> vRescoreJudgeVector;
unsigned int iMaxCombo; // maximum combo obtained [SM5 alpha 1a+]
StageAward stageAward; // stage award [SM5 alpha 1a+]
Expand Down Expand Up @@ -599,12 +603,18 @@ bool HighScoreImpl::WriteReplayData() {

unsigned int idx = vNoteRowVector.size() - 1;
//loop for writing both vectors side by side
for (unsigned int i = 0; i < idx; i++) {
append = to_string(vNoteRowVector[i]) + " " + to_string(vOffsetVector[i]) + "\n";
for (unsigned int i = 0; i <= idx; i++) {
append = to_string(vNoteRowVector[i]) + " " + to_string(vOffsetVector[i])
+ " " + to_string(vTrackVector[i]) +
(vTapNoteTypeVector[i] != TapNoteType_Tap ?
" " + to_string(vTapNoteTypeVector[i])
+ (vTapNoteSubTypeVector[i] != TapNoteSubType_Invalid ?
" " + to_string(vTapNoteSubTypeVector[i])
: "")
: "")
+ "\n";
fileStream.write(append.c_str(), append.size());
}
append = to_string(vNoteRowVector[idx]) + " " + to_string(vOffsetVector[idx]);
fileStream.write(append.c_str(), append.size());
fileStream.close();
LOG->Trace("Created replay file at %s", path.c_str());
return true;
Expand All @@ -627,12 +637,10 @@ bool HighScore::WriteInputData(const vector<float>& oop) {

unsigned int idx = oop.size() - 1;
//loop for writing both vectors side by side
for (unsigned int i = 0; i < idx; i++) {
for (unsigned int i = 0; i <= idx; i++) {
append = to_string(oop[i]) + "\n";
fileStream.write(append.c_str(), append.size());
}
append = to_string(oop[idx]);
fileStream.write(append.c_str(), append.size());
fileStream.close();
LOG->Trace("Created replay file at %s", path.c_str());
return true;
Expand All @@ -647,6 +655,9 @@ bool HighScore::LoadReplayData() {
string profiledir;
vector<int> vNoteRowVector;
vector<float> vOffsetVector;
vector<int> vTrackVector;
vector<TapNoteType> vTapNoteTypeVector;
vector<TapNoteSubType> vTapNoteSubTypeVector;
string path = REPLAY_DIR + m_Impl->ScoreKey;

std::ifstream fileStream(path, ios::binary);
Expand All @@ -655,6 +666,10 @@ bool HighScore::LoadReplayData() {
vector<string> tokens;
int noteRow;
float offset;
int track;
TapNoteType tnt;
TapNoteSubType tnst;
int tmp;

//check file
if (!fileStream) {
Expand All @@ -681,11 +696,35 @@ bool HighScore::LoadReplayData() {
LOG->Warn("Failed to load replay data at %s (\"Offset value is not of type: float\")", path.c_str());
}
vOffsetVector.emplace_back(offset);

track = std::stoi(tokens[2]);
if (!(typeid(track) == typeid(int))) {
LOG->Warn("Failed to load replay data at %s (\"Track/Column value is not of type: int\")", path.c_str());
}
vTrackVector.emplace_back(track);

tmp = tokens.size() >= 4 ? ::stoi(tokens[3]) : TapNoteType_Tap;
if (tmp < 0 || tmp >= TapNoteType_Invalid || !(typeid(tmp) == typeid(int))) {
LOG->Warn("Failed to load replay data at %s (\"Tapnotetype value is not of type TapNoteType\")", path.c_str());
}
tnt = static_cast<TapNoteType>(tmp);
vTapNoteTypeVector.emplace_back(tnt);

tmp = tokens.size() >= 5 ? std::stoi(tokens[4]) : TapNoteSubType_Invalid;
if (tmp < 0 || tmp >= TapNoteSubType_Invalid || !(typeid(tmp) == typeid(int))) {
LOG->Warn("Failed to load replay data at %s (\"Tapnotesubtype value is not of type TapNoteSubType\")", path.c_str());
}
tnst = static_cast<TapNoteSubType>(tmp);
vTapNoteSubTypeVector.emplace_back(tnst);

tokens.clear();
}
fileStream.close();
SetNoteRowVector(vNoteRowVector);
SetOffsetVector(vOffsetVector);
SetTrackVector(vTrackVector);
SetTapNoteTypeVector(vTapNoteTypeVector);
SetTapNoteSubTypeVector(vTapNoteSubTypeVector);
LOG->Trace("Loaded replay data at %s", path.c_str());
return true;
}
Expand Down Expand Up @@ -743,8 +782,14 @@ bool HighScore::IsUploadedToServer(string s) const {
}
vector<float> HighScore::GetCopyOfOffsetVector() const { return m_Impl->vOffsetVector; }
vector<int> HighScore::GetCopyOfNoteRowVector() const { return m_Impl->vNoteRowVector; }
vector<int> HighScore::GetCopyOfTrackVector() const { return m_Impl->vTrackVector; }
vector<TapNoteType> HighScore::GetCopyOfTapNoteTypeVector() const { return m_Impl->vTapNoteTypeVector; }
vector<TapNoteSubType> HighScore::GetCopyOfTapNoteSubTypeVector() const { return m_Impl->vTapNoteSubTypeVector; }
const vector<float>& HighScore::GetOffsetVector() const { return m_Impl->vOffsetVector; }
const vector<int>& HighScore::GetNoteRowVector() const { return m_Impl->vNoteRowVector; }
const vector<int>& HighScore::GetTrackVector() const { return m_Impl->vTrackVector; }
const vector<TapNoteType>& HighScore::GetTapNoteTypeVector() const { return m_Impl->vTapNoteTypeVector; }
const vector<TapNoteSubType>& HighScore::GetTapNoteSubTypeVector() const { return m_Impl->vTapNoteSubTypeVector; }
string HighScore::GetScoreKey() const { return m_Impl->ScoreKey; }
float HighScore::GetSurviveSeconds() const { return m_Impl->fSurviveSeconds; }
float HighScore::GetSurvivalSeconds() const { return GetSurviveSeconds() + GetLifeRemainingSeconds(); }
Expand Down Expand Up @@ -784,6 +829,9 @@ void HighScore::AddUploadedServer(string s) {
}
void HighScore::SetOffsetVector(const vector<float>& v) { m_Impl->vOffsetVector = v; }
void HighScore::SetNoteRowVector(const vector<int>& v) { m_Impl->vNoteRowVector = v; }
void HighScore::SetTrackVector(const vector<int>& v) { m_Impl->vTrackVector = v; }
void HighScore::SetTapNoteTypeVector(const vector<TapNoteType>& v) { m_Impl->vTapNoteTypeVector = v; }
void HighScore::SetTapNoteSubTypeVector(const vector<TapNoteSubType>& v) { m_Impl->vTapNoteSubTypeVector = v; }
void HighScore::SetScoreKey(const string& 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; }
Expand Down
10 changes: 10 additions & 0 deletions src/HighScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DateTime.h"
#include "GameConstantsAndTypes.h"
#include "Grade.h"
#include "NoteTypes.h"
#include "RageUtil_AutoPtr.h"

class XNode;
Expand Down Expand Up @@ -53,8 +54,14 @@ struct HighScore
vector<float> timeStamps;
const vector<float>& GetOffsetVector() const;
const vector<int>& GetNoteRowVector() const;
const vector<int>& GetTrackVector() const;
const vector<TapNoteType>& GetTapNoteTypeVector() const;
const vector<TapNoteSubType>& GetTapNoteSubTypeVector() const;
vector<float> GetCopyOfOffsetVector() const;
vector<int> GetCopyOfNoteRowVector() const;
vector<int> GetCopyOfTrackVector() const;
vector<TapNoteType> GetCopyOfTapNoteTypeVector() const;
vector<TapNoteSubType> GetCopyOfTapNoteSubTypeVector() const;
string GetScoreKey() const;
int GetTopScore() const;
/**
Expand Down Expand Up @@ -102,6 +109,9 @@ struct HighScore
void AddUploadedServer(string s);
void SetOffsetVector(const vector<float>& v);
void SetNoteRowVector(const vector<int>& v);
void SetTrackVector(const vector<int>& v);
void SetTapNoteTypeVector(const vector<TapNoteType>& v);
void SetTapNoteSubTypeVector(const vector<TapNoteSubType>& v);
void SetScoreKey(const string& ck);
void SetRescoreJudgeVector(const vector<int>& v);
void SetAliveSeconds( float f );
Expand Down
10 changes: 8 additions & 2 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,14 @@ void Player::Step( int col, int row, const std::chrono::steady_clock::time_point
m_LastTapNoteScore = score;
if( GAMESTATE->CountNotesSeparately() )
{
if (pTN->result.tns != TNS_None)
{
m_pPlayerStageStats->m_vOffsetVector.emplace_back(pTN->result.fTapNoteOffset);
m_pPlayerStageStats->m_vTrackVector.emplace_back(col);
m_pPlayerStageStats->m_vNoteRowVector.emplace_back(iRowOfOverlappingNoteOrRow);
m_pPlayerStageStats->m_vTapNoteTypeVector.emplace_back(pTN->type);
m_pPlayerStageStats->m_vTapNoteSubTypeVector.emplace_back(pTN->subType);
}
if( pTN->type != TapNoteType_Mine )
{
const bool bBlind = (m_pPlayerState->m_PlayerOptions.GetCurrent().m_fBlind != 0);
Expand Down Expand Up @@ -2930,8 +2938,6 @@ void Player::SetJudgment( int iRow, int iTrack, const TapNote &tn, TapNoteScore
m_pPlayerStageStats->m_fWifeScore = curwifescore / totalwifescore;
m_pPlayerStageStats->CurWifeScore = curwifescore;
m_pPlayerStageStats->MaxWifeScore = maxwifescore;
m_pPlayerStageStats->m_vOffsetVector.emplace_back(tn.result.fTapNoteOffset);
m_pPlayerStageStats->m_vNoteRowVector.emplace_back(iRow);
}
else {
curwifescore -= 666.f; // hail satan
Expand Down
28 changes: 28 additions & 0 deletions src/PlayerStageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void PlayerStageStats::InternalInit()
m_fTimingScale = 0.f;
m_vOffsetVector.clear();
m_vNoteRowVector.clear();
m_vTrackVector.clear();
InputData.clear();
m_iPossibleGradePoints = 0;
m_iCurCombo = 0;
Expand Down Expand Up @@ -378,6 +379,15 @@ vector<float> PlayerStageStats::GetOffsetVector() const {
vector<int> PlayerStageStats::GetNoteRowVector() const {
return m_vNoteRowVector;
}
vector<int> PlayerStageStats::GetTrackVector() const {
return m_vTrackVector;
}
vector<TapNoteType> PlayerStageStats::GetTapNoteTypeVector() const {
return m_vTapNoteTypeVector;
}
vector<TapNoteSubType> PlayerStageStats::GetTapNoteSubTypeVector() const {
return m_vTapNoteSubTypeVector;
}

float PlayerStageStats::GetCurMaxPercentDancePoints() const
{
Expand Down Expand Up @@ -971,6 +981,21 @@ class LunaPlayerStageStats: public Luna<PlayerStageStats>
return 1;
}

static int GetTrackVector(T* p, lua_State *L) {
LuaHelpers::CreateTableFromArray(p->m_vTrackVector, L);
return 1;
}

static int GetTapNoteTypeVector(T* p, lua_State *L) {
LuaHelpers::CreateTableFromArray(p->m_vTapNoteTypeVector, L);
return 1;
}

static int GetTapNoteSubTypeVector(T* p, lua_State *L) {
LuaHelpers::CreateTableFromArray(p->m_vTapNoteSubTypeVector, L);
return 1;
}

static int WifeScoreOffset(T* p, lua_State *L) {
lua_pushnumber(L, wife2(FArg(1), p->GetTimingScale()));
return 1;
Expand Down Expand Up @@ -1091,6 +1116,9 @@ class LunaPlayerStageStats: public Luna<PlayerStageStats>
ADD_METHOD( GetCurrentScoreMultiplier );
ADD_METHOD( GetScore );
ADD_METHOD( GetOffsetVector );
ADD_METHOD(GetTrackVector);
ADD_METHOD(GetTapNoteSubTypeVector);
ADD_METHOD(GetTapNoteTypeVector);
ADD_METHOD( WifeScoreOffset );
ADD_METHOD( GetNoteRowVector );
ADD_METHOD( GetWifeScore );
Expand Down
7 changes: 7 additions & 0 deletions src/PlayerStageStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "NoteDataStructures.h"
#include "PlayerNumber.h"
#include "RadarValues.h"
#include "NoteTypes.h"
#include <map>

class Steps;
Expand Down Expand Up @@ -44,6 +45,9 @@ class PlayerStageStats
float GetTimingScale() const;
vector<float> GetOffsetVector() const;
vector<int> GetNoteRowVector() const;
vector<int> GetTrackVector() const;
vector<TapNoteType> GetTapNoteTypeVector() const;
vector<TapNoteSubType> GetTapNoteSubTypeVector() const;
float GetCurMaxPercentDancePoints() const;

int GetLessonScoreActual() const;
Expand Down Expand Up @@ -84,6 +88,9 @@ class PlayerStageStats
float m_fTimingScale;
vector<float> m_vOffsetVector;
vector<int> m_vNoteRowVector;
vector<TapNoteType> m_vTapNoteTypeVector;
vector<TapNoteSubType> m_vTapNoteSubTypeVector;
vector<int> m_vTrackVector;
vector<float> InputData;
int m_iTapNoteScores[NUM_TapNoteScore];
int m_iHoldNoteScores[NUM_HoldNoteScore];
Expand Down
3 changes: 3 additions & 0 deletions src/StageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ static HighScore FillInHighScore(const PlayerStageStats &pss, const PlayerState
if (pss.m_fWifeScore > 0.f) {
hs.SetOffsetVector(pss.GetOffsetVector());
hs.SetNoteRowVector(pss.GetNoteRowVector());
hs.SetTrackVector(pss.GetTrackVector());
hs.SetTapNoteTypeVector(pss.GetTapNoteTypeVector());
hs.SetTapNoteSubTypeVector(pss.GetTapNoteSubTypeVector());

if (pss.GetGrade() == Grade_Failed)
hs.SetSSRNormPercent(0.f);
Expand Down

0 comments on commit 198c255

Please sign in to comment.