Skip to content

Commit

Permalink
generic jack calc abomination | 509
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Aug 29, 2023
1 parent a4142e2 commit 1b75bb6
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Etterna/MinaCalc/MinaCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ MinaSDCalcDebug(
}
}

int mina_calc_version = 508;
int mina_calc_version = 509;
auto
GetCalcVersion() -> int
{
Expand Down
110 changes: 110 additions & 0 deletions src/Etterna/MinaCalc/SequencedBaseDiffCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,116 @@ struct techyo
}
};


struct jack_col
{
int len = 1;
float last_ms = ms_init;
float max_ms = ms_init;
float len_capped_ms = ms_init;
float last_note_sec = s_init;
float start_note_sec = s_init;
inline void reset()
{
len = 1;
last_ms = ms_init;
max_ms = ms_init;
len_capped_ms = ms_init;
last_note_sec = s_init;
start_note_sec = s_init;
}
inline void operator()(const float& now)
{
last_ms = ms_from(now, last_note_sec);
if (last_ms > max_ms + jack_spacing_buffer_ms ||
last_ms * jack_speed_increase_cutoff_factor < max_ms) {
// too slow reset, too fast reset
start_note_sec = last_note_sec;
len = 2;
} else {
len++;
}
max_ms = last_ms;
last_note_sec = now;
}
inline float get_ms() {
if (len > jack_len_cap) {
return len_capped_ms;
}
static const auto avg_ms_mult = 1.5F;
static const auto anchor_time_buffer_ms = 30.F;
static const auto min_ms = 95.F;
const auto total_ms = ms_from(last_note_sec, start_note_sec);
const auto _len = static_cast<float>(len - 1);
const auto avg_ms = total_ms / _len;
const auto adj_total_ms =
total_ms + anchor_time_buffer_ms + avg_ms * avg_ms_mult;
auto ms = adj_total_ms / _len;
if (len == 2) {
ms *= 1.1F;
ms = ms < 180.F ? 180.F : ms;
}
ms = ms < min_ms ? min_ms : ms;
if (std::isnan(ms))
ms = max_ms;
if (len == jack_len_cap) {
len_capped_ms = ms;
}
return ms;
}
};
struct oversimplified_jacks
{
std::vector<jack_col> sequencers{};

std::vector<unsigned> left_hand_mask{};
std::vector<unsigned> right_hand_mask{};

void init(const int& keycount) {
sequencers = std::vector<jack_col>(keycount);
left_hand_mask.clear();
right_hand_mask.clear();
for (auto i = 0; i < keycount / 2; i++) {
left_hand_mask.push_back(i);
}
/*
if (keycount > 2 && keycount % 2 != 0) {
left_hand_mask.push_back(keycount / 2);
}
*/
for (auto i = keycount / 2; i < keycount; i++) {
right_hand_mask.push_back(i);
}
reset();
}

void reset() {
for (auto& seq : sequencers) {
seq.reset();
}
}

void operator()(const int& column,
const float& now)
{
sequencers.at(column)(now);
}

float get_lowest_jack_ms(unsigned hand, Calc& calc) {
auto& mask = hand == left_hand ? left_hand_mask : right_hand_mask;

auto min = ms_init;
for (auto& col : mask) {
const auto v = sequencers.at(col).get_ms();
if (v < min) {
min = v;
}
}
return min;
}

};

struct diffz
{
nps _nps;
Expand Down
16 changes: 15 additions & 1 deletion src/Etterna/MinaCalc/SequencingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ keycount_to_bin(const unsigned& keycount) -> unsigned
{
if (keycount < 2)
return 0b11;
return ~(~1 << (keycount - 1));
return ~(~1u << (keycount - 1u));
}

// outputs 0b1100 for 4, 0b110 for 3, etc
Expand All @@ -47,6 +47,20 @@ column_count(const unsigned& notes) -> int
return std::popcount(notes);
}

// return a vector of which columns are not empty
// 0 is the leftmost column
inline auto
find_non_empty_cols(const unsigned& notes) -> std::vector<unsigned>
{
std::vector<unsigned> o{};
for (auto i = 0u; 1u << i <= notes; i++) {
if (((1u << i) & notes) != 0u) {
o.push_back(i);
}
}
return o;
}

/// milliseconds between two given timestamps in seconds
inline auto
ms_from(const float& now, const float& last) -> float
Expand Down
57 changes: 57 additions & 0 deletions src/Etterna/MinaCalc/UlbuBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct Bazoinkazoink
public:
Calc& _calc;

oversimplified_jacks lazy_jacks;

