diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 3e3e66e903..f3d7cbc6a1 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -49,16 +49,18 @@ typedef P3DSplashWindow SplashWindowType; // splash window. This list must match the ImageType enum. const char *P3DInstance::_image_type_names[P3DInstance::IT_num_image_types] = { "download", + "unauth", "ready", "failed", "launch", - "play_ready", - "play_rollover", - "play_click", - "unauth", + "active", + "done", "auth_ready", "auth_rollover", "auth_click", + "play_ready", + "play_rollover", + "play_click", "none", // Not really used. }; @@ -128,6 +130,10 @@ P3DInstance(P3D_request_ready_func *func, // Set some initial properties. _panda_script_object->set_float_property("instanceDownloadProgress", 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("downloadPackageDisplayName", ""); _panda_script_object->set_bool_property("downloadComplete", false); @@ -1817,6 +1823,9 @@ make_splash_window() { // Go get the required images. for (int i = 0; i < (int)IT_none; ++i) { 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)) { // No specific image for this type is specified; get the default // 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_package_index = 0; _total_downloaded = 0; + _download_begin = time(NULL); nout << "Beginning install of " << _downloading_packages.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_int_property("numDownloadingPackages", _downloading_packages.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"); start_next_download(); @@ -2200,6 +2212,23 @@ report_package_progress(P3DPackage *package, double progress) { _splash_window->set_install_progress(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); + } } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index eda85114e5..eb0b0e69b3 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -139,16 +139,18 @@ private: enum ImageType { // Also update _image_type_names when you update this list. IT_download, + IT_unauth, IT_ready, IT_failed, IT_launch, - IT_play_ready, - IT_play_rollover, - IT_play_click, - IT_unauth, + IT_active, + IT_done, IT_auth_ready, IT_auth_rollover, IT_auth_click, + IT_play_ready, + IT_play_rollover, + IT_play_click, IT_none, // Must be the last value IT_num_image_types, // Not a real value }; @@ -274,6 +276,7 @@ private: int _download_package_index; size_t _total_download_size; size_t _total_downloaded; + time_t _download_begin; bool _download_complete; // We keep the _panda3d pointer separately because it's so diff --git a/direct/src/plugin/p3dObject.cxx b/direct/src/plugin/p3dObject.cxx index b0e9f7331a..6fab75e13f 100644 --- a/direct/src/plugin/p3dObject.cxx +++ b/direct/src/plugin/p3dObject.cxx @@ -17,6 +17,7 @@ #include "p3dIntObject.h" #include "p3dFloatObject.h" #include "p3dStringObject.h" +#include "p3dInstanceManager.h" #include // strncpy // 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); 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); +} diff --git a/direct/src/plugin/p3dObject.h b/direct/src/plugin/p3dObject.h index e252bdab56..f3957c25cd 100644 --- a/direct/src/plugin/p3dObject.h +++ b/direct/src/plugin/p3dObject.h @@ -69,6 +69,8 @@ public: string get_string_property(const string &property); void set_string_property(const string &property, const string &value); + void set_undefined_property(const string &property); + public: static P3D_class_definition _object_class; static P3D_class_definition _generic_class; diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index efc5945544..2f68e21290 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -747,7 +747,7 @@ start_p3dpython(P3DInstance *inst) { if (!prc_name.empty()) { // Add the prc_name to the path too, even if this directory doesn't // 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) {