David Rose 20 лет назад
Родитель
Сommit
6e8adc36ad

+ 17 - 7
panda/src/gobj/texture.cxx

@@ -1706,7 +1706,7 @@ make_from_bam(const FactoryParams &params) {
       if (!manager->get_filename().empty()) {
 	// If texture filename was given relative to the bam filename,
 	// expand it now.
-	DSearchPath bam_dir = manager->get_filename().get_dirname();
+	Filename bam_dir = manager->get_filename().get_dirname();
         vfs->resolve_filename(filename, bam_dir);
 	if (!alpha_filename.empty()) {
 	  vfs->resolve_filename(alpha_filename, bam_dir);
@@ -1808,6 +1808,8 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
 ////////////////////////////////////////////////////////////////////
 void Texture::
 write_datagram(BamWriter *manager, Datagram &me) {
+  bool has_bam_dir = !manager->get_filename().empty();
+  Filename bam_dir = manager->get_filename().get_dirname();
   Filename filename = get_filename();
   Filename alpha_filename = get_alpha_filename();
 
@@ -1835,17 +1837,25 @@ write_datagram(BamWriter *manager, Datagram &me) {
   case BTM_relative:
     filename = get_fullpath();
     alpha_filename = get_alpha_fullpath();
-    filename.find_on_searchpath(get_texture_path()) ||
-      filename.find_on_searchpath(get_model_path());
+    if (!has_bam_dir || filename.find_on_searchpath(bam_dir) == -1) {
+      if (filename.find_on_searchpath(get_texture_path()) == -1) {
+	filename.find_on_searchpath(get_model_path());
+      }
+    }
     if (gobj_cat.is_debug()) {
       gobj_cat.debug()
-        << "Texture file " << get_filename() << " found as " << filename << "\n";
+        << "Texture file " << get_filename()
+	<< " found as " << filename << "\n";
+    }
+    if (!has_bam_dir || alpha_filename.find_on_searchpath(bam_dir) == -1) {
+      if (alpha_filename.find_on_searchpath(get_texture_path()) == -1) {
+	alpha_filename.find_on_searchpath(get_model_path());
+      }
     }
-    alpha_filename.find_on_searchpath(get_texture_path()) ||
-      alpha_filename.find_on_searchpath(get_model_path());
     if (gobj_cat.is_debug()) {
       gobj_cat.debug()
-        << "Alpha image " << get_alpha_filename() << " found as " << alpha_filename << "\n";
+        << "Alpha image " << get_alpha_filename()
+	<< " found as " << alpha_filename << "\n";
     }
     break;
 

+ 2 - 2
panda/src/pgraph/bamFile.cxx

@@ -404,7 +404,7 @@ continue_open_read(const string &bam_filename, bool report_errors) {
     return false;
   }
 
-  _reader = new BamReader(&_din, bam_filename);
+  _reader = new BamReader(&_din, _bam_filename);
   if (!_reader->init()) {
     close();
     return false;
@@ -431,7 +431,7 @@ continue_open_write(const string &bam_filename, bool report_errors) {
     return false;
   }
 
-  _writer = new BamWriter(&_dout);
+  _writer = new BamWriter(&_dout, _bam_filename);
 
   if (!_writer->init()) {
     close();

+ 1 - 1
panda/src/pgraph/loader.cxx

@@ -418,7 +418,7 @@ load_file(const Filename &filename, const LoaderOptions &options) const {
     num_files = find_all_files(filename, get_model_path(), results);
   } else {
     // Look for the file only where it is.
-    num_files = find_all_files(filename, DSearchPath("."), results);
+    num_files = find_all_files(filename, DSearchPath(Filename(".")), results);
   }
 
   if (num_files == 0) {

+ 13 - 0
panda/src/putil/bamReader.I

@@ -17,6 +17,19 @@
 ////////////////////////////////////////////////////////////////////
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: BamReader::get_filename
+//       Access: Public
+//  Description: If a BAM is a file, then the BamReader should
+//               contain the name of the file.  This enables the
+//               reader to interpret pathnames in the BAM as relative
+//               to the directory containing the BAM.
+////////////////////////////////////////////////////////////////////
+INLINE const Filename &BamReader::
+get_filename() const {
+  return _filename;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: BamReader::is_eof
 //       Access: Public

+ 0 - 13
panda/src/putil/bamReader.cxx

@@ -169,19 +169,6 @@ get_aux_data(const string &name) const {
   return NULL;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: BamReader::get_filename
-//       Access: Public
-//  Description: If a BAM is a file, then the BamReader should
-//               contain the name of the file.  This enables the
-//               reader to interpret pathnames in the BAM as relative
-//               to the directory containing the BAM.
-////////////////////////////////////////////////////////////////////
-const Filename &BamReader::
-get_filename() const {
-  return _filename;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: BamReader::read_object
 //       Access: Public

+ 2 - 2
panda/src/putil/bamReader.h

@@ -94,14 +94,14 @@ public:
   static WritableFactory *const NullFactory;
 
   // The primary interface for a caller.
-  BamReader(DatagramGenerator *generator, const Filename &name="");
+  BamReader(DatagramGenerator *generator, const Filename &name = "");
   ~BamReader();
 
   bool init();
 
   void set_aux_data(const string &name, void *data);
   void *get_aux_data(const string &name) const;
-  const Filename &get_filename() const;
+  INLINE const Filename &get_filename() const;
   
   TypedWritable *read_object();
   INLINE bool is_eof() const;

+ 13 - 0
panda/src/putil/bamWriter.I

@@ -17,6 +17,19 @@
 ////////////////////////////////////////////////////////////////////
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: BamWriter::get_filename
+//       Access: Public
+//  Description: If a BAM is a file, then the BamWriter should
+//               contain the name of the file.  This enables the
+//               writer to convert pathnames in the BAM to relative
+//               to the directory containing the BAM.
+////////////////////////////////////////////////////////////////////
+INLINE const Filename &BamWriter::
+get_filename() const {
+  return _filename;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: BamWriter::get_file_endian
 //       Access: Public

+ 3 - 2
panda/src/putil/bamWriter.cxx

@@ -33,8 +33,9 @@
 //  Description:
 ////////////////////////////////////////////////////////////////////
 BamWriter::
-BamWriter(DatagramSink *sink) :
-  _target(sink)
+BamWriter(DatagramSink *sink, const Filename &name) :
+  _target(sink),
+  _filename(name)
 {
 }
 

+ 5 - 1
panda/src/putil/bamWriter.h

@@ -76,12 +76,13 @@ struct PipelineCyclerBase;
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA BamWriter {
 public:
-  BamWriter(DatagramSink *sink);
+  BamWriter(DatagramSink *sink, const Filename &name = "");
   ~BamWriter();
 
   // The primary interface for a caller.
 
   bool init();
+  INLINE const Filename &get_filename() const;
   bool write_object(const TypedWritable *obj);
   bool has_object(const TypedWritable *obj) const;
 
@@ -104,6 +105,9 @@ private:
   void write_pta_id(Datagram &dg, int pta_id);
   int enqueue_object(const TypedWritable *object);
 
+  // This is the filename of the BAM, or null string if not in a file.
+  Filename _filename;
+
   BamEndian _file_endian;
 
   // This is the set of all TypeHandles already written.