]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Use a pointer to a structure instead of a large number of variables when calling...
[flightgear.git] / src / Main / main.cxx
index 2a80636555b91bc813f93449f4009fe696c5efc0..c1ad6e9b399e7c65aa2400ca7537c22d766f8d86 100644 (file)
@@ -120,6 +120,7 @@ SG_USING_STD(endl);
 #include <MultiPlayer/multiplayrxmgr.hxx>
 #endif
 
+#include <Replay/replay.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #ifdef ENABLE_AUDIO_SUPPORT
@@ -165,7 +166,7 @@ sgVec3 rway_ols;
 float scene_nearplane = 0.5f;
 float scene_farplane = 120000.0f;
 
-static double delta_time_sec = 0;
+static double delta_time_sec = 0.0;
 
 
 #ifdef FG_WEATHERCM
@@ -556,7 +557,7 @@ void fgRenderFrame() {
         thesky->set_visibility(visibility_meters);
 
         thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
-                        ( global_multi_loop * fgGetInt("/sim/speed-up") )
+                            ( global_multi_loop * fgGetInt("/sim/speed-up") )
                             / (double)fgGetInt("/sim/model-hz") );
 
         // Set correct opengl fog density
@@ -579,15 +580,20 @@ void fgRenderFrame() {
                     "    sun_angle = " << cur_light_params.sun_angle
              << "    moon_angle = " << cur_light_params.moon_angle );
             */
