Display transfer rate when uploading user packs
authorPatrick McIlroy <itgpmc@gmail.com>
Wed, 22 Sep 2010 00:18:33 +0000 (00:18 +0000)
committerPatrick McIlroy <itgpmc@gmail.com>
Wed, 22 Sep 2010 00:18:33 +0000 (00:18 +0000)
git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg/branches/dev@847 83fadc84-e282-4d84-a09a-c4228d6ae7e5

src/DiagnosticsUtil.cpp
src/RageUtil.cpp
src/RageUtil.h
src/ScreenUserPacks.cpp
src/StepMania-net2008.vcproj

index 39bbed7..c50c114 100644 (file)
@@ -50,43 +50,6 @@ CString DiagnosticsUtil::GetIP()
                return sError;
 }
 
-namespace
-{
-       /* declared as floats so the division isn't implicitly cast to int */
-       float KILOBYTE = 1024;
-       float MEGABYTE = 1024*KILOBYTE;
-       float GIGABYTE = 1024*MEGABYTE;
-
-       CString FormatByteValue( uint64_t iBytes )
-       {
-               CString sSuffix;
-               float fShownSpace = 0.0f;
-
-               if( iBytes > GIGABYTE )
-               {
-                       fShownSpace = iBytes / GIGABYTE;
-                       sSuffix = "GB";
-               }
-               else if( iBytes > MEGABYTE )
-               {
-                       fShownSpace = iBytes / MEGABYTE;
-                       sSuffix = "MB";
-               }
-               else if( iBytes > KILOBYTE )
-               {
-                       fShownSpace = iBytes / KILOBYTE;
-                       sSuffix = "KB";
-               }
-               else
-               {
-                       fShownSpace = float(iBytes);
-                       sSuffix = "bytes";
-               }
-
-               return ssprintf( "%.02f %s", fShownSpace, sSuffix.c_str() );
-       }
-}
-
 // XXX: we should probably take a parameter for these later on.
 // for now, return the only disk space value that matters to us.
 
index 422fdc2..e05f97c 100755 (executable)
@@ -210,6 +210,61 @@ CString FormatNumberAndSuffix( int i )
        return ssprintf("%i", i) + sSuffix;
 }
 
+namespace
+{
+       /* declared as floats so the division isn't implicitly cast to int */
+       float KILOBYTE = 1024;
+       float MEGABYTE = 1024*KILOBYTE;
+       float GIGABYTE = 1024*MEGABYTE;
+}
+
+CString FormatByteValue( uint64_t iBytes )
+{
+       CString sSuffix;
+       float fShownSpace = 0.0f;
+               if( iBytes > GIGABYTE )
+       {
+               fShownSpace = iBytes / GIGABYTE;
+               sSuffix = "GB";
+       }
+       else if( iBytes > MEGABYTE )
+       {
+               fShownSpace = iBytes / MEGABYTE;
+               sSuffix = "MB";
+       }
+       else if( iBytes > KILOBYTE )
+       {
+               fShownSpace = iBytes / KILOBYTE;
+               sSuffix = "KB";
+       }
+       else
+       {
+               fShownSpace = float(iBytes);
+               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() );
+}
+
 struct tm GetLocalTime()
 {
        const time_t t = time(NULL);
index e6c194e..6cf7f9e 100755 (executable)
@@ -267,6 +267,9 @@ inline CString PrettyPercent( int fNumerator, int fDenominator ) { return Pretty
 CString Commify( int iNum );
 CString FormatNumberAndSuffix( int i );
 
+CString FormatByteValue( uint64_t iBytes );
+CString FormatByteRateValue( float fRate );
+
 
 struct tm GetLocalTime();
 
index 15c2736..803303c 100644 (file)
@@ -243,6 +243,8 @@ void ScreenUserPacks::Input( const DeviceInput& DeviceI, const InputEventType ty
 \r
 CString g_CurXferFile;\r
 CString g_CurSelection;\r
+unsigned long g_iLastCurrentBytes;\r
+RageTimer g_UpdateDuration;\r
 \r
 void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal )\r
 {\r
@@ -268,10 +270,13 @@ void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal )
        if( DrawTimer.Ago() < DRAW_UPDATE_TIME )\r
                return;\r
 \r
+       float fXferRate = (iCurrent / g_UpdateDuration.Ago()) / 1024.0;\r
        float fPercent = iCurrent / (iTotal/100);\r
-       CString sMessage = ssprintf( "\n\n%s\n%.2f%%\n\n%s",\r
+\r
+       CString sMessage = ssprintf( "\n\n%s\n%.2f%% %s\n\n%s",\r
                USER_PACK_WAIT_TEXT.GetValue().c_str(),\r
                fPercent,\r
+               FormatByteRateValue(fXferRate).c_str(),\r
                USER_PACK_CANCEL_TEXT.GetValue().c_str()\r
        );\r
        SCREENMAN->OverlayMessage( sMessage );\r
@@ -372,6 +377,8 @@ m_PlayerSongLoadThread.Create( InitSASSongThread, this )
                        sError = ""; //  ??\r
                        RageTimer start;\r
                        DrawTimer.Touch();\r
+                       g_iLastCurrentBytes = 0;\r
+                       g_UpdateDuration.Touch();\r
                        if (!UPACKMAN->TransferPack( g_CurXferFile, sSelection, UpdateXferProgress, sError ) )\r
                        {\r
                                SCREENMAN->SystemMessage( "Transfer error:\n" + sError );\r
index e880515..de67fc4 100644 (file)
                                EnableIntrinsicFunctions="true"\r
                                FavorSizeOrSpeed="2"\r
                                AdditionalIncludeDirectories=".;vorbis;libjpeg;&quot;lua-5.0\include&quot;;libusb\include;BaseClasses"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINDOWS;RELEASE"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINDOWS;RELEASE;_CRT_SECURE_NO_WARNINGS"\r
                                StringPooling="true"\r
                                MinimalRebuild="false"\r
                                ExceptionHandling="0"\r