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:
parent
7d92bd3a1a
commit
88f7c05274
4 changed files with 25 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue