From 88f7c0527409263be766760e3bbca7f6fb60b418 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 12 Jun 2011 20:31:56 +0200 Subject: [PATCH] Introduce "PRESERVE" flag to protect properties on sim reset. Some specific properties need protection and shouldn't be restored to their original values on sim-reset. --- src/GUI/property_list.cxx | 8 ++++++++ src/Main/globals.cxx | 26 ++++++++++++-------------- src/Scripting/NasalSys.cxx | 4 +++- src/Scripting/nasal-props.cxx | 2 ++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/GUI/property_list.cxx b/src/GUI/property_list.cxx index 5bcb46a35..7940ca28f 100644 --- a/src/GUI/property_list.cxx +++ b/src/GUI/property_list.cxx @@ -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) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 62ae38ffa..9ed3a6b56 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -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, diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index af67ae368..9542c5d55 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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 diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index 214cc5c9a..15a3016f3 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -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(); -- 2.39.5