Browse Source

a bit more .pz support

David Rose 20 years ago
parent
commit
6d0b7f4344

+ 12 - 0
pandatool/src/converter/somethingToEggConverter.cxx

@@ -93,6 +93,18 @@ get_additional_extensions() const {
   return string();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: SomethingToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool SomethingToEggConverter::
+supports_compressed() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: SomethingToEggConverter::get_input_units
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/converter/somethingToEggConverter.h

@@ -106,6 +106,7 @@ public:
   virtual string get_name() const=0;
   virtual string get_extension() const=0;
   virtual string get_additional_extensions() const;
+  virtual bool supports_compressed() const;
 
   virtual bool convert_file(const Filename &filename)=0;
   virtual DistanceUnit get_input_units();

+ 25 - 5
pandatool/src/dxf/dxfFile.cxx

@@ -18,6 +18,7 @@
 
 #include "dxfFile.h"
 #include "string_utils.h"
+#include "virtualFileSystem.h"
 
 DXFFile::Color DXFFile::_colors[DXF_num_colors] = {
   { 1, 1, 1 },        // Color 0 is not used.
@@ -286,6 +287,8 @@ DXFFile::Color DXFFile::_colors[DXF_num_colors] = {
 ////////////////////////////////////////////////////////////////////
 DXFFile::
 DXFFile() {
+  _in = NULL;
+  _owns_in = false;
   _layer = NULL;
   reset_entity();
   _color_index = -1;
@@ -298,6 +301,10 @@ DXFFile() {
 ////////////////////////////////////////////////////////////////////
 DXFFile::
 ~DXFFile() {
+  if (_owns_in) {
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+    vfs->close_read_file(_in);
+  }
 }
 
 
@@ -310,19 +317,32 @@ DXFFile::
 void DXFFile::
 process(Filename filename) {
   filename.set_text();
-  filename.open_read(_in_file);
-  process(_in_file);
+
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  istream *in = vfs->open_read_file(filename, true);
+  if (in == (istream *)NULL) {
+    return;
+  }
+  process(in, true);
 }
 
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXFFile::process
 //       Access: Public
-//  Description: Reads the indicated stream as a DXF file.
+//  Description: Reads the indicated stream as a DXF file.  If owns_in
+//               is true, then the istream will be deleted via
+//               vfs->close_read_file() when the DXFFile object
+//               destructs.
 ////////////////////////////////////////////////////////////////////
 void DXFFile::
-process(istream &in) {
-  _in = ∈
+process(istream *in, bool owns_in) {
+  if (_owns_in) {
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+    vfs->close_read_file(_in);
+  }
+  _in = in;
+  _owns_in = owns_in;
   _state = ST_top;
 
   begin_file();

+ 2 - 2
pandatool/src/dxf/dxfFile.h

@@ -46,7 +46,7 @@ public:
   virtual ~DXFFile();
 
   void process(Filename filename);
-  void process(istream &in);
+  void process(istream *in, bool owns_in);
 
   // These functions are called as the file is processed.  These are
   // the main hooks for redefining how the class should dispense its
@@ -151,7 +151,7 @@ protected:
   LMatrix4d _ocs2wcs;
 
   istream *_in;
-  ifstream _in_file;
+  bool _owns_in;
 
   int _code;
   string _string;

+ 15 - 3
pandatool/src/dxfegg/dxfToEggConverter.cxx

@@ -82,6 +82,18 @@ get_extension() const {
   return "dxf";
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXFToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool DXFToEggConverter::
+supports_compressed() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXFToEggConverter::convert_file
 //       Access: Public, Virtual
@@ -144,10 +156,10 @@ done_entity() {
     // same).  We'll add the vertices to our list of vertices and then
     // define the polygon.
     _verts.clear();
-    _verts.push_back(DXFVertex(_p));
-    _verts.push_back(DXFVertex(_q));
-    _verts.push_back(DXFVertex(_r));
     _verts.push_back(DXFVertex(_s));
+    _verts.push_back(DXFVertex(_r));
+    _verts.push_back(DXFVertex(_q));
+    _verts.push_back(DXFVertex(_p));
     
     nassertv(_layer!=NULL);
     ((DXFToEggLayer *)_layer)->add_polygon(this);

+ 1 - 0
pandatool/src/dxfegg/dxfToEggConverter.h

@@ -39,6 +39,7 @@ public:
 
   virtual string get_name() const;
   virtual string get_extension() const;
+  virtual bool supports_compressed() const;
 
   virtual bool convert_file(const Filename &filename);
 

+ 3 - 3
pandatool/src/dxfegg/dxfToEggLayer.cxx

@@ -57,9 +57,9 @@ add_polygon(const DXFToEggConverter *entity) {
   const DXFFile::Color &color = entity->get_color();
   poly->set_color(Colorf(color.r, color.g, color.b, 1.0));
 
-  // A polyline's vertices are stored in the attached vector by dxf.C.
-  // They were defined in the DXF file using a series of "VERTEX"
-  // entries.
+  // A polyline's vertices are stored in the attached vector by
+  // dxf.cxx.  They were defined in the DXF file using a series of
+  // "VERTEX" entries.
 
   // For a 3dface, the vertices are defined explicitly as part of the
   // entity; but in this case, they were added to the vector before

+ 2 - 0
pandatool/src/flt/Sources.pp

@@ -1,3 +1,5 @@
+#define USE_PACKAGES zlib
+
 #begin ss_lib_target
   #define TARGET flt
   #define LOCAL_LIBS converter pandatoolbase

+ 17 - 5
pandatool/src/flt/fltHeader.cxx

@@ -21,8 +21,9 @@
 #include "fltRecordWriter.h"
 #include "fltUnsupportedRecord.h"
 #include "config_flt.h"
-
+#include "zStream.h"
 #include "nearly_zero.h"
+#include "virtualFileSystem.h"
 
 #include <assert.h>
 #include <math.h>
@@ -222,13 +223,15 @@ read_flt(Filename filename) {
   filename.set_binary();
   _flt_filename = filename;
 
-  ifstream in;
-  if (!filename.open_read(in)) {
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  istream *in = vfs->open_read_file(filename, true);
+  if (in == (istream *)NULL) {
     assert(!flt_error_abort);
     return FE_could_not_open;
   }
-
-  return read_flt(in);
+  FltError result = read_flt(*in);
+  vfs->close_read_file(in);
+  return result;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -280,6 +283,15 @@ write_flt(Filename filename) {
     return FE_could_not_open;
   }
 
+#ifdef HAVE_ZLIB
+  if (filename.get_extension() == "pz") {
+    // The filename ends in .pz, which means to automatically compress
+    // the flt file that we write.
+    OCompressStream compressor(&out, false);
+    return write_flt(compressor);
+  }
+#endif  // HAVE_ZLIB
+
   return write_flt(out);
 }
 

+ 12 - 0
pandatool/src/fltegg/fltToEggConverter.cxx

@@ -107,6 +107,18 @@ get_extension() const {
   return "flt";
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: FltToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool FltToEggConverter::
+supports_compressed() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: FltToEggConverter::convert_file
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/fltegg/fltToEggConverter.h

@@ -63,6 +63,7 @@ public:
 
   virtual string get_name() const;
   virtual string get_extension() const;
+  virtual bool supports_compressed() const;
 
   virtual bool convert_file(const Filename &filename);
   virtual DistanceUnit get_input_units();

+ 15 - 9
pandatool/src/lwo/iffInputFile.cxx

@@ -18,9 +18,9 @@
 
 #include "iffInputFile.h"
 #include "iffGenericChunk.h"
-
 #include "datagram.h"
 #include "datagramIterator.h"
+#include "virtualFileSystem.h"
 
 TypeHandle IffInputFile::_type_handle;
 
@@ -46,7 +46,8 @@ IffInputFile() {
 IffInputFile::
 ~IffInputFile() {
   if (_owns_istream) {
-    delete _input;
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+    vfs->close_read_file(_input);
   }
 }
 
@@ -59,13 +60,16 @@ IffInputFile::
 bool IffInputFile::
 open_read(Filename filename) {
   filename.set_binary();
-  ifstream *in = new ifstream;
-  if (filename.open_read(*in)) {
-    set_input(in, true);
-    set_filename(filename);
-    return true;
+
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  istream *in = vfs->open_read_file(filename, true);
+  if (in == (istream *)NULL) {
+    return false;
   }
 
+  set_input(in, true);
+  set_filename(filename);
+
   return false;
 }
 
@@ -74,12 +78,14 @@ open_read(Filename filename) {
 //       Access: Public
 //  Description: Sets up the input to use an arbitrary istream.  If
 //               owns_istream is true, the istream will be deleted
-//               when the IffInputFile destructs.
+//               (via vfs->close_read_file()) when the IffInputFile
+//               destructs.
 ////////////////////////////////////////////////////////////////////
 void IffInputFile::
 set_input(istream *input, bool owns_istream) {
   if (_owns_istream) {
-    delete _input;
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+    vfs->close_read_file(_input);
   }
   _input = input;
   _owns_istream = owns_istream;

+ 12 - 0
pandatool/src/lwoegg/lwoToEggConverter.cxx

@@ -101,6 +101,18 @@ get_extension() const {
   return "lwo";
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LwoToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool LwoToEggConverter::
+supports_compressed() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LwoToEggConverter::convert_file
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/lwoegg/lwoToEggConverter.h

@@ -55,6 +55,7 @@ public:
 
   virtual bool convert_file(const Filename &filename);
   bool convert_lwo(const LwoHeader *lwo_header);
+  virtual bool supports_compressed() const;
 
   CLwoLayer *get_layer(int number) const;
   CLwoClip *get_clip(int number) const;

+ 12 - 0
pandatool/src/ptloader/loaderFileTypePandatool.cxx

@@ -79,6 +79,18 @@ get_additional_extensions() const {
   return _converter->get_additional_extensions();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LoaderFileTypePandatool::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool LoaderFileTypePandatool::
+supports_compressed() const {
+  return _converter->supports_compressed();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LoaderFileTypePandatool::resolve_filename
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/ptloader/loaderFileTypePandatool.h

@@ -40,6 +40,7 @@ public:
   virtual string get_name() const;
   virtual string get_extension() const;
   virtual string get_additional_extensions() const;
+  virtual bool supports_compressed() const;
 
   virtual void resolve_filename(Filename &path) const;
   virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options) const;

+ 8 - 5
pandatool/src/vrml/parse_vrml.cxx

@@ -33,6 +33,7 @@
 #include "vrmlNode.h"
 #include "standard_nodes.h"
 #include "zStream.h"
+#include "virtualFileSystem.h"
 
 extern int vrmlyyparse();
 extern void vrmlyyResetLineNumber();
@@ -87,13 +88,15 @@ get_standard_nodes() {
 VrmlScene *
 parse_vrml(Filename filename) {
   filename.set_text();
-  ifstream infile;
-  if (!filename.open_read(infile)) {
-    cerr << "Error, couldn't open " << filename << "\n";
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  istream *in = vfs->open_read_file(filename, true);
+  if (in == (istream *)NULL) {
+    nout << "Cannot open " << filename << " for reading.\n";
     return NULL;
   }
-
-  return parse_vrml(infile, filename);
+  VrmlScene *result = parse_vrml(*in, filename);
+  vfs->close_read_file(in);
+  return result;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 12 - 0
pandatool/src/vrmlegg/vrmlToEggConverter.cxx

@@ -89,6 +89,18 @@ get_extension() const {
   return "wrl";
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: VRMLToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool VRMLToEggConverter::
+supports_compressed() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: VRMLToEggConverter::convert_file
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/vrmlegg/vrmlToEggConverter.h

@@ -45,6 +45,7 @@ public:
 
   virtual string get_name() const;
   virtual string get_extension() const;
+  virtual bool supports_compressed() const;
 
   virtual bool convert_file(const Filename &filename);
 

+ 2 - 0
pandatool/src/xfile/Sources.pp

@@ -1,6 +1,8 @@
 #define YACC_PREFIX xyy
 #define LFLAGS -i
 
+#define USE_PACKAGES zlib
+
 #begin ss_lib_target
   #define TARGET xfile
   #define LOCAL_LIBS pandatoolbase

+ 9 - 0
pandatool/src/xfile/xFile.cxx

@@ -161,6 +161,15 @@ write(Filename filename) const {
     return false;
   }
 
+#ifdef HAVE_ZLIB
+  if (filename.get_extension() == "pz") {
+    // The filename ends in .pz, which means to automatically compress
+    // the X file that we write.
+    OCompressStream compressor(&out, false);
+    return write(compressor);
+  }
+#endif  // HAVE_ZLIB
+
   return write(out);
 }
 

+ 12 - 0
pandatool/src/xfileegg/xFileToEggConverter.cxx

@@ -101,6 +101,18 @@ get_extension() const {
   return "x";
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: XFileToEggConverter::supports_compressed
+//       Access: Published, Virtual
+//  Description: Returns true if this file type can transparently load
+//               compressed files (with a .pz extension), false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+bool XFileToEggConverter::
+supports_compressed() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: XFileToEggConverter::convert_file
 //       Access: Public, Virtual

+ 1 - 0
pandatool/src/xfileegg/xFileToEggConverter.h

@@ -53,6 +53,7 @@ public:
 
   virtual string get_name() const;
   virtual string get_extension() const;
+  virtual bool supports_compressed() const;
 
   virtual bool convert_file(const Filename &filename);
   void close();