Skip to content

Commit

Permalink
Consider filters when getting songs from songutil
Browse files Browse the repository at this point in the history
most of the time, when it matters
  • Loading branch information
poco0317 committed Jul 13, 2020
1 parent e6b1a44 commit adeb392
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
30 changes: 26 additions & 4 deletions src/Etterna/Models/Songs/SongUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "Etterna/Models/Misc/ThemeMetric.h"
#include "Etterna/FileTypes/XmlFile.h"
#include "Etterna/Models/StepsAndStyles/StepsUtil.h"
#include "Etterna/Singletons/FilterManager.h"
#include "Etterna/Models/Misc/PlayerState.h"

#include <functional>
#include <algorithm>
Expand All @@ -34,6 +36,7 @@ SongUtil::GetSteps(const Song* pSong,
Difficulty dc,
int iMeterLow,
int iMeterHigh,
bool filteringSteps,
const std::string& sDescription,
const std::string& sCredit,
bool bIncludeAutoGen,
Expand Down Expand Up @@ -61,6 +64,22 @@ SongUtil::GetSteps(const Song* pSong,
if (uHash != 0 && uHash != pSteps->GetHash())
continue;

if (FILTERMAN != nullptr && FILTERMAN->AnyActiveFilter()) {
// iterating over all rates until it just works
// explanation in MusicWheel::FilterBySkillsets
auto success = false;
for (auto currate = FILTERMAN->MaxFilterRate;
currate > FILTERMAN->m_pPlayerState->wtFFF - .01f;
currate -= 0.1f) {
if (pSteps->MatchesFilter(currate)) {
success = true;
break;
}
}
if (!success)
continue;
}

arrayAddTo.push_back(pSteps);

if (iMaxToGet != -1) {
Expand All @@ -77,6 +96,7 @@ SongUtil::GetOneSteps(const Song* pSong,
Difficulty dc,
int iMeterLow,
int iMeterHigh,
bool filteringSteps,
const std::string& sDescription,
const std::string& sCredit,
unsigned uHash,
Expand All @@ -89,6 +109,7 @@ SongUtil::GetOneSteps(const Song* pSong,
dc,
iMeterLow,
iMeterHigh,
filteringSteps,
sDescription,
sCredit,
bIncludeAutoGen,
Expand Down Expand Up @@ -147,7 +168,8 @@ SongUtil::GetStepsByDescription(const Song* pSong,
const std::string& sDescription)
{
vector<Steps*> vNotes;
GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, sDescription, "");
GetSteps(
pSong, vNotes, st, Difficulty_Invalid, -1, -1, false, sDescription, "");
if (vNotes.empty())
return nullptr;
return vNotes[0];
Expand All @@ -159,7 +181,7 @@ SongUtil::GetStepsByCredit(const Song* pSong,
const std::string& sCredit)
{
vector<Steps*> vNotes;
GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, "", sCredit);
GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, false, "", sCredit);
if (vNotes.empty())
return nullptr;
return vNotes[0];
Expand Down Expand Up @@ -998,13 +1020,13 @@ SongUtil::GetPlayableStepsTypes(const Song* pSong, set<StepsType>& vOut)
}

void
SongUtil::GetPlayableSteps(const Song* pSong, vector<Steps*>& vOut)
SongUtil::GetPlayableSteps(const Song* pSong, vector<Steps*>& vOut, bool filteringSteps)
{
set<StepsType> vStepsType;
GetPlayableStepsTypes(pSong, vStepsType);

for (const auto& st : vStepsType) {
GetSteps(pSong, vOut, st);
GetSteps(pSong, vOut, st, Difficulty_Invalid, -1, -1, filteringSteps);
}

StepsUtil::SortNotesArrayByDifficulty(vOut);
Expand Down
4 changes: 3 additions & 1 deletion src/Etterna/Models/Songs/SongUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ GetSteps(const Song* pSong,
Difficulty dc = Difficulty_Invalid,
int iMeterLow = -1,
int iMeterHigh = -1,
bool filteringSteps = false,
const std::string& sDescription = "",
const std::string& sCredit = "",
bool bIncludeAutoGen = true,
Expand All @@ -38,6 +39,7 @@ GetOneSteps(const Song* pSong,
Difficulty dc = Difficulty_Invalid,
int iMeterLow = -1,
int iMeterHigh = -1,
bool filteringSteps = false,
const std::string& sDescription = "",
const std::string& sCredit = "",
unsigned uHash = 0,
Expand Down Expand Up @@ -157,7 +159,7 @@ GetAllSongGenres(vector<std::string>& vsOut);
void
GetPlayableStepsTypes(const Song* pSong, std::set<StepsType>& vOut);
void
GetPlayableSteps(const Song* pSong, vector<Steps*>& vOut);
GetPlayableSteps(const Song* pSong, vector<Steps*>& vOut, bool filteringSteps = false);
auto
IsStepsTypePlayable(Song* pSong, StepsType st) -> bool;
auto
Expand Down
4 changes: 2 additions & 2 deletions src/Etterna/Models/StepsAndStyles/StepsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ StepsID::ToSteps(const Song* p, bool bAllowNull) const
Steps* pRet = nullptr;
if (dc == Difficulty_Edit) {
pRet = SongUtil::GetOneSteps(
p, st, dc, -1, -1, sDescription, "", uHash, true);
p, st, dc, -1, -1, false, sDescription, "", uHash, true);
} else {
pRet = SongUtil::GetOneSteps(p, st, dc, -1, -1, "", "", 0, true);
pRet = SongUtil::GetOneSteps(p, st, dc, -1, -1, false, "", "", 0, true);
}

if (!bAllowNull && pRet == nullptr)
Expand Down

0 comments on commit adeb392

Please sign in to comment.