Browse Source

debug output

Dave Schuyler 21 years ago
parent
commit
d973f8a2ac

+ 11 - 18
panda/src/express/virtualFileSystem.cxx

@@ -102,7 +102,6 @@ mount(const Filename &physical_filename, const string &mount_point,
                                  flags);
     _mounts.push_back(mount);
     return true;
-
   } else {
     // It's not a directory; it must be a Multifile.
     PT(Multifile) multifile = new Multifile;
@@ -308,7 +307,6 @@ get_file(const Filename &filename) const {
       if (found_match(found_file, composite_file, mount, "")) {
         return found_file;
       }
-
     } else if (mount_point.empty()) {
       // This is the root mount point; all files are in here.
       if (mount->has_file(strpath)) {
@@ -317,7 +315,6 @@ get_file(const Filename &filename) const {
           return found_file;
         }
       }            
-
     } else if (strpath.length() > mount_point.length() &&
                strpath.substr(0, mount_point.length()) == mount_point &&
                strpath[mount_point.length()] == '/') {
@@ -349,7 +346,7 @@ find_file(const Filename &filename, const DSearchPath &searchpath) const {
   }
 
   int num_directories = searchpath.get_num_directories();
-  for (int i = 0; i < num_directories; i++) {
+  for (int i = 0; i < num_directories; ++i) {
     Filename match(searchpath.get_directory(i), filename);
     if (searchpath.get_directory(i) == "." && 
         filename.is_fully_qualified()) {
@@ -395,12 +392,10 @@ resolve_filename(Filename &filename,
         found = find_file(try_ext.get_fullpath(), searchpath);
       }
     }
-
   } else {
     if (exists(filename)) {
       // The full pathname exists.  Return true.
       return true;
-
     } else {
       // The full pathname doesn't exist with the given extension;
       // does it exist with the default extension?
@@ -439,10 +434,10 @@ find_all_files(const Filename &filename, const DSearchPath &searchpath,
 
   if (filename.is_local()) {
     int num_directories = searchpath.get_num_directories();
-    for (int i = 0; i < num_directories; i++) {
+    for (int i = 0; i < num_directories; ++i) {
       Filename match(searchpath.get_directory(i), filename);
       if (exists(match)) {
-        if (searchpath.get_directory(i) == "." && 
+        if (searchpath.get_directory(i) == "." &&
             filename.is_fully_qualified()) {
           // A special case for the "." directory: to avoid prefixing
           // an endless stream of ./ in front of files, if the
@@ -453,7 +448,7 @@ find_all_files(const Filename &filename, const DSearchPath &searchpath,
         } else {
           results.add_file(match);
         }
-        num_added++;
+        ++num_added;
       }
     }
   }
@@ -464,10 +459,12 @@ find_all_files(const Filename &filename, const DSearchPath &searchpath,
 ////////////////////////////////////////////////////////////////////
 //     Function: VirtualFileSystem::write
 //       Access: Published
-//  Description: 
+//  Description: Print debugging information.
+//               (e.g. from Python or gdb prompt).
 ////////////////////////////////////////////////////////////////////
 void VirtualFileSystem::
 write(ostream &out) const {
+  out << "_cwd" << _cwd << "\n_mounts:\n";
   Mounts::const_iterator mi;
   for (mi = _mounts.begin(); mi != _mounts.end(); ++mi) {
     VirtualFileMount *mount = (*mi);
@@ -541,7 +538,7 @@ get_global_ptr() {
           options = mount_point;
           mount_point = mount_desc.substr(space + 1);
           while (space > 0 && isspace(mount_desc[space - 1])) {
-            space--;
+            --space;
           }
           mount_desc = mount_desc.substr(0, space);
         }
@@ -587,12 +584,12 @@ close_read_file(istream *stream) const {
     // the stream pointer does not call the appropriate global delete
     // function; instead apparently calling the system delete
     // function.  So we call the delete function by hand instead.
-#ifndef NDEBUG
+    #ifndef NDEBUG
     stream->~istream();
     (*global_operator_delete)(stream);
-#else
+    #else
     delete stream;
-#endif
+    #endif
   }
 }
 
@@ -681,7 +678,6 @@ found_match(PT(VirtualFile) &found_file, VirtualFileComposite *&composite_file,
       // If it's not a directory, we're done.
       return true;
     }
-    
   } else {
     // This was our second match.  The previous match(es) must
     // have been directories.
@@ -715,13 +711,10 @@ void VirtualFileSystem::
 parse_option(const string &option, int &flags, string &password) {
   if (option == "0" || option.empty()) {
     // 0 is the null option.
-
   } else if (option == "ro") {
     flags |= MF_read_only;
-
   } else if (option.substr(0, 3) == "pw:") {
     password = option.substr(3);
-
   } else {
     express_cat.warning()
       << "Invalid option on vfs-mount: \"" << option << "\"\n";

+ 14 - 3
panda/src/gobj/materialPool.cxx

@@ -52,7 +52,7 @@ ns_garbage_collect() {
         gobj_cat.debug()
           << "Releasing " << *mat << "\n";
       }
-      num_released++;
+      ++num_released;
     } else {
       new_set.insert(new_set.end(), *mi);
     }
@@ -68,9 +68,9 @@ ns_garbage_collect() {
 //  Description: The nonstatic implementation of list_contents().
 ////////////////////////////////////////////////////////////////////
 void MaterialPool::
-ns_list_contents(ostream &out) {
+ns_list_contents(ostream &out) const {
   out << _materials.size() << " materials:\n";
-  Materials::iterator mi;
+  Materials::const_iterator mi;
   for (mi = _materials.begin(); mi != _materials.end(); ++mi) {
     const Material *mat = (*mi);
     out << "  " << *mat
@@ -91,3 +91,14 @@ get_ptr() {
   }
   return _global_ptr;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: MaterialPool::write
+//       Access: Public, Static
+//  Description: Lists the contents of the material pool to the
+//               indicated output stream.
+////////////////////////////////////////////////////////////////////
+INLINE void MaterialPool::
+write(ostream &out, unsigned int) {
+  get_ptr()->ns_list_contents(out);
+}

+ 2 - 1
panda/src/gobj/materialPool.h

@@ -51,13 +51,14 @@ PUBLISHED:
   INLINE static const Material *get_material(const CPT(Material) &temp);
   INLINE static int garbage_collect();
   INLINE static void list_contents(ostream &out);
+  static void write(ostream &out, unsigned int indent=0);
 
 private:
   INLINE MaterialPool();
 
   const Material *ns_get_material(const CPT(Material) &temp);
   int ns_garbage_collect();
-  void ns_list_contents(ostream &out);
+  void ns_list_contents(ostream &out) const;
 
   static MaterialPool *get_ptr();
 

+ 1 - 1
panda/src/gobj/texture.cxx

@@ -264,7 +264,7 @@ read(const Filename &fullpath, const Filename &alpha_fullpath,
   PNMImage alpha_image;
   if (!alpha_image.read(alpha_fullpath)) {
     gobj_cat.error()
-      << "Texture::read() - couldn't read: " << alpha_fullpath << endl;
+      << "Texture::read() - couldn't read (alpha): " << alpha_fullpath << endl;
     return false;
   }
 

+ 19 - 6
panda/src/gobj/texturePool.cxx

@@ -43,7 +43,6 @@ ns_has_texture(const Filename &orig_filename) {
     VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
     vfs->resolve_filename(filename, get_texture_path());
     vfs->resolve_filename(filename, get_model_path());
-
   } else {
     filename.resolve_filename(get_texture_path());
     filename.resolve_filename(get_model_path());
@@ -76,7 +75,6 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels) {
     VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
     vfs->resolve_filename(filename, get_texture_path()) ||
       vfs->resolve_filename(filename, get_model_path());
-
   } else {
     filename.resolve_filename(get_texture_path()) ||
       filename.resolve_filename(get_model_path());
@@ -95,7 +93,10 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels) {
   if (!tex->read(filename, primary_file_num_channels)) {
     // This texture was not found.
     gobj_cat.error()
-      << "Unable to read texture " << filename << "\n";
+      << "Unable to read texture \"" << filename << "\""
+      << (use_vfs ? " (using vfs) ": "")
+      << " on texture_path " << texture_path
+      << " or model_path " << model_path <<"\n";
     return NULL;
   }
 
@@ -224,7 +225,7 @@ ns_garbage_collect() {
         gobj_cat.debug()
           << "Releasing " << (*ti).first << "\n";
       }
-      num_released++;
+      ++num_released;
     } else {
       new_set.insert(new_set.end(), *ti);
     }
@@ -240,9 +241,9 @@ ns_garbage_collect() {
 //  Description: The nonstatic implementation of list_contents().
 ////////////////////////////////////////////////////////////////////
 void TexturePool::
-ns_list_contents(ostream &out) {
+ns_list_contents(ostream &out) const {
   out << _textures.size() << " textures:\n";
-  Textures::iterator ti;
+  Textures::const_iterator ti;
   for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
     Texture *texture = (*ti).second;
     out << "  " << (*ti).first
@@ -264,3 +265,15 @@ get_ptr() {
   }
   return _global_ptr;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePool::write
+//       Access: Published, Static
+//  Description: Lists the contents of the texture pool to the
+//               indicated output stream.
+//               For debugging.
+////////////////////////////////////////////////////////////////////
+void TexturePool::
+write(ostream &out, unsigned int) {
+  get_ptr()->ns_list_contents(out);
+}

+ 4 - 1
panda/src/gobj/texturePool.h

@@ -59,6 +59,9 @@ PUBLISHED:
   INLINE static void clear_fake_texture_image();
   INLINE static bool has_fake_texture_image();
   INLINE static const string &get_fake_texture_image();
+  
+  // static void output(ostream &out);
+  static void write(ostream &out, unsigned int indent=0);
 
 private:
   INLINE TexturePool();
@@ -73,7 +76,7 @@ private:
   void ns_release_texture(Texture *texture);
   void ns_release_all_textures();
   int ns_garbage_collect();
-  void ns_list_contents(ostream &out);
+  void ns_list_contents(ostream &out) const;
 
   static TexturePool *get_ptr();
 

+ 15 - 3
panda/src/pgraph/modelPool.cxx

@@ -121,7 +121,7 @@ ns_garbage_collect() {
         loader_cat.debug()
           << "Releasing " << (*ti).first << "\n";
       }
-      num_released++;
+      ++num_released;
     } else {
       new_set.insert(new_set.end(), *ti);
     }
@@ -137,9 +137,9 @@ ns_garbage_collect() {
 //  Description: The nonstatic implementation of list_contents().
 ////////////////////////////////////////////////////////////////////
 void ModelPool::
-ns_list_contents(ostream &out) {
+ns_list_contents(ostream &out) const {
   out << _models.size() << " models:\n";
-  Models::iterator ti;
+  Models::const_iterator ti;
   for (ti = _models.begin(); ti != _models.end(); ++ti) {
     out << "  " << (*ti).first
         << " (count = " << (*ti).second->get_ref_count() << ")\n";
@@ -159,3 +159,15 @@ get_ptr() {
   }
   return _global_ptr;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ModelPool::write
+//       Access: Public, Static
+//  Description: Lists the contents of the model pool to the
+//               indicated output stream.
+//               Helps with debugging.
+////////////////////////////////////////////////////////////////////
+void ModelPool::
+write(ostream &out, unsigned int) {
+  get_ptr()->ns_list_contents(out);
+}

+ 2 - 1
panda/src/pgraph/modelPool.h

@@ -59,6 +59,7 @@ PUBLISHED:
   INLINE static int garbage_collect();
 
   INLINE static void list_contents(ostream &out);
+  static void write(ostream &out, unsigned int indent=0);
 
 private:
   INLINE ModelPool();
@@ -69,7 +70,7 @@ private:
   void ns_release_model(const string &filename);
   void ns_release_all_models();
   int ns_garbage_collect();
-  void ns_list_contents(ostream &out);
+  void ns_list_contents(ostream &out) const;
 
   static ModelPool *get_ptr();
 

+ 14 - 4
panda/src/text/fontPool.cxx

@@ -176,9 +176,9 @@ ns_garbage_collect() {
 //  Description: The nonstatic implementation of list_contents().
 ////////////////////////////////////////////////////////////////////
 void FontPool::
-ns_list_contents(ostream &out) {
+ns_list_contents(ostream &out) const {
   out << _fonts.size() << " fonts:\n";
-  Fonts::iterator ti;
+  Fonts::const_iterator ti;
   for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
     TextFont *font = (*ti).second;
     out << "  " << (*ti).first
@@ -205,13 +205,12 @@ lookup_filename(const string &str, string &index_str,
   int colon = (int)str.length() - 1;
   // Scan backwards over digits for a colon.
   while (colon >= 0 && isdigit(str[colon])) {
-    colon--;
+    --colon;
   }
   if (colon >= 0 && str[colon] == ':') {
     string digits = str.substr(colon + 1);
     filename = str.substr(0, colon);
     face_index = atoi(digits.c_str());
-
   } else {
     filename = str;
     face_index = 0;
@@ -244,3 +243,14 @@ get_ptr() {
   }
   return _global_ptr;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: FontPool::write
+//       Access: Public, Static
+//  Description: Lists the contents of the font pool to the
+//               indicated output stream.
+////////////////////////////////////////////////////////////////////
+void FontPool::
+write(ostream &out, unsigned int) {
+  get_ptr()->ns_list_contents(out);
+}

+ 2 - 1
panda/src/text/fontPool.h

@@ -49,6 +49,7 @@ PUBLISHED:
   INLINE static int garbage_collect();
 
   INLINE static void list_contents(ostream &out);
+  static void write(ostream &out, unsigned int indent=0);
 
 private:
   INLINE FontPool();
@@ -59,7 +60,7 @@ private:
   void ns_release_font(const string &filename);
   void ns_release_all_fonts();
   int ns_garbage_collect();
-  void ns_list_contents(ostream &out);
+  void ns_list_contents(ostream &out) const;
 
   static void lookup_filename(const string &str, string &index_str,
                               Filename &filename, int &face_index);