Move percent formatting into PlayerStageStats and apply the truncating rules in GetPercentScore(). The percent score that ends up in HighScore should match what is shown on the screen.

This commit is contained in:
Chris Danford
2007-09-14 08:50:29 +00:00
parent 71cca3a067
commit 77940f76a2
7 changed files with 41 additions and 36 deletions
-24
View File
@@ -10,8 +10,6 @@
#include "PlayerState.h"
#include "XmlFile.h"
ThemeMetric<int> PERCENT_DECIMAL_PLACES ( "PercentageDisplay", "PercentDecimalPlaces" );
ThemeMetric<int> PERCENT_TOTAL_SIZE ( "PercentageDisplay", "PercentTotalSize" );
REGISTER_ACTOR_CLASS( PercentageDisplay )
@@ -189,28 +187,6 @@ void PercentageDisplay::Refresh()
m_textPercent.SetText( sNumToDisplay );
}
RString PercentageDisplay::FormatPercentScore( float fPercentDancePoints )
{
CLAMP( fPercentDancePoints, 0.f, 1.f );
// TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent
// score that's too high and doesn't match up with the calculated grade.
float fTruncInterval = powf( 0.1f, (float)PERCENT_TOTAL_SIZE-1 );
// TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to
// fPercentDancePoints to correct for this.
fPercentDancePoints += 0.000001f;
fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval );
RString s = ssprintf( "%*.*f%%", (int)PERCENT_TOTAL_SIZE, (int)PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 );
return s;
}
// lua start
#include "LuaManager.h"
LuaFunction( FormatPercentScore, PercentageDisplay::FormatPercentScore( FArg(1) ) )
#include "LuaBinding.h"