1
0
Fork 0

Wrap SGEphemeris in a subsytem/property interface, and remove from mainloop.

This commit is contained in:
James Turner 2010-06-12 17:08:04 +02:00 committed by James Turner
parent 3fbf3aa080
commit 4756cd4882
7 changed files with 116 additions and 22 deletions

View file

@ -3485,6 +3485,14 @@
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"

View 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

View file

@ -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());
}

View file

@ -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

View 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;

View 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;

View file

@ -31,10 +31,10 @@
#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);