From 4a2c105c8c75c73f861032a63284fa21a37c8bc6 Mon Sep 17 00:00:00 2001 From: Mark Cannon Date: Thu, 23 Sep 2010 03:38:16 +0000 Subject: [PATCH] Remove FormatByteRateValue, fix some potential typing issues with FormatByteValue git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg/branches/dev@848 83fadc84-e282-4d84-a09a-c4228d6ae7e5 --- src/RageUtil.cpp | 49 ++++++++++++++++++------------------------------- src/RageUtil.h | 3 --- src/ScreenUserPacks.cpp | 12 ++++++++---- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index e05f97c0..738a0764 100755 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -212,57 +212,44 @@ CString FormatNumberAndSuffix( int i ) namespace { - /* declared as floats so the division isn't implicitly cast to int */ - float KILOBYTE = 1024; - float MEGABYTE = 1024*KILOBYTE; - float GIGABYTE = 1024*MEGABYTE; + /* declared as doubles so the division isn't implicitly cast to int */ + double KILOBYTE = 1024; + double MEGABYTE = 1024*KILOBYTE; + double GIGABYTE = 1024*MEGABYTE; } CString FormatByteValue( uint64_t iBytes ) { CString sSuffix; float fShownSpace = 0.0f; - if( iBytes > GIGABYTE ) + + /* this loses precision with large ints, but not enough to + * worry about it for now...just keep it in mind for later */ + + double fBytes = double(iBytes); + + if( fBytes > GIGABYTE ) { - fShownSpace = iBytes / GIGABYTE; + fShownSpace = fBytes / GIGABYTE; sSuffix = "GB"; } - else if( iBytes > MEGABYTE ) + else if( fBytes > MEGABYTE ) { - fShownSpace = iBytes / MEGABYTE; + fShownSpace = fBytes / MEGABYTE; sSuffix = "MB"; } - else if( iBytes > KILOBYTE ) + else if( fBytes > KILOBYTE ) { - fShownSpace = iBytes / KILOBYTE; + fShownSpace = fBytes / KILOBYTE; sSuffix = "KB"; } else { - fShownSpace = float(iBytes); + fShownSpace = fBytes; sSuffix = "bytes"; } - return ssprintf( "%.02f %s", fShownSpace, sSuffix.c_str() ); -} -CString FormatByteRateValue( float fRate ) -{ - CString sSuffix; - if( fRate > MEGABYTE ) - { - fRate /= MEGABYTE; - sSuffix = "MB/s"; - } - else if( fRate > KILOBYTE ) - { - fRate /= KILOBYTE; - sSuffix = "kb/s"; - } - else - { - sSuffix = "bytes/s"; - } - return ssprintf( "%.02f %s", fRate, sSuffix.c_str() ); + return ssprintf( "%.02f %s", fShownSpace, sSuffix.c_str() ); } struct tm GetLocalTime() diff --git a/src/RageUtil.h b/src/RageUtil.h index 6cf7f9e7..fb303075 100755 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -266,10 +266,7 @@ CString PrettyPercent( float fNumerator, float fDenominator ); inline CString PrettyPercent( int fNumerator, int fDenominator ) { return PrettyPercent( float(fNumerator), float(fDenominator) ); } CString Commify( int iNum ); CString FormatNumberAndSuffix( int i ); - CString FormatByteValue( uint64_t iBytes ); -CString FormatByteRateValue( float fRate ); - struct tm GetLocalTime(); diff --git a/src/ScreenUserPacks.cpp b/src/ScreenUserPacks.cpp index 803303c2..285eac18 100644 --- a/src/ScreenUserPacks.cpp +++ b/src/ScreenUserPacks.cpp @@ -246,7 +246,7 @@ CString g_CurSelection; unsigned long g_iLastCurrentBytes; RageTimer g_UpdateDuration; -void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal ) +void UpdateXferProgress( unsigned long iBytesCurrent, unsigned long iBytesTotal ) { bool bInterrupt = false; @@ -270,13 +270,17 @@ void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal ) if( DrawTimer.Ago() < DRAW_UPDATE_TIME ) return; - float fXferRate = (iCurrent / g_UpdateDuration.Ago()) / 1024.0; - float fPercent = iCurrent / (iTotal/100); + /* this truncates to int, but that's okay for our purposes */ + float iTransferRate = iBytesCurrent / g_UpdateDuration.Ago(); + + float fPercent = iBytesCurrent / (iBytesTotal/100); + + const CString sRate = FormatByteValue( iTransferRate ) + "/sec"; CString sMessage = ssprintf( "\n\n%s\n%.2f%% %s\n\n%s", USER_PACK_WAIT_TEXT.GetValue().c_str(), fPercent, - FormatByteRateValue(fXferRate).c_str(), + sRate.c_str(), USER_PACK_CANCEL_TEXT.GetValue().c_str() ); SCREENMAN->OverlayMessage( sMessage ); -- 2.11.0