From: durk Date: Sat, 11 Mar 2006 18:14:48 +0000 (+0000) Subject: Bugfix: Non-existent AIModels could trigger a request to load scenery tiles X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f8eb3d430972884181e11c886ffe86b598e1ef1e;p=flightgear.git 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. --- diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 2e465eea0..00bad5ebd 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -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) diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index a33b45d11..9ac106e40 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -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; }