]> git.mxchange.org Git - flightgear.git/commitdiff
Use SGTime instead of time() in traffic/AI code
authorJames Turner <zakalawe@mac.com>
Wed, 6 Jan 2016 04:00:12 +0000 (22:00 -0600)
committerJames Turner <zakalawe@mac.com>
Wed, 6 Jan 2016 05:19:28 +0000 (23:19 -0600)
- avoids manual handling of /sim/time/warp in many places

src/AIModel/AIAircraft.cxx
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlanCreate.cxx
src/ATC/GroundController.cxx
src/ATC/trafficcontrol.cxx
src/Traffic/Schedule.cxx
src/Traffic/TrafficMgr.cxx

index 836550afb87eabe7b16d21ace358f3dc3ff21e15..3cb90a51c0d4e2953d9492326a4bc3b154f1e145 100644 (file)
@@ -1397,7 +1397,7 @@ time_t FGAIAircraft::checkForArrivalTime(const string& wptName) {
      } else {
          return 0;
      }
-     time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+     time_t now = globals->get_time_params()->get_cur_time();
      time_t arrivalTime = fp->getArrivalTime();
      
      time_t ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0); 
index dbfd06ee9d6eb4318806914afc0c560888e6807d..d9917227457f6679e36ae67ebaebadf898ec7025 100644 (file)
@@ -29,6 +29,7 @@
 #include <simgear/constants.h>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
@@ -192,7 +193,7 @@ void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
                                      const string& acType,
                                      const string& airline)
 {
-  time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+  time_t now = globals->get_time_params()->get_cur_time();
   time_t timeDiff = now-start;
   leg = 1;
   
index ae369d57b5c8fe73ae8384c706a9f945b5bf1f7d..b7a24ab1a2080a7c66f72c5179cc8be33f37fb0a 100644 (file)
@@ -29,6 +29,7 @@
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <Airports/airport.hxx>
 #include <Airports/runways.hxx>
@@ -694,7 +695,8 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
     double turnDistance = (2 * M_PI * initialTurnRadius) * (side / 360.0);
     time_t remaining =
         (turnDistance + distance) / ((vDescent * SG_NM_TO_METER) / 3600.0);
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+    time_t now = globals->get_time_params()->get_cur_time();
+
     //if (ac->getTrafficRef()->getCallSign() == fgGetString("/ai/track-callsign")) {
     //     cerr << "   Arrival time estimation: turn angle " <<  side << ". Turn distance " << turnDistance << ". Linear distance " << distance << ". Time to go " << remaining << endl;
     //     //exit(1);
index b3c11741d0baf997914a9714b3b489163f2b8b7d..d4b71f3dbafdb8ce080a772137962e83fa1f49cb 100644 (file)
@@ -42,6 +42,7 @@
 #include <simgear/scene/util/OsgMath.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/timing/timestamp.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <Airports/airport.hxx>
 #include <Airports/dynamics.hxx>
@@ -263,7 +264,8 @@ void FGGroundController::updateAircraftInformation(int id, double lat, double lo
     } else {
         current->setHoldPosition(true);
         int state = current->getState();
-        time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+        time_t now = globals->get_time_params()->get_cur_time();
+
         if ((now - lastTransmission) > 15) {
             available = true;
         }
@@ -467,7 +469,8 @@ void FGGroundController::checkHoldPosition(int id, double lat,
     } else {
         return;
     }
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+
+    time_t now = globals->get_time_params()->get_cur_time();
     if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
         SG_LOG(SG_GENERAL, SG_ALERT,
                "AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkHoldPosition at " << SG_ORIGIN);
@@ -778,7 +781,8 @@ void FGGroundController::render(bool visible)
         FGScenery * local_scenery = globals->get_scenery();
         // double elevation_meters = 0.0;
 //        double elevation_feet = 0.0;
-        time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+        time_t now = globals->get_time_params()->get_cur_time();
+
         //for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
         //double dx = 0;
 
@@ -951,7 +955,7 @@ string FGGroundController::getName() {
 
 void FGGroundController::update(double dt)
 {
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+    time_t now = globals->get_time_params()->get_cur_time();
     FGGroundNetwork* network = dynamics->getGroundNetwork();
     network->unblockAllSegments(now);
     int priority = 1;
index d2fc499e9acf1f1877946c225e20c08d80c1d780..0da90a6a882270232311a13aa04c4a3a5168536b 100644 (file)
@@ -36,6 +36,8 @@
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/material/mat.hxx>
 #include <simgear/scene/util/OsgMath.hxx>
+#include <simgear/timing/sg_time.hxx>
+
 #include <Scenery/scenery.hxx>
 
 #include "trafficcontrol.hxx"
@@ -132,7 +134,9 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
     estimatedArrivalTimes.push_back(newEta);
     sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
     // do some housekeeping : remove any timestamps that are past
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+
+    time_t now = globals->get_time_params()->get_cur_time();
+
     TimeVectorIterator i = estimatedArrivalTimes.begin();
     while (i != estimatedArrivalTimes.end()) {
         if ((*i) < now) {
@@ -431,7 +435,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
 
 bool FGTrafficRecord::isActive(int margin) const
 {
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+    time_t now = globals->get_time_params()->get_cur_time();
     time_t deptime = aircraft->getTrafficRef()->getDepartureTime();
     return ((now + margin) > deptime);
 }
@@ -1269,7 +1273,8 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
     // The user controlled aircraft should have crased here, because it doesn't have a traffic reference.
     // NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
     time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+    time_t now = globals->get_time_params()->get_cur_time();
+
     //cerr << i->getAircraft()->getTrafficRef()->getCallSign()
     //     << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
     //     << " at parking " << getGateName(i->getAircraft()) << endl;
@@ -1352,7 +1357,8 @@ void FGStartupController::render(bool visible)
 
         //for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
         double dx = 0;
-        time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+        time_t now = globals->get_time_params()->get_cur_time();
+
         for   (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
             if (i->isActive(300)) {
                 // Handle start point
index 01878ea269b0eff9849c364ac3b4b3be3b2992e7..09efa2deca879cc7b48a682ea9180189ac295e16 100644 (file)
@@ -44,6 +44,7 @@
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/xml/easyxml.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <AIModel/AIFlightPlan.hxx>
 #include <AIModel/AIManager.hxx>
@@ -557,7 +558,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
                                                       const string &req,
                                                      time_t min, time_t max)
 {
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+    time_t now = globals->get_time_params()->get_cur_time();
 
     FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
     FGScheduledFlightVecIterator fltBegin, fltEnd;
index 62a2de4e33a329e5e2f8e4ea69ace4b81d7122df..eeda08ac63b8a19fa405325221a38aa2dcbffc3f 100644 (file)
@@ -58,6 +58,7 @@
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <simgear/xml/easyxml.hxx>
 #include <simgear/threads/SGThread.hxx>
@@ -719,17 +720,19 @@ void FGTrafficManager::update(double dt)
         finishInit();
     }
         
-    time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+
     if (scheduledAircraft.empty()) {
         return;
     }
 
     SGVec3d userCart = globals->get_aircraft_position_cart();
-
+    
     if (currAircraft == scheduledAircraft.end()) {
         currAircraft = scheduledAircraft.begin();
     }
 
+    time_t now = globals->get_time_params()->get_cur_time();
+
     //cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
     if ((*currAircraft)->update(now, userCart)) {
         // schedule is done - process another aircraft in next iteration