]> git.mxchange.org Git - flightgear.git/commitdiff
Support disabling AI traffic at run-time.
authorThorstenB <brehmt@gmail.com>
Tue, 1 May 2012 08:32:30 +0000 (10:32 +0200)
committerThorstenB <brehmt@gmail.com>
Tue, 1 May 2012 08:32:30 +0000 (10:32 +0200)
src/Traffic/Schedule.cxx
src/Traffic/TrafficMgr.cxx
src/Traffic/TrafficMgr.hxx

index 5f1dc9f31e6c8f5ea893ffd3cf9bac01b8c4becc..017e2b0d5766151047b31202a03ea8ae3019265f 100644 (file)
@@ -158,6 +158,15 @@ FGAISchedule::FGAISchedule(const FGAISchedule &other)
 
 FGAISchedule::~FGAISchedule()
 {
+    // remove related object from AI manager
+    if (AIManagerRef)
+    {
+        FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
+        if (aimgr)
+            aimgr->destroyObject(AIManagerRef);
+        AIManagerRef = 0;
+    }
+
 /*  for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
     {
       delete (*flt);
index bfcb732fd309f3436aea11d52acc177043ce681d..0f9dbc0b3f2606a9b49a549b622441d1398d3ac5 100644 (file)
@@ -90,6 +90,11 @@ FGTrafficManager::FGTrafficManager() :
 }
 
 FGTrafficManager::~FGTrafficManager()
+{
+    shutdown();
+}
+
+void FGTrafficManager::shutdown()
 {
     // Save the heuristics data
     bool saveData = false;
@@ -129,6 +134,11 @@ FGTrafficManager::~FGTrafficManager()
     }
     scheduledAircraft.clear();
     flights.clear();
+    releaseList.clear();
+
+    currAircraft = scheduledAircraft.begin();
+    doingInit = false;
+    inited = false;
 }
 
 
@@ -261,7 +271,14 @@ void FGTrafficManager::loadHeuristics()
 
 void FGTrafficManager::update(double /*dt */ )
 {
-    if (!enabled || (realWxEnabled && !metarValid)) {
+    if (!enabled)
+    {
+        if (inited || doingInit)
+            shutdown();
+        return;
+    }
+
+    if ((realWxEnabled && !metarValid)) {
         return;
     }
 
index aab3c8ae3ea6799ccb243aa366158f183e093493..f417a95cfbe6414ce5a71c0614de5c3925c60c1f 100644 (file)
@@ -108,6 +108,7 @@ private:
   
   void initStep();
   void finishInit();
+  void shutdown();
   
   // during incremental init, contains the XML files still be read in
   simgear::PathList schedulesToRead;