Stuart Buchanan :
It fixes the following issues (to a greater or lesser extent): 1) Performance. Quad trees used to improve culling, and the sprites are placed on the surface of a sphere rather than randomly throughout the cloud, requiring fewer textures. This saves about 5-10fps on my machine. 2) Disabled 3D clouds have no performance impact. Previously they were still in the scenegraph. Now they are removed. 3) Clouds are now loaded on start-up, and don't require the scenario to be changed, they also work with METAR. 4) The cloud field is shifted as you travel. There's a small bug in that the clouds "jump" as you reach the edge of the field. 5) Iterative sorting of sprites. This doesn't appear to solve the alpha blending problem completely, but may help a bit.
This commit is contained in:
parent
78d3763b41
commit
7b547acbf9
3 changed files with 83 additions and 43 deletions
|
@ -182,9 +182,9 @@ FGEnvironmentMgr::bind ()
|
||||||
&FGEnvironmentMgr::set_cloud_layer_coverage);
|
&FGEnvironmentMgr::set_cloud_layer_coverage);
|
||||||
fgSetArchivable(buf);
|
fgSetArchivable(buf);
|
||||||
}
|
}
|
||||||
fgTie("/sim/rendering/clouds3d-enable", thesky,
|
fgTie("/sim/rendering/clouds3d-enable", fgClouds,
|
||||||
&SGSky::get_3dClouds,
|
&FGClouds::get_3dClouds,
|
||||||
&SGSky::set_3dClouds);
|
&FGClouds::set_3dClouds);
|
||||||
fgTie("/sim/rendering/clouds3d-density", thesky,
|
fgTie("/sim/rendering/clouds3d-density", thesky,
|
||||||
&SGSky::get_3dCloudDensity,
|
&SGSky::get_3dCloudDensity,
|
||||||
&SGSky::set_3dCloudDensity);
|
&SGSky::set_3dCloudDensity);
|
||||||
|
|
|
@ -51,6 +51,7 @@ FGClouds::FGClouds(FGEnvironmentCtrl * controller) :
|
||||||
station_elevation_ft(0.0),
|
station_elevation_ft(0.0),
|
||||||
_controller( controller ),
|
_controller( controller ),
|
||||||
snd_lightning(NULL),
|
snd_lightning(NULL),
|
||||||
|
rebuild_required(true),
|
||||||
last_scenario( "none" ),
|
last_scenario( "none" ),
|
||||||
last_env_config( new SGPropertyNode() ),
|
last_env_config( new SGPropertyNode() ),
|
||||||
last_env_clouds( new SGPropertyNode() )
|
last_env_clouds( new SGPropertyNode() )
|
||||||
|
@ -78,6 +79,8 @@ void FGClouds::init(void) {
|
||||||
soundMgr->add( snd_lightning, "thunder" );
|
soundMgr->add( snd_lightning, "thunder" );
|
||||||
sgEnviro.set_soundMgr( soundMgr );
|
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) {
|
void FGClouds::buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, const string& name, sgVec3 pos, SGCloudField *layer) {
|
||||||
|
@ -154,6 +157,8 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
||||||
int CloudVarietyCount = 0;
|
int CloudVarietyCount = 0;
|
||||||
double totalCount = 0.0;
|
double totalCount = 0.0;
|
||||||
|
|
||||||
|
if (! clouds_3d_enabled) return;
|
||||||
|
|
||||||
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
|
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
|
||||||
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
|
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
|
||||||
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
|
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
|
||||||
|
@ -231,7 +236,7 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we've built any clouds, enable them
|
// Now we've built any clouds, enable them
|
||||||
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(thesky->get_3dClouds());
|
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(clouds_3d_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:call this after real metar updates
|
// TODO:call this after real metar updates
|
||||||
|
@ -476,11 +481,14 @@ void FGClouds::buildScenario( const string& scenario ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FGClouds::build(void) {
|
void FGClouds::build() {
|
||||||
string scenario = fgGetString("/environment/weather-scenario", "METAR");
|
string scenario = fgGetString("/environment/weather-scenario", "METAR");
|
||||||
|
|
||||||
if( scenario == last_scenario)
|
if(!rebuild_required && (scenario == last_scenario))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( last_scenario == "none" ) {
|
if( last_scenario == "none" ) {
|
||||||
// save clouds and weather conditions
|
// save clouds and weather conditions
|
||||||
SGPropertyNode *param = fgGetNode("/environment/config", true);
|
SGPropertyNode *param = fgGetNode("/environment/config", true);
|
||||||
|
@ -515,9 +523,38 @@ void FGClouds::build(void) {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
buildScenario( scenario );
|
buildScenario( scenario );
|
||||||
|
|
||||||
last_scenario = scenario;
|
last_scenario = scenario;
|
||||||
|
rebuild_required = false;
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
if( snd_lightning == NULL )
|
if( snd_lightning == NULL )
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGClouds::set_3dClouds(bool enable)
|
||||||
|
{
|
||||||
|
if (enable != clouds_3d_enabled)
|
||||||
|
{
|
||||||
|
clouds_3d_enabled = enable;
|
||||||
|
|
||||||
|
for(int iLayer = 0 ; iLayer < thesky->get_cloud_layer_count(); iLayer++) {
|
||||||
|
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(enable);
|
||||||
|
|
||||||
|
if (!enable) {
|
||||||
|
thesky->get_cloud_layer(iLayer)->get_layer3D()->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
rebuild_required = true;
|
||||||
|
build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FGClouds::get_3dClouds() const {
|
||||||
|
return clouds_3d_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,8 @@ void buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, co
|
||||||
SGSoundSample *snd_lightning;
|
SGSoundSample *snd_lightning;
|
||||||
FGEnvironmentCtrl * _controller;
|
FGEnvironmentCtrl * _controller;
|
||||||
float station_elevation_ft;
|
float station_elevation_ft;
|
||||||
|
bool clouds_3d_enabled;
|
||||||
|
bool rebuild_required;
|
||||||
string last_scenario;
|
string last_scenario;
|
||||||
SGPropertyNode *last_env_config, *last_env_clouds;
|
SGPropertyNode *last_env_config, *last_env_clouds;
|
||||||
|
|
||||||
|
@ -72,7 +74,8 @@ public:
|
||||||
|
|
||||||
int get_update_event(void) const;
|
int get_update_event(void) const;
|
||||||
void set_update_event(int count);
|
void set_update_event(int count);
|
||||||
|
bool get_3dClouds() const;
|
||||||
|
void set_3dClouds(bool enable);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FGCLOUDS_HXX
|
#endif // _FGCLOUDS_HXX
|
||||||
|
|
Loading…
Reference in a new issue