]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/xmlloader.cxx
Some headers missing... ;)
[flightgear.git] / src / Airports / xmlloader.cxx
index b2ce07ed4b3fdbb28975f48a48685f4db96b6994..8ff3eb1fdae00f22fbb268c7922702f384091175 100644 (file)
 #  include "config.h"
 #endif
 
+#include <cstdio>
+
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/xml/easyxml.hxx>
 #include <simgear/misc/strutils.hxx>
+#include <simgear/timing/timestamp.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include "runwayprefloader.hxx"
 
 #include "dynamics.hxx"
+#include "simple.hxx"
 #include "runwayprefs.hxx"
 
+#include <Navaids/NavDataCache.hxx>
+
 using std::string;
 
 XMLLoader::XMLLoader() {}
 XMLLoader::~XMLLoader() {}
 
-void XMLLoader::load(FGAirportDynamics* d) {
-  FGAirportDynamicsXMLLoader visitor(d);
-  if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) {
-   SGPath parkpath( globals->get_fg_root() );
-   parkpath.append( "/AI/Airports/" );
-   parkpath.append( d->getId() );
-   parkpath.append( "parking.xml" );
-   SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
-   if (parkpath.exists()) {
-       try {
-           readXML(parkpath.str(), visitor);
-           d->init();
-       } 
-       catch (const sg_exception &) {
-       }
-   }
-  } else {
-    if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) {
-        d->init();
-    }
+void XMLLoader::load(FGAirportDynamics* d)
+{
+  SGPath path;
+  if (!findAirportData(d->parent()->ident(), "groundnet", path)) {
+    return;
   }
-}
 
-void XMLLoader::load(FGRunwayPreference* p) {
-  FGRunwayPreferenceXMLLoader visitor(p);
-  if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) {
-    SGPath rwyPrefPath( globals->get_fg_root() );
-    rwyPrefPath.append( "AI/Airports/" );
-    rwyPrefPath.append( p->getId() );
-    rwyPrefPath.append( "rwyuse.xml" );
-    if (rwyPrefPath.exists()) {
-        try {
-            readXML(rwyPrefPath.str(), visitor);
-        } 
-        catch (const sg_exception &) {
-        }
-     }
-  } else {
-    loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
+  flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
+  if (!cache->isCachedFileModified(path)) {
+    return;
   }
+  
+  SG_LOG(SG_NAVAID, SG_INFO, "reading groundnet data from " << path);
+  SGTimeStamp t;
+  try {
+    flightgear::NavDataCache::Transaction txn(cache);
+    t.stamp();
+    {
+      // drop all current data
+      cache->dropGroundnetFor(d->parent()->guid());
+      
+      FGAirportDynamicsXMLLoader visitor(d);
+      readXML(path.str(), visitor);
+    } // ensure visitor is destroyed so its destructor runs
+    cache->stampCacheFile(path);
+    txn.commit();
+  } catch (sg_exception& e) {
+    SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML failed:" << e.getFormattedMessage());
+  }
+
+  SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML took " << t.elapsedMSec());
 }
 
-void XMLLoader::load(FGSidStar* p) {
-  SGPath path;
-  if (findAirportData(p->getId(), "SID", path)) {
-    p->load(path);
-  }
+void XMLLoader::load(FGRunwayPreference* p) {
+  FGRunwayPreferenceXMLLoader visitor(p);
+  loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
 }
 
 bool XMLLoader::findAirportData(const std::string& aICAO, 
@@ -119,7 +114,7 @@ bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
 {
   SGPath path;
   if (!findAirportData(aICAO, aFileName, path)) {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
+    SG_LOG(SG_NAVAID, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
     return false;
   }