Make saveInitialProperties smarter, and hence simplify the reset code path.
This commit is contained in:
parent
c4d8cec0f4
commit
388a0a5b6a
2 changed files with 15 additions and 40 deletions
|
@ -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)
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Reference in a new issue