Skip to content

Commit e6b1a44

Browse files
committed
Create a specific function for checking for a chart's filter eligibility
also make a way to compile a list of steps via the song route
1 parent 0b1af21 commit e6b1a44

File tree

4 files changed

+86
-59
lines changed

4 files changed

+86
-59
lines changed

src/Etterna/Models/Songs/Song.cpp

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,73 +1651,32 @@ Song::HighestMSDOfSkillset(Skillset skill, float rate) const
16511651
bool
16521652
Song::IsSkillsetHighestOfChart(Steps* chart, Skillset skill, float rate) const
16531653
{
1654-
auto sorted_skills = chart->SortSkillsetsAtRate(rate, false);
1655-
return (sorted_skills[0].first == skill);
1654+
return chart->IsSkillsetHighest(skill, rate);
16561655
}
16571656

16581657
bool
1659-
Song::MatchesFilter(const float rate) const
1658+
Song::MatchesFilter(const float rate, std::vector<Steps*>* vMatchingStepsOut) const
16601659
{
16611660
auto charts = GetChartsOfCurrentGameMode();
16621661

16631662
for (auto* const chart : charts) {
1664-
// Iterate over all maps of the given type
1665-
auto addsong = FILTERMAN->ExclusiveFilter;
1666-
/* The default behaviour of an exclusive filter is to accept
1667-
* by default, (i.e. addsong=true) and reject if any
1668-
* filters fail. The default behaviour of a non-exclusive filter is
1669-
* the exact opposite: reject by default (i.e.
1670-
* addsong=false), and accept if any filters match.
1671-
*/
1672-
for (auto ss = 0; ss < NUM_Skillset + 1; ss++) {
1673-
// Iterate over all skillsets, up to and
1674-
// including the placeholder NUM_Skillset
1675-
const auto lb = FILTERMAN->SSFilterLowerBounds[ss];
1676-
const auto ub = FILTERMAN->SSFilterUpperBounds[ss];
1677-
if (lb > 0.f || ub > 0.f) { // If either bound is active, continue
1678-
1679-
if (!FILTERMAN->ExclusiveFilter) { // Non-Exclusive filter
1680-
if (FILTERMAN->HighestSkillsetsOnly)
1681-
if (!IsSkillsetHighestOfChart(
1682-
chart, static_cast<Skillset>(ss), rate) &&
1683-
ss < NUM_Skillset) // The current skill is not
1684-
// in highest in the chart
1685-
continue;
1686-
}
1687-
float val;
1688-
if (ss < NUM_Skillset)
1689-
val = chart->GetMSD(rate, ss);
1690-
else {
1691-
// If we are on the placeholder skillset, look at song
1692-
// length instead of a skill
1693-
val = chart->GetLengthSeconds(rate);
1694-
}
1695-
if (FILTERMAN->ExclusiveFilter) {
1696-
/* Our behaviour is to accept by default,
1697-
* but reject if any filters don't match.*/
1698-
if ((val < lb && lb > 0.f) || (val > ub && ub > 0.f)) {
1699-
/* If we're below the lower bound and it's set,
1700-
* or above the upper bound and it's set*/
1701-
addsong = false;
1702-
break;
1703-
}
1704-
} else { // Non-Exclusive Filter
1705-
/* Our behaviour is to reject by default,
1706-
* but accept if any filters match.*/
1707-
if ((val > lb || !(lb > 0.f)) &&
1708-
(val < ub || !(ub > 0.f))) {
1709-
/* If we're above the lower bound or it's not set
1710-
* and also below the upper bound or it isn't set*/
1711-
addsong = true;
1712-
break;
1713-
}
1714-
}
1715-
}
1663+
// Iterate over all charts of the given type
1664+
1665+
bool addchart = chart->MatchesFilter(rate);
1666+
1667+
// terminate early if not grabbing each matching chart
1668+
// otherwise continue and add to the list
1669+
if (addchart) {
1670+
if (vMatchingStepsOut != nullptr)
1671+
vMatchingStepsOut->push_back(chart);
1672+
else
1673+
return true;
17161674
}
1717-
if (addsong)
1718-
return true;
17191675
}
1720-
return false;
1676+
// if we reach this and we arent adding to a vector, its false
1677+
// if we reach this and we are adding to a vector, it COULD be false
1678+
// (if adding, false would be if the list size is 0)
1679+
return (vMatchingStepsOut != nullptr && vMatchingStepsOut->size() != 0);
17211680
}
17221681

17231682
bool

src/Etterna/Models/Songs/Song.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class Song
346346
float rate) const -> bool;
347347
/** @brief This functions returns whether it has any chart of the given
348348
types with the given rate. If no type is given it checks all charts.*/
349-
[[nodiscard]] auto MatchesFilter(float rate) const -> bool;
349+
[[nodiscard]] auto MatchesFilter(float rate, std::vector<Steps*>* vMatchingStepsOut = nullptr) const -> bool;
350350

351351
auto HasChartByHash(const std::string& hash) -> bool;
352352

src/Etterna/Models/StepsAndStyles/Steps.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "RageUtil/Utils/RageUtil.h"
3030
#include "Etterna/Models/Songs/Song.h"
3131
#include "Etterna/Singletons/SongManager.h"
32+
#include "Etterna/Singletons/FilterManager.h"
3233

3334
#include "Etterna/Models/NoteData/NoteDataStructures.h"
3435
#include "Etterna/Globals/SoloCalc.h"
@@ -368,6 +369,71 @@ Steps::IsRecalcValid() -> bool
368369
return true;
369370
}
370371

372+
auto
373+
Steps::IsSkillsetHighest(Skillset skill, float rate) -> bool
374+
{
375+
auto sorted_skills = SortSkillsetsAtRate(rate, false);
376+
return (sorted_skills[0].first == skill);
377+
}
378+
379+
auto
380+
Steps::MatchesFilter(const float rate) -> bool
381+
{
382+
auto addchart = FILTERMAN->ExclusiveFilter;
383+
384+
/* The default behaviour of an exclusive filter is to accept
385+
* by default, (i.e. addsong=true) and reject if any
386+
* filters fail. The default behaviour of a non-exclusive filter is
387+
* the exact opposite: reject by default (i.e.
388+
* addsong=false), and accept if any filters match.
389+
*/
390+
391+
for (auto ss = 0; ss < NUM_Skillset + 1; ss++) {
392+
// Iterate over all skillsets, up to and
393+
// including the placeholder NUM_Skillset
394+
const auto lb = FILTERMAN->SSFilterLowerBounds[ss];
395+
const auto ub = FILTERMAN->SSFilterUpperBounds[ss];
396+
if (lb > 0.f || ub > 0.f) { // If either bound is active, continue
397+
398+
if (!FILTERMAN->ExclusiveFilter) { // Non-Exclusive filter
399+
if (FILTERMAN->HighestSkillsetsOnly)
400+
if (!IsSkillsetHighest(static_cast<Skillset>(ss), rate) &&
401+
ss < NUM_Skillset) // The current skill is not
402+
// in highest in the chart
403+
continue;
404+
}
405+
float val;
406+
if (ss < NUM_Skillset)
407+
val = GetMSD(rate, ss);
408+
else {
409+
// If we are on the placeholder skillset, look at song
410+
// length instead of a skill
411+
val = GetLengthSeconds(rate);
412+
}
413+
if (FILTERMAN->ExclusiveFilter) {
414+
/* Our behaviour is to accept by default,
415+
* but reject if any filters don't match.*/
416+
if ((val < lb && lb > 0.f) || (val > ub && ub > 0.f)) {
417+
/* If we're below the lower bound and it's set,
418+
* or above the upper bound and it's set*/
419+
addchart = false;
420+
break;
421+
}
422+
} else { // Non-Exclusive Filter
423+
/* Our behaviour is to reject by default,
424+
* but accept if any filters match.*/
425+
if ((val > lb || !(lb > 0.f)) && (val < ub || !(ub > 0.f))) {
426+
/* If we're above the lower bound or it's not set
427+
* and also below the upper bound or it isn't set*/
428+
addchart = true;
429+
break;
430+
}
431+
}
432+
}
433+
}
434+
return addchart;
435+
}
436+
371437
auto
372438
Steps::GetMSD(float rate, Skillset ss) const -> float
373439
{

src/Etterna/Models/StepsAndStyles/Steps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class Steps
262262
{
263263
return debugstrings;
264264
}
265+
auto IsSkillsetHighest(Skillset skill, float rate) -> bool;
266+
auto MatchesFilter(const float rate) -> bool;
265267

266268
private:
267269
std::string ChartKey = "";

0 commit comments

Comments
 (0)