Skip to content

Commit

Permalink
add MIN_MUSIC_RATE and MAX_MUSIC_RATE global consts
Browse files Browse the repository at this point in the history
also accessible by lua so it can be controlled in one place
  • Loading branch information
poco0317 committed Aug 25, 2023
1 parent 915094c commit 382e31f
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Themes/Rebirth/BGAnimations/chordDensityGraph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end
local function updateGraphMultiVertex(parent, self, steps)
if steps then
local ncol = steps:GetNumColumns()
local rate = math.max(0.05, getCurRateValue())
local rate = math.max(MIN_MUSIC_RATE, getCurRateValue())
local graphVectors = steps:GetCDGraphVectors(rate)
local txt = parent:GetChild("NPSText")
if graphVectors == nil then
Expand Down
2 changes: 1 addition & 1 deletion Themes/Rebirth/Scripts/98 util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ end
function setMusicRate(rate)
-- the classic clamps are 0.7 and 3
-- the game wont allow 0 and wont allow over 3
rate = clamp(rate, 0.05, 3)
rate = clamp(rate, MIN_MUSIC_RATE, MAX_MUSIC_RATE)
GAMESTATE:GetSongOptionsObject("ModsLevel_Preferred"):MusicRate(rate)
GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(rate)
GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate(rate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,23 @@ local ret = Def.ActorFrame {
CodeMessageCommand = function(self, params) -- this is intentionally bad to remind me to fix other things that are bad -mina
if ((getTabIndex() == 2 and nestedTab == 2) and not collapsed) and DLMAN:GetCurrentRateFilter() then
local rate = getCurRateValue()
if params.Name == "PrevScore" and rate < 2.95 then
if params.Name == "PrevScore" and rate < MAX_MUSIC_RATE - 0.05 then
GAMESTATE:GetSongOptionsObject("ModsLevel_Preferred"):MusicRate(rate + 0.1)
GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(rate + 0.1)
GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate(rate + 0.1)
MESSAGEMAN:Broadcast("CurrentRateChanged")
elseif params.Name == "NextScore" and rate > 0.75 then
elseif params.Name == "NextScore" and rate > MIN_MUSIC_RATE + 0.05 then
GAMESTATE:GetSongOptionsObject("ModsLevel_Preferred"):MusicRate(rate - 0.1)
GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(rate - 0.1)
GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate(rate - 0.1)
MESSAGEMAN:Broadcast("CurrentRateChanged")
end
if params.Name == "PrevRate" and rate < 3 then
if params.Name == "PrevRate" and rate < MAX_MUSIC_RATE then
GAMESTATE:GetSongOptionsObject("ModsLevel_Preferred"):MusicRate(rate + 0.05)
GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(rate + 0.05)
GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate(rate + 0.05)
MESSAGEMAN:Broadcast("CurrentRateChanged")
elseif params.Name == "NextRate" and rate > 0.7 then
elseif params.Name == "NextRate" and rate > MIN_MUSIC_RATE then
GAMESTATE:GetSongOptionsObject("ModsLevel_Preferred"):MusicRate(rate - 0.05)
GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(rate - 0.05)
GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate(rate - 0.05)
Expand Down
2 changes: 1 addition & 1 deletion Themes/Til Death/BGAnimations/_chorddensitygraph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function updateGraphMultiVertex(parent, realgraph)
local steps = GAMESTATE:GetCurrentSteps()
if steps then
local ncol = steps:GetNumColumns()
local rate = math.max(0.05, getCurRateValue())
local rate = math.max(MIN_MUSIC_RATE, getCurRateValue())
local graphVectors = steps:GetCDGraphVectors(rate)
if graphVectors == nil then
-- reset everything if theres nothing to show
Expand Down
4 changes: 2 additions & 2 deletions Themes/_fallback/Scripts/02 ThemePrefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ end
function RateList()
local ratelist = {}
do
local startrate = 0.05
local upperrate = 3.00
local startrate = MIN_MUSIC_RATE -- 0.05
local upperrate = MAX_MUSIC_RATE -- 3.0
local increment = 0.05
while startrate <= upperrate do
ratelist[#ratelist+1] = tostring(startrate) .. "x"
Expand Down
4 changes: 2 additions & 2 deletions Themes/_fallback/Scripts/10 WifeSundries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ function GetPlayableTime()
end

function ChangeMusicRate(rate, params)
local min = 0.05 -- going below this is not a good idea (0 crashes)
local max = 3 -- going over this tends to crash or whatever
local min = MIN_MUSIC_RATE -- going below this is not a good idea (0 crashes)
local max = MAX_MUSIC_RATE -- going over this tends to crash or whatever
local old = getCurRateValue()
local new = getCurRateValue()
local largeincrement = 0.1
Expand Down
3 changes: 3 additions & 0 deletions src/Etterna/Models/Misc/GameConstantsAndTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const float HOLD_DROP_SEC = 0.250F;
// how long between each subsequent tap on a roll before death
const float ROLL_DROP_SEC = 0.500F;

const float MIN_MUSIC_RATE = 0.05F;
const float MAX_MUSIC_RATE = 3.F;

enum GameplayMode
{
GameplayMode_Normal,
Expand Down
2 changes: 1 addition & 1 deletion src/Etterna/Models/Misc/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ class LunaScoreGoal : public Luna<ScoreGoal>
{
if (!p->achieved) {
auto newrate = FArg(1);
CLAMP(newrate, 0.7f, 3.0f);
CLAMP(newrate, MIN_MUSIC_RATE, MAX_MUSIC_RATE);
p->rate = newrate;
p->CheckVacuity();
p->UploadIfNotVacuous();
Expand Down
15 changes: 9 additions & 6 deletions src/Etterna/Models/StepsAndStyles/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ Steps::GetMSD(float rate, Skillset ss) const -> float
}

auto
Steps::SortSkillsetsAtRate(float x, bool includeoverall)
Steps::SortSkillsetsAtRate(float rate, bool includeoverall)
-> std::vector<std::pair<Skillset, float>>
{
const auto idx = static_cast<int>(x * 10) - 7;
// for safety
CLAMP(rate, .7F, 2.F);

const auto idx = static_cast<int>(rate * 10) - 7;
auto tmp = diffByRate[idx];
std::vector<std::pair<Skillset, float>> mort;
FOREACH_ENUM(Skillset, ss)
Expand Down Expand Up @@ -942,7 +945,7 @@ class LunaSteps : public Luna<Steps>

static auto GetSSRs(T* p, lua_State* L) -> int
{
const auto rate = std::clamp(FArg(1), 0.7F, 3.F);
const auto rate = std::clamp(FArg(1), MIN_MUSIC_RATE, MAX_MUSIC_RATE);
const auto goal = FArg(2);
auto nd = p->GetNoteData();
const auto loot = nd.BuildAndGetNerv(p->GetTimingData());
Expand All @@ -967,7 +970,7 @@ class LunaSteps : public Luna<Steps>
}
static auto GetRelevantSkillsetsByMSDRank(T* p, lua_State* L) -> int
{
const auto rate = std::clamp(FArg(1), 0.7F, 2.F);
const auto rate = FArg(1);
const auto rank = IArg(2) - 1; // indexing
auto sortedskillsets = p->SortSkillsetsAtRate(rate, false);
const auto relevance_cutoff = 0.9F;
Expand Down Expand Up @@ -1020,7 +1023,7 @@ class LunaSteps : public Luna<Steps>
}
static auto GetCDGraphVectors(T* p, lua_State* L) -> int
{
const auto rate = std::clamp(FArg(1), 0.05F, 3.F);
const auto rate = std::clamp(FArg(1), MIN_MUSIC_RATE, MAX_MUSIC_RATE);
auto nd = p->GetNoteData();
if (nd.IsEmpty()) {
return 0;
Expand Down Expand Up @@ -1284,7 +1287,7 @@ class LunaSteps : public Luna<Steps>
}
static auto GetNPSPerMeasure(T* p, lua_State* L) -> int
{
const auto rate = std::clamp(FArg(1), 0.7F, 3.F);
const auto rate = std::clamp(FArg(1), MIN_MUSIC_RATE, MAX_MUSIC_RATE);

auto nd = p->GetNoteData();
if (nd.IsEmpty()) {
Expand Down
8 changes: 4 additions & 4 deletions src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ ScreenGameplayPractice::AddToRate(float amountAdded) -> float

// Rates outside of this range may crash
// (weird comparisons because floats)
if (0.05F - newRate > 0.001F)
return 0.05F;
if (newRate - 3.F > 0.001F)
return 3.F;
if (MIN_MUSIC_RATE - newRate > 0.001F)
return MIN_MUSIC_RATE;
if (newRate - MAX_MUSIC_RATE > 0.001F)
return MAX_MUSIC_RATE;

RageTimer tm;
const auto fSeconds = m_pSoundMusic->GetPositionSeconds(nullptr, &tm);
Expand Down
8 changes: 4 additions & 4 deletions src/Etterna/Screen/Gameplay/ScreenGameplayReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ ScreenGameplayReplay::SetRate(const float newRate) -> float

// Rates outside of this range may crash
// (weird comparisons because floats)
if (0.05F - newRate > 0.001F)
return 0.05F;
if (newRate - 3.F > 0.001F)
return 3.F;
if (MIN_MUSIC_RATE - newRate > 0.001F)
return MIN_MUSIC_RATE;
if (newRate - MAX_MUSIC_RATE > 0.001F)
return MAX_MUSIC_RATE;

const auto paused = GAMESTATE->GetPaused();

Expand Down
4 changes: 2 additions & 2 deletions src/Etterna/Singletons/FilterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class LunaFilterManager : public Luna<FilterManager>
static int SetMaxFilterRate(T* p, lua_State* L)
{
float mfr = FArg(1);
CLAMP(mfr, p->MinFilterRate, 3.f);
CLAMP(mfr, p->MinFilterRate, MAX_MUSIC_RATE);
p->MaxFilterRate = mfr;
return 0;
}
Expand All @@ -157,7 +157,7 @@ class LunaFilterManager : public Luna<FilterManager>
static int SetMinFilterRate(T* p, lua_State* L)
{
float mfr = FArg(1);
CLAMP(mfr, 0.05f, p->MaxFilterRate);
CLAMP(mfr, MIN_MUSIC_RATE, p->MaxFilterRate);
p->MinFilterRate = mfr;
return 0;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Etterna/Singletons/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ GameState::GameState()
lua_pushstring(L, "GAMESTATE");
this->PushSelf(L);
lua_settable(L, LUA_GLOBALSINDEX);
LUA->Release(L);
LUA->Release(L);

LUA->SetGlobal("MIN_MUSIC_RATE", MIN_MUSIC_RATE);
LUA->SetGlobal("MAX_MUSIC_RATE", MAX_MUSIC_RATE);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Etterna/Singletons/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,7 @@ ScoreManager::GetPlaycountPerSkillset(const string& profileID)
if (c == nullptr)
continue;

auto ss = c->SortSkillsetsAtRate(
std::clamp(s->GetMusicRate(), 0.7F, 2.F), false);
auto ss = c->SortSkillsetsAtRate(s->GetMusicRate(), false);
counts[ss[0].first]++;
}
return counts;
Expand Down
2 changes: 1 addition & 1 deletion src/Etterna/Singletons/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ class LunaChart : public Luna<Chart>
static auto ChangeRate(T* p, lua_State* L) -> int
{
p->rate += FArg(1);
p->rate = std::clamp(p->rate, 0.7F, 3.F);
p->rate = std::clamp(p->rate, MIN_MUSIC_RATE, MAX_MUSIC_RATE);
return 1;
}

Expand Down

0 comments on commit 382e31f

Please sign in to comment.