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