]> git.mxchange.org Git - flightgear.git/commitdiff
Some small updates that hopefully solve the segmentation fault at the end of the...
authorehofman <ehofman>
Tue, 18 May 2004 09:09:08 +0000 (09:09 +0000)
committerehofman <ehofman>
Tue, 18 May 2004 09:09:08 +0000 (09:09 +0000)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlan.hxx

index bbed46642da14e0baa2e52c60d0df2523139dc66..8e773d481f82b81894fc88dd3be830141ab8b21b 100644 (file)
@@ -52,12 +52,12 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
 FGAIAircraft *FGAIAircraft::_self = NULL;
 
 FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
+   _self = this;       // This needs to be the first entry.
    manager = mgr;   
-   _self = this;
    _type_str = "aircraft";
    _otype = otAircraft;
    fp = 0;
-   fp_count = 0;
+   dt_count = 0;
    use_perf_vs = true;
 
    // set heading and altitude locks
@@ -113,7 +113,7 @@ void FGAIAircraft::Run(double dt) {
 
    FGAIAircraft::dt = dt;
 
-   if (fp) ProcessFlightPlan();
+   if (fp) ProcessFlightPlan(dt);
        
    double turn_radius_ft;
    double turn_circum_ft;
@@ -336,14 +336,14 @@ void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
   fp = f;
 }
 
-void FGAIAircraft::ProcessFlightPlan( void ) {
+void FGAIAircraft::ProcessFlightPlan( double dt ) {
   FGAIFlightPlan::waypoint* prev = 0; // the one behind you
   FGAIFlightPlan::waypoint* curr = 0; // the one ahead
   FGAIFlightPlan::waypoint* next = 0; // the next plus 1
   prev = fp->getPreviousWaypoint();
   curr = fp->getCurrentWaypoint();
   next = fp->getNextWaypoint();
-  ++fp_count;
+  dt_count += dt;
 
   if (!prev) {  //beginning of flightplan, do this initialization once
     fp->IncrementWaypoint();
@@ -375,11 +375,12 @@ void FGAIAircraft::ProcessFlightPlan( void ) {
     return;  
   } // end of initialization
 
-  // let's only process the flight plan every 11 time steps
-  if (fp_count < 11) { 
+  // let's only process the flight plan every 500 ms.
+  if (dt_count < 0.5) {
     return;
   } else {
-    fp_count = 0;
+    while (dt_count > 0.5)
+      dt_count -= dt;
 
     // check to see if we've reached the lead point for our next turn
     double dist_to_go = fp->getDistanceToGo(pos.lat(), pos.lon(), curr); 
@@ -388,7 +389,7 @@ void FGAIAircraft::ProcessFlightPlan( void ) {
     //cout << "dist_to_go: " << dist_to_go << ",  lead_dist: " << lead_dist << endl;
 
     if ( dist_to_go < lead_dist ) {
-      if (curr->name == "END") {  //end of the flight plan, so terminate
+      if (curr->finished) {  //end of the flight plan, so terminate
         setDie(true);
         return;
       }
index fb62588e23ae1a6e560ee3c71d1b2516b0a4082f..4048deb9e3a8252cc092407a461136774301c967 100644 (file)
@@ -66,7 +66,7 @@ public:
         void YawTo(double angle);
         void ClimbTo(double altitude);
         void TurnTo(double heading);
-        void ProcessFlightPlan( void );
+        void ProcessFlightPlan( double dt );
         //double getHeading(double lat1, double lon1, double lat2, double lon2);
 
 protected:
@@ -77,7 +77,7 @@ private:
         bool hdg_lock;
         bool alt_lock;
         FGAIFlightPlan *fp;
-        int fp_count;  
+        double dt_count;  
         double dt; 
 
         const PERF_STRUCT *performance;
@@ -91,7 +91,6 @@ private:
 
 inline bool FGAIAircraft::_getGearDown() {
     return ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
-             && (fgGetFloat("/orientation/pitch-deg") < 0.0)
              && (fgGetFloat("/velocities/airspeed-kt")
                    < _self->performance->land_speed*1.5));
 }
index 3bde497cafb9195f68e23f40e9862ac3d5b15215..d8c95e75e3d8bd9c77bbb7f6032cead3657e4129 100644 (file)
@@ -50,7 +50,6 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
   for (i = 0; i < node->nChildren(); i++) { 
      //cout << "Reading waypoint " << i << endl;        
      waypoint* wpt = new waypoint;
-     waypoints.push_back( wpt );
      SGPropertyNode * wpt_node = node->getChild(i);
      wpt->name      = wpt_node->getStringValue("name", "END");
      wpt->latitude  = wpt_node->getDoubleValue("lat", 0);
@@ -60,6 +59,11 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
      wpt->crossat   = wpt_node->getDoubleValue("crossat", -10000);
      wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
      wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
+
+     if (wpt->name == "END") wpt->finished = true;
+     else wpt->finished = false;
+
+     waypoints.push_back( wpt );
    }
 
   wpt_iterator = waypoints.begin();
@@ -163,6 +167,8 @@ double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp){
   if (!southerly && easterly) return 90.0 - angle;
   if (southerly && !easterly) return 270.0 - angle;
   if (!southerly && !easterly) return 270.0 + angle; 
-}
 
+  // Omit a compiler warning.
+  return 0;
+}
 
index e511c2c16b020ea054e57963dcc3a645434b34de..9eaf570291f4b40e206fc61595554553ff2d11aa 100644 (file)
@@ -37,6 +37,7 @@ public:
    double altitude;
    double speed;
    double crossat;
+   bool finished;
    bool gear_down;
    bool flaps_down;
   } waypoint;