]> git.mxchange.org Git - flightgear.git/commitdiff
The FlightGear patches add new saveInitialState and
authorcurt <curt>
Fri, 19 Jan 2001 22:57:24 +0000 (22:57 +0000)
committercurt <curt>
Fri, 19 Jan 2001 22:57:24 +0000 (22:57 +0000)
restoreInitialState methods to FGGlobals, as well as the two-stage
commit described above for loading saved files.  fgInit now takes a
snapshot of the initial state before handing off to the main loop, and
the GUI reInit function restores that state explicitly before calling
fgReInit.

The FlightGear patches also modify fg_props.hxx to add optional
useDefault arguments to all of the fgTie functions -- that lets you
choose whether you want to pick up any default value in the property
tree when you tie the property (the default is true).

src/GUI/gui_local.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/fg_props.hxx
src/Main/globals.cxx
src/Main/globals.hxx

index 398a47ac8dd910f1956833ed046edc7662db9b64..a68e3063ebee97b1d7187339b4f55f5831cd7135 100644 (file)
@@ -2,6 +2,7 @@
 #include <plib/pu.h>           // plib include
 
 
+#include <Main/globals.hxx>
 #include <Main/fg_init.hxx>
 
 #include "gui.h"
@@ -38,6 +39,7 @@ void reInit(puObject *cb)
        BusyCursor(0);
        Quat0();
        build_rotmatrix(GuiQuat_mat, curGuiQuat);
+       /* check */ globals->restoreInitialState();
        fgReInitSubsystems();
        BusyCursor(1);
 }
index 3581a5818d544982d42d86fbf072de2fdd2b4983..0c506726ffdb49e812378c8c4a30e6d03bf56aa9 100644 (file)
@@ -778,6 +778,10 @@ bool fgInitSubsystems( void ) {
 
     FG_LOG( FG_GENERAL, FG_INFO, endl);
 
+                               // Save the initial state for future
+                               // reference.
+    globals->saveInitialState();
+
     return true;
 }
 
@@ -867,7 +871,7 @@ void fgReInitSubsystems( void )
            << globals->get_current_view()->get_abs_view_pos());
 
     cur_fdm_state->init();
-    cur_fdm_state->bind();
+//     cur_fdm_state->bind();
 //     cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
 
     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
index 46bc65838e97dc5e360cc003ab0f03e35a7c18e6..30c337e9a4f77a4f50b36e1c9a2373a9d3434bb9 100644 (file)
@@ -45,7 +45,16 @@ fgSaveFlight (ostream &output)
 bool
 fgLoadFlight (istream &input)
 {
-  return readProperties(input, globals->get_props());
+  SGPropertyNode props;
+  if (readProperties(input, &props)) {
+    copyProperties(&props, globals->get_props());
+                               // When loading a flight, make it the
+                               // new initial state.
+    globals->saveInitialState();
+  } else {
+    FG_LOG(FG_INPUT, FG_ALERT, "Error restoring flight; aborted");
+    return false;
+  }
 }
 
 // end of fg_props.cxx
index 8dd28cea452ca2830d3417c9f01b17d3dc4a7e20..be9e6878874536352636cbb8a9d342bb182bc006 100644 (file)
@@ -101,50 +101,57 @@ fgUntie (const string &name)
 
                                // Templates cause ambiguity here
 inline void
-fgTie (const string &name, bool *pointer)
+fgTie (const string &name, bool *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer)))
+  if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, int *pointer)
+fgTie (const string &name, int *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer)))
+  if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, float *pointer)
+fgTie (const string &name, float *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer)))
+  if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, double *pointer)
+fgTie (const string &name, double *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer)))
+  if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, string *pointer)
+fgTie (const string &name, string *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer)))
+  if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 template <class V>
 inline void
-fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
+fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
+       bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter)))
+  if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to functions");
 }
@@ -152,12 +159,13 @@ fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
 template <class V>
 inline void
 fgTie (const string &name, int index, V (*getter)(int),
-       void (*setter)(int, V) = 0)
+       void (*setter)(int, V) = 0, bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
                                 SGRawValueFunctionsIndexed<V>(index,
                                                               getter,
-                                                              setter)))
+                                                              setter),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to indexed functions");
 }