explicit Bazoinkazoink(Calc& calc)
: _calc(calc)
{
Expand Down Expand Up @@ -84,6 +86,8 @@ struct Bazoinkazoink
virtual void operator()() {
reset_base_diffs();

lazy_jacks.init(_calc.keycount);

// just nps base
unsigned hand = 0;
for (const auto& ids : _calc.hand_col_masks) {
Expand All @@ -92,9 +96,62 @@ struct Bazoinkazoink
0.F,
_calc.numitv);

auto row_time = s_init;
auto last_row_time = s_init;
auto any_ms = ms_init;
auto row_notes = 0u;
for (auto itv = 0; itv < _calc.numitv; ++itv) {
for (auto row = 0; row < _calc.itv_size.at(itv); row++) {
const auto& ri = _calc.adj_ni.at(itv).at(row);
row_time = ri.row_time;
row_notes = ri.row_notes;
any_ms = ms_from(row_time, last_row_time);
auto masked_notes = row_notes & ids;

auto non_empty_cols = find_non_empty_cols(masked_notes);
if (non_empty_cols.empty()) {
continue;
}

for (auto& c : non_empty_cols) {
lazy_jacks(c, row_time);
}

auto thing = std::pair{
row_time,
ms_to_scaled_nps(lazy_jacks.get_lowest_jack_ms(hand, _calc)) *
basescalers[Skill_JackSpeed]
};
if (std::isnan(thing.second)) {
thing.second = 0.F;
}
_calc.jack_diff.at(hand).push_back(thing);
}
}

hand++;
}



// hand agnostic sequencing
/*
{
auto row_time = s_init;
auto last_row_time = s_init;
auto any_ms = ms_init;
auto row_notes = 0u;
for (auto itv = 0; itv < _calc.numitv; ++itv) {
for (auto row = 0; row < _calc.itv_size.at(itv); row++) {
const auto& ri = _calc.adj_ni.at(itv).at(row);
row_time = ri.row_time;
row_notes = ri.row_notes;
any_ms = ms_from(row_time, last_row_time);
}
}
}*/

}

/// load custom xml parameters
Expand Down
35 changes: 35 additions & 0 deletions src/Etterna/MinaCalc/UlbuSevenKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct TheSevenFootedBazoinkazoink : public Bazoinkazoink
{
reset_base_diffs();

lazy_jacks.init(_calc.keycount);

// just nps base
unsigned hand = 0;
for (const auto& ids : _calc.hand_col_masks) {
Expand All @@ -73,6 +75,39 @@ struct TheSevenFootedBazoinkazoink : public Bazoinkazoink
0.F,
_calc.numitv);

auto row_time = s_init;
auto last_row_time = s_init;
auto any_ms = ms_init;
auto row_notes = 0u;
for (auto itv = 0; itv < _calc.numitv; ++itv) {
for (auto row = 0; row < _calc.itv_size.at(itv); row++) {
const auto& ri = _calc.adj_ni.at(itv).at(row);
row_time = ri.row_time;
row_notes = ri.row_notes;
any_ms = ms_from(row_time, last_row_time);
auto masked_notes = row_notes & ids;

auto non_empty_cols = find_non_empty_cols(masked_notes);
if (non_empty_cols.empty()) {
continue;
}

for (auto& c : non_empty_cols) {
lazy_jacks(c, row_time);
}

auto thing = std::pair{
row_time,
ms_to_scaled_nps(lazy_jacks.get_lowest_jack_ms(hand, _calc)) *
basescalers[Skill_JackSpeed]
};
if (std::isnan(thing.second)) {
thing.second = 0.F;
}
_calc.jack_diff.at(hand).push_back(thing);
}
}

hand++;
}

Expand Down
43 changes: 43 additions & 0 deletions src/Etterna/MinaCalc/UlbuSixKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,26 @@ struct TheSixEyedBazoinkazoink : public Bazoinkazoink
},
} };

const std::array<float, NUM_Skillset> basescalers = {
0.F, 1.F, 1.F, 1.F, 0.93F, 1.F, 1.F, 1.F
};

public:
const std::array<std::vector<int>, NUM_Skillset>& get_pmods() const override
{
return pmods;
}
const std::array<float, NUM_Skillset>& get_basescalers() const
{
return basescalers;
}

void operator()() override
{
reset_base_diffs();

lazy_jacks.init(_calc.keycount);

// just nps base
unsigned hand = 0;
for (const auto& ids : _calc.hand_col_masks) {
Expand All @@ -65,6 +75,39 @@ struct TheSixEyedBazoinkazoink : public Bazoinkazoink
0.F,
_calc.numitv);

auto row_time = s_init;
auto last_row_time = s_init;
auto any_ms = ms_init;
auto row_notes = 0u;
for (auto itv = 0; itv < _calc.numitv; ++itv) {
for (auto row = 0; row < _calc.itv_size.at(itv); row++) {
const auto& ri = _calc.adj_ni.at(itv).at(row);
row_time = ri.row_time;
row_notes = ri.row_notes;
any_ms = ms_from(row_time, last_row_time);
auto masked_notes = row_notes & ids;

auto non_empty_cols = find_non_empty_cols(masked_notes);
if (non_empty_cols.empty()) {
continue;
}

for (auto& c : non_empty_cols) {
lazy_jacks(c, row_time);
}

auto thing =
std::pair{ row_time,
ms_to_scaled_nps(
lazy_jacks.get_lowest_jack_ms(hand, _calc)) *
basescalers[Skill_JackSpeed] };
if (std::isnan(thing.second)) {
thing.second = 0.F;
}
_calc.jack_diff.at(hand).push_back(thing);
}
}

hand++;
}

Expand Down

0 comments on commit 1b75bb6

Please sign in to comment.