浏览代码

putil: Extend bam format to allow skipping/ignoring objects

rdb 4 年之前
父节点
当前提交
bc2008564c
共有 4 个文件被更改,包括 35 次插入0 次删除
  1. 3 0
      panda/src/putil/bamEnums.cxx
  2. 4 0
      panda/src/putil/bamEnums.h
  3. 27 0
      panda/src/putil/bamReader.cxx
  4. 1 0
      panda/src/putil/bamReader.h

+ 3 - 0
panda/src/putil/bamEnums.cxx

@@ -72,6 +72,9 @@ operator << (ostream &out, BamEnums::BamObjectCode boc) {
 
 
   case BamEnums::BOC_file_data:
   case BamEnums::BOC_file_data:
     return out << "file_data";
     return out << "file_data";
+
+  case BamEnums::BOC_ignore:
+    return out << "ignore";
   }
   }
 
 
   return out << "**invalid BamEnums::BamObjectCode value: (" << (int)boc << ")**";
   return out << "**invalid BamEnums::BamObjectCode value: (" << (int)boc << ")**";

+ 4 - 0
panda/src/putil/bamEnums.h

@@ -59,6 +59,10 @@ PUBLISHED:
     // May appear at any level and indicates the following datagram contains
     // May appear at any level and indicates the following datagram contains
     // auxiliary file data that may be referenced by a later object.
     // auxiliary file data that may be referenced by a later object.
     BOC_file_data,
     BOC_file_data,
+
+    // Indicates that this datagram should be skipped in its entirety, likely
+    // used for an extension to the bam format.
+    BOC_ignore,
   };
   };
 
 
   // This enum is used to control how textures are written to a bam stream.
   // This enum is used to control how textures are written to a bam stream.

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

@@ -308,6 +308,29 @@ read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr) {
   }
   }
 }
 }
 
 
+/**
+ * Like read_object(), but does not return the object.
+ */
+bool BamReader::
+skip_object() {
+  nassertr(_num_extra_objects == 0, false);
+
+  int start_level = _nesting_level;
+
+  int object_id = p_read_object();
+
+  while (_num_extra_objects > 0) {
+    p_read_object();
+    _num_extra_objects--;
+  }
+
+  while (_nesting_level > start_level) {
+    p_read_object();
+  }
+
+  return object_id != 0;
+}
+
 /**
 /**
  * This may be called at any time during processing of the Bam file to resolve
  * This may be called at any time during processing of the Bam file to resolve
  * all the known pointers so far.  It is usually called at the end of the
  * all the known pointers so far.  It is usually called at the end of the
@@ -1111,6 +1134,10 @@ p_read_object() {
 
 
     return p_read_object();
     return p_read_object();
 
 
+  case BOC_ignore:
+    // Ignore this datagram.
+    return p_read_object();
+
   default:
   default:
     bam_cat.error()
     bam_cat.error()
       << "Encountered invalid BamObjectCode 0x" << std::hex << (int)boc << std::dec << ".\n";
       << "Encountered invalid BamObjectCode 0x" << std::hex << (int)boc << std::dec << ".\n";

+ 1 - 0
panda/src/putil/bamReader.h

@@ -134,6 +134,7 @@ PUBLISHED:
 
 
   BLOCKING TypedWritable *read_object();
   BLOCKING TypedWritable *read_object();
   BLOCKING bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr);
   BLOCKING bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr);
+  BLOCKING bool skip_object();
 
 
   INLINE bool is_eof() const;
   INLINE bool is_eof() const;
   bool resolve();
   bool resolve();