]> git.mxchange.org Git - flightgear.git/commitdiff
Adapt to revised SGTime API
authorJames Turner <zakalawe@mac.com>
Sun, 23 Sep 2012 23:03:23 +0000 (00:03 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 23 Sep 2012 23:03:23 +0000 (00:03 +0100)
Convert SGTime users to pass SGGeod/SGPath instead of raw values.

src/Environment/magvarmanager.cxx
src/Environment/metarproperties.cxx
src/Instrumentation/dclgps.cxx
src/Instrumentation/dclgps.hxx
src/Main/options.cxx
src/Time/TimeManager.cxx
src/Time/TimeManager.hxx
src/Time/sunsolver.cxx
src/Time/sunsolver.hxx

index 726ba4983d7402cdf05eb155a86da10e897ffa8b..ed02b651f9d055c8b15dd803a6f0f8245b4fa152 100644 (file)
@@ -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>
index aa67b355a7b8fa9bfadcfb6a08c8f6ff0322e8ba..944307b0169825e7e3afdbeb89a193d0aae35b8e 100644 (file)
@@ -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() );
   }
 }
index 855dfc425763e7813b7624ccab254c0cead0f415..aeeb54fdc9534b322257aa15cb68e39b5b090dcd 100644 (file)
@@ -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));
 }
 
index 9037e97f15d56d1237578a20899852ee61d65077..1eeadfd6760107e2ef63983ed5a2aea0faa1f695 100644 (file)
@@ -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);
index 844c8ea68caee9ffe4cae9f7f2fe18e3b0f125f3..d8a48a9a905ab5dc3f97034a341cae4e01eb5db0 100644 (file)
@@ -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();
index 3a3cde1a04f277a3b653b3bb513b33713e8ef6fe..91d47bbe4c2e2255275b0e96e4e06771be179982 100644 (file)
@@ -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;
index b710a75cee6708e692ec6d11de37736d640074f2..9eb40980be2f013f8b0da1d59fa036928edec194 100644 (file)
@@ -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;
index b37112816282f1e061219139f600a770087b47ad..cc8a64e8f266fd2c58598dc60e0e0209fa556682 100644 (file)
@@ -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
index 8c98812dccd4c31465c533f85486d1c497d75a82..16d312231e4d4e0f3949665a328dfa84378c6e5e 100644 (file)
@@ -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 );