diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index 64c977922b..d09fef72ae 100644 --- a/direct/src/p3d/AppRunner.py +++ b/direct/src/p3d/AppRunner.py @@ -33,7 +33,7 @@ else: from direct.showbase import VFSImporter from direct.showbase.DirectObject import DirectObject -from pandac.PandaModules import VirtualFileSystem, Filename, Multifile, loadPrcFileData, unloadPrcFile, getModelPath, Thread, WindowProperties, ExecutionEnvironment, PandaSystem, Notify, StreamWriter, ConfigVariableString, initAppForGui +from pandac.PandaModules import VirtualFileSystem, Filename, Multifile, loadPrcFileData, unloadPrcFile, getModelPath, Thread, WindowProperties, ExecutionEnvironment, PandaSystem, Notify, StreamWriter, ConfigVariableString, ConfigPageManager, initAppForGui from pandac import PandaModules from direct.stdpy import file, glob from direct.task.TaskManagerGlobal import taskMgr @@ -1011,12 +1011,24 @@ class AppRunner(DirectObject): # the Multifile interface to find the prc files, rather than # vfs.scanDirectory(), so we only pick up the files in this # particular multifile. + cpMgr = ConfigPageManager.getGlobalPtr() for f in mf.getSubfileNames(): fn = Filename(f) if fn.getDirname() == '' and fn.getExtension() == 'prc': pathname = '%s/%s' % (root, f) - data = file.open(Filename(pathname), 'r').read() - loadPrcFileData(pathname, data) + + alreadyLoaded = False + for cpi in range(cpMgr.getNumImplicitPages()): + if cpMgr.getImplicitPage(cpi).getName() == pathname: + # No need to load this file twice. + alreadyLoaded = True + break + + if not alreadyLoaded: + data = file.open(Filename(pathname), 'r').read() + cp = loadPrcFileData(pathname, data) + # Set it to sort value 20, behind the implicit pages. + cp.setSort(20) def __clearWindowProperties(self): diff --git a/dtool/src/prc/configPage.I b/dtool/src/prc/configPage.I index 12275515d6..9f3f62cda4 100644 --- a/dtool/src/prc/configPage.I +++ b/dtool/src/prc/configPage.I @@ -22,11 +22,10 @@ //////////////////////////////////////////////////////////////////// INLINE bool ConfigPage:: operator < (const ConfigPage &other) const { - if (is_implicit() != other.is_implicit()) { - // Explicitly-loaded pages are more important than - // implicitly-loaded pages, so put the implicit pages at the end - // of the list. - return (int)is_implicit() < (int)other.is_implicit(); + // The explicit sort value is the most important setting. It's + // usually zero unless explicitly changed. + if (get_sort() != other.get_sort()) { + return get_sort() < other.get_sort(); } // Within the implicit/explicit categorization, sort by the page @@ -73,6 +72,17 @@ is_implicit() const { return _implicit_load; } +//////////////////////////////////////////////////////////////////// +// Function: ConfigPage::get_sort +// Access: Published +// Description: Returns the explicit sort order of this particular +// ConfigPage. See set_sort(). +//////////////////////////////////////////////////////////////////// +INLINE int ConfigPage:: +get_sort() const { + return _sort; +} + //////////////////////////////////////////////////////////////////// // Function: ConfigPage::get_page_seq // Access: Published diff --git a/dtool/src/prc/configPage.cxx b/dtool/src/prc/configPage.cxx index 7eccee0dde..f0d0dc7155 100644 --- a/dtool/src/prc/configPage.cxx +++ b/dtool/src/prc/configPage.cxx @@ -41,6 +41,7 @@ ConfigPage(const string &name, bool implicit_load, int page_seq) : _name(name), _implicit_load(implicit_load), _page_seq(page_seq), + _sort(implicit_load ? 10 : 0), _next_decl_seq(1), _trust_level(0) { @@ -89,6 +90,26 @@ get_local_page() { return _local_page; } +//////////////////////////////////////////////////////////////////// +// Function: ConfigPage::set_sort +// Access: Published +// Description: Changes the explicit sort order of this particular +// ConfigPage. Lower-numbered pages supercede +// higher-numbered pages. Initially, all +// explicitly-loaded pages have sort value 0, and +// implicitly-loaded pages (found on disk) have sort +// value 10; you may set an individual page higher or +// lower to influence its priority relative to other +// pages. +//////////////////////////////////////////////////////////////////// +void ConfigPage:: +set_sort(int sort) { + if (_sort != sort) { + _sort = sort; + ConfigPageManager::get_global_ptr()->mark_unsorted(); + } +} + //////////////////////////////////////////////////////////////////// // Function: ConfigPage::clear // Access: Published diff --git a/dtool/src/prc/configPage.h b/dtool/src/prc/configPage.h index c0b6a117b1..17d675f0a7 100644 --- a/dtool/src/prc/configPage.h +++ b/dtool/src/prc/configPage.h @@ -47,6 +47,9 @@ PUBLISHED: INLINE bool is_special() const; INLINE bool is_implicit() const; + void set_sort(int sort); + INLINE int get_sort() const; + INLINE int get_page_seq() const; INLINE int get_trust_level() const; INLINE void set_trust_level(int trust_level); @@ -78,6 +81,7 @@ private: string _name; bool _implicit_load; int _page_seq; + int _sort; int _next_decl_seq; int _trust_level; diff --git a/dtool/src/prc/configPageManager.I b/dtool/src/prc/configPageManager.I index 0eb5ec5266..f6ad1f78cc 100644 --- a/dtool/src/prc/configPageManager.I +++ b/dtool/src/prc/configPageManager.I @@ -188,6 +188,20 @@ get_explicit_page(int n) const { return _explicit_pages[n]; } + +//////////////////////////////////////////////////////////////////// +// Function: ConfigPageManager::mark_unsorted() +// Access: Public +// Description: This method is meant to be used internally to this +// module; there is no need to call it directly. It +// indicates that the sort values of some pages may have +// changed and pages need to be re-sorted. +//////////////////////////////////////////////////////////////////// +INLINE void ConfigPageManager:: +mark_unsorted() { + _pages_sorted = false; +} + //////////////////////////////////////////////////////////////////// // Function: ConfigPageManager::check_sort_pages() // Access: Private diff --git a/dtool/src/prc/configPageManager.h b/dtool/src/prc/configPageManager.h index 4d22fa14b1..c3ce0a757c 100644 --- a/dtool/src/prc/configPageManager.h +++ b/dtool/src/prc/configPageManager.h @@ -66,6 +66,9 @@ PUBLISHED: static ConfigPageManager *get_global_ptr(); +public: + INLINE void mark_unsorted(); + private: INLINE void check_sort_pages() const; void sort_pages();