Improve precision in ArrowEffects

Floating point time is being stored as a float here, we can prevent precision loss by changing some of these to double during the lifetime of the function to get a more accurate result.
This commit is contained in:
sukibaby
2025-01-15 08:58:40 -08:00
committed by teejusb
parent 96ee25800a
commit 1fa31c64c6
+16 -10
View File
@@ -94,21 +94,27 @@ static float GetNoteFieldHeight()
float ArrowEffects::GetTime() float ArrowEffects::GetTime()
{ {
float mult = 1.f + curr_options->m_fModTimerMult; double mult = 1.0 + static_cast<double>(curr_options->m_fModTimerMult);
float offset = curr_options->m_fModTimerOffset; double offset = static_cast<double>(curr_options->m_fModTimerOffset);
ModTimerType modtimer = curr_options->m_ModTimerType; ModTimerType modtimer = curr_options->m_ModTimerType;
double returned_time = 0;
switch(modtimer) switch(modtimer)
{ {
case ModTimerType_Default: case ModTimerType_Default:
case ModTimerType_Game: case ModTimerType_Game:
return (RageTimer::GetTimeSinceStart()+offset)*mult; returned_time = (RageTimer::GetTimeSinceStart() + offset) * mult;
break;
case ModTimerType_Beat: case ModTimerType_Beat:
return (GAMESTATE->m_Position.m_fSongBeatVisible+offset)*mult; returned_time = (static_cast<double>(GAMESTATE->m_Position.m_fSongBeatVisible) + offset) * mult;
break;
case ModTimerType_Song: case ModTimerType_Song:
return (GAMESTATE->m_Position.m_fMusicSeconds+offset)*mult; returned_time = (static_cast<double>(GAMESTATE->m_Position.m_fMusicSeconds) + offset) * mult;
break;
default: default:
return RageTimer::GetTimeSinceStart()+offset; returned_time = RageTimer::GetTimeSinceStart() + offset;
break;
} }
return static_cast<float>(returned_time);
} }
namespace namespace
@@ -315,8 +321,8 @@ void ArrowEffects::Init(PlayerNumber pn)
void ArrowEffects::Update() void ArrowEffects::Update()
{ {
static float fLastTime = 0; static double fLastTime = 0.0;
float fTime = RageTimer::GetTimeSinceStart(); double fTime = RageTimer::GetTimeSinceStart();
FOREACH_EnabledPlayer( pn ) FOREACH_EnabledPlayer( pn )
{ {
@@ -337,9 +343,9 @@ void ArrowEffects::Update()
if( !position.m_bFreeze || !position.m_bDelay ) if( !position.m_bFreeze || !position.m_bDelay )
{ {
data.m_fExpandSeconds += fTime - fLastTime; data.m_fExpandSeconds += static_cast<float>(fTime - fLastTime);
data.m_fExpandSeconds = std::fmod( data.m_fExpandSeconds, (PI*2)/(accels[PlayerOptions::ACCEL_EXPAND_PERIOD]+1) ); data.m_fExpandSeconds = std::fmod( data.m_fExpandSeconds, (PI*2)/(accels[PlayerOptions::ACCEL_EXPAND_PERIOD]+1) );
data.m_fTanExpandSeconds += fTime - fLastTime; data.m_fTanExpandSeconds += static_cast<float>(fTime - fLastTime);
data.m_fTanExpandSeconds = std::fmod( data.m_fTanExpandSeconds, (PI*2)/(accels[PlayerOptions::ACCEL_TAN_EXPAND_PERIOD]+1) ); data.m_fTanExpandSeconds = std::fmod( data.m_fTanExpandSeconds, (PI*2)/(accels[PlayerOptions::ACCEL_TAN_EXPAND_PERIOD]+1) );
} }