From 36374829167da7c77bc0644d04ac87d07251ae88 Mon Sep 17 00:00:00 2001 From: jmt Date: Thu, 8 Oct 2009 21:08:07 +0000 Subject: [PATCH] Fix various route-manager issues - HUD display of waypoints, some potential divide-by-zeroes when paused or stationary, and Win32 compilation. --- src/Autopilot/route_mgr.cxx | 25 +++++++++++++++++++++---- src/Cockpit/hud.cxx | 4 +++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index daf9697de..b8903685f 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -27,6 +27,10 @@ # include #endif +#ifdef HAVE_WINDOWS_H +#include +#endif + #include #include "route_mgr.hxx" @@ -215,12 +219,20 @@ bool FGRouteMgr::isRouteActive() const } void FGRouteMgr::update( double dt ) { + if (dt <= 0.0) { + // paused, nothing to do here + return; + } + if (!active->getBoolValue()) { return; } double groundSpeed = get_ground_speed(); - if (!airborne->getBoolValue()) { + if (airborne->getBoolValue()) { + time_t now = time(NULL); + elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime)); + } else { // not airborne if (weightOnWheels->getBoolValue() || (groundSpeed < 40)) { return; } @@ -230,9 +242,7 @@ void FGRouteMgr::update( double dt ) { departure->setIntValue("takeoff-time", _takeoffTime); } - time_t now = time(NULL); - elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime)); - + // basic course/distance information double inboundCourse, dummy, wp_course, wp_distance; SGWayPoint wp = _route->get_current(); @@ -251,6 +261,7 @@ void FGRouteMgr::update( double dt ) { } } + // update wp0 / wp1 / wp-last for legacy users wp0->setDoubleValue("dist", wp_distance * SG_METER_TO_NM); wp_course -= magvar->getDoubleValue(); // expose magnetic bearing wp0->setDoubleValue("bearing-deg", wp_course); @@ -283,6 +294,12 @@ void FGRouteMgr::update( double dt ) { void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance) { + double speed = get_ground_speed(); + if (speed < 1.0) { + aProp->setStringValue("--:--"); + return; + } + char eta_str[64]; double eta = aDistance * SG_METER_TO_NM / get_ground_speed(); if ( eta >= 100.0 ) { diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index f9b9f3a97..5c58abce6 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -467,7 +467,9 @@ void drawHUD(osg::State* state) fgGetDouble("/autopilot/settings/true-heading-deg") ); HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) ); apY -= 15; - + } + + if (fgGetBool("/autopilot/route-manager/active", false)) { string wp0_id = fgGetString( "/autopilot/route-manager/wp[0]/id" ); if ( wp0_id.length() > 0 ) { snprintf( hud_wp0_text, 256, "%5s %6.1fnm %s", wp0_id.c_str(), -- 2.39.5