]> git.mxchange.org Git - flightgear.git/commitdiff
Bugfix: Non-existent AIModels could trigger a request to load scenery tiles
authordurk <durk>
Sat, 11 Mar 2006 18:14:48 +0000 (18:14 +0000)
committerdurk <durk>
Sat, 11 Mar 2006 18:14:48 +0000 (18:14 +0000)
at (lon, lat) coordinates -1000,0. This patch fixes the AIModels/Traffic
Manager side of things. The AIModels subsystems allowed the creation of
AIAircraft with non-existent 3D models. If such a model didn't exist, the
aip class didn't get initialized, resulting in the above-mentioned bogus
position information. Here I circumvent this problem by a) only interacting
with the tile loader if the model is visible (and hence has succesfully been
initialized) and b) by disallowing the traffic manager to create AIAircraft
objects if the path to the 3D model doesn't exist.

src/AIModel/AIAircraft.cxx
src/Traffic/Schedule.cxx

index 2e465eea09a4bdb0e5d89ce8be30359a87a51f32..00bad5ebdd213af4aa644f071d5507bf0115c043 100644 (file)
@@ -926,48 +926,50 @@ void FGAIAircraft::getGroundElev(double dt) {
   //aip.getSGLocation()->set_tile_center(Point3D(buck.get_center_lon(), buck.get_center_lat(), 0.0));
   
   // Only do the proper hitlist stuff if we are within visible range of the viewer.
-  double visibility_meters = fgGetDouble("/environment/visibility-m"); 
-
-  FGViewer* vw = globals->get_current_view();
-  double 
-    course, 
-    distance;
-
-  //Point3D currView(vw->getLongitude_deg(), 
-  //              vw->getLatitude_deg(), 0.0);
-  SGWayPoint current  (pos.lon(),
-                      pos.lat(),
-                      0);
-  SGWayPoint view (   vw->getLongitude_deg(),
-                     vw->getLatitude_deg(),
-                     0);
-  view.CourseAndDistance(current, &course, &distance);
-  if(distance > visibility_meters) {
-    //aip.getSGLocation()->set_cur_elev_m(aptElev);
-    return;
-  }
-    
-  // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
-  double range = 500.0;
-  if (!globals->get_tile_mgr()->scenery_available(pos.lat(), pos.lon(), range))
-  {
-    // Try to shedule tiles for that position.
-    globals->get_tile_mgr()->update( aip.getSGLocation(), range );
-  }
-
-  // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
-  double alt;
-  if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
-                                              20000.0, alt))
-      tgt_altitude = alt * SG_METER_TO_FEET; 
-  //cerr << "Target altitude : " << tgt_altitude << endl;
-  // if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
-  //                                            20000.0, alt))
-  //    tgt_altitude = alt * SG_METER_TO_FEET;
-  //cerr << "Target altitude : " << tgt_altitude << endl;
+   if (!invisible) {
+     double visibility_meters = fgGetDouble("/environment/visibility-m");      
+     
+     
+     FGViewer* vw = globals->get_current_view();
+     double 
+       course, 
+       distance;
+     
+     //Point3D currView(vw->getLongitude_deg(), 
+     //                   vw->getLatitude_deg(), 0.0);
+     SGWayPoint current  (pos.lon(),
+                         pos.lat(),
+                         0);
+     SGWayPoint view (   vw->getLongitude_deg(),
+                        vw->getLatitude_deg(),
+                        0);
+     view.CourseAndDistance(current, &course, &distance);
+     if(distance > visibility_meters) {
+       //aip.getSGLocation()->set_cur_elev_m(aptElev);
+       return;
+     }
+     
+     // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
+     double range = 500.0;
+     if (!globals->get_tile_mgr()->scenery_available(pos.lat(), pos.lon(), range))
+       {
+        // Try to shedule tiles for that position.
+        globals->get_tile_mgr()->update( aip.getSGLocation(), range );
+       }
+     
+     // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
+     double alt;
+     if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
+                                                20000.0, alt))
+       tgt_altitude = alt * SG_METER_TO_FEET; 
+     //cerr << "Target altitude : " << tgt_altitude << endl;
+     // if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
+     //                                            20000.0, alt))
+     //    tgt_altitude = alt * SG_METER_TO_FEET;
+     //cerr << "Target altitude : " << tgt_altitude << endl;
+   }
 }
