]> git.mxchange.org Git - flightgear.git/commitdiff
Introduce "PRESERVE" flag to protect properties on sim reset.
authorThorstenB <brehmt@gmail.com>
Sun, 12 Jun 2011 18:31:56 +0000 (20:31 +0200)
committerThorstenB <brehmt@gmail.com>
Sun, 12 Jun 2011 18:31:56 +0000 (20:31 +0200)
Some specific properties need protection and shouldn't be restored to their
original values on sim-reset.

src/GUI/property_list.cxx
src/Main/globals.cxx
src/Scripting/NasalSys.cxx
src/Scripting/nasal-props.cxx

index 5bcb46a3542cbca9a729460102433b3fd0cfbfae..7940ca28f11a464f28cff6cd60cf618267c572cb 100644 (file)
@@ -343,6 +343,8 @@ void PropertyList::updateTextForEntry(NodeData& data)
                 ext += 'A';
             if (node->getAttribute(SGPropertyNode::USERARCHIVE))
                 ext += 'U';
+            if (node->getAttribute(SGPropertyNode::PRESERVE))
+                ext += 'P';
             if (node->isTied())
                 ext += 'T';
 
@@ -357,6 +359,12 @@ void PropertyList::updateTextForEntry(NodeData& data)
         }
         line << ')';
     }
+    else
+    if ((_verbose)&&(node->getAttribute(SGPropertyNode::PRESERVE)))
+    {
+        // only preserve/protection flag matters for nodes without values
+        line << " (P)";
+    }
 
     stdString out = line.str();
     if (out.size() >= PUSTRING_MAX)
index 62ae38ffadd1fa3c3416acd7bcc2de1e2e60c818..9ed3a6b56478bddcadc44b845ee6e3dbd53d2f7d 100644 (file)
@@ -364,21 +364,18 @@ FGGlobals::saveInitialState ()
 {
   initial_state = new SGPropertyNode();
 
-  // copy properties which are READ/WRITEable - but not USERARCHIVEd
-  if (!copyProperties(props, initial_state,
-          SGPropertyNode::READ+SGPropertyNode::WRITE,
-          SGPropertyNode::READ+SGPropertyNode::WRITE+SGPropertyNode::USERARCHIVE))
+  // copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
+  int checked  = SGPropertyNode::READ+SGPropertyNode::WRITE+
+                 SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
+  int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
+  if (!copyProperties(props, initial_state, expected, checked))
     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
-  
+  // => Properties should now use the PRESERVE flag to protect their values
+  // on sim-reset. Remove some specific properties for backward compatibility.
   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");
@@ -396,10 +393,11 @@ FGGlobals::restoreInitialState ()
                "No initial state available to restore!!!");
         return;
     }
-    // restore properties which are READ/WRITEable - but not USERARCHIVEd
-    if ( copyProperties(initial_state, props,
-            SGPropertyNode::READ+SGPropertyNode::WRITE,
-            SGPropertyNode::READ+SGPropertyNode::WRITE+SGPropertyNode::USERARCHIVE)) {
+    // copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
+    int checked  = SGPropertyNode::READ+SGPropertyNode::WRITE+
+                   SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
+    int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
+    if ( copyProperties(initial_state, props, expected, checked)) {
         SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" );
     } else {
         SG_LOG( SG_GENERAL, SG_INFO,
index af67ae3689a94098a5c98369880565001eb37ccc..9542c5d55a790e080bdcf97307e471f63b49f3a2 100644 (file)
@@ -914,7 +914,9 @@ void FGNasalSys::loadPropertyScripts(SGPropertyNode* n)
             enable->addChangeListener(listener, false);
         }
     }
-    n->setBoolValue("loaded",is_loaded);
+    SGPropertyNode* loaded = n->getChild("loaded",0,true);
+    loaded->setAttribute(SGPropertyNode::PRESERVE,true);
+    loaded->setBoolValue(is_loaded);
 }
 
 // Logs a runtime error, with stack trace, to the FlightGear log stream
index 214cc5c9a4065e0add761112fbb15689dbfb8df9..15a3016f3f31c9f1669625100132fe543d6c053a 100644 (file)
@@ -103,6 +103,7 @@ static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
     else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
+    else if(!strcmp(a, "preserve"))    attr = SGPropertyNode::PRESERVE;
     else {
         naRuntimeError(c, "props.getAttribute() with invalid attribute");
         return naNil();
@@ -128,6 +129,7 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
     else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
+    else if(!strcmp(a, "preserve"))    attr = SGPropertyNode::PRESERVE;
     else {
         naRuntimeError(c, "props.setAttribute() with invalid attribute");
         return naNil();