]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
Tidy up the autoconf/automake configuration a bit.
[simgear.git] / simgear / io / sg_binobj.cxx
index 01141d4528c7cfd29b524dc62a62ae9796ccf783..3b4bdf7971e1500ea9dc3e9f30808ba17ddff9a4 100644 (file)
@@ -61,10 +61,10 @@ enum {
 } sgObjectTypes;
 
 enum {
-    SG_IDX_VERTICES =  0x0001,
-    SG_IDX_NORMALS =   0x0010,
-    SG_IDX_COLORS =    0x0100,
-    SG_IDX_TEXCOORDS = 0x1000
+    SG_IDX_VERTICES =  0x01,
+    SG_IDX_NORMALS =   0x02,
+    SG_IDX_COLORS =    0x04,
+    SG_IDX_TEXCOORDS = 0x08
 } sgIndexTypes;
 
 enum {
@@ -170,7 +170,7 @@ static void read_object( gzFile fp,
                         string_list *materials )
 {
     unsigned int nbytes;
-    char idx_mask;
+    unsigned char idx_mask;
     int idx_size;
     bool do_vertices, do_normals, do_colors, do_texcoords;
     int j, k, idx;
@@ -209,6 +209,7 @@ static void read_object( gzFile fp,
            // cout << "material type = " << material << endl;
        } else if ( prop_type == SG_INDEX_TYPES ) {
            idx_mask = ptr[0];
+           // cout << "idx_mask = " << (int)idx_mask << endl;
            idx_size = 0;
            do_vertices = false;
            do_normals = false;
@@ -315,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;
+           cout << "ERROR: opening " << file << " or " << filegz
+                << "for reading!" << endl;
 
            return false;
        }
@@ -346,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
@@ -438,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;
                }
            }
@@ -472,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]) );
@@ -479,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;
                }
            }
@@ -506,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,
@@ -514,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;
                }
            }
@@ -542,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;
                }
            }
@@ -566,114 +564,10 @@ bool SGBinObject::read_bin( const string& file ) {
            read_object( fp, SG_TRIANGLE_STRIPS, nproperties, nelements,
                         &strips_v, &strips_n, &strips_c, &strips_tc,
                         &strip_materials );
-#if 0
-           // default values
-           idx_size = 2;
-           idx_mask = (char)(SG_IDX_VERTICES | SG_IDX_TEXCOORDS);
-           do_vertices = true;
-           do_normals = false;
-           do_colors = false;
-           do_texcoords = true;
-
-           for ( j = 0; j < nproperties; ++j ) {
-               char prop_type;
-               sgReadChar( fp, &prop_type );
-
-               sgReadUInt( fp, &nbytes );
-               // cout << "property size = " << nbytes << endl;
-               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
-               char *ptr = buf.get_ptr();
-               sgReadBytes( fp, nbytes, ptr );
-               if ( prop_type == SG_MATERIAL ) {
-                   strncpy( material, ptr, nbytes );
-                   material[nbytes] = '\0';
-                   // cout << "material type = " << material << endl;
-               }
-           }
-
-           // read triangle strip elements
-           for ( j = 0; j < nelements; ++j ) {
-               sgReadUInt( fp, &nbytes );
-               // cout << "element size = " << nbytes << endl;
-               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
-               char *ptr = buf.get_ptr();
-               sgReadBytes( fp, nbytes, ptr );
-               int count = nbytes / (sizeof(short) * 2);
-               short *sptr = (short *)ptr;
-               int_list vs, tcs;
-               vs.clear(); tcs.clear();
-               for ( k = 0; k < count; ++k ) {
-                   if ( sgIsBigEndian() ) {
-                       sgEndianSwap( (unsigned short *)&(sptr[0]) );
-                       sgEndianSwap( (unsigned short *)&(sptr[1]) );
-                   }
-                   vs.push_back( sptr[0] );
-                   tcs.push_back( sptr[1] );
-                   // cout << sptr[0] << "/" << sptr[1] << " ";
-                   sptr += idx_size;
-               }
-               // cout << endl;
-               strips_v.push_back( vs );
-               strips_tc.push_back( tcs );
-               strip_materials.push_back( material );
-           }
-#endif
        } else if ( obj_type == SG_TRIANGLE_FANS ) {
            // read triangle fan properties
            read_object( fp, SG_TRIANGLE_FANS, nproperties, nelements,
                         &fans_v, &fans_n, &fans_c, &fans_tc, &fan_materials );
-#if 0
-           // default values
-           idx_size = 2;
-           idx_mask = (char)(SG_IDX_VERTICES | SG_IDX_TEXCOORDS);
-           do_vertices = true;
-           do_normals = false;
-           do_colors = false;
-           do_texcoords = true;
-
-           for ( j = 0; j < nproperties; ++j ) {
-               char prop_type;
-               sgReadChar( fp, &prop_type );
-
-               sgReadUInt( fp, &nbytes );
-               // cout << "property size = " << nbytes << endl;
-               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
-               char *ptr = buf.get_ptr();
-               sgReadBytes( fp, nbytes, ptr );
-               if ( prop_type == SG_MATERIAL ) {
-                   strncpy( material, ptr, nbytes );
-                   material[nbytes] = '\0';
-                   // cout << "material type = " << material << endl;
-               }
-           }
-
-           // read triangle fan elements
-           for ( j = 0; j < nelements; ++j ) {
-               sgReadUInt( fp, &nbytes );
-               // cout << "element size = " << nbytes << endl;
-               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
-               char *ptr = buf.get_ptr();
-               sgReadBytes( fp, nbytes, ptr );
-               int count = nbytes / (sizeof(short) * 2);
-               short *sptr = (short *)ptr;
-               int_list vs, tcs;
-               vs.clear(); tcs.clear();
-               for ( k = 0; k < count; ++k ) {
-                   if ( sgIsBigEndian() ) {
-                       sgEndianSwap( (unsigned short *)&(sptr[0]) );
-                       sgEndianSwap( (unsigned short *)&(sptr[1]) );
-                   }
-                   vs.push_back( sptr[0] );
-                   tcs.push_back( sptr[1] );
-                   // cout << sptr[0] << "/" << sptr[1] << " ";
-                   sptr += idx_size;
-               }
-               // cout << endl;
-               fans_v.push_back( vs );
-               fans_tc.push_back( tcs );
-               fan_materials.push_back( material );
-           }
-#endif
        } else {
            // unknown object type, just skip
 
@@ -723,7 +617,7 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     sgVec3 pt;
     sgVec4 color;
     int i, j;
-    char idx_mask;
+    unsigned char idx_mask;
     int idx_size;
 
     string dir = base + "/" + b.gen_base_path();