Skip to content

Commit

Permalink
remove unusedfunctions from rageutil (and getsongpopularityrank)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jul 2, 2020
1 parent 50e8fa3 commit 370eaa4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 163 deletions.
25 changes: 0 additions & 25 deletions src/Etterna/Singletons/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,13 +1584,6 @@ SongManager::GetNumStepsLoadedFromProfile()
return iCount;
}

int
SongManager::GetSongRank(Song* pSong)
{
const int index =
FindIndex(m_pPopularSongs.begin(), m_pPopularSongs.end(), pSong);
return index; // -1 means we didn't find it
}
void
makePlaylist(const RString& answer)
{
Expand Down Expand Up @@ -1820,23 +1813,6 @@ class LunaSongManager : public Luna<SongManager>
DEFINE_METHOD(GetSongColor, GetSongColor(Luna<Song>::check(L, 1)))
DEFINE_METHOD(GetSongGroupColor, GetSongGroupColor(SArg(1)))

static int GetSongRank(T* p, lua_State* L)
{
Song* pSong = Luna<Song>::check(L, 1);
int index = p->GetSongRank(pSong);
if (index != -1)
lua_pushnumber(L, index + 1);
else
lua_pushnil(L);
return 1;
}
/*
static int GetSongRankFromProfile( T* p, lua_State *L )
{
// it's like the above but also takes in a ProfileSlot as well.
}
*/

static int GetSongGroupNames(T* p, lua_State* L)
{
vector<RString> v;
Expand Down Expand Up @@ -1955,7 +1931,6 @@ class LunaSongManager : public Luna<SongManager>
ADD_METHOD(GetExtraStageInfo);
ADD_METHOD(GetSongColor);
ADD_METHOD(GetSongGroupColor);
ADD_METHOD(GetSongRank);
ADD_METHOD(GetSongGroupNames);
ADD_METHOD(GetSongsInGroup);
ADD_METHOD(ShortenGroupName);
Expand Down
1 change: 0 additions & 1 deletion src/Etterna/Singletons/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class SongManager
{
return m_sSongGroupNames[index];
}
int GetSongRank(Song* pSong);

void GetStepsLoadedFromProfile(vector<Steps*>& AddTo,
ProfileSlot slot) const;
Expand Down
99 changes: 2 additions & 97 deletions src/RageUtil/Utils/RageUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,6 @@ BinaryToHex(const RString& sString)
return BinaryToHex(sString.data(), sString.size());
}

bool
HexToBinary(const RString& s, unsigned char* stringOut)
{
if (!IsHexVal(s))
return false;

for (int i = 0; true; i++) {
if ((int)s.size() <= i * 2)
break;
RString sByte = s.substr(i * 2, 2);

uint8_t val = 0;
if (sscanf(sByte, "%hhx", &val) != 1)
return false;
stringOut[i] = val;
}
return true;
}

bool
HexToBinary(const RString& s, RString& sOut)
{
sOut.resize(s.size() / 2);
return HexToBinary(s, (unsigned char*)sOut.data());
}

float
HHMMSSToSeconds(const RString& sHHMMSS)
{
Expand Down Expand Up @@ -300,13 +274,6 @@ PrettyPercent(float fNumerator, float fDenominator)
return ssprintf("%0.2f%%", fNumerator / fDenominator * 100);
}

RString
Commify(int iNum)
{
RString sNum = ssprintf("%d", iNum);
return Commify(sNum);
}

RString
Commify(const RString& num, const RString& sep, const RString& dot)
{
Expand Down Expand Up @@ -929,20 +896,6 @@ split(const wstring& sSource,
do_split(sSource, sDelimitor, asAddIt, bIgnoreEmpty);
}

/* Use:
RString str="a,b,c";
int start = 0, size = -1;
for(;;)
{
do_split( str, ",", start, size );
if( start == str.size() )
break;
str[start] = 'Q';
}
*/

template<class S>
void
do_split(const S& Source,
Expand Down Expand Up @@ -974,7 +927,7 @@ do_split(const S& Source,
pos = Source.find(Delimitor[0], begin);
else
pos = Source.find(Delimitor, begin);
if (pos == Source.npos || (int)pos > len)
if (pos == Source.npos || static_cast<int>(pos) > len)
pos = len;
size = pos - begin;
}
Expand Down Expand Up @@ -1328,54 +1281,6 @@ calc_stddev(const float* pStart, const float* pEnd, bool bSample)
return fDev;
}

bool
CalcLeastSquares(const vector<pair<float, float>>& vCoordinates,
float& fSlope,
float& fIntercept,
float& fError)
{
if (vCoordinates.empty())
return false;
float fSumXX = 0.0f, fSumXY = 0.0f, fSumX = 0.0f, fSumY = 0.0f;
for (unsigned i = 0; i < vCoordinates.size(); ++i) {
fSumXX += vCoordinates[i].first * vCoordinates[i].first;
fSumXY += vCoordinates[i].first * vCoordinates[i].second;
fSumX += vCoordinates[i].first;
fSumY += vCoordinates[i].second;
}
const float fDenominator = vCoordinates.size() * fSumXX - fSumX * fSumX;
fSlope = (vCoordinates.size() * fSumXY - fSumX * fSumY) / fDenominator;
fIntercept = (fSumXX * fSumY - fSumX * fSumXY) / fDenominator;

fError = 0.0f;
for (unsigned i = 0; i < vCoordinates.size(); ++i) {
const float fOneError =
fIntercept + fSlope * vCoordinates[i].first - vCoordinates[i].second;
fError += fOneError * fOneError;
}
fError /= vCoordinates.size();
fError = sqrtf(fError);
return true;
}

void
FilterHighErrorPoints(vector<pair<float, float>>& vCoordinates,
float fSlope,
float fIntercept,
float fCutoff)
{
unsigned int iOut = 0;
for (unsigned int iIn = 0; iIn < vCoordinates.size(); ++iIn) {
const float fError = fIntercept + fSlope * vCoordinates[iIn].first -
vCoordinates[iIn].second;
if (fabsf(fError) < fCutoff) {
vCoordinates[iOut] = vCoordinates[iIn];
++iOut;
}
}
vCoordinates.resize(iOut);
}

void
TrimLeft(RString& sStr, const char* s)
{
Expand Down Expand Up @@ -2824,7 +2729,7 @@ LuaFunction(Lowercase, MakeLower(SArg(1))) static RString MakeUpper(RString s)
return s;
}
LuaFunction(Uppercase, MakeUpper(SArg(1)))
LuaFunction(mbstrlen, (int)RStringToWstring(SArg(1)).length())
LuaFunction(mbstrlen, static_cast<int>(RStringToWstring(SArg(1)).length()))
LuaFunction(URLEncode, URLEncode(SArg(1)));
LuaFunction(PrettyPercent, PrettyPercent(FArg(1), FArg(2)));
// LuaFunction( IsHexVal, IsHexVal( SArg(1) ) );
Expand Down
40 changes: 0 additions & 40 deletions src/RageUtil/Utils/RageUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ RString
BinaryToHex(const void* pData_, int iNumBytes);
RString
BinaryToHex(const RString& sString);
bool
HexToBinary(const RString& s, unsigned char* stringOut);
bool
HexToBinary(const RString& s, RString* sOut);
float
HHMMSSToSeconds(const RString& sHMS);
RString
Expand Down Expand Up @@ -694,8 +690,6 @@ void
GetLanguageInfos(vector<const LanguageInfo*>& vAddTo);
const LanguageInfo*
GetLanguageInfo(const RString& sIsoCode);
RString
GetLanguageNameFromISO639Code(const RString& sName);

// Splits a RString into an vector<RString> according the Delimitor.
void
Expand Down Expand Up @@ -809,8 +803,6 @@ DirectoryIsEmpty(const RString& sPath);

bool
CompareRStringsAsc(const RString& sStr1, const RString& sStr2);
bool
CompareRStringsDesc(const RString& sStr1, const RString& sStr2);
void
SortRStringArray(vector<RString>& asAddTo, const bool bSortAscending = true);

Expand All @@ -825,38 +817,6 @@ calc_mean(const float* pStart, const float* pEnd);
float
calc_stddev(const float* pStart, const float* pEnd, bool bSample = false);

/*
* Find the slope, intercept, and error of a linear least squares regression
* of the points given. Error is returned as the sqrt of the average squared
* Y distance from the chosen line.
* Returns true on success, false on failure.
*/
bool
CalcLeastSquares(const vector<pair<float, float>>& vCoordinates,
float& fSlope,
float& fIntercept,
float& fError);

/*
* This method throws away any points that are more than fCutoff away from
* the line defined by fSlope and fIntercept.
*/
void
FilterHighErrorPoints(vector<pair<float, float>>& vCoordinates,
float fSlope,
float fIntercept,
float fCutoff);

template<class T1, class T2>
int
FindIndex(T1 begin, T1 end, const T2* p)
{
T1 iter = find(begin, end, p);
if (iter == end)
return -1;
return iter - begin;
}

/* Useful for objects with no operator-, eg. map::iterator (more convenient than
* advance). */
template<class T>
Expand Down

0 comments on commit 370eaa4

Please sign in to comment.