mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
downloadRemainingSeconds
This commit is contained in:
parent
a36bc45d08
commit
4509e4354c
@ -49,16 +49,18 @@ typedef P3DSplashWindow SplashWindowType;
|
|||||||
// splash window. This list must match the ImageType enum.
|
// splash window. This list must match the ImageType enum.
|
||||||
const char *P3DInstance::_image_type_names[P3DInstance::IT_num_image_types] = {
|
const char *P3DInstance::_image_type_names[P3DInstance::IT_num_image_types] = {
|
||||||
"download",
|
"download",
|
||||||
|
"unauth",
|
||||||
"ready",
|
"ready",
|
||||||
"failed",
|
"failed",
|
||||||
"launch",
|
"launch",
|
||||||
"play_ready",
|
"active",
|
||||||
"play_rollover",
|
"done",
|
||||||
"play_click",
|
|
||||||
"unauth",
|
|
||||||
"auth_ready",
|
"auth_ready",
|
||||||
"auth_rollover",
|
"auth_rollover",
|
||||||
"auth_click",
|
"auth_click",
|
||||||
|
"play_ready",
|
||||||
|
"play_rollover",
|
||||||
|
"play_click",
|
||||||
"none", // Not really used.
|
"none", // Not really used.
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -128,6 +130,10 @@ P3DInstance(P3D_request_ready_func *func,
|
|||||||
// Set some initial properties.
|
// Set some initial properties.
|
||||||
_panda_script_object->set_float_property("instanceDownloadProgress", 0.0);
|
_panda_script_object->set_float_property("instanceDownloadProgress", 0.0);
|
||||||
_panda_script_object->set_float_property("downloadProgress", 0.0);
|
_panda_script_object->set_float_property("downloadProgress", 0.0);
|
||||||
|
_panda_script_object->set_undefined_property("downloadElapsedSeconds");
|
||||||
|
_panda_script_object->set_undefined_property("downloadElapsedFormatted");
|
||||||
|
_panda_script_object->set_undefined_property("downloadRemainingSeconds");
|
||||||
|
_panda_script_object->set_undefined_property("downloadRemainingFormatted");
|
||||||
_panda_script_object->set_string_property("downloadPackageName", "");
|
_panda_script_object->set_string_property("downloadPackageName", "");
|
||||||
_panda_script_object->set_string_property("downloadPackageDisplayName", "");
|
_panda_script_object->set_string_property("downloadPackageDisplayName", "");
|
||||||
_panda_script_object->set_bool_property("downloadComplete", false);
|
_panda_script_object->set_bool_property("downloadComplete", false);
|
||||||
@ -1817,6 +1823,9 @@ make_splash_window() {
|
|||||||
// Go get the required images.
|
// Go get the required images.
|
||||||
for (int i = 0; i < (int)IT_none; ++i) {
|
for (int i = 0; i < (int)IT_none; ++i) {
|
||||||
string token_keyword = string(_image_type_names[i]) + "_img";
|
string token_keyword = string(_image_type_names[i]) + "_img";
|
||||||
|
if (!_fparams.has_token(token_keyword) && i != IT_done) {
|
||||||
|
token_keyword = "splash_img";
|
||||||
|
}
|
||||||
if (!_fparams.has_token(token_keyword)) {
|
if (!_fparams.has_token(token_keyword)) {
|
||||||
// No specific image for this type is specified; get the default
|
// No specific image for this type is specified; get the default
|
||||||
// image. We do this via the P3DPackage interface, so we can
|
// image. We do this via the P3DPackage interface, so we can
|
||||||
@ -2000,6 +2009,7 @@ report_package_info_ready(P3DPackage *package) {
|
|||||||
_download_complete = false;
|
_download_complete = false;
|
||||||
_download_package_index = 0;
|
_download_package_index = 0;
|
||||||
_total_downloaded = 0;
|
_total_downloaded = 0;
|
||||||
|
_download_begin = time(NULL);
|
||||||
|
|
||||||
nout << "Beginning install of " << _downloading_packages.size()
|
nout << "Beginning install of " << _downloading_packages.size()
|
||||||
<< " packages, total " << _total_download_size
|
<< " packages, total " << _total_download_size
|
||||||
@ -2018,6 +2028,8 @@ report_package_info_ready(P3DPackage *package) {
|
|||||||
_panda_script_object->set_string_property("status", "downloading");
|
_panda_script_object->set_string_property("status", "downloading");
|
||||||
_panda_script_object->set_int_property("numDownloadingPackages", _downloading_packages.size());
|
_panda_script_object->set_int_property("numDownloadingPackages", _downloading_packages.size());
|
||||||
_panda_script_object->set_int_property("totalDownloadSize", _total_download_size);
|
_panda_script_object->set_int_property("totalDownloadSize", _total_download_size);
|
||||||
|
_panda_script_object->set_int_property("downloadElapsedSeconds", 0);
|
||||||
|
_panda_script_object->set_undefined_property("downloadRemainingSeconds");
|
||||||
send_notify("ondownloadbegin");
|
send_notify("ondownloadbegin");
|
||||||
|
|
||||||
start_next_download();
|
start_next_download();
|
||||||
@ -2200,6 +2212,23 @@ report_package_progress(P3DPackage *package, double progress) {
|
|||||||
_splash_window->set_install_progress(progress);
|
_splash_window->set_install_progress(progress);
|
||||||
}
|
}
|
||||||
_panda_script_object->set_float_property("downloadProgress", progress);
|
_panda_script_object->set_float_property("downloadProgress", progress);
|
||||||
|
|
||||||
|
static const size_t buffer_size = 256;
|
||||||
|
char buffer[buffer_size];
|
||||||
|
|
||||||
|
time_t elapsed = time(NULL) - _download_begin;
|
||||||
|
_panda_script_object->set_int_property("downloadElapsedSeconds", elapsed);
|
||||||
|
|
||||||
|
sprintf(buffer, "%d:%02d", elapsed / 60, elapsed % 60);
|
||||||
|
_panda_script_object->set_string_property("downloadElapsedFormatted", buffer);
|
||||||
|
|
||||||
|
if (progress > 0 && (elapsed > 5 || progress > 0.2)) {
|
||||||
|
time_t total = (time_t)((double)elapsed / progress);
|
||||||
|
time_t remaining = max(total, elapsed) - elapsed;
|
||||||
|
_panda_script_object->set_int_property("downloadRemainingSeconds", remaining);
|
||||||
|
sprintf(buffer, "%d:%02d", remaining / 60, remaining % 60);
|
||||||
|
_panda_script_object->set_string_property("downloadRemainingFormatted", buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -139,16 +139,18 @@ private:
|
|||||||
enum ImageType {
|
enum ImageType {
|
||||||
// Also update _image_type_names when you update this list.
|
// Also update _image_type_names when you update this list.
|
||||||
IT_download,
|
IT_download,
|
||||||
|
IT_unauth,
|
||||||
IT_ready,
|
IT_ready,
|
||||||
IT_failed,
|
IT_failed,
|
||||||
IT_launch,
|
IT_launch,
|
||||||
IT_play_ready,
|
IT_active,
|
||||||
IT_play_rollover,
|
IT_done,
|
||||||
IT_play_click,
|
|
||||||
IT_unauth,
|
|
||||||
IT_auth_ready,
|
IT_auth_ready,
|
||||||
IT_auth_rollover,
|
IT_auth_rollover,
|
||||||
IT_auth_click,
|
IT_auth_click,
|
||||||
|
IT_play_ready,
|
||||||
|
IT_play_rollover,
|
||||||
|
IT_play_click,
|
||||||
IT_none, // Must be the last value
|
IT_none, // Must be the last value
|
||||||
IT_num_image_types, // Not a real value
|
IT_num_image_types, // Not a real value
|
||||||
};
|
};
|
||||||
@ -274,6 +276,7 @@ private:
|
|||||||
int _download_package_index;
|
int _download_package_index;
|
||||||
size_t _total_download_size;
|
size_t _total_download_size;
|
||||||
size_t _total_downloaded;
|
size_t _total_downloaded;
|
||||||
|
time_t _download_begin;
|
||||||
bool _download_complete;
|
bool _download_complete;
|
||||||
|
|
||||||
// We keep the _panda3d pointer separately because it's so
|
// We keep the _panda3d pointer separately because it's so
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "p3dIntObject.h"
|
#include "p3dIntObject.h"
|
||||||
#include "p3dFloatObject.h"
|
#include "p3dFloatObject.h"
|
||||||
#include "p3dStringObject.h"
|
#include "p3dStringObject.h"
|
||||||
|
#include "p3dInstanceManager.h"
|
||||||
#include <string.h> // strncpy
|
#include <string.h> // strncpy
|
||||||
|
|
||||||
// The following functions are C-style wrappers around the below
|
// The following functions are C-style wrappers around the below
|
||||||
@ -502,3 +503,17 @@ set_string_property(const string &property, const string &value) {
|
|||||||
set_property(property, false, svalue);
|
set_property(property, false, svalue);
|
||||||
P3D_OBJECT_DECREF(svalue);
|
P3D_OBJECT_DECREF(svalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DObject::set_undefined_property
|
||||||
|
// Access: Public
|
||||||
|
// Description: Changes the value of the named property to the
|
||||||
|
// undefined value.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void P3DObject::
|
||||||
|
set_undefined_property(const string &property) {
|
||||||
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
|
P3D_object *uvalue = inst_mgr->new_undefined_object();
|
||||||
|
set_property(property, false, uvalue);
|
||||||
|
P3D_OBJECT_DECREF(uvalue);
|
||||||
|
}
|
||||||
|
@ -69,6 +69,8 @@ public:
|
|||||||
string get_string_property(const string &property);
|
string get_string_property(const string &property);
|
||||||
void set_string_property(const string &property, const string &value);
|
void set_string_property(const string &property, const string &value);
|
||||||
|
|
||||||
|
void set_undefined_property(const string &property);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static P3D_class_definition _object_class;
|
static P3D_class_definition _object_class;
|
||||||
static P3D_class_definition _generic_class;
|
static P3D_class_definition _generic_class;
|
||||||
|
@ -747,7 +747,7 @@ start_p3dpython(P3DInstance *inst) {
|
|||||||
if (!prc_name.empty()) {
|
if (!prc_name.empty()) {
|
||||||
// Add the prc_name to the path too, even if this directory doesn't
|
// Add the prc_name to the path too, even if this directory doesn't
|
||||||
// actually exist.
|
// actually exist.
|
||||||
prc_path = inst_mgr->get_root_dir() + "/" + prc_name + sep + prc_path;
|
prc_path = inst_mgr->get_root_dir() + "/prc/" + prc_name + sep + prc_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keep_pythonpath) {
|
if (keep_pythonpath) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user