]> git.mxchange.org Git - flightgear.git/commitdiff
Pull Ephemeris out of FGGlobals
authorJames Turner <zakalawe@mac.com>
Thu, 31 Dec 2015 05:11:06 +0000 (23:11 -0600)
committerJames Turner <zakalawe@mac.com>
Thu, 31 Dec 2015 21:19:51 +0000 (15:19 -0600)
src/Environment/ephemeris.cxx
src/Environment/ephemeris.hxx
src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Viewer/renderer.cxx

index 612501c74dca795f6e6d54c18c00f1ac91bb791e..e11827b30dc282dbdc2fd457934e2172b9329220 100644 (file)
@@ -41,7 +41,11 @@ Ephemeris::Ephemeris() :
 
 Ephemeris::~Ephemeris()
 {
-  delete _impl;
+}
+
+SGEphemeris* Ephemeris::data()
+{
+    return _impl;
 }
 
 void Ephemeris::init()
@@ -49,21 +53,26 @@ void Ephemeris::init()
   SGPath ephem_data_path(globals->get_fg_root());
   ephem_data_path.append("Astro");
   _impl = new SGEphemeris(ephem_data_path.c_str());
-  globals->set_ephem(_impl);
 
   tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
   tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
   tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
   tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
   tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
-  
-  _latProp = fgGetNode("/position/latitude-deg", true);
-  update(0.0);
+
+    _latProp = fgGetNode("/position/latitude-deg", true);
+
+    update(0.0);
+}
+
+void Ephemeris::shutdown()
+{
+    delete _impl;
+    _impl = NULL;
 }
 
 void Ephemeris::postinit()
 {
-  
 }
 
 void Ephemeris::bind()
@@ -72,10 +81,11 @@ void Ephemeris::bind()
 
 void Ephemeris::unbind()
 {
+    _latProp = 0;
 }
 
 void Ephemeris::update(double)
 {
-  SGTime* st = globals->get_time_params();
-  _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
+    SGTime* st = globals->get_time_params();
+    _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
 }
index 766cff7340c5139d0034b6e21ec0681f98941e1b..82d67521a6956bc723d2d3790454678cd31f0b87 100644 (file)
@@ -42,8 +42,12 @@ public:
        virtual void unbind();
        virtual void update(double dt);
        virtual void init();
-  virtual void postinit();
-  
+    virtual void shutdown();
+    virtual void postinit();
+
+    static const char* subsystemName() { return "ephemeris"; }
+
+    SGEphemeris* data();
 private:
   SGEphemeris* _impl;
   SGPropertyNode* _latProp;
index a1456872f9191286dc2c3ada29850616c73b099a..64232f96e3b7777735db891951cb6b0688e08529 100644 (file)
@@ -762,7 +762,7 @@ void fgCreateSubsystems(bool duringReset) {
 
     // Initialize the weather modeling subsystem
     globals->add_subsystem("environment", new FGEnvironmentMgr);
-    globals->add_subsystem("ephemeris", new Ephemeris);
+    globals->add_new_subsystem<Ephemeris>();
     
     ////////////////////////////////////////////////////////////////////
     // Initialize the aircraft systems and instrumentation (before the
index de3124dc418eee55881176d3c516339a25a0990e..ff86ee15bd9779626fc94876bb830327b3afdad4 100644 (file)
@@ -157,7 +157,6 @@ FGGlobals::FGGlobals() :
     fg_root( "" ),
     fg_home( "" ),
     time_params( NULL ),
-    ephem( NULL ),
     commands( SGCommandMgr::instance() ),
     channel_options_list( NULL ),
     initial_waypoints( NULL ),
index 82dd12681ff03050be786207911c88bb46907b40..e08da98918f17a5929d08a4df9185444243e8075 100644 (file)
@@ -46,7 +46,6 @@ typedef std::vector<SGPath> PathList;
 // pointers, we don't need to know anything about the class details
 // anyway.
 
-class SGEphemeris;
 class SGCommandMgr;
 class SGMaterialLib;
 class SGPropertyNode;
@@ -114,9 +113,6 @@ private:
     // Time structure
     SGTime *time_params;
 
-    // Sky structures
-    SGEphemeris *ephem;
-
     // Material properties library
     SGSharedPtr<SGMaterialLib> matlib;
 
@@ -289,9 +285,6 @@ public:
     inline SGTime *get_time_params() const { return time_params; }
     inline void set_time_params( SGTime *t ) { time_params = t; }
 
-    inline SGEphemeris *get_ephem() const { return ephem; }
-    inline void set_ephem( SGEphemeris *e ) { ephem = e; }
-
     inline SGMaterialLib *get_matlib() const { return matlib; }
     void set_matlib( SGMaterialLib *m );
 
index be51ad4d158f398409a2d3bd75cf88abc01c9efc..0158073202d6e566aed1746ca358fcf3093de237 100644 (file)
 #include <Instrumentation/HUD/HUD.hxx>
 #include <Environment/precipitation_mgr.hxx>
 #include <Environment/environment_mgr.hxx>
+#include <Environment/ephemeris.hxx>
 
 //#include <Main/main.hxx>
 #include "viewer.hxx"
@@ -1448,7 +1449,10 @@ FGRenderer::setupView( void )
 
     setupRoot();
   
-// build the sky    
+// build the sky
+    Ephemeris* ephemerisSub = globals->get_subsystem<Ephemeris>();
+
+
     // The sun and moon diameters are scaled down numbers of the
     // actual diameters. This was needed to fit both the sun and the
     // moon within the distance to the far clip plane.
@@ -1459,7 +1463,7 @@ FGRenderer::setupView( void )
     opt->setPropertyNode(globals->get_props());
     _sky->build( 80000.0, 80000.0,
                   463.3, 361.8,
-                  *globals->get_ephem(),
+                  *ephemerisSub->data(),
                   fgGetNode("/environment", true),
                   opt.get());
     
@@ -1685,6 +1689,8 @@ FGRenderer::updateSky()
     } else {
         sun_horiz_eff = moon_horiz_eff = 1.0;
     }
+
+
     
     SGSkyState sstate;
     sstate.pos       = globals->get_current_view()->getViewPosition();
@@ -1703,10 +1709,11 @@ FGRenderer::updateSky()
     scolor.cloud_color = SGVec3f(l->cloud_color().data());
     scolor.sun_angle   = l->get_sun_angle();
     scolor.moon_angle  = l->get_moon_angle();
-    
+
+    Ephemeris* ephemerisSub = globals->get_subsystem<Ephemeris>();
     double delta_time_sec = _sim_delta_sec->getDoubleValue();
-    _sky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
-    _sky->repaint( scolor, *globals->get_ephem() );
+    _sky->reposition( sstate, *ephemerisSub->data(), delta_time_sec );
+    _sky->repaint( scolor, *ephemerisSub->data() );
 }
                                     
 void