Browse Source

added -R to remove egg files

David Rose 24 years ago
parent
commit
4fbf974e3c

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

@@ -378,6 +378,22 @@ update_egg() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggFile::remove_egg
+//       Access: Public
+//  Description: Removes this egg file from all things that reference
+//               it, in preparation for removing it from the database.
+////////////////////////////////////////////////////////////////////
+void EggFile::
+remove_egg() {
+  Textures::iterator ti;
+  for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
+    TextureReference *reference = (*ti);
+    TexturePlacement *placement = reference->get_placement();
+    placement->remove_egg(reference);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggFile::read_egg
 //       Access: Public

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

@@ -59,6 +59,7 @@ public:
   bool has_data() const;
   
   void update_egg();
+  void remove_egg();
   bool read_egg();
   bool write_egg();
 

+ 40 - 1
pandatool/src/egg-palettize/eggPalettize.cxx

@@ -57,7 +57,7 @@ EggPalettize() : EggMultiFilter(true) {
   add_option
     ("a", "filename", 0, 
      "Read the indicated file as the .txa file.  The default is textures.txa.",
-     &EggPalettize::dispatch_filename, NULL, &_txa_filename);
+     &EggPalettize::dispatch_filename, &_got_txa_filename, &_txa_filename);
 
   add_option
     ("pi", "", 0, 
@@ -71,6 +71,12 @@ EggPalettize() : EggMultiFilter(true) {
      "and texture utilization.",
      &EggPalettize::dispatch_none, &_report_statistics);
 
+  add_option
+    ("R", "", 0, 
+     "Remove the named egg files from the previously-generated state data "
+     "in textures.boo.",
+     &EggPalettize::dispatch_none, &_remove_eggs);
+
   // We redefine -d using add_option() instead of redescribe_option()
   // so it gets listed along with these other options that relate.
   add_option
@@ -140,6 +146,10 @@ EggPalettize() : EggMultiFilter(true) {
      "may invalidate other egg files which share this palette.",
      &EggPalettize::dispatch_none, &_optimal);
 
+  // This isn't even implement yet.  Presently, we never lock anyway.
+  // Dangerous, but hard to implement reliable file locking across
+  // NFS/Samba and between multiple OS's.
+  /*
   add_option
     ("nolock", "", 0, 
      "Don't attempt to grab a file lock on the .txa file.  Use "
@@ -147,6 +157,8 @@ EggPalettize() : EggMultiFilter(true) {
      ".txa file may overwrite each other.  Use this only if the lock "
      "cannot be achieved for some reason.",
      &EggPalettize::dispatch_none, &_dont_lock_txa);
+  */
+
   add_option
     ("H", "", 0, 
      "Describe the syntax of the attributes file.",
@@ -171,6 +183,14 @@ handle_args(ProgramBase::Args &args) {
     exit(1);
   }
 
+  if (_remove_eggs) {
+    // If we're removing these egg files from the database, we don't
+    // want to try to load them up.  Instead, just save the filenames.
+    _remove_egg_list = args;
+    return true;
+  }
+
+  // Otherwise, load the named egg files up normally.
   return EggMultiFilter::handle_args(args);
 }
 
@@ -457,6 +477,17 @@ run() {
     loader_cat->set_severity(NS_warning);
   }
 
+  if (!_txa_filename.exists() && !_got_txa_filename) {
+    // If we did not specify a filename, and the default filename of
+    // "textures.txa" doesn't exist, try looking in src/maps, as
+    // another likely possibility.
+    Filename maybe = _txa_filename;
+    maybe.set_dirname("src/maps");
+    if (maybe.exists()) {
+      _txa_filename = maybe;
+    }
+  }
+
   if (!_txa_filename.exists()) {
     nout << FilenameUnifier::make_user_filename(_txa_filename)
 	 << " does not exist; cannot run.\n";
@@ -553,6 +584,14 @@ run() {
 
   pal->all_params_set();
 
+  // Remove any files named for removal.
+  Args::const_iterator ai;
+  for (ai = _remove_egg_list.begin(); ai != _remove_egg_list.end(); ++ai) {
+    Filename filename = (*ai);
+    pal->remove_egg_file(filename.get_basename());
+  }
+
+  // And process the egg files named for addition.
   Eggs::const_iterator ei;
   for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
     EggData *egg_data = (*ei);

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

@@ -28,6 +28,7 @@ public:
 
   // The following parameter values specifically relate to textures
   // and palettes.  These values are copied to the Palettizer.
+  bool _got_txa_filename;
   Filename _txa_filename;
   string _map_dirname;
   bool _got_map_dirname;
@@ -52,6 +53,8 @@ private:
   bool _dont_lock_txa;
 
   bool _describe_input_file;
+  bool _remove_eggs;
+  Args _remove_egg_list;
 };
 
 #endif

+ 24 - 2
pandatool/src/egg-palettize/palettizer.cxx

@@ -162,8 +162,10 @@ report_pi() const {
   Textures::const_iterator ti;
   for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
     TextureImage *texture = (*ti).second;
-    cout << "  " << texture->get_name() << ":\n";
-    texture->write_source_pathnames(cout, 4);
+    if (texture->is_used()) {
+      cout << "  " << texture->get_name() << ":\n";
+      texture->write_source_pathnames(cout, 4);
+    }
   }
 
   cout << "\negg files and textures referenced\n";
@@ -662,6 +664,26 @@ get_egg_file(const string &name) {
   return file;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Palettizer::remove_egg_file
+//       Access: Public
+//  Description: Removes the named egg file from the database, if it
+//               exists.  Returns true if the egg file was found,
+//               false if it was not.
+////////////////////////////////////////////////////////////////////
+bool Palettizer::
+remove_egg_file(const string &name) {
+  EggFiles::iterator ei = _egg_files.find(name);
+  if (ei != _egg_files.end()) {
+    EggFile *file = (*ei).second;
+    file->remove_egg();
+    _egg_files.erase(ei);
+    return true;
+  }
+
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Palettizer::get_palette_group
 //       Access: Public

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

@@ -48,6 +48,8 @@ public:
   bool write_eggs();
 
   EggFile *get_egg_file(const string &name);
+  bool remove_egg_file(const string &name);
+
   PaletteGroup *get_palette_group(const string &name);
   PaletteGroup *test_palette_group(const string &name) const;
   PaletteGroup *get_default_group();

+ 27 - 4
pandatool/src/egg-palettize/textureImage.cxx

@@ -385,6 +385,18 @@ is_surprise() const {
   return _is_surprise;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: TextureImage::is_used
+//       Access: Public
+//  Description: Returns true if this particular texture has been
+//               placed somewhere, anywhere, or false if it is not
+//               used.
+////////////////////////////////////////////////////////////////////
+bool TextureImage::
+is_used() const {
+  return !_placement.empty();
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: TextureImage::get_source
@@ -638,16 +650,27 @@ write_source_pathnames(ostream &out, int indent_level) const {
     for (ei = _egg_files.begin(); ei != _egg_files.end(); ++ei) {
       EggFile *egg = (*ei);
       indent(out, indent_level + 2)
-	<< egg->get_name() << " (" 
-	<< egg->get_explicit_groups() << ")\n";
+	<< egg->get_name() << " (";
+      if (egg->get_explicit_groups().empty()) {
+        out << *egg->get_default_group();
+      } else {
+        out << egg->get_explicit_groups();
+      }
+      out << ")\n";
     }
   }
   if (!_explicitly_assigned_groups.empty()) {
     indent(out, indent_level)
       << "Explicitly assigned to " << _explicitly_assigned_groups << " in .txa\n";
   }
-  indent(out, indent_level)
-    << "Assigned to " << _actual_assigned_groups << "\n";
+
+  if (_placement.empty()) {
+    indent(out, indent_level)
+      << "Not used.\n";
+  } else {
+    indent(out, indent_level)
+      << "Assigned to " << _actual_assigned_groups << "\n";
+  }
 }
 
 ////////////////////////////////////////////////////////////////////

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

@@ -57,6 +57,7 @@ public:
   double get_coverage_threshold() const;
   int get_margin() const;
   bool is_surprise() const;
+  bool is_used() const;
 
   SourceTextureImage *get_source(const Filename &filename, 
 				 const Filename &alpha_filename);

+ 11 - 2
pandatool/src/egg-palettize/texturePlacement.cxx

@@ -343,7 +343,6 @@ determine_size() {
 	    _position._max_uv[0] <= _placed._max_uv[0] &&
 	    _position._max_uv[1] <= _placed._max_uv[1]) {
 	  // No problem!  It fits here, so leave well enough alone.
-
 	} else {
 	  // That's not good enough either, so go back to rounding.
 	  compute_size_from_uvs(rounded_min_uv, rounded_max_uv);
@@ -682,7 +681,17 @@ write_placed(ostream &out, int indent_level) {
 	<< get_placed_x() << " " << get_placed_y() << " to "
 	<< get_placed_x() + get_placed_x_size() << " "
 	<< get_placed_y() + get_placed_y_size() << " (coverage "
-	<< get_placed_uv_area() << ")\n";
+	<< get_placed_uv_area() << ")";
+
+    if (_placed._wrap_u != EggTexture::WM_unspecified ||
+        _placed._wrap_v != EggTexture::WM_unspecified) {
+      if (_placed._wrap_u != _placed._wrap_v) {
+        out << " (" << _placed._wrap_u << ", " << _placed._wrap_v << ")";
+      } else {
+        out << " " << _placed._wrap_u;
+      }
+    }
+    out << "\n";
   } else {
     out << " not yet placed.\n";
   }

+ 9 - 0
pandatool/src/egg-palettize/textureReference.cxx

@@ -355,6 +355,15 @@ write(ostream &out, int indent_level) const {
     out << " coverage " << area;
   }
 
+  if (_wrap_u != EggTexture::WM_unspecified ||
+      _wrap_v != EggTexture::WM_unspecified) {
+    if (_wrap_u != _wrap_v) {
+      out << " (" << _wrap_u << ", " << _wrap_v << ")";
+    } else {
+      out << " " << _wrap_u;
+    }
+  }
+
   if (_properties._format != EggTexture::F_unspecified) {
     out << " " << _properties._format;
   }