From: James Turner Date: Thu, 31 Dec 2015 05:11:06 +0000 (-0600) Subject: Pull Ephemeris out of FGGlobals X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ba56c42eb43de0c0de69f2fcd1abff379eed819d;p=flightgear.git Pull Ephemeris out of FGGlobals --- diff --git a/src/Environment/ephemeris.cxx b/src/Environment/ephemeris.cxx index 612501c74..e11827b30 100644 --- a/src/Environment/ephemeris.cxx +++ b/src/Environment/ephemeris.cxx @@ -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()); } diff --git a/src/Environment/ephemeris.hxx b/src/Environment/ephemeris.hxx index 766cff734..82d67521a 100644 --- a/src/Environment/ephemeris.hxx +++ b/src/Environment/ephemeris.hxx @@ -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; diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index a1456872f..64232f96e 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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(); //////////////////////////////////////////////////////////////////// // Initialize the aircraft systems and instrumentation (before the diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index de3124dc4..ff86ee15b 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -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 ), diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 82dd12681..e08da9891 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -46,7 +46,6 @@ typedef std::vector 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 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 ); diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index be51ad4d1..015807320 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -102,6 +102,7 @@ #include #include #include +#include //#include
#include "viewer.hxx" @@ -1448,7 +1449,10 @@ FGRenderer::setupView( void ) setupRoot(); -// build the sky +// build the sky + Ephemeris* ephemerisSub = globals->get_subsystem(); + + // 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(); 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