diff --git a/panda/src/doc/howto.use_config.txt b/panda/src/doc/howto.use_config.txt index e56ad0607d..0e92ce527d 100644 --- a/panda/src/doc/howto.use_config.txt +++ b/panda/src/doc/howto.use_config.txt @@ -353,6 +353,13 @@ on the standard prc file search path (e.g. $PRC_DIR), as well as on the model-path. It may be a physical file on disk, or a subfile of a multifile (and mounted via Panda's virtual file system). +If your prc file is stored as an in-memory string instead of as a disk +file (for instance, maybe you just built it up), you can use the +load_prc_file_data() method to load the prc file from the string data. +The first parameter is an arbitrary name to assign to your in-memory +prc file; supply a filename if you have one, or use some other name +that is meaningful to you. + You can see the complete list of prc files that have been loaded into the config system at any given time, including files loaded explicitly via load_prc_file(), as well as files found in the standard prc file diff --git a/panda/src/putil/load_prc_file.cxx b/panda/src/putil/load_prc_file.cxx index 51f55bbd0d..0fc6580ba3 100644 --- a/panda/src/putil/load_prc_file.cxx +++ b/panda/src/putil/load_prc_file.cxx @@ -76,6 +76,38 @@ load_prc_file(const string &filename) { } } +//////////////////////////////////////////////////////////////////// +// Function: load_prc_file_data +// Description: Another convenience function to load a prc file from +// an explicit string, which represents the contents of +// the prc file. +// +// The first parameter is an arbitrary name to assign to +// this in-memory prc file. Supply a filename if the +// data was read from a file, or use any other name that +// is meaningful to you. The name is only used when the +// set of loaded prc files is listed. +//////////////////////////////////////////////////////////////////// +EXPCL_PANDA ConfigPage * +load_prc_file_data(const string &name, const string &data) { + istringstream strm(data); + + ConfigPageManager *cp_mgr = ConfigPageManager::get_global_ptr(); + + ConfigPage *page = cp_mgr->make_explicit_page(name); + bool read_ok = page->read_prc(strm); + + if (read_ok) { + return page; + + } else { + util_cat.info() + << "Unable to read explicit prc data " << name << "\n"; + cp_mgr->delete_explicit_page(page); + return NULL; + } +} + //////////////////////////////////////////////////////////////////// // Function: unload_prc_file // Description: Unloads (and deletes) a ConfigPage that represents a diff --git a/panda/src/putil/load_prc_file.h b/panda/src/putil/load_prc_file.h index 45320f1403..a492c0bbb1 100644 --- a/panda/src/putil/load_prc_file.h +++ b/panda/src/putil/load_prc_file.h @@ -45,6 +45,21 @@ BEGIN_PUBLISH EXPCL_PANDA ConfigPage * load_prc_file(const string &filename); +//////////////////////////////////////////////////////////////////// +// Function: load_prc_file_data +// Description: Another convenience function to load a prc file from +// an explicit string, which represents the contents of +// the prc file. +// +// The first parameter is an arbitrary name to assign to +// this in-memory prc file. Supply a filename if the +// data was read from a file, or use any other name that +// is meaningful to you. The name is only used when the +// set of loaded prc files is listed. +//////////////////////////////////////////////////////////////////// +EXPCL_PANDA ConfigPage * +load_prc_file_data(const string &name, const string &data); + //////////////////////////////////////////////////////////////////// // Function: unload_prc_file // Description: Unloads (and deletes) a ConfigPage that represents a