Skip to content

Commit

Permalink
Merge pull request etternagame#282 from nico-abram/ndCache
Browse files Browse the repository at this point in the history
Nd cache
  • Loading branch information
nico-abram authored Sep 16, 2018
2 parents dc3209e + ec0f3bc commit ecc9a0f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
93 changes: 93 additions & 0 deletions src/ScreenInstallOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ScreenInstallOverlay.h"
#include "RageFileManager.h"
#include "ScreenManager.h"
#include "CryptManager.h"
#include "Preference.h"
#include "RageLog.h"
#include "json/value.h"
Expand All @@ -28,6 +29,15 @@ class Song;
#include "SongManager.h"
#include "SongManager.h"
#include "StepMania.h"
#include "ActorUtil.h"
#include "Song.h"
#include "NoteData.h"
#include "Steps.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
#include <fstream>

#if !defined(WITHOUT_NETWORKING)
#include "DownloadManager.h"
Expand Down Expand Up @@ -73,6 +83,89 @@ void DoInstalls(CommandLineActions::CommandLineArgs args)
for (int i = 0; i<(int)args.argv.size(); i++)
{
RString s = args.argv[i];
if (s == "notedataCache") {
FOREACH_CONST(Song*, SONGMAN->GetAllSongs(), iSong) {
Song *pSong = (*iSong);

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

// Only save steps that weren't loaded from a profile.
if (pSteps->WasLoadedFromProfile())
continue;
vpStepsToSave.push_back(pSteps);
}
FOREACH_CONST(Steps*, pSong->m_UnknownStyleSteps, s)
{
vpStepsToSave.push_back(*s);
}
string songkey;
for (auto& st : vpStepsToSave)
songkey += st->GetChartKey();
songkey = BinaryToHex(CRYPTMAN->GetSHA1ForString(songkey));
if (pSong->HasBanner()) {
RageFile f;
f.Open(pSong->GetBannerPath());
string p = f.GetPath();
f.Close();
std::ofstream dst(args.argv[i + 1] + songkey + "_banner." + GetExtension(pSong->m_sBannerFile).c_str(), std::ios::binary);
std::ifstream src(p, std::ios::binary);
dst << src.rdbuf();
dst.close();
}
if (pSong->HasCDTitle()) {
RageFile f;
f.Open(pSong->GetCDTitlePath());
string p = f.GetPath();
f.Close();
std::ofstream dst(args.argv[i + 1] + songkey + "_cd." + GetExtension(pSong->m_sCDTitleFile).c_str(), std::ios::binary);
std::ifstream src(p, std::ios::binary);
dst << src.rdbuf();
dst.close();
}

if (pSong->HasBackground()) {
RageFile f;
f.Open(pSong->GetBackgroundPath());
string p = f.GetPath();
f.Close();
std::ofstream dst(args.argv[i + 1] +songkey + "_bg." + GetExtension(pSong->m_sBackgroundFile).c_str(), std::ios::binary);
std::ifstream src(p, std::ios::binary);
dst << src.rdbuf();
dst.close();
}
FOREACH_CONST(Steps*, pSong->GetAllSteps(), iSteps) {
Steps* steps = (*iSteps);
TimingData* td = steps->GetTimingData();
NoteData nd;
steps->GetNoteData(nd);

nd.LogNonEmptyRows();
auto& nerv = nd.GetNonEmptyRowVector();
auto& etaner = td->BuildAndGetEtaner(nerv);
auto& serializednd = nd.SerializeNoteData(etaner);

string path = args.argv[i+1]+ steps->GetChartKey()+".cache";
ofstream FILE(path, ios::out | ofstream::binary);
FILE.write((char *)&serializednd[0], serializednd.size() * sizeof(NoteInfo));
FILE.close();
vector<NoteInfo> newVector;
std::ifstream INFILE(path, std::ios::in | std::ifstream::binary);
INFILE.seekg(0, ios::end);
newVector.resize(INFILE.tellg() / sizeof(NoteInfo));
INFILE.seekg(0, ios::beg);
INFILE.read((char *)&newVector[0], newVector.capacity() * sizeof(NoteData));
INFILE.close();

td->UnsetEtaner();
nd.UnsetNerv();
nd.UnsetSerializedNoteData();
steps->Compress();
}
}
}
if (IsHTTPProtocol(s))
{

Expand Down
4 changes: 2 additions & 2 deletions src/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,17 @@ class Song
// Lua
void PushSelf( lua_State *L );

vector<Steps*> m_vpSteps;
vector<Steps*> m_UnknownStyleSteps;
private:
bool isfavorited = false;
bool permamirror = false;
bool hasgoal = false;
bool m_loaded_from_autosave;
/** @brief the Steps that belong to this Song. */
vector<Steps*> m_vpSteps;
/** @brief the Steps of a particular StepsType that belong to this Song. */
vector<Steps*> m_vpStepsByType[NUM_StepsType];
/** @brief the Steps that are of unrecognized Styles. */
vector<Steps*> m_UnknownStyleSteps;
};

#endif
Expand Down

0 comments on commit ecc9a0f

Please sign in to comment.