From: ThorstenB Date: Sat, 29 Oct 2011 19:15:29 +0000 (+0200) Subject: terrasync improvements X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3477e1a4f531ab4e3f9585ddd17bd99d985c94f6;p=simgear.git terrasync improvements Detach from console to make "Ctrl-C" work for fgfs on Linux. Immediately start synchronization of current position when starting at run-time. --- diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index ec2e5ca0..d48b39e9 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -486,7 +486,18 @@ bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir) command = buf.str(); #endif SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'"); + +#ifdef SG_WINDOWS + // tbd: does Windows support "popen"? int rc = system( command.c_str() ); +#else + FILE* pipe = popen( command.c_str(), "r"); + int rc=-1; + // wait for external process to finish + if (pipe) + rc = pclose(pipe); +#endif + if (rc) { SG_LOG(SG_TERRAIN,SG_ALERT, @@ -701,12 +712,21 @@ void SGTerraSync::reinit() _svnThread->setExtSvnUtility(_terraRoot->getStringValue("ext-svn-utility","svn")); if (_svnThread->start()) + { syncAirportsModels(); + if (last_lat != NOWHERE && last_lon != NOWHERE) + { + // reschedule most recent position + int lat = last_lat; + int lon = last_lon; + last_lat = NOWHERE; + last_lon = NOWHERE; + schedulePosition(lat, lon); + } + } } _stalled_node->setBoolValue(_svnThread->_stalled); - last_lat = NOWHERE; - last_lon = NOWHERE; } void SGTerraSync::bind() @@ -897,46 +917,49 @@ void SGTerraSync::syncAreas( int lat, int lon, int lat_dir, int lon_dir ) bool SGTerraSync::schedulePosition(int lat, int lon) { + bool Ok = false; + // Ignore messages where the location does not change if ( lat != last_lat || lon != last_lon ) { - SG_LOG(SG_TERRAIN,SG_DEBUG, "Requesting scenery update for position " << - lat << "," << lon); - int lat_dir, lon_dir, dist; - if ( last_lat == NOWHERE || last_lon == NOWHERE ) - { - lat_dir = lon_dir = 0; - } else + if (_svnThread->_running) { - dist = lat - last_lat; - if ( dist != 0 ) - { - lat_dir = dist / abs(dist); - } - else + SG_LOG(SG_TERRAIN,SG_DEBUG, "Requesting scenery update for position " << + lat << "," << lon); + int lat_dir=0; + int lon_dir=0; + if ( last_lat != NOWHERE && last_lon != NOWHERE ) { - lat_dir = 0; - } - dist = lon - last_lon; - if ( dist != 0 ) - { - lon_dir = dist / abs(dist); - } else - { - lon_dir = 0; + int dist = lat - last_lat; + if ( dist != 0 ) + { + lat_dir = dist / abs(dist); + } + else + { + lat_dir = 0; + } + dist = lon - last_lon; + if ( dist != 0 ) + { + lon_dir = dist / abs(dist); + } else + { + lon_dir = 0; + } } - } - SG_LOG(SG_TERRAIN,SG_DEBUG, "Scenery update for " << - "lat = " << lat << ", lon = " << lon << - ", lat_dir = " << lat_dir << ", " << - "lon_dir = " << lon_dir); - - syncAreas( lat, lon, lat_dir, lon_dir ); + SG_LOG(SG_TERRAIN,SG_DEBUG, "Scenery update for " << + "lat = " << lat << ", lon = " << lon << + ", lat_dir = " << lat_dir << ", " << + "lon_dir = " << lon_dir); + syncAreas( lat, lon, lat_dir, lon_dir ); + Ok = true; + } last_lat = lat; last_lon = lon; - return true; } - return false; + + return Ok; }