Bugfix: Non-existent AIModels could trigger a request to load scenery tiles
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.
This commit is contained in:
parent
9aaac1e352
commit
f8eb3d4309
2 changed files with 77 additions and 68 deletions
|
@ -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));
|
//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.
|
// Only do the proper hitlist stuff if we are within visible range of the viewer.
|
||||||
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
if (!invisible) {
|
||||||
|
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
||||||
|
|
||||||
FGViewer* vw = globals->get_current_view();
|
|
||||||
double
|
FGViewer* vw = globals->get_current_view();
|
||||||
course,
|
double
|
||||||
distance;
|
course,
|
||||||
|
distance;
|
||||||
//Point3D currView(vw->getLongitude_deg(),
|
|
||||||
// vw->getLatitude_deg(), 0.0);
|
//Point3D currView(vw->getLongitude_deg(),
|
||||||
SGWayPoint current (pos.lon(),
|
// vw->getLatitude_deg(), 0.0);
|
||||||
pos.lat(),
|
SGWayPoint current (pos.lon(),
|
||||||
0);
|
pos.lat(),
|
||||||
SGWayPoint view ( vw->getLongitude_deg(),
|
0);
|
||||||
vw->getLatitude_deg(),
|
SGWayPoint view ( vw->getLongitude_deg(),
|
||||||
0);
|
vw->getLatitude_deg(),
|
||||||
view.CourseAndDistance(current, &course, &distance);
|
0);
|
||||||
if(distance > visibility_meters) {
|
view.CourseAndDistance(current, &course, &distance);
|
||||||
//aip.getSGLocation()->set_cur_elev_m(aptElev);
|
if(distance > visibility_meters) {
|
||||||
return;
|
//aip.getSGLocation()->set_cur_elev_m(aptElev);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
|
||||||
double range = 500.0;
|
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
||||||
if (!globals->get_tile_mgr()->scenery_available(pos.lat(), pos.lon(), range))
|
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 );
|
// 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;
|
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
||||||
if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
|
double alt;
|
||||||
20000.0, alt))
|
if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
|
||||||
tgt_altitude = alt * SG_METER_TO_FEET;
|
20000.0, alt))
|
||||||
//cerr << "Target altitude : " << tgt_altitude << endl;
|
tgt_altitude = alt * SG_METER_TO_FEET;
|
||||||
// if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
|
//cerr << "Target altitude : " << tgt_altitude << endl;
|
||||||
// 20000.0, alt))
|
// if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
|
||||||
// tgt_altitude = alt * SG_METER_TO_FEET;
|
// 20000.0, alt))
|
||||||
//cerr << "Target altitude : " << tgt_altitude << endl;
|
// tgt_altitude = alt * SG_METER_TO_FEET;
|
||||||
|
//cerr << "Target altitude : " << tgt_altitude << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIAircraft::doGroundAltitude()
|
void FGAIAircraft::doGroundAltitude()
|
||||||
{
|
{
|
||||||
if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
|
if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
|
||||||
|
|
|
@ -366,33 +366,40 @@ bool FGAISchedule::update(time_t now)
|
||||||
// alt = dep->_elevation+19;
|
// alt = dep->_elevation+19;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Fixme: A non-existent model path results in an
|
// Only allow traffic to be created when the model path exists
|
||||||
// abort, due to an unhandled exeption, in fg main loop.
|
SGPath mp(globals->get_fg_root());
|
||||||
FGAIAircraft *aircraft = new FGAIAircraft(this);
|
mp.append(modelPath);
|
||||||
aircraft->setPerformance(m_class); //"jet_transport";
|
if (mp.exists())
|
||||||
aircraft->setCompany(airline); //i->getAirline();
|
{
|
||||||
aircraft->setAcType(acType); //i->getAcType();
|
FGAIAircraft *aircraft = new FGAIAircraft(this);
|
||||||
aircraft->setPath(modelPath.c_str());
|
aircraft->setPerformance(m_class); //"jet_transport";
|
||||||
aircraft->setFlightPlan(flightPlanName);
|
aircraft->setCompany(airline); //i->getAirline();
|
||||||
aircraft->setLatitude(lat);
|
aircraft->setAcType(acType); //i->getAcType();
|
||||||
aircraft->setLongitude(lon);
|
aircraft->setPath(modelPath.c_str());
|
||||||
aircraft->setAltitude(i->getCruiseAlt()*100); // convert from FL to feet
|
aircraft->setFlightPlan(flightPlanName);
|
||||||
aircraft->setSpeed(speed);
|
aircraft->setLatitude(lat);
|
||||||
aircraft->setBank(0);
|
aircraft->setLongitude(lon);
|
||||||
aircraft->SetFlightPlan(new FGAIFlightPlan(modelPath, courseToDest, i->getDepartureTime(), dep,
|
aircraft->setAltitude(i->getCruiseAlt()*100); // convert from FL to feet
|
||||||
arr,true, radius, i->getCruiseAlt()*100, lat, lon, speed, flightType, acType, airline));
|
aircraft->setSpeed(speed);
|
||||||
aimgr->attach(aircraft);
|
aircraft->setBank(0);
|
||||||
|
aircraft->SetFlightPlan(new FGAIFlightPlan(modelPath, courseToDest, i->getDepartureTime(), dep,
|
||||||
|
arr,true, radius, i->getCruiseAlt()*100, lat, lon, speed, flightType, acType, airline));
|
||||||
AIManagerRef = aircraft->getID();
|
aimgr->attach(aircraft);
|
||||||
//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;
|
AIManagerRef = aircraft->getID();
|
||||||
//cerr << "Arr : " << arr->getLatitude()<< ", "<< arr->getLongitude() << endl;
|
//cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
|
||||||
//cerr << "Time remaining = " << (remainingTimeEnroute/3600.0) << endl;
|
//cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
|
||||||
//cerr << "Total time = " << (totalTimeEnroute/3600.0) << endl;
|
//cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
|
||||||
//cerr << "Distance remaining = " << distanceToDest*SG_METER_TO_NM << 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue