Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
6f9ffaaf6b

+ 1 - 1
pandatool/src/egg-palettize/Sources.pp

@@ -10,7 +10,7 @@
   #define SOURCES \
     attribFile.cxx attribFile.h config_egg_palettize.cxx \
     eggPalettize.cxx eggPalettize.h \
-    imageFile.cxx imageFile.h palette.cxx palette.h paletteGroup.cxx \
+    palette.cxx palette.h paletteGroup.cxx \
     paletteGroup.h pTexture.cxx pTexture.h sourceEgg.cxx \
     sourceEgg.h string_utils.cxx string_utils.h \
     textureEggRef.cxx textureEggRef.h textureOmitReason.h \

+ 19 - 1
pandatool/src/egg-palettize/attribFile.cxx

@@ -29,9 +29,12 @@ AttribFile(const Filename &filename) {
   _pi_filename.set_extension("pi");
   _txa_fd = -1;
 
+  _default_group = (PaletteGroup *)NULL;
+
   _optimal = false;
   _txa_needs_rewrite = false;
 
+  _map_dirname = "%s";
   _pal_xsize = 512;
   _pal_ysize = 512;
   _default_margin = 2;
@@ -177,6 +180,18 @@ get_group(const string &group_name) {
   return new_group;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AttribFile::set_default_group
+//       Access: Public
+//  Description: Sets the PaletteGroup that should be associated
+//               with any textures or egg files not explicitly placed
+//               in a different group.
+////////////////////////////////////////////////////////////////////
+void AttribFile::
+set_default_group(PaletteGroup *default_group) {
+  _default_group = default_group;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AttribFile::get_default_group
 //       Access: Public
@@ -186,7 +201,10 @@ get_group(const string &group_name) {
 ////////////////////////////////////////////////////////////////////
 PaletteGroup *AttribFile::
 get_default_group() {
-  return get_group(_name);
+  if (_default_group == (PaletteGroup *)NULL) {
+    _default_group = get_group(_name);
+  }
+  return _default_group;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 4 - 1
pandatool/src/egg-palettize/attribFile.h

@@ -40,6 +40,7 @@ public:
   void update_params(EggPalettize *prog);
 
   PaletteGroup *get_group(const string &group_name);
+  void set_default_group(PaletteGroup *default_group);
   PaletteGroup *get_default_group();
 
   void get_egg_group_requests();
@@ -116,13 +117,15 @@ private:
   Filename _txa_filename;
   Filename _pi_filename;
 
+  PaletteGroup *_default_group;
+
 public:
   // These parameter values come from the command line, or from the
   // .pi file if omitted from the command line.  These are the
   // parameter values that specifically refer to textures and
   // palettes, and thus should be stored in the .pi file for future
   // reference.
-  Filename _map_dirname;
+  string _map_dirname;
   int _pal_xsize, _pal_ysize;
   int _default_margin;
   bool _force_power_2;

+ 31 - 10
pandatool/src/egg-palettize/eggPalettize.cxx

@@ -51,22 +51,35 @@ EggPalettize() : EggMultiFilter(true) {
      "Do not process anything, but report statistics on all palette "
      "information files read.",
      &EggPalettize::dispatch_none, &_statistics_only);
-  redescribe_option
-    ("d",
+
+  // We redefine -d using add_option() instead of redescribe_option()
+  // so it gets listed along with these other options that relate.
+  add_option
+    ("d", "dirname", 0, 
      "The directory in which to write the palettized egg files.  This is "
      "only necessary if more than one egg file is processed at the same "
      "time; if it is included, each egg file will be processed and written "
-     "into the indicated directory.");
+     "into the indicated directory.",
+     &EggPalettize::dispatch_filename, &_got_output_dirname, &_output_dirname);
   add_option
     ("dm", "dirname", 0, 
      "The directory in which to place all maps: generated palettes, "
      "as well as images which were not placed on palettes "
-     "(but may have been resized).  It is often best if this is a "
-     "fully-qualified directory name rather than a relative directory name, "
-     "particularly if -d is used to write the egg files to a directory "
-     "different than the current directory, as the same name is written "
-     "into the egg files.",
-     &EggPalettize::dispatch_filename, &_got_map_dirname, &_map_dirname);
+     "(but may have been resized).  If this contains the string %s, "
+     "this will be replaced with the \"dir\" string associated with a "
+     "palette group.",
+     &EggPalettize::dispatch_string, &_got_map_dirname, &_map_dirname);
+  add_option
+    ("g", "group", 0, 
+     "The default palette group that egg files will be assigned to if they "
+     "are not explicitly assigned to any other group.",
+     &EggPalettize::dispatch_string, &_got_default_groupname, &_default_groupname);
+  add_option
+    ("gdir", "name", 0, 
+     "The \"dir\" string to associate with the default palette group "
+     "specified with -g, if no other dir name is given in the .txa file.",
+     &EggPalettize::dispatch_string, &_got_default_groupdir, &_default_groupdir);
+  
   add_option
     ("f", "", 0, 
      "Force an optimal packing.  By default, textures are added to "
@@ -127,7 +140,7 @@ EggPalettize() : EggMultiFilter(true) {
   add_option
     ("2", "", 0, 
      "Force textures that have been left out of the palette to a size "
-     "which is an even power of 2.  They will be scaled down to "
+     "which is an integer power of 2.  They will be scaled down to "
      "achieve this.",
      &EggPalettize::dispatch_none, &_got_force_power_2);
   add_option
@@ -534,6 +547,14 @@ run() {
   for (afi = _attrib_files.begin(); afi != _attrib_files.end(); ++afi) {
     AttribFile &af = *(*afi);
 
+    if (_got_default_groupname) {
+      PaletteGroup *group = af.get_group(_default_groupname);
+      if (_got_default_groupdir) {
+	group->set_dirname(_default_groupdir);
+      }
+      af.set_default_group(group);
+    }
+
     if (!af.grab_lock()) {
       // Failing to grab the write lock on the attribute file is a
       // fatal error.

+ 5 - 1
pandatool/src/egg-palettize/eggPalettize.h

@@ -38,8 +38,12 @@ public:
   // The following parameter values specifically relate to textures
   // and palettes.  These values are stored in the .pi file for future
   // reference.
-  Filename _map_dirname;
+  string _map_dirname;
   bool _got_map_dirname;
+  string _default_groupname;
+  bool _got_default_groupname;
+  string _default_groupdir;
+  bool _got_default_groupdir;
   int _pal_size[2];
   bool _got_palette_size;
   int _default_margin;

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

@@ -108,18 +108,6 @@ add_filename(const Filename &filename) {
   }
 }
 
-Filename PTexture::
-get_filename() const {
-  Filename filename = _name;
-  filename.set_dirname(_attrib_file->_map_dirname);
-  return filename;
-}
-
-Filename PTexture::
-get_basename() const {
-  return _name;
-}
-
 bool PTexture::
 get_size(int &xsize, int &ysize, int &zsize) {
   if (!_got_size) {

+ 2 - 5
pandatool/src/egg-palettize/pTexture.h

@@ -8,7 +8,7 @@
 
 #include <pandatoolbase.h>
 
-#include "imageFile.h"
+#include <filename.h>
 
 #include <set>
 #include <map>
@@ -27,7 +27,7 @@ class TextureEggRef;
 //               palettization on a number of different groups, but it
 //               must have the same size in each group.
 ////////////////////////////////////////////////////////////////////
-class PTexture : public ImageFile {
+class PTexture {
 public:
   PTexture(AttribFile *attrib_file, const Filename &name);
   ~PTexture();
@@ -36,9 +36,6 @@ public:
   
   void add_filename(const Filename &filename);
 
-  virtual Filename get_filename() const;
-  virtual Filename get_basename() const;
-
   bool get_size(int &xsize, int &ysize, int &zsize);
   void set_size(int xsize, int ysize, int zsize);
 

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

@@ -332,7 +332,7 @@ finalize_palette() {
     sprintf(index_str, "%03d", _index);
     _basename = _group->get_name() + "-palette." + index_str + ".rgb";
 
-    Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
+    Filename dirname = _group->get_full_dirname(_attrib_file);
     _filename = _basename;
     _filename.set_dirname(dirname.get_fullpath());
   } else {
@@ -387,6 +387,7 @@ generate_image() {
   }
 
   nout << "Writing " << _filename << "\n";
+  _filename.make_dir();
   if (!palette.write(_filename)) {
     nout << "Error in writing.\n";
     okflag = false;

+ 3 - 5
pandatool/src/egg-palettize/palette.h

@@ -8,8 +8,6 @@
 
 #include <pandatoolbase.h>
 
-#include "imageFile.h"
-
 #include <filename.h>
 
 #include <vector>
@@ -28,7 +26,7 @@ class AttribFile;
 //               depending on the number and size of the palettized
 //               textures.
 ////////////////////////////////////////////////////////////////////
-class Palette : public ImageFile {
+class Palette {
 public:
   Palette(const Filename &filename, PaletteGroup *group,
 	  int xsize, int ysize, int components, AttribFile *attrib_file);
@@ -36,8 +34,8 @@ public:
 	  int xsize, int ysize, int components, AttribFile *attrib_file);
   ~Palette();
 
-  virtual Filename get_filename() const;
-  virtual Filename get_basename() const;
+  Filename get_filename() const;
+  Filename get_basename() const;
 
   PaletteGroup *get_group() const;
 

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

@@ -8,6 +8,8 @@
 #include "palette.h"
 #include "attribFile.h"
 
+#include <stdio.h> // for sprintf()
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PaletteGroup::Constructor
 //       Access: Public
@@ -89,6 +91,20 @@ set_dirname(const string &dirname) {
   _dirname = dirname;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PaletteGroup::get_full_dirname
+//       Access: Public
+//  Description: Computes the actual directory name to which palettes
+//               and textures should be written, based on
+//               get_dirname() and on the -dm parameter.
+////////////////////////////////////////////////////////////////////
+string PaletteGroup::
+get_full_dirname(AttribFile *attrib_file) const {
+  char buffer[4096];
+  sprintf(buffer, attrib_file->_map_dirname.c_str(), _dirname.c_str());
+  return buffer;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PaletteGroup::pack_texture
 //       Access: Public

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

@@ -54,6 +54,8 @@ public:
   const string &get_dirname() const;
   void set_dirname(const string &dirname);
 
+  string get_full_dirname(AttribFile *attrib_file) const;
+
   bool pack_texture(TexturePacking *packing, AttribFile *attrib_file);
   bool generate_palette_images();
   void optimal_resize();

+ 1 - 1
pandatool/src/egg-palettize/sourceEgg.cxx

@@ -271,7 +271,7 @@ update_trefs() {
 	  packing->get_omit() != OR_none) {
 	// This texture wasn't palettized, so just rename the
 	// reference to the new one.
-	eggtex->set_fullpath(texture->get_filename());
+	eggtex->set_fullpath(packing->get_new_filename());
 
       } else {
 	// This texture was palettized, so redirect the tref to point

+ 16 - 5
pandatool/src/egg-palettize/texturePacking.cxx

@@ -413,12 +413,12 @@ needs_refresh() {
 
     } else {
       // Compare to the resized file.
-      target_filename = _texture->get_filename();
+      target_filename = get_new_filename();
     }
 
     if (!any_change) {
       any_change = 
-	(target_filename.compare_timestamps(_texture->_filename, true, false) < 0);
+	(target_filename.compare_timestamps(get_old_filename(), true, false) < 0);
     }
   }
 
@@ -472,11 +472,21 @@ write_unplaced(ostream &out) const {
 ////////////////////////////////////////////////////////////////////
 Filename TexturePacking::
 get_new_filename() const {
-  Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
+  Filename dirname = _group->get_full_dirname(_attrib_file);
   Filename new_filename(dirname, _texture->get_name());
   return new_filename;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePacking::get_old_filename
+//       Access: Public
+//  Description: Returns the original filename of this texture.
+////////////////////////////////////////////////////////////////////
+Filename TexturePacking::
+get_old_filename() const {
+  return _texture->_filename;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: TexturePacking::transfer
 //       Access: Public
@@ -491,7 +501,7 @@ bool TexturePacking::
 transfer() {
   bool okflag = true;
 
-  Filename old_filename = _texture->_filename;
+  Filename old_filename = get_old_filename();
   Filename new_filename = get_new_filename();
   if (new_filename == old_filename) {
     nout << "*** Texture " << _texture->get_name()
@@ -541,7 +551,8 @@ transfer() {
 	   << " (size " << nx << " " << ny << ")\n";
     }
   }
-    
+  
+  new_filename.make_dir();
   if (!image->write(new_filename)) {
     nout << "Error in writing.\n";
     okflag = false;

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

@@ -61,6 +61,7 @@ public:
   void write_unplaced(ostream &out) const;
 
   Filename get_new_filename() const;
+  Filename get_old_filename() const;
   bool transfer();
 
 private:

+ 1 - 0
pandatool/src/eggbase/eggMultiFilter.cxx

@@ -153,6 +153,7 @@ write_eggs() {
     }
 
     nout << "Writing " << filename << "\n";
+    filename.make_dir();
     if (!data->write_egg(filename)) {
       // Error writing an egg file; abort.
       exit(1);

+ 1 - 0
pandatool/src/eggbase/eggWriter.cxx

@@ -96,6 +96,7 @@ get_output() {
     } else {
       // Attempt to open the named file.
       unlink(_output_filename.c_str());
+      _output_filename.make_dir();
       if (!_output_filename.open_write(_output_stream)) {
 	nout << "Unable to write to " << _output_filename << "\n";
 	exit(1);