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;
56 void get_complete_placements(pvector<TexturePlacement *> &placements) const;
57
58 void reset_dependency_level();
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
76 TexturePlacement *prepare(TextureImage *texture);
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
100 typedef pset<TexturePlacement *> Placements;
101 Placements _placements;
102
103 typedef pmap<TextureProperties, PalettePage *> Pages;
104 Pages _pages;
105
106 typedef pmap<std::string, vector_string> TextureSwapInfo;
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
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
EggFile
This represents a single egg file known to the palettizer.
Definition: eggFile.h:36
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
Namable
A base class for all things which can have a name.
Definition: namable.h:26
PaletteGroup
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:43
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
PaletteGroup::update_images
void update_images(bool redo_all)
Regenerates each PaletteImage on this group that needs it.
Definition: paletteGroup.cxx:549
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
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::has_dirname
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
Definition: paletteGroup.cxx:62
PaletteGroup::get_groups
const PaletteGroups & get_groups() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:102
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
PaletteGroup::get_egg_count
int get_egg_count() const
Returns the number of egg files that share this PaletteGroup.
Definition: paletteGroup.cxx:319
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
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
PaletteGroup::set_dirname
void set_dirname(const std::string &dirname)
Sets the directory name associated with the palette group.
Definition: paletteGroup.cxx:53
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
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_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::group_with
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
Definition: paletteGroup.cxx:94
PaletteGroup::get_dirname_order
int get_dirname_order() const
Returns the dependency order of this group.
Definition: paletteGroup.cxx:282
PaletteGroup::get_margin_override
int get_margin_override() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:110
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::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
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
PaletteGroup::set_dependency_order
bool set_dependency_order()
Updates the dependency order of this group.
Definition: paletteGroup.cxx:204
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::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
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::optimal_resize
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
Definition: paletteGroup.cxx:510
PaletteGroup::clear_depends
void clear_depends()
Eliminates all the dependency information for this group.
Definition: paletteGroup.cxx:79
PaletteGroup::get_dependency_level
int get_dependency_level() const
Returns the dependency level of this group.
Definition: paletteGroup.cxx:253
PaletteGroup::get_dependency_order
int get_dependency_order() const
Returns the dependency order of this group.
Definition: paletteGroup.cxx:268
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
PaletteGroup::get_dirname
const std::string & get_dirname() const
Returns the directory name associated with the palette group.
Definition: paletteGroup.cxx:71
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
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
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
PaletteGroup::get_page
PalettePage * get_page(const TextureProperties &properties)
Returns the page associated with the indicated properties.
Definition: paletteGroup.cxx:328
PaletteGroup::set_margin_override
void set_margin_override(const int override)
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:118
PaletteGroup::has_margin_override
bool has_margin_override() const
Returns the set of groups this group depends on.
Definition: paletteGroup.cxx:127
PaletteGroups
A set of PaletteGroups.
Definition: paletteGroups.h:28
PalettePage
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
Definition: palettePage.h:33
TextureImage
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:46
TexturePlacement
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
Definition: texturePlacement.h:41
TextureProperties
This is the set of characteristics of a texture that, if different from another texture,...
Definition: textureProperties.h:30
TxaFile
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition: txaFile.h:30
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
pmap< TextureProperties, PalettePage * >
pset< TexturePlacement * >
pvector< TexturePlacement * >
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
paletteGroups.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pset.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
textureProperties.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedWritable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_string.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.