-
+   
 void FGAIAircraft::doGroundAltitude()
 {
   if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
index a33b45d11d718266c6e1ea6e4360647f7c0dd71f..9ac106e4023e52d298c8d54709c0d5c40c4cc390 100644 (file)
@@ -366,33 +366,40 @@ bool FGAISchedule::update(time_t now)
              //          alt = dep->_elevation+19;
              //        }
 
-             // Fixme: A non-existent model path results in an
-             // abort, due to an unhandled exeption, in fg main loop.
-              FGAIAircraft *aircraft = new FGAIAircraft(this);
-              aircraft->setPerformance(m_class); //"jet_transport";
-             aircraft->setCompany(airline); //i->getAirline();
-             aircraft->setAcType(acType); //i->getAcType();
-              aircraft->setPath(modelPath.c_str());
-              aircraft->setFlightPlan(flightPlanName);
-              aircraft->setLatitude(lat);
-              aircraft->setLongitude(lon);
-              aircraft->setAltitude(i->getCruiseAlt()*100); // convert from FL to feet
-              aircraft->setSpeed(speed);
-              aircraft->setBank(0);
-              aircraft->SetFlightPlan(new FGAIFlightPlan(modelPath, courseToDest, i->getDepartureTime(), dep, 
-                                                         arr,true, radius, i->getCruiseAlt()*100, lat, lon, speed, flightType, acType, airline));
-              aimgr->attach(aircraft);
-             
-
-             AIManagerRef = aircraft->getID();
-             //cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
-             //cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
-             //cerr << "Dep      : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
-             //cerr << "Arr      : " << arr->getLatitude()<< ", "<< arr->getLongitude() << endl;
-             //cerr << "Time remaining = " << (remainingTimeEnroute/3600.0) << endl;
-             //cerr << "Total time     = " << (totalTimeEnroute/3600.0) << endl;
-             //cerr << "Distance remaining = " << distanceToDest*SG_METER_TO_NM << endl;
-             
+             // Only allow traffic to be created when the model path exists
+             SGPath mp(globals->get_fg_root());
+             mp.append(modelPath);
+             if (mp.exists()) 
+             {
+                 FGAIAircraft *aircraft = new FGAIAircraft(this);
+                 aircraft->setPerformance(m_class); //"jet_transport";
+                 aircraft->setCompany(airline); //i->getAirline();
+                 aircraft->setAcType(acType); //i->getAcType();
+                 aircraft->setPath(modelPath.c_str());
+                 aircraft->setFlightPlan(flightPlanName);
+                 aircraft->setLatitude(lat);
+                 aircraft->setLongitude(lon);
+                 aircraft->setAltitude(i->getCruiseAlt()*100); // convert from FL to feet
+                 aircraft->setSpeed(speed);
+                 aircraft->setBank(0);
+                 aircraft->SetFlightPlan(new FGAIFlightPlan(modelPath, courseToDest, i->getDepartureTime(), dep, 
+                                                            arr,true, radius, i->getCruiseAlt()*100, lat, lon, speed, flightType, acType, airline));
+                 aimgr->attach(aircraft);
+                 
+                 
+                 AIManagerRef = aircraft->getID();
+                 //cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
+                 //cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
+                 //cerr << "Dep      : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
+                 //cerr << "Arr      : " << arr->getLatitude()<< ", "<< arr->getLongitude() << endl;
+                 //cerr << "Time remaining = " << (remainingTimeEnroute/3600.0) << endl;
+                 //cerr << "Total time     = " << (totalTimeEnroute/3600.0) << endl;
+                 //cerr << "Distance remaining = " << distanceToDest*SG_METER_TO_NM << endl;
+                 }
+             else
+               {
+                 SG_LOG(SG_INPUT, SG_WARN, "TrafficManager: Could not load model " << mp.str());
+               }
            }
          return true;
     }