Stuart Buchanan :
Attached is yet another 3D clouds patch, to fix the following: 1) The 3D clouds were not modified by the cloud coverage, due to some problems with osg::Switch 2) METAR changes to cloud coverage were not obeyed. 3) Making changes via the Cloud dialog had no effect unless 3D clouds were toggled. 4) Cloud cover was too sparse. 5) 3D Stratus clouds caused performance issues on some hardware (fixed by removing 3D stratus from cloudlayers.xml - it will now be a 2D layer).
This commit is contained in:
parent
35f7f55507
commit
b0b4ab5003
3 changed files with 47 additions and 35 deletions
|
@ -502,6 +502,7 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
|||
double aircraft_alt = fgGetDouble("/position/altitude-ft");
|
||||
char s[128];
|
||||
int i;
|
||||
bool rebuild_clouds = false;
|
||||
|
||||
for (i = 0, layer = layers.begin(); layer != layers_end; ++layer, i++) {
|
||||
double currentval;
|
||||
|
@ -517,8 +518,10 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
|||
snprintf(s, 128, cl, i);
|
||||
strncat(s, "/coverage", 128);
|
||||
const char* coverage = (*layer)->getStringValue("coverage", "clear");
|
||||
if (strncmp(fgGetString(s), coverage, 128) != 0)
|
||||
if (strncmp(fgGetString(s), coverage, 128) != 0) {
|
||||
fgSetString(s, coverage);
|
||||
rebuild_clouds = true;
|
||||
}
|
||||
|
||||
snprintf(s, 128, cl, i);
|
||||
strncat(s, "/elevation-ft", 128);
|
||||
|
@ -567,6 +570,10 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
|||
}
|
||||
}
|
||||
|
||||
if (rebuild_clouds) {
|
||||
// Force an update of the 3D clouds
|
||||
fgSetDouble("/environment/rebuild-layers", 1.0);
|
||||
}
|
||||
} else {
|
||||
// We haven't already loaded a METAR, so apply it immediately.
|
||||
dir_from = fgGetDouble("/environment/metar/base-wind-range-from");
|
||||
|
|
|
@ -51,7 +51,6 @@ FGClouds::FGClouds(FGEnvironmentCtrl * controller) :
|
|||
station_elevation_ft(0.0),
|
||||
_controller( controller ),
|
||||
snd_lightning(NULL),
|
||||
rebuild_required(true),
|
||||
last_scenario( "unset" ),
|
||||
last_env_config( new SGPropertyNode() ),
|
||||
last_env_clouds( new SGPropertyNode() )
|
||||
|
@ -78,8 +77,6 @@ void FGClouds::init(void) {
|
|||
soundMgr->add( snd_lightning, "thunder" );
|
||||
sgEnviro.set_soundMgr( soundMgr );
|
||||
}
|
||||
|
||||
rebuild_required = true;
|
||||
}
|
||||
|
||||
void FGClouds::buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, const string& name, sgVec3 pos, SGCloudField *layer) {
|
||||
|
@ -157,20 +154,19 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
|||
int CloudVarietyCount = 0;
|
||||
double totalCount = 0.0;
|
||||
|
||||
if (! clouds_3d_enabled) return;
|
||||
|
||||
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
|
||||
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
|
||||
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
|
||||
SGCloudField *layer = thesky->get_cloud_layer(iLayer)->get_layer3D();
|
||||
|
||||
layer->clear();
|
||||
|
||||
// when we don't generate clouds the layer is rendered in 2D
|
||||
if( coverage == 0.0 )
|
||||
return;
|
||||
if( layer_def_root == NULL || cloud_def_root == NULL || box_def_root == NULL)
|
||||
if ((! clouds_3d_enabled) || coverage == 0.0 ||
|
||||
layer_def_root == NULL || cloud_def_root == NULL || box_def_root == NULL)
|
||||
{
|
||||
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(false);
|
||||
return;
|
||||
}
|
||||
|
||||
SGPropertyNode *layer_def=NULL;
|
||||
|
||||
|
@ -181,8 +177,11 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
|||
layer_def = layer_def_root->getChild(base_name.c_str());
|
||||
}
|
||||
if( !layer_def )
|
||||
{
|
||||
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
double grid_x_size = layer_def->getDoubleValue("grid-x-size", 1000.0);
|
||||
double grid_y_size = layer_def->getDoubleValue("grid-y-size", 1000.0);
|
||||
|
@ -217,22 +216,31 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
|||
double x = px + grid_x_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
||||
double y = py + grid_y_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
||||
double z = grid_z_rand * (sg_random() - 0.5);
|
||||
|
||||
if (sg_random() < coverage)
|
||||
{
|
||||
double choice = sg_random();
|
||||
|
||||
for(int i = 0; i < CloudVarietyCount ; i ++) {
|
||||
choice -= tCloudVariety[i].count * totalCount;
|
||||
if( choice <= 0.0 ) {
|
||||
sgVec3 pos={x,z,y};
|
||||
buildCloud(cloud_def_root, box_def_root, tCloudVariety[i].name, pos, layer);
|
||||
|
||||
buildCloud(cloud_def_root,
|
||||
box_def_root,
|
||||
tCloudVariety[i].name,
|
||||
pos,
|
||||
layer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now we've built any clouds, enable them and set the density (coverage)
|
||||
layer->setCoverage(coverage);
|
||||
layer->applyCoverage();
|
||||
//layer->setCoverage(coverage);
|
||||
//layer->applyCoverage();
|
||||
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(clouds_3d_enabled);
|
||||
}
|
||||
|
||||
|
@ -282,7 +290,7 @@ void FGClouds::buildCloudLayers(void) {
|
|||
} else if( alt_ft > 6500 ) {
|
||||
// layer_type = "as|ac|ns";
|
||||
layer_type = "ac";
|
||||
if( pressure_mb < 1005.0 && coverage_norm >= 5.5 )
|
||||
if( pressure_mb < 1005.0 && coverage_norm >= 0.5 )
|
||||
layer_type = "ns";
|
||||
} else {
|
||||
// layer_type = "st|cu|cb|sc";
|
||||
|
@ -492,8 +500,8 @@ void FGClouds::buildScenario( const string& scenario ) {
|
|||
void FGClouds::build() {
|
||||
string scenario = fgGetString("/environment/weather-scenario", "METAR");
|
||||
|
||||
if(!rebuild_required && (scenario == last_scenario))
|
||||
return;
|
||||
// if(!rebuild_required && (scenario == last_scenario))
|
||||
// return;
|
||||
|
||||
if( last_scenario == "none" ) {
|
||||
// save clouds and weather conditions
|
||||
|
@ -536,7 +544,6 @@ void FGClouds::build() {
|
|||
}
|
||||
|
||||
last_scenario = scenario;
|
||||
rebuild_required = false;
|
||||
|
||||
if( snd_lightning == NULL )
|
||||
init();
|
||||
|
@ -556,7 +563,6 @@ void FGClouds::set_3dClouds(bool enable)
|
|||
}
|
||||
|
||||
if (enable) {
|
||||
rebuild_required = true;
|
||||
build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,12 +55,13 @@ void buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, co
|
|||
|
||||
void update_env_config ();
|
||||
|
||||
void build(void);
|
||||
|
||||
int update_event;
|
||||
SGSoundSample *snd_lightning;
|
||||
FGEnvironmentCtrl * _controller;
|
||||
float station_elevation_ft;
|
||||
bool clouds_3d_enabled;
|
||||
bool rebuild_required;
|
||||
string last_scenario;
|
||||
SGPropertyNode *last_env_config, *last_env_clouds;
|
||||
|
||||
|
@ -68,8 +69,6 @@ public:
|
|||
FGClouds(FGEnvironmentCtrl * controller);
|
||||
~FGClouds();
|
||||
|
||||
void build(void);
|
||||
|
||||
void init(void);
|
||||
|
||||
int get_update_event(void) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue