Prechádzať zdrojové kódy

*** empty log message ***

David Rose 25 rokov pred
rodič
commit
2bf0a7c7b6

+ 1 - 1
panda/src/audio/Sources.pp

@@ -24,7 +24,7 @@
     audio_trait.h audio_mikmod_traits.h \
     audio_win_traits.I audio_win_traits.h audio_null_traits.I \
     audio_null_traits.h audio_linux_traits.I audio_linux_traits.h \
-    audio_music.I config_audio.h audio_manager.I audio_sound.h audio_sound.I
+    config_audio.h audio_manager.I audio_sound.h audio_sound.I
 
   #define IGATESCAN audio.h
 

+ 1 - 1
panda/src/express/datagramGenerator.h

@@ -20,7 +20,7 @@ public:
   INLINE DatagramGenerator();
   virtual ~DatagramGenerator();
   
-  virtual bool get_datagram(Datagram& dataBlock) = 0;
+  virtual bool get_datagram(Datagram &data) = 0;
   virtual bool is_eof() = 0;
   virtual bool is_error() = 0;
 };

+ 42 - 0
panda/src/express/datagramInputFile.I

@@ -0,0 +1,42 @@
+// Filename: datagramInputFile.I
+// Created by:  drose (30Oct00)
+// 
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE DatagramInputFile::
+DatagramInputFile() {
+  _error = true;
+  _read_first_datagram = false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::open
+//       Access: Public
+//  Description: Opens the indicated filename for reading.  Returns
+//               true if successful, false on failure.
+////////////////////////////////////////////////////////////////////
+INLINE bool DatagramInputFile::
+open(Filename filename) {
+  // DatagramInputFiles are always binary.
+  _read_first_datagram = false;
+  _error = false;
+  filename.set_binary();
+  return filename.open_read(_in);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::close
+//       Access: Public
+//  Description: Closes the file.  This is also implicitly done when
+//               the DatagramInputFile destructs.
+////////////////////////////////////////////////////////////////////
+INLINE void DatagramInputFile::
+close() {
+  _in.close();
+}

+ 84 - 0
panda/src/express/datagramInputFile.cxx

@@ -0,0 +1,84 @@
+// Filename: datagramInputFile.h
+// Created by:  drose (30Oct00)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "datagramInputFile.h"
+#include "numeric_types.h"
+#include "datagramIterator.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::read_header
+//       Access: Public
+//  Description: Reads a sequence of bytes from the beginning of the
+//               datagram file.  This may be called any number of
+//               times after the file has been opened and before the
+//               first datagram is written.  It may not be called once
+//               the first datagram is written.
+////////////////////////////////////////////////////////////////////
+bool DatagramInputFile::
+read_header(string &header, size_t num_bytes) {
+  nassertr(!_read_first_datagram, false);
+
+  char *buffer = (char *)alloca(num_bytes);
+  nassertr(buffer != (char *)NULL, false);
+
+  _in.read(buffer, num_bytes);
+  if (_in.fail() || _in.eof()) {
+    return false;
+  }
+
+  header = string(buffer, num_bytes);
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::get_datagram
+//       Access: Public, Virtual
+//  Description: Reads the next datagram from the file.  Returns true
+//               on success, false if there is an error or end of
+//               file.
+////////////////////////////////////////////////////////////////////
+bool DatagramInputFile::
+get_datagram(Datagram &data) {
+  _read_first_datagram = true;
+
+  // First, get the size of the upcoming datagram.  We do this with
+  // the help of a second datagram.
+  char sizebuf[sizeof(PN_uint32)];
+  _in.read(sizebuf, sizeof(PN_uint32));
+  if (_in.fail() || _in.eof()) {
+    return false;
+  }
+
+  Datagram size(sizebuf, sizeof(PN_uint32));
+  DatagramIterator di(size);
+  PN_uint32 num_bytes = di.get_uint32();
+
+  // Now, read the datagram itself.
+  char *buffer = (char *)alloca(num_bytes);
+  nassertr(buffer != (char *)NULL, false);
+
+  _in.read(buffer, num_bytes);
+  if (_in.fail() || _in.eof()) {
+    _error = true;
+    return false;
+  }
+
+  data = Datagram(buffer, num_bytes);
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramInputFile::is_error
+//       Access: Public, Virtual
+//  Description: Returns true if the file has reached an error
+//               condition.
+////////////////////////////////////////////////////////////////////
+bool DatagramInputFile::
+is_error() {
+  if (_in.fail()) {
+    _error = true;
+  }
+  return _error;
+}

+ 41 - 0
panda/src/express/datagramInputFile.h

@@ -0,0 +1,41 @@
+// Filename: datagramInputFile.h
+// Created by:  drose (30Oct00)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef DATAGRAMINPUTFILE_H
+#define DATAGRAMINPUTFILE_H
+
+#include <pandabase.h>
+
+#include "datagramGenerator.h"
+#include "filename.h"
+
+////////////////////////////////////////////////////////////////////
+// 	 Class : DatagramInputFile
+// Description : This class can be used to read a binary file that
+//               consists of an arbitrary header followed by a number
+//               of datagrams.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAEXPRESS DatagramInputFile : public DatagramGenerator {
+public:
+  INLINE DatagramInputFile();
+
+  INLINE bool open(Filename filename);
+
+  bool read_header(string &header, size_t num_bytes);
+  virtual bool get_datagram(Datagram &data);
+  virtual bool is_eof();
+  virtual bool is_error();
+
+  INLINE void close();
+
+private:
+  bool _read_first_datagram;
+  bool _error;
+  ifstream _in;
+};
+
+#include "datagramInputFile.I"
+
+#endif

+ 0 - 14
panda/src/express/datagramOutputFile.I

@@ -30,20 +30,6 @@ open(Filename filename) {
   return filename.open_write(_out);
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DatagramOutputFile::is_error
-//       Access: Public
-//  Description: Returns true if the file has reached an error
-//               condition.
-////////////////////////////////////////////////////////////////////
-INLINE bool DatagramOutputFile::
-is_error() {
-  if (_out.fail()) {
-    _error = true;
-  }
-  return _error;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DatagramOutputFile::close
 //       Access: Public

+ 59 - 0
panda/src/express/datagramOutputFile.cxx

@@ -0,0 +1,59 @@
+// Filename: datagramOutputFile.h
+// Created by:  drose (30Oct00)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "datagramOutputFile.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramOutputFile::write_header
+//       Access: Public
+//  Description: Writes a sequence of bytes to the beginning of the
+//               datagram file.  This may be called any number of
+//               times after the file has been opened and before the
+//               first datagram is written.  It may not be called once
+//               the first datagram is written.
+////////////////////////////////////////////////////////////////////
+bool DatagramOutputFile::
+write_header(const string &header) {
+  nassertr(!_wrote_first_datagram, false);
+
+  _out.write((void *)header.data(), header.size());
+  return !_out.fail();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramOutputFile::put_datagram
+//       Access: Public, Virtual
+//  Description: Writes the given datagram to the file.  Returns true
+//               on success, false if there is an error.
+////////////////////////////////////////////////////////////////////
+bool DatagramOutputFile::
+put_datagram(const Datagram &data) {
+  _wrote_first_datagram = true;
+
+  // First, write the size of the upcoming datagram.  We do this with
+  // the help of a second datagram.
+  Datagram size;
+  size.add_uint32(data.get_length());
+  _out.write(size.get_data(), size.get_length());
+
+  // Now, write the datagram itself.
+  _out.write(data.get_data(), data.get_length());
+
+  return !_out.fail();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DatagramOutputFile::is_error
+//       Access: Public, Virtual
+//  Description: Returns true if the file has reached an error
+//               condition.
+////////////////////////////////////////////////////////////////////
+bool DatagramOutputFile::
+is_error() {
+  if (_out.fail()) {
+    _error = true;
+  }
+  return _error;
+}

+ 40 - 0
panda/src/express/datagramOutputFile.h

@@ -0,0 +1,40 @@
+// Filename: datagramOutputFile.h
+// Created by:  drose (30Oct00)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef DATAGRAMOUTPUTFILE_H
+#define DATAGRAMOUTPUTFILE_H
+
+#include <pandabase.h>
+
+#include "datagramSink.h"
+#include "filename.h"
+
+////////////////////////////////////////////////////////////////////
+// 	 Class : DatagramOutputFile
+// Description : This class can be used to write a binary file that
+//               consists of an arbitrary header followed by a number
+//               of datagrams.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAEXPRESS DatagramOutputFile : public DatagramSink {
+public:
+  INLINE DatagramOutputFile();
+
+  INLINE bool open(Filename filename);
+
+  bool write_header(const string &header);
+  virtual bool put_datagram(const Datagram &data);
+  virtual bool is_error();
+
+  INLINE void close();
+
+private:
+  bool _wrote_first_datagram;
+  bool _error;
+  ofstream _out;
+};
+
+#include "datagramOutputFile.I"
+
+#endif

+ 2 - 1
panda/src/express/datagramSink.h

@@ -20,7 +20,8 @@ public:
   INLINE DatagramSink(void);
   virtual ~DatagramSink(void);
   
-  virtual bool put_datagram(const Datagram& dataBlock) = 0;
+  virtual bool put_datagram(const Datagram &data) = 0;
+  virtual bool is_error() = 0;
 };
 
 #include "datagramSink.I"

+ 6 - 1
panda/src/loader/bamFile.cxx

@@ -64,7 +64,12 @@ open_read(const Filename &filename, bool report_errors) {
     return false;
   }
 
-  string head = _din.read_header(_bam_header.size());
+  string head;
+  if (!_din.read_header(head, _bam_header.size())) {
+    loader_cat.error() << bam_filename << " is not a valid BAM file.\n";
+    return false;
+  }
+
   if (head != _bam_header) {
     loader_cat.error() << bam_filename << " is not a valid BAM file.\n";
     return false;