*** empty log message ***

This commit is contained in:
David Rose 2000-11-09 08:19:19 +00:00
parent a534f2b338
commit 6f9ffaaf6b
16 changed files with 105 additions and 43 deletions

View File

@ -10,7 +10,7 @@
#define SOURCES \ #define SOURCES \
attribFile.cxx attribFile.h config_egg_palettize.cxx \ attribFile.cxx attribFile.h config_egg_palettize.cxx \
eggPalettize.cxx eggPalettize.h \ eggPalettize.cxx eggPalettize.h \
imageFile.cxx imageFile.h palette.cxx palette.h paletteGroup.cxx \ palette.cxx palette.h paletteGroup.cxx \
paletteGroup.h pTexture.cxx pTexture.h sourceEgg.cxx \ paletteGroup.h pTexture.cxx pTexture.h sourceEgg.cxx \
sourceEgg.h string_utils.cxx string_utils.h \ sourceEgg.h string_utils.cxx string_utils.h \
textureEggRef.cxx textureEggRef.h textureOmitReason.h \ textureEggRef.cxx textureEggRef.h textureOmitReason.h \

View File

@ -29,9 +29,12 @@ AttribFile(const Filename &filename) {
_pi_filename.set_extension("pi"); _pi_filename.set_extension("pi");
_txa_fd = -1; _txa_fd = -1;
_default_group = (PaletteGroup *)NULL;
_optimal = false; _optimal = false;
_txa_needs_rewrite = false; _txa_needs_rewrite = false;
_map_dirname = "%s";
_pal_xsize = 512; _pal_xsize = 512;
_pal_ysize = 512; _pal_ysize = 512;
_default_margin = 2; _default_margin = 2;
@ -177,6 +180,18 @@ get_group(const string &group_name) {
return new_group; return new_group;
} }
////////////////////////////////////////////////////////////////////
// Function: AttribFile::set_default_group
// Access: Public
// Description: Sets the PaletteGroup that should be associated
// with any textures or egg files not explicitly placed
// in a different group.
////////////////////////////////////////////////////////////////////
void AttribFile::
set_default_group(PaletteGroup *default_group) {
_default_group = default_group;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AttribFile::get_default_group // Function: AttribFile::get_default_group
// Access: Public // Access: Public
@ -186,7 +201,10 @@ get_group(const string &group_name) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PaletteGroup *AttribFile:: PaletteGroup *AttribFile::
get_default_group() { get_default_group() {
return get_group(_name); if (_default_group == (PaletteGroup *)NULL) {
_default_group = get_group(_name);
}
return _default_group;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -40,6 +40,7 @@ public:
void update_params(EggPalettize *prog); void update_params(EggPalettize *prog);
PaletteGroup *get_group(const string &group_name); PaletteGroup *get_group(const string &group_name);
void set_default_group(PaletteGroup *default_group);
PaletteGroup *get_default_group(); PaletteGroup *get_default_group();
void get_egg_group_requests(); void get_egg_group_requests();
@ -116,13 +117,15 @@ private:
Filename _txa_filename; Filename _txa_filename;
Filename _pi_filename; Filename _pi_filename;
PaletteGroup *_default_group;
public: public:
// These parameter values come from the command line, or from the // These parameter values come from the command line, or from the
// .pi file if omitted from the command line. These are the // .pi file if omitted from the command line. These are the
// parameter values that specifically refer to textures and // parameter values that specifically refer to textures and
// palettes, and thus should be stored in the .pi file for future // palettes, and thus should be stored in the .pi file for future
// reference. // reference.
Filename _map_dirname; string _map_dirname;
int _pal_xsize, _pal_ysize; int _pal_xsize, _pal_ysize;
int _default_margin; int _default_margin;
bool _force_power_2; bool _force_power_2;

View File

@ -51,22 +51,35 @@ EggPalettize() : EggMultiFilter(true) {
"Do not process anything, but report statistics on all palette " "Do not process anything, but report statistics on all palette "
"information files read.", "information files read.",
&EggPalettize::dispatch_none, &_statistics_only); &EggPalettize::dispatch_none, &_statistics_only);
redescribe_option
("d", // We redefine -d using add_option() instead of redescribe_option()
// so it gets listed along with these other options that relate.
add_option
("d", "dirname", 0,
"The directory in which to write the palettized egg files. This is " "The directory in which to write the palettized egg files. This is "
"only necessary if more than one egg file is processed at the same " "only necessary if more than one egg file is processed at the same "
"time; if it is included, each egg file will be processed and written " "time; if it is included, each egg file will be processed and written "
"into the indicated directory."); "into the indicated directory.",
&EggPalettize::dispatch_filename, &_got_output_dirname, &_output_dirname);
add_option add_option
("dm", "dirname", 0, ("dm", "dirname", 0,
"The directory in which to place all maps: generated palettes, " "The directory in which to place all maps: generated palettes, "
"as well as images which were not placed on palettes " "as well as images which were not placed on palettes "
"(but may have been resized). It is often best if this is a " "(but may have been resized). If this contains the string %s, "
"fully-qualified directory name rather than a relative directory name, " "this will be replaced with the \"dir\" string associated with a "
"particularly if -d is used to write the egg files to a directory " "palette group.",
"different than the current directory, as the same name is written " &EggPalettize::dispatch_string, &_got_map_dirname, &_map_dirname);
"into the egg files.", add_option
&EggPalettize::dispatch_filename, &_got_map_dirname, &_map_dirname); ("g", "group", 0,
"The default palette group that egg files will be assigned to if they "
"are not explicitly assigned to any other group.",
&EggPalettize::dispatch_string, &_got_default_groupname, &_default_groupname);
add_option
("gdir", "name", 0,
"The \"dir\" string to associate with the default palette group "
"specified with -g, if no other dir name is given in the .txa file.",
&EggPalettize::dispatch_string, &_got_default_groupdir, &_default_groupdir);
add_option add_option
("f", "", 0, ("f", "", 0,
"Force an optimal packing. By default, textures are added to " "Force an optimal packing. By default, textures are added to "
@ -127,7 +140,7 @@ EggPalettize() : EggMultiFilter(true) {
add_option add_option
("2", "", 0, ("2", "", 0,
"Force textures that have been left out of the palette to a size " "Force textures that have been left out of the palette to a size "
"which is an even power of 2. They will be scaled down to " "which is an integer power of 2. They will be scaled down to "
"achieve this.", "achieve this.",
&EggPalettize::dispatch_none, &_got_force_power_2); &EggPalettize::dispatch_none, &_got_force_power_2);
add_option add_option
@ -534,6 +547,14 @@ run() {
for (afi = _attrib_files.begin(); afi != _attrib_files.end(); ++afi) { for (afi = _attrib_files.begin(); afi != _attrib_files.end(); ++afi) {
AttribFile &af = *(*afi); AttribFile &af = *(*afi);
if (_got_default_groupname) {
PaletteGroup *group = af.get_group(_default_groupname);
if (_got_default_groupdir) {
group->set_dirname(_default_groupdir);
}
af.set_default_group(group);
}
if (!af.grab_lock()) { if (!af.grab_lock()) {
// Failing to grab the write lock on the attribute file is a // Failing to grab the write lock on the attribute file is a
// fatal error. // fatal error.

View File

@ -38,8 +38,12 @@ public:
// The following parameter values specifically relate to textures // The following parameter values specifically relate to textures
// and palettes. These values are stored in the .pi file for future // and palettes. These values are stored in the .pi file for future
// reference. // reference.
Filename _map_dirname; string _map_dirname;
bool _got_map_dirname; bool _got_map_dirname;
string _default_groupname;
bool _got_default_groupname;
string _default_groupdir;
bool _got_default_groupdir;
int _pal_size[2]; int _pal_size[2];
bool _got_palette_size; bool _got_palette_size;
int _default_margin; int _default_margin;

View File

@ -108,18 +108,6 @@ add_filename(const Filename &filename) {
} }
} }
Filename PTexture::
get_filename() const {
Filename filename = _name;
filename.set_dirname(_attrib_file->_map_dirname);
return filename;
}
Filename PTexture::
get_basename() const {
return _name;
}
bool PTexture:: bool PTexture::
get_size(int &xsize, int &ysize, int &zsize) { get_size(int &xsize, int &ysize, int &zsize) {
if (!_got_size) { if (!_got_size) {

View File

@ -8,7 +8,7 @@
#include <pandatoolbase.h> #include <pandatoolbase.h>
#include "imageFile.h" #include <filename.h>
#include <set> #include <set>
#include <map> #include <map>
@ -27,7 +27,7 @@ class TextureEggRef;
// palettization on a number of different groups, but it // palettization on a number of different groups, but it
// must have the same size in each group. // must have the same size in each group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class PTexture : public ImageFile { class PTexture {
public: public:
PTexture(AttribFile *attrib_file, const Filename &name); PTexture(AttribFile *attrib_file, const Filename &name);
~PTexture(); ~PTexture();
@ -36,9 +36,6 @@ public:
void add_filename(const Filename &filename); void add_filename(const Filename &filename);
virtual Filename get_filename() const;
virtual Filename get_basename() const;
bool get_size(int &xsize, int &ysize, int &zsize); bool get_size(int &xsize, int &ysize, int &zsize);
void set_size(int xsize, int ysize, int zsize); void set_size(int xsize, int ysize, int zsize);

View File

@ -332,7 +332,7 @@ finalize_palette() {
sprintf(index_str, "%03d", _index); sprintf(index_str, "%03d", _index);
_basename = _group->get_name() + "-palette." + index_str + ".rgb"; _basename = _group->get_name() + "-palette." + index_str + ".rgb";
Filename dirname(_attrib_file->_map_dirname, _group->get_dirname()); Filename dirname = _group->get_full_dirname(_attrib_file);
_filename = _basename; _filename = _basename;
_filename.set_dirname(dirname.get_fullpath()); _filename.set_dirname(dirname.get_fullpath());
} else { } else {
@ -387,6 +387,7 @@ generate_image() {
} }
nout << "Writing " << _filename << "\n"; nout << "Writing " << _filename << "\n";
_filename.make_dir();
if (!palette.write(_filename)) { if (!palette.write(_filename)) {
nout << "Error in writing.\n"; nout << "Error in writing.\n";
okflag = false; okflag = false;

View File

@ -8,8 +8,6 @@
#include <pandatoolbase.h> #include <pandatoolbase.h>
#include "imageFile.h"
#include <filename.h> #include <filename.h>
#include <vector> #include <vector>
@ -28,7 +26,7 @@ class AttribFile;
// depending on the number and size of the palettized // depending on the number and size of the palettized
// textures. // textures.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class Palette : public ImageFile { class Palette {
public: public:
Palette(const Filename &filename, PaletteGroup *group, Palette(const Filename &filename, PaletteGroup *group,
int xsize, int ysize, int components, AttribFile *attrib_file); int xsize, int ysize, int components, AttribFile *attrib_file);
@ -36,8 +34,8 @@ public:
int xsize, int ysize, int components, AttribFile *attrib_file); int xsize, int ysize, int components, AttribFile *attrib_file);
~Palette(); ~Palette();
virtual Filename get_filename() const; Filename get_filename() const;
virtual Filename get_basename() const; Filename get_basename() const;
PaletteGroup *get_group() const; PaletteGroup *get_group() const;

View File

@ -8,6 +8,8 @@
#include "palette.h" #include "palette.h"
#include "attribFile.h" #include "attribFile.h"
#include <stdio.h> // for sprintf()
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PaletteGroup::Constructor // Function: PaletteGroup::Constructor
// Access: Public // Access: Public
@ -89,6 +91,20 @@ set_dirname(const string &dirname) {
_dirname = dirname; _dirname = dirname;
} }
////////////////////////////////////////////////////////////////////
// Function: PaletteGroup::get_full_dirname
// Access: Public
// Description: Computes the actual directory name to which palettes
// and textures should be written, based on
// get_dirname() and on the -dm parameter.
////////////////////////////////////////////////////////////////////
string PaletteGroup::
get_full_dirname(AttribFile *attrib_file) const {
char buffer[4096];
sprintf(buffer, attrib_file->_map_dirname.c_str(), _dirname.c_str());
return buffer;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PaletteGroup::pack_texture // Function: PaletteGroup::pack_texture
// Access: Public // Access: Public

View File

@ -54,6 +54,8 @@ public:
const string &get_dirname() const; const string &get_dirname() const;
void set_dirname(const string &dirname); void set_dirname(const string &dirname);
string get_full_dirname(AttribFile *attrib_file) const;
bool pack_texture(TexturePacking *packing, AttribFile *attrib_file); bool pack_texture(TexturePacking *packing, AttribFile *attrib_file);
bool generate_palette_images(); bool generate_palette_images();
void optimal_resize(); void optimal_resize();

View File

@ -271,7 +271,7 @@ update_trefs() {
packing->get_omit() != OR_none) { packing->get_omit() != OR_none) {
// This texture wasn't palettized, so just rename the // This texture wasn't palettized, so just rename the
// reference to the new one. // reference to the new one.
eggtex->set_fullpath(texture->get_filename()); eggtex->set_fullpath(packing->get_new_filename());
} else { } else {
// This texture was palettized, so redirect the tref to point // This texture was palettized, so redirect the tref to point

View File

@ -413,12 +413,12 @@ needs_refresh() {
} else { } else {
// Compare to the resized file. // Compare to the resized file.
target_filename = _texture->get_filename(); target_filename = get_new_filename();
} }
if (!any_change) { if (!any_change) {
any_change = any_change =
(target_filename.compare_timestamps(_texture->_filename, true, false) < 0); (target_filename.compare_timestamps(get_old_filename(), true, false) < 0);
} }
} }
@ -472,11 +472,21 @@ write_unplaced(ostream &out) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
Filename TexturePacking:: Filename TexturePacking::
get_new_filename() const { get_new_filename() const {
Filename dirname(_attrib_file->_map_dirname, _group->get_dirname()); Filename dirname = _group->get_full_dirname(_attrib_file);
Filename new_filename(dirname, _texture->get_name()); Filename new_filename(dirname, _texture->get_name());
return new_filename; return new_filename;
} }
////////////////////////////////////////////////////////////////////
// Function: TexturePacking::get_old_filename
// Access: Public
// Description: Returns the original filename of this texture.
////////////////////////////////////////////////////////////////////
Filename TexturePacking::
get_old_filename() const {
return _texture->_filename;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: TexturePacking::transfer // Function: TexturePacking::transfer
// Access: Public // Access: Public
@ -491,7 +501,7 @@ bool TexturePacking::
transfer() { transfer() {
bool okflag = true; bool okflag = true;
Filename old_filename = _texture->_filename; Filename old_filename = get_old_filename();
Filename new_filename = get_new_filename(); Filename new_filename = get_new_filename();
if (new_filename == old_filename) { if (new_filename == old_filename) {
nout << "*** Texture " << _texture->get_name() nout << "*** Texture " << _texture->get_name()
@ -542,6 +552,7 @@ transfer() {
} }
} }
new_filename.make_dir();
if (!image->write(new_filename)) { if (!image->write(new_filename)) {
nout << "Error in writing.\n"; nout << "Error in writing.\n";
okflag = false; okflag = false;

View File

@ -61,6 +61,7 @@ public:
void write_unplaced(ostream &out) const; void write_unplaced(ostream &out) const;
Filename get_new_filename() const; Filename get_new_filename() const;
Filename get_old_filename() const;
bool transfer(); bool transfer();
private: private:

View File

@ -153,6 +153,7 @@ write_eggs() {
} }
nout << "Writing " << filename << "\n"; nout << "Writing " << filename << "\n";
filename.make_dir();
if (!data->write_egg(filename)) { if (!data->write_egg(filename)) {
// Error writing an egg file; abort. // Error writing an egg file; abort.
exit(1); exit(1);

View File

@ -96,6 +96,7 @@ get_output() {
} else { } else {
// Attempt to open the named file. // Attempt to open the named file.
unlink(_output_filename.c_str()); unlink(_output_filename.c_str());
_output_filename.make_dir();
if (!_output_filename.open_write(_output_stream)) { if (!_output_filename.open_write(_output_stream)) {
nout << "Unable to write to " << _output_filename << "\n"; nout << "Unable to write to " << _output_filename << "\n";
exit(1); exit(1);