1
0
Fork 0

use safer and faster property methods instead of creating property

paths via snprintf+strncat+absolute paths every time (more to come)
This commit is contained in:
mfranz 2009-05-12 20:51:02 +00:00 committed by Tim Moore
parent b87e8ba3ee
commit 3700a42783
2 changed files with 76 additions and 120 deletions

View file

@ -861,14 +861,12 @@ void
FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
{
int i;
double d;
char s[128];
fgSetString("/environment/metar/real-metar", m->getData());
// don't update with real weather when we use a custom weather scenario
const char *current_scenario = fgGetString("/environment/weather-scenario", "METAR");
if( strcmp(current_scenario, "METAR") && strcmp(current_scenario, "none"))
return;
// don't update with real weather when we use a custom weather scenario
const char *current_scenario = fgGetString("/environment/weather-scenario", "METAR");
if (strcmp(current_scenario, "METAR") && strcmp(current_scenario, "none"))
return;
fgSetString("/environment/metar/last-metar", m->getData());
fgSetString("/environment/metar/station-id", m->getId());
fgSetDouble("/environment/metar/min-visibility-m",
@ -876,17 +874,15 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
fgSetDouble("/environment/metar/max-visibility-m",
m->getMaxVisibility().getVisibility_m() );
SGPropertyNode *metar = fgGetNode("/environment/metar", true);
const SGMetarVisibility *dirvis = m->getDirVisibility();
for (i = 0; i < 8; i++, dirvis++) {
const char *min = "/environment/metar/visibility[%d]/min-m";
const char *max = "/environment/metar/visibility[%d]/max-m";
SGPropertyNode *vis = metar->getChild("visibility", i, true);
double v = dirvis->getVisibility_m();
d = dirvis->getVisibility_m();
snprintf(s, 128, min, i);
fgSetDouble(s, d);
snprintf(s, 128, max, i);
fgSetDouble(s, d);
vis->setDoubleValue("min-m", v);
vis->setDoubleValue("max-m", v);
}
fgSetInt("/environment/metar/base-wind-range-from",
@ -907,51 +903,34 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
m->getPressure_inHg() );
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::const_iterator cloud;
vector<SGMetarCloud>::const_iterator cloud, cloud_end = cv.end();
const char *cl = "/environment/metar/clouds/layer[%i]";
for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
const char *coverage_string[5] =
{ "clear", "few", "scattered", "broken", "overcast" };
const double thickness[5] = { 0, 65, 600,750, 1000};
int q;
SGPropertyNode *metar_clouds = fgGetNode("/environment/metar/clouds", true);
snprintf(s, 128, cl, i);
strncat(s, "/coverage", 128);
q = cloud->getCoverage();
fgSetString(s, coverage_string[q] );
for (i = 0, cloud = cv.begin(); i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
const char *coverage_string[5] = { "clear", "few", "scattered", "broken", "overcast" };
const double thickness_value[5] = { 0, 65, 600, 750, 1000 };
snprintf(s, 128, cl, i);
strncat(s, "/elevation-ft", 128);
fgSetDouble(s, cloud->getAltitude_ft() + station_elevation_ft);
const char *coverage = "clear";
double elevation = -9999.0;
double thickness = 0.0;
const double span = 40000.0;
snprintf(s, 128, cl, i);
strncat(s, "/thickness-ft", 128);
fgSetDouble(s, thickness[q]);
if (cloud != cloud_end) {
int c = cloud->getCoverage();
coverage = coverage_string[c];
elevation = cloud->getAltitude_ft() + station_elevation_ft;
thickness = thickness_value[c];
++cloud;
}
snprintf(s, 128, cl, i);
strncat(s, "/span-m", 128);
fgSetDouble(s, 40000.0);
SGPropertyNode *layer;
layer = metar_clouds->getChild("layer", i, true);
layer->setStringValue("coverage", coverage);
layer->setDoubleValue("elevation-ft", elevation);
layer->setDoubleValue("thickness-ft", thickness);
layer->setDoubleValue("span-m", span);
}
for (; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
snprintf(s, 128, cl, i);
strncat(s, "/coverage", 128);
fgSetString(s, "clear");
snprintf(s, 128, cl, i);
strncat(s, "/elevation-ft", 128);
fgSetDouble(s, -9999);
snprintf(s, 128, cl, i);
strncat(s, "/thickness-ft", 128);
fgSetDouble(s, 0);
snprintf(s, 128, cl, i);
strncat(s, "/span-m", 128);
fgSetDouble(s, 40000.0);
}
fgSetDouble("/environment/metar/rain-norm", m->getRain());
fgSetDouble("/environment/metar/hail-norm", m->getHail());
fgSetDouble("/environment/metar/snow-norm", m->getSnow());

View file

@ -48,13 +48,13 @@ extern SGSky *thesky;
FGClouds::FGClouds(FGEnvironmentCtrl * controller) :
station_elevation_ft(0.0),
_controller( controller ),
snd_lightning(NULL),
snd_lightning(0),
_controller(controller),
station_elevation_ft(0.0),
clouds_3d_enabled(false),
last_scenario( "unset" ),
last_env_config( new SGPropertyNode() ),
last_env_clouds( new SGPropertyNode() )
last_env_config( new SGPropertyNode ),
last_env_clouds( new SGPropertyNode )
{
update_event = 0;
}
@ -252,8 +252,8 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
void FGClouds::buildCloudLayers(void) {
SGPropertyNode *metar_root = fgGetNode("/environment", true);
double wind_speed_kt = metar_root->getDoubleValue("wind-speed-kt");
//double wind_speed_kt = metar_root->getDoubleValue("wind-speed-kt");
double temperature_degc = metar_root->getDoubleValue("temperature-sea-level-degc");
double dewpoint_degc = metar_root->getDoubleValue("dewpoint-sea-level-degc");
double pressure_mb = metar_root->getDoubleValue("pressure-sea-level-inhg") * SG_INHG_TO_PA / 100.0;
@ -266,8 +266,6 @@ void FGClouds::buildCloudLayers(void) {
double cumulus_base = 122.0 * (temperature_degc - dewpoint_degc);
double stratus_base = 100.0 * (100.0 - rel_humidity) * SG_FEET_TO_METER;
bool cu_seen = false;
for(int iLayer = 0 ; iLayer < thesky->get_cloud_layer_count(); iLayer++) {
SGPropertyNode *cloud_root = fgGetNode("/environment/clouds/layer", iLayer, true);
@ -325,9 +323,6 @@ void
FGClouds::update_metar_properties( const FGMetar *m )
{
int i;
int j;
double d;
char s[128];
fgSetString("/environment/metar/station-id", m->getId());
fgSetDouble("/environment/metar/min-visibility-m",
@ -335,17 +330,15 @@ FGClouds::update_metar_properties( const FGMetar *m )
fgSetDouble("/environment/metar/max-visibility-m",
m->getMaxVisibility().getVisibility_m() );
SGPropertyNode *metar = fgGetNode("/environment/metar", true);
const SGMetarVisibility *dirvis = m->getDirVisibility();
for (i = 0; i < 8; i++, dirvis++) {
const char *min = "/environment/metar/visibility[%d]/min-m";
const char *max = "/environment/metar/visibility[%d]/max-m";
SGPropertyNode *vis = metar->getChild("visibility", i, true);
double v = dirvis->getVisibility_m();
d = dirvis->getVisibility_m();
snprintf(s, 128, min, i);
fgSetDouble(s, d);
snprintf(s, 128, max, i);
fgSetDouble(s, d);
vis->setDoubleValue("min-m", v);
vis->setDoubleValue("max-m", v);
}
fgSetInt("/environment/metar/base-wind-range-from",
@ -366,57 +359,41 @@ FGClouds::update_metar_properties( const FGMetar *m )
m->getPressure_inHg() );
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::const_iterator cloud;
vector<SGMetarCloud>::const_iterator cloud, cloud_end = cv.end();
// Load into both the METAR and environment properties to stop interpolation
const char *cl[] = {"/environment/metar/clouds/layer[%i]",
"/environment/clouds/layer[%i]"};
SGPropertyNode *metar_clouds = fgGetNode("/environment/metar/clouds", true);
SGPropertyNode *clouds = fgGetNode("/environment/clouds", true);
for (j = 0; j < 2; j++)
{
for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
const char *coverage_string[5] =
{ "clear", "few", "scattered", "broken", "overcast" };
const double thickness[5] = { 0, 65, 600,750, 1000};
int q;
snprintf(s, 128, cl[j], i);
strncat(s, "/coverage", 128);
q = cloud->getCoverage();
fgSetString(s, coverage_string[q] );
snprintf(s, 128, cl[j], i);
strncat(s, "/elevation-ft", 128);
fgSetDouble(s, cloud->getAltitude_ft() + station_elevation_ft);
snprintf(s, 128, cl[j], i);
strncat(s, "/thickness-ft", 128);
fgSetDouble(s, thickness[q]);
snprintf(s, 128, cl[j], i);
strncat(s, "/span-m", 128);
fgSetDouble(s, 40000.0);
}
for (; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
snprintf(s, 128, cl[j], i);
strncat(s, "/coverage", 128);
fgSetString(s, "clear");
snprintf(s, 128, cl[j], i);
strncat(s, "/elevation-ft", 128);
fgSetDouble(s, -9999);
snprintf(s, 128, cl[j], i);
strncat(s, "/thickness-ft", 128);
fgSetDouble(s, 0);
snprintf(s, 128, cl[j], i);
strncat(s, "/span-m", 128);
fgSetDouble(s, 40000.0);
for (i = 0, cloud = cv.begin(); i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
const char *coverage_string[5] = { "clear", "few", "scattered", "broken", "overcast" };
const double thickness_value[5] = { 0, 65, 600, 750, 1000 };
const char *coverage = "clear";
double elevation = -9999.0;
double thickness = 0.0;
const double span = 40000.0;
if (cloud != cloud_end) {
int c = cloud->getCoverage();
coverage = coverage_string[c];
elevation = cloud->getAltitude_ft() + station_elevation_ft;
thickness = thickness_value[c];
++cloud;
}
SGPropertyNode *layer;
layer = metar_clouds->getChild("layer", i, true);
layer->setStringValue("coverage", coverage);
layer->setDoubleValue("elevation-ft", elevation);
layer->setDoubleValue("thickness-ft", thickness);
layer->setDoubleValue("span-m", span);
layer = clouds->getChild("layer", i, true);
layer->setStringValue("coverage", coverage);
layer->setDoubleValue("elevation-ft", elevation);
layer->setDoubleValue("thickness-ft", thickness);
layer->setDoubleValue("span-m", span);
}
fgSetDouble("/environment/metar/rain-norm", m->getRain());