]> git.mxchange.org Git - flightgear.git/blobdiff - src/Replay/replay.cxx
Fix an oversight/inefficiency spotted by Frederic Bouvier. We were passing a
[flightgear.git] / src / Replay / replay.cxx
index d0dc3f6fa3880697d90301588b184a4e8f5b7583..659c7b3873190c88ef1d460d25fbcd4196d2c9e5 100644 (file)
@@ -24,6 +24,7 @@
 #include <simgear/constants.h>
 
 #include <FDM/flight.hxx>
+#include <Main/fg_props.hxx>
 #include <Network/native_ctrls.hxx>
 #include <Network/native_fdm.hxx>
 #include <Network/net_ctrls.hxx>
 
 #include "replay.hxx"
 
+const double FGReplay::st_list_time = 60.0;   // 60 secs of high res data
+const double FGReplay::mt_list_time = 600.0;  // 10 mins of 1 fps data
+const double FGReplay::lt_list_time = 3600.0; // 1 hr of 10 spf data
+
+// short term sample rate is as every frame
+const double FGReplay::mt_dt = 0.5; // medium term sample rate (sec)
+const double FGReplay::lt_dt = 5.0; // long term sample rate (sec)
 
 /**
  * Constructor
@@ -94,10 +102,10 @@ void FGReplay::unbind() {
  */
 
 void FGReplay::update( double dt ) {
+    static SGPropertyNode *replay_master = fgGetNode( "/sim/freeze/replay" );
 
-    if ( dt <= 0 ) {
-        // don't save data if nothing is going on ...
-
+    if ( replay_master->getBoolValue() ) {
+        // don't record the replay session
         return;
     }
 
@@ -208,9 +216,14 @@ static FGReplayData interpolate( double time, FGReplayData f1, FGReplayData f2 )
     FGNetFDM fdm1 = f1.fdm;
     FGNetFDM fdm2 = f2.fdm;
 
+    FGNetCtrls ctrls1 = f1.ctrls;
+    FGNetCtrls ctrls2 = f2.ctrls;
+
     double ratio = (time - f1.sim_time) / (f2.sim_time - f1.sim_time);
 
-    cout << fdm1.longitude << " " << fdm2.longitude << endl;
+    // Interpolate FDM data
+
+    // Positions
     result.fdm.longitude = weight( fdm1.longitude, fdm2.longitude, ratio );
     result.fdm.latitude = weight( fdm1.latitude, fdm2.latitude, ratio );
     result.fdm.altitude = weight( fdm1.altitude, fdm2.altitude, ratio );
@@ -219,6 +232,7 @@ static FGReplayData interpolate( double time, FGReplayData f1, FGReplayData f2 )
     result.fdm.theta = weight( fdm1.theta, fdm2.theta, ratio, true );
     result.fdm.psi = weight( fdm1.psi, fdm2.psi, ratio, true );
 
+    // Velocities
     result.fdm.phidot = weight( fdm1.phidot, fdm2.phidot, ratio, true );
     result.fdm.thetadot = weight( fdm1.thetadot, fdm2.thetadot, ratio, true );
     result.fdm.psidot = weight( fdm1.psidot, fdm2.psidot, ratio, true );
@@ -235,20 +249,130 @@ static FGReplayData interpolate( double time, FGReplayData f1, FGReplayData f2 )
     result.fdm.v_wind_body_down
         = weight( fdm1.v_wind_body_down, fdm2.v_wind_body_down, ratio );
 
+    // Stall
     result.fdm.stall_warning
         = weight( fdm1.stall_warning, fdm2.stall_warning, ratio );
 
+    // Accelerations
     result.fdm.A_X_pilot = weight( fdm1.A_X_pilot, fdm2.A_X_pilot, ratio );
     result.fdm.A_Y_pilot = weight( fdm1.A_Y_pilot, fdm2.A_Y_pilot, ratio );
     result.fdm.A_Z_pilot = weight( fdm1.A_Z_pilot, fdm2.A_Z_pilot, ratio );
 
+    int i;
+
+    // Engine status
+    for ( i = 0; i < fdm1.num_engines; ++i ) {
+        result.fdm.eng_state[i] = fdm1.eng_state[i];
+        result.fdm.rpm[i] = weight( fdm1.rpm[i], fdm2.rpm[i], ratio );
+        result.fdm.fuel_flow[i]
+            = weight( fdm1.fuel_flow[i], fdm2.fuel_flow[i], ratio );
+        result.fdm.EGT[i] = weight( fdm1.EGT[i], fdm2.EGT[i], ratio );
+        result.fdm.oil_temp[i]
+            = weight( fdm1.oil_temp[i], fdm2.oil_temp[i], ratio );
+        result.fdm.oil_px[i] = weight( fdm1.oil_px[i], fdm2.oil_px[i], ratio );
+    }
+
+    // Consumables
+    for ( i = 0; i < fdm1.num_tanks; ++i ) {
+        result.fdm.fuel_quantity[i]
+            = weight( fdm1.fuel_quantity[i], fdm2.fuel_quantity[i], ratio );
+    }
+
+    // Gear status
+    for ( i = 0; i < fdm1.num_wheels; ++i ) {
+        result.fdm.wow[i] = weight( fdm1.wow[i], fdm2.wow[i], ratio );
+        result.fdm.gear_pos[i]
+            = weight( fdm1.gear_pos[i], fdm2.gear_pos[i], ratio );
+        result.fdm.gear_steer[i]
+            = weight( fdm1.gear_steer[i], fdm2.gear_steer[i], ratio );
+        result.fdm.gear_compression[i]
+            = weight( fdm1.gear_compression[i], fdm2.gear_compression[i],
+                      ratio );
+    }
+
+    // Environment
+    result.fdm.cur_time = fdm1.cur_time;
+    result.fdm.warp = fdm1.warp;
+    result.fdm.visibility = weight( fdm1.visibility, fdm2.visibility, ratio );
+
+    // Control surface positions (normalized values)
+    result.fdm.elevator = weight( fdm1.elevator, fdm2.elevator, ratio );
+    result.fdm.flaps = weight( fdm1.flaps, fdm2.flaps, ratio );
+    result.fdm.left_aileron
+        = weight( fdm1.left_aileron, fdm2.left_aileron, ratio );
+    result.fdm.right_aileron
+        = weight( fdm1.right_aileron, fdm2.right_aileron, ratio );
+    result.fdm.rudder = weight( fdm1.rudder, fdm2.rudder, ratio );
+    result.fdm.speedbrake = weight( fdm1.speedbrake, fdm2.speedbrake, ratio );
+    result.fdm.spoilers = weight( fdm1.spoilers, fdm2.spoilers, ratio );
+     
+    // Interpolate Control input data
+
+    // Aero controls
+    result.ctrls.aileron = weight( ctrls1.aileron, ctrls2.aileron, ratio );
+    result.ctrls.elevator = weight( ctrls1.elevator, ctrls2.elevator, ratio );
+    result.ctrls.elevator_trim
+        = weight( ctrls1.elevator_trim, ctrls2.elevator_trim, ratio );
+    result.ctrls.rudder = weight( ctrls1.rudder, ctrls2.rudder, ratio );
+    result.ctrls.flaps = weight( ctrls1.flaps, ctrls2.flaps, ratio );
+    result.ctrls.flaps_power
+        = weight( ctrls1.flaps_power, ctrls2.flaps_power, ratio );
+
+    // Engine controls
+    for ( i = 0; i < ctrls1.num_engines; ++i ) {
+        result.ctrls.magnetos[i] = ctrls1.magnetos[i];
+        result.ctrls.starter_power[i] = ctrls1.starter_power[i];
+        result.ctrls.throttle[i]
+            = weight( ctrls1.throttle[i], ctrls2.throttle[i], ratio );
+        result.ctrls.mixture[i]
+            = weight( ctrls1.mixture[i], ctrls2.mixture[i], ratio );
+        result.ctrls.fuel_pump_power[i] = ctrls1.fuel_pump_power[i];
+        result.ctrls.prop_advance[i]
+            = weight( ctrls1.prop_advance[i], ctrls2.prop_advance[i], ratio );
+    }
+
+    // Fuel management
+    for ( i = 0; i < ctrls1.num_tanks; ++i ) {
+        result.ctrls.fuel_selector[i] = ctrls1.fuel_selector[i];
+    }
+
+    // Brake controls
+    for ( i = 0; i < ctrls1.num_wheels; ++i ) {
+        result.ctrls.brake[i]
+            = weight( ctrls1.brake[i], ctrls2.brake[i], ratio );
+    }
+
+    // Landing Gear
+    result.ctrls.gear_handle = ctrls1.gear_handle;
+
+    // Switches
+    result.ctrls.master_bat = ctrls1.master_bat;
+    result.ctrls.master_alt = ctrls1.master_alt;
+    result.ctrls.turbulence_norm = ctrls1.turbulence_norm;
+
+    // wind and turbulance
+    result.ctrls.wind_speed_kt
+        = weight( ctrls1.wind_speed_kt, ctrls2.wind_speed_kt, ratio );
+    result.ctrls.wind_dir_deg
+        = weight( ctrls1.wind_dir_deg, ctrls2.wind_dir_deg, ratio );
+    result.ctrls.turbulence_norm
+        = weight( ctrls1.turbulence_norm, ctrls2.turbulence_norm, ratio );
+
+    // other information about environment
+    result.ctrls.hground = weight( ctrls1.hground, ctrls2.hground, ratio );
+    result.ctrls.magvar = weight( ctrls1.magvar, ctrls2.magvar, ratio );
+
+    // simulation control
+    result.ctrls.speedup = ctrls1.speedup;
+    result.ctrls.freeze = ctrls1.freeze;
+
     return result;
 }
 
 /** 
  * interpolate a specific time from a specific list
  */
-static void interpolate( double time, replay_list_type list ) {
+static void interpolate( double time, const replay_list_type &list ) {
     // sanity checking
     if ( list.size() == 0 ) {
         // handle empty list
@@ -294,7 +418,7 @@ static void interpolate( double time, replay_list_type list ) {
  */
 
 void FGReplay::replay( double time ) {
-    cout << "replay: " << time << " ";
+    // cout << "replay: " << time << " ";
     // find the two frames to interpolate between
     double t1, t2;
 
@@ -304,10 +428,10 @@ void FGReplay::replay( double time ) {
         if ( time > t1 ) {
             // replay the most recent frame
             update_fdm( short_term.back() );
-            cout << "first frame" << endl;
+            // cout << "first frame" << endl;
         } else if ( time <= t1 && time >= t2 ) {
             interpolate( time, short_term );
-            cout << "from short term" << endl;
+            // cout << "from short term" << endl;
         } else if ( medium_term.size() > 0 ) {
             t1 = short_term.front().sim_time;
             t2 = medium_term.back().sim_time;
@@ -316,13 +440,13 @@ void FGReplay::replay( double time ) {
                                                    medium_term.back(),
                                                    short_term.front() );
                 update_fdm( result );
-                cout << "from short/medium term" << endl;
+                // cout << "from short/medium term" << endl;
             } else {
                 t1 = medium_term.back().sim_time;
                 t2 = medium_term.front().sim_time;
                 if ( time <= t1 && time >= t2 ) {
                     interpolate( time, medium_term );
-                    cout << "from medium term" << endl;
+                    // cout << "from medium term" << endl;
                 } else if ( long_term.size() > 0 ) {
                     t1 = medium_term.front().sim_time;
                     t2 = long_term.back().sim_time;
@@ -331,29 +455,29 @@ void FGReplay::replay( double time ) {
                                                            long_term.back(),
                                                            medium_term.front());
                         update_fdm( result );
-                       cout << "from medium/long term" << endl;
+                        // cout << "from medium/long term" << endl;
                     } else {
                         t1 = long_term.back().sim_time;
                         t2 = long_term.front().sim_time;
                         if ( time <= t1 && time >= t2 ) {
                             interpolate( time, long_term );
-                            cout << "from long term" << endl;
+                            // cout << "from long term" << endl;
                         } else {
                             // replay the oldest long term frame
                             update_fdm( long_term.front() );
-                            cout << "oldest long term frame" << endl;
+                            // cout << "oldest long term frame" << endl;
                         }
                     }
                 } else {
                     // replay the oldest medium term frame
                     update_fdm( medium_term.front() );
-                    cout << "oldest medium term frame" << endl;
+                    // cout << "oldest medium term frame" << endl;
                 }
             }
         } else {
             // replay the oldest short term frame
             update_fdm( short_term.front() );
-            cout << "oldest short term frame" << endl;
+            // cout << "oldest short term frame" << endl;
         }
     } else {
         // nothing to replay