]> git.mxchange.org Git - flightgear.git/commitdiff
[AIModel] Fix a crash when starting at the poles and reduce property reading
authorChristian Schmitt <chris@ilovelinux.de>
Wed, 5 Feb 2014 16:43:07 +0000 (17:43 +0100)
committerChristian Schmitt <chris@ilovelinux.de>
Wed, 5 Feb 2014 16:51:28 +0000 (17:51 +0100)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx

index f05a5891774686baaec485c2de71e62fdbe27c05..5e803ef5e159b81e6c3934a73c060f13ab96a16a 100644 (file)
@@ -172,18 +172,12 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string&
     // AI manager. In this particular case, the AIAircraft is used to shadow the user's aircraft's behavior in the AI world.
     // Since we perhaps don't want a radar entry of our own aircraft, the following conditional should probably be adequate
     // enough
-     if (manager)
+     if (manager){
         UpdateRadar(manager);
-     checkVisibility();
+       invisible = !manager->isVisible(pos);
+     }
   }
 
-void FGAIAircraft::checkVisibility() 
-{
-  double visibility_meters = fgGetDouble("/environment/visibility-m");
-  invisible = (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters);
-}
-
-
 
 void FGAIAircraft::AccelTo(double speed) {
     tgt_speed = speed;
index 0d92868eee1a09a4de5e73c060524e2a76111a20..3ad8b8a67130db4a779e2e0ef76b2dbb817cc3e4 100644 (file)
@@ -155,7 +155,6 @@ private:
     void updateActualState();
     void updateModelProperties(double dt);
     void handleATCRequests();
-    void checkVisibility();
     inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
     inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
    
index aa80b26c5d032a600bca8b10b0e83d56f9fcc79d..27582d9ca708a2fb52a236acce96d99989006886 100644 (file)
@@ -134,6 +134,7 @@ FGAIManager::init() {
     
     globals->get_commands()->addCommand("load-scenario", this, &FGAIManager::loadScenarioCommand);
     globals->get_commands()->addCommand("unload-scenario", this, &FGAIManager::unloadScenarioCommand);
+    _environmentVisiblity = fgGetNode("/environment/visibility-m");
 }
 
 void
@@ -184,6 +185,7 @@ FGAIManager::shutdown()
     }
     
     ai_list.clear();
+    _environmentVisiblity.clear();
     
     globals->get_commands()->removeCommand("load-scenario");
     globals->get_commands()->removeCommand("unload-scenario");
@@ -298,6 +300,12 @@ FGAIManager::attach(FGAIBase *model)
     p->setBoolValue("valid", true);
 }
 
+bool FGAIManager::isVisible(const SGGeod& pos) const
+{
+  double visibility_meters = _environmentVisiblity->getDoubleValue();
+  return ( dist(globals->get_view_position_cart(), SGVec3d::fromGeod(pos)) ) <= visibility_meters;
+}
+
 int
 FGAIManager::getNumAiObjects() const
 {
index 140b343667799e5c5bcbfcacadf1fd59320f916e..a35f64968ddb802c2f76af3eeb6ad5403dd1fb6c 100644 (file)
@@ -77,6 +77,7 @@ public:
         SGGeod& geodPos, double& hdng, SGVec3d& uvw);
 
     FGAIBasePtr addObject(const SGPropertyNode* definition);
+    bool isVisible(const SGGeod& pos) const;
     
     /**
      * @brief given a reference to an /ai/models/<foo>[n] node, return the
@@ -117,6 +118,7 @@ private:
     SGPropertyNode_ptr user_speed_node;
     SGPropertyNode_ptr wind_from_east_node;
     SGPropertyNode_ptr wind_from_north_node;
+    SGPropertyNode_ptr _environmentVisiblity;
 
 
     ai_list_type ai_list;