Skip to content

Commit

Permalink
add fastwalk back and array itv_rows/size, add basic derived rowinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jun 23, 2020
1 parent 3f28aa0 commit 51f53f3
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 59 deletions.
16 changes: 8 additions & 8 deletions src/Etterna/Globals/MinaCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ static const std::array<float, NUM_Skillset> basescalers = {
0.F, 0.97F, 0.92F, 0.83F, 0.94F, 0.95F, 0.78F, 0.9F
};

static thread_local int numitv = 0;

void
Calc::TotalMaxPoints()
{
Expand Down Expand Up @@ -346,7 +344,9 @@ Calc::InitializeHands(const vector<NoteInfo>& NoteInfo,
float offset) -> bool
{
numitv = static_cast<int>(
std::ceil(NoteInfo.back().rowTime / (music_rate * IntervalSpan)));
std::ceil(NoteInfo.back().rowTime / (music_rate * IntervalSpan)));

fastwalk(NoteInfo, music_rate, *this, offset);

bool junk_file_mon = false;
ProcessedFingers fingers;
Expand All @@ -368,7 +368,7 @@ Calc::InitializeHands(const vector<NoteInfo>& NoteInfo,
l_hand.InitPoints(fingers[0], fingers[1]);
r_hand.InitPoints(fingers[2], fingers[3]);

ulbu_that_which_consumes_all(nervIntervals, music_rate);
ulbu_that_which_consumes_all();

l_hand.InitAdjDiff(*this);
r_hand.InitAdjDiff(*this);
Expand Down Expand Up @@ -569,7 +569,7 @@ Hand::InitAdjDiff(Calc& calc)
};

// ok this loop is pretty wack i know, for each interval
for (int i = 0; i < numitv; ++i) {
for (int i = 0; i < calc.numitv; ++i) {
float tp_mods[NUM_Skillset] = {
1.F, 1.F, 1.F, 1.F, 1.F, 1.F, 1.F, 1.F
};
Expand Down Expand Up @@ -708,7 +708,7 @@ Hand::CalcInternal(float& gotpoints,
// }
// }
//} else {
for (int i = 0; i < numitv; ++i) {
for (int i = 0; i < calc.numitv; ++i) {
if (x < (*v)[i]) {
auto pts = static_cast<float>(v_itvpoints[i]);
gotpoints -=
Expand Down Expand Up @@ -740,7 +740,7 @@ Hand::StamAdjust(float x, int ss, Calc& calc, bool debug)
// i don't like the copypasta either but the boolchecks where
// they were were too slow
if (debug) {
for (int i = 0; i < numitv; i++) {
for (int i = 0; i < calc.numitv; i++) {
avs1 = avs2;
avs2 = base_diff->at(i);
mod += ((((avs1 + avs2) / 2.F) / (stam_prop * x)) - 1.F) / stam_mag;
Expand All @@ -754,7 +754,7 @@ Hand::StamAdjust(float x, int ss, Calc& calc, bool debug)
debugValues[2][StamMod][i] = mod;
}
} else {
for (int i = 0; i < numitv; i++) {
for (int i = 0; i < calc.numitv; i++) {
avs1 = avs2;
avs2 = base_diff->at(i);
mod += ((((avs1 + avs2) / 2.F) / (stam_prop * x)) - 1.F) / stam_mag;
Expand Down
27 changes: 27 additions & 0 deletions src/Etterna/Globals/MinaCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ class Calc;
// should be able to handle 1hr 54min easily
static const int max_intervals = 40000;

// intervals are _half_ second, no point in wasting time or cpu cycles on 100
// nps joke files. even at most generous, 100 nps spread across all fingers,
// that's still 25 nps which is considerably faster than anyone can sustain
// vibro for a full second
static const int max_rows_for_single_interval = 50;

enum hands
{
left_hand,
right_hand,
num_hands,
};

// uhhh
struct RowInfo
{
unsigned row_notes = 0U;
int row_count = 0;
std::array<int, num_hands> hand_counts = { 0, 0 };
float row_time = 0.F;
};

class Hand
{
public:
Expand Down Expand Up @@ -133,6 +148,16 @@ class Calc
const float IntervalSpan = 0.5F; // Intervals of time we slice the chart at

public:
// the most basic derviations from the most basic notedata
std::array<std::array<RowInfo, max_rows_for_single_interval>, max_intervals>
adj_ni;

// size of each interval in rows
std::array<int, max_intervals> itv_size;

// Point allotment for each interval
std::array<std::array<int, max_intervals>, num_hands> itv_points;

// holds pattern mods
std::array<std::array<std::array<float, max_intervals>, NUM_CalcPatternMod>,
num_hands>
Expand Down Expand Up @@ -161,6 +186,8 @@ class Calc
// but that might just be too confusing idk
std::array<float, max_intervals> stam_adj_diff;

int numitv = 0;

/* NOTE: all _incoming_ diffs should be stored as MS values, and only
* converted to scaled NPS on the way out */
};
Expand Down
6 changes: 1 addition & 5 deletions src/Etterna/Globals/MinaCalc/SequencingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ static const float ms_init = 5000.F;
// global multiplier to standardize baselines
static const float finalscaler = 3.632F;

// intervals are _half_ second, no point in wasting time or cpu cycles on 100
// nps joke files. even at most generous, 100 nps spread across all fingers,
// that's still 25 nps which is considerably faster than anyone can sustain
// vibro for a full second
static const int max_rows_for_single_interval = 50;


inline auto
column_count(const unsigned& notes) -> int
Expand Down
67 changes: 21 additions & 46 deletions src/Etterna/Globals/MinaCalc/Ulbu.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ struct TheGreatBazoinkazoinkInTheSky
bool dbg = false;

Calc& _calc;
const vector<NoteInfo>& _ni;
vector<vector<int>> _itv_rows;
float _rate = 0.F;
int hand = 0;

// to generate these
Expand Down Expand Up @@ -110,10 +107,7 @@ struct TheGreatBazoinkazoinkInTheSky
diffz _diffz;

TheGreatBazoinkazoinkInTheSky(const vector<NoteInfo>& ni, Calc& calc)
: // doesn't change with offset or anything, and we may do
// multi-passes at some point
_ni(ni)
, _calc(calc)
: _calc(calc)
{
#ifndef RELWITHDEBINFO
#if NDEBUG
Expand All @@ -137,13 +131,8 @@ struct TheGreatBazoinkazoinkInTheSky
_mhi = std::make_unique<metaHandInfo>();
}

inline void operator()(const vector<vector<int>>& itv_rows,
const float& rate)
inline void operator()()
{
// set interval/offset pass specific stuff
_itv_rows = itv_rows;
_rate = rate;

run_agnostic_pmod_loop();
run_dependent_pmod_loop();
}
Expand Down Expand Up @@ -194,15 +183,12 @@ struct TheGreatBazoinkazoinkInTheSky
unsigned row_notes = 0;
int row_count = 0;

for (int itv = 0; itv < _itv_rows.size(); ++itv) {

// run the row by row construction for interval info
for (auto& row : _itv_rows[itv]) {
row_time = _ni[row].rowTime / _rate;
row_notes = _ni[row].notes;
row_count = column_count(row_notes);
for (int itv = 0; itv < _calc.numitv; ++itv) {
for (int row = 0; row < _calc.itv_size.at(itv); ++row) {

(*_mri)(*_last_mri, _mitvi, row_time, row_count, row_notes);
const auto& ri = _calc.adj_ni.at(itv).at(row);
(*_mri)(
*_last_mri, _mitvi, ri.row_time, ri.row_count, ri.row_notes);

advance_agnostic_sequencing();

Expand All @@ -219,10 +205,10 @@ struct TheGreatBazoinkazoinkInTheSky
_mitvi.handle_interval_end();
}

PatternMods::run_agnostic_smoothing_pass(_itv_rows.size(), _calc);
PatternMods::run_agnostic_smoothing_pass(_calc.numitv, _calc);

// copy left -> right for agnostic mods
PatternMods::bruh_they_the_same(_itv_rows.size(), _calc);
PatternMods::bruh_they_the_same(_calc.numitv, _calc);
}

#pragma endregion
Expand Down Expand Up @@ -363,32 +349,21 @@ struct TheGreatBazoinkazoinkInTheSky
col_type ct = col_init;
full_hand_reset();

Smooth(_calc.soap.at(hand).at(NPSBase), 0.F, _itv_rows.size());

// so we are technically doing this again (twice) and don't to
// be doing it, but it makes debugging much less of a pita if we
// aren't doing something like looping over intervals, running
// agnostic pattern mods, then looping over hands for dependent
// mods in the same interval, we may still want to do that or at
// least have an optional set for that in case a situation
// arises where something might need both types of info (we'd
// also need to have 2 itvhandinfo objects, or just for general
// performance (though the redundancy on this pass vs agnostic
// the pass is limited to like... a couple floats and 2 ints)
for (int itv = 0; itv < _itv_rows.size(); ++itv) {

// run the row by row construction for interval info
for (auto& row : _itv_rows[itv]) {

// derive and set the most basic information, from which
// everything else will be derived
row_time = _ni[row].rowTime / _rate;
row_notes = _ni[row].notes;
row_count = column_count(row_notes);
Smooth(_calc.soap.at(hand).at(NPSBase), 0.F, _calc.numitv);

for (int itv = 0; itv < _calc.numitv; ++itv) {
for (int 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;
row_count = ri.row_count;

// don't like having this here
any_ms = ms_from(row_time, last_row_time);

assert(any_ms > 0.F);

ct = determine_col_type(row_notes, ids);

// handle any special cases that need to be executed on
Expand Down Expand Up @@ -439,7 +414,7 @@ struct TheGreatBazoinkazoinkInTheSky

handle_dependent_interval_end(itv);
}
PatternMods::run_dependent_smoothing_pass(_itv_rows.size(), _calc);
PatternMods::run_dependent_smoothing_pass(_calc.numitv, _calc);

// smoothing has been built into the construction process so we
// probably don't need these anymore? maybe ms smooth if necessary,
Expand Down
120 changes: 120 additions & 0 deletions src/Etterna/Globals/MinaCalc/UlbuAcolytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

static const std::string calc_params_xml = "Save/calc params.xml";
static const std::array<unsigned, num_hands> hand_col_ids = { 3, 12 };
static const float interval_span = 0.5F;

// holds pattern mods
/*
Expand Down Expand Up @@ -109,3 +110,122 @@ struct PatternMods
}
}
};

// converts time to interval index, if there's an offset to add or a rate to
// scale by, it should be done prior
inline int
time_to_itv_idx(const float& time)
{
return static_cast<int>(time / interval_span);
}

// checks to see if the noteinfo will fit in our static arrays, if it won't it's
// some garbage joke file and we can throw it out, setting values to 0
inline auto
fastwalk(const vector<NoteInfo>& ni,
const float& rate,
Calc& calc,
const float& offset = 0.F) -> bool
{
// add 1 to convert index to size, we're just using this to guess due to
// potential float precision differences, the actual numitv will be set at
// the end
calc.numitv = time_to_itv_idx(ni.back().rowTime / rate) + 1;

// are there more intervals than our alloted max
if (calc.numitv >= max_intervals)
return true;

// for various reasons we actually have to do this, scan the file and make
// sure each successive row time is greater than the last
for (int i = 1; i < ni.size(); ++i) {
if (ni.at(i - 1).rowTime >= ni.at(i).rowTime) {
return true;
}
}

// now we can attempt to construct notinfo that includes column count and
// rate adjusted row time, both of which are derived data that both pmod
// loops require
int itv = 0;
int last_itv = 0;
int row_counter = 0;
float scaled_time = 0.F;
for (int i = 0; i < ni.size(); ++i) {

// it's at least 25 nps per finger, throw it out
if (row_counter >= max_rows_for_single_interval)
return true;

const auto& ri = ni.at(i);

float zoop = (ni.at(i).rowTime + offset) / rate;

if (i > 0)
assert(zoop > scaled_time);

scaled_time = (ni.at(i).rowTime + offset) / rate;

// set current interval and current scaled time
itv = time_to_itv_idx(scaled_time);

// new interval, reset row counter and set new last interval
if (itv > last_itv) {

// we're using static arrays so if we skip over some empty intervals
// we have to go back and set their row counts to 0
if (itv - last_itv > 1) {
for (int j = last_itv + 1; j < itv; ++j) {
calc.itv_size.at(j) = 0;
}
}

calc.itv_size.at(last_itv) = row_counter;

last_itv = itv;
row_counter = 0;
}

auto& nri = calc.adj_ni.at(itv).at(row_counter);

nri.row_notes = ri.notes;
nri.row_count = column_count(ri.notes);
nri.row_time = scaled_time;

int left = 0;
int right = 0;

if (ri.notes & 1) {
++left;
}
if (ri.notes & 2) {
++left;
}
if (ri.notes & 4) {
++right;
}
if (ri.notes & 8) {
++right;
}

nri.hand_counts[left_hand] = left;
nri.hand_counts[right_hand] = right;

++row_counter;
}

// take care to set the proper values for the last row, the set logic block
// won't be hit on it
if (itv - last_itv > 1) {
for (int j = last_itv + 1; j < itv; ++j) {
calc.itv_size.at(j) = 0;
}
}

calc.itv_size.at(itv) = row_counter;

// make sure we only set up to the interval/row we actually use
calc.numitv = itv + 1;

return false;
}

0 comments on commit 51f53f3

Please sign in to comment.