[AIModel] Fix a crash when starting at the poles and reduce property reading
This commit is contained in:
parent
a92c697989
commit
ae8ddd04d9
4 changed files with 13 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -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;}
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue