]> git.mxchange.org Git - flightgear.git/commitdiff
Encapsulate the interpolstion version of FGEnvironment and fix some bugs
authorehofman <ehofman>
Sat, 21 Feb 2004 14:04:40 +0000 (14:04 +0000)
committerehofman <ehofman>
Sat, 21 Feb 2004 14:04:40 +0000 (14:04 +0000)
src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx
src/Environment/environment_mgr.cxx
src/Main/options.cxx

index 3ded1f43bdc3ef6fc1f6cb9d631780d634c4d967..2f08e98280beb424af96603dee34f96267f0e74f 100644 (file)
@@ -32,6 +32,9 @@
 
 SG_USING_STD(sort);
 
+// FIXME, from options.cxx
+extern void fgSetupWind (double min_hdg, double max_hdg, double speed, double gust);
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -310,7 +313,8 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const bucket &b) const
 ////////////////////////////////////////////////////////////////////////
 
 FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
-    : _icao( strdup( fgGetString("/sim/presets/airport-id") ) )
+    : env( new FGInterpolateEnvironmentCtrl ),
+      _icao( strdup( fgGetString("/sim/presets/airport-id") ) )
 {
 }
 
@@ -320,6 +324,9 @@ FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
       free(_icao);
       _icao = NULL;
     }
+
+   delete env;
+   env = NULL;
 }
 
 
@@ -331,30 +338,66 @@ FGMetarEnvironmentCtrl::init ()
         _icao = NULL;
     }
 
-    read_table(_icao);
-    _base_wind_speed_node =
-        fgGetNode("/environment/metar/base-wind-range-from", true);
-    _gust_wind_speed_node =
-        fgGetNode("/environment/metar/gust-wind-speed-kt", true);
+    fetch_data(_icao);
+    fgSetupWind( fgGetDouble("/environment/metar/base-wind-range-from"),
+                 fgGetDouble("/environment/metar/base-wind-range-to"),
+                 fgGetDouble("/environment/metar/base-wind-speed-kt"),
+                 fgGetDouble("/environment/metar/gust-wind-speed-kt") );
 
     fgSetDouble("/environment/visibility-m",
         fgGetDouble("/environment/metar/min-visibility-m"));
     fgSetDouble("/environment/temperature-degc",
-        fgGetDouble("/environment/metar/temperature_degc"));
+        fgGetDouble("/environment/metar/temperature-degc"));
     fgSetDouble("/environment/dewpoint-degc",
         fgGetDouble("/environment/metar/dewpoint-degc"));
     fgSetDouble("/environment/pressure-inhg",
         fgGetDouble("/environment/metar/pressure-inhg"));
+
+    env->init();
 }
 
 void
 FGMetarEnvironmentCtrl::reinit ()
 {
-    init();
+    if (_icao != NULL) {
+        free(_icao);
+        _icao = NULL;
+    }
+
+    fetch_data(_icao);
+    fgSetupWind( fgGetDouble("/environment/metar/base-wind-range-from"),
+                 fgGetDouble("/environment/metar/base-wind-range-to"),
+                 fgGetDouble("/environment/metar/base-wind-speed-kt"),
+                 fgGetDouble("/environment/metar/gust-wind-speed-kt") );
+
+    fgSetDouble("/environment/visibility-m",
+        fgGetDouble("/environment/metar/min-visibility-m"));
+    fgSetDouble("/environment/pressure-inhg",
+        fgGetDouble("/environment/metar/pressure-inhg"));
+
+    // FIXME: The following seem to egt overriden?
+    fgSetDouble("/environment/temperature-degc",
+        fgGetDouble("/environment/metar/temperature-degc"));
+    fgSetDouble("/environment/dewpoint-degc",
+        fgGetDouble("/environment/metar/dewpoint-degc"));
+
+    env->reinit();
 }
 
 void
-FGMetarEnvironmentCtrl::read_table (const char *icao)
+FGMetarEnvironmentCtrl::update(double delta_time_sec)
+{
+    env->update(delta_time_sec);
+}
+
+void
+FGMetarEnvironmentCtrl::setEnvironment (FGEnvironment * environment)
+{
+    env->setEnvironment(environment);
+}
+
+void
+FGMetarEnvironmentCtrl::fetch_data (const char *icao)
 {
     char s[128];
     double d, dt;
@@ -381,8 +424,8 @@ FGMetarEnvironmentCtrl::read_table (const char *icao)
 
     SGMetarVisibility *dirvis = m->getDirVisibility();
     for (i = 0; i < 8; i++, dirvis++) {
-        const char *min = "/environment/metar/visibility[%]/min-m";
-        const char *max = "/environment/metar/visibility[%]/max-m";
+        const char *min = "/environment/metar/visibility[%d]/min-m";
+        const char *max = "/environment/metar/visibility[%d]/max-m";
         char s[128];
 
         d = dirvis->getVisibility_m();
@@ -420,7 +463,7 @@ FGMetarEnvironmentCtrl::read_table (const char *icao)
                     m->getRelHumidity() );
     }   
     d = (d != SGMetarNaN) ? d : 15.0;
-    fgSetDouble("/environment/metar/temperature_degc", d);
+    fgSetDouble("/environment/metar/temperature-degc", d);
 
     d = m->getPressure_inHg();
     d = (d != SGMetarNaN) ? d : 30.0;
