fix rounding error in displaying percent score
This commit is contained in:
@@ -71,7 +71,11 @@ void PercentageDisplay::Refresh()
|
|||||||
m_Last = iActualDancePoints;
|
m_Last = iActualDancePoints;
|
||||||
|
|
||||||
CString sNumToDisplay;
|
CString sNumToDisplay;
|
||||||
if( !PREFSMAN->m_bDancePointsForOni )
|
if( PREFSMAN->m_bDancePointsForOni )
|
||||||
|
{
|
||||||
|
sNumToDisplay = ssprintf( "%*d", DANCE_POINT_DIGITS, max( 0, iActualDancePoints ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
float fPercentDancePoints = m_pSource->GetPercentDancePoints( m_PlayerNumber );
|
float fPercentDancePoints = m_pSource->GetPercentDancePoints( m_PlayerNumber );
|
||||||
|
|
||||||
@@ -87,15 +91,17 @@ void PercentageDisplay::Refresh()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float fNumToDisplay = fPercentDancePoints*100;
|
// TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent
|
||||||
sNumToDisplay = ssprintf( "%*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, fNumToDisplay );
|
// score that's too high and doesn't match up with the calculated grade.
|
||||||
|
float fTruncInterval = powf(0.1f,PERCENT_TOTAL_SIZE);
|
||||||
|
fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval );
|
||||||
|
|
||||||
|
sNumToDisplay = ssprintf( "%*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 );
|
||||||
|
|
||||||
// HACK: Use the last frame in the numbers texture as '-'
|
// HACK: Use the last frame in the numbers texture as '-'
|
||||||
sNumToDisplay.Replace('-','x');
|
sNumToDisplay.Replace('-','x');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
sNumToDisplay = ssprintf( "%*d", DANCE_POINT_DIGITS, max( 0, iActualDancePoints ) );
|
|
||||||
|
|
||||||
m_textPercent.SetText( sNumToDisplay );
|
m_textPercent.SetText( sNumToDisplay );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,11 +150,18 @@ inline float randomf( const float low=-1.0f, const float high=1.0f )
|
|||||||
return RandomFloat( low, high );
|
return RandomFloat( low, high );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return f rounded to the nearest multiple of fRoundInterval */
|
||||||
inline float froundf( const float f, const float fRoundInterval )
|
inline float froundf( const float f, const float fRoundInterval )
|
||||||
{
|
{
|
||||||
return int( (f + fRoundInterval/2)/fRoundInterval ) * fRoundInterval;
|
return int( (f + fRoundInterval/2)/fRoundInterval ) * fRoundInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return f truncated to the nearest multiple of fTruncInterval */
|
||||||
|
inline float ftruncf( const float f, const float fTruncInterval )
|
||||||
|
{
|
||||||
|
return int( (f)/fTruncInterval ) * fTruncInterval;
|
||||||
|
}
|
||||||
|
|
||||||
// Move val toward other_val by to_move.
|
// Move val toward other_val by to_move.
|
||||||
void fapproach( float& val, float other_val, float to_move );
|
void fapproach( float& val, float other_val, float to_move );
|
||||||
|
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ void ScreenEvaluation::Init()
|
|||||||
/* Use "ScreenEvaluation Percent" for the [metric set], but position and
|
/* Use "ScreenEvaluation Percent" for the [metric set], but position and
|
||||||
* tween it with "PercentP1X", etc. */
|
* tween it with "PercentP1X", etc. */
|
||||||
m_Percent[p].SetName( "ScreenEvaluation Percent" );
|
m_Percent[p].SetName( "ScreenEvaluation Percent" );
|
||||||
m_Percent[p].Load( (PlayerNumber) p, &g_CurStageStats, true );
|
m_Percent[p].Load( p, &g_CurStageStats, true );
|
||||||
m_Percent[p].SetXY( THEME->GetMetricF(m_sName, ssprintf("PercentP%dX",p+1)),
|
m_Percent[p].SetXY( THEME->GetMetricF(m_sName, ssprintf("PercentP%dX",p+1)),
|
||||||
THEME->GetMetricF(m_sName,ssprintf("PercentP%dY",p+1)) );
|
THEME->GetMetricF(m_sName,ssprintf("PercentP%dY",p+1)) );
|
||||||
m_Percent[p].Command( THEME->GetMetric(m_sName,ssprintf("PercentP%dOnCommand",p+1)) );
|
m_Percent[p].Command( THEME->GetMetric(m_sName,ssprintf("PercentP%dOnCommand",p+1)) );
|
||||||
|
|||||||
@@ -197,14 +197,13 @@ Grade StageStats::GetGrade( PlayerNumber pn ) const
|
|||||||
|
|
||||||
LOG->Trace( "GetGrade: Actual: %f, Possible: %f", Actual, Possible );
|
LOG->Trace( "GetGrade: Actual: %f, Possible: %f", Actual, Possible );
|
||||||
|
|
||||||
#define ROUNDING_ERROR 0.00001f
|
|
||||||
Grade grade = GRADE_FAILED;
|
Grade grade = GRADE_FAILED;
|
||||||
|
|
||||||
float fPercent = (Possible == 0) ? 0 : Actual / Possible;
|
float fPercent = (Possible == 0) ? 0 : Actual / Possible;
|
||||||
|
|
||||||
FOREACH_Grade(g)
|
FOREACH_Grade(g)
|
||||||
{
|
{
|
||||||
if( fPercent >= PREFSMAN->m_fGradePercent[g]-ROUNDING_ERROR )
|
if( fPercent >= PREFSMAN->m_fGradePercent[g] )
|
||||||
{
|
{
|
||||||
grade = g;
|
grade = g;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user