Procházet zdrojové kódy

add had_absolute_pathnames()

David Rose před 21 roky
rodič
revize
697f2a2b67

+ 21 - 0
panda/src/egg/eggData.I

@@ -25,6 +25,7 @@
 INLINE EggData::
 EggData() {
   _auto_resolve_externals = false;
+  _had_absolute_pathnames = false;
   _coordsys = CS_default;
 }
 
@@ -38,6 +39,7 @@ INLINE EggData::
 EggData(const EggData &copy) :
   EggGroupNode(copy),
   _auto_resolve_externals(copy._auto_resolve_externals),
+  _had_absolute_pathnames(copy._had_absolute_pathnames),
   _coordsys(copy._coordsys),
   _egg_filename(copy._egg_filename) 
 {
@@ -52,6 +54,7 @@ INLINE EggData &EggData::
 operator = (const EggData &copy) {
   EggGroupNode::operator = (copy);
   _auto_resolve_externals = copy._auto_resolve_externals;
+  _had_absolute_pathnames = copy._had_absolute_pathnames;
   _coordsys = copy._coordsys;
   _egg_filename = copy._egg_filename;
   return *this;
@@ -81,6 +84,24 @@ get_auto_resolve_externals() const {
   return _auto_resolve_externals;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggData::original_had_absolute_pathnames
+//       Access: Public
+//  Description: Returns true if the data processed in the last call
+//               to read() contained absolute pathnames, or false if
+//               those pathnames were all relative.
+//
+//               This method is necessary because if
+//               auto_resolve_externals() is in effect, it may modify
+//               the pathnames to be absolute whether or not they were
+//               as loaded from disk.  This method can be used to
+//               query the state of the original egg file from disk.
+////////////////////////////////////////////////////////////////////
+INLINE bool EggData::
+original_had_absolute_pathnames() const {
+  return _had_absolute_pathnames;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggData::get_coordinate_system
 //       Access: Public

+ 3 - 0
panda/src/egg/eggData.cxx

@@ -342,6 +342,9 @@ post_read() {
     set_coordinate_system(old_coordsys);
   }
 
+  // Fill this in before we automatically resolve pathnames.
+  _had_absolute_pathnames = has_absolute_pathnames();
+
   if (get_auto_resolve_externals()) {
     // Resolve filenames that are relative to the egg file.
     DSearchPath dir;

+ 2 - 0
panda/src/egg/eggData.h

@@ -62,6 +62,7 @@ PUBLISHED:
 
   INLINE void set_auto_resolve_externals(bool resolve);
   INLINE bool get_auto_resolve_externals() const;
+  INLINE bool original_had_absolute_pathnames() const;
 
   void set_coordinate_system(CoordinateSystem coordsys);
   INLINE CoordinateSystem get_coordinate_system() const;
@@ -81,6 +82,7 @@ private:
   void pre_write();
 
   bool _auto_resolve_externals;
+  bool _had_absolute_pathnames;
   CoordinateSystem _coordsys;
   Filename _egg_filename;
 

+ 57 - 0
panda/src/egg/eggGroupNode.cxx

@@ -350,6 +350,63 @@ find_child(const string &name) const {
   return NULL;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggGroupNode::has_absolute_pathnames
+//       Access: Published
+//  Description: Returns true if any nodes at this level and below
+//               include a reference to a file via an absolute
+//               pathname, or false if all references are relative.
+////////////////////////////////////////////////////////////////////
+bool EggGroupNode::
+has_absolute_pathnames() const {
+  Children::const_iterator ci;
+  for (ci = _children.begin();
+       ci != _children.end();
+       ++ci) {
+    EggNode *child = *ci;
+    if (child->is_of_type(EggTexture::get_class_type())) {
+      EggTexture *tex = DCAST(EggTexture, child);
+      if (!tex->get_filename().is_local()) {
+        if (egg_cat.is_debug()) {
+          egg_cat.debug()
+            << "Absolute pathname: " << tex->get_filename()
+            << "\n";
+        }
+        return true;
+      }
+
+      if (tex->has_alpha_filename()) {
+        if (!tex->get_alpha_filename().is_local()) {
+          if (egg_cat.is_debug()) {
+            egg_cat.debug()
+              << "Absolute pathname: " << tex->get_alpha_filename()
+              << "\n";
+          }
+          return true;
+        }
+      }
+
+    } else if (child->is_of_type(EggFilenameNode::get_class_type())) {
+      EggFilenameNode *fnode = DCAST(EggFilenameNode, child);
+      if (!fnode->get_filename().is_local()) {
+        if (egg_cat.is_debug()) {
+          egg_cat.debug()
+            << "Absolute pathname: " << fnode->get_filename()
+            << "\n";
+        }
+        return true;
+      }
+
+    } else if (child->is_of_type(EggGroupNode::get_class_type())) {
+      if (DCAST(EggGroupNode, child)->has_absolute_pathnames()) {
+        return true;
+      }
+    }
+  }
+
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggGroupNode::resolve_filenames
 //       Access: Published

+ 1 - 0
panda/src/egg/eggGroupNode.h

@@ -120,6 +120,7 @@ PUBLISHED:
 
   EggNode *find_child(const string &name) const;
 
+  bool has_absolute_pathnames() const;
   void resolve_filenames(const DSearchPath &searchpath);
   void force_filenames(const Filename &directory);
   void reverse_vertex_ordering();