@@ -165,10 +173,11 @@ fgTie (const string &name, int index, V (*getter)(int),
 template <class T, class V>
 inline void
 fgTie (const string &name, T * obj, V (T::*getter)() const,
-       void (T::*setter)(V) = 0)
+       void (T::*setter)(V) = 0, bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
-                                SGRawValueMethods<T,V>(*obj, getter, setter)))
+                                SGRawValueMethods<T,V>(*obj, getter, setter),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to object methods");
 }
@@ -176,13 +185,15 @@ fgTie (const string &name, T * obj, V (T::*getter)() const,
 template <class T, class V>
 inline void 
 fgTie (const string &name, T * obj, int index,
-       V (T::*getter)(int) const, void (T::*setter)(int, V) = 0)
+       V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
+       bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
                                 SGRawValueMethodsIndexed<T,V>(*obj,
                                                               index,
                                                               getter,
-                                                              setter)))
+                                                              setter),
+                                useDefault))
     FG_LOG(FG_GENERAL, FG_WARN,
           "Failed to tie property " << name << " to indexed object methods");
 }
index ab752033b401603ef4dd8dcf6389a18ba22bda48..312dc0b81080983ff34e846d8683e8c397f31880 100644 (file)
 #include "fg_props.hxx"
 
 
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGGlobals.
+////////////////////////////////////////////////////////////////////////
+
 // global global :-)
 FGGlobals *globals;
 
@@ -33,21 +38,44 @@ FGGlobals *globals;
 FGGlobals::FGGlobals() :
     freeze( false ),
     warp( 0 ),
-    warp_delta( 0 )
+    warp_delta( 0 ),
+    props(0),
+    initial_state(0)
 {
-                               // TODO: move to a proper bind method
-//   fgTie("/sim/freeze", &freeze);
-//   fgTie("/sim/warp", &warp);
-//   fgTie("/sim/warp-delta", &warp_delta);
 }
 
 
 // Destructor
 FGGlobals::~FGGlobals() 
 {
-                               // TODO: move to a proper unbind method
-//   fgUntie("/sim/freeze");
-//   fgUntie("/sim/warp");
-//   fgUntie("/sim/warp-delta");
+  delete initial_state;
+}
+
+
+// Save the current state as the initial state.
+void
+FGGlobals::saveInitialState ()
+{
+  delete initial_state;
+  initial_state = new SGPropertyNode();
+  if (!copyProperties(props, initial_state))
+    FG_LOG(FG_GENERAL, FG_ALERT, "Error saving initial state");
 }
 
+
+// Restore the saved initial state, if any
+void
+FGGlobals::restoreInitialState ()
+{
+  if (initial_state == 0) {
+    FG_LOG(FG_GENERAL, FG_ALERT, "No initial state available to restore!!!");
+  } else if (!copyProperties(initial_state, props)) {
+    FG_LOG(FG_GENERAL, FG_INFO,
+          "Some errors restoring initial state (probably just read-only props)");
+  } else {
+    FG_LOG(FG_GENERAL, FG_INFO, "Initial state restored successfully");
+  }
+}
+
+
+// end of globals.cxx
index e092aec89407974e02f84c57b9f9dc8dd54c798e..72d3433eff7f0988427fb2a74a56be1b8bfd0a6d 100644 (file)
@@ -83,6 +83,7 @@ private:
 
     // properties
     SGPropertyNode *props;
+    SGPropertyNode *initial_state;
 
     // list of serial port-like configurations
     string_list channel_options_list;
@@ -134,7 +135,19 @@ public:
     inline string_list get_channel_options_list () {
       return channel_options_list;
     }
-    
+
+
+    /**
+     * Save the current state as the initial state.
+     */
+    void saveInitialState ();
+
+
+    /**
+     * Restore the saved initial state, if any.
+     */
+    void restoreInitialState ();
+
 };