Adapt to revised SGTime API
Convert SGTime users to pass SGGeod/SGPath instead of raw values.
This commit is contained in:
parent
66a6438de1
commit
6c6452c62b
9 changed files with 33 additions and 59 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <simgear/sg_inlines.h>
|
||||
#include <simgear/magvar/magvar.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
|
|
@ -88,10 +88,8 @@ inline void MagneticVariation::recalc( double lon, double lat, double alt )
|
|||
_lat = lat;
|
||||
_alt = alt;
|
||||
|
||||
lon *= SGD_DEGREES_TO_RADIANS;
|
||||
lat *= SGD_DEGREES_TO_RADIANS;
|
||||
alt *= SG_FEET_TO_METER;
|
||||
_time.update( lon, lat, 0, 0 );
|
||||
SGGeod location(SGGeod::fromDegFt(lon, lat, alt));
|
||||
_time.update( location, 0, 0 );
|
||||
update( lon, lat, alt, _time.getJD() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,9 +206,7 @@ DCLGPS::DCLGPS(RenderArea2D* instrument) {
|
|||
// Configuration Initialisation
|
||||
// Should this be in kln89.cxx ?
|
||||
_turnAnticipationEnabled = false;
|
||||
|
||||
_time = new SGTime;
|
||||
|
||||
|
||||
_messageStack.clear();
|
||||
|
||||
_dto = false;
|
||||
|
@ -221,7 +219,6 @@ DCLGPS::DCLGPS(RenderArea2D* instrument) {
|
|||
}
|
||||
|
||||
DCLGPS::~DCLGPS() {
|
||||
delete _time;
|
||||
delete _approachFP; // Don't need to delete the waypoints inside since they point to
|
||||
// the waypoints in the approach database.
|
||||
// TODO - may need to delete the approach database!!
|
||||
|
@ -305,7 +302,6 @@ void DCLGPS::update(double dt) {
|
|||
_elapsedTime += dt;
|
||||
}
|
||||
|
||||
_time->update(_gpsLon * SG_DEGREES_TO_RADIANS, _gpsLat * SG_DEGREES_TO_RADIANS, 0, 0);
|
||||
// FIXME - currently all the below assumes leg mode and no DTO or OBS cancelled.
|
||||
if(_activeFP->IsEmpty()) {
|
||||
// Not sure if we need to reset these each update or only when fp altered
|
||||
|
@ -1443,7 +1439,8 @@ double DCLGPS::GetMagHeadingFromTo(double latA, double lonA, double latB, double
|
|||
h *= SG_RADIANS_TO_DEGREES;
|
||||
// TODO - use the real altitude below instead of 0.0!
|
||||
//cout << "MagVar = " << sgGetMagVar(_gpsLon, _gpsLat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES << '\n';
|
||||
h -= sgGetMagVar(_gpsLon, _gpsLat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES;
|
||||
double jd = globals->get_time_params()->getJD();
|
||||
h -= sgGetMagVar(_gpsLon, _gpsLat, 0.0, jd) * SG_RADIANS_TO_DEGREES;
|
||||
while(h >= 360.0) h -= 360.0;
|
||||
while(h < 0.0) h += 360.0;
|
||||
return(h);
|
||||
|
@ -1525,7 +1522,8 @@ double DCLGPS::GetGreatCircleCourse (double lat1, double lon1, double lat2, doub
|
|||
// Return a position on a radial from wp1 given distance d (nm) and magnetic heading h (degrees)
|
||||
// Note that d should be less that 1/4 Earth diameter!
|
||||
GPSWaypoint DCLGPS::GetPositionOnMagRadial(const GPSWaypoint& wp1, double d, double h) {
|
||||
h += sgGetMagVar(wp1.lon, wp1.lat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES;
|
||||
double jd = globals->get_time_params()->getJD();
|
||||
h += sgGetMagVar(wp1.lon, wp1.lat, 0.0, jd) * SG_RADIANS_TO_DEGREES;
|
||||
return(GetPositionOnRadial(wp1, d, h));
|
||||
}
|
||||
|
||||
|
|
|
@ -435,9 +435,6 @@ protected:
|
|||
// Configuration that affects flightplan operation
|
||||
bool _turnAnticipationEnabled;
|
||||
|
||||
// Magvar stuff. Might get some of this stuff (such as time) from FG in future.
|
||||
SGTime* _time;
|
||||
|
||||
std::list<std::string> _messageStack;
|
||||
|
||||
virtual void CreateFlightPlan(GPSFlightPlan* fp, std::vector<std::string> ids, std::vector<GPSWpType> wps);
|
||||
|
|
|
@ -410,8 +410,8 @@ parse_date( const string& date, const char* timeType)
|
|||
int year,month,day,hour,minute,second;
|
||||
char *argument, *date_str;
|
||||
|
||||
SGTime CurrentTime = SGTime();
|
||||
CurrentTime.update(0,0,0,0);
|
||||
SGTime CurrentTime;
|
||||
CurrentTime.update(SGGeod(),0,0);
|
||||
|
||||
// FIXME This should obtain system/aircraft/GMT time depending on timeType
|
||||
pCurrentTime = CurrentTime.getGmt();
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/timing/lowleveltime.h>
|
||||
#include <simgear/structure/commands.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
|
@ -83,15 +84,10 @@ void TimeManager::init()
|
|||
|
||||
_warpDelta = fgGetNode("/sim/time/warp-delta", true);
|
||||
|
||||
_longitudeDeg = fgGetNode("/position/longitude-deg", true);
|
||||
_latitudeDeg = fgGetNode("/position/latitude-deg", true);
|
||||
|
||||
SGPath zone(globals->get_fg_root());
|
||||
zone.append("Timezone");
|
||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
|
||||
_impl = new SGTime(lon, lat, zone.str(), _timeOverride->getLongValue());
|
||||
_impl = new SGTime(globals->get_aircraft_position(), zone, _timeOverride->getLongValue());
|
||||
|
||||
_warpDelta->setIntValue(0);
|
||||
|
||||
|
@ -99,7 +95,7 @@ void TimeManager::init()
|
|||
&TimeManager::updateLocalTime, 30*60 );
|
||||
updateLocalTime();
|
||||
|
||||
_impl->update(lon, lat, _timeOverride->getLongValue(),
|
||||
_impl->update(globals->get_aircraft_position(), _timeOverride->getLongValue(),
|
||||
_warp->getIntValue());
|
||||
globals->set_time_params(_impl);
|
||||
|
||||
|
@ -145,9 +141,7 @@ void TimeManager::valueChanged(SGPropertyNode* aProp)
|
|||
_adjustWarpOnUnfreeze = false;
|
||||
}
|
||||
|
||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
_impl->update(lon, lat,
|
||||
_impl->update(globals->get_aircraft_position(),
|
||||
_timeOverride->getLongValue(),
|
||||
_warp->getIntValue());
|
||||
}
|
||||
|
@ -253,9 +247,7 @@ void TimeManager::update(double dt)
|
|||
}
|
||||
|
||||
_lastClockFreeze = freeze;
|
||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
_impl->update(lon, lat,
|
||||
_impl->update(globals->get_aircraft_position(),
|
||||
_timeOverride->getLongValue(),
|
||||
_warp->getIntValue());
|
||||
|
||||
|
@ -294,12 +286,7 @@ void TimeManager::updateLocalTime()
|
|||
{
|
||||
SGPath zone(globals->get_fg_root());
|
||||
zone.append("Timezone");
|
||||
|
||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "updateLocal(" << lon << ", " << lat << ", " << zone.str() << ")");
|
||||
_impl->updateLocal(lon, lat, zone.str());
|
||||
_impl->updateLocal(globals->get_aircraft_position(), zone.str());
|
||||
}
|
||||
|
||||
void TimeManager::initTimeOffset()
|
||||
|
@ -321,26 +308,25 @@ void TimeManager::setTimeOffset(const std::string& offset_type, long int offset)
|
|||
sgTimeGetGMT( fgLocaltime(&cur_time, _impl->get_zonename() ) );
|
||||
|
||||
// Okay, we now have several possible scenarios
|
||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||
SGGeod loc = globals->get_aircraft_position();
|
||||
int warp = 0;
|
||||
|
||||
if ( offset_type == "real" ) {
|
||||
warp = 0;
|
||||
} else if ( offset_type == "dawn" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 90.0, true );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 90.0, true );
|
||||
} else if ( offset_type == "morning" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 75.0, true );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 75.0, true );
|
||||
} else if ( offset_type == "noon" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 0.0, true );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 0.0, true );
|
||||
} else if ( offset_type == "afternoon" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 75.0, false );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 75.0, false );
|
||||
} else if ( offset_type == "dusk" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 90.0, false );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 90.0, false );
|
||||
} else if ( offset_type == "evening" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 100.0, false );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 100.0, false );
|
||||
} else if ( offset_type == "midnight" ) {
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 180.0, false );
|
||||
warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 180.0, false );
|
||||
} else if ( offset_type == "system-offset" ) {
|
||||
warp = offset;
|
||||
orig_warp = 0;
|
||||
|
|
|
@ -78,9 +78,6 @@ private:
|
|||
bool _lastClockFreeze;
|
||||
bool _adjustWarpOnUnfreeze;
|
||||
|
||||
SGPropertyNode_ptr _longitudeDeg;
|
||||
SGPropertyNode_ptr _latitudeDeg;
|
||||
|
||||
// frame-rate / worst-case latency / update-rate counters
|
||||
SGPropertyNode_ptr _frameRate;
|
||||
SGPropertyNode_ptr _frameRateWorst;
|
||||
|
|
|
@ -73,8 +73,7 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
|
|||
*lat = dec;
|
||||
}
|
||||
|
||||
static double sun_angle( const SGTime &t, const SGVec3d& world_up,
|
||||
double lon_rad, double lat_rad ) {
|
||||
static double sun_angle( const SGTime &t, const SGVec3d& world_up) {
|
||||
SG_LOG( SG_EVENT, SG_DEBUG, " Updating Sun position" );
|
||||
SG_LOG( SG_EVENT, SG_DEBUG, " Gst = " << t.getGst() );
|
||||
|
||||
|
@ -117,15 +116,12 @@ static double sun_angle( const SGTime &t, const SGVec3d& world_up,
|
|||
* when the sun angle is 90 and ascending.
|
||||
*/
|
||||
time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
|
||||
double lon_rad,
|
||||
double lat_rad,
|
||||
const SGGeod& loc,
|
||||
double target_angle_deg,
|
||||
bool ascending )
|
||||
{
|
||||
// cout << "location = " << lon_rad * SG_RADIANS_TO_DEGREES << ", "
|
||||
// << lat_rad * SG_RADIANS_TO_DEGREES << endl;
|
||||
SGVec3d world_up = SGVec3d::fromGeod(SGGeod::fromRad(lon_rad, lat_rad));
|
||||
SGTime t = SGTime( lon_rad, lat_rad, "", 0 );
|
||||
SGVec3d world_up = SGVec3d::fromGeod(loc);
|
||||
SGTime t = SGTime( loc, SGPath(), 0 );
|
||||
|
||||
double best_diff = 180.0;
|
||||
double last_angle = -99999.0;
|
||||
|
@ -135,8 +131,8 @@ time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
|
|||
secs < cur_time + half_day_secs;
|
||||
secs += step_secs )
|
||||
{
|
||||
t.update( lon_rad, lat_rad, secs, 0 );
|
||||
double angle_deg = sun_angle( t, world_up, lon_rad, lat_rad );
|
||||
t.update( loc, secs, 0 );
|
||||
double angle_deg = sun_angle( t, world_up );
|
||||
double diff = fabs( angle_deg - target_angle_deg );
|
||||
if ( diff < best_diff ) {
|
||||
if ( last_angle <= 180.0 && ascending
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
class SGGeod;
|
||||
|
||||
/**
|
||||
* Given the current unix time in seconds, calculate seconds to the
|
||||
* specified sun angle (relative to straight up.) Also specify if we
|
||||
|
@ -45,8 +47,7 @@
|
|||
* when the sun angle is 90 and ascending.
|
||||
*/
|
||||
time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
|
||||
double lon_rad,
|
||||
double lat_rad,
|
||||
const SGGeod& loc,
|
||||
double target_angle_deg,
|
||||
bool ascending );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue