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:
@@ -23,7 +23,7 @@ ThemeMetricDifficultiesToShow CommonMetrics::DIFFICULTIES_TO_SHOW ("Common","D
|
||||
ThemeMetricCourseDifficultiesToShow CommonMetrics::COURSE_DIFFICULTIES_TO_SHOW ("Common","CourseDifficultiesToShow");
|
||||
ThemeMetricStepsTypesToShow CommonMetrics::STEPS_TYPES_TO_SHOW ("Common","StepsTypesToHide"); // This metric takes a list of StepsTypes to hide and returns a list of StepsTypes to show
|
||||
ThemeMetric<bool> CommonMetrics::AUTO_SET_STYLE ("Common","AutoSetStyle");
|
||||
|
||||
ThemeMetric<int> CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES ("Common","PercentScoreDecimalPlaces");
|
||||
|
||||
ThemeMetricDifficultiesToShow::ThemeMetricDifficultiesToShow( const RString& sGroup, const RString& sName ) :
|
||||
ThemeMetric<RString>(sGroup,sName)
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace CommonMetrics
|
||||
extern ThemeMetricCourseDifficultiesToShow COURSE_DIFFICULTIES_TO_SHOW;
|
||||
extern ThemeMetricStepsTypesToShow STEPS_TYPES_TO_SHOW;
|
||||
extern ThemeMetric<bool> AUTO_SET_STYLE;
|
||||
extern ThemeMetric<int> PERCENT_SCORE_DECIMAL_PLACES;
|
||||
|
||||
RString LocalizeOptionItem( const RString &s, bool bOptional );
|
||||
};
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "Style.h"
|
||||
#include "ActorUtil.h"
|
||||
#include "Foreach.h"
|
||||
#include "PercentageDisplay.h"
|
||||
#include "LuaManager.h"
|
||||
#include "XmlFile.h"
|
||||
#include "PlayerStageStats.h"
|
||||
|
||||
#define SHIFT_X(p) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iX", p+1))
|
||||
#define SHIFT_Y(p) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iY", p+1))
|
||||
@@ -169,7 +169,7 @@ void PaneDisplay::SetContent( PaneContents c )
|
||||
if( bIsPlayerEdit )
|
||||
str = NOT_AVAILABLE;
|
||||
else
|
||||
str = PercentageDisplay::FormatPercentScore( val );
|
||||
str = PlayerStageStats::FormatPercentScore( val );
|
||||
break;
|
||||
case SONG_NUM_STEPS:
|
||||
case SONG_JUMPS:
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ public:
|
||||
virtual void LoadFromNode( const XNode* pNode );
|
||||
virtual PercentageDisplay *Copy() const;
|
||||
|
||||
static RString FormatPercentScore( float fPercentDancePoints );
|
||||
|
||||
//
|
||||
// Lua
|
||||
//
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Steps.h"
|
||||
#include "ScoreKeeperNormal.h"
|
||||
#include "PrefsManager.h"
|
||||
#include "CommonMetrics.h"
|
||||
|
||||
#define GRADE_PERCENT_TIER(i) THEME->GetMetricF("PlayerStageStats",ssprintf("GradePercent%s",GradeToString((Grade)i).c_str()))
|
||||
#define GRADE_TIER02_IS_ALL_W2S THEME->GetMetricB("PlayerStageStats","GradeTier02IsAllW2s")
|
||||
@@ -228,20 +229,47 @@ Grade PlayerStageStats::GetGrade() const
|
||||
return grade;
|
||||
}
|
||||
|
||||
float PlayerStageStats::GetPercentDancePoints() const
|
||||
float PlayerStageStats::MakePercentScore( int iActual, int iPossible )
|
||||
{
|
||||
if( m_iPossibleDancePoints == 0 )
|
||||
if( iPossible == 0 )
|
||||
return 0; // div/0
|
||||
|
||||
if( m_iActualDancePoints == m_iPossibleDancePoints )
|
||||
if( iActual == iPossible )
|
||||
return 1; // correct for rounding error
|
||||
|
||||
/* This can happen in battle, with transform attacks. */
|
||||
//ASSERT_M( iActualDancePoints <= iPossibleDancePoints, ssprintf("%i/%i", iActualDancePoints, iPossibleDancePoints) );
|
||||
//ASSERT_M( iActual <= iPossible, ssprintf("%i/%i", iActual, iPossible) );
|
||||
|
||||
float fPercentDancePoints = m_iActualDancePoints / (float)m_iPossibleDancePoints;
|
||||
float fPercent = iActual / (float)iPossible;
|
||||
|
||||
// don't allow negative
|
||||
fPercent = max( 0, fPercent );
|
||||
|
||||
int iPercentTotalDigits = 3 + CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES; // "100" + "." + "00"
|
||||
|
||||
// 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)iPercentTotalDigits-1 );
|
||||
|
||||
return fPercentDancePoints;
|
||||
// TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to
|
||||
// fPercentDancePoints to correct for this.
|
||||
fPercent += 0.000001f;
|
||||
|
||||
fPercent = ftruncf( fPercent, fTruncInterval );
|
||||
return fPercent;
|
||||
}
|
||||
|
||||
RString PlayerStageStats::FormatPercentScore( float fPercentDancePoints )
|
||||
{
|
||||
int iPercentTotalDigits = 3 + CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES; // "100" + "." + "00"
|
||||
|
||||
RString s = ssprintf( "%*.*f%%", iPercentTotalDigits, (int)CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES, fPercentDancePoints*100 );
|
||||
return s;
|
||||
}
|
||||
|
||||
float PlayerStageStats::GetPercentDancePoints() const
|
||||
{
|
||||
return MakePercentScore( m_iActualDancePoints, m_iPossibleDancePoints );
|
||||
}
|
||||
|
||||
float PlayerStageStats::GetCurMaxPercentDancePoints() const
|
||||
@@ -634,7 +662,7 @@ bool PlayerStageStats::IsDisqualified() const
|
||||
}
|
||||
|
||||
LuaFunction( GetGradeFromPercent, GetGradeFromPercent( FArg(1), false ) )
|
||||
|
||||
LuaFunction( FormatPercentScore, PlayerStageStats::FormatPercentScore( FArg(1) ) )
|
||||
|
||||
|
||||
// lua start
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
void AddStats( const PlayerStageStats& other ); // accumulate
|
||||
|
||||
Grade GetGrade() const;
|
||||
static float MakePercentScore( int iActual, int iPossible );
|
||||
static RString FormatPercentScore( float fPercentScore );
|
||||
float GetPercentDancePoints() const;
|
||||
float GetCurMaxPercentDancePoints() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user