src/Main/options.cxx: Fixed bug introduced by recent support for replaying from url.
We used to modify the --aircraft and --airport options when handling --load-tape, which invalidated iterators and for example could cause later options to be ignored. The solution here is rather crude - we store the new options in globals to ensure that they are used in preference later on.
This commit is contained in:
parent
ad1b932324
commit
538e32d555
1 changed files with 36 additions and 14 deletions
|
@ -1593,6 +1593,19 @@ static std::string urlToLocalPath(const char* url)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When loading a Continuous recording at startup, we need to override the
|
||||||
|
// aircraft and airport. Unfortunately we can't simply set /sim/aircraft
|
||||||
|
// because there may be --aircraft options later on in the command line. Also
|
||||||
|
// fgMainInit() ends up calling Options::initAircraft() after we have processed
|
||||||
|
// all options, and Options::initAircraft() seems to look directly at the
|
||||||
|
// options again, instead of using /sim/aircraft.
|
||||||
|
//
|
||||||
|
// So we store any aircraft/airport override here, so that
|
||||||
|
// Options::initAircraft() can use them if they are set, instead of going back
|
||||||
|
// to any user-specified aircraft.
|
||||||
|
//
|
||||||
|
static std::string g_load_tape_aircraft;
|
||||||
|
static std::string g_load_tape_airport;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fgOptLoadTape(const char* arg)
|
fgOptLoadTape(const char* arg)
|
||||||
|
@ -1719,19 +1732,11 @@ fgOptLoadTape(const char* arg)
|
||||||
std::string aircraft = properties->getStringValue("meta/aircraft-type");
|
std::string aircraft = properties->getStringValue("meta/aircraft-type");
|
||||||
std::string airport = properties->getStringValue("meta/closest-airport-id");
|
std::string airport = properties->getStringValue("meta/closest-airport-id");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "From recording header: aircraft=" << aircraft << " airport=" << airport);
|
SG_LOG(SG_GENERAL, SG_ALERT, "From recording header: aircraft=" << aircraft << " airport=" << airport);
|
||||||
if (aircraft != "") {
|
// Override aircraft and airport settings to match what is in the
|
||||||
// Force --aircraft and --airport options to use values from the
|
// recording.
|
||||||
// recording.
|
//
|
||||||
//
|
g_load_tape_aircraft = aircraft;
|
||||||
Options::sharedInstance()->setOption("aircraft", aircraft);
|
g_load_tape_airport = airport;
|
||||||
}
|
|
||||||
if (airport != "") {
|
|
||||||
// Looks like setting --airport option doesn't work - we need to call
|
|
||||||
// fgOptAirport() directly.
|
|
||||||
//
|
|
||||||
Options::sharedInstance()->setOption("airport", airport);
|
|
||||||
fgOptAirport(airport.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arrange to load the recording after FDM has initialised.
|
// Arrange to load the recording after FDM has initialised.
|
||||||
new DelayedTapeLoader(path.c_str(), filerequest);
|
new DelayedTapeLoader(path.c_str(), filerequest);
|
||||||
|
@ -2378,7 +2383,11 @@ void Options::initPaths()
|
||||||
OptionResult Options::initAircraft()
|
OptionResult Options::initAircraft()
|
||||||
{
|
{
|
||||||
string aircraft;
|
string aircraft;
|
||||||
if (isOptionSet("aircraft")) {
|
if (g_load_tape_aircraft != "") {
|
||||||
|
// Use Continuous recording's aircraft if we are replaying on startup.
|
||||||
|
aircraft = g_load_tape_aircraft;
|
||||||
|
}
|
||||||
|
else if (isOptionSet("aircraft")) {
|
||||||
aircraft = valueForOption("aircraft");
|
aircraft = valueForOption("aircraft");
|
||||||
} else if (isOptionSet("vehicle")) {
|
} else if (isOptionSet("vehicle")) {
|
||||||
aircraft = valueForOption("vehicle");
|
aircraft = valueForOption("vehicle");
|
||||||
|
@ -2834,6 +2843,19 @@ OptionResult Options::processOptions()
|
||||||
globals->append_fg_scenery(root);
|
globals->append_fg_scenery(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_load_tape_aircraft != "") {
|
||||||
|
// This might not be necessary, because we always end up calling
|
||||||
|
// Options::initAircraft() later on, which also knows to use
|
||||||
|
// g_load_tape_aircraft if it is not "".
|
||||||
|
//
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "overriding aircraft from " << fgGetString("/sim/aircraft") << " to " << g_load_tape_aircraft);
|
||||||
|
fgSetString("/sim/aircraft", g_load_tape_aircraft);
|
||||||
|
}
|
||||||
|
if (g_load_tape_airport != "") {
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "overriding airport from " << fgGetString("/sim/presets/airport-id") << " to " << g_load_tape_airport);
|
||||||
|
fgOptAirport(g_load_tape_airport.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
if (isOptionSet("json-report")) {
|
if (isOptionSet("json-report")) {
|
||||||
printJSONReport();
|
printJSONReport();
|
||||||
return FG_OPTIONS_EXIT;
|
return FG_OPTIONS_EXIT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue