diff --git a/pandatool/src/egg-palettize/paletteGroup.cxx b/pandatool/src/egg-palettize/paletteGroup.cxx index 9dbf490c37..18bdfb67aa 100644 --- a/pandatool/src/egg-palettize/paletteGroup.cxx +++ b/pandatool/src/egg-palettize/paletteGroup.cxx @@ -27,6 +27,7 @@ PaletteGroup() { _egg_count = 0; _dependency_level = 0; _dependency_order = 0; + _dirname_order = 0; } //////////////////////////////////////////////////////////////////// @@ -76,6 +77,7 @@ clear_depends() { _dependent.clear(); _dependency_level = 0; _dependency_order = 0; + _dirname_order = 0; } //////////////////////////////////////////////////////////////////// @@ -156,6 +158,7 @@ void PaletteGroup:: reset_dependency_level() { _dependency_level = 0; _dependency_order = 0; + _dirname_order = 0; } //////////////////////////////////////////////////////////////////// @@ -209,6 +212,20 @@ set_dependency_order() { _dependency_order = group->get_dependency_order() + 1; any_changed = true; } + + if (_dirname == group->get_dirname()) { + // The dirname orders should be equal. + if (_dirname_order < group->get_dirname_order()) { + _dirname_order = group->get_dirname_order(); + any_changed = true; + } + } else { + // The dirname orders should be different. + if (_dirname_order <= group->get_dirname_order()) { + _dirname_order = group->get_dirname_order() + 1; + any_changed = true; + } + } } return any_changed; @@ -260,6 +277,47 @@ get_dependency_order() const { return _dependency_order; } +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::get_dirname_order +// Access: Public +// Description: Returns the dependency order of this group. This is +// similar in principle to the dependency level, but it +// represents the inverse concept: if group a depends on +// group b, then a->get_dirname_order() > +// b->get_dirname_order(). +// +// This is not exactly the same thing as n - +// get_dependency_level(). In particular, this can be +// used to sort the groups into an ordering such that +// all the groups that group a depends on appear before +// group a in the list. +//////////////////////////////////////////////////////////////////// +int PaletteGroup:: +get_dirname_order() const { + return _dirname_order; +} + +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::is_preferred_over +// Access: Public +// Description: Returns true if this group should be preferred for +// adding textures over the other group, if both are +// available. In other words, this is a more specific +// group than the other one. +//////////////////////////////////////////////////////////////////// +bool PaletteGroup:: +is_preferred_over(const PaletteGroup &other) const { + if (get_dirname_order() != other.get_dirname_order()) { + return (get_dirname_order() > other.get_dirname_order()); + + } else if (get_dependency_order() != other.get_dependency_order()) { + return (get_dependency_order() > other.get_dependency_order()); + + } else { + return (get_egg_count() < other.get_egg_count()); + } +} + //////////////////////////////////////////////////////////////////// // Function: PaletteGroup::increment_egg_count // Access: Public @@ -503,6 +561,7 @@ write_datagram(BamWriter *writer, Datagram &datagram) { datagram.add_int32(_dependency_level); datagram.add_int32(_dependency_order); + datagram.add_int32(_dirname_order); datagram.add_uint32(_placements.size()); Placements::const_iterator pli; @@ -616,6 +675,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { if (Palettizer::_read_pi_version >= 3) { _dependency_level = scan.get_int32(); _dependency_order = scan.get_int32(); + if (Palettizer::_read_pi_version >= 4) { + _dirname_order = scan.get_int32(); + } } _num_placements = scan.get_uint32(); diff --git a/pandatool/src/egg-palettize/paletteGroup.h b/pandatool/src/egg-palettize/paletteGroup.h index ccf4c99f6e..1802a063c3 100644 --- a/pandatool/src/egg-palettize/paletteGroup.h +++ b/pandatool/src/egg-palettize/paletteGroup.h @@ -53,6 +53,9 @@ public: bool set_dependency_order(); int get_dependency_level() const; int get_dependency_order() const; + int get_dirname_order() const; + + bool is_preferred_over(const PaletteGroup &other) const; void increment_egg_count(); int get_egg_count() const; @@ -77,6 +80,7 @@ private: PaletteGroups _dependent; int _dependency_level; int _dependency_order; + int _dirname_order; typedef set Placements; Placements _placements; diff --git a/pandatool/src/egg-palettize/palettizer.cxx b/pandatool/src/egg-palettize/palettizer.cxx index f03f8896ec..22beb3e7fa 100644 --- a/pandatool/src/egg-palettize/palettizer.cxx +++ b/pandatool/src/egg-palettize/palettizer.cxx @@ -28,10 +28,11 @@ Palettizer *pal = (Palettizer *)NULL; // allows us to easily update egg-palettize to write out additional // information to its pi file, without having it increment the bam // version number for all bam and boo files anywhere in the world. -int Palettizer::_pi_version = 3; +int Palettizer::_pi_version = 4; // Updated to version 1 on 12/11/00 to add _remap_char_uv. // Updated to version 2 on 12/19/00 to add TexturePlacement::_dest. // Updated to version 3 on 12/19/00 to add PaletteGroup::_dependency_order. +// Updated to version 4 on 5/3/01 to add PaletteGroup::_dirname_order. int Palettizer::_read_pi_version = 0; @@ -67,6 +68,14 @@ public: } }; +// And this one is used in report_pi(). +class SortGroupsByPreference { +public: + bool operator ()(PaletteGroup *a, PaletteGroup *b) { + return !a->is_preferred_over(*b); + } +}; + //////////////////////////////////////////////////////////////////// // Function: Palettizer::Constructor // Access: Public @@ -149,7 +158,7 @@ report_pi() const { cout << "\n"; } - cout << "\ntexture source pathnames and sizes\n"; + cout << "\ntexture source pathnames and assignments\n"; Textures::const_iterator ti; for (ti = _textures.begin(); ti != _textures.end(); ++ti) { TextureImage *texture = (*ti).second; @@ -165,14 +174,26 @@ report_pi() const { egg_file->write_texture_refs(cout, 4); } - cout << "\npalette groups\n"; + // Sort the palette groups into order of preference, so that the + // more specific ones appear at the bottom. + vector sorted_groups; Groups::const_iterator gi; for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - PaletteGroup *group = (*gi).second; - if (gi != _groups.begin()) { + sorted_groups.push_back((*gi).second); + } + sort(sorted_groups.begin(), sorted_groups.end(), + SortGroupsByPreference()); + + cout << "\npalette groups\n"; + vector::iterator si; + for (si = sorted_groups.begin(); si != sorted_groups.end(); ++si) { + PaletteGroup *group = (*si); + if (si != sorted_groups.begin()) { cout << "\n"; } - cout << " " << group->get_name() << ": " + cout << " " << group->get_name() << " (" + << group->get_dirname_order() << "," + << group->get_dependency_order() << "): " << group->get_groups() << "\n"; group->write_image_info(cout, 4); } diff --git a/pandatool/src/egg-palettize/textureImage.cxx b/pandatool/src/egg-palettize/textureImage.cxx index c10fbafd4a..b31b64ad1f 100644 --- a/pandatool/src/egg-palettize/textureImage.cxx +++ b/pandatool/src/egg-palettize/textureImage.cxx @@ -119,8 +119,9 @@ assign_groups() { // Now, find the group that will satisfy the most egg files. If // two groups satisfy the same number of egg files, choose (a) the - // most specific one, i.e. with the lowest dependency_level value, - // and (b) the one that has the fewest egg files sharing it. + // most specific one, i.e. with the lowest dirname_level, or the + // lowest dependency_level if the dirname_levels are equal, and + // (b) the one that has the fewest egg files sharing it. nassertv(!total.empty()); PaletteGroups::iterator gi = total.begin(); PaletteGroup *best = (*gi); @@ -135,12 +136,8 @@ assign_groups() { if (group_egg_count != best_egg_count) { prefer_group = (group_egg_count > best_egg_count); - } else if (group->get_dependency_level() != best->get_dependency_level()){ - prefer_group = - (group->get_dependency_level() < best->get_dependency_level()); - } else { - prefer_group = (group->get_egg_count() < best->get_egg_count()); + prefer_group = group->is_preferred_over(*best); } if (prefer_group) { @@ -173,8 +170,8 @@ assign_groups() { //////////////////////////////////////////////////////////////////// // Function: TextureImage::get_groups // Access: Public -// Description: Once get_groups() has been called, this returns the -// actual set of groups the TextureImage has been +// Description: Once assign_groups() has been called, this returns +// the actual set of groups the TextureImage has been // assigned to. //////////////////////////////////////////////////////////////////// const PaletteGroups &TextureImage:: @@ -632,6 +629,25 @@ write_source_pathnames(ostream &out, int indent_level) const { out << "\n"; } } + + // Now write out the group assignments. + if (!_egg_files.empty()) { + indent(out, indent_level) + << "Used by:\n"; + EggFiles::const_iterator ei; + 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"; + } + } + 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"; } ////////////////////////////////////////////////////////////////////