Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
8f268e22a5

+ 1 - 1
panda/src/downloader/crypto_utils.cxx

@@ -32,7 +32,7 @@ md5_a_file(const Filename &name, HashVal &ret) {
   ostringstream os;
   MD5 md5;
 
-  string fs = name.get_fullpath();
+  string fs = name.to_os_specific();
   FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os)));
 
   istringstream is(os.str());

+ 5 - 4
pandatool/src/egg-palettize/attribFile.cxx

@@ -529,13 +529,14 @@ transfer_unplaced_images(bool force_redo_all) {
       // maybe it's already there and hasn't changed recently.
       if (force_redo_all || packing->needs_refresh()) {
 	// Nope, needs to be updated.
-	okflag = texture->transfer() && okflag;
+	okflag = packing->transfer() && okflag;
       }
     } else {
       if (_aggressively_clean_mapdir && texture->is_unused()) {
-	if (texture->get_filename().exists()) {
-	  nout << "Deleting " << texture->get_filename() << "\n";
-	  texture->get_filename().unlink();
+	Filename new_filename = packing->get_new_filename();
+	if (new_filename.exists()) {
+	  nout << "Deleting " << new_filename << "\n";
+	  new_filename.unlink();
 	}
       }
     }

+ 0 - 71
pandatool/src/egg-palettize/pTexture.cxx

@@ -384,68 +384,6 @@ write_pathname(ostream &out) const {
   }
 }
 
