diff --git a/pandatool/src/cvscopy/cvsCopy.cxx b/pandatool/src/cvscopy/cvsCopy.cxx index b129a2459e..f4e56c9915 100644 --- a/pandatool/src/cvscopy/cvsCopy.cxx +++ b/pandatool/src/cvscopy/cvsCopy.cxx @@ -26,7 +26,7 @@ CVSCopy() { add_option ("f", "", 80, - "Force copy to happen without any input from the user. If a file " + "Force the copy to happen without any input from the user. If a file " "with the same name exists anywhere in the source hierarchy, it will " "be overwritten without prompting; if a file does not yet exist, it " "will be created in the directory named by -d or by -m, as appropriate.", @@ -53,8 +53,8 @@ CVSCopy() { add_option ("root", "dirname", 80, "Specify the root of the CVS source hierarchy. The default is to " - "use the ppremake convention of locating the directory containing " - "Package.pp.", + "use the ppremake convention of locating the directory above the -d " + "directory that contains a file called Package.pp.", &CVSCopy::dispatch_filename, &_got_root_dirname, &_root_dirname); add_option @@ -62,8 +62,8 @@ CVSCopy() { "Specify the name of the file that must exist in each directory for " "it to be considered part of the CVS source hierarchy. The default " "is the ppremake convention, \"Sources.pp\". Other likely candidates " - "are \"CVS\" to search the entire CVS hierarchy, or \".\" to include " - "all subdirectories.", + "are \"CVS\" to search a CVS hierarchy, or \".\" to include " + "all subdirectories indiscriminately.", &CVSCopy::dispatch_filename, NULL, &_key_filename); add_option @@ -86,18 +86,20 @@ CVSCopy() { // directory hierarchy, and chooses a place to import // it. Copies the file by calling copy_file(). // -// Type is an integer number that is defined by the -// derivated class; CVSCopy simply passes it unchanged -// to copy_file(). It presumably gives the class a hint -// as to how the file should be copied. Suggested_dir -// is the suggested directory in which to copy the file, -// if it does not already exist elsewhere. +// Extra_data may be NULL or a pointer to some +// user-defined structure; CVSCopy simply passes it +// unchanged to copy_file(). It presumably gives the +// class a hint as to how the file should be copied. +// Suggested_dir is the suggested directory in which to +// copy the file, if it does not already exist +// elsewhere. // // On success, returns the CVSSourceDirectory it was // actually copied to. On failure, returns NULL. //////////////////////////////////////////////////////////////////// CVSSourceDirectory *CVSCopy:: -import(const Filename &source, int type, CVSSourceDirectory *suggested_dir) { +import(const Filename &source, void *extra_data, + CVSSourceDirectory *suggested_dir) { CopiedFiles::const_iterator ci; ci = _copied_files.find(source); if (ci != _copied_files.end()) { @@ -106,7 +108,7 @@ import(const Filename &source, int type, CVSSourceDirectory *suggested_dir) { } if (!source.exists()) { - cerr << "Source filename " << source << " does not exist!\n"; + nout << "Source filename " << source << " does not exist!\n"; return (CVSSourceDirectory *)NULL; } @@ -116,12 +118,14 @@ import(const Filename &source, int type, CVSSourceDirectory *suggested_dir) { _tree.choose_directory(basename, suggested_dir, _force, _interactive); nassertr(dir != (CVSSourceDirectory *)NULL, dir); + nout << "Copying " << basename << " to " << dir->get_path() << "\n"; + Filename dest = dir->get_fullpath() + "/" + basename; _copied_files[source] = dir; bool new_file = !dest.exists(); - if (!copy_file(source, dest, dir, type, new_file)) { + if (!copy_file(source, dest, dir, extra_data, new_file)) { return (CVSSourceDirectory *)NULL; } if (new_file) { @@ -196,6 +200,52 @@ post_command_line() { return true; } +//////////////////////////////////////////////////////////////////// +// Function: CVSCopy::copy_binary_file +// Access: Protected +// Description: Copies a file without modifying it or scanning it in +// any way. This is particularly useful for copying +// textures. This is provided as a convenience function +// for derived programs because so many model file +// formats will also require copying textures or other +// black-box files. +//////////////////////////////////////////////////////////////////// +bool CVSCopy:: +copy_binary_file(Filename source, Filename dest) { + source.set_binary(); + dest.set_binary(); + + ifstream in; + ofstream out; + if (!source.open_read(in)) { + nout << "Cannot read " << source << "\n"; + return false; + } + + if (!dest.open_write(out)) { + nout << "Cannot write " << dest << "\n"; + return false; + } + + int c; + c = in.get(); + while (!in.eof() && !in.fail() && !out.fail()) { + out.put(c); + c = in.get(); + } + + if (in.fail()) { + nout << "Error reading " << source << "\n"; + return false; + } + if (out.fail()) { + nout << "Error writing " << dest << "\n"; + return false; + } + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: CVSCopy::create_file // Access: Protected diff --git a/pandatool/src/cvscopy/cvsCopy.h b/pandatool/src/cvscopy/cvsCopy.h index f00ee8f211..0a3b4caa70 100644 --- a/pandatool/src/cvscopy/cvsCopy.h +++ b/pandatool/src/cvscopy/cvsCopy.h @@ -25,15 +25,19 @@ public: CVSCopy(); CVSSourceDirectory * - import(const Filename &source, int type, CVSSourceDirectory *suggested_dir); + import(const Filename &source, void *extra_data, + CVSSourceDirectory *suggested_dir); protected: virtual bool handle_args(Args &args); virtual bool post_command_line(); - virtual bool copy_file(Filename source, Filename dest, + virtual bool copy_file(const Filename &source, const Filename &dest, CVSSourceDirectory *dest_dir, - int type, bool new_file)=0; + void *extra_data, bool new_file)=0; + + bool copy_binary_file(Filename source, Filename dest); + bool create_file(const Filename &filename); private: diff --git a/pandatool/src/cvscopy/cvsSourceDirectory.cxx b/pandatool/src/cvscopy/cvsSourceDirectory.cxx index b5c834921a..629e6a0661 100644 --- a/pandatool/src/cvscopy/cvsSourceDirectory.cxx +++ b/pandatool/src/cvscopy/cvsSourceDirectory.cxx @@ -234,7 +234,7 @@ bool CVSSourceDirectory:: scan(const string &fullpath, const string &key_filename) { DIR *root = opendir(fullpath.c_str()); if (root == (DIR *)NULL) { - cerr << "Unable to scan directory " << fullpath << "\n"; + nout << "Unable to scan directory " << fullpath << "\n"; return false; } diff --git a/pandatool/src/cvscopy/cvsSourceTree.cxx b/pandatool/src/cvscopy/cvsSourceTree.cxx index 832f8e6aa7..cb48407d33 100644 --- a/pandatool/src/cvscopy/cvsSourceTree.cxx +++ b/pandatool/src/cvscopy/cvsSourceTree.cxx @@ -251,7 +251,7 @@ restore_cwd() { if (chdir(start_fullpath.c_str()) < 0) { // Hey! We can't get back to the directory we started from! perror(start_fullpath.c_str()); - cerr << "Can't continue, aborting.\n"; + nout << "Can't continue, aborting.\n"; exit(1); } } @@ -269,7 +269,7 @@ prompt_user(const string &filename, CVSSourceDirectory *suggested_dir, bool force, bool interactive) { if (dirs.size() == 1) { // The file already exists in exactly one place. - if (interactive) { + if (!interactive) { return dirs[0]; } CVSSourceDirectory *result = ask_existing(filename, dirs[0]); @@ -286,6 +286,13 @@ prompt_user(const string &filename, CVSSourceDirectory *suggested_dir, if (result != (CVSSourceDirectory *)NULL) { return result; } + + } else { // dirs.empty() + nassertr(dirs.empty(), (CVSSourceDirectory *)NULL); + // The file does not already exist. + if (!interactive) { + return suggested_dir; + } } // The file does not already exist, or the user declined to replace diff --git a/pandatool/src/cvscopy/testCopy.cxx b/pandatool/src/cvscopy/testCopy.cxx index 6805a62840..4a62f34998 100644 --- a/pandatool/src/cvscopy/testCopy.cxx +++ b/pandatool/src/cvscopy/testCopy.cxx @@ -49,40 +49,9 @@ run() { // true, then dest does not already exist. //////////////////////////////////////////////////////////////////// bool TestCopy:: -copy_file(Filename source, Filename dest, - CVSSourceDirectory *dir, int type, bool new_file) { - source.set_binary(); - dest.set_binary(); - - ifstream in; - ofstream out; - if (!source.open_read(in)) { - cerr << "Cannot read " << source << "\n"; - return false; - } - - if (!dest.open_write(out)) { - cerr << "Cannot write " << dest << "\n"; - return false; - } - - int c; - c = in.get(); - while (!in.eof() && !in.fail() && !out.fail()) { - out.put(c); - c = in.get(); - } - - if (in.fail()) { - cerr << "Error reading " << source << "\n"; - return false; - } - if (out.fail()) { - cerr << "Error writing " << dest << "\n"; - return false; - } - - return true; +copy_file(const Filename &source, const Filename &dest, + CVSSourceDirectory *, void *, bool) { + return copy_binary_file(source, dest); } diff --git a/pandatool/src/cvscopy/testCopy.h b/pandatool/src/cvscopy/testCopy.h index 443e442729..d0b9727e29 100644 --- a/pandatool/src/cvscopy/testCopy.h +++ b/pandatool/src/cvscopy/testCopy.h @@ -22,8 +22,9 @@ public: void run(); protected: - virtual bool copy_file(Filename source, Filename dest, - CVSSourceDirectory *dir, int type, bool new_file); + virtual bool copy_file(const Filename &source, const Filename &dest, + CVSSourceDirectory *dir, void *extra_data, + bool new_file); }; #endif diff --git a/pandatool/src/flt/fltHeader.cxx b/pandatool/src/flt/fltHeader.cxx index 589335f181..db43464449 100644 --- a/pandatool/src/flt/fltHeader.cxx +++ b/pandatool/src/flt/fltHeader.cxx @@ -6,6 +6,7 @@ #include "fltHeader.h" #include "fltRecordReader.h" #include "fltRecordWriter.h" +#include "fltUnsupportedRecord.h" TypeHandle FltHeader::_type_handle; @@ -1104,6 +1105,9 @@ extract_ancillary(FltRecordReader &reader) { case FO_texture: return extract_texture(reader); + case FO_texture_map_palette: + return extract_texture_map(reader); + case FO_light_definition: return extract_light_source(reader); @@ -1324,6 +1328,28 @@ extract_texture(FltRecordReader &reader) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: FltHeader::extract_texture_map +// Access: Private +// Description: Reads the a single texture mapping ancillary record. +// This describes a kind of texture mapping in the +// texture mapping palette. +//////////////////////////////////////////////////////////////////// +bool FltHeader:: +extract_texture_map(FltRecordReader &reader) { + // At the moment, we ignore this, since it's not needed for + // meaningful extraction of data: we can get this information from + // the UV's for a particular model. We just add an + // UnsupportedRecord for it. + FltUnsupportedRecord *rec = new FltUnsupportedRecord(this); + if (!rec->extract_record(reader)) { + return false; + } + add_ancillary(rec); + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: FltHeader::extract_light_source // Access: Private diff --git a/pandatool/src/flt/fltHeader.h b/pandatool/src/flt/fltHeader.h index 80a3d5b691..5ba67640a8 100644 --- a/pandatool/src/flt/fltHeader.h +++ b/pandatool/src/flt/fltHeader.h @@ -277,6 +277,7 @@ private: bool extract_color_palette(FltRecordReader &reader); bool extract_material(FltRecordReader &reader); bool extract_texture(FltRecordReader &reader); + bool extract_texture_map(FltRecordReader &reader); bool extract_light_source(FltRecordReader &reader); bool extract_eyepoint_palette(FltRecordReader &reader); diff --git a/pandatool/src/flt/fltRecord.cxx b/pandatool/src/flt/fltRecord.cxx index 9c9ddf3762..4e47e49ff1 100644 --- a/pandatool/src/flt/fltRecord.cxx +++ b/pandatool/src/flt/fltRecord.cxx @@ -337,6 +337,7 @@ is_ancillary(FltOpcode opcode) { case FO_texture: case FO_eyepoint_palette: case FO_light_definition: + case FO_texture_map_palette: return true; case FO_header: diff --git a/pandatool/src/flt/fltTexture.cxx b/pandatool/src/flt/fltTexture.cxx index 6575633547..7395bfb344 100644 --- a/pandatool/src/flt/fltTexture.cxx +++ b/pandatool/src/flt/fltTexture.cxx @@ -158,14 +158,24 @@ read_attr_data() { //////////////////////////////////////////////////////////////////// FltError FltTexture:: write_attr_data() const { + return write_attr_data(get_attr_filename()); +} + +//////////////////////////////////////////////////////////////////// +// Function: FltTexture::write_attr_data +// Access: Public +// Description: Writes the texture's .attr file to the named +// file. +//////////////////////////////////////////////////////////////////// +FltError FltTexture:: +write_attr_data(Filename attr_filename) const { Datagram datagram; FltError result = pack_attr(datagram); if (result != FE_ok) { return result; } - Filename attr_filename = get_attr_filename(); - + attr_filename.set_binary(); ofstream attr; if (!attr_filename.open_write(attr)) { return FE_could_not_open; diff --git a/pandatool/src/flt/fltTexture.h b/pandatool/src/flt/fltTexture.h index f9985e6636..0a725c3503 100644 --- a/pandatool/src/flt/fltTexture.h +++ b/pandatool/src/flt/fltTexture.h @@ -30,6 +30,7 @@ public: Filename get_attr_filename() const; FltError read_attr_data(); FltError write_attr_data() const; + FltError write_attr_data(Filename attr_filename) const; // The remaining fields are from the attr file. enum FileFormat { diff --git a/pandatool/src/flt/fltUnsupportedRecord.h b/pandatool/src/flt/fltUnsupportedRecord.h index 5627f5360d..3995d36271 100644 --- a/pandatool/src/flt/fltUnsupportedRecord.h +++ b/pandatool/src/flt/fltUnsupportedRecord.h @@ -46,6 +46,8 @@ public: private: static TypeHandle _type_handle; + + friend class FltHeader; }; #endif diff --git a/pandatool/src/flt/fltVertex.cxx b/pandatool/src/flt/fltVertex.cxx index 998eb5aade..fcb5ba7ffe 100644 --- a/pandatool/src/flt/fltVertex.cxx +++ b/pandatool/src/flt/fltVertex.cxx @@ -216,6 +216,6 @@ build_record(FltRecordWriter &writer) const { datagram.add_be_uint32(_color_index); - nassertr(datagram.get_length() == get_record_length() - 4, true); + nassertr((int)datagram.get_length() == get_record_length() - 4, true); return true; } diff --git a/pandatool/src/fltprogs/Sources.pp b/pandatool/src/fltprogs/Sources.pp new file mode 100644 index 0000000000..f276573025 --- /dev/null +++ b/pandatool/src/fltprogs/Sources.pp @@ -0,0 +1,11 @@ +#begin bin_target + #define TARGET fltcopy + #define LOCAL_LIBS cvscopy flt + + #define OTHER_LIBS \ + dconfig:c dtool:m pystub + + #define SOURCES \ + fltCopy.cxx fltCopy.h + +#end bin_target diff --git a/pandatool/src/progbase/programBase.cxx b/pandatool/src/progbase/programBase.cxx index 86beee44cd..39ced555fe 100644 --- a/pandatool/src/progbase/programBase.cxx +++ b/pandatool/src/progbase/programBase.cxx @@ -12,6 +12,7 @@ // with libprogbase.so. #include +#include #include #include #include @@ -629,6 +630,29 @@ dispatch_filename(const string &opt, const string &arg, void *var) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: ProgramBase::dispatch_search_path +// Access: Protected +// Description: Standard dispatch function for an option that takes +// one parameter, which is to be interpreted as a +// colon-delimited search path. The data pointer is to +// a DSearchPath variable. This kind of option may +// appear multiple times on the command line; each time, +// the new search paths are appended. +//////////////////////////////////////////////////////////////////// +bool ProgramBase:: +dispatch_search_path(const string &opt, const string &arg, void *var) { + if (arg.empty()) { + nout << "-" << opt << " requires a search path parameter.\n"; + return false; + } + + DSearchPath *ip = (DSearchPath *)var; + ip->append_path(arg); + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: ProgramBase::dispatch_coordinate_system // Access: Protected diff --git a/pandatool/src/progbase/programBase.h b/pandatool/src/progbase/programBase.h index 044735eca2..5b94285533 100644 --- a/pandatool/src/progbase/programBase.h +++ b/pandatool/src/progbase/programBase.h @@ -64,6 +64,7 @@ protected: bool dispatch_double(const string &opt, const string &arg, void *var); bool dispatch_string(const string &opt, const string &arg, void *var); bool dispatch_filename(const string &opt, const string &arg, void *var); + bool dispatch_search_path(const string &opt, const string &arg, void *var); bool dispatch_coordinate_system(const string &opt, const string &arg, void *var); bool handle_help_option(const string &opt, const string &arg, void *); diff --git a/pandatool/src/progbase/test_prog.cxx b/pandatool/src/progbase/test_prog.cxx index 1fc171b903..d3986af10e 100644 --- a/pandatool/src/progbase/test_prog.cxx +++ b/pandatool/src/progbase/test_prog.cxx @@ -5,6 +5,8 @@ #include "programBase.h" +#include + class TestProgram : public ProgramBase { public: TestProgram();