From 6c6452c62b28e11153e2f52750efa35eff938977 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 24 Sep 2012 00:03:23 +0100 Subject: [PATCH] Adapt to revised SGTime API Convert SGTime users to pass SGGeod/SGPath instead of raw values. --- src/Environment/magvarmanager.cxx | 1 + src/Environment/metarproperties.cxx | 6 ++--- src/Instrumentation/dclgps.cxx | 12 ++++----- src/Instrumentation/dclgps.hxx | 3 --- src/Main/options.cxx | 4 +-- src/Time/TimeManager.cxx | 42 ++++++++++------------------- src/Time/TimeManager.hxx | 3 --- src/Time/sunsolver.cxx | 16 +++++------ src/Time/sunsolver.hxx | 5 ++-- 9 files changed, 33 insertions(+), 59 deletions(-) diff --git a/src/Environment/magvarmanager.cxx b/src/Environment/magvarmanager.cxx index 726ba4983..ed02b651f 100644 --- a/src/Environment/magvarmanager.cxx +++ b/src/Environment/magvarmanager.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include
#include
diff --git a/src/Environment/metarproperties.cxx b/src/Environment/metarproperties.cxx index aa67b355a..944307b01 100644 --- a/src/Environment/metarproperties.cxx +++ b/src/Environment/metarproperties.cxx @@ -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() ); } } diff --git a/src/Instrumentation/dclgps.cxx b/src/Instrumentation/dclgps.cxx index 855dfc425..aeeb54fdc 100644 --- a/src/Instrumentation/dclgps.cxx +++ b/src/Instrumentation/dclgps.cxx @@ -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)); } diff --git a/src/Instrumentation/dclgps.hxx b/src/Instrumentation/dclgps.hxx index 9037e97f1..1eeadfd67 100644 --- a/src/Instrumentation/dclgps.hxx +++ b/src/Instrumentation/dclgps.hxx @@ -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 _messageStack; virtual void CreateFlightPlan(GPSFlightPlan* fp, std::vector ids, std::vector wps); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 844c8ea68..d8a48a9a9 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -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(); diff --git a/src/Time/TimeManager.cxx b/src/Time/TimeManager.cxx index 3a3cde1a0..91d47bbe4 100644 --- a/src/Time/TimeManager.cxx +++ b/src/Time/TimeManager.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include
#include
@@ -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; diff --git a/src/Time/TimeManager.hxx b/src/Time/TimeManager.hxx index b710a75ce..9eb40980b 100644 --- a/src/Time/TimeManager.hxx +++ b/src/Time/TimeManager.hxx @@ -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; diff --git a/src/Time/sunsolver.cxx b/src/Time/sunsolver.cxx index b37112816..cc8a64e8f 100644 --- a/src/Time/sunsolver.cxx +++ b/src/Time/sunsolver.cxx @@ -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 diff --git a/src/Time/sunsolver.hxx b/src/Time/sunsolver.hxx index 8c98812dc..16d312231 100644 --- a/src/Time/sunsolver.hxx +++ b/src/Time/sunsolver.hxx @@ -36,6 +36,8 @@ #include +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 ); -- 2.39.5