From f6fafffeb58a992e47cc94b3a8474cfb618877c5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 1 Oct 2013 21:14:30 +0100 Subject: [PATCH] Initial hacking on terra-sync of traffic files. --- src/Main/main.cxx | 8 +++++++- src/Traffic/TrafficMgr.cxx | 37 ++++++++++++++++++++++++++++++++++--- src/Traffic/TrafficMgr.hxx | 2 ++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 792362632..12d55fdd1 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -128,7 +128,7 @@ static void fgIdleFunction ( void ) { } else if ( idle_state == 2 ) { // start TerraSync up now, so it can be synchronizing shared models - // and airports data in parallel with a nav-cahce rebuild. + // and airports data in parallel with a nav-cache rebuild. SGPath tsyncCache(globals->get_fg_home()); tsyncCache.append("terrasync-cache.xml"); fgSetString("/sim/terrasync/cache-path", tsyncCache.c_str()); @@ -136,9 +136,15 @@ static void fgIdleFunction ( void ) { simgear::SGTerraSync* terra_sync = new simgear::SGTerraSync(globals->get_props()); globals->add_subsystem("terrasync", terra_sync); + + terra_sync->bind(); terra_sync->init(); + // add the terrasync root as a data path so data can be retrieved from it + std::string terraSyncDir(fgGetString("/sim/terrasync/scenery-dir")); + globals->append_data_path(terraSyncDir); + idle_state++; fgSplashProgress("loading-nav-dat"); diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index d36645b46..731687c68 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -371,6 +372,7 @@ private: BOOST_FOREACH(SGPath p, d) { simgear::Dir d2(p); + SG_LOG(SG_AI, SG_INFO, "parsing traffic in:" << p); simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml"); BOOST_FOREACH(SGPath xml, trafficFiles) { readXML(xml.str(), *this); @@ -412,6 +414,7 @@ private: FGTrafficManager::FGTrafficManager() : inited(false), doingInit(false), + trafficSyncRequested(false), waitingMetarTime(0.0), enabled("/sim/traffic-manager/enabled"), aiEnabled("/sim/ai/enabled"), @@ -478,6 +481,7 @@ void FGTrafficManager::shutdown() currAircraft = scheduledAircraft.begin(); doingInit = false; inited = false; + trafficSyncRequested = false; } void FGTrafficManager::init() @@ -487,9 +491,36 @@ void FGTrafficManager::init() } assert(!doingInit); + simgear::SGTerraSync* terraSync = static_cast(globals->get_subsystem("terrasync")); + + if (terraSync) { + if (!trafficSyncRequested) { + terraSync->scheduleDataDir("AI/Traffic"); + trafficSyncRequested = true; + } + + if (terraSync->isDataDirPending("AI/Traffic")) { + return; // remain in the init state + } + + SG_LOG(SG_AI, SG_INFO, "Traffic files sync complete"); + } + doingInit = true; - if (string(fgGetString("/sim/traffic-manager/datafile")).empty()) { + if (string(fgGetString("/sim/traffic-manager/datafile")).empty()) { PathList dirs = globals->get_data_paths("AI/Traffic"); + + // temporary flag to restrict loading while traffic data is found + // through terrasync /and/ fgdata. Ultimatley we *do* want to be able to + // overlay sources. + + if (dirs.size() > 1) { + SGPath p = dirs.back(); + if (simgear::strutils::starts_with(p.str(), globals->get_fg_root())) { + dirs.pop_back(); + } + } + if (dirs.empty()) { doingInit = false; return; @@ -649,8 +680,8 @@ void FGTrafficManager::update(double dt) if (!doingInit) { init(); } - - if (!scheduleParser->isFinished()) { + + if (!doingInit || !scheduleParser->isFinished()) { return; } diff --git a/src/Traffic/TrafficMgr.hxx b/src/Traffic/TrafficMgr.hxx index a550431e5..15a3467c8 100644 --- a/src/Traffic/TrafficMgr.hxx +++ b/src/Traffic/TrafficMgr.hxx @@ -80,6 +80,8 @@ class FGTrafficManager : public SGSubsystem private: bool inited; bool doingInit; + bool trafficSyncRequested; + double waitingMetarTime; std::string waitingMetarStation; -- 2.39.5