Panda3D
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"
27 #include "indirectCompareNames.h"
28 #include "pvector.h"
29 
30 using std::string;
31 
32 TypeHandle PaletteGroup::_type_handle;
33 
34 /**
35  *
36  */
37 PaletteGroup::
38 PaletteGroup() {
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  */
52 void PaletteGroup::
53 set_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  */
61 bool PaletteGroup::
62 has_dirname() const {
63  return !_dirname.empty();
64 }
65 
66 /**
67  * Returns the directory name associated with the palette group. See
68  * set_dirname().
69  */
70 const string &PaletteGroup::
71 get_dirname() const {
72  return _dirname;
73 }
74 
75 /**
76  * Eliminates all the dependency information for this group.
77  */
78 void PaletteGroup::
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  */
93 void PaletteGroup::
95  _dependent.insert(other);
96 }
97 
98 /**
99  * Returns the set of groups this group depends on.
100  */
102 get_groups() const {
103  return _dependent;
104 }
105 
106 /**
107  * Returns the set of groups this group depends on.
108  */
109 int PaletteGroup::
111  return _margin_override;
112 }
113 
114 /**
115  * Returns the set of groups this group depends on.
116  */
117 void PaletteGroup::
118 set_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  */
126 bool PaletteGroup::
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  */
137 void PaletteGroup::
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  */
149 void PaletteGroup::
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  */
168 void PaletteGroup::
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  */
183 void PaletteGroup::
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  */
203 bool PaletteGroup::
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  */
252 int PaletteGroup::
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  */
267 int PaletteGroup::
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  */
281 int PaletteGroup::
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  */
291 bool PaletteGroup::
292 is_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  */
310 void PaletteGroup::
312  _egg_count++;
313 }
314 
315 /**
316  * Returns the number of egg files that share this PaletteGroup.
317  */
318 int PaletteGroup::
319 get_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  */
328 get_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  */
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  */
388 void PaletteGroup::
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  */
407 void PaletteGroup::
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  */
434 void PaletteGroup::
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  */
459 void PaletteGroup::
460 write_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  */
509 void PaletteGroup::
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  */
522 void PaletteGroup::
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  */
536 void PaletteGroup::
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  */
548 void PaletteGroup::
549 update_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  */
560 void PaletteGroup::
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  */
570 void PaletteGroup::
571 write_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  */
603 int PaletteGroup::
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  */
637 void PaletteGroup::
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  */
656 TypedWritable *PaletteGroup::
657 make_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  */
672 void PaletteGroup::
673 fillin(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  */
698 void PaletteGroup::
699 add_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  */
710 bool PaletteGroup::
712  return _textureSwapInfo.empty();
713 }
TexturePlacement::is_size_known
bool is_size_known() const
Returns true if the texture's size is known, false otherwise.
Definition: texturePlacement.cxx:392
PaletteGroup::clear_depends
void clear_depends()
Eliminates all the dependency information for this group.
Definition: paletteGroup.cxx:79
TextureImage::got_txa_file
bool got_txa_file() const
Returns true if this TextureImage has been looked up in the .txa file this session,...
Definition: textureImage.cxx:412
DatagramIterator::get_string
std::string get_string()
Extracts a variable-length string.
Definition: datagramIterator.cxx:26
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
PaletteGroup::get_dependency_order
int get_dependency_order() const
Returns the dependency order of this group.
Definition: paletteGroup.cxx:268
PalettePage::get_properties
const TextureProperties & get_properties() const
Returns the texture grouping properties that all textures in this page share.
Definition: palettePage.cxx:62
palettePage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TextureImage::get_source
SourceTextureImage * get_source(const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
Returns the SourceTextureImage corresponding to the given filename(s).
Definition: textureImage.cxx:519
PaletteGroup::place_all
void place_all()
Once all the textures have been assigned to this group, try to place them all onto suitable PaletteIm...
Definition: paletteGroup.cxx:408
DatagramIterator::get_int32
int32_t get_int32()
Extracts a signed 32-bit integer.
Definition: datagramIterator.I:107
PaletteGroup
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:43
PaletteGroups::write_datagram
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
Definition: paletteGroups.cxx:291
pvector< TexturePlacement * >
DatagramIterator::get_int16
int16_t get_int16()
Extracts a signed 16-bit integer.
Definition: datagramIterator.I:88
PaletteGroup::update_images
void update_images(bool redo_all)
Regenerates each PaletteImage on this group that needs it.
Definition: paletteGroup.cxx:549
PaletteGroups::complete_pointers
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...
Definition: paletteGroups.cxx:308
PaletteGroup::set_dependency_level
void set_dependency_level(int level)
Sets the dependency level of this group to the indicated level, provided that level is not lower than...
Definition: paletteGroup.cxx:184
Filename::get_dirname
std::string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:358
PaletteGroup::add_texture_swap_info
void add_texture_swap_info(const std::string sourceTextureName, const vector_string &swapTextures)
Store textureswap information from textures.txa.
Definition: paletteGroup.cxx:699
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PaletteGroup::get_dirname
const std::string & get_dirname() const
Returns the directory name associated with the palette group.
Definition: paletteGroup.cxx:71
ImageFile::get_filename
const Filename & get_filename() const
Returns the primary filename of the image file.
Definition: imageFile.cxx:225
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
PaletteGroup::update_unknown_textures
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...
Definition: paletteGroup.cxx:435
TypedWritable::complete_pointers
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().
Definition: typedWritable.cxx:81
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
TxaFile::match_texture
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
PaletteGroup::has_dirname
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
Definition: paletteGroup.cxx:62
IndirectCompareNames
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
Definition: indirectCompareNames.h:26
PaletteGroup::reset_images
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
Definition: paletteGroup.cxx:523
PaletteGroup::group_with
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
Definition: paletteGroup.cxx:94
PaletteGroup::finalize
virtual void finalize(BamReader *manager)
This method is called by the BamReader after all pointers everywhere in the world have been completel...
Definition: paletteGroup.cxx:638
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
TextureImage::pre_txa_file
void pre_txa_file()
Updates any internal state prior to reading the .txa file.
Definition: textureImage.cxx:265
PalettePage::setup_shadow_images
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types,...
Definition: palettePage.cxx:191
PaletteGroup::get_page
PalettePage * get_page(const TextureProperties &properties)
Returns the page associated with the indicated properties.
Definition: paletteGroup.cxx:328
BamWriter::write_pointer
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317
texturePlacement.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TxaFile
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition: txaFile.h:30
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
PaletteGroup::is_preferred_over
bool is_preferred_over(const PaletteGroup &other) const
Returns true if this group should be preferred for adding textures over the other group,...
Definition: paletteGroup.cxx:292
PaletteGroup::get_complete_placements
void get_complete_placements(pvector< TexturePlacement * > &placements) const
Adds the set of TexturePlacements associated with this group and all dependent groups to the indicate...
Definition: paletteGroup.cxx:150
TexturePlacement::get_properties
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
Definition: texturePlacement.cxx:111
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textureImage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PalettePage::place_all
void place_all()
Assigns all the textures to their final home in a PaletteImage somewhere.
Definition: palettePage.cxx:80
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
SourceTextureImage
This is a texture image reference as it appears in an egg file: the source image of the texture.
Definition: sourceTextureImage.h:28
TextureImage::post_txa_file
void post_txa_file()
Once the .txa file has been read and the TextureImage matched against it, considers applying the requ...
Definition: textureImage.cxx:289
ImageFile::get_alpha_filename
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
Definition: imageFile.cxx:235
Datagram::add_string
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
Definition: datagram.I:219
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PaletteGroup::set_margin_override
void set_margin_override(const int override)
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:118
BamReader::register_finalize
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
Definition: bamReader.cxx:808
TexturePlacement::get_page
PalettePage * get_page() const
Returns the particular PalettePage on which the texture has been placed.
Definition: texturePlacement.cxx:465
TexturePlacement::get_omit_reason
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.
Definition: texturePlacement.cxx:401
paletteImage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PaletteGroups::insert
void insert(PaletteGroup *group)
Inserts a new group to the set, if it is not already there.
Definition: paletteGroups.cxx:55
PalettePage::optimal_resize
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
Definition: palettePage.cxx:161
ImageFile::get_alpha_file_channel
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
Definition: imageFile.cxx:246
BamReader::read_pointers
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
Definition: bamReader.cxx:653
DatagramIterator::get_bool
bool get_bool()
Extracts a boolean value.
Definition: datagramIterator.I:48
PaletteGroup::get_margin_override
int get_margin_override() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:110
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PaletteGroup::has_margin_override
bool has_margin_override() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:127
PalettePage::update_images
void update_images(bool redo_all)
Regenerates each PaletteImage on this page that needs it.
Definition: palettePage.cxx:203
TexturePlacement::get_x_size
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...
Definition: texturePlacement.cxx:411
TexturePlacement::get_y_size
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...
Definition: texturePlacement.cxx:422
PaletteGroup::get_egg_count
int get_egg_count() const
Returns the number of egg files that share this PaletteGroup.
Definition: paletteGroup.cxx:319
palettizer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PalettePage::unplace
void unplace(TexturePlacement *placement)
Removes the TexturePlacement from wherever it has been placed.
Definition: palettePage.cxx:134
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: typedWritable.cxx:54
PaletteGroup::write_image_info
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,...
Definition: paletteGroup.cxx:460
PaletteGroup::complete_pointers
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...
Definition: paletteGroup.cxx:604
PaletteGroups::begin
iterator begin() const
Returns an iterator suitable for traversing the set.
Definition: paletteGroups.cxx:200
Datagram::add_int16
void add_int16(int16_t value)
Adds a signed 16-bit integer to the datagram.
Definition: datagram.I:58
PalettePage::reset_images
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
Definition: palettePage.cxx:174
PaletteGroup::optimal_resize
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
Definition: paletteGroup.cxx:510
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PalettePage
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
Definition: palettePage.h:33
PalettePage::assign
void assign(TexturePlacement *placement)
Adds the indicated texture to the list of textures to consider placing on the page.
Definition: palettePage.cxx:71
sourceTextureImage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PaletteGroup::set_dirname
void set_dirname(const std::string &dirname)
Sets the directory name associated with the palette group.
Definition: paletteGroup.cxx:53
PaletteGroup::set_dependency_order
bool set_dependency_order()
Updates the dependency order of this group.
Definition: paletteGroup.cxx:204
Datagram::add_int32
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:67
PaletteGroup::get_dependency_level
int get_dependency_level() const
Returns the dependency level of this group.
Definition: paletteGroup.cxx:253
TexturePlacement::get_texture
TextureImage * get_texture() const
Returns the texture that this placement represents.
Definition: texturePlacement.cxx:103
TextureProperties
This is the set of characteristics of a texture that, if different from another texture,...
Definition: textureProperties.h:30
Datagram::add_uint32
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
Definition: datagram.I:94
PaletteGroup::register_with_read_factory
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Definition: paletteGroup.cxx:561
PaletteGroups::make_complete
void make_complete(const PaletteGroups &a)
Completes the set with the transitive closure of all dependencies: for each PaletteGroup already in t...
Definition: paletteGroups.cxx:75
TexturePlacement
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
Definition: texturePlacement.h:41
Datagram::add_bool
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition: datagram.I:34
PaletteGroups::clear
void clear()
Empties the set.
Definition: paletteGroups.cxx:176
PaletteGroup::get_placements
void get_placements(pvector< TexturePlacement * > &placements) const
Adds the set of TexturePlacements associated with this group to the indicated vector.
Definition: paletteGroup.cxx:138
PalettePage::write_image_info
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,...
Definition: palettePage.cxx:144
datagramIterator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PaletteGroup::unplace
void unplace(TexturePlacement *placement)
Removes the texture from its position on a PaletteImage, if it has been so placed.
Definition: paletteGroup.cxx:389
TexturePlacement::get_group
PaletteGroup * get_group() const
Returns the group that this placement represents.
Definition: texturePlacement.cxx:119
TexturePlacement::get_uv_area
double get_uv_area() const
Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.
Definition: texturePlacement.cxx:433
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TexturePlacement::is_placed
bool is_placed() const
Returns true if the texture has been placed on a palette image, false otherwise.
Definition: texturePlacement.cxx:448
DatagramIterator::get_uint32
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
Definition: datagramIterator.I:164
TypedWritable::fillin
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...
Definition: typedWritable.cxx:103
PaletteGroup::increment_egg_count
void increment_egg_count()
Increments by one the number of egg files that are known to reference this PaletteGroup.
Definition: paletteGroup.cxx:311
Palettizer::get_texture
TextureImage * get_texture(const std::string &name)
Returns the TextureImage with the given name.
Definition: palettizer.cxx:838
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PaletteGroups
A set of PaletteGroups.
Definition: paletteGroups.h:28
PaletteGroup::prepare
TexturePlacement * prepare(TextureImage *texture)
Marks the indicated Texture as ready for placing somewhere within this group, and returns a placehold...
Definition: paletteGroup.cxx:347
PaletteGroup::setup_shadow_images
void setup_shadow_images()
Ensures that each PaletteImage's _shadow_image has the correct filename and image types,...
Definition: paletteGroup.cxx:537
PaletteGroup::is_none_texture_swap
bool is_none_texture_swap() const
Returns textureswap information is set or not, True if it's not set.
Definition: paletteGroup.cxx:711
PaletteGroup::get_dirname_order
int get_dirname_order() const
Returns the dependency order of this group.
Definition: paletteGroup.cxx:282
TextureImage::get_preferred_source
SourceTextureImage * get_preferred_source()
Determines the preferred source image for examining size and reading pixels, etc.
Definition: textureImage.cxx:547
PaletteGroup::reset_dependency_level
void reset_dependency_level()
Unconditionally sets the dependency level and order of this group to zero, in preparation for a later...
Definition: paletteGroup.cxx:169
Filename::get_extension
std::string get_extension() const
Returns the file extension.
Definition: filename.I:400
paletteGroup.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
parse_params
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
PaletteGroups::end
iterator end() const
Returns an iterator suitable for traversing the set.
Definition: paletteGroups.cxx:208
TexturePlacement::determine_size
bool determine_size()
Attempts to determine the appropriate size of the texture for the given placement.
Definition: texturePlacement.cxx:196
TextureImage
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:46
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PaletteGroup::get_groups
const PaletteGroups & get_groups() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:102
PaletteGroups::fillin
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
Definition: paletteGroups.cxx:339
PaletteGroup::write_datagram
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
Definition: paletteGroup.cxx:571
indirectCompareNames.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.