Panda3D
eggFile.h
1 // Filename: eggFile.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 EGGFILE_H
16 #define EGGFILE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "paletteGroups.h"
21 #include "textureReference.h"
22 #include "eggData.h"
23 #include "filename.h"
24 #include "namable.h"
25 #include "typedWritable.h"
26 #include "pointerTo.h"
27 #include "pset.h"
28 
29 class TextureImage;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : EggFile
33 // Description : This represents a single egg file known to the
34 // palettizer. It may reference a number of textures,
35 // and may also be assigned to a number of groups. All
36 // of its textures will try to assign themselves to one
37 // of its groups.
38 ////////////////////////////////////////////////////////////////////
39 class EggFile : public TypedWritable, public Namable {
40 public:
41  EggFile();
42 
43  bool from_command_line(EggData *data,
44  const Filename &source_filename,
45  const Filename &dest_filename,
46  const string &egg_comment);
47 
48  const Filename &get_source_filename() const;
49 
50  void scan_textures();
51  void get_textures(pset<TextureImage *> &result) const;
52 
53  void pre_txa_file();
54  void match_txa_groups(const PaletteGroups &groups);
55  void post_txa_file();
56 
57  const PaletteGroups &get_explicit_groups() const;
59  const PaletteGroups &get_complete_groups() const;
60  void clear_surprise();
61  bool is_surprise() const;
62 
63  void mark_stale();
64  bool is_stale() const;
65 
66  void build_cross_links();
68  void choose_placements();
69 
70  bool has_data() const;
71  bool had_data() const;
72 
73  void update_egg();
74  void remove_egg();
75  bool read_egg(bool noabs);
76  void release_egg_data();
77  bool write_egg();
78 
79  void write_description(ostream &out, int indent_level = 0) const;
80  void write_texture_refs(ostream &out, int indent_level = 0) const;
81 
82 private:
83  void remove_backstage(EggGroupNode *node);
84  void rescan_textures();
85 
86 private:
87  PT(EggData) _data;
88  Filename _current_directory;
89  Filename _source_filename;
90  Filename _dest_filename;
91  string _egg_comment;
92 
94  Textures _textures;
95 
96  bool _noabs;
97  bool _first_txa_match;
98  PaletteGroups _explicitly_assigned_groups;
99  PaletteGroup *_default_group;
100  PaletteGroups _complete_groups;
101  bool _is_surprise;
102  bool _is_stale;
103  bool _had_data;
104 
105 
106  // The TypedWritable interface follows.
107 public:
108  static void register_with_read_factory();
109  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
110  virtual int complete_pointers(TypedWritable **p_list,
111  BamReader *manager);
112 
113 protected:
114  static TypedWritable *make_EggFile(const FactoryParams &params);
115  void fillin(DatagramIterator &scan, BamReader *manager);
116 
117 private:
118  // This value is only filled in while reading from the bam file;
119  // don't use it otherwise.
120  int _num_textures;
121 
122 public:
123  static TypeHandle get_class_type() {
124  return _type_handle;
125  }
126  static void init_type() {
127  TypedWritable::init_type();
128  Namable::init_type();
129  register_type(_type_handle, "EggFile",
130  TypedWritable::get_class_type(),
131  Namable::get_class_type());
132  }
133  virtual TypeHandle get_type() const {
134  return get_class_type();
135  }
136 
137 private:
138  static TypeHandle _type_handle;
139 };
140 
141 #endif
142 
void post_txa_file()
Once the egg file has been matched against all of the matching lines the .txa file, do whatever adjustment is necessary.
Definition: eggFile.cxx:274
void scan_textures()
Scans the egg file for texture references and updates the _textures list appropriately.
Definition: eggFile.cxx:114
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
bool had_data() const
Returns true if the EggData for this EggFile has ever been loaded in this session.
Definition: eggFile.cxx:498
void clear_surprise()
Removes the &#39;surprise&#39; flag; this file has been successfully matched against a line in the ...
Definition: eggFile.cxx:320
void mark_stale()
Marks this particular egg file as stale, meaning that something has changed, such as the location of ...
Definition: eggFile.cxx:345
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
const Filename & get_source_filename() const
Returns the filename this egg file was read from.
Definition: eggFile.cxx:100
void remove_egg()
Removes this egg file from all things that reference it, in preparation for removing it from the data...
Definition: eggFile.cxx:527
void pre_txa_file()
Does some processing prior to scanning the .txa file.
Definition: eggFile.cxx:239
bool read_egg(bool noabs)
Reads in the egg file from its _source_filename.
Definition: eggFile.cxx:549
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
const PaletteGroups & get_explicit_groups() const
Returns the set of PaletteGroups that the egg file has been explicitly assigned to in the ...
Definition: eggFile.cxx:284
void apply_properties_to_source()
Calls apply_properties_to_source() for each texture reference, updating all the referenced source tex...
Definition: eggFile.cxx:416
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
const PaletteGroups & get_complete_groups() const
Returns the complete set of PaletteGroups that the egg file is assigned to.
Definition: eggFile.cxx:309
void choose_placements()
Once all the textures have been assigned to groups (but before they may actually be placed)...
Definition: eggFile.cxx:437
void release_egg_data()
Releases the memory that was loaded by a previous call to read_egg().
Definition: eggFile.cxx:625
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...
Definition: eggFile.cxx:836
A base class for all things which can have a name.
Definition: namable.h:29
void match_txa_groups(const PaletteGroups &groups)
Adds the indicated set of groups, read from the .txa file, to the set of groups to which the egg file...
Definition: eggFile.cxx:252
bool write_egg()
Writes out the egg file to its _dest_filename.
Definition: eggFile.cxx:644
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void update_egg()
Once all textures have been placed appropriately, updates the egg file with all the information to re...
Definition: eggFile.cxx:510
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Definition: eggFile.cxx:786
bool has_data() const
Returns true if the EggData for this EggFile has been loaded, and not yet released.
Definition: eggFile.cxx:487
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
bool from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, const string &egg_comment)
Accepts the information about the egg file as supplied from the command line.
Definition: eggFile.cxx:63
bool is_surprise() const
Returns true if this particular egg file is a &#39;surprise&#39;, i.e.
Definition: eggFile.cxx:332
bool is_stale() const
Returns true if the egg file needs to be updated, i.e.
Definition: eggFile.cxx:357
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.
Definition: eggFile.cxx:799
A set of PaletteGroups.
Definition: paletteGroups.h:31
void write_texture_refs(ostream &out, int indent_level=0) const
Writes the list of texture references to the indicated output stream, one per line.
Definition: eggFile.cxx:691
void get_textures(pset< TextureImage *> &result) const
Fills up the indicated set with the set of textures referenced by this egg file.
Definition: eggFile.cxx:226
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
void build_cross_links()
Calls TextureImage::note_egg_file() and SourceTextureImage::increment_egg_count() for each texture th...
Definition: eggFile.cxx:373
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void write_description(ostream &out, int indent_level=0) const
Writes a one-line description of the egg file and its group assignments to the indicated output strea...
Definition: eggFile.cxx:668
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This represents a single egg file known to the palettizer.
Definition: eggFile.h:39
PaletteGroup * get_default_group() const
Returns the PaletteGroup that was specified as the default group on the command line at the time the ...
Definition: eggFile.cxx:296