]> git.mxchange.org Git - flightgear.git/commitdiff
Shift of management of the precipitation OSG scene graph to the scenery manager.
authorEdward d'Auvergne <edward@nmr-relax.com>
Tue, 3 May 2016 07:56:06 +0000 (09:56 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:34 +0000 (23:27 +0200)
The precipitation branch of the OSG scene graph is now centrally managed by the
scenery manager rather the precipitation manager itself.  The scene graph
initialisation from the constructor has also been shifted into the new
FGPrecipitationMgr::sceneGraphSetup() function.

src/Environment/precipitation_mgr.cxx
src/Environment/precipitation_mgr.hxx
src/Scenery/scenery.cxx
src/Scenery/scenery.hxx

index 9e83ab8529aeff365f7ce50939b5f6dfd17f16ef..ee48da79a53df051779129084417245928d05292 100644 (file)
  */
 FGPrecipitationMgr::FGPrecipitationMgr()
 {      
-    group = new osg::Group();
-    transform = new osg::MatrixTransform();
-    precipitation = new SGPrecipitation();
-
-
-    // By default, no precipitation
-    precipitation->setRainIntensity(0);
-    precipitation->setSnowIntensity(0);
-
-    // set the clip distance from the config
-    precipitation->setClipDistance(fgGetFloat("/environment/precipitation-control/clip-distance",5.0));
-    transform->addChild(precipitation->build());
-    group->addChild(transform.get());
+    // Try to set up the scenegraph.
+    setupSceneGraph();
 }
 
-
 /** 
  * @brief FGPrecipitaiton Manager destructor
  */
@@ -87,9 +75,6 @@ void FGPrecipitationMgr::init()
     osg::Matrix position(makeZUpFrame(geod));
     // Move the precipitation object to player position
     transform->setMatrix(position);
-    // Add to scene graph
-    osg::Group* scenery = globals->get_scenery()->get_scene_graph();
-    scenery->addChild(getObject());
     fgGetNode("environment/params/precipitation-level-ft", true);
 }
 
@@ -106,19 +91,29 @@ void FGPrecipitationMgr::unbind ()
   _tiedProperties.Untie();
 }
 
-void FGPrecipitationMgr::setPrecipitationLevel(double a)
+// Set up the precipitation manager scenegraph.
+void FGPrecipitationMgr::setupSceneGraph(void)
 {
-    fgSetDouble("environment/params/precipitation-level-ft",a);
+    FGScenery* scenery = globals->get_scenery();
+    osg::Group* group = scenery->get_precipitation_branch();
+    transform = new osg::MatrixTransform();
+    precipitation = new SGPrecipitation();
+
+
+    // By default, no precipitation
+    precipitation->setRainIntensity(0);
+    precipitation->setSnowIntensity(0);
+
+    // set the clip distance from the config
+    precipitation->setClipDistance(fgGetFloat("/environment/precipitation-control/clip-distance",5.0));
+    transform->addChild(precipitation->build());
+    group->addChild(transform.get());
 }
 
-/** 
- * @brief Get OSG precipitation object
- * 
- * @returns A pointer on the OSG object (osg::Group *)
- */
-osg::Group * FGPrecipitationMgr::getObject(void)
+
+void FGPrecipitationMgr::setPrecipitationLevel(double a)
 {
-    return this->group.get();
+    fgSetDouble("environment/params/precipitation-level-ft",a);
 }
 
 /** 
index 449f7f47c332a60bdc6c6a63e75d854c8550da08..3c3b8a6141951161b713287c57b9c056d8bcb30b 100644 (file)
@@ -36,7 +36,6 @@
 class FGPrecipitationMgr : public SGSubsystem
 {
 private:
-    osg::ref_ptr<osg::Group> group;
     osg::ref_ptr<osg::MatrixTransform> transform;
     osg::ref_ptr<SGPrecipitation> precipitation;
     float getPrecipitationAtAltitudeMax(void);
@@ -52,10 +51,8 @@ public:
     virtual void init ();
     virtual void update (double dt);
     
+    void setupSceneGraph(void);
     void setPrecipitationLevel(double l);
-
-    osg::Group * getObject(void);
-
 };
 
 #endif
index 48334337eeafc3216a85e1d032de8b2d0df3c8c7..b64c16d5ce92492304e179582069daa8b3e95420 100644 (file)
@@ -340,6 +340,11 @@ void FGScenery::init() {
     scene_graph->addChild(particles_branch.get());
     simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
   
+    // Set up the precipitation system.
+    precipitation_branch = new osg::Group;
+    precipitation_branch->setName("Precipitation");
+    scene_graph->addChild(precipitation_branch.get());
+
     _listener = new ScenerySwitchListener(this);
 
     // Toggle the setup flag.
@@ -353,6 +358,7 @@ void FGScenery::shutdown()
     models_branch = NULL;
     aircraft_branch = NULL;
     particles_branch = NULL;
+    precipitation_branch = NULL;
 
     // Toggle the setup flag.
     _inited = false;
index 55176ca55961a5cff351b60ae80a04c6b851a178..c4f8cec3679162fe119af9262c3df7e81935ef65 100644 (file)
@@ -57,6 +57,7 @@ class FGScenery : public SGSubsystem
     osg::ref_ptr<osg::Group> aircraft_branch;
     osg::ref_ptr<osg::Group> interior_branch;
     osg::ref_ptr<osg::Group> particles_branch;
+    osg::ref_ptr<osg::Group> precipitation_branch;
     
     osg::ref_ptr<flightgear::SceneryPager> _pager;
     ScenerySwitchListener* _listener;
@@ -117,6 +118,7 @@ public:
     osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
     osg::Group *get_interior_branch () const { return interior_branch.get(); }
     osg::Group *get_particles_branch () const { return particles_branch.get(); }
+    osg::Group *get_precipitation_branch () const { return precipitation_branch.get(); }
     
     /// Returns true if scenery is available for the given lat, lon position
     /// within a range of range_m.