Panda3D
eggFile.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 eggFile.h
10  * @author drose
11  * @date 2000-11-28
12  */
13 
14 #ifndef EGGFILE_H
15 #define EGGFILE_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "paletteGroups.h"
20 #include "textureReference.h"
21 #include "eggData.h"
22 #include "filename.h"
23 #include "namable.h"
24 #include "typedWritable.h"
25 #include "pointerTo.h"
26 #include "pset.h"
27 
28 class TextureImage;
29 
30 /**
31  * This represents a single egg file known to the palettizer. It may
32  * reference a number of textures, and may also be assigned to a number of
33  * groups. All of its textures will try to assign themselves to one of its
34  * groups.
35  */
36 class EggFile : public TypedWritable, public Namable {
37 public:
38  EggFile();
39 
40  bool from_command_line(EggData *data,
41  const Filename &source_filename,
42  const Filename &dest_filename,
43  const std::string &egg_comment);
44 
45  const Filename &get_source_filename() const;
46 
47  void scan_textures();
48  void get_textures(pset<TextureImage *> &result) const;
49 
50  void pre_txa_file();
51  void match_txa_groups(const PaletteGroups &groups);
52  void post_txa_file();
53 
54  const PaletteGroups &get_explicit_groups() const;
56  const PaletteGroups &get_complete_groups() const;
57  void clear_surprise();
58  bool is_surprise() const;
59 
60  void mark_stale();
61  bool is_stale() const;
62 
63  void build_cross_links();
65  void choose_placements();
66 
67  bool has_data() const;
68  bool had_data() const;
69 
70  void update_egg();
71  void remove_egg();
72  bool read_egg(bool noabs);
73  void release_egg_data();
74  bool write_egg();
75 
76  void write_description(std::ostream &out, int indent_level = 0) const;
77  void write_texture_refs(std::ostream &out, int indent_level = 0) const;
78 
79 private:
80  void remove_backstage(EggGroupNode *node);
81  void rescan_textures();
82 
83 private:
84  PT(EggData) _data;
85  Filename _current_directory;
86  Filename _source_filename;
87  Filename _dest_filename;
88  std::string _egg_comment;
89 
91  Textures _textures;
92 
93  bool _first_txa_match;
94  PaletteGroups _explicitly_assigned_groups;
95  PaletteGroup *_default_group;
96  PaletteGroups _complete_groups;
97  bool _is_surprise;
98  bool _is_stale;
99  bool _had_data;
100 
101 
102  // The TypedWritable interface follows.
103 public:
104  static void register_with_read_factory();
105  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
106  virtual int complete_pointers(TypedWritable **p_list,
107  BamReader *manager);
108 
109 protected:
110  static TypedWritable *make_EggFile(const FactoryParams &params);
111  void fillin(DatagramIterator &scan, BamReader *manager);
112 
113 private:
114  // This value is only filled in while reading from the bam file; don't use
115  // it otherwise.
116  int _num_textures;
117 
118 public:
119  static TypeHandle get_class_type() {
120  return _type_handle;
121  }
122  static void init_type() {
123  TypedWritable::init_type();
124  Namable::init_type();
125  register_type(_type_handle, "EggFile",
126  TypedWritable::get_class_type(),
127  Namable::get_class_type());
128  }
129  virtual TypeHandle get_type() const {
130  return get_class_type();
131  }
132 
133 private:
134  static TypeHandle _type_handle;
135 };
136 
137 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
This represents a single egg file known to the palettizer.
Definition: eggFile.h:36
void remove_egg()
Removes this egg file from all things that reference it, in preparation for removing it from the data...
Definition: eggFile.cxx:462
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:231
void pre_txa_file()
Does some processing prior to scanning the .txa file.
Definition: eggFile.cxx:221
bool from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, const std::string &egg_comment)
Accepts the information about the egg file as supplied from the command line.
Definition: eggFile.cxx:57
void choose_placements()
Once all the textures have been assigned to groups (but before they may actually be placed),...
Definition: eggFile.cxx:381
bool is_stale() const
Returns true if the egg file needs to be updated, i.e.
Definition: eggFile.cxx:313
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
Definition: eggFile.cxx:707
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:210
void write_description(std::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:591
const Filename & get_source_filename() const
Returns the filename this egg file was read from.
Definition: eggFile.cxx:91
const PaletteGroups & get_complete_groups() const
Returns the complete set of PaletteGroups that the egg file is assigned to.
Definition: eggFile.cxx:276
void update_egg()
Once all textures have been placed appropriately, updates the egg file with all the information to re...
Definition: eggFile.cxx:447
void apply_properties_to_source()
Calls apply_properties_to_source() for each texture reference, updating all the referenced source tex...
Definition: eggFile.cxx:364
void clear_surprise()
Removes the 'surprise' flag; this file has been successfully matched against a line in the ....
Definition: eggFile.cxx:285
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:266
void build_cross_links()
Calls TextureImage::note_egg_file() and SourceTextureImage::increment_egg_count() for each texture th...
Definition: eggFile.cxx:325
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:257
void release_egg_data()
Releases the memory that was loaded by a previous call to read_egg().
Definition: eggFile.cxx:553
void scan_textures()
Scans the egg file for texture references and updates the _textures list appropriately.
Definition: eggFile.cxx:102
void write_texture_refs(std::ostream &out, int indent_level=0) const
Writes the list of texture references to the indicated output stream, one per line.
Definition: eggFile.cxx:612
bool had_data() const
Returns true if the EggData for this EggFile has ever been loaded in this session.
Definition: eggFile.cxx:438
bool is_surprise() const
Returns true if this particular egg file is a 'surprise', i.e.
Definition: eggFile.cxx:294
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Definition: eggFile.cxx:697
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: eggFile.cxx:740
bool write_egg()
Writes out the egg file to its _dest_filename.
Definition: eggFile.cxx:569
void mark_stale()
Marks this particular egg file as stale, meaning that something has changed, such as the location of ...
Definition: eggFile.cxx:304
void post_txa_file()
Once the egg file has been matched against all of the matching lines the .txa file,...
Definition: eggFile.cxx:249
bool read_egg(bool noabs)
Reads in the egg file from its _source_filename.
Definition: eggFile.cxx:480
bool has_data() const
Returns true if the EggData for this EggFile has been loaded, and not yet released.
Definition: eggFile.cxx:429
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
A base class for all things which can have a name.
Definition: namable.h:26
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:43
A set of PaletteGroups.
Definition: paletteGroups.h:28
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.