@@ -477,58 +520,5 @@ FGMetarEnvironmentCtrl::read_table (const char *icao)
     delete m;
 }
 
-void
-FGMetarEnvironmentCtrl::update (double delta_time_sec)
-{
-  double base_wind_speed = _base_wind_speed_node->getDoubleValue();
-  double gust_wind_speed = _gust_wind_speed_node->getDoubleValue();
-
-  if (gust_wind_speed < base_wind_speed) {
-      gust_wind_speed = base_wind_speed;
-      _gust_wind_speed_node->setDoubleValue(gust_wind_speed);
-  }
-
-  if (base_wind_speed == gust_wind_speed) {
-    _current_wind_speed_kt = base_wind_speed;
-  } else {
-    int rn = rand() % 128;
-    int sign = (_delta_wind_speed_kt < 0 ? -1 : 1);
-    double gust = _current_wind_speed_kt - base_wind_speed;
-    double incr = gust / 50;
-
-    if (rn == 0)
-      _delta_wind_speed_kt = - _delta_wind_speed_kt;
-    else if (rn < 4)
-      _delta_wind_speed_kt -= incr * sign;
-    else if (rn < 16)
-      _delta_wind_speed_kt += incr * sign;
-
-    _current_wind_speed_kt += _delta_wind_speed_kt;
-
-    if (_current_wind_speed_kt < base_wind_speed) {
-      _current_wind_speed_kt = base_wind_speed;
-      _delta_wind_speed_kt = 0.01;
-    } else if (_current_wind_speed_kt > gust_wind_speed) {
-      _current_wind_speed_kt = gust_wind_speed;
-      _delta_wind_speed_kt = -0.01;
-    }
-  }
-
-  if (_environment != 0)
-    _environment->set_wind_speed_kt(_current_wind_speed_kt);
-}
-
-void
-FGMetarEnvironmentCtrl::do_interpolate (vector<bucket *> &table,
-                                              double altitude_ft,
-                                              FGEnvironment * environment)
-{
-}
-
-bool
-FGMetarEnvironmentCtrl::bucket::operator< (const bucket &b) const
-{
-    return (altitude_ft < b.altitude_ft);
-}
 
 // end of environment_ctrl.cxx
index ca5c5eb8f3802ef221df44401792d08ad4e4f604..d22e30641496a8d2abb0dc01fa08f4f16cd517df 100644 (file)
@@ -148,24 +148,13 @@ public:
     virtual void reinit ();
     virtual void update (double delta_time_sec);
 
-private:
+    virtual void setEnvironment (FGEnvironment * environment);
 
-    struct bucket {
-        double altitude_ft;
-        FGEnvironment environment;
-        bool operator< (const bucket &b) const;
-    };
+private:
+    FGInterpolateEnvironmentCtrl *env;
 
     char *_icao;
-    SGPropertyNode * _base_wind_speed_node;
-    SGPropertyNode * _gust_wind_speed_node;
-
-    double _current_wind_speed_kt;
-    double _delta_wind_speed_kt;
-
-    void read_table (const char *icao);
-    void do_interpolate (vector<bucket *> &table, double altitude_ft,
-                         FGEnvironment * environment);
+    void fetch_data (const char *icao);
 };
 
 #endif // _ENVIRONMENT_CTRL_HXX
index 0a692c2d60e4fd7c80c8843337c03b220bd2662a..172c41f1c110e905baa6c236a3a6c0944921b33d 100644 (file)
@@ -36,7 +36,7 @@ FGEnvironmentMgr::FGEnvironmentMgr ()
   : _environment(new FGEnvironment)
 {
 
-   if (fgGetBool("/environment/params/use-real-wether-fetch") == true)
+   if (fgGetBool("/environment/params/real-world-weather-fetch") == true)
        _controller = new FGMetarEnvironmentCtrl;
    else
        _controller = new FGInterpolateEnvironmentCtrl;
index 1d76c20bdecc1574c7978df44371e068f4032076..17611685d30aa3a0b82f831c3cb2819e6c98f5f3 100644 (file)
@@ -535,8 +535,8 @@ add_channel( const string& type, const string& channel_str ) {
 }
 
 
-static void
-setup_wind (double min_hdg, double max_hdg, double speed, double gust)
+void
+fgSetupWind (double min_hdg, double max_hdg, double speed, double gust)
 {
                                 // Initialize to a reasonable state
   fgDefaultWeatherValue("wind-from-heading-deg", min_hdg);
@@ -1026,7 +1026,7 @@ fgOptRandomWind( const char *arg )
     double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
     double speed = sg_random() * sg_random() * 40;
     double gust = speed + (10 - sqrt(sg_random() * 100));
-    setup_wind(min_hdg, max_hdg, speed, gust);
+    fgSetupWind(min_hdg, max_hdg, speed, gust);
     return FG_OPTIONS_OK;
 }
 
@@ -1038,7 +1038,7 @@ fgOptWind( const char *arg )
        SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
        return FG_OPTIONS_ERROR;
     }
-    setup_wind(min_hdg, max_hdg, speed, gust);
+    fgSetupWind(min_hdg, max_hdg, speed, gust);
     return FG_OPTIONS_OK;
 }