Panda3D
Loading...
Searching...
No Matches
paletteGroup.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file paletteGroup.cxx
10 * @author drose
11 * @date 2000-11-30
12 */
13
14#include "paletteGroup.h"
15#include "palettePage.h"
16#include "texturePlacement.h"
17#include "textureImage.h"
18#include "palettizer.h"
19#include "paletteImage.h"
20#include "sourceTextureImage.h"
21
22#include "indent.h"
23#include "datagram.h"
24#include "datagramIterator.h"
25#include "bamReader.h"
26#include "bamWriter.h"
28#include "pvector.h"
29
30using std::string;
31
32TypeHandle PaletteGroup::_type_handle;
33
34/**
35 *
36 */
37PaletteGroup::
38PaletteGroup() {
39 _egg_count = 0;
40 _dependency_level = 0;
41 _dependency_order = 0;
42 _dirname_order = 0;
43 _has_margin_override = false;
44 _margin_override = 0;
45}
46
47/**
48 * Sets the directory name associated with the palette group. This is an
49 * optional feature that can be used to place the maps for the different
50 * palette groups into different install directories.
51 */
53set_dirname(const string &dirname) {
54 _dirname = dirname;
55}
56
57/**
58 * Returns true if the directory name has been explicitly set for this group.
59 * If it has not, get_dirname() returns an empty string.
60 */
62has_dirname() const {
63 return !_dirname.empty();
64}
65
66/**
67 * Returns the directory name associated with the palette group. See
68 * set_dirname().
69 */
70const string &PaletteGroup::
71get_dirname() const {
72 return _dirname;
73}
74
75/**
76 * Eliminates all the dependency information for this group.
77 */
80 _dependent.clear();
81 _dependency_level = 0;
82 _dependency_order = 0;
83 _dirname_order = 0;
84}
85
86/**
87 * Indicates a dependency of this group on some other group. This means that
88 * the textures assigned to this group may be considered successfully assigned
89 * if they are actually placed in the other group. In practice, this means
90 * that the textures associated with the other palette group will always be
91 * resident at runtime when textures from this palette group are required.
92 */
95 _dependent.insert(other);
96}
97
98/**
99 * Returns the set of groups this group depends on.
100 */
102get_groups() const {
103 return _dependent;
104}
105
106/**
107 * Returns the set of groups this group depends on.
108 */
110get_margin_override() const {
111 return _margin_override;
112}
113
114/**
115 * Returns the set of groups this group depends on.
116 */
118set_margin_override(const int override) {
119 _margin_override = override;
120 _has_margin_override = true;
121}
122
123/**
124 * Returns the set of groups this group depends on.
125 */
127has_margin_override() const {
128 return _has_margin_override;
129}
130
131/**
132 * Adds the set of TexturePlacements associated with this group to the
133 * indicated vector. The vector is not cleared before this operation; if the
134 * user wants to retrieve the set of placements particular to this group only,
135 * it is the user's responsibility to clear the vector first.
136 */
139 Placements::const_iterator pi;
140 for (pi = _placements.begin(); pi != _placements.end(); ++pi) {
141 placements.push_back(*pi);
142 }
143}
144
145/**
146 * Adds the set of TexturePlacements associated with this group and all
147 * dependent groups to the indicated vector. See get_placements().
148 */
151 PaletteGroups complete;
152 complete.make_complete(_dependent);
153
154 PaletteGroups::iterator gi;
155 for (gi = complete.begin(); gi != complete.end(); ++gi) {
156 PaletteGroup *group = (*gi);
157 group->get_placements(placements);
158 }
159
160 get_placements(placements);
161}
162
163/**
164 * Unconditionally sets the dependency level and order of this group to zero,
165 * in preparation for a later call to set_dependency_level(). See
166 * set_dependency_level().
167 */
170 _dependency_level = 0;
171 _dependency_order = 0;
172 _dirname_order = 0;
173}
174
175/**
176 * Sets the dependency level of this group to the indicated level, provided
177 * that level is not lower than the level that was set previously. Also
178 * cascades to all dependent groups. See get_dependency_level().
179 *
180 * This call recurses to correctly set the dependency level of all
181 * PaletteGroups in the hierarchy.
182 */
184set_dependency_level(int level) {
185 if (level > _dependency_level) {
186 _dependency_level = level;
187 PaletteGroups::iterator gi;
188 for (gi = _dependent.begin(); gi != _dependent.end(); ++gi) {
189 PaletteGroup *group = (*gi);
190 group->set_dependency_level(level + 1);
191 }
192 }
193}
194
195/**
196 * Updates the dependency order of this group. This number is the inverse of
197 * the dependency level, and can be used to rank the groups in order so that
198 * all the groups that a given group depends on will appear first in the list.
199 * See get_dependency_order().
200 *
201 * This function returns true if anything was changed, false otherwise.
202 */
205 bool any_changed = false;
206
207 PaletteGroups::iterator gi;
208 for (gi = _dependent.begin(); gi != _dependent.end(); ++gi) {
209 PaletteGroup *group = (*gi);
210 if (group->set_dependency_order()) {
211 any_changed = true;
212 }
213
214 if (_dependency_order <= group->get_dependency_order()) {
215 _dependency_order = group->get_dependency_order() + 1;
216 any_changed = true;
217 }
218
219 if (_dirname == group->get_dirname()) {
220 // The dirname orders should be equal.
221 if (_dirname_order < group->get_dirname_order()) {
222 _dirname_order = group->get_dirname_order();
223 any_changed = true;
224 }
225 } else {
226 // The dirname orders should be different.
227 if (_dirname_order <= group->get_dirname_order()) {
228 _dirname_order = group->get_dirname_order() + 1;
229 any_changed = true;
230 }
231 }
232 }
233
234 return any_changed;
235}
236
237/**
238 * Returns the dependency level of this group. This is a measure of how
239 * specific the group is; the lower the dependency level, the more specific
240 * the group.
241 *
242 * Groups depend on other groups in a hierarchical relationship. In general,
243 * if group a depends on group b, then b->get_dependency_level() >
244 * a->get_dependency_level().
245 *
246 * Thus, groups that lots of other groups depend on have a higher dependency
247 * level; groups that no one else depends on have a low dependency level.
248 * This is important when deciding which groups are best suited for assigning
249 * a texture to; in general, the texture should be assigned to the most
250 * specific suitable group (i.e. the one with the lowest dependency level).
251 */
253get_dependency_level() const {
254 return _dependency_level;
255}
256
257/**
258 * Returns the dependency order of this group. This is similar in principle
259 * to the dependency level, but it represents the inverse concept: if group a
260 * depends on group b, then a->get_dependency_order() >
261 * b->get_dependency_order().
262 *
263 * This is not exactly the same thing as n - get_dependency_level(). In
264 * particular, this can be used to sort the groups into an ordering such that
265 * all the groups that group a depends on appear before group a in the list.
266 */
268get_dependency_order() const {
269 return _dependency_order;
270}
271
272/**
273 * Returns the dependency order of this group. This is similar in principle
274 * to the dependency level, but it represents the inverse concept: if group a
275 * depends on group b, then a->get_dirname_order() > b->get_dirname_order().
276 *
277 * This is not exactly the same thing as n - get_dependency_level(). In
278 * particular, this can be used to sort the groups into an ordering such that
279 * all the groups that group a depends on appear before group a in the list.
280 */
282get_dirname_order() const {
283 return _dirname_order;
284}
285
286/**
287 * Returns true if this group should be preferred for adding textures over the
288 * other group, if both are available. In other words, this is a more
289 * specific group than the other one.
290 */
292is_preferred_over(const PaletteGroup &other) const {
293 if (get_dirname_order() != other.get_dirname_order()) {
294 return (get_dirname_order() > other.get_dirname_order());
295
296 } else if (get_dependency_order() != other.get_dependency_order()) {
297 return (get_dependency_order() > other.get_dependency_order());
298
299 } else {
300 return (get_egg_count() < other.get_egg_count());
301 }
302}
303
304/**
305 * Increments by one the number of egg files that are known to reference this
306 * PaletteGroup. This is designed to aid the heuristics in texture placing;
307 * it's useful to know how many different egg files are sharing a particular
308 * PaletteGroup.
309 */
312 _egg_count++;
313}
314
315/**
316 * Returns the number of egg files that share this PaletteGroup.
317 */
319get_egg_count() const {
320 return _egg_count;
321}
322
323/**
324 * Returns the page associated with the indicated properties. If no page
325 * object has yet been created, creates one.
326 */
328get_page(const TextureProperties &properties) {
329 Pages::iterator pi = _pages.find(properties);
330 if (pi != _pages.end()) {
331 return (*pi).second;
332 }
333
334 PalettePage *page = new PalettePage(this, properties);
335 bool inserted = _pages.insert(Pages::value_type(properties, page)).second;
336 nassertr(inserted, page);
337 return page;
338}
339
340/**
341 * Marks the indicated Texture as ready for placing somewhere within this
342 * group, and returns a placeholder TexturePlacement object. The texture is
343 * not placed immediately, but may be placed later when place_all() is called;
344 * at this time, the TexturePlacement fields will be filled in as appropriate.
345 */
347prepare(TextureImage *texture) {
348 TexturePlacement *placement = new TexturePlacement(texture, this);
349 _placements.insert(placement);
350
351 // [gjeon] update swapTexture information
352 TextureSwapInfo::iterator tsi = _textureSwapInfo.find(texture->get_name());
353 if (tsi != _textureSwapInfo.end()) {
354 vector_string swapTextures = (*tsi).second;
355
356 vector_string::const_iterator wi;
357 wi = swapTextures.begin();
358 ++wi;
359 ++wi;
360
361 // [gjeon] since swapped texture usually didn't mapped to any egg file we
362 // need to create soucreTextureImage by using original texture file's info
363 const string originalTextureName = (*wi);
364 TextureImage *originalTexture = pal->get_texture(originalTextureName);
365 SourceTextureImage *source = originalTexture->get_preferred_source();
366 const Filename originalTextureFilename = source->get_filename();
367 const Filename originalTextureAlphaFilename = source->get_alpha_filename();
368 int originalTextureAlphaFileChannel = source->get_alpha_file_channel();
369
370 ++wi;
371 while (wi != swapTextures.end()) {
372 const string &swapTextureName = (*wi);
373 TextureImage *swapTextureImage = pal->get_texture(swapTextureName);
374 Filename swapTextureFilename = Filename(originalTextureFilename.get_dirname(), swapTextureName + "." + originalTextureFilename.get_extension());
375 swapTextureImage->get_source(swapTextureFilename, originalTextureAlphaFilename, originalTextureAlphaFileChannel);
376 placement->_textureSwaps.push_back(swapTextureImage);
377 ++wi;
378 }
379 }
380
381 return placement;
382}
383
384/**
385 * Removes the texture from its position on a PaletteImage, if it has been so
386 * placed.
387 */
389unplace(TexturePlacement *placement) {
390 nassertv(placement->get_group() == this);
391
392 Placements::iterator pi;
393 pi = _placements.find(placement);
394 if (pi != _placements.end()) {
395 _placements.erase(pi);
396
397 if (placement->is_placed()) {
398 placement->get_page()->unplace(placement);
399 }
400 }
401}
402
403/**
404 * Once all the textures have been assigned to this group, try to place them
405 * all onto suitable PaletteImages.
406 */
408place_all() {
409 // First, go through our prepared textures and assign each unplaced one to
410 // an appropriate page.
411 Placements::iterator pli;
412 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
413 TexturePlacement *placement = (*pli);
414
415 if (placement->get_omit_reason() == OR_working) {
416 PalettePage *page = get_page(placement->get_properties());
417 page->assign(placement);
418 }
419 }
420
421 // Then, go through the pages and actually do the placing.
422 Pages::iterator pai;
423 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
424 PalettePage *page = (*pai).second;
425 page->place_all();
426 }
427}
428
429/**
430 * Checks for new information on any textures within the group for which some
431 * of the saved information is incomplete. This may be necessary before we
432 * can properly place all of the textures.
433 */
435update_unknown_textures(const TxaFile &txa_file) {
436 Placements::iterator pli;
437 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
438 TexturePlacement *placement = (*pli);
439
440 if (!placement->is_size_known()) {
441 // This texture's size isn't known; we have to determine its size.
442 TextureImage *texture = placement->get_texture();
443 if (!texture->got_txa_file()) {
444 // But first, we need to look up the texture in the .txa file.
445 texture->pre_txa_file();
446 txa_file.match_texture(texture);
447 texture->post_txa_file();
448 }
449
450 placement->determine_size();
451 }
452 }
453}
454
455/**
456 * Writes a list of the PaletteImages associated with this group, and all of
457 * their textures, to the indicated output stream.
458 */
460write_image_info(std::ostream &out, int indent_level) const {
461 Pages::const_iterator pai;
462 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
463 PalettePage *page = (*pai).second;
464 page->write_image_info(out, indent_level);
465 }
466
467 // Write out all the unplaced textures, in alphabetical order by name.
468 pvector<TexturePlacement *> placement_vector;
469 placement_vector.reserve(_placements.size());
470 Placements::const_iterator pli;
471 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
472 TexturePlacement *placement = (*pli);
473 if (placement->get_omit_reason() != OR_none) {
474 placement_vector.push_back(placement);
475 }
476 }
477 sort(placement_vector.begin(), placement_vector.end(),
479
481 for (pvi = placement_vector.begin();
482 pvi != placement_vector.end();
483 ++pvi) {
484 TexturePlacement *placement = (*pvi);
485
486 indent(out, indent_level)
487 << placement->get_texture()->get_name()
488 << " unplaced because ";
489 switch (placement->get_omit_reason()) {
490 case OR_coverage:
491 out << "coverage (" << placement->get_uv_area() << ")";
492 break;
493
494 case OR_size:
495 out << "size (" << placement->get_x_size() << " "
496 << placement->get_y_size() << ")";
497 break;
498
499 default:
500 out << placement->get_omit_reason();
501 }
502 out << "\n";
503 }
504}
505
506/**
507 * Attempts to resize each PalettteImage down to its smallest possible size.
508 */
511 Pages::iterator pai;
512 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
513 PalettePage *page = (*pai).second;
514 page->optimal_resize();
515 }
516}
517
518/**
519 * Throws away all of the current PaletteImages, so that new ones may be
520 * created (and the packing made more optimal).
521 */
523reset_images() {
524 Pages::iterator pai;
525 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
526 PalettePage *page = (*pai).second;
527 page->reset_images();
528 }
529}
530
531/**
532 * Ensures that each PaletteImage's _shadow_image has the correct filename and
533 * image types, based on what was supplied on the command line and in the .txa
534 * file.
535 */
538 Pages::iterator pai;
539 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
540 PalettePage *page = (*pai).second;
541 page->setup_shadow_images();
542 }
543}
544
545/**
546 * Regenerates each PaletteImage on this group that needs it.
547 */
549update_images(bool redo_all) {
550 Pages::iterator pai;
551 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
552 PalettePage *page = (*pai).second;
553 page->update_images(redo_all);
554 }
555}
556
557/**
558 * Registers the current object as something that can be read from a Bam file.
559 */
563 register_factory(get_class_type(), make_PaletteGroup);
564}
565
566/**
567 * Fills the indicated datagram up with a binary representation of the current
568 * object, in preparation for writing to a Bam file.
569 */
571write_datagram(BamWriter *writer, Datagram &datagram) {
572 TypedWritable::write_datagram(writer, datagram);
573 datagram.add_string(get_name());
574 datagram.add_string(_dirname);
575 _dependent.write_datagram(writer, datagram);
576
577 datagram.add_int32(_dependency_level);
578 datagram.add_int32(_dependency_order);
579 datagram.add_int32(_dirname_order);
580
581 datagram.add_uint32(_placements.size());
582 Placements::const_iterator pli;
583 for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
584 writer->write_pointer(datagram, (*pli));
585 }
586
587 datagram.add_uint32(_pages.size());
588 Pages::const_iterator pai;
589 for (pai = _pages.begin(); pai != _pages.end(); ++pai) {
590 writer->write_pointer(datagram, (*pai).second);
591 }
592 datagram.add_bool(_has_margin_override);
593 datagram.add_int16(_margin_override);
594
595}
596
597/**
598 * Called after the object is otherwise completely read from a Bam file, this
599 * function's job is to store the pointers that were retrieved from the Bam
600 * file for each pointer object written. The return value is the number of
601 * pointers processed from the list.
602 */
604complete_pointers(TypedWritable **p_list, BamReader *manager) {
605 int pi = TypedWritable::complete_pointers(p_list, manager);
606
607 pi += _dependent.complete_pointers(p_list + pi, manager);
608
609 int i;
610 for (i = 0; i < _num_placements; i++) {
611 TexturePlacement *placement;
612 DCAST_INTO_R(placement, p_list[pi++], pi);
613 bool inserted = _placements.insert(placement).second;
614 nassertr(inserted, pi);
615 }
616
617 // We must store the list of pages in a temporary vector first. We can't
618 // put them directly into the map because the map requires that all the
619 // pointers in the page's get_properties() member have been filled in, which
620 // may not have happened yet.
621 _load_pages.reserve(_num_pages);
622 for (i = 0; i < _num_pages; i++) {
623 PalettePage *page;
624 DCAST_INTO_R(page, p_list[pi++], pi);
625 _load_pages.push_back(page);
626 }
627
628 return pi;
629}
630
631/**
632 * This method is called by the BamReader after all pointers everywhere in the
633 * world have been completely read in. It's a hook at which the object can do
634 * whatever final setup it requires that depends on other pointers being
635 * valid.
636 */
639 // Now we can copy the pages into the actual map.
641 for (pi = _load_pages.begin(); pi != _load_pages.end(); ++pi) {
642 PalettePage *page = (*pi);
643 bool inserted = _pages.
644 insert(Pages::value_type(page->get_properties(), page)).second;
645 nassertv(inserted);
646 }
647
648 _load_pages.clear();
649}
650
651/**
652 * This method is called by the BamReader when an object of this type is
653 * encountered in a Bam file; it should allocate and return a new object with
654 * all the data read.
655 */
656TypedWritable *PaletteGroup::
657make_PaletteGroup(const FactoryParams &params) {
658 PaletteGroup *me = new PaletteGroup;
659 DatagramIterator scan;
660 BamReader *manager;
661
662 parse_params(params, scan, manager);
663 me->fillin(scan, manager);
664 manager->register_finalize(me);
665 return me;
666}
667
668/**
669 * Reads the binary data from the given datagram iterator, which was written
670 * by a previous call to write_datagram().
671 */
672void PaletteGroup::
673fillin(DatagramIterator &scan, BamReader *manager) {
674 TypedWritable::fillin(scan, manager);
675 set_name(scan.get_string());
676 _dirname = scan.get_string();
677 _dependent.fillin(scan, manager);
678
679 _dependency_level = scan.get_int32();
680 _dependency_order = scan.get_int32();
681 _dirname_order = scan.get_int32();
682
683 _num_placements = scan.get_uint32();
684 manager->read_pointers(scan, _num_placements);
685
686 _num_pages = scan.get_uint32();
687 manager->read_pointers(scan, _num_pages);
688
689 if(Palettizer::_read_pi_version >= 19) {
690 _has_margin_override = scan.get_bool();
691 _margin_override = scan.get_int16();
692 }
693}
694
695/**
696 * Store textureswap information from textures.txa
697 */
699add_texture_swap_info(const string sourceTextureName, const vector_string &swapTextures) {
700 TextureSwapInfo::iterator tsi = _textureSwapInfo.find(sourceTextureName);
701 if (tsi != _textureSwapInfo.end()) {
702 _textureSwapInfo.erase(tsi);
703 }
704 _textureSwapInfo.insert(TextureSwapInfo::value_type(sourceTextureName, swapTextures));
705}
706
707/**
708 * Returns textureswap information is set or not, True if it's not set.
709 */
711is_none_texture_swap() const {
712 return _textureSwapInfo.empty();
713}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram.
int16_t get_int16()
Extracts a signed 16-bit integer.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
bool get_bool()
Extracts a boolean value.
std::string get_string()
Extracts a variable-length string.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
Definition datagram.I:94
void add_int16(int16_t value)
Adds a signed 16-bit integer to the datagram.
Definition datagram.I:58
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
Definition datagram.I:67
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition datagram.I:34
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
Definition datagram.I:219
An instance of this class is passed to the Factory when requesting it to do its business and construc...
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
std::string get_extension() const
Returns the file extension.
Definition filename.I:400
std::string get_dirname() const
Returns the directory part of the filename.
Definition filename.I:358
const Filename & get_filename() const
Returns the primary filename of the image file.
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
This is the highest level of grouping for TextureImages.
void reset_dependency_level()
Unconditionally sets the dependency level and order of this group to zero, in preparation for a later...
void update_images(bool redo_all)
Regenerates each PaletteImage on this group that needs it.
void get_placements(pvector< TexturePlacement * > &placements) const
Adds the set of TexturePlacements associated with this group to the indicated vector.
bool is_none_texture_swap() const
Returns textureswap information is set or not, True if it's not set.
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
const PaletteGroups & get_groups() const
Returns the set of groups this group depends on.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
int get_egg_count() const
Returns the number of egg files that share this PaletteGroup.
void increment_egg_count()
Increments by one the number of egg files that are known to reference this PaletteGroup.
void unplace(TexturePlacement *placement)
Removes the texture from its position on a PaletteImage, if it has been so placed.
void set_dirname(const std::string &dirname)
Sets the directory name associated with the palette group.
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...
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types,...
bool is_preferred_over(const PaletteGroup &other) const
Returns true if this group should be preferred for adding textures over the other group,...
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
int get_dirname_order() const
Returns the dependency order of this group.
int get_margin_override() const
Returns the set of groups this group depends on.
void write_image_info(std::ostream &out, int indent_level=0) const
Writes a list of the PaletteImages associated with this group, and all of their textures,...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
void add_texture_swap_info(const std::string sourceTextureName, const vector_string &swapTextures)
Store textureswap information from textures.txa.
bool set_dependency_order()
Updates the dependency order of this group.
TexturePlacement * prepare(TextureImage *texture)
Marks the indicated Texture as ready for placing somewhere within this group, and returns a placehold...
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 reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
void clear_depends()
Eliminates all the dependency information for this group.
int get_dependency_level() const
Returns the dependency level of this group.
int get_dependency_order() const
Returns the dependency order of this group.
virtual void finalize(BamReader *manager)
This method is called by the BamReader after all pointers everywhere in the world have been completel...
const std::string & get_dirname() const
Returns the directory name associated with the palette group.
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 set_dependency_level(int level)
Sets the dependency level of this group to the indicated level, provided that level is not lower than...
void place_all()
Once all the textures have been assigned to this group, try to place them all onto suitable PaletteIm...
PalettePage * get_page(const TextureProperties &properties)
Returns the page associated with the indicated properties.
void set_margin_override(const int override)
Returns the set of groups this group depends on.
bool has_margin_override() const
Returns the set of groups this group depends on.
A set of PaletteGroups.
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 make_complete(const PaletteGroups &a)
Completes the set with the transitive closure of all dependencies: for each PaletteGroup already in t...
iterator begin() const
Returns an iterator suitable for traversing the set.
void insert(PaletteGroup *group)
Inserts a new group to the set, if it is not already there.
void clear()
Empties the set.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
iterator end() const
Returns an iterator suitable for traversing the set.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
Definition palettePage.h:33
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
void write_image_info(std::ostream &out, int indent_level=0) const
Writes a list of the PaletteImages associated with this page, and all of their textures,...
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types,...
void update_images(bool redo_all)
Regenerates each PaletteImage on this page that needs it.
void unplace(TexturePlacement *placement)
Removes the TexturePlacement from wherever it has been placed.
const TextureProperties & get_properties() const
Returns the texture grouping properties that all textures in this page share.
void place_all()
Assigns all the textures to their final home in a PaletteImage somewhere.
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
void assign(TexturePlacement *placement)
Adds the indicated texture to the list of textures to consider placing on the page.
TextureImage * get_texture(const std::string &name)
Returns the TextureImage with the given name.
This is a texture image reference as it appears in an egg file: the source image of the texture.
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,...
void pre_txa_file()
Updates any internal state prior to reading the .txa file.
SourceTextureImage * get_preferred_source()
Determines the preferred source image for examining size and reading pixels, etc.
void post_txa_file()
Once the .txa file has been read and the TextureImage matched against it, considers applying the requ...
SourceTextureImage * get_source(const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
Returns the SourceTextureImage corresponding to the given filename(s).
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.
PaletteGroup * get_group() const
Returns the group that this placement represents.
bool is_size_known() const
Returns true if the texture's size is known, false otherwise.
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...
double get_uv_area() const
Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
bool is_placed() const
Returns true if the texture has been placed on a palette image, false otherwise.
TextureImage * get_texture() const
Returns the texture that this placement represents.
bool determine_size()
Attempts to determine the appropriate size of the texture for the given placement.
PalettePage * get_page() const
Returns the particular PalettePage on which the texture has been placed.
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...
This is the set of characteristics of a texture that, if different from another texture,...
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition txaFile.h:30
bool match_texture(TextureImage *texture) const
Searches for a matching line in the .txa file for the given texture and applies its specifications.
Definition txaFile.cxx:149
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
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.
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().
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.