]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Fix the nmea and garmin output to a) fake a GSA sentence, b) fix a y2k bug
[flightgear.git] / src / Main / main.cxx
index 9f2b701d24300d58d1cc73463411146aee1ef403..c021b109644408597761dd0796364f8903e91bb4 100644 (file)
 #include <Time/fg_timer.hxx>
 #include <Environment/environment_mgr.hxx>
 
-#ifdef FG_NETWORK_OLK
-#include <NetworkOLK/network.h>
-#endif
-
 #ifdef FG_MPLAYER_AS
 #include <MultiPlayer/multiplaytxmgr.hxx>
 #include <MultiPlayer/multiplayrxmgr.hxx>
@@ -117,6 +113,7 @@ sgVec3 rway_ols;
 float scene_nearplane = 0.5f;
 float scene_farplane = 120000.0f;
 
+static double real_delta_time_sec = 0.0;
 static double delta_time_sec = 0.0;
 
 glPointParameterfProc glPointParameterfPtr = 0;
@@ -151,11 +148,6 @@ static GLfloat rwy_exp2_punch_through;
 static GLfloat taxi_exp2_punch_through;
 static GLfloat ground_exp2_punch_through;
 
-#ifdef FG_NETWORK_OLK
-ssgSelector *fgd_sel = NULL;
-ssgTransform *fgd_pos = NULL;
-#endif
-
 // Sky structures
 SGSky *thesky;
 
@@ -632,32 +624,6 @@ void fgRenderFrame() {
 
         ssgSetNearFar( scene_nearplane, scene_farplane );
 
-        // $$$ begin - added VS Renganthan 17 Oct 2K
-        if(objc)
-          fgUpdateDCS();
-        // $$$ end - added VS Renganthan 17 Oct 2K
-
-# ifdef FG_NETWORK_OLK
-        if ( fgGetBool("/sim/networking/network-olk") ) {
-            sgCoord fgdpos;
-            other = head->next;             /* put listpointer to start  */
-            while ( other != tail) {        /* display all except myself */
-            if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
-                other->fgd_sel->select(1);
-                sgSetCoord( &fgdpos, other->sgFGD_COORD );
-                other->fgd_pos->setTransform( &fgdpos );
-            }
-            other = other->next;
-            }
-
-            // fgd_sel->select(1);
-            // sgCopyMat4( sgTUX, current_view.sgVIEW);
-            // sgCoord fgdpos;
-            // sgSetCoord( &fgdpos, sgFGD_VIEW );
-            // fgd_pos->setTransform( &fgdpos);
-        }
-# endif
-
 #ifdef FG_MPLAYER_AS
         // Update any multiplayer models
         globals->get_multiplayer_rx_mgr()->Update();
@@ -993,10 +959,13 @@ static void fgMainLoop( void ) {
         current_time_stamp.stamp();
     }
 
-    delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
+    real_delta_time_sec
+        = double(current_time_stamp - last_time_stamp) / 1000000.0;
     if ( clock_freeze->getBoolValue() ) {
         delta_time_sec = 0;
-    } 
+    } else {
+        delta_time_sec = real_delta_time_sec;
+    }
     last_time_stamp = current_time_stamp;
     globals->inc_sim_time_sec( delta_time_sec );
     SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
