From 2891b585b0c91ecf4a1b0eaebd3024f8527afbca Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 26 Dec 2009 20:08:36 +0000 Subject: [PATCH] Custom root_dir functionality --- direct/src/plugin/load_plugin.cxx | 2 +- direct/src/plugin/p3dInstanceManager.cxx | 15 ++++--- direct/src/plugin/p3dInstanceManager.h | 3 +- direct/src/plugin/p3d_plugin.cxx | 13 +++++-- direct/src/plugin/p3d_plugin.h | 5 ++- direct/src/plugin_standalone/panda3dBase.cxx | 41 ++++++++++---------- 6 files changed, 44 insertions(+), 35 deletions(-) diff --git a/direct/src/plugin/load_plugin.cxx b/direct/src/plugin/load_plugin.cxx index 210e4e0c54..49f450e8f8 100755 --- a/direct/src/plugin/load_plugin.cxx +++ b/direct/src/plugin/load_plugin.cxx @@ -322,7 +322,7 @@ load_plugin(const string &p3d_plugin_filename, if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str(), host_url.c_str(), verify_contents, platform.c_str(), log_directory.c_str(), log_basename.c_str(), - trusted_environment, console_environment)) { + trusted_environment, console_environment, NULL)) { // Oops, failure to initialize. logfile << "Failed to initialize plugin (passed API version " diff --git a/direct/src/plugin/p3dInstanceManager.cxx b/direct/src/plugin/p3dInstanceManager.cxx index 5bfaa6d97f..a42cf01662 100644 --- a/direct/src/plugin/p3dInstanceManager.cxx +++ b/direct/src/plugin/p3dInstanceManager.cxx @@ -188,7 +188,7 @@ initialize(int api_version, const string &contents_filename, const string &host_url, bool verify_contents, const string &platform, const string &log_directory, const string &log_basename, bool trusted_environment, - bool console_environment) { + bool console_environment, const string &root_dir) { _api_version = api_version; _host_url = host_url; _verify_contents = verify_contents; @@ -221,11 +221,14 @@ initialize(int api_version, const string &contents_filename, _log_basename = "p3dcore"; } - _root_dir = find_root_dir(); - - if (_root_dir.empty()) { - cerr << "Could not find root directory.\n"; - return false; + if (root_dir.empty()) { + _root_dir = find_root_dir(); + if (_root_dir.empty()) { + cerr << "Could not find root directory.\n"; + return false; + } + } else { + _root_dir = root_dir; } // Allow the caller (e.g. panda3d.exe) to specify a log directory. diff --git a/direct/src/plugin/p3dInstanceManager.h b/direct/src/plugin/p3dInstanceManager.h index dc23b94043..40618a9bd0 100644 --- a/direct/src/plugin/p3dInstanceManager.h +++ b/direct/src/plugin/p3dInstanceManager.h @@ -57,7 +57,8 @@ public: const string &log_directory, const string &log_basename, bool trusted_environment, - bool console_environment); + bool console_environment, + const string &root_dir = ""); inline bool is_initialized() const; inline void reconsider_runtime_environment(); diff --git a/direct/src/plugin/p3d_plugin.cxx b/direct/src/plugin/p3d_plugin.cxx index f2c09d5dc4..3de1c4d129 100644 --- a/direct/src/plugin/p3d_plugin.cxx +++ b/direct/src/plugin/p3d_plugin.cxx @@ -36,9 +36,9 @@ LOCK _api_lock; bool P3D_initialize(int api_version, const char *contents_filename, const char *host_url, bool verify_contents, - const char *platform, - const char *log_directory, const char *log_basename, - bool trusted_environment, bool console_environment) { + const char *platform, const char *log_directory, + const char *log_basename, bool trusted_environment, + bool console_environment, const char *root_dir) { if (api_version < 10 || api_version > P3D_API_VERSION) { // Can't accept an incompatible version. return false; @@ -69,12 +69,17 @@ P3D_initialize(int api_version, const char *contents_filename, if (log_basename == NULL) { log_basename = ""; } + + if (P3D_API_VERSION < 12 || root_dir == NULL) { + root_dir = ""; + } P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); bool result = inst_mgr->initialize(api_version, contents_filename, host_url, verify_contents, platform, log_directory, log_basename, - trusted_environment, console_environment); + trusted_environment, console_environment, + root_dir); RELEASE_LOCK(_api_lock); return result; } diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index 83815b444e..3572d99b00 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -79,7 +79,7 @@ extern "C" { (below). This number will be incremented whenever there are changes to any of the interface specifications defined in this header file. */ -#define P3D_API_VERSION 11 +#define P3D_API_VERSION 12 /************************ GLOBAL FUNCTIONS **************************/ @@ -143,7 +143,8 @@ P3D_initialize_func(int api_version, const char *contents_filename, const char *host_url, bool verify_contents, const char *platform, const char *log_directory, const char *log_basename, - bool trusted_environment, bool console_environment); + bool trusted_environment, bool console_environment, + const char *root_dir); /* This function should be called to unload the core API. It will release all internally-allocated memory and return the core API to diff --git a/direct/src/plugin_standalone/panda3dBase.cxx b/direct/src/plugin_standalone/panda3dBase.cxx index b854955e47..f42d5f2b98 100644 --- a/direct/src/plugin_standalone/panda3dBase.cxx +++ b/direct/src/plugin_standalone/panda3dBase.cxx @@ -138,43 +138,42 @@ run_embedded(int read_offset, int argc, char *argv[]) { read_offset = read.tellg(); read.close(); - // Initialize the plugin - if (!P3D_initialize(P3D_API_VERSION, NULL, - _host_url.c_str(), _verify_contents, _this_platform.c_str(), - _log_dirname.c_str(), _log_basename.c_str(), - !_enable_security, _console_environment)) { - // Oops, failure to initialize. - cerr << "Failed to initialize plugin (wrong API version?)\n"; - return 1; - } - - // Set the super-mirror URL - Filename super_mirror (f); - super_mirror = Filename(super_mirror.get_dirname()); + // Find the root directory + Filename root_dir (f); + root_dir = Filename(root_dir.get_dirname()); #ifdef __APPLE__ - super_mirror = Filename(super_mirror.get_dirname(), "Resources"); + root_dir = Filename(root_dir.get_dirname(), "Resources"); #endif - if (Filename(super_mirror, "contents.xml").exists()) { - string path = super_mirror.to_os_generic(); + if (Filename(root_dir, "contents.xml").exists()) { + string path = root_dir.to_os_generic(); if (!path.empty() && path[0] != '/') { // On Windows, a leading drive letter must be preceded by an // additional slash. path = "/" + path; } path = "file://" + path; - P3D_set_super_mirror(path.c_str()); } #if !defined(_WIN32) && !defined(__APPLE__) else { // On Unix, we should try to find it in the share directory under the prefix. - super_mirror = Filename(super_mirror.get_dirname(), "share/" + f.get_basename()); - if (Filename(super_mirror, "contents.xml").exists()) { - string path = super_mirror.to_os_generic(); + root_dir = Filename(root_dir.get_dirname(), "share/" + f.get_basename()); + if (Filename(root_dir, "contents.xml").exists()) { + string path = root_dir.to_os_generic(); path = "file://" + path; - P3D_set_super_mirror(path.c_str()); } } #endif + // Initialize the plugin + if (!P3D_initialize(P3D_API_VERSION, NULL, + _host_url.c_str(), _verify_contents, _this_platform.c_str(), + _log_dirname.c_str(), _log_basename.c_str(), + !_enable_security, _console_environment, + root_dir.c_str())) { + // Oops, failure to initialize. + cerr << "Failed to initialize plugin (wrong API version?)\n"; + return 1; + } + // Create a plugin instance and run the program P3D_instance *inst = create_instance (f, true, _win_x, _win_y, _win_width, _win_height,