From cfab8366307f1f90bcb05a2353d5c6ead2a5b846 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 11 Jun 2003 14:18:24 +0000 Subject: [PATCH] Fix weather-related command-line options to work with the new weather scheme. --- src/Main/options.cxx | 31 +++++++++++++++++++++---------- src/Main/util.cxx | 22 ++++++++++++++++++++++ src/Main/util.hxx | 11 +++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 2db0c79a1..ea9d3e51b 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -60,6 +60,7 @@ #include "fg_init.hxx" #include "fg_props.hxx" #include "options.hxx" +#include "util.hxx" #include "viewmgr.hxx" @@ -208,7 +209,6 @@ fgSetDefaults () fgSetInt("/sim/rendering/bits-per-pixel", 16); fgSetString("/sim/view-mode", "pilot"); fgSetDouble("/sim/current-view/heading-offset-deg", 0); - fgSetDouble("/environment/visibility-m", 20000); // HUD options fgSetString("/sim/startup/units", "feet"); @@ -542,12 +542,8 @@ add_channel( const string& type, const string& channel_str ) { static void setup_wind (double min_hdg, double max_hdg, double speed, double gust) { - fgSetDouble("/environment/wind-from-heading-deg", min_hdg); - fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg); - fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg); - fgSetDouble("/environment/wind-speed-kt", speed); - fgSetDouble("/environment/params/base-wind-speed-kt", speed); - fgSetDouble("/environment/params/gust-wind-speed-kt", gust); + fgDefaultWeatherValue("wind-from-heading-deg", min_hdg); + fgDefaultWeatherValue("wind-speed-kt", speed); SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' << speed << " knots" << endl); @@ -955,11 +951,19 @@ fgOptViewOffset( const char *arg ) return FG_OPTIONS_OK; } +static int +fgOptVisibilityMeters( const char *arg ) +{ + double visibility = atof( arg ); + fgDefaultWeatherValue("visibility-m", visibility); + return FG_OPTIONS_OK; +} + static int fgOptVisibilityMiles( const char *arg ) { double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER; - fgSetDouble("/environment/visibility-m", visibility); + fgDefaultWeatherValue("visibility-m", visibility); return FG_OPTIONS_OK; } @@ -986,6 +990,13 @@ fgOptWind( const char *arg ) return FG_OPTIONS_OK; } +static int +fgOptTurbulence( const char *arg) +{ + fgDefaultWeatherValue("turbulence-norm", atof(arg)); + return FG_OPTIONS_OK; +} + static int fgOptWp( const char *arg ) { @@ -1187,11 +1198,11 @@ struct OptionDesc { {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite }, {"log-level", true, OPTION_INT, "/sim/log-level", false, "", 0 }, {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset }, - {"visibility", true, OPTION_DOUBLE, "/environment/visibility-m", false, "", 0 }, + {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters }, {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles }, {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind }, {"wind", true, OPTION_FUNC, "", false, "", fgOptWind }, - {"turbulence", true, OPTION_DOUBLE, "/environment/turbulence-norm", false, "", 0 }, + {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence }, {"wp", true, OPTION_FUNC, "", false, "", fgOptWp }, {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan }, {"config", true, OPTION_FUNC, "", false, "", fgOptConfig }, diff --git a/src/Main/util.cxx b/src/Main/util.cxx index 4e952685b..c6ab0aa5c 100644 --- a/src/Main/util.cxx +++ b/src/Main/util.cxx @@ -18,8 +18,13 @@ // $Id$ +#include + #include +#include +SG_USING_STD(vector); + #include #include "fg_io.hxx" @@ -32,6 +37,23 @@ #endif +void +fgDefaultWeatherValue (const char * propname, double value) +{ + int i; + + SGPropertyNode * branch = fgGetNode("/environment/config/boundary", true); + vector entries = branch->getChildren("entry"); + for (i = 0; i < entries.size(); i++) + entries[i]->setDoubleValue(propname, value); + + branch = fgGetNode("/environment/config/aloft", true); + entries = branch->getChildren("entry"); + for (i = 0; i < entries.size(); i++) + entries[i]->setDoubleValue(propname, value); +} + + void fgExit (int status) { diff --git a/src/Main/util.hxx b/src/Main/util.hxx index 20507033c..093e7d69e 100644 --- a/src/Main/util.hxx +++ b/src/Main/util.hxx @@ -26,6 +26,17 @@ #endif +/** + * Initialize a single value through all existing weather levels. + * + * This function is useful mainly from the command-line. + * + * @param propname The name of the subproperty to initialized. + * @param value The initial value. + */ +extern void fgDefaultWeatherValue (const char * propname, double value); + + /** * Clean up and exit FlightGear. *