Skip to content

Commit

Permalink
remove obsolete index and add ability to reconcile busted keys with p…
Browse files Browse the repository at this point in the history
…roper ones
  • Loading branch information
MinaciousGrace committed Jun 3, 2017
1 parent a11d424 commit 4020933
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
15 changes: 11 additions & 4 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,23 @@ vector<string> Playlist::GetKeys() {
return o;
}

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

FOREACHUM(string, Steps*, StepsByKey, i) {
for (auto& n : i->second->bustedkeys)
if (ck == n)
ck = n;
}
}

// Only store 1 steps/song pointer per key -Mina
void SongManager::AddKeyedPointers(Song* new_song) {
const vector<Steps*> steps = new_song->GetAllSteps();
for (size_t i = 0; i < steps.size(); ++i) {
const RString& ck = steps[i]->GetChartKey();
if (!StepsByKey.count(ck)) {
if (steps.size() > 1) {
multichartbs.emplace(ck);
}

StepsByKey.emplace(ck, steps[i]);
if (!SongsByKey.count(ck)) {
SongsByKey.emplace(ck, new_song);
Expand Down
3 changes: 1 addition & 2 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ class SongManager
// Lua
void PushSelf( lua_State *L );


set<string> multichartbs;
map<string, Playlist> allplaylists;
string activeplaylist;
string playlistcourse;
void ReconcileBustedKeys(string& ck);

map<string, vector<Song*>> groupderps;
protected:
Expand Down
64 changes: 34 additions & 30 deletions src/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ bool Steps::IsRecalcValid() {
if (m_StepsType != StepsType_dance_single)
return false;

if (m_CachedRadarValues[RadarCategory_Notes] < 200)
return false;

TimingData* td = GetTimingData();
if (td->HasWarps())
return false;
Expand Down Expand Up @@ -382,51 +385,52 @@ void Steps::CalcEtternaMetadata() {

stuffnthings = MinaSDCalc(GetNoteData().SerializeNoteData(etaner), GetNoteData().GetNumTracks(), 0.93f, 1.f, GetTimingData()->HasWarps());
ChartKey = GenerateChartKey(*m_pNoteData, GetTimingData());
for (int i = 0; i < 8; ++i)
bustedkeys.emplace_back(GenerateBustedChartKey(*m_pNoteData, GetTimingData(), i));


m_pNoteData->UnsetNerv();
m_pNoteData->UnsetSerializedNoteData();
GetTimingData()->UnsetEtaner();
}

/*
RString Steps::GenerateChartKey(NoteData& nd, TimingData *td) {
RString o = "X"; // I was thinking of using "C" to indicate chart.. however.. X is cooler... - Mina
vector<int>& nerv = nd.GetNonEmptyRowVector();
string Steps::GenerateBustedChartKey(NoteData& nd, TimingData *td, int cores) {
RString o = "X"; // I was thinking of using "C" to indicate chart.. however.. X is cooler... - Mina
vector<int>& nerv = nd.GetNonEmptyRowVector();

unsigned int numThreads = max(std::thread::hardware_concurrency(), 1u);
std::vector<RString> keyParts;
keyParts.reserve(numThreads);
unsigned int numThreads = min(std::thread::hardware_concurrency(), 1u + cores);
std::vector<RString> keyParts;
keyParts.reserve(numThreads);

size_t segmentSize = nerv.size() / numThreads;
std::vector<std::thread> threads;
threads.reserve(numThreads);
size_t segmentSize = nerv.size() / numThreads;
std::vector<std::thread> threads;
threads.reserve(numThreads);

for (unsigned int curThread = 0; curThread < numThreads; curThread++)
{
keyParts.push_back("");
size_t start = segmentSize * curThread;
size_t end = start + segmentSize;
if (curThread + 1 == numThreads)
end = nerv.size();
for (unsigned int curThread = 0; curThread < numThreads; curThread++)
{
keyParts.push_back("");
size_t start = segmentSize * curThread;
size_t end = start + segmentSize;
if (curThread + 1 == numThreads)
end = nerv.size();

threads.push_back(std::thread(&Steps::FillStringWithBPMs, this, start, end, std::ref(nerv), std::ref(nd), td, std::ref(keyParts[curThread])));
}
threads.push_back(std::thread(&Steps::FillStringWithBPMs, this, start, end, std::ref(nerv), std::ref(nd), td, std::ref(keyParts[curThread])));
}

for (auto& t : threads)
{
if (t.joinable())
t.join();
}
for (auto& t : threads)
{
if (t.joinable())
t.join();
}

// handle empty charts if they get to here -mina
if (*keyParts.data() == "")
return "";
// handle empty charts if they get to here -mina
if (*keyParts.data() == "")
return "";

o.append(BinaryToHex(CryptManager::GetSHA1ForString(*keyParts.data())));
o.append(BinaryToHex(CryptManager::GetSHA1ForString(*keyParts.data())));

return o;
return o;
}
*/


RString Steps::GenerateChartKey(NoteData& nd, TimingData *td)
Expand Down
4 changes: 4 additions & 0 deletions src/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class Steps

void CalcEtternaMetadata();

string GenerateBustedChartKey(NoteData & nd, TimingData * td, int cores);
vector<string> bustedkeys;
void MakeBustedKeys();

// this is bugged and returns true for files with negative bpms when it shouldn't - mina
bool IsRecalcValid();

Expand Down

0 comments on commit 4020933

Please sign in to comment.