X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FEnvironment%2Fenvironment_mgr.cxx;h=51ccfd986d794cc04bb1226a02dabdbb8ded9047;hb=35e67c3a315159f276a57d938e96b2602d34cfa4;hp=8a4e8d4957a8d65963163cd12bb7b46684fee51c;hpb=5a849b66e855a643c600ad4cfcce1f82e0fcdeb3;p=flightgear.git diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index 8a4e8d495..51ccfd986 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -21,6 +21,7 @@ // $Id$ #include +#include #include
#include @@ -29,6 +30,8 @@ #include "environment_ctrl.hxx" #include "environment_mgr.hxx" +extern SGSky *thesky; // FIXME: from main.cxx + FGEnvironmentMgr::FGEnvironmentMgr () : _environment(new FGEnvironment), @@ -48,6 +51,7 @@ FGEnvironmentMgr::init () SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem"); _controller->setEnvironment(_environment); _controller->init(); + _update_fdm(); } void @@ -60,10 +64,28 @@ FGEnvironmentMgr::bind () &FGEnvironment::get_temperature_sea_level_degc, &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"); + 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"); 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"); + fgTie("/environment/density-slugft3", _environment, + &FGEnvironment::get_density_slugft3); // read-only fgTie("/environment/wind-from-heading-deg", _environment, &FGEnvironment::get_wind_from_heading_deg, &FGEnvironment::set_wind_from_heading_deg); @@ -81,17 +103,64 @@ FGEnvironmentMgr::bind () &FGEnvironment::get_wind_from_down_fps, &FGEnvironment::set_wind_from_down_fps); fgSetArchivable("/environment/wind-from-down-fps"); + + for (int i = 0; i < MAX_CLOUD_LAYERS; i++) { + char buf[128]; + sprintf(buf, "/environment/clouds/layer[%d]/span-m", i); + fgTie(buf, this, i, + &FGEnvironmentMgr::get_cloud_layer_span_m, + &FGEnvironmentMgr::set_cloud_layer_span_m); + fgSetArchivable(buf); + sprintf(buf, "/environment/clouds/layer[%d]/elevation-ft", i); + fgTie(buf, this, i, + &FGEnvironmentMgr::get_cloud_layer_elevation_ft, + &FGEnvironmentMgr::set_cloud_layer_elevation_ft); + fgSetArchivable(buf); + sprintf(buf, "/environment/clouds/layer[%d]/thickness-ft", i); + fgTie(buf, this, i, + &FGEnvironmentMgr::get_cloud_layer_thickness_ft, + &FGEnvironmentMgr::set_cloud_layer_thickness_ft); + fgSetArchivable(buf); + sprintf(buf, "/environment/clouds/layer[%d]/transition-ft", i); + fgTie(buf, this, i, + &FGEnvironmentMgr::get_cloud_layer_transition_ft, + &FGEnvironmentMgr::set_cloud_layer_transition_ft); + fgSetArchivable(buf); + sprintf(buf, "/environment/clouds/layer[%d]/type", i); + fgTie(buf, this, i, + &FGEnvironmentMgr::get_cloud_layer_type, + &FGEnvironmentMgr::set_cloud_layer_type); + fgSetArchivable(buf); + } } void FGEnvironmentMgr::unbind () { fgUntie("/environment/visibility-m"); - fgUntie("/environment/wind-from-heading-deg"); - fgUntie("/environment/wind-speed-kt"); + fgUntie("/environment/temperature-sea-level-degc"); + fgUntie("/environment/temperature-degc"); + fgUntie("/environment/dewpoint-sea-level-degc"); + fgUntie("/environment/dewpoint-degc"); + fgUntie("/environment/pressure-sea-level-inhg"); + fgUntie("/environment/pressure-inhg"); + fgUntie("/environment/density-inhg"); fgUntie("/environment/wind-from-north-fps"); fgUntie("/environment/wind-from-east-fps"); fgUntie("/environment/wind-from-down-fps"); + for (int i = 0; i < MAX_CLOUD_LAYERS; i++) { + char buf[128]; + sprintf(buf, "/environment/clouds/layer[%d]/span-m", i); + fgUntie(buf); + sprintf(buf, "/environment/clouds/layer[%d]/elevation-ft", i); + fgUntie(buf); + sprintf(buf, "/environment/clouds/layer[%d]/thickness-ft", i); + fgUntie(buf); + sprintf(buf, "/environment/clouds/layer[%d]/transition-ft", i); + fgUntie(buf); + sprintf(buf, "/environment/clouds/layer[%d]/type", i); + fgUntie(buf); + } } void @@ -103,21 +172,141 @@ FGEnvironmentMgr::update (double dt) ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(), _environment->get_wind_from_east_fps(), _environment->get_wind_from_down_fps()); + _environment->set_elevation_ft(fgGetDouble("/position/altitude-ft")); + + _update_fdm(); } -const FGEnvironment * +FGEnvironment FGEnvironmentMgr::getEnvironment () const { - return _environment; + return *_environment; } -const FGEnvironment * +FGEnvironment FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const { // Always returns the same environment // for now; we'll make it interesting // later. - return _environment; + FGEnvironment env = *_environment; + env.set_elevation_ft(alt); + return env; +} + +void +FGEnvironmentMgr::_update_fdm () const +{ + // + // Pass atmosphere on to FDM + // FIXME: have FDMs read properties directly. + // + if (fgGetBool("/environment/params/control-fdm-atmosphere")) { + // convert from Rankine to Celsius + cur_fdm_state + ->set_Static_temperature((9.0/5.0) + * (_environment->get_temperature_degc() + 273.15)); + // convert from inHG to PSF + cur_fdm_state + ->set_Static_pressure(_environment->get_pressure_inhg() * 70.726566); + // keep in slugs/ft^3 + cur_fdm_state + ->set_Density(_environment->get_density_slugft3()); + } +} + +double +FGEnvironmentMgr::get_cloud_layer_span_m (int index) const +{ + return thesky->get_cloud_layer(index)->getSpan_m(); +} + +void +FGEnvironmentMgr::set_cloud_layer_span_m (int index, double span_m) +{ + thesky->get_cloud_layer(index)->setSpan_m(span_m); +} + +double +FGEnvironmentMgr::get_cloud_layer_elevation_ft (int index) const +{ + return thesky->get_cloud_layer(index)->getElevation_m() * SG_METER_TO_FEET; +} + +void +FGEnvironmentMgr::set_cloud_layer_elevation_ft (int index, double elevation_ft) +{ + thesky->get_cloud_layer(index) + ->setElevation_m(elevation_ft * SG_FEET_TO_METER); +} + +double +FGEnvironmentMgr::get_cloud_layer_thickness_ft (int index) const +{ + return thesky->get_cloud_layer(index)->getThickness_m() * SG_METER_TO_FEET; +} + +void +FGEnvironmentMgr::set_cloud_layer_thickness_ft (int index, double thickness_ft) +{ + thesky->get_cloud_layer(index) + ->setThickness_m(thickness_ft * SG_FEET_TO_METER); +} + +double +FGEnvironmentMgr::get_cloud_layer_transition_ft (int index) const +{ + return thesky->get_cloud_layer(index)->getTransition_m() * SG_METER_TO_FEET; +} + +void +FGEnvironmentMgr::set_cloud_layer_transition_ft (int index, + double transition_ft) +{ + thesky->get_cloud_layer(index) + ->setTransition_m(transition_ft * SG_FEET_TO_METER); +} + +const char * +FGEnvironmentMgr::get_cloud_layer_type (int index) const +{ + switch (thesky->get_cloud_layer(index)->getType()) { + 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_CIRRUS: + return "cirrus"; + case SGCloudLayer::SG_CLOUD_CLEAR: + return "clear"; + default: + return "unknown"; + } } +void +FGEnvironmentMgr::set_cloud_layer_type (int index, const char * type_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; + else { + SG_LOG(SG_INPUT, SG_WARN, "Unknown cloud type " << type_name); + type = SGCloudLayer::SG_CLOUD_CLEAR; + } + thesky->get_cloud_layer(index)->setType(type); +} + + + // end of environment-mgr.cxx