-            thesky->repaint( cur_light_params.sky_color,
-                             cur_light_params.adj_fog_color,
-                             cur_light_params.cloud_color,
-                             cur_light_params.sun_angle,
-                             cur_light_params.moon_angle,
-                             globals->get_ephem()->getNumPlanets(),
-                             globals->get_ephem()->getPlanets(),
-                             globals->get_ephem()->getNumStars(),
-                             globals->get_ephem()->getStars() );
+
+            static SGSkyColor scolor;
+
+            scolor.sky_color   = cur_light_params.sky_color;
+            scolor.fog_color   = cur_light_params.adj_fog_color;
+            scolor.cloud_color = cur_light_params.cloud_color;
+            scolor.sun_angle   = cur_light_params.sun_angle;
+            scolor.moon_angle  = cur_light_params.moon_angle;
+            scolor.nplanets    = globals->get_ephem()->getNumPlanets();
+            scolor.nstars      = globals->get_ephem()->getNumStars();
+            scolor.planet_data = globals->get_ephem()->getPlanets();
+            scolor.star_data   = globals->get_ephem()->getStars();
+
+            thesky->repaint( scolor );
 
             /*
             SG_LOG( SG_GENERAL, SG_BULK,
@@ -620,23 +626,28 @@ void fgRenderFrame() {
             } else {
                sun_horiz_eff = moon_horiz_eff = 1.0;
             }
-            thesky->reposition( current__view->get_view_pos(),
-                                current__view->get_zero_elev(),
-                                current__view->get_world_up(),
-                                current__view->getLongitude_deg()
-                                  * SGD_DEGREES_TO_RADIANS,
-                                current__view->getLatitude_deg()
-                                  * SGD_DEGREES_TO_RADIANS,
-                                current__view->getAltitudeASL_ft()
-                                  * SG_FEET_TO_METER,
-                                cur_light_params.sun_rotation,
-                                globals->get_time_params()->getGst(),
-                                globals->get_ephem()->getSunRightAscension(),
-                                globals->get_ephem()->getSunDeclination(),
-                                50000.0 * sun_horiz_eff,
-                                globals->get_ephem()->getMoonRightAscension(),
-                                globals->get_ephem()->getMoonDeclination(),
-                                40000.0 * moon_horiz_eff );
+
+            static SGSkyState sstate;
+
+            sstate.view_pos  = current__view->get_view_pos();
+            sstate.zero_elev = current__view->get_zero_elev();
+            sstate.view_up   = current__view->get_world_up();
+            sstate.lon       = current__view->getLongitude_deg()
+                                * SGD_DEGREES_TO_RADIANS;
+            sstate.lat       = current__view->getLatitude_deg()
+                                * SGD_DEGREES_TO_RADIANS;
+            sstate.alt       = current__view->getAltitudeASL_ft()
+                                * SG_FEET_TO_METER;
+            sstate.spin      = cur_light_params.sun_rotation;
+            sstate.gst       = globals->get_time_params()->getGst();
+            sstate.sun_ra    = globals->get_ephem()->getSunRightAscension();
+            sstate.sun_dec   = globals->get_ephem()->getSunDeclination();
+            sstate.sun_dist  = 50000.0 * sun_horiz_eff;
+            sstate.moon_ra   = globals->get_ephem()->getMoonRightAscension();
+            sstate.moon_dec  = globals->get_ephem()->getMoonDeclination();
+            sstate.moon_dist = 40000.0 * moon_horiz_eff;
+
+            thesky->reposition( sstate );
         }
 
         glEnable( GL_DEPTH_TEST );
@@ -932,6 +943,13 @@ void fgRenderFrame() {
 void fgUpdateTimeDepCalcs() {
     static bool inited = false;
 
+    static const SGPropertyNode *replay_master
+        = fgGetNode( "/sim/freeze/replay", true );
+    static SGPropertyNode *replay_time
+        = fgGetNode( "/sim/replay/time", true );
+    static const SGPropertyNode *replay_end_time
+        = fgGetNode( "/sim/replay/end-time", true );
+
     //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
 
     fgLIGHT *l = &cur_light_params;
@@ -955,17 +973,25 @@ void fgUpdateTimeDepCalcs() {
 
     // conceptually, the following block could be done for each fdm
     // instance ...
-    if ( !cur_fdm_state->get_inited() ) {
-        // do nothing, fdm isn't inited yet
-    } else {
+    if ( cur_fdm_state->get_inited() ) {
         // we have been inited, and  we are good to go ...
 
         if ( !inited ) {
             inited = true;
         }
 
-        globals->get_autopilot()->update(delta_time_sec);
-        cur_fdm_state->update(delta_time_sec);
+        if ( ! replay_master->getBoolValue() ) {
+            globals->get_autopilot()->update( delta_time_sec );
+            cur_fdm_state->update( delta_time_sec );
+        } else {
+            FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
+            r->replay( replay_time->getDoubleValue() );
+            replay_time->setDoubleValue( replay_time->getDoubleValue()
+                                         + ( delta_time_sec
+                                             * fgGetInt("/sim/speed-up") ) );
+        }
+    } else {
+        // do nothing, fdm isn't inited yet
     }
 
     globals->get_model_mgr()->update(delta_time_sec);
@@ -1010,6 +1036,8 @@ static void fgMainLoop( void ) {
         = fgGetNode("/sim/freeze/clock", true);
     static const SGPropertyNode *cur_time_override
         = fgGetNode("/sim/time/cur-time-override", true);
+    static const SGPropertyNode *replay_master
+        = fgGetNode("/sim/freeze/replay", true);
 
     // Update the elapsed time.
     static bool first_time = true;
@@ -1034,7 +1062,7 @@ static void fgMainLoop( void ) {
     delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
     if ( clock_freeze->getBoolValue() ) {
         delta_time_sec = 0;
-    }
+    } 
     last_time_stamp = current_time_stamp;
     globals->inc_sim_time_sec( delta_time_sec );
     SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
@@ -1092,15 +1120,20 @@ static void fgMainLoop( void ) {
            cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
            cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
 
-// Curt is this code used?  I don't see any problems when I comment it out.
+#if 0
+// This code is used by LaRCsim/UIUC to position the aircraft at a proper
+// place. This code should eventually go into the LaRCsim directory.
+// Commented out at Jul 27 2003 because tests show it is not needed.
+// Can probbaly be safely removed after Spet. 2003 - EMH
+
     if ( acmodel_location != 0 ) {
       if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
         if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER < 
-             (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
+             (acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0) ) {
             // now set aircraft altitude above ground
             printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n", 
                cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
-               acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
+               acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0,
                acmodel_location->get_cur_elev_m() + alt_adjust_m );
             cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m() 
                                                 + alt_adjust_m) * SG_METER_TO_FEET );
@@ -1112,6 +1145,7 @@ static void fgMainLoop( void ) {
       }
     }
 // End of code in question. (see Curt is this code used? above)
+#endif
 
     /* printf("Adjustment - ground = %.2f  runway = %.2f  alt = %.2f\n",
            scenery.get_cur_elev(),
@@ -1626,7 +1660,7 @@ static bool fgMainInit( int argc, char **argv ) {
 
     // Initialize the various GLUT Event Handlers.
     if( !fgGlutInitEvents() ) {
- SG_LOG( SG_GENERAL, SG_ALERT, 
       SG_LOG( SG_GENERAL, SG_ALERT, 
                "GLUT event handler initialization failed ..." );
         exit(-1);
     }
@@ -1726,7 +1760,6 @@ static bool fgMainInit( int argc, char **argv ) {
     ////////////////////////////////////////////////////////////////////
     // Initialize the view manager subsystem.
     ////////////////////////////////////////////////////////////////////
-
     FGViewMgr *viewmgr = new FGViewMgr;
     globals->set_viewmgr( viewmgr );
     viewmgr->init();
@@ -1778,8 +1811,16 @@ static bool fgMainInit( int argc, char **argv ) {
                                 // kludge to initialize mag compass
                                 // (should only be done for in-flight
                                 // startup)
-    fgSetDouble("/instrumentation/heading-indicator/offset-deg",
-                globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES);
+    // update magvar model
+    globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
+                                * SGD_DEGREES_TO_RADIANS,
+                                fgGetDouble("/position/latitude-deg")
+                                * SGD_DEGREES_TO_RADIANS,
+                                fgGetDouble("/position/altitude-ft")
+                                * SG_FEET_TO_METER,
+                                globals->get_time_params()->getJD() );
+    double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
+    fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
 
     // airport = new ssgBranch;
     // airport->setName( "Airport Lighting" );