From c2eed48e876dd35491b7b5b61ae30cec4ca81b33 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 20 Nov 2000 23:12:11 +0000 Subject: [PATCH] *** empty log message *** --- dtool/src/dtoolutil/dSearchPath.cxx | 10 ++++++ dtool/src/dtoolutil/dSearchPath.h | 1 + pandatool/src/cvscopy/cvsCopy.cxx | 3 +- pandatool/src/flt/fltExternalReference.cxx | 16 +++++++++ pandatool/src/flt/fltExternalReference.h | 2 ++ pandatool/src/flt/fltHeader.cxx | 41 ++++++++++++++++++++-- pandatool/src/flt/fltHeader.h | 13 +++++-- pandatool/src/fltprogs/fltCopy.cxx | 7 ++-- 8 files changed, 81 insertions(+), 12 deletions(-) diff --git a/dtool/src/dtoolutil/dSearchPath.cxx b/dtool/src/dtoolutil/dSearchPath.cxx index bf8cd65293..12be49a7af 100644 --- a/dtool/src/dtoolutil/dSearchPath.cxx +++ b/dtool/src/dtoolutil/dSearchPath.cxx @@ -145,6 +145,16 @@ append_directory(const Filename &directory) { _directories.push_back(directory); } +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::prepend_directory +// Access: Public +// Description: Adds a new directory to the front of the search list. +//////////////////////////////////////////////////////////////////// +void DSearchPath:: +prepend_directory(const Filename &directory) { + _directories.insert(_directories.begin(), directory); +} + //////////////////////////////////////////////////////////////////// // Function: DSearchPath::append_path // Access: Public diff --git a/dtool/src/dtoolutil/dSearchPath.h b/dtool/src/dtoolutil/dSearchPath.h index 86d562ee93..c306331e2c 100644 --- a/dtool/src/dtoolutil/dSearchPath.h +++ b/dtool/src/dtoolutil/dSearchPath.h @@ -49,6 +49,7 @@ PUBLISHED: void clear(); void append_directory(const Filename &directory); + void prepend_directory(const Filename &directory); void append_path(const string &path, const string &delimiters = ": \t\n"); diff --git a/pandatool/src/cvscopy/cvsCopy.cxx b/pandatool/src/cvscopy/cvsCopy.cxx index 220dd42364..bd627bfa2b 100644 --- a/pandatool/src/cvscopy/cvsCopy.cxx +++ b/pandatool/src/cvscopy/cvsCopy.cxx @@ -290,6 +290,7 @@ copy_binary_file(Filename source, Filename dest) { return false; } + dest.unlink(); if (!dest.open_write(out)) { nout << "Cannot write " << dest << "\n"; return false; @@ -310,7 +311,7 @@ copy_binary_file(Filename source, Filename dest) { nout << "Error writing " << dest << "\n"; return false; } - + return true; } diff --git a/pandatool/src/flt/fltExternalReference.cxx b/pandatool/src/flt/fltExternalReference.cxx index 7fdf995080..be9f98d96f 100644 --- a/pandatool/src/flt/fltExternalReference.cxx +++ b/pandatool/src/flt/fltExternalReference.cxx @@ -6,6 +6,7 @@ #include "fltExternalReference.h" #include "fltRecordReader.h" #include "fltRecordWriter.h" +#include "fltHeader.h" TypeHandle FltExternalReference::_type_handle; @@ -35,6 +36,21 @@ output(ostream &out) const { } } +//////////////////////////////////////////////////////////////////// +// Function: FltTexture::get_ref_filename +// Access: Public +// Description: Returns the name of the referenced file. If it +// appears to be a relative filename, it will be +// converted to the correct full pathname according to +// the model_path specified in the header. +//////////////////////////////////////////////////////////////////// +Filename FltExternalReference:: +get_ref_filename() const { + Filename file(_filename); + file.resolve_filename(_header->get_model_path()); + return file; +} + //////////////////////////////////////////////////////////////////// // Function: FltExternalReference::extract_record // Access: Protected, Virtual diff --git a/pandatool/src/flt/fltExternalReference.h b/pandatool/src/flt/fltExternalReference.h index d9d121eade..0bbcc60f6b 100644 --- a/pandatool/src/flt/fltExternalReference.h +++ b/pandatool/src/flt/fltExternalReference.h @@ -36,6 +36,8 @@ public: string _bead_id; int _flags; + Filename get_ref_filename() const; + protected: virtual bool extract_record(FltRecordReader &reader); virtual bool build_record(FltRecordWriter &writer) const; diff --git a/pandatool/src/flt/fltHeader.cxx b/pandatool/src/flt/fltHeader.cxx index 43d109d206..ddd8be3c04 100644 --- a/pandatool/src/flt/fltHeader.cxx +++ b/pandatool/src/flt/fltHeader.cxx @@ -83,11 +83,12 @@ read_flt(Filename filename) { return FE_could_not_open; } - // By default, the filename's directory is added to the texture - // search path. + // By default, the filename's directory is added to the texture and + // model search path. string dirname = filename.get_dirname(); if (!dirname.empty()) { - _texture_path.append_directory(dirname); + _texture_path.prepend_directory(dirname); + _model_path.prepend_directory(dirname); } return read_flt(in); @@ -847,6 +848,40 @@ get_texture_path() const { return _texture_path; } +//////////////////////////////////////////////////////////////////// +// Function: FltHeader::set_model_path +// Access: Public +// Description: Sets the search path that relative external +// references will be looked for along. +//////////////////////////////////////////////////////////////////// +void FltHeader:: +set_model_path(const DSearchPath &path) { + _model_path = path; +} + +//////////////////////////////////////////////////////////////////// +// Function: FltHeader::update_model_path +// Access: Public +// Description: Returns a non-const reference to the model search +// path, so that it may be appended to or otherwise +// modified. +//////////////////////////////////////////////////////////////////// +DSearchPath &FltHeader:: +update_model_path() { + return _model_path; +} + +//////////////////////////////////////////////////////////////////// +// Function: FltHeader::get_model_path +// Access: Public +// Description: Returns the search path for looking up external +// references. +//////////////////////////////////////////////////////////////////// +const DSearchPath &FltHeader:: +get_model_path() const { + return _model_path; +} + //////////////////////////////////////////////////////////////////// // Function: FltHeader::has_light_source // Access: Public diff --git a/pandatool/src/flt/fltHeader.h b/pandatool/src/flt/fltHeader.h index 180f3bf3e2..a3b04ef914 100644 --- a/pandatool/src/flt/fltHeader.h +++ b/pandatool/src/flt/fltHeader.h @@ -182,12 +182,17 @@ public: void add_texture(FltTexture *texture); void remove_texture(int texture_index); - // Sometimes Flt files store textures as relative pathnames. - // Setting this search path helps resolve that tendency. + // Sometimes Flt files store textures and external references as + // relative pathnames. Setting these search paths helps resolve + // that tendency. void set_texture_path(const DSearchPath &path); DSearchPath &update_texture_path(); const DSearchPath &get_texture_path() const; + void set_model_path(const DSearchPath &path); + DSearchPath &update_model_path(); + const DSearchPath &get_model_path() const; + // Accessors into the light source palette. bool has_light_source(int light_index) const; @@ -207,6 +212,9 @@ public: FltTrackplane *get_trackplane(int n); private: + DSearchPath _texture_path; + DSearchPath _model_path; + // Instance subtrees. These are standalone subtrees, which may be // referenced by various points in the hierarchy, stored by instance // ID number. @@ -252,7 +260,6 @@ private: AttrUpdate _auto_attr_update; typedef map Textures; Textures _textures; - DSearchPath _texture_path; // Support for the light source palette. diff --git a/pandatool/src/fltprogs/fltCopy.cxx b/pandatool/src/fltprogs/fltCopy.cxx index 5bb312880a..83121629f4 100644 --- a/pandatool/src/fltprogs/fltCopy.cxx +++ b/pandatool/src/fltprogs/fltCopy.cxx @@ -50,9 +50,6 @@ FltCopy() { //////////////////////////////////////////////////////////////////// void FltCopy:: run() { - if (_search_path.get_num_directories() == 0) { - _search_path.append_directory("."); - } SourceFiles::iterator fi; for (fi = _source_files.begin(); fi != _source_files.end(); ++fi) { ExtraData ed; @@ -99,6 +96,7 @@ copy_flt_file(const Filename &source, const Filename &dest, CVSSourceDirectory *dir) { PT(FltHeader) header = new FltHeader; header->set_texture_path(_search_path); + header->set_model_path(_search_path); // We don't want to automatically generate .attr files--we'd rather // write them out explicitly. @@ -118,8 +116,7 @@ copy_flt_file(const Filename &source, const Filename &dest, Refs::const_iterator ri; for (ri = refs.begin(); ri != refs.end(); ++ri) { FltExternalReference *ref = (*ri); - Filename ref_filename = ref->_filename; - ref_filename.resolve_filename(_search_path); + Filename ref_filename = ref->get_ref_filename(); if (!ref_filename.exists()) { nout << "*** Warning: external reference " << ref_filename