@@ -1023,16 +992,6 @@ static void fgMainLoop( void ) {
     SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
     SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
 
-#ifdef FG_NETWORK_OLK
-    if ( fgGetBool("/sim/networking/network-olk") ) {
-        if ( net_is_registered == 0 ) {             // We first have to reg. to fgd
-            // printf("FGD: Netupdate\n");
-            fgd_send_com( "A", FGFS_host);   // Send Mat4 data
-            fgd_send_com( "B", FGFS_host);   // Recv Mat4 data
-        }
-    }
-#endif
-
 #if defined( ENABLE_PLIB_JOYSTICK )
     // Read joystick and update control settings
     // if ( fgGetString("/sim/control-mode") == "joystick" )
@@ -1176,7 +1135,7 @@ static void fgMainLoop( void ) {
     }
 
     // Do any I/O channel work that might need to be done
-    globals->get_io()->update( delta_time_sec );
+    globals->get_io()->update( real_delta_time_sec );
 
     // see if we need to load any deferred-load textures
     globals->get_matlib()->load_next_deferred();
@@ -1247,10 +1206,11 @@ static void fgMainLoop( void ) {
     // END Tile Manager udpates
 
     if (fgGetBool("/sim/rendering/specular-highlight")) {
-        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
+        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+       // glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
     } else {
         glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
-         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
+        // glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
     }
 
     // redraw display
@@ -1515,7 +1475,7 @@ bool fgMainInit( int argc, char **argv ) {
 #endif
 
     // set default log levels
-    sglog().setLogLevels( SG_ALL, SG_INFO );
+    sglog().setLogLevels( SG_ALL, SG_ALERT );
 
     string version;
 #ifdef FLIGHTGEAR_VERSION
@@ -1742,18 +1702,6 @@ bool fgMainInit( int argc, char **argv ) {
     // airport->setName( "Airport Lighting" );
     // lighting->addKid( airport );
 
-    // ADA
-    fgLoadDCS();
-    // ADA
-
-#ifdef FG_NETWORK_OLK
-    // Do the network intialization
-    if ( fgGetBool("/sim/networking/network-olk") ) {
-        printf("Multipilot mode %s\n",
-               fg_net_init( globals->get_scenery()->get_scene_graph() ) );
-    }
-#endif
-
     // build our custom render states
     fgBuildRenderStates();
     
@@ -1766,319 +1714,4 @@ bool fgMainInit( int argc, char **argv ) {
 }
 
 
-// $$$ end - added VS Renganathan, 15 Oct 2K
-//         - added Venky         , 12 Nov 2K
-
-
-void fgLoadDCS(void) {
-
-    ssgEntity *ship_obj = NULL;
-
-    char obj_filename[25];
-
-    for ( int k = 0; k < 32; k++ ) {
-        ship_pos[k]=NULL;
-    }
-
-    SGPath tile_path( globals->get_fg_root());
-    tile_path.append( "Scenery" );
-    tile_path.append( "Objects.txt" );
-    sg_gzifstream in( tile_path.str() );
-    if ( ! in.is_open() ) {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
-    } else {
-
-        SGPath modelpath( globals->get_fg_root() );
-        modelpath.append( "Models" );
-        modelpath.append( "Geometry" );
-  
-        SGPath texturepath( globals->get_fg_root() );
-        texturepath.append( "Models" );
-        texturepath.append( "Textures" );
-        ssgModelPath( (char *)modelpath.c_str() );
-        ssgTexturePath( (char *)texturepath.c_str() );
-
-        ship_sel = new ssgSelector;
-
-        char c;
-        while ( ! in.eof() ) {
-            in >> ::skipws;
-            if ( in.get( c ) && c == '#' ) { 
-                in >> skipeol;
-            } else { 
-                in.putback(c);
-                in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
-                /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] <<  " " << obj_alt[objc] << endl;
-                   int chj=getchar();*/
-                
-                obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
-                obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
-                
-                ship_pos[objc] = new ssgTransform;
-       
-                // type "repeat" in objects.txt to load one more
-                // instance of the last object.
-
-                if ( strcmp(obj_filename,"repeat") != 0) {
-                    ship_obj =
-                      globals->get_model_lib()->load_model( globals->get_fg_root(), obj_filename, globals->get_props(), globals->get_sim_time_sec() );
-                }
-      
-                if ( ship_obj != NULL ) {
-                               ship_obj->setName(obj_filename);
-                            if (objc == 0)
-                                       ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
-                               else
-                                       ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
-                    ship_pos[objc]->addKid( ship_obj ); // add object to transform node
-                    ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
-                    SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
-                            << obj_filename );
-                } else {
-                    SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
-                            << obj_filename );
-                }
-            
-                            // temporary hack for deck lights - ultimately should move to PLib (when??)
-                            //const char *extn = file_extension ( obj_filename ) ;
-                            if ( objc == 1 ){
-                                // ssgVertexArray *lights = new ssgVertexArray( 100 );
-                               ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
-                               ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
-                               ssgVertexArray *lightdir = new ssgVertexArray( 100 );
-                               int ltype[500], light_type = 0;
-                               static int ltcount = 0;
-                                string token;
-                               sgVec3 rway_dir,rway_normal,lightpt;
-                               Point3D node;
-                               modelpath.append(obj_filename);
-                               sg_gzifstream in1( modelpath.str() );
-                               if ( ! in1.is_open() ) {
-                                       SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
-                               } else {
-                                       while ( ! in1.eof() ) {
-                                                        in1 >> ::skipws;
-                                               if ( in1.get( c ) && c == '#' ) { 
-                                                       in1 >> skipeol;
-                                               } else { 
-                                                       in1.putback(c);
-                                                       in1 >> token;
-                                                       //cout << token << endl;
-                                                       if ( token == "runway" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_dir, node[0], node[1], node[2] );                        
-                                                       } else if ( token == "edgelight" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );
-                                                               light_type = 1;
-                                                       } else if ( token == "taxi" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );                     
-                                                               light_type = 2;
-                                                       } else if ( token == "vasi" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );                     
-                                                               light_type = 3;
-                                                       } else if ( token == "threshold" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );                     
-                                                               light_type = 4;
-                                                       } else if ( token == "rabbit" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );
-                                                               light_type = 5;
-                                                       } else if ( token == "ols" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_ols, node[0], node[1], node[2] );
-                                                               light_type = 6;
-                                                       } else if ( token == "red" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );
-                                                               light_type = 7;
-                                                       } else if ( token == "green" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (rway_normal, node[0], node[1], node[2] );
-                                                               light_type = 8;
-                                                       } else if ( token == "lp" ) {
-                                                               in1 >> node;
-                                                               sgSetVec3 (lightpt, node[0], node[1], node[2] );
-                                                               lightpoints->add( lightpt );
-                                                               lightnormals->add( rway_normal );
-                                                               lightdir->add( rway_dir );
-                                                               ltype[ltcount]= light_type;
-                                                               ltcount++;
-                                                       }
-                                                       if (in1.eof()) break;
-                                               } 
-                                       }  //while
-
-#if 0        
-                                       if ( lightpoints->getNum() ) {
-                                               ssgBranch *lightpoints_branch;
-                                               long int dummy = -999;
-                                               dummy_tile = new FGTileEntry((SGBucket)dummy);
-                                               dummy_tile->lightmaps_sequence = new ssgSelector;
-                                               dummy_tile->ols_transform = new ssgTransform;
-
-                                               // call function to generate the runway lights
-                                               lightpoints_branch = 
-                                               dummy_tile->gen_runway_lights( lightpoints, lightnormals,
-                                                                                                                       lightdir, ltype);
-                                               lightpoints_brightness->addKid(lightpoints_branch);
-                                               lightpoints_transform->addKid(lightpoints_brightness);
-                                           //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
-                                               lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
-                                               lightpoints_transform->ref();
-                                               globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
-                                       } 
-#endif
-                               } //if in1 
-                } //if objc
-                            // end hack for deck lights
-
-                objc++;
-
-                if (in.eof()) break;
-            }
-        } // while
-
-        SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
-
-        globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node 
-    }
-
-    return;
- }
-
-
-void fgUpdateDCS (void) {
-
-    // double eye_lat,eye_lon,eye_alt;
-    // static double obj_head;
-    double sl_radius,obj_latgc;
-    // float nresultmat[4][4];
-    // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
-    double bz[3];
-
-    // Instantaneous Geodetic Lat/Lon/Alt of moving object
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
-    
-    // Deck should be the first object in objects.txt in case of fdm=ada
-
-    if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
-            if ((fdm->get_iaux(1))==1)
-            {
-                    obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
-                    obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
-                    obj_alt[1] = fdm->get_daux(3);
-                    obj_pitch[1] = fdm->get_faux(1);
-                    obj_roll[1] = fdm->get_faux(2);
-            }
-    }
-    
-    for ( int m = 0; m < objc; m++ ) {
-       //cout << endl <<  obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
-        //int v=getchar();
-
-        //Geodetic to Geocentric angles for rotation
-        sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
-
-        //moving object gbs-posn in cartesian coords
-        Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
-        Point3D obj_pos = sgGeodToCart( obj_posn );
-
-        // Translate moving object w.r.t eye
-        Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
-        bz[0]=Objtrans.x();
-        bz[1]=Objtrans.y();
-        bz[2]=Objtrans.z();
-
-       // rotate dynamic objects for lat,lon & alt and other motion about its axes
-        
-        sgMat4 sgTRANS;
-        sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
-
-        sgVec3 ship_fwd,ship_rt,ship_up;
-        sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
-        sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
-        sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
-
-        sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
-        sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
-        sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
-        sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
-        sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
-        sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
-        
-        sgMat4 sgTUX;
-        sgCopyMat4( sgTUX, sgROT_hdg );
-        sgPostMultMat4( sgTUX, sgROT_pitch );
-        sgPostMultMat4( sgTUX, sgROT_roll );
-        sgPostMultMat4( sgTUX, sgROT_lat );
-        sgPostMultMat4( sgTUX, sgROT_lon );
-        sgPostMultMat4( sgTUX, sgTRANS );
-
-        sgCoord shippos;
-        sgSetCoord(&shippos, sgTUX );
-        ship_pos[m]->setTransform( &shippos );
-        // temporary hack for deck lights - ultimately should move to PLib (when ??)
-        if (m == 1) {
-            if (lightpoints_transform) {
-                lightpoints_transform->setTransform( &shippos );
-                FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
-                float sun_angle = l->get_sun_angle() * SGD_RADIANS_TO_DEGREES;
-                if ( sun_angle > 89 ) {
-                        lightpoints_brightness->select(0x01);
-                } else {
-                        lightpoints_brightness->select(0x00);
-                }
-            }
-
-            float elev;
-            sgVec3 rp,to;
-            float *vp;
-            float alt;
-            float ref_elev;
-            sgXformPnt3( rp, rway_ols, sgTUX );
-            vp = globals->get_current_view()->get_view_pos();
-            to[0] = rp[0]-vp[0];
-            to[1] = rp[1]-vp[1];
-            to[2] = rp[2]-vp[2];
-            float dist = sgLengthVec3( to );
-            alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
-
-            elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
-
-            ref_elev = elev - 3.75; // +ve above, -ve below
-        
-            unsigned int sel;
-            sel = 0xFF;
-// DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
-//             if (ref_elev > 0.51) sel = 0x21;
-//             if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
-//             if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
-//             if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
-//             if (ref_elev < -0.51) sel = 0x30;
-// DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
-            // dummy_tile->lightmaps_sequence->select(sel);
-
-            sgVec3 up;
-            sgCopyVec3 (up, ship_up);
-            if (dist > 750) 
-                    sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
-            else
-                    sgScaleVec3 (up, 4.0*ref_elev);
-            // dummy_tile->ols_transform->setTransform(up);
-            //cout << "ref_elev  " << ref_elev << endl;
-        }
-    // end hack for deck lights
-
-    }
-    if ( ship_sel != NULL ) {
-        ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
-    }
-}
-
-// $$$ end - added VS Renganathan, 15 Oct 2K
-//           added Venky         , 12 Nov 2K
+// end of main.cxx