Panda3D
|
00001 // Filename: paletteGroup.h 00002 // Created by: drose (28Nov00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PALETTEGROUP_H 00016 #define PALETTEGROUP_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "paletteGroups.h" 00021 #include "textureProperties.h" 00022 00023 #include "namable.h" 00024 #include "typedWritable.h" 00025 00026 #include "pset.h" 00027 #include "pvector.h" 00028 #include "vector_string.h" 00029 00030 class EggFile; 00031 class TexturePlacement; 00032 class PalettePage; 00033 class TextureImage; 00034 class TxaFile; 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Class : PaletteGroup 00038 // Description : This is the highest level of grouping for 00039 // TextureImages. Textures are assigned to one or 00040 // several PaletteGroups based on the information in the 00041 // .txa file; each PaletteGroup is conceptually a 00042 // collection of textures that are to be moved around 00043 // (into texture memory, downloaded, etc.) in one big 00044 // chunk. It is the set of all textures that may be 00045 // displayed together at any given time. 00046 //////////////////////////////////////////////////////////////////// 00047 class PaletteGroup : public TypedWritable, public Namable { 00048 public: 00049 PaletteGroup(); 00050 00051 void set_dirname(const string &dirname); 00052 bool has_dirname() const; 00053 const string &get_dirname() const; 00054 00055 void clear_depends(); 00056 void group_with(PaletteGroup *other); 00057 const PaletteGroups &get_groups() const; 00058 00059 void get_placements(pvector<TexturePlacement *> &placements) const; 00060 void get_complete_placements(pvector<TexturePlacement *> &placements) const; 00061 00062 void reset_dependency_level(); 00063 void set_dependency_level(int level); 00064 bool set_dependency_order(); 00065 int get_dependency_level() const; 00066 int get_dependency_order() const; 00067 int get_dirname_order() const; 00068 00069 void set_margin_override(const int override); 00070 int get_margin_override() const; 00071 bool has_margin_override() const; 00072 00073 bool is_preferred_over(const PaletteGroup &other) const; 00074 00075 void increment_egg_count(); 00076 int get_egg_count() const; 00077 00078 PalettePage *get_page(const TextureProperties &properties); 00079 00080 TexturePlacement *prepare(TextureImage *texture); 00081 00082 void unplace(TexturePlacement *placement); 00083 00084 void place_all(); 00085 void update_unknown_textures(const TxaFile &txa_file); 00086 00087 void write_image_info(ostream &out, int indent_level = 0) const; 00088 void optimal_resize(); 00089 void reset_images(); 00090 void setup_shadow_images(); 00091 void update_images(bool redo_all); 00092 00093 void add_texture_swap_info(const string sourceTextureName, const vector_string &swapTextures); 00094 bool is_none_texture_swap() const; 00095 00096 private: 00097 string _dirname; 00098 int _egg_count; 00099 PaletteGroups _dependent; 00100 int _dependency_level; 00101 int _dependency_order; 00102 int _dirname_order; 00103 00104 typedef pset<TexturePlacement *> Placements; 00105 Placements _placements; 00106 00107 typedef pmap<TextureProperties, PalettePage *> Pages; 00108 Pages _pages; 00109 00110 typedef pmap<string, vector_string> TextureSwapInfo; 00111 TextureSwapInfo _textureSwapInfo; 00112 00113 // The TypedWritable interface follows. 00114 public: 00115 static void register_with_read_factory(); 00116 virtual void write_datagram(BamWriter *writer, Datagram &datagram); 00117 virtual int complete_pointers(TypedWritable **p_list, 00118 BamReader *manager); 00119 virtual void finalize(BamReader *manager); 00120 00121 protected: 00122 static TypedWritable *make_PaletteGroup(const FactoryParams ¶ms); 00123 void fillin(DatagramIterator &scan, BamReader *manager); 00124 00125 private: 00126 // These values are only filled in while reading from the bam file; 00127 // don't use them otherwise. 00128 int _num_placements; 00129 int _num_pages; 00130 bool _has_margin_override; 00131 int _margin_override; 00132 pvector<PalettePage *> _load_pages; 00133 00134 public: 00135 static TypeHandle get_class_type() { 00136 return _type_handle; 00137 } 00138 static void init_type() { 00139 TypedWritable::init_type(); 00140 Namable::init_type(); 00141 register_type(_type_handle, "PaletteGroup", 00142 TypedWritable::get_class_type(), 00143 Namable::get_class_type()); 00144 } 00145 virtual TypeHandle get_type() const { 00146 return get_class_type(); 00147 } 00148 00149 private: 00150 static TypeHandle _type_handle; 00151 00152 friend class PaletteGroups; 00153 }; 00154 00155 #endif 00156