-bool PTexture::
-transfer() {
-  bool okflag = true;
-
-  Filename new_filename = get_filename();
-  if (new_filename == _filename) {
-    nout << "*** PTexture " << _name << " is already in the map directory!\n"
-	 << "    Cannot modify texture in place!\n";
-    return false;
-  }
-
-  int nx, ny;
-  if (!get_req(nx, ny)) {
-    nout << "Unknown size for image " << _name << "\n";
-    nx = 16;
-    ny = 16;
-  }
-
-  if (_attrib_file->_force_power_2) {
-    int newx = to_power_2(nx);
-    int newy = to_power_2(ny);
-    if (newx != nx || newy != ny) {
-      nx = newx;
-      ny = newy;
-    }
-  }
- 
-  PNMImage *image = read_image();
-  if (image == NULL) {
-    nout << "*** Unable to read " << _name << "\n";
-    okflag = false;
-
-    // Create a solid red texture for images we can't read.
-    image = new PNMImage(nx, ny);
-    image->fill(1.0, 0.0, 0.0);
-
-  } else {
-    // Should we scale it?
-    if (nx != image->get_x_size() && ny != image->get_y_size()) {
-      nout << "Resizing " << new_filename << " to " 
-	   << nx << " " << ny << "\n";
-      PNMImage *new_image =
-	new PNMImage(nx, ny, image->get_color_type());
-      new_image->gaussian_filter_from(0.5, *image);
-      delete image;
-      image = new_image;
-      
-    } else {
-      nout << "Copying " << new_filename
-	   << " (size " << nx << " " << ny << ")\n";
-    }
-  }
-    
-  if (!image->write(new_filename)) {
-    nout << "Error in writing.\n";
-    okflag = false;
-  }
-  delete image;
-
-  return okflag;
-}
-
 PNMImage *PTexture::
 read_image() {
   if (!_got_filename || !_file_exists) {
@@ -504,12 +442,3 @@ read_image_header(const Filename &filename, int &xsize, int &ysize,
   zsize = header.get_num_channels();
   return true;
 }
-
-int PTexture::
-to_power_2(int value) {
-  int x = 1;
-  while ((x << 1) <= value) {
-    x = (x << 1);
-  }
-  return x;
-}

+ 0 - 3
pandatool/src/egg-palettize/pTexture.h

@@ -67,8 +67,6 @@ public:
   void write_size(ostream &out);
   void write_pathname(ostream &out) const;
 
-  bool transfer();
-
   PNMImage *read_image();
 
   typedef set<TextureEggRef *> Eggs;
@@ -79,7 +77,6 @@ private:
   void read_header();
   bool read_image_header(const Filename &filename, 
 			 int &xsize, int &ysize, int &zsize);
-  static int to_power_2(int value);
 
   Filename _name;
 

+ 3 - 1
pandatool/src/egg-palettize/palette.cxx

@@ -331,8 +331,10 @@ finalize_palette() {
     char index_str[128];
     sprintf(index_str, "%03d", _index);
     _basename = _group->get_name() + "-palette." + index_str + ".rgb";
+
+    Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
     _filename = _basename;
-    _filename.set_dirname(_attrib_file->_map_dirname);
+    _filename.set_dirname(dirname.get_fullpath());
   } else {
     _basename = _filename.get_basename();
   }

+ 22 - 0
pandatool/src/egg-palettize/paletteGroup.cxx

@@ -67,6 +67,28 @@ add_parent(PaletteGroup *parent) {
   _parents.push_back(parent);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PaletteGroup::get_dirname
+//       Access: Public
+//  Description: Returns the directory name to which palettes and
+//               textures associated with this group will be written.
+////////////////////////////////////////////////////////////////////
+const string &PaletteGroup::
+get_dirname() const {
+  return _dirname;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PaletteGroup::set_dirname
+//       Access: Public
+//  Description: Sets the directory name to which palettes and
+//               textures associated with this group will be written.
+////////////////////////////////////////////////////////////////////
+void PaletteGroup::
+set_dirname(const string &dirname) {
+  _dirname = dirname;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PaletteGroup::pack_texture
 //       Access: Public

+ 5 - 0
pandatool/src/egg-palettize/paletteGroup.h

@@ -51,6 +51,9 @@ public:
   PaletteGroup *get_parent(int n) const;
   void add_parent(PaletteGroup *parent);
 
+  const string &get_dirname() const;
+  void set_dirname(const string &dirname);
+
   bool pack_texture(TexturePacking *packing, AttribFile *attrib_file);
   bool generate_palette_images();
   void optimal_resize();
@@ -72,6 +75,8 @@ private:
 
   typedef vector<Palette *> Palettes;
   Palettes _palettes;
+
+  string _dirname;
 };
 
 

+ 104 - 0
pandatool/src/egg-palettize/texturePacking.cxx

@@ -9,6 +9,8 @@
 #include "palette.h"
 #include "pTexture.h"
 
+#include <pnmImage.h>
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: TexturePacking::Constructor
@@ -461,3 +463,105 @@ write_unplaced(ostream &out) const {
     out << "\n";
   }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePacking::get_new_filename
+//       Access: Public
+//  Description: Returns the filename to which this texture will be
+//               copied, assuming it is not placed on a palette.
+////////////////////////////////////////////////////////////////////
+Filename TexturePacking::
+get_new_filename() const {
+  Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
+  Filename new_filename(dirname, _texture->get_name());
+  return new_filename;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePacking::transfer
+//       Access: Public
+//  Description: Copies an unpalettized image to the install
+//               directory, if it is not already there.  The
+//               particular directory it is installed into may depend
+//               on the PaletteGroup to which it has been added.
+//               Returns true if successful, false if there is an
+//               error.
+////////////////////////////////////////////////////////////////////
+bool TexturePacking::
+transfer() {
+  bool okflag = true;
+
+  Filename old_filename = _texture->_filename;
+  Filename new_filename = get_new_filename();
+  if (new_filename == old_filename) {
+    nout << "*** Texture " << _texture->get_name()
+	 << " is already in the map directory!\n"
+	 << "    Cannot modify texture in place!\n";
+    return false;
+  }
+
+  int nx, ny;
+  if (!_texture->get_req(nx, ny)) {
+    nout << "Unknown size for image " << _texture->get_name() << "\n";
+    nx = 16;
+    ny = 16;
+  }
+
+  if (_attrib_file->_force_power_2) {
+    int newx = to_power_2(nx);
+    int newy = to_power_2(ny);
+    if (newx != nx || newy != ny) {
+      nx = newx;
+      ny = newy;
+    }
+  }
+ 
+  PNMImage *image = _texture->read_image();
+  if (image == NULL) {
+    nout << "*** Unable to read " << _texture->get_name() << "\n";
+    okflag = false;
+
+    // Create a solid red texture for images we can't read.
+    image = new PNMImage(nx, ny);
+    image->fill(1.0, 0.0, 0.0);
+
+  } else {
+    // Should we scale it?
+    if (nx != image->get_x_size() && ny != image->get_y_size()) {
+      nout << "Resizing " << new_filename << " to " 
+	   << nx << " " << ny << "\n";
+      PNMImage *new_image =
+	new PNMImage(nx, ny, image->get_color_type());
+      new_image->gaussian_filter_from(0.5, *image);
+      delete image;
+      image = new_image;
+      
+    } else {
+      nout << "Copying " << new_filename
+	   << " (size " << nx << " " << ny << ")\n";
+    }
+  }
+    
+  if (!image->write(new_filename)) {
+    nout << "Error in writing.\n";
+    okflag = false;
+  }
+  delete image;
+
+  return okflag;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePacking::to_power_2
+//       Access: Public, Static
+//  Description: Returns the largest power of 2 less than or equal to
+//               value.
+////////////////////////////////////////////////////////////////////
+int TexturePacking::
+to_power_2(int value) {
+  int x = 1;
+  while ((x << 1) <= value) {
+    x = (x << 1);
+  }
+  return x;
+}

+ 5 - 0
pandatool/src/egg-palettize/texturePacking.h

@@ -60,7 +60,12 @@ public:
 
   void write_unplaced(ostream &out) const;
 
+  Filename get_new_filename() const;
+  bool transfer();
+
 private:
+  static int to_power_2(int value);
+
   AttribFile *_attrib_file;
   PTexture *_texture;
   PaletteGroup *_group;

+ 35 - 7
pandatool/src/egg-palettize/userAttribLine.cxx

@@ -25,6 +25,8 @@ UserAttribLine(const string &cline, AttribFile *af) : _attrib_file(af) {
   // matches that line.
   _was_used = true;
 
+  _got_dirname = false;
+
   string line = cline;
 
   // First, strip off the comment.
@@ -108,9 +110,15 @@ write(ostream &out) const {
     break;
 
   case LT_group_relate:
-    out << ":group " << _names[0] << " with";
-    for (i = 1; i < (int)_names.size(); i++) {
-      out << " " << _names[i];
+    out << ":group " << _names[0];
+    if (!_got_dirname) {
+      out << " dir " << _dirname;
+    }
+    if (!_names.empty()) {
+      out << " with";
+      for (i = 1; i < (int)_names.size(); i++) {
+	out << " " << _names[i];
+      }
     }
     out << "\n";
     break;
@@ -333,14 +341,34 @@ keyword_line(const string &line) {
 
   } else if (words[0] == ":group") {
     _line_type = LT_group_relate;
-    if (words.size() < 4 || !(words[2] == "with")) {
-      nout << "Expected :group groupname with groupname [groupname ...].\n";
+    if (words.size() < 2) {
+      nout << "Expected :group name.\n";
       return false;
     }
+
     PaletteGroup *group = _attrib_file->get_group(words[1]);
 
-    for (int i = 3; i < (int)words.size(); i++) {
-      group->add_parent(_attrib_file->get_group(words[i]));
+    int kw = 2;
+    while (kw < (int)words.size()) {
+      if (words[kw] == "with") {
+	kw++;
+	
+	while (kw < (int)words.size()) {
+	  group->add_parent(_attrib_file->get_group(words[kw]));
+	  kw++;
+	}
+
+      } else if (words[kw] == "dir") {
+	kw++;
+	_got_dirname = true;
+	_dirname = words[kw];
+	group->set_dirname(_dirname);
+	kw++;
+
+      } else {
+	nout << "Invalid keyword: " << words[kw] << "\n";
+	return false;
+      }
     }
 
   } else {

+ 3 - 1
pandatool/src/egg-palettize/userAttribLine.h

@@ -29,7 +29,7 @@ class SourceEgg;
 //   # Comment
 //   :margin msize
 //   :palette xsize ysize 
-//   :group groupname with groupname [groupname ...]
+//   :group groupname [dir dirname] [with groupname [groupname ...]]
 //   texturename xsize ysize msize
 //   texturename [texturename ...] : xsize ysize [msize] [omit]
 //   texturename [texturename ...] : scale% [msize] [omit]
@@ -77,6 +77,8 @@ private:
   int _xsize, _ysize;
   double _scale_pct;
   int _msize;
+  string _dirname;
+  bool _got_dirname;
   bool _omit;
   bool _is_old_style;
   bool _was_used;