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

View File

@ -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 )
if (_svnThread->_running)
{
lat_dir = lon_dir = 0;
} else
{
dist = lat - last_lat;
if ( dist != 0 )
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 = dist / abs(dist);
}
else
{
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 );
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_lon = lon;
return true;
}
return false;
return Ok;
}