Clean up math functions
- Remove checking for standard functions from the build system - Prefix all invocations with std:: - Replace suffixed functions with unprefixed versions - Include <cmath> in all files that use it and remove the global include e.g. floorf(x) -> std::floor(x)
This commit is contained in:
+20
-19
@@ -3,7 +3,6 @@
|
||||
#include "RageLog.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "LuaManager.h"
|
||||
#include <float.h>
|
||||
#include "GameState.h"
|
||||
#include "Course.h"
|
||||
#include "Steps.h"
|
||||
@@ -11,6 +10,8 @@
|
||||
#include "PrefsManager.h"
|
||||
#include "CommonMetrics.h"
|
||||
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
#define GRADE_PERCENT_TIER(i) THEME->GetMetricF("PlayerStageStats",ssprintf("GradePercent%s",GradeToString((Grade)i).c_str()))
|
||||
@@ -151,7 +152,7 @@ void PlayerStageStats::AddStats( const PlayerStageStats& other )
|
||||
Combo_t &combo = m_ComboList[i];
|
||||
const float PrevComboEnd = prevcombo.m_fStartSecond + prevcombo.m_fSizeSeconds;
|
||||
const float ThisComboStart = combo.m_fStartSecond;
|
||||
if( fabsf(PrevComboEnd - ThisComboStart) > 0.001 )
|
||||
if( std::abs(PrevComboEnd - ThisComboStart) > 0.001 )
|
||||
continue;
|
||||
|
||||
// These are really the same combo.
|
||||
@@ -261,7 +262,7 @@ float PlayerStageStats::MakePercentScore( int iActual, int iPossible )
|
||||
|
||||
// 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 );
|
||||
float fTruncInterval = std::pow( 0.1f, (float)iPercentTotalDigits-1 );
|
||||
|
||||
// TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost
|
||||
// to fPercentDancePoints to correct for this.
|
||||
@@ -275,7 +276,7 @@ RString PlayerStageStats::FormatPercentScore( float fPercentDancePoints )
|
||||
{
|
||||
int iPercentTotalDigits = 3 + CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES; // "100" + "." + "00"
|
||||
|
||||
RString s = ssprintf( "%*.*f%%", iPercentTotalDigits,
|
||||
RString s = ssprintf( "%*.*f%%", iPercentTotalDigits,
|
||||
(int)CommonMetrics::PERCENT_SCORE_DECIMAL_PLACES,
|
||||
fPercentDancePoints*100 );
|
||||
return s;
|
||||
@@ -338,7 +339,7 @@ int PlayerStageStats::GetLessonScoreNeeded() const
|
||||
{
|
||||
float fScore = std::accumulate(m_vpPossibleSteps.begin(), m_vpPossibleSteps.end(), 0.f,
|
||||
[](float total, Steps const *steps) { return total + steps->GetRadarValues(PLAYER_1)[RadarCategory_TapsAndHolds]; });
|
||||
return lrintf( fScore * LESSON_PASS_THRESHOLD );
|
||||
return std::lrint( fScore * LESSON_PASS_THRESHOLD );
|
||||
}
|
||||
|
||||
void PlayerStageStats::ResetScoreForLesson()
|
||||
@@ -398,8 +399,8 @@ void PlayerStageStats::SetLifeRecordAt( float fLife, float fStepsSecond )
|
||||
|
||||
// Memory optimization:
|
||||
// If we have three consecutive records A, B, and C all with the same fLife,
|
||||
// we can eliminate record B without losing data. Only check the last three
|
||||
// records in the map since we're only inserting at the end, and we know all
|
||||
// we can eliminate record B without losing data. Only check the last three
|
||||
// records in the map since we're only inserting at the end, and we know all
|
||||
// earlier redundant records have already been removed.
|
||||
std::map<float, float>::iterator C = m_fLifeRecord.end();
|
||||
--C;
|
||||
@@ -471,7 +472,7 @@ float PlayerStageStats::GetCurrentLife() const
|
||||
if( m_fLifeRecord.empty() )
|
||||
return 0;
|
||||
std::map<float, float>::const_iterator iter = m_fLifeRecord.end();
|
||||
--iter;
|
||||
--iter;
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
@@ -557,7 +558,7 @@ bool PlayerStageStats::FullComboOfScore( TapNoteScore tnsAllGreaterOrEqual ) con
|
||||
{
|
||||
ASSERT( tnsAllGreaterOrEqual >= TNS_W5 );
|
||||
ASSERT( tnsAllGreaterOrEqual <= TNS_W1 );
|
||||
|
||||
|
||||
//if we've set MissCombo to anything besides 0, it's not a full combo
|
||||
if( !m_bPlayerCanAchieveFullCombo )
|
||||
return false;
|
||||
@@ -724,7 +725,7 @@ LuaFunction( FormatPercentScore, PlayerStageStats::FormatPercentScore( FArg(1) )
|
||||
// lua start
|
||||
#include "LuaBinding.h"
|
||||
|
||||
/** @brief Allow Lua to have access to the PlayerStageStats. */
|
||||
/** @brief Allow Lua to have access to the PlayerStageStats. */
|
||||
class LunaPlayerStageStats: public Luna<PlayerStageStats>
|
||||
{
|
||||
public:
|
||||
@@ -843,13 +844,13 @@ public:
|
||||
|
||||
static int GetRadarPossible( T* p, lua_State *L ) { p->m_radarPossible.PushSelf(L); return 1; }
|
||||
static int GetRadarActual( T* p, lua_State *L ) { p->m_radarActual.PushSelf(L); return 1; }
|
||||
static int SetScore( T* p, lua_State *L )
|
||||
{
|
||||
static int SetScore( T* p, lua_State *L )
|
||||
{
|
||||
if( IArg(1) >= 0 )
|
||||
{
|
||||
p->m_iScore = IArg(1);
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
p->m_iScore = IArg(1);
|
||||
return 1;
|
||||
}
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
static int SetCurMaxScore( T* p, lua_State *L )
|
||||
@@ -880,7 +881,7 @@ public:
|
||||
}
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
|
||||
|
||||
static int FailPlayer( T* p, lua_State *L )
|
||||
{
|
||||
p->m_bFailed = true;
|
||||
@@ -943,7 +944,7 @@ LUA_REGISTER_CLASS( PlayerStageStats )
|
||||
/*
|
||||
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@@ -953,7 +954,7 @@ LUA_REGISTER_CLASS( PlayerStageStats )
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
|
||||
Reference in New Issue
Block a user