Browse Source

add ConfigPage.setSort()

David Rose 14 years ago
parent
commit
42764ffee5

+ 15 - 3
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):

+ 15 - 5
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

+ 21 - 0
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

+ 4 - 0
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;
 

+ 14 - 0
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

+ 3 - 0
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();