From: ehofman Date: Sat, 4 Mar 2006 12:49:30 +0000 (+0000) Subject: Mathias Fröhlich: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=479d4d7484f6aabd4f4e5bb5ece9c6499272ed51;p=flightgear.git Mathias Fröhlich: Fix the AI-Radar code. --- diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 348058c87..b1dca66e7 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -76,7 +76,7 @@ FGAIBase::~FGAIBase() { if (props) { SGPropertyNode* parent = props->getParent(); if (parent) - parent->removeChild(props->getName(), props->getIndex()); + parent->removeChild(props->getName(), props->getIndex(), false); } delete fp; fp = 0; @@ -121,12 +121,6 @@ void FGAIBase::Transform() { bool FGAIBase::init() { - SGPropertyNode *root = globals->get_props()->getNode("ai/models", true); - - unsigned index = root->getChildren(getTypeString()).size(); - - props = root->getNode(getTypeString(), index, true); - if (!model_path.empty()) { try { model = load3DModel( globals->get_fg_root(), model_path, props, diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 446a258e3..1bed52ab1 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -57,7 +57,7 @@ public: virtual void bind(); virtual void unbind(); - void setManager(FGAIManager* mgr); + void setManager(FGAIManager* mgr, SGPropertyNode* p); void setPath( const char* model ); void setSpeed( double speed_KTAS ); void setAltitude( double altitude_ft ); @@ -182,8 +182,9 @@ public: static bool _isNight(); }; -inline void FGAIBase::setManager(FGAIManager* mgr) { +inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) { manager = mgr; + props = p; } inline void FGAIBase::setPath(const char* model ) { diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index bb294bd6e..11b028c41 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -36,6 +36,8 @@ FGAIManager::FGAIManager() { _dt = 0.0; mNumAiModels = 0; + for (unsigned i = 0; i < FGAIBase::MAX_OBJECTS; ++i) + mNumAiTypeModels[i] = 0; } FGAIManager::~FGAIManager() { @@ -112,6 +114,7 @@ void FGAIManager::update(double dt) { if ((*ai_list_itr)->getDie()) { tmgr->release((*ai_list_itr)->getID()); --mNumAiModels; + --(mNumAiTypeModels[(*ai_list_itr)->getType()]); (*ai_list_itr)->unbind(); ai_list_itr = ai_list.erase(ai_list_itr); } else { @@ -131,9 +134,14 @@ void FGAIManager::update(double dt) { void FGAIManager::attach(SGSharedPtr model) { - model->setManager(this); + unsigned idx = mNumAiTypeModels[model->getType()]; + const char* typeString = model->getTypeString(); + SGPropertyNode* root = globals->get_props()->getNode("ai/models", true); + SGPropertyNode* p = root->getNode(typeString, idx, true); + model->setManager(this, p); ai_list.push_back(model); ++mNumAiModels; + ++(mNumAiTypeModels[model->getType()]); model->init(); model->bind(); } @@ -144,6 +152,7 @@ void FGAIManager::destroyObject( int ID ) { while(ai_list_itr != ai_list.end()) { if ((*ai_list_itr)->getID() == ID) { --mNumAiModels; + --(mNumAiTypeModels[(*ai_list_itr)->getType()]); (*ai_list_itr)->unbind(); ai_list_itr = ai_list.erase(ai_list_itr); } else diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 3472df89f..2153111c7 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -110,6 +110,7 @@ public: private: bool enabled; + int mNumAiTypeModels[FGAIBase::MAX_OBJECTS]; int mNumAiModels; SGPropertyNode* root;