]> git.mxchange.org Git - flightgear.git/commitdiff
Make saveInitialProperties smarter, and hence simplify the reset code path.
authorJames Turner <zakalawe@mac.com>
Sun, 4 Jul 2010 11:53:51 +0000 (12:53 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 1 Aug 2010 18:04:20 +0000 (19:04 +0100)
src/Main/fg_init.cxx
src/Main/globals.cxx

index b740425a857640c5bd14be076fac750bef4b1816..7805ac413c6950c8e111a63824a818080825a37f 100644 (file)
@@ -1738,35 +1738,11 @@ void doSimulatorReset(void)  // from gui_local.cxx -- TODO merge with fgReInitSu
 
     globals->get_subsystem("flight")->unbind();
 
-    // in case user has changed window size as
-    // restoreInitialState() overwrites these
-    int xsize = fgGetInt("/sim/startup/xsize");
-    int ysize = fgGetInt("/sim/startup/ysize");
-
-    // viewports also needs to be saved/restored as
-    // restoreInitialState() overwrites these
-    SGPropertyNode *guiNode = new SGPropertyNode;
-    SGPropertyNode *cameraNode = new SGPropertyNode;
-    SGPropertyNode *cameraGroupNode = fgGetNode("/sim/rendering/camera-group");
-    copyProperties(cameraGroupNode->getChild("camera"), cameraNode);
-    copyProperties(cameraGroupNode->getChild("gui"), guiNode);
-
     globals->restoreInitialState();
 
     // update our position based on current presets
     fgInitPosition();
 
-    // We don't know how to resize the window, so keep the last values
-    //  for xsize and ysize, and don't use the one set initially
-    fgSetInt("/sim/startup/xsize", xsize);
-    fgSetInt("/sim/startup/ysize", ysize);
-
-    copyProperties(cameraNode, cameraGroupNode->getChild("camera"));
-    copyProperties(guiNode, cameraGroupNode->getChild("gui"));
-
-    delete guiNode;
-    delete cameraNode;
-
     SGTime *t = globals->get_time_params();
     delete t;
     t = fgInitTime();
@@ -1775,7 +1751,6 @@ void doSimulatorReset(void)  // from gui_local.cxx -- TODO merge with fgReInitSu
     fgReInitSubsystems();
 
     globals->get_tile_mgr()->update(fgGetDouble("/environment/visibility-m"));
-    globals->get_renderer()->resize(xsize, ysize);
     fgSetBool("/sim/signals/reinit", false);
 
     if (!freeze)
index a7023045d22d409d35adbc945ac8712b3ddfbc6a..c01057925c4cfcc3466ab6cf42394b986e7edc3a 100644 (file)
@@ -359,6 +359,21 @@ FGGlobals::saveInitialState ()
 
   if (!copyProperties(props, initial_state))
     SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state");
+    
+  // delete various properties from the initial state, since we want to
+  // preserve their values even if doing a restore
+  
+  SGPropertyNode* sim = initial_state->getChild("sim");
+  sim->removeChild("presets");
+  SGPropertyNode* simStartup = sim->getChild("startup");
+  simStartup->removeChild("xsize");
+  simStartup->removeChild("ysize");
+  
+  SGPropertyNode* cameraGroupNode = sim->getNode("rendering/camera-group");
+  if (cameraGroupNode) {
+    cameraGroupNode->removeChild("camera");
+    cameraGroupNode->removeChild("gui");
+  }
 }
 
 
@@ -372,14 +387,6 @@ FGGlobals::restoreInitialState ()
         return;
     }
 
-    SGPropertyNode *currentPresets = new SGPropertyNode;
-    SGPropertyNode *targetNode = fgGetNode( "/sim/presets" );
-
-    // stash the /sim/presets tree
-    if ( !copyProperties(targetNode, currentPresets) ) {
-        SG_LOG( SG_GENERAL, SG_ALERT, "Failed to save /sim/presets subtree" );
-    }
-    
     if ( copyProperties(initial_state, props) ) {
         SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" );
     } else {
@@ -387,13 +394,6 @@ FGGlobals::restoreInitialState ()
                 "Some errors restoring initial state (read-only props?)" );
     }
 
-    // recover the /sim/presets tree
-    if ( !copyProperties(currentPresets, targetNode) ) {
-        SG_LOG( SG_GENERAL, SG_ALERT,
-                "Failed to restore /sim/presets subtree" );
-    }
-
-   delete currentPresets;
 }
 
 FGViewer *