Skip to content

Commit

Permalink
First working/compiling draft of cache db
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Feb 10, 2018
1 parent fa80c28 commit b2c1a65
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 440 deletions.
4 changes: 2 additions & 2 deletions src/NotesLoaderSSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void SetChartKey(SSC::StepsTagInfo& info) {
info.steps->SetChartKey((*info.params)[1]);
}

vector<float> msdsplit(const RString& s) {
vector<float> SSC::msdsplit(const RString& s) {
vector<float> o;
for (size_t i = 0; i < s.size(); ++i) {
o.emplace_back(StringToFloat(s.substr(i, 5)));
Expand All @@ -477,7 +477,7 @@ void SetMSDValues(SSC::StepsTagInfo& info) {
auto size = params.params.size();
// Start from index 1
for (size_t i = 1; i <= size; i++)
o.emplace_back(msdsplit(params[i]));
o.emplace_back(SSC::msdsplit(params[i]));
info.steps->SetAllMSD(o);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NotesLoaderSSC.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MsdFile;
class Song;
class Steps;
class TimingData;

class SSCLoader;
/**
* @brief The various states while parsing a .ssc file.
*/
Expand Down
19 changes: 12 additions & 7 deletions src/NotesWriterSSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ static RString JoinLineList( vector<RString> &lines )
return join( "\r\n", lines.begin()+j, lines.end() );
}

RString MSDToString(MinaSD x) {
RString NotesWriterSSC::MSDToString(MinaSD x) {
RString o = "";
for (size_t i = 0; i < x.size(); i++) {
for (size_t ii = 0; ii < x[i].size(); ii++) {
o.append(to_string(x[i][ii]).substr(0,5));
if (ii != x[i].size() - 1)
o.append(",");
}
o.append(NotesWriterSSC::SkillsetDiffsToString(x[i]));
if (i != x.size() - 1)
o.append(":");
}
return o;
}

RString NotesWriterSSC::SkillsetDiffsToString(SDiffs x) {
RString o = "";
for (size_t ii = 0; ii < x.size(); ii++) {
o.append(to_string(x[ii]).substr(0, 5));
if (ii != x.size() - 1)
o.append(",");
}
return o;
}
// A utility class to write timing tags more easily!
struct TimingTagWriter {

Expand Down Expand Up @@ -361,7 +366,7 @@ static RString GetSSCNoteData( const Song &song, const Steps &in, bool bSavingCa
emplace_back_tag(lines, "#CHARTSTYLE:%s;", in.GetChartStyle());
emplace_back_tag(lines, "#DIFFICULTY:%s;", DifficultyToString(in.GetDifficulty()));
lines.emplace_back(ssprintf("#METER:%d;", in.GetMeter()));
lines.emplace_back(ssprintf("#MSDVALUES:%s;", MSDToString(in.GetAllMSD()).c_str()));
lines.emplace_back(ssprintf("#MSDVALUES:%s;", NotesWriterSSC::MSDToString(in.GetAllMSD()).c_str()));
lines.emplace_back(ssprintf("#CHARTKEY:%s;", SmEscape(in.GetChartKey()).c_str()));

emplace_back_tag(lines, "#MUSIC:%s;", in.GetMusicFile());
Expand Down
3 changes: 3 additions & 0 deletions src/NotesWriterSSC.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef NOTES_WRITER_SSC_H
#define NOTES_WRITER_SSC_H

#include "Steps.h"

class Song;
class Steps;
/** @brief Writes a Song to an .SSC file. */
Expand Down Expand Up @@ -35,6 +37,7 @@ namespace NotesWriterSSC
* @return its success or failure. */
bool WriteEditFileToMachine( const Song *pSong, Steps *pSteps, RString &sErrorOut );
RString MSDToString(MinaSD x);
RString SkillsetDiffsToString(SDiffs x);
}

#endif
Expand Down
24 changes: 4 additions & 20 deletions src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ bool Song::SaveToSMFile()
return NotesWriterSM::Write( sPath, *this, vpStepsToSave );

}
vector<Steps*> Song::GetStepsToSave(bool bSavingCache=true, string path="")
vector<Steps*> Song::GetStepsToSave(bool bSavingCache, string path)
{

vector<Steps*> vpStepsToSave;
Expand Down Expand Up @@ -1172,7 +1172,7 @@ bool Song::SaveToSSCFile( const RString &sPath, bool bSavingCache, bool autosave

if(bSavingCache || autosave)
{
return NotesWriterSSC::Write(path, *this, vpStepsToSave, bSavingCache);
return SONGINDEX->CacheSong(*this, path);
}

if( !NotesWriterSSC::Write(path, *this, vpStepsToSave, bSavingCache) )
Expand Down Expand Up @@ -1225,23 +1225,7 @@ bool Song::SaveToETTFile(const RString &sPath, bool bSavingCache, bool autosave)
if (!bSavingCache && !autosave && IsAFile(path))
FileCopy(path, path + ".old");

vector<Steps*> vpStepsToSave;
FOREACH_CONST(Steps*, m_vpSteps, s)
{
Steps *pSteps = *s;

// Only save steps that weren't loaded from a profile.
if (pSteps->WasLoadedFromProfile())
continue;

if (!bSavingCache)
pSteps->SetFilename(path);
vpStepsToSave.push_back(pSteps);
}
FOREACH_CONST(Steps*, m_UnknownStyleSteps, s)
{
vpStepsToSave.push_back(*s);
}
vector<Steps*> vpStepsToSave = GetStepsToSave(bSavingCache, sPath);

if (bSavingCache || autosave)
{
Expand Down Expand Up @@ -1293,7 +1277,7 @@ bool Song::SaveToCacheFile()
{
return true;
}
return SONGINDEX->SaveSong(*this, m_sSongDir);
return SONGINDEX->CacheSong(*this, m_sSongDir);
SONGINDEX->AddCacheIndex(m_sSongDir, GetHashForDirectory(m_sSongDir));
const RString sPath = GetCacheFilePath();
return SaveToSSCFile(sPath, true);
Expand Down
Loading

0 comments on commit b2c1a65

Please sign in to comment.