1
0
Fork 0

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.
This commit is contained in:
ThorstenB 2011-06-12 20:31:56 +02:00
parent 7d92bd3a1a
commit 88f7c05274
4 changed files with 25 additions and 15 deletions

View file

@ -343,6 +343,8 @@ void PropertyList::updateTextForEntry(NodeData& data)
ext += 'A'; ext += 'A';
if (node->getAttribute(SGPropertyNode::USERARCHIVE)) if (node->getAttribute(SGPropertyNode::USERARCHIVE))
ext += 'U'; ext += 'U';
if (node->getAttribute(SGPropertyNode::PRESERVE))
ext += 'P';
if (node->isTied()) if (node->isTied())
ext += 'T'; ext += 'T';
@ -357,6 +359,12 @@ void PropertyList::updateTextForEntry(NodeData& data)
} }
line << ')'; line << ')';
} }
else
if ((_verbose)&&(node->getAttribute(SGPropertyNode::PRESERVE)))
{
// only preserve/protection flag matters for nodes without values
line << " (P)";
}
stdString out = line.str(); stdString out = line.str();
if (out.size() >= PUSTRING_MAX) if (out.size() >= PUSTRING_MAX)

View file

@ -364,21 +364,18 @@ FGGlobals::saveInitialState ()
{ {
initial_state = new SGPropertyNode(); initial_state = new SGPropertyNode();
// copy properties which are READ/WRITEable - but not USERARCHIVEd // copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
if (!copyProperties(props, initial_state, int checked = SGPropertyNode::READ+SGPropertyNode::WRITE+
SGPropertyNode::READ+SGPropertyNode::WRITE, SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
SGPropertyNode::READ+SGPropertyNode::WRITE+SGPropertyNode::USERARCHIVE)) int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
if (!copyProperties(props, initial_state, expected, checked))
SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state"); SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state");
// delete various properties from the initial state, since we want to // delete various properties from the initial state, since we want to
// preserve their values even if doing a restore // 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"); 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"); SGPropertyNode* cameraGroupNode = sim->getNode("rendering/camera-group");
if (cameraGroupNode) { if (cameraGroupNode) {
cameraGroupNode->removeChild("camera"); cameraGroupNode->removeChild("camera");
@ -396,10 +393,11 @@ FGGlobals::restoreInitialState ()
"No initial state available to restore!!!"); "No initial state available to restore!!!");
return; return;
} }
// restore properties which are READ/WRITEable - but not USERARCHIVEd // copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
if ( copyProperties(initial_state, props, int checked = SGPropertyNode::READ+SGPropertyNode::WRITE+
SGPropertyNode::READ+SGPropertyNode::WRITE, SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
SGPropertyNode::READ+SGPropertyNode::WRITE+SGPropertyNode::USERARCHIVE)) { int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
if ( copyProperties(initial_state, props, expected, checked)) {
SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" ); SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" );
} else { } else {
SG_LOG( SG_GENERAL, SG_INFO, SG_LOG( SG_GENERAL, SG_INFO,

View file

@ -914,7 +914,9 @@ void FGNasalSys::loadPropertyScripts(SGPropertyNode* n)
enable->addChangeListener(listener, false); 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 // Logs a runtime error, with stack trace, to the FlightGear log stream

View 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-read")) attr = SGPropertyNode::TRACE_READ;
else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE; else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE; else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
else if(!strcmp(a, "preserve")) attr = SGPropertyNode::PRESERVE;
else { else {
naRuntimeError(c, "props.getAttribute() with invalid attribute"); naRuntimeError(c, "props.getAttribute() with invalid attribute");
return naNil(); 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-read")) attr = SGPropertyNode::TRACE_READ;
else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE; else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE; else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
else if(!strcmp(a, "preserve")) attr = SGPropertyNode::PRESERVE;
else { else {
naRuntimeError(c, "props.setAttribute() with invalid attribute"); naRuntimeError(c, "props.setAttribute() with invalid attribute");
return naNil(); return naNil();