X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIAircraft.cxx;h=8d7df9225d226ff4ea0b9035f6c2528fec413671;hb=5ec5c34255d2488d5a7b255cf9c95520eccf3ac5;hp=ac79b97cc7f19aaad3f854f075d9c06be9bc3284;hpb=e168260a4f7c5c3c076ba98991d809354d3816c5;p=flightgear.git diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index ac79b97cc..8d7df9225 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,7 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) : FGAIBase(otAircraft) { holdPos = false; needsTaxiClearance = false; + _needsGroundElevation = true; _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB dt = 0; @@ -178,6 +180,8 @@ void FGAIAircraft::checkVisibility() void FGAIAircraft::AccelTo(double speed) { tgt_speed = speed; + if (!isStationary()) + _needsGroundElevation = true; } @@ -333,7 +337,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) { use_perf_vs = true; } } - tgt_speed = prev->speed; + AccelTo(prev->speed); hdg_lock = alt_lock = true; no_roll = prev->on_ground; } @@ -402,6 +406,8 @@ bool FGAIAircraft::loadNextLeg(double distance) { void FGAIAircraft::getGroundElev(double dt) { dt_elev_count += dt; + if (!needGroundElevation()) + return; // Update minimally every three secs, but add some randomness // to prevent all AI objects doing this in synchrony if (dt_elev_count < (3.0) + (rand() % 10)) @@ -419,20 +425,26 @@ void FGAIAircraft::getGroundElev(double dt) { } double range = 500.0; - if (!globals->get_tile_mgr()->scenery_available(pos, range)) { - // Try to shedule tiles for that position. - globals->get_tile_mgr()->update( pos, range ); + if (globals->get_tile_mgr()->schedule_scenery(pos, range, 5.0)) + { + double alt; + if (getGroundElevationM(SGGeod::fromGeodM(pos, 20000), alt, 0)) + { + tgt_altitude_ft = alt * SG_METER_TO_FEET; + if (isStationary()) + { + // aircraft is stationary and we obtained altitude for this spot - we're done. + _needsGroundElevation = false; + } + } } - - double alt; - if (getGroundElevationM(SGGeod::fromGeodM(pos, 20000), alt, 0)) - tgt_altitude_ft = alt * SG_METER_TO_FEET; } } void FGAIAircraft::doGroundAltitude() { - if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0) + if ((fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)|| + (isStationary())) altitude_ft = (tgt_altitude_ft + groundOffset); else altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft); @@ -602,6 +614,7 @@ void FGAIAircraft::handleFirstWaypoint() { Transform(); // make sure aip is initialized. getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value doGroundAltitude(); + _needsGroundElevation = true; // check ground elevation again (maybe scenery wasn't available yet) } // Make sure to announce the aircraft's position announcePositionToController(); @@ -648,7 +661,7 @@ bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) { // << dist_to_go << ": Lead distance " // << lead_dist << " " << curr->name // << " Ground target speed " << groundTargetSpeed << endl; - double bearing; + double bearing = 0; if (speed > 50) { // don't do bearing calculations for ground traffic bearing = getBearing(fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)); if (bearing < minBearing) {