]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/submodel.cxx
NavDisplay: fix update lag when switching range or centre.
[flightgear.git] / src / AIModel / submodel.cxx
index d1b79256348a44f72c57e833b655b635ec5dea98..e4746bfc8d3cc37bd65d319b81d2b7e2595b9249 100644 (file)
@@ -43,6 +43,11 @@ FGSubmodelMgr::~FGSubmodelMgr()
 {
 }
 
+FGAIManager* FGSubmodelMgr::aiManager()
+{
+   return (FGAIManager*)globals->get_subsystem("ai-model");
+}
+
 void FGSubmodelMgr::init()
 {
     index = 0;
@@ -74,8 +79,6 @@ void FGSubmodelMgr::init()
     _contrail_trigger       = fgGetNode("ai/submodels/contrails", true);
     _contrail_trigger->setBoolValue(false);
 
-    ai = (FGAIManager*)globals->get_subsystem("ai_model");
-
     load();
 
 }
@@ -116,9 +119,9 @@ void FGSubmodelMgr::update(double dt)
     _expiry = false;
 
     // check if the submodel hit an object or terrain
-    sm_list = ai->get_ai_list();
-    sm_list_iterator sm_list_itr = sm_list.begin();
-    sm_list_iterator end = sm_list.end();
+    FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
+    FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
+      end = sm_list.end();
 
     for (; sm_list_itr != end; ++sm_list_itr) {
         FGAIBase::object_type object_type =(*sm_list_itr)->getType();
@@ -133,19 +136,19 @@ void FGSubmodelMgr::update(double dt)
         if ( parent_subID == 0 || id == -1) // this entry in the list has no associated submodel
             continue;                       // or is invalid so we can continue
 
-        //SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
+        //SG_LOG(SG_AI, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
         //        << _hit <<" parent_subID " << parent_subID);
 
         _hit = (*sm_list_itr)->_getCollisionData();
         _impact = (*sm_list_itr)->_getImpactData();
         _expiry = (*sm_list_itr)->_getExpiryData();
 
-        //SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: " << (*sm_list_itr)->_getName()
+        //SG_LOG(SG_AI, SG_ALERT, "Submodel: " << (*sm_list_itr)->_getName()
         //    << " Impact " << _impact << " hit! " << _hit
         //    << " exipiry :-( " << _expiry );
 
         if (_impact || _hit || _expiry) {
-    //        SG_LOG(SG_GENERAL, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit 
+    //        SG_LOG(SG_AI, SG_ALERT, "Submodel: Impact " << _impact << " hit! " << _hit
                 //<< " exipiry :-( " << _expiry );
 
             submodel_iterator = submodels.begin();
@@ -188,7 +191,7 @@ void FGSubmodelMgr::update(double dt)
     while (submodel_iterator != submodels.end())  {
         i++;
 
-        /*SG_LOG(SG_GENERAL, SG_DEBUG,
+        /*SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels:  " << (*submodel_iterator)->id
                 << " name " << (*submodel_iterator)->name
                 );*/
@@ -204,10 +207,10 @@ void FGSubmodelMgr::update(double dt)
 
         if (trigger && (*submodel_iterator)->count != 0) {
 
-            int id = (*submodel_iterator)->id;
+            //int id = (*submodel_iterator)->id;
             string name = (*submodel_iterator)->name;
             
-            SG_LOG(SG_GENERAL, SG_DEBUG,
+            SG_LOG(SG_AI, SG_DEBUG,
             "Submodels release:  " << (*submodel_iterator)->id
             << " name " << (*submodel_iterator)->name
             << " count " << (*submodel_iterator)->count
@@ -300,7 +303,8 @@ bool FGSubmodelMgr::release(submodel *sm, double dt)
     ballist->setParentNodes(_selected_ac);
     ballist->setContentsNode(sm->contents_node);
     ballist->setWeight(sm->weight);
-    ai->attach(ballist);
+    
+    aiManager()->attach(ballist);
 
     if (sm->count > 0)
         sm->count--;
@@ -338,7 +342,7 @@ void FGSubmodelMgr::transform(submodel *sm)
         IC.mass = sm->weight * lbs_to_slugs;
 
     int id = sm->id;
-    int sub_id = sm->sub_id;
+    //int sub_id = sm->sub_id;
     string name = sm->name;
 
 
@@ -383,8 +387,6 @@ void FGSubmodelMgr::transform(submodel *sm)
     } else {
         // set the data for a submodel tied to an AI Object
         //cout << " set the data for a submodel tied to an AI Object " << id << endl;
-        sm_list_iterator sm_list_itr = sm_list.begin();
-        sm_list_iterator end = sm_list.end();
         setParentNode(id);
     }
 
@@ -475,17 +477,17 @@ void FGSubmodelMgr::updatelat(double lat)
 
 void FGSubmodelMgr::loadAI()
 {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
+    SG_LOG(SG_AI, SG_DEBUG, "Submodels: Loading AI submodels ");
 
-    sm_list = ai->get_ai_list();
+    FGAIManager::ai_list_type sm_list(aiManager()->get_ai_list());
 
     if (sm_list.empty()) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "Submodels: Unable to read AI submodel list");
+        SG_LOG(SG_AI, SG_ALERT, "Submodels: Unable to read AI submodel list");
         return;
     }
 
-    sm_list_iterator sm_list_itr = sm_list.begin();
-    sm_list_iterator end = sm_list.end();
+    FGAIManager::ai_list_iterator sm_list_itr = sm_list.begin(),
+      end = sm_list.end();
 
     while (sm_list_itr != end) {
         string path = (*sm_list_itr)->_getSMPath();
@@ -514,11 +516,11 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
 
     SGPath config = globals->resolve_aircraft_path(path);
     try {
-        SG_LOG(SG_GENERAL, SG_DEBUG,
+        SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
     } catch (const sg_exception &) {
-        SG_LOG(SG_GENERAL, SG_ALERT,
+        SG_LOG(SG_AI, SG_ALERT,
                 "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
@@ -618,12 +620,12 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
     SGPath config = globals->resolve_aircraft_path(path);
 
     try {
-        SG_LOG(SG_GENERAL, SG_DEBUG,
+        SG_LOG(SG_AI, SG_DEBUG,
                 "Submodels: Trying to read AI submodels file: " << config.str());
         readProperties(config.str(), &root);
 
     } catch (const sg_exception &) {
-        SG_LOG(SG_GENERAL, SG_ALERT,
+        SG_LOG(SG_AI, SG_ALERT,
                 "Submodels: Unable to read AI submodels file: " << config.str());
         return;
     }
@@ -720,7 +722,7 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
 
 void FGSubmodelMgr::loadSubmodels()
 {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading sub submodels");
+    SG_LOG(SG_AI, SG_DEBUG, "Submodels: Loading sub submodels");
 
     _found_sub = false;
 
@@ -731,7 +733,7 @@ void FGSubmodelMgr::loadSubmodels()
         if (!submodel.empty()) {
             //int id = (*submodel_iterator)->id;
             bool serviceable = true;
-            SG_LOG(SG_GENERAL, SG_DEBUG, "found path sub sub "
+            SG_LOG(SG_AI, SG_DEBUG, "found path sub sub "
                     << submodel
                     << " index " << index
                     << " name " << (*submodel_iterator)->name);
@@ -764,7 +766,7 @@ void FGSubmodelMgr::loadSubmodels()
     //    int id = (*submodel_iterator)->id;
     //    subcount++;
 
-    //    SG_LOG(SG_GENERAL, SG_ALERT,"after pushback "
+    //    SG_LOG(SG_AI, SG_ALERT,"after pushback "
     //            << " parent id " << id
     //            << " name " << (*submodel_iterator)->name
     //            << " sub id " << (*submodel_iterator)->sub_id
@@ -896,7 +898,7 @@ void FGSubmodelMgr::setParentNode(int id) {
         //cout << name << " IC.speed " << IC.speed << endl;
 
     } else {
-        SG_LOG(SG_GENERAL, SG_ALERT, "AISubmodel: parent node not found ");
+        SG_LOG(SG_AI, SG_ALERT, "AISubmodel: parent node not found ");
     }
 
 }