Panda3D
 All Classes Functions Variables Enumerations
paletteGroup.h
1 // Filename: paletteGroup.h
2 // Created by: drose (28Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PALETTEGROUP_H
16 #define PALETTEGROUP_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "paletteGroups.h"
21 #include "textureProperties.h"
22 
23 #include "namable.h"
24 #include "typedWritable.h"
25 
26 #include "pset.h"
27 #include "pvector.h"
28 #include "vector_string.h"
29 
30 class EggFile;
31 class TexturePlacement;
32 class PalettePage;
33 class TextureImage;
34 class TxaFile;
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : PaletteGroup
38 // Description : This is the highest level of grouping for
39 // TextureImages. Textures are assigned to one or
40 // several PaletteGroups based on the information in the
41 // .txa file; each PaletteGroup is conceptually a
42 // collection of textures that are to be moved around
43 // (into texture memory, downloaded, etc.) in one big
44 // chunk. It is the set of all textures that may be
45 // displayed together at any given time.
46 ////////////////////////////////////////////////////////////////////
47 class PaletteGroup : public TypedWritable, public Namable {
48 public:
49  PaletteGroup();
50 
51  void set_dirname(const string &dirname);
52  bool has_dirname() const;
53  const string &get_dirname() const;
54 
55  void clear_depends();
56  void group_with(PaletteGroup *other);
57  const PaletteGroups &get_groups() const;
58 
59  void get_placements(pvector<TexturePlacement *> &placements) const;
61 
63  void set_dependency_level(int level);
64  bool set_dependency_order();
65  int get_dependency_level() const;
66  int get_dependency_order() const;
67  int get_dirname_order() const;
68 
69  void set_margin_override(const int override);
70  int get_margin_override() const;
71  bool has_margin_override() const;
72 
73  bool is_preferred_over(const PaletteGroup &other) const;
74 
75  void increment_egg_count();
76  int get_egg_count() const;
77 
78  PalettePage *get_page(const TextureProperties &properties);
79 
81 
82  void unplace(TexturePlacement *placement);
83 
84  void place_all();
85  void update_unknown_textures(const TxaFile &txa_file);
86 
87  void write_image_info(ostream &out, int indent_level = 0) const;
88  void optimal_resize();
89  void reset_images();
90  void setup_shadow_images();
91  void update_images(bool redo_all);
92 
93  void add_texture_swap_info(const string sourceTextureName, const vector_string &swapTextures);
94  bool is_none_texture_swap() const;
95 
96 private:
97  string _dirname;
98  int _egg_count;
99  PaletteGroups _dependent;
100  int _dependency_level;
101  int _dependency_order;
102  int _dirname_order;
103 
105  Placements _placements;
106 
108  Pages _pages;
109 
111  TextureSwapInfo _textureSwapInfo;
112 
113  // The TypedWritable interface follows.
114 public:
115  static void register_with_read_factory();
116  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
117  virtual int complete_pointers(TypedWritable **p_list,
118  BamReader *manager);
119  virtual void finalize(BamReader *manager);
120 
121 protected:
122  static TypedWritable *make_PaletteGroup(const FactoryParams &params);
123  void fillin(DatagramIterator &scan, BamReader *manager);
124 
125 private:
126  // These values are only filled in while reading from the bam file;
127  // don't use them otherwise.
128  int _num_placements;
129  int _num_pages;
130  bool _has_margin_override;
131  int _margin_override;
132  pvector<PalettePage *> _load_pages;
133 
134 public:
135  static TypeHandle get_class_type() {
136  return _type_handle;
137  }
138  static void init_type() {
139  TypedWritable::init_type();
140  Namable::init_type();
141  register_type(_type_handle, "PaletteGroup",
142  TypedWritable::get_class_type(),
143  Namable::get_class_type());
144  }
145  virtual TypeHandle get_type() const {
146  return get_class_type();
147  }
148 
149 private:
150  static TypeHandle _type_handle;
151 
152  friend class PaletteGroups;
153 };
154 
155 #endif
156 
void setup_shadow_images()
Ensures that each PaletteImage&#39;s _shadow_image has the correct filename and image types...
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...
bool has_margin_override() const
Returns the set of groups this group depends on.
const PaletteGroups & get_groups() const
Returns the set of groups this group depends on.
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...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
bool is_none_texture_swap() const
Returns textureswap information is set or not, True if it&#39;s not set.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:47
void unplace(TexturePlacement *placement)
Removes the texture from its position on a PaletteImage, if it has been so placed.
int get_dirname_order() const
Returns the dependency order of this group.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
Definition: palettePage.h:37
void add_texture_swap_info(const string sourceTextureName, const vector_string &swapTextures)
Store textureswap information from textures.txa.
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 reset_dependency_level()
Unconditionally sets the dependency level and order of this group to zero, in preparation for a later...
bool is_preferred_over(const PaletteGroup &other) const
Returns true if this group should be preferred for adding textures over the other group...
A base class for all things which can have a name.
Definition: namable.h:29
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
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.
int get_margin_override() const
Returns the set of groups this group depends on.
void update_images(bool redo_all)
Regenerates each PaletteImage on this group that needs it.
int get_dependency_order() const
Returns the dependency order of this group.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function&#39;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...
PalettePage * get_page(const TextureProperties &properties)
Returns the page associated with the indicated properties.
void set_dirname(const string &dirname)
Sets the directory name associated with the palette group.
const string & get_dirname() const
Returns the directory name associated with the palette group.
int get_dependency_level() const
Returns the dependency level of this 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.
void get_complete_placements(pvector< TexturePlacement * > &placements) const
Adds the set of TexturePlacements associated with this group and all dependent groups to the indicate...
A set of PaletteGroups.
Definition: paletteGroups.h:31
void increment_egg_count()
Increments by one the number of egg files that are known to reference this PaletteGroup.
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...
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.
Definition: textureImage.h:51
int get_egg_count() const
Returns the number of egg files that share this PaletteGroup.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
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.
This represents a single egg file known to the palettizer.
Definition: eggFile.h:39
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition: txaFile.h:33
void set_margin_override(const int override)
Returns the set of groups this group depends on.
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.