From 389679a8e7c8a17075e1f7fca4681fda62421bf3 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 10 Nov 2000 01:58:40 +0000 Subject: [PATCH] *** empty log message *** --- pandatool/src/cvscopy/cvsSourceTree.cxx | 34 +--------- pandatool/src/cvscopy/cvsSourceTree.h | 1 - pandatool/src/egg-palettize/attribFile.cxx | 62 ++++++++++++++++--- pandatool/src/egg-palettize/attribFile.h | 22 ++++--- pandatool/src/egg-palettize/eggPalettize.cxx | 8 +-- pandatool/src/egg-palettize/pTexture.cxx | 4 +- pandatool/src/egg-palettize/pTexture.h | 2 +- pandatool/src/egg-palettize/paletteGroup.cxx | 27 ++++++-- pandatool/src/egg-palettize/paletteGroup.h | 3 +- pandatool/src/egg-palettize/sourceEgg.cxx | 36 +++++++++-- pandatool/src/egg-palettize/sourceEgg.h | 6 +- .../src/egg-palettize/texturePacking.cxx | 5 +- 12 files changed, 139 insertions(+), 71 deletions(-) diff --git a/pandatool/src/cvscopy/cvsSourceTree.cxx b/pandatool/src/cvscopy/cvsSourceTree.cxx index 5e13273687..6de30d2aa3 100644 --- a/pandatool/src/cvscopy/cvsSourceTree.cxx +++ b/pandatool/src/cvscopy/cvsSourceTree.cxx @@ -7,6 +7,7 @@ #include "cvsSourceDirectory.h" #include +#include #include #include @@ -491,7 +492,7 @@ get_actual_fullpath(const string &path) { return string(); } - string cwd = get_cwd(); + string cwd = ExecutionEnvironment::get_cwd(); restore_cwd(); return cwd; @@ -507,37 +508,8 @@ get_actual_fullpath(const string &path) { string CVSSourceTree:: get_start_fullpath() { if (!_got_start_fullpath) { - _start_fullpath = get_cwd(); + _start_fullpath = ExecutionEnvironment::get_cwd(); _got_start_fullpath = true; } return _start_fullpath; } - -//////////////////////////////////////////////////////////////////// -// Function: CVSSourceTree::get_cwd -// Access: Private, Static -// Description: Calls the system getcwd(), automatically allocating a -// large enough string. -//////////////////////////////////////////////////////////////////// -string CVSSourceTree:: -get_cwd() { - static size_t bufsize = 1024; - static char *buffer = NULL; - - if (buffer == (char *)NULL) { - buffer = new char[bufsize]; - } - - while (getcwd(buffer, bufsize) == (char *)NULL) { - if (errno != ERANGE) { - perror("getcwd"); - return string(); - } - delete[] buffer; - bufsize = bufsize * 2; - buffer = new char[bufsize]; - nassertr(buffer != (char *)NULL, string()); - } - - return string(buffer); -} diff --git a/pandatool/src/cvscopy/cvsSourceTree.h b/pandatool/src/cvscopy/cvsSourceTree.h index e2e7081957..24f9e797c2 100644 --- a/pandatool/src/cvscopy/cvsSourceTree.h +++ b/pandatool/src/cvscopy/cvsSourceTree.h @@ -63,7 +63,6 @@ private: static string get_actual_fullpath(const string &path); static string get_start_fullpath(); - static string get_cwd(); private: string _path; diff --git a/pandatool/src/egg-palettize/attribFile.cxx b/pandatool/src/egg-palettize/attribFile.cxx index ece64f19fa..ed88f05a97 100644 --- a/pandatool/src/egg-palettize/attribFile.cxx +++ b/pandatool/src/egg-palettize/attribFile.cxx @@ -48,7 +48,7 @@ get_name() const { } bool AttribFile:: -grab_lock() { +open_and_lock(bool lock) { if (!_txa_filename.exists()) { nout << "Attributes file " << _txa_filename << " does not exist.\n"; } @@ -65,12 +65,14 @@ grab_lock() { fl.l_start = 0; fl.l_len = 0; - if (fcntl(_txa_fd, F_SETLK, &fl) < 0) { - nout << "Waiting for lock on " << _txa_filename << "\n"; - while (fcntl(_txa_fd, F_SETLKW, &fl) < 0) { - if (errno != EINTR) { - perror(_txa_filename.c_str()); - return false; + if (lock) { + if (fcntl(_txa_fd, F_SETLK, &fl) < 0) { + nout << "Waiting for lock on " << _txa_filename << "\n"; + while (fcntl(_txa_fd, F_SETLKW, &fl) < 0) { + if (errno != EINTR) { + perror(_txa_filename.c_str()); + return false; + } } } } @@ -81,7 +83,7 @@ grab_lock() { } bool AttribFile:: -release_lock() { +close_and_unlock() { // Closing the fstream will close the fd, and thus release all the // file locks. _txa_fstrm.close(); @@ -747,6 +749,9 @@ read_pi(istream &infile, bool force_redo_all) { } else if (words[0] == "egg") { okflag = parse_egg(words, infile, line, line_num, force_redo_all); + } else if (words[0] == "group") { + okflag = parse_group(words, infile, line, line_num); + } else if (words[0] == "palette") { okflag = parse_palette(words, infile, line, line_num); @@ -821,9 +826,13 @@ write_pi(ostream &out) const { any_surprises = any_surprises || !egg->matched_anything(); } + out << "\n"; Groups::const_iterator gi; for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - (*gi).second->write(out); + (*gi).second->write_pi(out); + } + for (gi = _groups.begin(); gi != _groups.end(); ++gi) { + (*gi).second->write_palettes_pi(out); } out << "\n"; @@ -1028,13 +1037,20 @@ parse_pathname(const vector &words, istream &infile, bool AttribFile:: parse_egg(const vector &words, istream &infile, string &line, int &line_num, bool force_redo_all) { - if (words.size() != 2) { + if (words.size() < 2) { nout << "Egg filename expected.\n"; return false; } SourceEgg *egg = get_egg(words[1]); + if (words.size() > 2 && words[2] == "in") { + // Get the group names. + for (int i = 3; i < (int)words.size(); i++) { + egg->add_group(get_group(words[i])); + } + } + getline(infile, line); line = trim_right(line); line_num++; @@ -1093,6 +1109,32 @@ parse_egg(const vector &words, istream &infile, } +bool AttribFile:: +parse_group(const vector &words, istream &infile, + string &line, int &line_num) { + if (words.size() == 2) { + // Just a group name by itself; ignore it. + return true; + } + + if (words.size() != 4) { + nout << "Group dirname expected.\n"; + return false; + } + + if (!(words[2] == "dir")) { + nout << "Expected keyword 'dir'\n"; + return false; + } + PaletteGroup *group = get_group(words[1]); + + group->set_dirname(words[3]); + + getline(infile, line); + line_num++; + return true; +} + bool AttribFile:: parse_palette(const vector &words, istream &infile, string &line, int &line_num) { diff --git a/pandatool/src/egg-palettize/attribFile.h b/pandatool/src/egg-palettize/attribFile.h index 28c90f9476..3b8e0e5897 100644 --- a/pandatool/src/egg-palettize/attribFile.h +++ b/pandatool/src/egg-palettize/attribFile.h @@ -31,8 +31,8 @@ public: string get_name() const; - bool grab_lock(); - bool release_lock(); + bool open_and_lock(bool lock); + bool close_and_unlock(); bool read(bool force_redo_all); bool write(); @@ -94,21 +94,23 @@ private: bool write_pi(ostream &outfile) const; bool parse_params(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_packing(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_texture(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_pathname(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_egg(const vector &words, istream &infile, - string &line, int &line_num, bool force_redo_all); + string &line, int &line_num, bool force_redo_all); + bool parse_group(const vector &words, istream &infile, + string &line, int &line_num); bool parse_palette(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_unplaced(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool parse_surprises(const vector &words, istream &infile, - string &line, int &line_num); + string &line, int &line_num); bool _optimal; bool _txa_needs_rewrite; diff --git a/pandatool/src/egg-palettize/eggPalettize.cxx b/pandatool/src/egg-palettize/eggPalettize.cxx index 73cd50e293..475b5c2f65 100644 --- a/pandatool/src/egg-palettize/eggPalettize.cxx +++ b/pandatool/src/egg-palettize/eggPalettize.cxx @@ -562,9 +562,9 @@ run() { af.set_default_group(group); } - if (!_dont_lock_pi && !af.grab_lock()) { - // Failing to grab the write lock on the attribute file is a - // fatal error. + if (!af.open_and_lock(!_dont_lock_pi)) { + // Failing to open, or failing to grab the write lock, on the + // attribute file is a fatal error. exit(1); } @@ -640,7 +640,7 @@ run() { } } - okflag = af.release_lock() && okflag; + okflag = af.close_and_unlock() && okflag; } if (_statistics_only) { diff --git a/pandatool/src/egg-palettize/pTexture.cxx b/pandatool/src/egg-palettize/pTexture.cxx index 205a8ec124..c256b8a038 100644 --- a/pandatool/src/egg-palettize/pTexture.cxx +++ b/pandatool/src/egg-palettize/pTexture.cxx @@ -52,7 +52,9 @@ get_name() const { } void PTexture:: -add_filename(const Filename &filename) { +add_filename(Filename filename) { + filename.make_absolute(); + if (!filename.exists()) { // Store the filename, even though it doesn't exist. if (!_got_filename) { diff --git a/pandatool/src/egg-palettize/pTexture.h b/pandatool/src/egg-palettize/pTexture.h index 0b58526a70..df35e9ed05 100644 --- a/pandatool/src/egg-palettize/pTexture.h +++ b/pandatool/src/egg-palettize/pTexture.h @@ -34,7 +34,7 @@ public: Filename get_name() const; - void add_filename(const Filename &filename); + void add_filename(Filename filename); bool get_size(int &xsize, int &ysize, int &zsize); void set_size(int xsize, int ysize, int zsize); diff --git a/pandatool/src/egg-palettize/paletteGroup.cxx b/pandatool/src/egg-palettize/paletteGroup.cxx index dbe90ac829..f8a5b883b2 100644 --- a/pandatool/src/egg-palettize/paletteGroup.cxx +++ b/pandatool/src/egg-palettize/paletteGroup.cxx @@ -282,13 +282,32 @@ add_ancestors(PaletteGroups &groups) { } //////////////////////////////////////////////////////////////////// -// Function: PaletteGroup::write +// Function: PaletteGroup::write_pi // Access: Public -// Description: Writes out a .pi file description of the palette -// group and all of its nested Palette images. +// Description: Writes out a .pi file description of the group. //////////////////////////////////////////////////////////////////// void PaletteGroup:: -write(ostream &out) const { +write_pi(ostream &out) const { + if (_dirname.empty() && _palettes.empty()) { + // No real reason to write this group out. + return; + } + + out << "group " << get_name(); + if (!_dirname.empty()) { + out << " dir " << _dirname; + } + out << "\n"; +} + +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::write_palettes +// Access: Public +// Description: Writes out a .pi file description of all of the +// individual Palette images. +//////////////////////////////////////////////////////////////////// +void PaletteGroup:: +write_palettes_pi(ostream &out) const { Palettes::const_iterator pi; for (pi = _palettes.begin(); pi != _palettes.end(); ++pi) { out << "\n"; diff --git a/pandatool/src/egg-palettize/paletteGroup.h b/pandatool/src/egg-palettize/paletteGroup.h index bb1696ea7d..23d1efd28b 100644 --- a/pandatool/src/egg-palettize/paletteGroup.h +++ b/pandatool/src/egg-palettize/paletteGroup.h @@ -69,7 +69,8 @@ public: static void complete_groups(PaletteGroups &groups); void add_ancestors(PaletteGroups &groups); - void write(ostream &out) const; + void write_pi(ostream &out) const; + void write_palettes_pi(ostream &out) const; private: typedef vector Parents; diff --git a/pandatool/src/egg-palettize/sourceEgg.cxx b/pandatool/src/egg-palettize/sourceEgg.cxx index e17898e783..468d41a2e8 100644 --- a/pandatool/src/egg-palettize/sourceEgg.cxx +++ b/pandatool/src/egg-palettize/sourceEgg.cxx @@ -187,6 +187,18 @@ get_textures(EggPalettize *prog) { } } +//////////////////////////////////////////////////////////////////// +// Function: SourceEgg::add_group +// Access: Public +// Description: Adds the indicated group to the set of groups known +// to be required for the egg file. Typically this is +// done from the .pi file. +//////////////////////////////////////////////////////////////////// +void SourceEgg:: +add_group(PaletteGroup *group) { + _groups.insert(group); +} + //////////////////////////////////////////////////////////////////// // Function: SourceEgg::require_groups // Access: Public @@ -195,6 +207,7 @@ get_textures(EggPalettize *prog) { //////////////////////////////////////////////////////////////////// void SourceEgg:: require_groups(PaletteGroup *preferred, const PaletteGroups &groups) { + _groups = groups; TexRefs::iterator ti; for (ti = _texrefs.begin(); ti != _texrefs.end(); ++ti) { (*ti)->require_groups(preferred, groups); @@ -209,13 +222,18 @@ require_groups(PaletteGroup *preferred, const PaletteGroups &groups) { //////////////////////////////////////////////////////////////////// void SourceEgg:: all_textures_assigned() { + PaletteGroup *default_group; + + if (_groups.empty()) { + default_group = _attrib_file->get_default_group(); + _groups.insert(default_group); + } else { + default_group = *(_groups.begin()); + } + TexRefs::iterator ti; for (ti = _texrefs.begin(); ti != _texrefs.end(); ++ti) { - TextureEggRef *texref = (*ti); - if (texref->_packing == (TexturePacking *)NULL) { - texref->_packing = - texref->_texture->add_to_group(_attrib_file->get_default_group()); - } + (*ti)->require_groups(default_group, _groups); } } @@ -384,7 +402,13 @@ set_matched_anything(bool matched_anything) { //////////////////////////////////////////////////////////////////// void SourceEgg:: write_pi(ostream &out) const { - out << "egg " << get_egg_filename() << "\n"; + out << "egg " << get_egg_filename() << " in"; + PaletteGroups::const_iterator gi; + for (gi = _groups.begin(); gi != _groups.end(); ++gi) { + out << " " << (*gi)->get_name(); + } + out << "\n"; + TexRefs::const_iterator ti; for (ti = _texrefs.begin(); ti != _texrefs.end(); ++ti) { out << " " << (*ti)->_packing->get_texture()->get_name() diff --git a/pandatool/src/egg-palettize/sourceEgg.h b/pandatool/src/egg-palettize/sourceEgg.h index 43ac9badd8..52a749b4ca 100644 --- a/pandatool/src/egg-palettize/sourceEgg.h +++ b/pandatool/src/egg-palettize/sourceEgg.h @@ -28,6 +28,8 @@ public: TextureEggRef *add_texture(PTexture *texture, TexturePacking *packing, bool repeats, bool alpha); void get_textures(EggPalettize *prog); + + void add_group(PaletteGroup *group); void require_groups(PaletteGroup *preferred, const PaletteGroups &groups); void all_textures_assigned(); @@ -35,7 +37,7 @@ public: void update_trefs(); bool needs_rebuild(bool force_redo_all, - bool eggs_include_images) const; + bool eggs_include_images) const; bool matched_anything() const; void set_matched_anything(bool matched_anything); @@ -54,6 +56,8 @@ private: AttribFile *_attrib_file; bool _matched_anything; + PaletteGroups _groups; + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/pandatool/src/egg-palettize/texturePacking.cxx b/pandatool/src/egg-palettize/texturePacking.cxx index 4600b4545e..fa52324b3d 100644 --- a/pandatool/src/egg-palettize/texturePacking.cxx +++ b/pandatool/src/egg-palettize/texturePacking.cxx @@ -474,6 +474,7 @@ Filename TexturePacking:: get_new_filename() const { Filename dirname = _group->get_full_dirname(_attrib_file); Filename new_filename(dirname, _texture->get_name()); + new_filename.standardize(); return new_filename; } @@ -484,7 +485,9 @@ get_new_filename() const { //////////////////////////////////////////////////////////////////// Filename TexturePacking:: get_old_filename() const { - return _texture->_filename; + Filename old_filename = _texture->_filename; + old_filename.standardize(); + return old_filename; } ////////////////////////////////////////////////////////////////////