]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
My old email address is no longer valid ... point to my web page.
[simgear.git] / simgear / io / sg_binobj.cxx
index 146765c5ff4980c8cb6d97dc86a969b0b9b8acdc..3cbe455207387e01aa5cb7964f06be4f452a9cd4 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started January 2000.
 //
-// Copyright (C) 2000  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 //
 
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <simgear/compiler.h>
+#include <simgear/debug/logstream.hxx>
 
 #include <stdio.h>
 #include <time.h>
 SG_USING_STD( string );
 SG_USING_STD( vector );
 
-#if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
-SG_USING_STD( cout );
-SG_USING_STD( endl );
-#endif
-
 
 enum {
     SG_BOUNDING_SPHERE = 0,
@@ -89,7 +89,7 @@ public:
        while ( size < s ) {
            size *= 2;
        }
-       cout << "Creating a new buffer of size = " << size << endl;
+        SG_LOG(SG_EVENT, SG_DEBUG, "Creating a new buffer of size = " << size);
        ptr = new char[size];
     }
 
@@ -107,7 +107,7 @@ public:
            while ( size < s ) {
                size *= 2;
            }
-           cout << "resizing buffer to size = " << size << endl;
+            SG_LOG(SG_EVENT, SG_DEBUG, "resizing buffer to size = " << size);
            ptr = new char[size];
        }
     }
@@ -116,7 +116,7 @@ public:
 
 // calculate the center of a list of points, by taking the halfway
 // point between the min and max points.
