Skip to content

Commit

Permalink
use "proper" enums to avoid hardcoding loops for calc output lau side
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Apr 23, 2020
1 parent bd932af commit e2fae36
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 66 deletions.
36 changes: 32 additions & 4 deletions Themes/Til Death/BGAnimations/_calcdisplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ local finalSecond
local graphVecs = {}
local ssrs

local CalcPatternMod =
{
"OHJump",
"Anchor",
"Roll",
"HS",
"Jump",
"CJ",
}

local CalcDebugMisc =
{
"PtLoss", -- goes in bot graph
"StamMod",-- goes in top graph
}

local CalcDiffValue =
{
"BaseNPS",
"BaseMS",
"BaseMSD",
"MSD",
}

local function fitX(x, lastX) -- Scale time values to fit within plot width.
if lastX == 0 then
return 0
Expand Down Expand Up @@ -148,11 +172,15 @@ local function updateCoolStuff()
graphVecs[1] = {}
graphVecs[2] = {}
graphVecs[3] = {}
for i= 1, 12 do
graphVecs[1][i] = bap[i]
ms.ok(#bap["Jump"][1])
for i= 1, #CalcPatternMod do
graphVecs[1][i] = bap[CalcPatternMod[i]]
--ms.ok(showKeys(bap))
--ms.ok(#bap[CalcPatternMod[1]])
for ii = 1, #bap[CalcPatternMod[1]] do
--ms.ok(bap[CalcPatternMod[1]][ii])
end
end

-- need to properly enum this garbo
graphVecs[1][13] = bap[23] -- stammod (should be separate prolly?)
graphVecs[1][14] = bap[24]

Expand Down
73 changes: 38 additions & 35 deletions src/Etterna/Globals/MinaCalc.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#pragma once
#include "MinaCalc.h"
#include <cmath>
#include <iostream>
#include <algorithm>
#include <memory>
#include <numeric>

using std::max;
using std::min;
using std::pow;
using std::sqrt;
using std::vector;

static int DebugCount = NUM_CalcPatternMod + NUM_CalcDiffValue + NUM_CalcDebugMisc;

template<typename T>
T
CalcClamp(T x, T l, T h)
Expand Down Expand Up @@ -188,7 +191,8 @@ Calc::CalcMain(const vector<NoteInfo>& NoteInfo,

// first - zoot the boot up the loot, we don't want to straddle below and
// above 1 here
float mcfroggerbopper = pow(1.f + (mcbloop[highest_base_skillset] - base), 2) - 1.f;
float mcfroggerbopper =
pow(1.f + (mcbloop[highest_base_skillset] - base), 2) - 1.f;
// all pow with the pow now
float poodle_in_a_porta_potty = mcbloop[highest_base_skillset];

Expand All @@ -203,7 +207,8 @@ Calc::CalcMain(const vector<NoteInfo>& NoteInfo,
// leaderboards with charts that are just very high rated but have no
// stamina component
mcfroggerbopper = CalcClamp(mcfroggerbopper, 0.f, 1.1f);
mcbloop[Stamina] = 0.65f * poodle_in_a_porta_potty + (mcfroggerbopper * 0.35f * poodle_in_a_porta_potty);
mcbloop[Stamina] = 0.65f * poodle_in_a_porta_potty +
(mcfroggerbopper * 0.35f * poodle_in_a_porta_potty);

// yes i know how dumb this looks
DifficultyRating difficulty = { mcbloop[0], mcbloop[1], mcbloop[2],
Expand Down Expand Up @@ -380,7 +385,7 @@ Calc::InitializeHands(const vector<NoteInfo>& NoteInfo, float music_rate)
if (debugmode) {
left_hand.debugValues.resize(DebugCount);
right_hand.debugValues.resize(DebugCount);
for (size_t i = 0; i < DebugCount; ++i) {
for (int i = 0; i < DebugCount; ++i) {
left_hand.debugValues[i].resize(numitv);
right_hand.debugValues[i].resize(numitv);
}
Expand Down Expand Up @@ -425,15 +430,12 @@ Calc::InitializeHands(const vector<NoteInfo>& NoteInfo, float music_rate)
left_hand.debugValues[i] = left_hand.doot[i];
right_hand.debugValues[i] = right_hand.doot[i];
}
// uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh yea
// somehow i never did this and debug was still getting the
// somewhat right values... somehow??
left_hand.debugValues[BaseNPS] = left_hand.v_itvNPSdiff;
left_hand.debugValues[BaseMS] = left_hand.pureMSdiff;
left_hand.debugValues[BaseMSD] = left_hand.v_itvMSdiff;
right_hand.debugValues[BaseNPS] = right_hand.v_itvNPSdiff;
right_hand.debugValues[BaseMS] = right_hand.pureMSdiff;
right_hand.debugValues[BaseMSD] = right_hand.v_itvMSdiff;

// set everything but final adjusted output here
for (size_t i = 0; i < NUM_CalcDiffValue - 1; ++i) {
left_hand.debugValues[i] = left_hand.soap[i];
right_hand.debugValues[i] = right_hand.soap[i];
}
}

j0 = SequenceJack(NoteInfo, 0, music_rate);
Expand Down Expand Up @@ -500,9 +502,10 @@ Calc::Chisel(float player_skill,

// jack sequencer point loss for jack speed and (maybe?) cj
if (ss == JackSpeed || ss == Chordjack)
gotpoints = MaxPoints -
JackLoss(j0, player_skill) - JackLoss(j1, player_skill) -
JackLoss(j2, player_skill) - JackLoss(j3, player_skill);
gotpoints = MaxPoints - JackLoss(j0, player_skill) -
JackLoss(j1, player_skill) -
JackLoss(j2, player_skill) -
JackLoss(j3, player_skill);
else
// run standard calculator stuffies
gotpoints = left_hand.CalcInternal(player_skill, ss, stamina) +
Expand Down Expand Up @@ -541,29 +544,29 @@ Hand::CalcMSEstimate(vector<float>& input)
void
Hand::InitDiff(Finger& f1, Finger& f2)
{
v_itvNPSdiff = vector<float>(f1.size());
v_itvMSdiff = vector<float>(f1.size());
pureMSdiff = vector<float>(f1.size());
for (size_t i = 0; i < NUM_CalcDiffValue - 1; ++i)
soap[i].resize(f1.size());

for (size_t i = 0; i < f1.size(); i++) {
float nps = 1.6f * static_cast<float>(f1[i].size() + f2[i].size());
float left_difficulty = CalcMSEstimate(f1[i]);
float right_difficulty = CalcMSEstimate(f2[i]);
float difficulty = max(left_difficulty, right_difficulty);
v_itvNPSdiff[i] = finalscaler * nps;
pureMSdiff[i] = finalscaler * difficulty;
v_itvMSdiff[i] = finalscaler * (5.f * difficulty + 3.f * nps) / 8.f;
soap[BaseNPS][i] = finalscaler * nps;
soap[BaseMS][i] = finalscaler * difficulty;
soap[BaseMSD][i] = finalscaler * (5.f * difficulty + 3.f * nps) / 8.f;
}
Smooth(v_itvNPSdiff, 0.f);
Smooth(soap[BaseNPS], 0.f);
if (SmoothDifficulty)
DifficultyMSSmooth(v_itvMSdiff);
DifficultyMSSmooth(soap[BaseMSD]);
}

void
Hand::InitPoints(const Finger& f1, const Finger& f2)
{
for (size_t ki_is_rising = 0; ki_is_rising < f1.size(); ++ki_is_rising)
v_itvpoints.emplace_back(static_cast<int>(f1[ki_is_rising].size()) +
static_cast<int>(f2[ki_is_rising].size()));
static_cast<int>(f2[ki_is_rising].size()));
}

void
Expand Down Expand Up @@ -597,40 +600,39 @@ Hand::CalcInternal(float x, int ss, bool stam, bool debug)
{
// vector<float> temppatternsmods;
// we're going to recycle adj_diff for this part
for (size_t i = 0; i < v_itvNPSdiff.size(); ++i) {
for (size_t i = 0; i < soap[BaseNPS].size(); ++i) {
// only slightly less cancerous than before, this can/should be
// refactored once the areas of redundancy are more clearly defined
switch (ss) {
case Overall: // should never be the case, handled up the stack
break;
case Stream: // vanilla, apply everything based on nps diff
adj_diff[i] =
v_itvNPSdiff[i] * doot[HS][i] * doot[Jump][i] * doot[CJ][i];
soap[BaseNPS][i] * doot[HS][i] * doot[Jump][i] * doot[CJ][i];
adj_diff[i] *= basescalers[ss];
break;
case Jumpstream: // dont apply cj
adj_diff[i] = v_itvNPSdiff[i] * doot[HS][i] / doot[Jump][i];
adj_diff[i] = soap[BaseNPS][i] * doot[HS][i] / doot[Jump][i];
adj_diff[i] *= basescalers[ss];
break;
case Handstream: // here cj counterbalances hs a bit, not good
adj_diff[i] =
v_itvNPSdiff[i] / max(doot[HS][i], 0.925f) * doot[Jump][i];
soap[BaseNPS][i] / max(doot[HS][i], 0.925f) * doot[Jump][i];
adj_diff[i] *= basescalers[ss];
break;
case Stamina: // should never be the case, handled up the stack
break;
case JackSpeed: // use ms hybrid base
adj_diff[i] = v_itvMSdiff[i] * doot[HS][i] * doot[Jump][i];
adj_diff[i] = soap[BaseMSD][i] * doot[HS][i] * doot[Jump][i];
adj_diff[i] *= basescalers[ss];
break;
case Chordjack: // use ms hybrid base
adj_diff[i] =
v_itvMSdiff[i] / doot[CJ][i];
adj_diff[i] = soap[BaseMSD][i] / doot[CJ][i];
adj_diff[i] *= basescalers[ss];
break;
case Technical: // use ms hybrid base
adj_diff[i] =
v_itvMSdiff[i] * doot[HS][i] * doot[Jump][i] * doot[CJ][i];
soap[BaseMSD][i] * doot[HS][i] * doot[Jump][i] * doot[CJ][i];
adj_diff[i] *= basescalers[ss];
break;
}
Expand All @@ -651,7 +653,7 @@ Hand::CalcInternal(float x, int ss, bool stam, bool debug)
const vector<float>& v = stam ? stam_adj_diff : adj_diff;

if (debug) {

// final debug output should always be with stam activated
StamAdjust(x, adj_diff, true);
debugValues[MSD] = stam_adj_diff;
Expand All @@ -665,7 +667,8 @@ Hand::CalcInternal(float x, int ss, bool stam, bool debug)

output += gainedpoints;
if (debug)
debugValues[PtLoss][i] = (static_cast<float>(v_itvpoints[i]) - gainedpoints);
debugValues[PtLoss][i] =
(static_cast<float>(v_itvpoints[i]) - gainedpoints);
}

return output;
Expand Down
8 changes: 5 additions & 3 deletions src/Etterna/Globals/MinaCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ typedef std::vector<Finger> ProcessedFingers;
typedef std::vector<float> JackSeq;

// number of pattern mods yes i know this is dumb help
const static int ModCount = 6;
// we want to group stamina adjustment with the others for
// display purposes but we don't want it when initializing pattern arrays
// because it doesn't get generated until after we're done
const static int ModCount = NUM_CalcPatternMod;

/* The difficulties of each hand tend to be independent from one another. This
is not absolute, as in the case of polyrhythm trilling. However the goal of the
Expand Down Expand Up @@ -81,8 +84,7 @@ class Hand

std::vector<float> doot[ModCount];
std::vector<int> v_itvpoints; // Point allotment for each interval
std::vector<float> v_itvNPSdiff,
v_itvMSdiff, pureMSdiff; // Calculated difficulty for each interval
std::vector<float> soap[NUM_CalcDiffValue]; // Calculated difficulty for each interval

// pattern adjusted difficulty, allocate only once
std::vector<float> adj_diff;
Expand Down
18 changes: 18 additions & 0 deletions src/Etterna/Models/Misc/GameConstantsAndTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ StringToSkillset(const RString& s)
return Skill_Overall;
}

static const char* CalcPatternModNames[] = {
"OHJump", "Anchor", "Roll", "HS", "Jump", "CJ",
};
XToString(CalcPatternMod);
LuaXType(CalcPatternMod);

static const char* CalcDebugMiscNames[] = {
"PtLoss", "StamMod",
};
XToString(CalcDebugMisc);
LuaXType(CalcDebugMisc);

static const char* CalcDiffValueNames[] = {
"BaseNPS", "BaseMS", "BaseMSD", "MSD",
};
XToString(CalcDiffValue);
LuaXType(CalcDiffValue);

static const char* ValidationKeyNames[] = {
"Brittle",
"Weak",
Expand Down
8 changes: 8 additions & 0 deletions src/Etterna/Models/Misc/GameConstantsAndTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define GAME_CONSTANTS_AND_TYPES_H

#include "EnumHelper.h"
#include "Etterna/Models/NoteData/NoteDataStructures.h"
#include <cfloat> // need the max for default.

// Note definitions
Expand Down Expand Up @@ -44,6 +45,13 @@ enum Skillset
const RString&
SkillsetToString(Skillset ss);

const RString&
CalcPatternModToString(CalcPatternMod);
const RString&
CalcDebugMiscToString(CalcDebugMisc);
const RString&
CalcDiffValueToString(CalcDiffValue);

enum NSScoreBoardColumn
{
NSSB_NAMES = 0,
Expand Down
34 changes: 23 additions & 11 deletions src/Etterna/Models/NoteData/NoteDataStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,35 @@ struct DifficultyRating
float technical;
};

// we do actually want to register these with lua i guess
enum CalcPatternMod
{
OHJump, // pattern mod (values between 0-1)
Anchor, // pattern mod (values between 0.9 - ~ 1.1)
Roll, // pattern mod (values between 0-1)
HS, // pattern mod (values between 0-1)
Jump, // pattern mod (values between 0-1)
CJ, // pattern mod (values between 0-1)
NUM_CalcPatternMod,
CalcPatternMod_Invalid,
};

enum CalcDebugMisc
{
PtLoss, // expected points loss (not really a diff thing but w.e)
StamMod,// stam adjust (values between 1- ~1.15)
NUM_CalcDebugMisc,
CalcDebugMisc_Invalid,
};

enum CalcDebugValue
enum CalcDiffValue
{
OHJump, // pattern mod (% values between 0-1)
Anchor, // pattern mod (% values between 0-1)
Roll, // pattern mod (% values between 0-1)
HS, // pattern mod (% values between 0-1)
Jump, // pattern mod (% values between 0-1)
CJ,
BaseNPS, // unadjusted base nps difficulty
BaseMS, // unadjusted base ms difficulty
BaseMSD, // unadjusted weighted values
MSD, // pattern and stam adjusted difficulty values
PtLoss, // expected points lost
StamMod, // stam adjustment value (% values between 1-ciel)
DebugCount,
None
NUM_CalcDiffValue,
CalcDiffValue_Invalid,
};

#endif
Loading

0 comments on commit e2fae36

Please sign in to comment.