Wrap SGEphemeris in a subsytem/property interface, and remove from mainloop.
This commit is contained in:
parent
3fbf3aa080
commit
4756cd4882
7 changed files with 116 additions and 22 deletions
|
@ -3485,6 +3485,14 @@
|
||||||
RelativePath="..\..\..\src\Environment\ridge_lift.hxx"
|
RelativePath="..\..\..\src\Environment\ridge_lift.hxx"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\Environment\ephemeris.cxx"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\Environment\ephemeris.hxx"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="Lib_Model"
|
Name="Lib_Model"
|
||||||
|
|
|
@ -12,6 +12,7 @@ libEnvironment_a_SOURCES = \
|
||||||
fgwind.cxx fgwind.hxx \
|
fgwind.cxx fgwind.hxx \
|
||||||
atmosphere.cxx atmosphere.hxx \
|
atmosphere.cxx atmosphere.hxx \
|
||||||
precipitation_mgr.cxx precipitation_mgr.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
|
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
|
||||||
|
|
62
src/Environment/ephemeris.cxx
Normal file
62
src/Environment/ephemeris.cxx
Normal 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());
|
||||||
|
}
|
31
src/Environment/ephemeris.hxx
Normal file
31
src/Environment/ephemeris.hxx
Normal 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
|
||||||
|
|
|
@ -131,7 +131,6 @@ FGGlobals::~FGGlobals()
|
||||||
delete subsystem_mgr;
|
delete subsystem_mgr;
|
||||||
delete event_mgr;
|
delete event_mgr;
|
||||||
delete time_params;
|
delete time_params;
|
||||||
delete ephem;
|
|
||||||
delete mag;
|
delete mag;
|
||||||
delete matlib;
|
delete matlib;
|
||||||
delete route_mgr;
|
delete route_mgr;
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
#include <osgDB/Registry>
|
#include <osgDB/Registry>
|
||||||
|
|
||||||
// Class references
|
// Class references
|
||||||
#include <simgear/ephemeris/ephemeris.hxx>
|
|
||||||
#include <simgear/scene/model/modellib.hxx>
|
#include <simgear/scene/model/modellib.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/model/animation.hxx>
|
#include <simgear/scene/model/animation.hxx>
|
||||||
|
@ -71,6 +70,7 @@
|
||||||
#include <ATCDCL/AIMgr.hxx>
|
#include <ATCDCL/AIMgr.hxx>
|
||||||
#include <Time/tmp.hxx>
|
#include <Time/tmp.hxx>
|
||||||
#include <Environment/environment_mgr.hxx>
|
#include <Environment/environment_mgr.hxx>
|
||||||
|
#include <Environment/ephemeris.hxx>
|
||||||
#include <GUI/new_gui.hxx>
|
#include <GUI/new_gui.hxx>
|
||||||
#include <MultiPlayer/multiplaymgr.hxx>
|
#include <MultiPlayer/multiplaymgr.hxx>
|
||||||
|
|
||||||
|
@ -182,12 +182,6 @@ void fgUpdateTimeDepCalcs() {
|
||||||
} else {
|
} else {
|
||||||
// do nothing, fdm isn't inited yet
|
// 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 ) {
|
} else if ( idle_state == 6 ) {
|
||||||
idle_state++;
|
idle_state++;
|
||||||
// Initialize the sky
|
// Initialize the sky
|
||||||
SGPath ephem_data_path( globals->get_fg_root() );
|
|
||||||
ephem_data_path.append( "Astro" );
|
Ephemeris* eph = new Ephemeris;
|
||||||
SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
|
globals->add_subsystem("ephmeris", eph);
|
||||||
ephem->update( globals->get_time_params()->getMjd(),
|
eph->init(); // FIXME - remove this once SGSky code below is also a subsystem
|
||||||
globals->get_time_params()->getLst(),
|
|
||||||
0.0 );
|
|
||||||
globals->set_ephem( ephem );
|
|
||||||
|
|
||||||
// TODO: move to environment mgr
|
// TODO: move to environment mgr
|
||||||
thesky = new SGSky;
|
thesky = new SGSky;
|
||||||
|
|
|
@ -31,10 +31,10 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include <simgear/math/SGMath.hxx>
|
#include <simgear/math/SGMath.hxx>
|
||||||
#include <simgear/ephemeris/ephemeris.hxx>
|
|
||||||
#include <simgear/timing/sg_time.hxx>
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
#include "tmp.hxx"
|
#include "tmp.hxx"
|
||||||
#include "sunsolver.hxx"
|
#include "sunsolver.hxx"
|
||||||
|
@ -56,12 +56,14 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
|
||||||
double alpha, delta;
|
double alpha, delta;
|
||||||
double tmp;
|
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 r = globals->get_ephem()->get_sun()->getDistance();
|
||||||
double xs = globals->get_ephem()->get_sun()->getxs();
|
double xs = sun->getDoubleValue("xs");
|
||||||
double ys = globals->get_ephem()->get_sun()->getys();
|
double ys = sun->getDoubleValue("ys");
|
||||||
double ye = globals->get_ephem()->get_sun()->getye();
|
double ye = sun->getDoubleValue("ye");
|
||||||
double ze = globals->get_ephem()->get_sun()->getze();
|
double ze = sun->getDoubleValue("ze");
|
||||||
alpha = atan2(ys - tan(beta)*ze/ys, xs);
|
alpha = atan2(ys - tan(beta)*ze/ys, xs);
|
||||||
delta = asin(sin(beta)*ye/ys + cos(beta)*ze);
|
delta = asin(sin(beta)*ye/ys + cos(beta)*ze);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue