]> git.mxchange.org Git - flightgear.git/commitdiff
Mathias Fröhlich:
authorehofman <ehofman>
Sat, 4 Mar 2006 12:49:30 +0000 (12:49 +0000)
committerehofman <ehofman>
Sat, 4 Mar 2006 12:49:30 +0000 (12:49 +0000)
Fix the AI-Radar code.

src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx

index 348058c870f716e29a0328993fa96b67f31b6a43..b1dca66e790f2fdda3d4037eef64b07eb7657c40 100644 (file)
@@ -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,
index 446a258e3f6b30fb18fed61ac24970cd1b3600d6..1bed52ab1d747c9220c82aad55fdb1c000d50ed5 100644 (file)
@@ -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 ) {
index bb294bd6e0e69268dd0f009a0bbf29fafa809cde..11b028c4178edb9666784286b058e16b7797fa8a 100644 (file)
@@ -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<FGAIBase> 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
index 3472df89f994afbf3fd88da695b63490d2e013bb..2153111c7444fb37547578233291aceb3e778119 100644 (file)
@@ -110,6 +110,7 @@ public:
 private:
 
     bool enabled;
+    int mNumAiTypeModels[FGAIBase::MAX_OBJECTS];
     int mNumAiModels;
 
     SGPropertyNode* root;