From ae8ddd04d90029c4c6cc1942f362d91e0890e2a8 Mon Sep 17 00:00:00 2001 From: Christian Schmitt Date: Wed, 5 Feb 2014 17:43:07 +0100 Subject: [PATCH] [AIModel] Fix a crash when starting at the poles and reduce property reading --- src/AIModel/AIAircraft.cxx | 12 +++--------- src/AIModel/AIAircraft.hxx | 1 - src/AIModel/AIManager.cxx | 8 ++++++++ src/AIModel/AIManager.hxx | 2 ++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index f05a58917..5e803ef5e 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -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; diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 0d92868ee..3ad8b8a67 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -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;} diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index aa80b26c5..27582d9ca 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -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 { diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 140b34366..a35f64968 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -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/[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;