]> git.mxchange.org Git - flightgear.git/blobdiff - src/Aircraft/replay.cxx
Minor renaming issue.
[flightgear.git] / src / Aircraft / replay.cxx
index 8dd04d8713dbb517b4619277b7c50bb0fd996b58..f44d38b88234f743dcf5c45040d7b0fd7c74e22e 100644 (file)
@@ -31,7 +31,6 @@
 #include <simgear/structure/exception.hxx>
 
 #include <Main/fg_props.hxx>
-#include <FDM/fdm_shell.hxx>
 
 #include "replay.hxx"
 #include "flightrecorder.hxx"
@@ -174,19 +173,26 @@ printTimeStr(char* pStrBuffer,double _Time, bool ShowDecimal=true)
 {
     if (_Time<0)
         _Time = 0;
-    unsigned int Time = (unsigned int) (_Time*10);
-    int h = Time/36000;
-    int m = (Time % 36000)/600;
-    int s = (Time % 600)/10;
-    int d = Time % 10;
+    unsigned int Time = _Time*10;
+    unsigned int h = Time/36000;
+    unsigned int m = (Time % 36000)/600;
+    unsigned int s = (Time % 600)/10;
+    unsigned int d = Time % 10;
+
+    int len;
     if (h>0)
-        sprintf(pStrBuffer,"%u:%02u",h,m);
+        len = sprintf(pStrBuffer,"%u:%02u:%02u",h,m,s);
     else
-        sprintf(pStrBuffer,"%u",m);
+        len = sprintf(pStrBuffer,"%u:%02u",m,s);
+
+    if (len < 0)
+    {
+        *pStrBuffer = 0;
+        return;
+    }
+
     if (ShowDecimal)
-        sprintf(pStrBuffer,"%s:%02u.%u",pStrBuffer,s,d);
-    else
-        sprintf(pStrBuffer,"%s:%02u",pStrBuffer,s);
+        sprintf(&pStrBuffer[len],".%u",d);
 }
 
 /** Start replay session
@@ -235,43 +241,52 @@ FGReplay::update( double dt )
 
     if ( disable_replay->getBoolValue() )
     {
-        current_replay_state = replay_master->getIntValue();
-        replay_master->setIntValue(0);
-        replay_time->setDoubleValue(0);
-        replay_time_str->setStringValue("");
-        disable_replay->setBoolValue(0);
-        speed_up->setDoubleValue(1.0);
-        fgSetString("/sim/messages/copilot", "Replay stopped");
+        if (fgGetBool("/sim/freeze/master",false)||
+            fgGetBool("/sim/freeze/clock",false))
+        {
+            fgSetBool("/sim/freeze/master",false);
+            fgSetBool("/sim/freeze/clock",false);
+            last_replay_state = 1;
+        }
+        else
+        if ((replay_master->getIntValue() != 3)||
+            (last_replay_state == 3))
+        {
+            current_replay_state = replay_master->getIntValue();
+            replay_master->setIntValue(0);
+            replay_time->setDoubleValue(0);
+            replay_time_str->setStringValue("");
+            disable_replay->setBoolValue(0);
+            speed_up->setDoubleValue(1.0);
+            speed_up->setDoubleValue(1.0);
+            if (fgGetBool("/sim/replay/mute",false))
+            {
+                fgSetBool("/sim/sound/enabled",true);
+                fgSetBool("/sim/replay/mute",false);
+            }
+            fgSetString("/sim/messages/copilot", "Replay stopped. Your controls!");
+        }
     }
 
     int replay_state = replay_master->getIntValue();
-
-    if ((replay_state > 0)&&
-       (last_replay_state == 0))
-    {
-        // replay is starting, suspend FDM
-        /* FIXME we need to suspend/resume the FDM - not the entire FDM shell.
-         * FDM isn't available via the global subsystem manager yet, so need a
-         * method at the FDMshell for now */
-        ((FDMShell*) globals->get_subsystem("flight"))->getFDM()->suspend();
-    }
-    else
     if ((replay_state == 0)&&
         (last_replay_state > 0))
     {
         if (current_replay_state == 3)
         {
-            // "my controls!" requested: pilot takes control at current replay position...
+            // take control at current replay position ("My controls!").
             // May need to uncrash the aircraft here :)
             fgSetBool("/sim/crashed", false);
         }
         else
         {
-            // replay was active, restore most recent frame
+            // normal replay exit, restore most recent frame
             replay(DBL_MAX);
         }
-        // replay is finished, resume FDM
-        ((FDMShell*) globals->get_subsystem("flight"))->getFDM()->resume();
+
+        // replay is finished
+        last_replay_state = replay_state;
+        return;
     }
 
     // remember recent state
@@ -282,11 +297,13 @@ FGReplay::update( double dt )
         case 0:
             // replay inactive, keep recording
             break;
-        case 1:
+        case 1: // normal replay
+        case 3: // prepare to resume normal flight at current replay position 
         {
             // replay active
             double current_time = replay_time->getDoubleValue();
-            if (current_time<=0.0)
+            bool ResetTime = (current_time<=0.0);
+            if (ResetTime)
             {
                 // initialize start time
                 double startTime = get_start_time();
@@ -309,11 +326,14 @@ FGReplay::update( double dt )
             char StrBuffer[30];
             printTimeStr(StrBuffer,current_time);
             replay_time_str->setStringValue((const char*)StrBuffer);
+
+            // when time skipped (looped replay), trigger listeners to reset views etc
+            if (ResetTime)
+                replay_master->setIntValue(replay_state);
+
             return; // don't record the replay session 
         }
         case 2: // normal replay operation
-        case 3: // replay operation, prepare to resume normal flight at current replay position 
-            // replay paused, no-op
             return; // don't record the replay session
         default:
             throw sg_range_exception("unknown FGReplay state");