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.
This commit is contained in:
ThorstenB
2011-10-29 21:15:29 +02:00
parent a4b788980c
commit 3477e1a4f5
+57 -34
View File
@@ -486,7 +486,18 @@ bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
command = buf.str(); command = buf.str();
#endif #endif
SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'"); SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'");
#ifdef SG_WINDOWS
// tbd: does Windows support "popen"?
int rc = system( command.c_str() ); 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) if (rc)
{ {
SG_LOG(SG_TERRAIN,SG_ALERT, SG_LOG(SG_TERRAIN,SG_ALERT,
@@ -701,12 +712,21 @@ void SGTerraSync::reinit()
_svnThread->setExtSvnUtility(_terraRoot->getStringValue("ext-svn-utility","svn")); _svnThread->setExtSvnUtility(_terraRoot->getStringValue("ext-svn-utility","svn"));
if (_svnThread->start()) if (_svnThread->start())
{
syncAirportsModels(); 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); _stalled_node->setBoolValue(_svnThread->_stalled);
last_lat = NOWHERE;
last_lon = NOWHERE;
} }
void SGTerraSync::bind() 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 SGTerraSync::schedulePosition(int lat, int lon)
{ {
bool Ok = false;
// Ignore messages where the location does not change // Ignore messages where the location does not change
if ( lat != last_lat || lon != last_lon ) if ( lat != last_lat || lon != last_lon )
{ {
SG_LOG(SG_TERRAIN,SG_DEBUG, "Requesting scenery update for position " << if (_svnThread->_running)
lat << "," << lon);
int lat_dir, lon_dir, dist;
if ( last_lat == NOWHERE || last_lon == NOWHERE )
{ {
lat_dir = lon_dir = 0; SG_LOG(SG_TERRAIN,SG_DEBUG, "Requesting scenery update for position " <<
} else lat << "," << lon);
{ int lat_dir=0;
dist = lat - last_lat; int lon_dir=0;
if ( dist != 0 ) if ( last_lat != NOWHERE && last_lon != NOWHERE )
{ {
lat_dir = dist / abs(dist); int dist = lat - last_lat;
} if ( dist != 0 )
else {
{ lat_dir = dist / abs(dist);
lat_dir = 0; }
} else
dist = lon - last_lon; {
if ( dist != 0 ) lat_dir = 0;
{ }
lon_dir = dist / abs(dist); dist = lon - last_lon;
} else if ( dist != 0 )
{ {
lon_dir = 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 );
Ok = true;
} }
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 );
last_lat = lat; last_lat = lat;
last_lon = lon; last_lon = lon;
return true;
} }
return false;
return Ok;
} }