From 211116b6cc264ebfa5c83c5d2be1f9778ce5b566 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 8 Feb 2010 22:41:11 +0000 Subject: [PATCH] time download better--not from beginning of p3d file --- direct/src/plugin/p3dInstance.cxx | 28 ++++++++++++++++++---------- direct/src/plugin/p3dInstance.h | 12 ++++++++---- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index bf8979bf58..36f5dc5eff 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -417,9 +417,9 @@ set_p3d_url(const string &p3d_url) { // Mark the time we started downloading, so we'll know when to reveal // the progress bar, and we can predict the total download time. #ifdef _WIN32 - _start_dl_instance_tick = GetTickCount(); + _start_dl_tick = GetTickCount(); #else - gettimeofday(&_start_dl_instance_timeval, NULL); + gettimeofday(&_start_dl_timeval, NULL); #endif _show_dl_instance_progress = false; @@ -459,9 +459,9 @@ make_p3d_stream(const string &p3d_url) { // Mark the time we started downloading, so we'll know when to reveal // the progress bar. #ifdef _WIN32 - _start_dl_instance_tick = GetTickCount(); + _start_dl_tick = GetTickCount(); #else - gettimeofday(&_start_dl_instance_timeval, NULL); + gettimeofday(&_start_dl_timeval, NULL); #endif _show_dl_instance_progress = false; @@ -2758,6 +2758,14 @@ ready_to_install() { _download_package_index = 0; _total_downloaded = 0; + // Record the time we started the package download, so we can + // report downlaodElapsedTime and predict downloadRemainingTime. +#ifdef _WIN32 + _start_dl_tick = GetTickCount(); +#else + gettimeofday(&_start_dl_timeval, NULL); +#endif + nout << "Beginning install of " << _downloading_packages.size() << " packages, total " << _total_download_size << " bytes required.\n"; @@ -2914,12 +2922,12 @@ report_instance_progress(double progress, bool is_progress_known, // instance file might be already in the browser cache). #ifdef _WIN32 int now = GetTickCount(); - double elapsed = (double)(now - _start_dl_instance_tick) * 0.001; + double elapsed = (double)(now - _start_dl_tick) * 0.001; #else struct timeval now; gettimeofday(&now, NULL); - double elapsed = (double)(now.tv_sec - _start_dl_instance_timeval.tv_sec) + - (double)(now.tv_usec - _start_dl_instance_timeval.tv_usec) / 1000000.0; + double elapsed = (double)(now.tv_sec - _start_dl_timeval.tv_sec) + + (double)(now.tv_usec - _start_dl_timeval.tv_usec) / 1000000.0; #endif // Put up the progress bar after 2 seconds have elapsed, if we've @@ -2984,12 +2992,12 @@ report_package_progress(P3DPackage *package, double progress) { // Get the floating-point elapsed time. #ifdef _WIN32 int now = GetTickCount(); - double elapsed = (double)(now - _start_dl_instance_tick) * 0.001; + double elapsed = (double)(now - _start_dl_tick) * 0.001; #else struct timeval now; gettimeofday(&now, NULL); - double elapsed = (double)(now.tv_sec - _start_dl_instance_timeval.tv_sec) + - (double)(now.tv_usec - _start_dl_instance_timeval.tv_usec) / 1000000.0; + double elapsed = (double)(now.tv_sec - _start_dl_timeval.tv_sec) + + (double)(now.tv_usec - _start_dl_timeval.tv_usec) / 1000000.0; #endif int ielapsed = (int)elapsed; diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index fba30abc6a..eab04dda35 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -329,13 +329,17 @@ private: bool _instance_window_attached; bool _stuff_to_download; - // Members for deciding whether and when to display the progress bar - // for downloading the initial instance data. + // Keep track of when the download was started, for reporting + // purposes. These members are used both for the instance download, + // and for the later package download. #ifdef _WIN32 - int _start_dl_instance_tick; + int _start_dl_tick; #else - struct timeval _start_dl_instance_timeval; + struct timeval _start_dl_timeval; #endif + + // This is set false initially, but true if the instance download + // continues for more than a couple of seconds. bool _show_dl_instance_progress; typedef vector Packages;