-static Point3D calc_center( point_list& wgs84_nodes ) {
+Point3D sgCalcCenter( point_list& wgs84_nodes ) {
     Point3D p, min, max;
 
     if ( wgs84_nodes.size() ) {
@@ -316,13 +316,13 @@ bool SGBinObject::read_bin( const string& file ) {
     fans_c.clear();
     fans_tc.clear();
     fan_materials.clear();
-   
+
     gzFile fp;
     if ( (fp = gzopen( file.c_str(), "rb" )) == NULL ) {
        string filegz = file + ".gz";
        if ( (fp = gzopen( filegz.c_str(), "rb" )) == NULL ) {
-           cout << "ERROR: opening " << file << " or " << filegz
-                << "for reading!" << endl;
+            SG_LOG( SG_EVENT, SG_ALERT,
+               "ERROR: opening " << file << " or " << filegz << "for reading!");
 
            return false;
        }
@@ -347,10 +347,11 @@ bool SGBinObject::read_bin( const string& file ) {
     }
 
     // read creation time
-    time_t calendar_time;
-    sgReadLong( fp, &calendar_time );
+    unsigned int foo_calendar_time;
+    sgReadUInt( fp, &foo_calendar_time );
 
 #if 0
+    time_t calendar_time = foo_calendar_time;
     // The following code has a global effect on the host application
     // and can screws up the time elsewhere.  It should be avoided
     // unless you need this for debugging in which case you should
@@ -359,7 +360,7 @@ bool SGBinObject::read_bin( const string& file ) {
     local_tm = localtime( &calendar_time );
     char time_str[256];
     strftime( time_str, 256, "%a %b %d %H:%M:%S %Z %Y", local_tm);
-    cout << "File created on " << time_str << endl;
+    SG_LOG( SG_EVENT, SG_DEBUG, "File created on " << time_str);
 #endif
 
     // read number of top level objects
@@ -439,15 +440,14 @@ bool SGBinObject::read_bin( const string& file ) {
                sgReadBytes( fp, nbytes, ptr );
                int count = nbytes / (sizeof(float) * 3);
                float *fptr = (float *)ptr;
+               wgs84_nodes.reserve( count );
                for ( k = 0; k < count; ++k ) {
                    if ( sgIsBigEndian() ) {
                        sgEndianSwap( (unsigned int *)&(fptr[0]) );
                        sgEndianSwap( (unsigned int *)&(fptr[1]) );
                        sgEndianSwap( (unsigned int *)&(fptr[2]) );
                    }
-                   p = Point3D( fptr[0], fptr[1], fptr[2] );
-                   // cout << "node = " << p << endl;
-                   wgs84_nodes.push_back( p );
+                   wgs84_nodes.push_back( Point3D(fptr[0], fptr[1], fptr[2]) );
                    fptr += 3;
                }
            }
@@ -473,6 +473,7 @@ bool SGBinObject::read_bin( const string& file ) {
                sgReadBytes( fp, nbytes, ptr );
                int count = nbytes / (sizeof(float) * 4);
                float *fptr = (float *)ptr;
+               colors.reserve(count);
                for ( k = 0; k < count; ++k ) {
                    if ( sgIsBigEndian() ) {
                        sgEndianSwap( (unsigned int *)&(fptr[0]) );
@@ -480,9 +481,7 @@ bool SGBinObject::read_bin( const string& file ) {
                        sgEndianSwap( (unsigned int *)&(fptr[2]) );
                        sgEndianSwap( (unsigned int *)&(fptr[3]) );
                    }
-                   p = Point3D( fptr[0], fptr[1], fptr[2] );
-                   // cout << "node = " << p << endl;
-                   colors.push_back( p );
+                   colors.push_back( Point3D( fptr[0], fptr[1], fptr[2] ) );
                    fptr += 4;
                }
            }
@@ -507,6 +506,7 @@ bool SGBinObject::read_bin( const string& file ) {
                unsigned char *ptr = (unsigned char *)(buf.get_ptr());
                sgReadBytes( fp, nbytes, ptr );
                int count = nbytes / 3;
+               normals.reserve( count );
                for ( k = 0; k < count; ++k ) {
                     sgdVec3 normal;
                     sgdSetVec3( normal,
@@ -515,9 +515,7 @@ bool SGBinObject::read_bin( const string& file ) {
                                (ptr[2]) / 127.5 - 1.0 );
                     sgdNormalizeVec3( normal );
 
-                   p = Point3D( normal[0], normal[1], normal[2] );
-                   // cout << "normal = " << p << endl;
-                   normals.push_back( p );
+                   normals.push_back(Point3D(normal[0], normal[1], normal[2]));
                    ptr += 3;
                }
            }
@@ -543,14 +541,13 @@ bool SGBinObject::read_bin( const string& file ) {
                sgReadBytes( fp, nbytes, ptr );
                int count = nbytes / (sizeof(float) * 2);
                float *fptr = (float *)ptr;
+               texcoords.reserve(count);
                for ( k = 0; k < count; ++k ) {
                    if ( sgIsBigEndian() ) {
                        sgEndianSwap( (unsigned int *)&(fptr[0]) );
                        sgEndianSwap( (unsigned int *)&(fptr[1]) );
                    }
-                   p = Point3D( fptr[0], fptr[1], 0 );
-                   // cout << "texcoord = " << p << endl;
-                   texcoords.push_back( p );
+                   texcoords.push_back( Point3D( fptr[0], fptr[1], 0 ) );
                    fptr += 2;
                }
            }
@@ -1148,7 +1145,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
            for ( i = start; i < end; ++i ) {
                for ( j = 0; j < (int)tris_v[i].size(); ++j ) {
                    group_nodes.push_back( wgs84_nodes[ tris_v[i][j] ] );
-                   bs_center = calc_center( group_nodes );
+                   bs_center = sgCalcCenter( group_nodes );
                    bs_radius = sgCalcBoundingRadius( bs_center, group_nodes );
                }
            }
@@ -1199,7 +1196,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
            for ( i = start; i < end; ++i ) {
                for ( j = 0; j < (int)strips_v[i].size(); ++j ) {
                    group_nodes.push_back( wgs84_nodes[ strips_v[i][j] ] );
-                   bs_center = calc_center( group_nodes );
+                   bs_center = sgCalcCenter( group_nodes );
                    bs_radius = sgCalcBoundingRadius( bs_center, group_nodes );
                }
            }