// $Id$
#include <simgear/debug/logstream.hxx>
-#include <simgear/sky/sky.hxx>
+#include <simgear/scene/sky/sky.hxx>
+#include <Main/main.hxx>
#include <Main/fg_props.hxx>
#include <Aircraft/aircraft.hxx>
#include "environment_ctrl.hxx"
#include "environment_mgr.hxx"
-extern SGSky *thesky; // FIXME: from main.cxx
-
FGEnvironmentMgr::FGEnvironmentMgr ()
- : _environment(new FGEnvironment),
- _controller(new FGUserDefEnvironmentCtrl)
+ : _environment(new FGEnvironment)
{
+
+ if (fgGetBool("/environment/params/real-world-weather-fetch") == true)
+ _controller = new FGMetarEnvironmentCtrl;
+ else
+ _controller = new FGInterpolateEnvironmentCtrl;
+
+ _controller->setEnvironment(_environment);
+ set_subsystem("controller", _controller, 0.5);
}
FGEnvironmentMgr::~FGEnvironmentMgr ()
FGEnvironmentMgr::init ()
{
SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
- _controller->setEnvironment(_environment);
- _controller->init();
+ SGSubsystemGroup::init();
+ _update_fdm();
+}
+
+void
+FGEnvironmentMgr::reinit ()
+{
+ SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
+ SGSubsystemGroup::reinit();
_update_fdm();
}
&FGEnvironment::set_temperature_sea_level_degc);
fgSetArchivable("/environment/temperature-sea-level-degc");
fgTie("/environment/temperature-degc", _environment,
- &FGEnvironment::get_temperature_degc,
- &FGEnvironment::set_temperature_degc);
- fgSetArchivable("/environment/temperature-degc");
+ &FGEnvironment::get_temperature_degc); // FIXME: read-only for now
fgTie("/environment/dewpoint-sea-level-degc", _environment,
&FGEnvironment::get_dewpoint_sea_level_degc,
&FGEnvironment::set_dewpoint_sea_level_degc);
fgSetArchivable("/environment/dewpoint-sea-level-degc");
fgTie("/environment/dewpoint-degc", _environment,
- &FGEnvironment::get_dewpoint_degc,
- &FGEnvironment::set_dewpoint_degc);
- fgSetArchivable("/environment/dewpoint-degc");
+ &FGEnvironment::get_dewpoint_degc); // FIXME: read-only for now
fgTie("/environment/pressure-sea-level-inhg", _environment,
&FGEnvironment::get_pressure_sea_level_inhg,
&FGEnvironment::set_pressure_sea_level_inhg);
fgSetArchivable("/environment/pressure-sea-level-inhg");
fgTie("/environment/pressure-inhg", _environment,
- &FGEnvironment::get_pressure_inhg,
- &FGEnvironment::set_pressure_inhg);
- fgSetArchivable("/environment/pressure-inhg");
+ &FGEnvironment::get_pressure_inhg); // FIXME: read-only for now
fgTie("/environment/density-slugft3", _environment,
&FGEnvironment::get_density_slugft3); // read-only
- fgSetArchivable("/environment/density-inhg");
fgTie("/environment/wind-from-heading-deg", _environment,
&FGEnvironment::get_wind_from_heading_deg,
&FGEnvironment::set_wind_from_heading_deg);
&FGEnvironment::get_wind_from_down_fps,
&FGEnvironment::set_wind_from_down_fps);
fgSetArchivable("/environment/wind-from-down-fps");
+ fgTie("/environment/turbulence/magnitude-norm", _environment,
+ &FGEnvironment::get_turbulence_magnitude_norm,
+ &FGEnvironment::set_turbulence_magnitude_norm);
+ fgSetArchivable("/environment/turbulence/magnitude-norm");
+ fgTie("/environment/turbulence/rate-hz", _environment,
+ &FGEnvironment::get_turbulence_rate_hz,
+ &FGEnvironment::set_turbulence_rate_hz);
+ fgSetArchivable("/environment/turbulence/rate-hz");
for (int i = 0; i < MAX_CLOUD_LAYERS; i++) {
char buf[128];
&FGEnvironmentMgr::get_cloud_layer_transition_ft,
&FGEnvironmentMgr::set_cloud_layer_transition_ft);
fgSetArchivable(buf);
- sprintf(buf, "/environment/clouds/layer[%d]/type", i);
+ sprintf(buf, "/environment/clouds/layer[%d]/coverage", i);
fgTie(buf, this, i,
- &FGEnvironmentMgr::get_cloud_layer_type,
- &FGEnvironmentMgr::set_cloud_layer_type);
+ &FGEnvironmentMgr::get_cloud_layer_coverage,
+ &FGEnvironmentMgr::set_cloud_layer_coverage);
fgSetArchivable(buf);
}
}
void
FGEnvironmentMgr::update (double dt)
{
- _controller->update(dt);
+ SGSubsystemGroup::update(dt);
+
// FIXME: the FDMs should update themselves
current_aircraft.fdm_state
->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
void
FGEnvironmentMgr::set_cloud_layer_elevation_ft (int index, double elevation_ft)
{
+ FGEnvironment env = *_environment;
+ env.set_elevation_ft(elevation_ft);
+
thesky->get_cloud_layer(index)
->setElevation_m(elevation_ft * SG_FEET_TO_METER);
+
+ thesky->get_cloud_layer(index)
+ ->setSpeed(env.get_wind_speed_kt() * 0.5151); // 1 kt = 0.5151 m/s
+
+ thesky->get_cloud_layer(index)
+ ->setDirection(env.get_wind_from_heading_deg());
}
double
}
const char *
-FGEnvironmentMgr::get_cloud_layer_type (int index) const
+FGEnvironmentMgr::get_cloud_layer_coverage (int index) const
{
- switch (thesky->get_cloud_layer(index)->getType()) {
+ switch (thesky->get_cloud_layer(index)->getCoverage()) {
case SGCloudLayer::SG_CLOUD_OVERCAST:
return "overcast";
- case SGCloudLayer::SG_CLOUD_MOSTLY_CLOUDY:
- return "mostly-cloudy";
- case SGCloudLayer::SG_CLOUD_MOSTLY_SUNNY:
- return "mostly-sunny";
+ case SGCloudLayer::SG_CLOUD_BROKEN:
+ return "broken";
+ case SGCloudLayer::SG_CLOUD_SCATTERED:
+ return "scattered";
+ case SGCloudLayer::SG_CLOUD_FEW:
+ return "few";
case SGCloudLayer::SG_CLOUD_CIRRUS:
return "cirrus";
case SGCloudLayer::SG_CLOUD_CLEAR:
}
void
-FGEnvironmentMgr::set_cloud_layer_type (int index, const char * type_name)
+FGEnvironmentMgr::set_cloud_layer_coverage (int index,
+ const char * coverage_name)
{
- SGCloudLayer::Type type;
- if (!strcmp(type_name, "overcast"))
- type = SGCloudLayer::SG_CLOUD_OVERCAST;
- else if (!strcmp(type_name, "mostly-cloudy"))
- type = SGCloudLayer::SG_CLOUD_MOSTLY_CLOUDY;
- else if (!strcmp(type_name, "mostly-sunny"))
- type = SGCloudLayer::SG_CLOUD_MOSTLY_SUNNY;
- else if (!strcmp(type_name, "cirrus"))
- type = SGCloudLayer::SG_CLOUD_CIRRUS;
- else if (!strcmp(type_name, "clear"))
- type = SGCloudLayer::SG_CLOUD_CLEAR;
+ SGCloudLayer::Coverage coverage;
+ if (!strcmp(coverage_name, "overcast"))
+ coverage = SGCloudLayer::SG_CLOUD_OVERCAST;
+ else if (!strcmp(coverage_name, "broken"))
+ coverage = SGCloudLayer::SG_CLOUD_BROKEN;
+ else if (!strcmp(coverage_name, "scattered"))
+ coverage = SGCloudLayer::SG_CLOUD_SCATTERED;
+ else if (!strcmp(coverage_name, "few"))
+ coverage = SGCloudLayer::SG_CLOUD_FEW;
+ else if (!strcmp(coverage_name, "cirrus"))
+ coverage = SGCloudLayer::SG_CLOUD_CIRRUS;
+ else if (!strcmp(coverage_name, "clear"))
+ coverage = SGCloudLayer::SG_CLOUD_CLEAR;
else {
- SG_LOG(SG_INPUT, SG_WARN, "Unknown cloud type " << type_name);
- type = SGCloudLayer::SG_CLOUD_CLEAR;
+ SG_LOG(SG_INPUT, SG_WARN, "Unknown cloud type " << coverage_name);
+ coverage = SGCloudLayer::SG_CLOUD_CLEAR;
}
- thesky->get_cloud_layer(index)->setType(type);
+ thesky->get_cloud_layer(index)->setCoverage(coverage);
}