about summary refs log tree commit diff
path: root/src/game/client/components
diff options
context:
space:
mode:
authorChoupom <andycootlapin@hotmail.fr>2011-04-12 18:59:08 +0200
committeroy <Tom_Adams@web.de>2011-04-12 19:29:06 +0200
commitffe40db053b50bebc1743a2b96e8c76a8af79b12 (patch)
treeda2705187fa2791f62c073445cde54bf7b0a751b /src/game/client/components
parentb5070bac70beb39a45c1340ced3e0a7740997638 (diff)
downloadzcatch-ffe40db053b50bebc1743a2b96e8c76a8af79b12.tar.gz
zcatch-ffe40db053b50bebc1743a2b96e8c76a8af79b12.zip
fixed map download speed and remaining time
Diffstat (limited to 'src/game/client/components')
-rw-r--r--src/game/client/components/menus.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index 568b3a6e..8bed34c1 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -1038,20 +1038,24 @@ int CMenus::Render()
 					}
 
 					// update download speed
-					float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/1024.0f;
-					m_DownloadSpeed = absolute((m_DownloadSpeed*(1.0f-(1.0f/m_DownloadSpeed))) + (Diff*(1.0f/m_DownloadSpeed)));
+					float Diff = Client()->MapDownloadAmount()-m_DownloadLastCheckSize;
+					float StartDiff = m_DownloadLastCheckSize-0.0f;
+					if(StartDiff+Diff > 0.0f)
+						m_DownloadSpeed = (Diff/(StartDiff+Diff))*(Diff/1.0f) + (StartDiff/(Diff+StartDiff))*m_DownloadSpeed;
+					else
+						m_DownloadSpeed = 0.0f;
 					m_DownloadLastCheckTime = Now;
 					m_DownloadLastCheckSize = Client()->MapDownloadAmount();
 				}
 
 				Box.HSplitTop(64.f, 0, &Box);
 				Box.HSplitTop(24.f, &Part, &Box);
-				str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024,	m_DownloadSpeed);
+				str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024,	m_DownloadSpeed/1024.0f);
 				UI()->DoLabel(&Part, aBuf, 20.f, 0, -1);
 				
 				// time left
 				const char *pTimeLeftString;
-				int TimeLeft = (Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/(m_DownloadSpeed*1024)+1;
+				int TimeLeft = m_DownloadSpeed > 0.0f ? (Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/m_DownloadSpeed : 0.0f;
 				if(TimeLeft >= 60)
 				{
 					TimeLeft /= 60;
@@ -1346,7 +1350,7 @@ void CMenus::OnStateChange(int NewState, int OldState)
 		m_Popup = POPUP_CONNECTING;
 		m_DownloadLastCheckTime = time_get();
 		m_DownloadLastCheckSize = 0;
-		m_DownloadSpeed = 1.0f;
+		m_DownloadSpeed = 0.0f;
 		//client_serverinfo_request();
 	}
 	else if(NewState == IClient::STATE_CONNECTING)