mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-19 21:32:58 -04:00
Custom root_dir functionality
This commit is contained in:
parent
a03449d433
commit
2891b585b0
@ -322,7 +322,7 @@ load_plugin(const string &p3d_plugin_filename,
|
|||||||
if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str(),
|
if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str(),
|
||||||
host_url.c_str(), verify_contents, platform.c_str(),
|
host_url.c_str(), verify_contents, platform.c_str(),
|
||||||
log_directory.c_str(), log_basename.c_str(),
|
log_directory.c_str(), log_basename.c_str(),
|
||||||
trusted_environment, console_environment)) {
|
trusted_environment, console_environment, NULL)) {
|
||||||
// Oops, failure to initialize.
|
// Oops, failure to initialize.
|
||||||
logfile
|
logfile
|
||||||
<< "Failed to initialize plugin (passed API version "
|
<< "Failed to initialize plugin (passed API version "
|
||||||
|
@ -188,7 +188,7 @@ initialize(int api_version, const string &contents_filename,
|
|||||||
const string &host_url, bool verify_contents,
|
const string &host_url, bool verify_contents,
|
||||||
const string &platform, const string &log_directory,
|
const string &platform, const string &log_directory,
|
||||||
const string &log_basename, bool trusted_environment,
|
const string &log_basename, bool trusted_environment,
|
||||||
bool console_environment) {
|
bool console_environment, const string &root_dir) {
|
||||||
_api_version = api_version;
|
_api_version = api_version;
|
||||||
_host_url = host_url;
|
_host_url = host_url;
|
||||||
_verify_contents = verify_contents;
|
_verify_contents = verify_contents;
|
||||||
@ -221,12 +221,15 @@ initialize(int api_version, const string &contents_filename,
|
|||||||
_log_basename = "p3dcore";
|
_log_basename = "p3dcore";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root_dir.empty()) {
|
||||||
_root_dir = find_root_dir();
|
_root_dir = find_root_dir();
|
||||||
|
|
||||||
if (_root_dir.empty()) {
|
if (_root_dir.empty()) {
|
||||||
cerr << "Could not find root directory.\n";
|
cerr << "Could not find root directory.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_root_dir = root_dir;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow the caller (e.g. panda3d.exe) to specify a log directory.
|
// Allow the caller (e.g. panda3d.exe) to specify a log directory.
|
||||||
// Or, allow the developer to compile one in.
|
// Or, allow the developer to compile one in.
|
||||||
|
@ -57,7 +57,8 @@ public:
|
|||||||
const string &log_directory,
|
const string &log_directory,
|
||||||
const string &log_basename,
|
const string &log_basename,
|
||||||
bool trusted_environment,
|
bool trusted_environment,
|
||||||
bool console_environment);
|
bool console_environment,
|
||||||
|
const string &root_dir = "");
|
||||||
|
|
||||||
inline bool is_initialized() const;
|
inline bool is_initialized() const;
|
||||||
inline void reconsider_runtime_environment();
|
inline void reconsider_runtime_environment();
|
||||||
|
@ -36,9 +36,9 @@ LOCK _api_lock;
|
|||||||
bool
|
bool
|
||||||
P3D_initialize(int api_version, const char *contents_filename,
|
P3D_initialize(int api_version, const char *contents_filename,
|
||||||
const char *host_url, bool verify_contents,
|
const char *host_url, bool verify_contents,
|
||||||
const char *platform,
|
const char *platform, const char *log_directory,
|
||||||
const char *log_directory, const char *log_basename,
|
const char *log_basename, bool trusted_environment,
|
||||||
bool trusted_environment, bool console_environment) {
|
bool console_environment, const char *root_dir) {
|
||||||
if (api_version < 10 || api_version > P3D_API_VERSION) {
|
if (api_version < 10 || api_version > P3D_API_VERSION) {
|
||||||
// Can't accept an incompatible version.
|
// Can't accept an incompatible version.
|
||||||
return false;
|
return false;
|
||||||
@ -70,11 +70,16 @@ P3D_initialize(int api_version, const char *contents_filename,
|
|||||||
log_basename = "";
|
log_basename = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (P3D_API_VERSION < 12 || root_dir == NULL) {
|
||||||
|
root_dir = "";
|
||||||
|
}
|
||||||
|
|
||||||
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
bool result = inst_mgr->initialize(api_version, contents_filename, host_url,
|
bool result = inst_mgr->initialize(api_version, contents_filename, host_url,
|
||||||
verify_contents, platform,
|
verify_contents, platform,
|
||||||
log_directory, log_basename,
|
log_directory, log_basename,
|
||||||
trusted_environment, console_environment);
|
trusted_environment, console_environment,
|
||||||
|
root_dir);
|
||||||
RELEASE_LOCK(_api_lock);
|
RELEASE_LOCK(_api_lock);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ extern "C" {
|
|||||||
(below). This number will be incremented whenever there are changes
|
(below). This number will be incremented whenever there are changes
|
||||||
to any of the interface specifications defined in this header
|
to any of the interface specifications defined in this header
|
||||||
file. */
|
file. */
|
||||||
#define P3D_API_VERSION 11
|
#define P3D_API_VERSION 12
|
||||||
|
|
||||||
/************************ GLOBAL FUNCTIONS **************************/
|
/************************ 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 *host_url, bool verify_contents,
|
||||||
const char *platform,
|
const char *platform,
|
||||||
const char *log_directory, const char *log_basename,
|
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
|
/* This function should be called to unload the core API. It will
|
||||||
release all internally-allocated memory and return the core API to
|
release all internally-allocated memory and return the core API to
|
||||||
|
@ -138,43 +138,42 @@ run_embedded(int read_offset, int argc, char *argv[]) {
|
|||||||
read_offset = read.tellg();
|
read_offset = read.tellg();
|
||||||
read.close();
|
read.close();
|
||||||
|
|
||||||
// Initialize the plugin
|
// Find the root directory
|
||||||
if (!P3D_initialize(P3D_API_VERSION, NULL,
|
Filename root_dir (f);
|
||||||
_host_url.c_str(), _verify_contents, _this_platform.c_str(),
|
root_dir = Filename(root_dir.get_dirname());
|
||||||
_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());
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
super_mirror = Filename(super_mirror.get_dirname(), "Resources");
|
root_dir = Filename(root_dir.get_dirname(), "Resources");
|
||||||
#endif
|
#endif
|
||||||
if (Filename(super_mirror, "contents.xml").exists()) {
|
if (Filename(root_dir, "contents.xml").exists()) {
|
||||||
string path = super_mirror.to_os_generic();
|
string path = root_dir.to_os_generic();
|
||||||
if (!path.empty() && path[0] != '/') {
|
if (!path.empty() && path[0] != '/') {
|
||||||
// On Windows, a leading drive letter must be preceded by an
|
// On Windows, a leading drive letter must be preceded by an
|
||||||
// additional slash.
|
// additional slash.
|
||||||
path = "/" + path;
|
path = "/" + path;
|
||||||
}
|
}
|
||||||
path = "file://" + path;
|
path = "file://" + path;
|
||||||
P3D_set_super_mirror(path.c_str());
|
|
||||||
}
|
}
|
||||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||||
else { // On Unix, we should try to find it in the share directory under the prefix.
|
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());
|
root_dir = Filename(root_dir.get_dirname(), "share/" + f.get_basename());
|
||||||
if (Filename(super_mirror, "contents.xml").exists()) {
|
if (Filename(root_dir, "contents.xml").exists()) {
|
||||||
string path = super_mirror.to_os_generic();
|
string path = root_dir.to_os_generic();
|
||||||
path = "file://" + path;
|
path = "file://" + path;
|
||||||
P3D_set_super_mirror(path.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
// Create a plugin instance and run the program
|
||||||
P3D_instance *inst = create_instance
|
P3D_instance *inst = create_instance
|
||||||
(f, true, _win_x, _win_y, _win_width, _win_height,
|
(f, true, _win_x, _win_y, _win_width, _win_height,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user