]> git.mxchange.org Git - flightgear.git/commitdiff
Wrap SGEphemeris in a subsytem/property interface, and remove from mainloop.
authorJames Turner <jmt@Dulux.local>
Sat, 12 Jun 2010 15:08:04 +0000 (17:08 +0200)
committerJames Turner <zakalawe@mac.com>
Sat, 26 Jun 2010 09:31:21 +0000 (10:31 +0100)
projects/VC90/FlightGear/FlightGear.vcproj
src/Environment/Makefile.am
src/Environment/ephemeris.cxx [new file with mode: 0644]
src/Environment/ephemeris.hxx [new file with mode: 0644]
src/Main/globals.cxx
src/Main/main.cxx
src/Time/sunsolver.cxx

index 7661650cfd1ea435e8fa3b66ea96f19950e2e339..ce1edc9823965e0af190a86c1cfbac5d54d68142 100644 (file)
                                RelativePath="..\..\..\src\Environment\ridge_lift.hxx"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\src\Environment\ephemeris.cxx"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\src\Environment\ephemeris.hxx"
+                               >
+                       </File>
                </Filter>
                <Filter
                        Name="Lib_Model"
index a39d0ec3cbe2f779934cb6b7089e6a42884460a5..6c7ee1f5190e25fdf753db13129a1b3d23de0772 100644 (file)
@@ -12,6 +12,7 @@ libEnvironment_a_SOURCES = \
        fgwind.cxx fgwind.hxx \
        atmosphere.cxx atmosphere.hxx \
        precipitation_mgr.cxx precipitation_mgr.hxx \
-       ridge_lift.cxx ridge_lift.hxx
+       ridge_lift.cxx ridge_lift.hxx \
+       ephemeris.cxx ephemeris.hxx 
 
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
diff --git a/src/Environment/ephemeris.cxx b/src/Environment/ephemeris.cxx
new file mode 100644 (file)
index 0000000..a6a1f5c
--- /dev/null
@@ -0,0 +1,62 @@
+#include <Environment/ephemeris.hxx>
+
+#include <simgear/timing/sg_time.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
+
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+
+Ephemeris::Ephemeris() :
+  _impl(NULL),
+  _latProp(NULL)
+{
+}
+
+Ephemeris::~Ephemeris()
+{
+  delete _impl;
+}
+
+void Ephemeris::init()
+{
+  if (_impl) {
+    return;
+  }
+  
+  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);
+}
+
+void Ephemeris::postinit()
+{
+  update(0.0);
+}
+
+static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
+{
+  fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
+} 
+
+void Ephemeris::bind()
+{
+  _latProp = fgGetNode("/position/latitude-deg", true);
+  
+  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);
+}
+
+void Ephemeris::unbind()
+{
+}
+
+void Ephemeris::update(double)
+{
+  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
new file mode 100644 (file)
index 0000000..3a03de5
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef FG_ENVIRONMENT_EPHEMERIS_HXX
+#define FG_ENVIRONMENT_EPHEMERIS_HXX
+
+#include <simgear/structure/subsystem_mgr.hxx>
+
+class SGEphemeris;
+class SGPropertyNode;
+
+/**
+ * Wrap SGEphemeris in a susbsytem/property interface
+ */
+class Ephemeris : public SGSubsystem
+{
+public:
+
+       Ephemeris();
+       ~Ephemeris();           
+       
+       virtual void bind();
+       virtual void unbind();
+       virtual void update(double dt);
+       virtual void init();
+  virtual void postinit();
+  
+private:
+  SGEphemeris* _impl;
+  SGPropertyNode* _latProp;
+};
+
+#endif // of FG_ENVIRONMENT_EPHEMERIS_HXX
+
index da3de6a46beeba1fabe72597bd86356dde77e94a..1ae7c81d22fbb110104ff988720a128e5a32f72d 100644 (file)
@@ -131,7 +131,6 @@ FGGlobals::~FGGlobals()
     delete subsystem_mgr;
     delete event_mgr;
     delete time_params;
-    delete ephem;
     delete mag;
     delete matlib;
     delete route_mgr;
index 679c0e0b5901dcd6dc822485bf303fa3eee905db..edf2f84e4a0db5544ace018e994c69e0f317bd89 100644 (file)
@@ -41,7 +41,6 @@
 #include <osgDB/Registry>
 
 // Class references
-#include <simgear/ephemeris/ephemeris.hxx>
 #include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/model/animation.hxx>
@@ -71,6 +70,7 @@
 #include <ATCDCL/AIMgr.hxx>
 #include <Time/tmp.hxx>
 #include <Environment/environment_mgr.hxx>
+#include <Environment/ephemeris.hxx>
 #include <GUI/new_gui.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
 
@@ -182,12 +182,6 @@ void fgUpdateTimeDepCalcs() {
     } else {
         // do nothing, fdm isn't inited yet
     }
-
-    // Update solar system
-    globals->get_ephem()->update( globals->get_time_params()->getMjd(),
-                                  globals->get_time_params()->getLst(),
-                                  cur_fdm_state->get_Latitude() );
-
 }
 
 
@@ -715,13 +709,10 @@ static void fgIdleFunction ( void ) {
     } else if ( idle_state == 6 ) {
         idle_state++;
         // Initialize the sky
-        SGPath ephem_data_path( globals->get_fg_root() );
-        ephem_data_path.append( "Astro" );
-        SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
-        ephem->update( globals->get_time_params()->getMjd(),
-                       globals->get_time_params()->getLst(),
-                       0.0 );
-        globals->set_ephem( ephem );
+
+        Ephemeris* eph = new Ephemeris;
+        globals->add_subsystem("ephmeris", eph);
+        eph->init(); // FIXME - remove this once SGSky code below is also a subsystem
 
         // TODO: move to environment mgr
         thesky = new SGSky;
index 504de90817387a90011ab97e38eb8fe1085790e9..cdb53a6bfe43d99539d7d9ffa565fbdce7e5f9f5 100644 (file)
 #include <ctime>
 
 #include <simgear/math/SGMath.hxx>
-#include <simgear/ephemeris/ephemeris.hxx>
 #include <simgear/timing/sg_time.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
 
 #include "tmp.hxx"
 #include "sunsolver.hxx"
@@ -56,12 +56,14 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
     double alpha, delta;
     double tmp;
 
-    double beta = globals->get_ephem()->get_sun()->getLat();
+    SGPropertyNode* sun = fgGetNode("/ephemeris/sun");
+    assert(sun);
+    double beta = sun->getDoubleValue("lat-deg");
     // double r = globals->get_ephem()->get_sun()->getDistance();
-    double xs = globals->get_ephem()->get_sun()->getxs();
-    double ys = globals->get_ephem()->get_sun()->getys();
-    double ye = globals->get_ephem()->get_sun()->getye();
-    double ze = globals->get_ephem()->get_sun()->getze();
+    double xs = sun->getDoubleValue("xs");
+    double ys = sun->getDoubleValue("ys");
+    double ye = sun->getDoubleValue("ye");
+    double ze = sun->getDoubleValue("ze");
     alpha = atan2(ys - tan(beta)*ze/ys, xs);
     delta = asin(sin(beta)*ye/ys + cos(beta)*ze);