X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fsg_binobj.cxx;h=994f3dbe643018e016a83768c48343d15a35c0df;hb=adb7db9229db1d869b254ac18f1471bed464c508;hp=54f3b8debf5c3d7ec00f13b93f6e14b5b7f3874b;hpb=3104898c7cfbaa593846abfa433ec53623d2e162;p=simgear.git diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 54f3b8de..994f3dbe 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -423,10 +423,11 @@ bool SGBinObject::read_bin( const string& file ) { } else { // close the file before we return gzclose(fp); - + SG_LOG( SG_EVENT, SG_ALERT, + "ERROR: " << file << "has bad header"); return false; } - + // read creation time unsigned int foo_calendar_time; sgReadUInt( fp, &foo_calendar_time ); @@ -461,7 +462,7 @@ bool SGBinObject::read_bin( const string& file ) { //cout << "Total objects to read = " << nobjects << endl; if ( sgReadError() ) { - cout << "We detected an error while reading the file header" << endl; + cout << "Error while reading header of file " << file << "(.gz)" << endl; return false; } @@ -612,7 +613,7 @@ bool SGBinObject::read_bin( const string& file ) { } if ( sgReadError() ) { - cout << "We detected an error while reading object:" << i << endl; + cout << "Error while reading object:" << i << " in file " << file << "(.gz)" << endl; return false; } } @@ -621,7 +622,7 @@ bool SGBinObject::read_bin( const string& file ) { gzclose(fp); if ( sgReadError() ) { - cout << "We detected an error while reading the file." << endl; + cout << "Error while reading file " << file << "(.gz)" << endl; return false; } @@ -721,6 +722,26 @@ bool SGBinObject::write_bin( const string& base, const string& name, return write_bin_file(file); } +static unsigned int max_object_size( const string_list& materials ) +{ + unsigned int max_size = 0; + + for (unsigned int start=0; start < materials.size();) { + string m = materials[start]; + unsigned int end = start + 1; + // find range of objects with identical material, calc its size + for (; (end < materials.size()) && (m == materials[end]); ++end) {} + + unsigned int cur_size = end - start; + max_size = std::max(max_size, cur_size); + start = end; + } + + return max_size; +} + +const unsigned int VERSION_7_MATERIAL_LIMIT = 0x7fff; + bool SGBinObject::write_bin_file(const SGPath& file) { int i; @@ -752,9 +773,16 @@ bool SGBinObject::write_bin_file(const SGPath& file) cout << "tex coords = " << texcoords.size() << endl; version = 10; + bool shortMaterialsRanges = + (max_object_size(pt_materials) < VERSION_7_MATERIAL_LIMIT) && + (max_object_size(fan_materials) < VERSION_7_MATERIAL_LIMIT) && + (max_object_size(strip_materials) < VERSION_7_MATERIAL_LIMIT) && + (max_object_size(tri_materials) < VERSION_7_MATERIAL_LIMIT); + if ((wgs84_nodes.size() < 0xffff) && (normals.size() < 0xffff) && - (texcoords.size() < 0xffff)) { + (texcoords.size() < 0xffff) && + shortMaterialsRanges) { version = 7; // use smaller indices if possible } @@ -829,7 +857,7 @@ bool SGBinObject::write_bin_file(const SGPath& file) gzclose(fp); if ( sgWriteError() ) { - cout << "We detected an error while writing the file." << endl; + cout << "Error while writing file " << file.str() << endl; return false; } @@ -1006,9 +1034,13 @@ bool SGBinObject::write_ascii( const string& base, const string& name, fclose(fp); string command = "gzip --force --best " + file.str(); - system(command.c_str()); + int err = system(command.c_str()); + if (err) + { + cout << "ERROR: gzip " << file.str() << " failed!" << endl; + } - return true; + return (err == 0); } void SGBinObject::read_properties(gzFile fp, int nproperties)