debug output

This commit is contained in:
Dave Schuyler 2005-01-06 06:23:24 +00:00
parent dac28d3c1b
commit d973f8a2ac
10 changed files with 84 additions and 39 deletions

View File

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

View File

@ -52,7 +52,7 @@ ns_garbage_collect() {
gobj_cat.debug() gobj_cat.debug()
<< "Releasing " << *mat << "\n"; << "Releasing " << *mat << "\n";
} }
num_released++; ++num_released;
} else { } else {
new_set.insert(new_set.end(), *mi); new_set.insert(new_set.end(), *mi);
} }
@ -68,9 +68,9 @@ ns_garbage_collect() {
// Description: The nonstatic implementation of list_contents(). // Description: The nonstatic implementation of list_contents().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MaterialPool:: void MaterialPool::
ns_list_contents(ostream &out) { ns_list_contents(ostream &out) const {
out << _materials.size() << " materials:\n"; out << _materials.size() << " materials:\n";
Materials::iterator mi; Materials::const_iterator mi;
for (mi = _materials.begin(); mi != _materials.end(); ++mi) { for (mi = _materials.begin(); mi != _materials.end(); ++mi) {
const Material *mat = (*mi); const Material *mat = (*mi);
out << " " << *mat out << " " << *mat
@ -91,3 +91,14 @@ get_ptr() {
} }
return _global_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);
}

View File

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

View File

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

View File

@ -43,7 +43,6 @@ ns_has_texture(const Filename &orig_filename) {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(filename, get_texture_path()); vfs->resolve_filename(filename, get_texture_path());
vfs->resolve_filename(filename, get_model_path()); vfs->resolve_filename(filename, get_model_path());
} else { } else {
filename.resolve_filename(get_texture_path()); filename.resolve_filename(get_texture_path());
filename.resolve_filename(get_model_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(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(filename, get_texture_path()) || vfs->resolve_filename(filename, get_texture_path()) ||
vfs->resolve_filename(filename, get_model_path()); vfs->resolve_filename(filename, get_model_path());
} else { } else {
filename.resolve_filename(get_texture_path()) || filename.resolve_filename(get_texture_path()) ||
filename.resolve_filename(get_model_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)) { if (!tex->read(filename, primary_file_num_channels)) {
// This texture was not found. // This texture was not found.
gobj_cat.error() 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; return NULL;
} }
@ -224,7 +225,7 @@ ns_garbage_collect() {
gobj_cat.debug() gobj_cat.debug()
<< "Releasing " << (*ti).first << "\n"; << "Releasing " << (*ti).first << "\n";
} }
num_released++; ++num_released;
} else { } else {
new_set.insert(new_set.end(), *ti); new_set.insert(new_set.end(), *ti);
} }
@ -240,9 +241,9 @@ ns_garbage_collect() {
// Description: The nonstatic implementation of list_contents(). // Description: The nonstatic implementation of list_contents().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TexturePool:: void TexturePool::
ns_list_contents(ostream &out) { ns_list_contents(ostream &out) const {
out << _textures.size() << " textures:\n"; out << _textures.size() << " textures:\n";
Textures::iterator ti; Textures::const_iterator ti;
for (ti = _textures.begin(); ti != _textures.end(); ++ti) { for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
Texture *texture = (*ti).second; Texture *texture = (*ti).second;
out << " " << (*ti).first out << " " << (*ti).first
@ -264,3 +265,15 @@ get_ptr() {
} }
return _global_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);
}

View File

@ -59,6 +59,9 @@ PUBLISHED:
INLINE static void clear_fake_texture_image(); INLINE static void clear_fake_texture_image();
INLINE static bool has_fake_texture_image(); INLINE static bool has_fake_texture_image();
INLINE static const string &get_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: private:
INLINE TexturePool(); INLINE TexturePool();
@ -73,7 +76,7 @@ private:
void ns_release_texture(Texture *texture); void ns_release_texture(Texture *texture);
void ns_release_all_textures(); void ns_release_all_textures();
int ns_garbage_collect(); int ns_garbage_collect();
void ns_list_contents(ostream &out); void ns_list_contents(ostream &out) const;
static TexturePool *get_ptr(); static TexturePool *get_ptr();

View File

@ -121,7 +121,7 @@ ns_garbage_collect() {
loader_cat.debug() loader_cat.debug()
<< "Releasing " << (*ti).first << "\n"; << "Releasing " << (*ti).first << "\n";
} }
num_released++; ++num_released;
} else { } else {
new_set.insert(new_set.end(), *ti); new_set.insert(new_set.end(), *ti);
} }
@ -137,9 +137,9 @@ ns_garbage_collect() {
// Description: The nonstatic implementation of list_contents(). // Description: The nonstatic implementation of list_contents().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void ModelPool:: void ModelPool::
ns_list_contents(ostream &out) { ns_list_contents(ostream &out) const {
out << _models.size() << " models:\n"; out << _models.size() << " models:\n";
Models::iterator ti; Models::const_iterator ti;
for (ti = _models.begin(); ti != _models.end(); ++ti) { for (ti = _models.begin(); ti != _models.end(); ++ti) {
out << " " << (*ti).first out << " " << (*ti).first
<< " (count = " << (*ti).second->get_ref_count() << ")\n"; << " (count = " << (*ti).second->get_ref_count() << ")\n";
@ -159,3 +159,15 @@ get_ptr() {
} }
return _global_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);
}

View File

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

View File

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

View File

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