15 #include "paletteGroup.h" 16 #include "palettePage.h" 17 #include "texturePlacement.h" 18 #include "textureImage.h" 19 #include "palettizer.h" 20 #include "paletteImage.h" 24 #include "datagramIterator.h" 25 #include "bamReader.h" 26 #include "bamWriter.h" 27 #include "indirectCompareNames.h" 40 _dependency_level = 0;
41 _dependency_order = 0;
43 _has_margin_override =
false;
69 return !_dirname.empty();
92 _dependency_level = 0;
93 _dependency_order = 0;
131 return _margin_override;
141 _margin_override =
override;
142 _has_margin_override =
true;
152 return _has_margin_override;
167 Placements::const_iterator pi;
168 for (pi = _placements.begin(); pi != _placements.end(); ++pi) {
169 placements.push_back(*pi);
185 PaletteGroups::iterator gi;
186 for (gi = complete.
begin(); gi != complete.
end(); ++gi) {
204 _dependency_level = 0;
205 _dependency_order = 0;
223 if (level > _dependency_level) {
224 _dependency_level = level;
225 PaletteGroups::iterator gi;
226 for (gi = _dependent.
begin(); gi != _dependent.
end(); ++gi) {
247 bool any_changed =
false;
249 PaletteGroups::iterator gi;
250 for (gi = _dependent.
begin(); gi != _dependent.
end(); ++gi) {
302 return _dependency_level;
322 return _dependency_order;
342 return _dirname_order;
400 Pages::iterator pi = _pages.find(properties);
401 if (pi != _pages.end()) {
406 bool inserted = _pages.insert(Pages::value_type(properties, page)).second;
407 nassertr(inserted, page);
425 _placements.insert(placement);
428 TextureSwapInfo::iterator tsi = _textureSwapInfo.find(texture->get_name());
429 if (tsi != _textureSwapInfo.end()) {
430 vector_string swapTextures = (*tsi).second;
432 vector_string::const_iterator wi;
433 wi = swapTextures.begin();
439 const string originalTextureName = (*wi);
447 while (wi != swapTextures.end()) {
448 const string &swapTextureName = (*wi);
451 swapTextureImage->
get_source(swapTextureFilename, originalTextureAlphaFilename, originalTextureAlphaFileChannel);
452 placement->_textureSwaps.push_back(swapTextureImage);
468 nassertv(placement->
get_group() ==
this);
470 Placements::iterator pi;
471 pi = _placements.find(placement);
472 if (pi != _placements.end()) {
473 _placements.erase(pi);
492 Placements::iterator pli;
493 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
504 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
520 Placements::iterator pli;
521 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
549 Pages::const_iterator pai;
550 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
557 placement_vector.reserve(_placements.size());
558 Placements::const_iterator pli;
559 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
562 placement_vector.push_back(placement);
565 sort(placement_vector.begin(), placement_vector.end(),
569 for (pvi = placement_vector.begin();
570 pvi != placement_vector.end();
574 indent(out, indent_level)
576 <<
" unplaced because ";
579 out <<
"coverage (" << placement->
get_uv_area() <<
")";
583 out <<
"size (" << placement->
get_x_size() <<
" " 603 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
619 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
636 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
651 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
666 register_factory(get_class_type(), make_PaletteGroup);
688 Placements::const_iterator pli;
689 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
694 Pages::const_iterator pai;
695 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
698 datagram.
add_bool(_has_margin_override);
719 for (i = 0; i < _num_placements; i++) {
721 DCAST_INTO_R(placement, p_list[pi++], pi);
722 bool inserted = _placements.insert(placement).second;
723 nassertr(inserted, pi);
730 _load_pages.reserve(_num_pages);
731 for (i = 0; i < _num_pages; i++) {
733 DCAST_INTO_R(page, p_list[pi++], pi);
734 _load_pages.push_back(page);
753 for (pi = _load_pages.begin(); pi != _load_pages.end(); ++pi) {
755 bool inserted = _pages.
777 parse_params(params, scan, manager);
778 me->fillin(scan, manager);
795 _dependent.
fillin(scan, manager);
807 if(Palettizer::_read_pi_version >= 19) {
808 _has_margin_override = scan.
get_bool();
820 TextureSwapInfo::iterator tsi = _textureSwapInfo.find(sourceTextureName);
821 if (tsi != _textureSwapInfo.end()) {
822 _textureSwapInfo.erase(tsi);
824 _textureSwapInfo.insert(TextureSwapInfo::value_type(sourceTextureName, swapTextures));
835 return _textureSwapInfo.empty();
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types...
string get_dirname() const
Returns the directory part of the filename.
int get_y_size() const
Returns the size in the Y dimension, in pixels, of the texture image as it must appear in the palette...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
void write_image_info(ostream &out, int indent_level=0) const
Writes a list of the PaletteImages associated with this group, and all of their textures, to the indicated output stream.
void update_unknown_textures(const TxaFile &txa_file)
Checks for new information on any textures within the group for which some of the saved information i...
iterator end() const
Returns an iterator suitable for traversing the set.
bool determine_size()
Attempts to determine the appropriate size of the texture for the given placement.
bool get_bool()
Extracts a boolean value.
void add_string(const string &str)
Adds a variable-length string to the datagram.
void pre_txa_file()
Updates any internal state prior to reading the .txa file.
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
void place_all()
Once all the textures have been assigned to this group, try to place them all onto suitable PaletteIm...
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
PaletteGroup * get_group() const
Returns the group that this placement represents.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
SourceTextureImage * get_source(const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
Returns the SourceTextureImage corresponding to the given filename(s).
Base class for objects that can be written to and read from Bam files.
iterator begin() const
Returns an iterator suitable for traversing the set.
This is the highest level of grouping for TextureImages.
void unplace(TexturePlacement *placement)
Removes the texture from its position on a PaletteImage, if it has been so placed.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
void place_all()
Assigns all the textures to their final home in a PaletteImage somewhere.
void clear()
Empties the set.
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types...
double get_uv_area() const
Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
PN_int32 get_int32()
Extracts a signed 32-bit integer.
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
void add_texture_swap_info(const string sourceTextureName, const vector_string &swapTextures)
Store textureswap information from textures.txa.
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
string get_extension() const
Returns the file extension.
bool has_margin_override() const
Returns the set of groups this group depends on.
PN_int16 get_int16()
Extracts a signed 16-bit integer.
string get_string()
Extracts a variable-length string.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
bool is_none_texture_swap() const
Returns textureswap information is set or not, True if it's not set.
SourceTextureImage * get_preferred_source()
Determines the preferred source image for examining size and reading pixels, etc. ...
void reset_dependency_level()
Unconditionally sets the dependency level and order of this group to zero, in preparation for a later...
void add_int16(PN_int16 value)
Adds a signed 16-bit integer to the datagram.
int get_dirname_order() const
Returns the dependency order of this group.
void unplace(TexturePlacement *placement)
Removes the TexturePlacement from wherever it has been placed.
void add_bool(bool value)
Adds a boolean value to the datagram.
bool is_size_known() const
Returns true if the texture's size is known, false otherwise.
void write_image_info(ostream &out, int indent_level=0) const
Writes a list of the PaletteImages associated with this page, and all of their textures, to the indicated output stream.
The name of a file, such as a texture file or an Egg file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
void update_images(bool redo_all)
Regenerates each PaletteImage on this page that needs it.
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
void assign(TexturePlacement *placement)
Adds the indicated texture to the list of textures to consider placing on the page.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
const string & get_dirname() const
Returns the directory name associated with the palette group.
PalettePage * get_page() const
Returns the particular PalettePage on which the texture has been placed.
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
This is a texture image reference as it appears in an egg file: the source image of the texture...
void update_images(bool redo_all)
Regenerates each PaletteImage on this group that needs it.
int get_dependency_level() const
Returns the dependency level of this group.
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not...
void set_dependency_level(int level)
Sets the dependency level of this group to the indicated level, provided that level is not lower than...
PalettePage * get_page(const TextureProperties &properties)
Returns the page associated with the indicated properties.
void make_complete(const PaletteGroups &a)
Completes the set with the transitive closure of all dependencies: for each PaletteGroup already in t...
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
void set_dirname(const string &dirname)
Sets the directory name associated with the palette group.
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
bool set_dependency_order()
Updates the dependency order of this group.
TextureImage * get_texture() const
Returns the texture that this placement represents.
void insert(PaletteGroup *group)
Inserts a new group to the set, if it is not already there.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
int get_x_size() const
Returns the size in the X dimension, in pixels, of the texture image as it must appear in the palette...
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
void increment_egg_count()
Increments by one the number of egg files that are known to reference this PaletteGroup.
bool is_preferred_over(const PaletteGroup &other) const
Returns true if this group should be preferred for adding textures over the other group...
virtual void finalize(BamReader *manager)
This method is called by the BamReader after all pointers everywhere in the world have been completel...
TexturePlacement * prepare(TextureImage *texture)
Marks the indicated Texture as ready for placing somewhere within this group, and returns a placehold...
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram. ...
This represents a single source texture that is referenced by one or more egg files.
bool got_txa_file() const
Returns true if this TextureImage has been looked up in the .txa file this session, false otherwise.
void post_txa_file()
Once the .txa file has been read and the TextureImage matched against it, considers applying the requ...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
const Filename & get_filename() const
Returns the primary filename of the image file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
TextureImage * get_texture(const string &name)
Returns the TextureImage with the given name.
const PaletteGroups & get_groups() const
Returns the set of groups this group depends on.
int get_egg_count() const
Returns the number of egg files that share this PaletteGroup.
void get_complete_placements(pvector< TexturePlacement *> &placements) const
Adds the set of TexturePlacements associated with this group and all dependent groups to the indicate...
void clear_depends()
Eliminates all the dependency information for this group.
void get_placements(pvector< TexturePlacement *> &placements) const
Adds the set of TexturePlacements associated with this group to the indicated vector.
int get_dependency_order() const
Returns the dependency order of this group.
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
bool is_placed() const
Returns true if the texture has been placed on a palette image, false otherwise.
int get_margin_override() const
Returns the set of groups this group depends on.
bool match_texture(TextureImage *texture) const
Searches for a matching line in the .txa file for the given texture and applies its specifications...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void set_margin_override(const int override)
Returns the set of groups this group depends on.
const TextureProperties & get_properties() const
Returns the texture grouping properties that all textures in this page share.
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.