1 // terrasync.cxx -- scenery fetcher
3 // Started by Curtis Olson, November 2002.
5 // Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt
6 // Copyright (C) 2008 Alexander R. Perry <alex.perry@ieee.org>
7 // Copyright (C) 2011 Thorsten Brehm <brehmt@gmail.com>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 # include <simgear_config.h>
29 #include <simgear/compiler.h>
38 #elif defined(_MSC_VER)
40 # ifndef HAVE_SVN_CLIENT_H
46 #include <stdlib.h> // atoi() atof() abs() system()
47 #include <signal.h> // signal()
54 #include <simgear/compiler.h>
56 #include "terrasync.hxx"
57 #include <simgear/bucket/newbucket.hxx>
58 #include <simgear/misc/sg_path.hxx>
59 #include <simgear/misc/strutils.hxx>
60 #include <simgear/threads/SGQueue.hxx>
61 #include <simgear/scene/tgdb/TileCache.hxx>
62 #include <simgear/misc/sg_dir.hxx>
63 #include <OpenThreads/Thread>
65 #ifdef HAVE_SVN_CLIENT_H
66 # ifdef HAVE_LIBSVN_CLIENT_1
67 # include <svn_version.h>
68 # include <svn_auth.h>
69 # include <svn_client.h>
70 # include <svn_cmdline.h>
71 # include <svn_pools.h>
73 # undef HAVE_SVN_CLIENT_H
77 #ifdef HAVE_SVN_CLIENT_H
78 static const svn_version_checklist_t mysvn_checklist[] = {
79 { "svn_subr", svn_subr_version },
80 { "svn_client", svn_client_version },
83 static const bool svn_built_in_available = true;
85 static const bool svn_built_in_available = false;
88 using namespace simgear;
91 const char* rsync_cmd =
92 "rsync --verbose --archive --delete --perms --owner --group";
94 const char* svn_options =
97 namespace UpdateInterval
99 // interval in seconds to allow an update to repeat after a successful update (=daily)
100 static const double SuccessfulAttempt = 24*60*60;
101 // interval in seconds to allow another update after a failed attempt (10 minutes)
102 static const double FailedAttempt = 10*60;
105 typedef map<string,time_t> CompletedTiles;
107 ///////////////////////////////////////////////////////////////////////////////
108 // helper functions ///////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////////////////
110 string stripPath(string path)
112 // svn doesn't like trailing white-spaces or path separators - strip them!
113 path = simgear::strutils::strip(path);
114 int slen = path.length();
116 ((path[slen-1]=='/')||(path[slen-1]=='\\')))
120 return path.substr(0,slen);
123 bool hasWhitespace(string path)
125 return path.find(' ')!=string::npos;
128 ///////////////////////////////////////////////////////////////////////////////
129 // WaitingTile ////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////////////
134 WaitingTile(string dir,bool refresh) :
135 _dir(dir), _refreshScenery(refresh) {}
137 bool _refreshScenery;
140 ///////////////////////////////////////////////////////////////////////////////
141 // SGTerraSync::SvnThread /////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////////////
143 class SGTerraSync::SvnThread : public OpenThreads::Thread
147 virtual ~SvnThread( ) { stop(); }
152 bool isIdle() {return waitingTiles.empty();}
153 void request(const WaitingTile& dir) {waitingTiles.push_front(dir);}
154 bool isDirty() { bool r = _is_dirty;_is_dirty = false;return r;}
155 bool hasNewTiles() { return !_freshTiles.empty();}
156 WaitingTile getNewTile() { return _freshTiles.pop_front();}
158 void setSvnServer(string server) { _svn_server = stripPath(server);}
159 void setExtSvnUtility(string svn_util) { _svn_command = simgear::strutils::strip(svn_util);}
160 void setRsyncServer(string server) { _rsync_server = simgear::strutils::strip(server);}
161 void setLocalDir(string dir) { _local_dir = stripPath(dir);}
162 string getLocalDir() { return _local_dir;}
163 void setUseSvn(bool use_svn) { _use_svn = use_svn;}
165 #ifdef HAVE_SVN_CLIENT_H
166 void setUseBuiltin(bool built_in) { _use_built_in = built_in;}
169 volatile bool _active;
170 volatile bool _running;
172 volatile bool _stalled;
173 volatile int _fail_count;
174 volatile int _updated_tile_count;
175 volatile int _success_count;
176 volatile int _consecutive_errors;
180 bool syncTree(const char* dir, bool& isNewDirectory);
181 bool syncTreeExternal(const char* dir);
183 #ifdef HAVE_SVN_CLIENT_H
184 static int svnClientSetup(void);
185 bool syncTreeInternal(const char* dir);
189 // Things we need for doing subversion checkout - often
190 static apr_pool_t *_svn_pool;
191 static svn_client_ctx_t *_svn_ctx;
192 static svn_opt_revision_t *_svn_rev;
193 static svn_opt_revision_t *_svn_rev_peg;
196 volatile bool _is_dirty;
198 SGBlockingDeque <WaitingTile> waitingTiles;
199 CompletedTiles _completedTiles;
200 SGBlockingDeque <WaitingTile> _freshTiles;
204 string _rsync_server;
208 #ifdef HAVE_SVN_CLIENT_H
209 apr_pool_t* SGTerraSync::SvnThread::_svn_pool = NULL;
210 svn_client_ctx_t* SGTerraSync::SvnThread::_svn_ctx = NULL;
211 svn_opt_revision_t* SGTerraSync::SvnThread::_svn_rev = NULL;
212 svn_opt_revision_t* SGTerraSync::SvnThread::_svn_rev_peg = NULL;
215 SGTerraSync::SvnThread::SvnThread() :
221 _updated_tile_count(0),
223 _consecutive_errors(0),
224 #ifdef HAVE_SVN_CLIENT_H
231 #ifdef HAVE_SVN_CLIENT_H
232 int errCode = SGTerraSync::SvnThread::svnClientSetup();
233 if (errCode != EXIT_SUCCESS)
235 SG_LOG(SG_TERRAIN,SG_ALERT,
236 "Failed to initialize built-in SVN client, error = " << errCode);
241 void SGTerraSync::SvnThread::stop()
243 // drop any pending requests
244 waitingTiles.clear();
249 // set stop flag and wake up the thread with an empty request
251 WaitingTile w("",false);
257 bool SGTerraSync::SvnThread::start()
264 SG_LOG(SG_TERRAIN,SG_ALERT,
265 "Cannot start scenery download. Local cache directory is undefined.");
271 SGPath path(_local_dir);
274 SG_LOG(SG_TERRAIN,SG_ALERT,
275 "Cannot start scenery download. Directory '" << _local_dir <<
276 "' does not exist. Set correct directory path or create directory folder.");
282 path.append("version");
285 SG_LOG(SG_TERRAIN,SG_ALERT,
286 "Cannot start scenery download. Directory '" << _local_dir <<
287 "' contains the base package. Use a separate directory.");
293 #ifdef HAVE_SVN_CLIENT_H
294 _use_svn |= _use_built_in;
297 if ((_use_svn)&&(_svn_server==""))
299 SG_LOG(SG_TERRAIN,SG_ALERT,
300 "Cannot start scenery download. Subversion scenery server is undefined.");
305 if ((!_use_svn)&&(_rsync_server==""))
307 SG_LOG(SG_TERRAIN,SG_ALERT,
308 "Cannot start scenery download. Rsync scenery server is undefined.");
315 _updated_tile_count = 0;
317 _consecutive_errors = 0;
323 #ifdef HAVE_SVN_CLIENT_H
324 if (_use_svn && _use_built_in)
325 status = "Using built-in SVN support. ";
330 status = "Using external SVN utility '";
331 status += _svn_command;
336 status = "Using RSYNC. ";
339 // not really an alert - but we want to (always) see this message, so user is
340 // aware we're downloading scenery (and using bandwidth).
341 SG_LOG(SG_TERRAIN,SG_ALERT,
342 "Starting automatic scenery download/synchronization. "
344 << "Directory: '" << _local_dir << "'.");
346 OpenThreads::Thread::start();
350 // sync one directory tree
351 bool SGTerraSync::SvnThread::syncTree(const char* dir, bool& isNewDirectory)
354 SGPath path( _local_dir );
357 isNewDirectory = !path.exists();
360 rc = path.create_dir( 0755 );
363 SG_LOG(SG_TERRAIN,SG_ALERT,
364 "Cannot create directory '" << dir << "', return code = " << rc );
369 #ifdef HAVE_SVN_CLIENT_H
371 return syncTreeInternal(dir);
375 return syncTreeExternal(dir);
380 #ifdef HAVE_SVN_CLIENT_H
381 bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
383 SG_LOG(SG_TERRAIN,SG_DEBUG, "Synchronizing scenery directory " << dir);
386 SG_LOG(SG_TERRAIN,SG_ALERT,
387 "Built-in SVN client failed to initialize.");
391 ostringstream command;
392 command << _svn_server << "/" << dir;
394 ostringstream dest_base_dir;
395 dest_base_dir << _local_dir << "/" << dir;
397 apr_pool_t *subpool = svn_pool_create(_svn_pool);
399 svn_error_t *err = NULL;
400 #if (SVN_VER_MINOR >= 5)
401 err = svn_client_checkout3(NULL,
402 command.str().c_str(),
403 dest_base_dir.str().c_str(),
407 0, // ignore-externals = false
408 0, // allow unver obstructions = false
413 err = svn_client_checkout2(NULL,
414 command.str().c_str(),
415 dest_base_dir.str().c_str(),
418 1, // recurse=true - same as svn_depth_infinity for checkout3 above
419 0, // ignore externals = false
424 bool ReturnValue = true;
427 // Report errors from the checkout attempt
428 if (err->apr_err == SVN_ERR_RA_ILLEGAL_URL)
430 // ignore errors when remote path doesn't exist (no scenery data for ocean areas)
434 SG_LOG(SG_TERRAIN,SG_ALERT,
435 "Failed to synchronize directory '" << dir << "', " <<
436 err->message << " (code " << err->apr_err << ").");
437 svn_error_clear(err);
439 err = svn_client_cleanup(dest_base_dir.str().c_str(),
443 SG_LOG(SG_TERRAIN,SG_ALERT,
444 "SVN repository cleanup successful for '" << dir << "'.");
450 SG_LOG(SG_TERRAIN,SG_DEBUG, "Done with scenery directory " << dir);
452 svn_pool_destroy(subpool);
457 bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
460 SGPath localPath( _local_dir );
461 localPath.append( dir );
465 buf << "\"" << _svn_command << "\" "
466 << svn_options << " "
467 << "\"" << _svn_server << "/" << dir << "\" "
468 << "\"" << localPath.str_native() << "\"";
470 buf << rsync_cmd << " "
471 << "\"" << _rsync_server << "/" << dir << "/\" "
472 << "\"" << localPath.str_native() << "/\"";
477 // windows command line parsing is just lovely...
478 // to allow white spaces, the system call needs this:
479 // ""C:\Program Files\something.exe" somearg "some other arg""
480 // Note: whitespace strings quoted by a pair of "" _and_ the
481 // entire string needs to be wrapped by "" too.
482 // The svn url needs forward slashes (/) as a path separator while
483 // the local path needs windows-native backslash as a path separator.
484 command = "\"" + buf.str() + "\"";
488 SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'");
491 // tbd: does Windows support "popen"?
492 int rc = system( command.c_str() );
494 FILE* pipe = popen( command.c_str(), "r");
496 // wait for external process to finish
503 SG_LOG(SG_TERRAIN,SG_ALERT,
504 "Failed to synchronize directory '" << dir << "', " <<
505 "error code= " << rc);
511 void SGTerraSync::SvnThread::run()
516 WaitingTile next = waitingTiles.pop_front();
520 CompletedTiles::iterator ii =
521 _completedTiles.find( next._dir );
522 time_t now = time(0);
523 if ((ii == _completedTiles.end())||
526 bool isNewDirectory = false;
529 if (!syncTree(next._dir.c_str(),isNewDirectory))
531 _consecutive_errors++;
533 _completedTiles[ next._dir ] = now + UpdateInterval::FailedAttempt;
537 _consecutive_errors = 0;
539 SG_LOG(SG_TERRAIN,SG_INFO,
540 "Successfully synchronized directory '" << next._dir << "'");
541 if (next._refreshScenery)
544 _updated_tile_count++;
547 // for now only report new directories to refresh display
548 // (i.e. only when ocean needs to be replaced with actual data)
549 _freshTiles.push_back(next);
553 _completedTiles[ next._dir ] = now + UpdateInterval::SuccessfulAttempt;
558 if (_consecutive_errors >= 5)
570 #ifdef HAVE_SVN_CLIENT_H
571 // Configure our subversion session
572 int SGTerraSync::SvnThread::svnClientSetup(void)
574 // Are we already prepared?
575 if (_svn_pool) return EXIT_SUCCESS;
576 // No, so initialize svn internals generally
579 // there is a segfault when providing an error stream.
580 // Apparently, calling setvbuf with a nul buffer is
581 // not supported under msvc 7.1 ( code inside svn_cmdline_init )
582 if (svn_cmdline_init("terrasync", 0) != EXIT_SUCCESS)
585 // revert locale setting
586 setlocale(LC_ALL,"C");
588 /* svn_cmdline_init configures the locale. Setup environment to ensure the
589 * default "C" locale remains active, since fgfs isn't locale aware - especially
590 * requires "." as decimal point in strings containing floating point varibales. */
591 setenv("LC_ALL", "C", 1);
593 if (svn_cmdline_init("terrasync", stderr) != EXIT_SUCCESS)
598 apr_pool_create(&pool, NULL);
599 svn_error_t *err = NULL;
600 SVN_VERSION_DEFINE(_svn_version);
601 err = svn_ver_check_list(&_svn_version, mysvn_checklist);
603 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
604 err = svn_ra_initialize(pool);
606 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
607 char *config_dir = NULL;
608 err = svn_config_ensure(config_dir, pool);
610 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
611 err = svn_client_create_context(&_svn_ctx, pool);
613 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
614 err = svn_config_get_config(&(_svn_ctx->config),
617 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
619 cfg = ( svn_config_t*) apr_hash_get(
621 SVN_CONFIG_CATEGORY_CONFIG,
622 APR_HASH_KEY_STRING);
624 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
626 svn_auth_baton_t *ab=NULL;
628 #if (SVN_VER_MINOR >= 6)
629 err = svn_cmdline_create_auth_baton (&ab,
630 TRUE, NULL, NULL, config_dir, TRUE, FALSE, cfg,
631 _svn_ctx->cancel_func, _svn_ctx->cancel_baton, pool);
633 err = svn_cmdline_setup_auth_baton(&ab,
634 TRUE, NULL, NULL, config_dir, TRUE, cfg,
635 _svn_ctx->cancel_func, _svn_ctx->cancel_baton, pool);
639 return svn_cmdline_handle_exit_error(err, pool, "fgfs: ");
641 _svn_ctx->auth_baton = ab;
642 #if (SVN_VER_MINOR >= 5)
643 _svn_ctx->conflict_func = NULL;
644 _svn_ctx->conflict_baton = NULL;
647 // Now our magic revisions
648 _svn_rev = (svn_opt_revision_t*) apr_palloc(pool,
649 sizeof(svn_opt_revision_t));
652 _svn_rev_peg = (svn_opt_revision_t*) apr_palloc(pool,
653 sizeof(svn_opt_revision_t));
656 _svn_rev->kind = svn_opt_revision_head;
657 _svn_rev_peg->kind = svn_opt_revision_unspecified;
658 // Success if we got this far
664 ///////////////////////////////////////////////////////////////////////////////
665 // SGTerraSync ////////////////////////////////////////////////////////////////
666 ///////////////////////////////////////////////////////////////////////////////
667 SGTerraSync::SGTerraSync(SGPropertyNode_ptr root) :
671 _terraRoot(root->getNode("/sim/terrasync",true)),
674 _svnThread = new SvnThread();
677 SGTerraSync::~SGTerraSync()
679 _tiedProperties.Untie();
684 void SGTerraSync::init()
686 _refresh_display = _terraRoot->getNode("refresh-display",true);
687 _terraRoot->getNode("built-in-svn-available",true)->setBoolValue(svn_built_in_available);
691 void SGTerraSync::reinit()
693 // do not reinit when enabled and we're already up and running
694 if ((_terraRoot->getBoolValue("enabled",false))&&
695 (_svnThread->_active && _svnThread->_running))
700 if (_terraRoot->getBoolValue("enabled",false))
702 _svnThread->setSvnServer(_terraRoot->getStringValue("svn-server",""));
703 _svnThread->setRsyncServer(_terraRoot->getStringValue("rsync-server",""));
704 _svnThread->setLocalDir(_terraRoot->getStringValue("scenery-dir",""));
706 #ifdef HAVE_SVN_CLIENT_H
707 _svnThread->setUseBuiltin(_terraRoot->getBoolValue("use-built-in-svn",true));
709 _terraRoot->getNode("use-built-in-svn",true)->setBoolValue(false);
711 _svnThread->setUseSvn(_terraRoot->getBoolValue("use-svn",true));
712 _svnThread->setExtSvnUtility(_terraRoot->getStringValue("ext-svn-utility","svn"));
714 if (_svnThread->start())
716 syncAirportsModels();
717 if (last_lat != NOWHERE && last_lon != NOWHERE)
719 // reschedule most recent position
724 schedulePosition(lat, lon);
729 _stalled_node->setBoolValue(_svnThread->_stalled);
732 void SGTerraSync::bind()
734 _tiedProperties.Tie( _terraRoot->getNode("busy", true), (bool*) &_svnThread->_busy );
735 _tiedProperties.Tie( _terraRoot->getNode("active", true), (bool*) &_svnThread->_active );
736 _tiedProperties.Tie( _terraRoot->getNode("update-count", true), (int*) &_svnThread->_success_count );
737 _tiedProperties.Tie( _terraRoot->getNode("error-count", true), (int*) &_svnThread->_fail_count );
738 _tiedProperties.Tie( _terraRoot->getNode("tile-count", true), (int*) &_svnThread->_updated_tile_count );
739 _terraRoot->getNode("busy", true)->setAttribute(SGPropertyNode::WRITE,false);
740 _terraRoot->getNode("active", true)->setAttribute(SGPropertyNode::WRITE,false);
741 _terraRoot->getNode("update-count", true)->setAttribute(SGPropertyNode::WRITE,false);
742 _terraRoot->getNode("error-count", true)->setAttribute(SGPropertyNode::WRITE,false);
743 _terraRoot->getNode("tile-count", true)->setAttribute(SGPropertyNode::WRITE,false);
744 _terraRoot->getNode("use-built-in-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
745 _terraRoot->getNode("use-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
746 // stalled is used as a signal handler (to connect listeners triggering GUI pop-ups)
747 _stalled_node = _terraRoot->getNode("stalled", true);
748 _stalled_node->setBoolValue(_svnThread->_stalled);
749 _stalled_node->setAttribute(SGPropertyNode::PRESERVE,true);
752 void SGTerraSync::unbind()
755 _tiedProperties.Untie();
758 void SGTerraSync::update(double)
760 static SGBucket bucket;
761 if (_svnThread->isDirty())
763 if (!_svnThread->_active)
765 if (_svnThread->_stalled)
767 SG_LOG(SG_TERRAIN,SG_ALERT,
768 "Automatic scenery download/synchronization stalled. Too many errors.");
772 // not really an alert - just always show this message
773 SG_LOG(SG_TERRAIN,SG_ALERT,
774 "Automatic scenery download/synchronization has stopped.");
776 _stalled_node->setBoolValue(_svnThread->_stalled);
779 if (!_refresh_display->getBoolValue())
782 while (_svnThread->hasNewTiles())
784 WaitingTile next = _svnThread->getNewTile();
785 if (next._refreshScenery)
787 refreshScenery(_svnThread->getLocalDir(),next._dir);
793 void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
795 // find tiles to be refreshed
798 path.append(relativeDir);
801 simgear::Dir dir(path);
802 //TODO need to be smarter here. only update tiles which actually
803 // changed recently. May also be possible to use information from the
804 // built-in SVN client directly (instead of checking directory contents).
805 PathList tileList = dir.children(simgear::Dir::TYPE_FILE, ".stg");
806 for (unsigned int i=0; i<tileList.size(); ++i)
808 // reload scenery tile
809 long index = atoi(tileList[i].file().c_str());
810 _tile_cache->refresh_tile(index);
816 bool SGTerraSync::isIdle() {return _svnThread->isIdle();}
818 void SGTerraSync::setTileCache(TileCache* tile_cache)
820 _tile_cache = tile_cache;
823 void SGTerraSync::syncAirportsModels()
825 static const char* bounds = "MZAJKL"; // airport sync order: K-L, A-J, M-Z
826 // note "request" method uses LIFO order, i.e. processes most recent request first
827 for( unsigned i = 0; i < strlen(bounds)/2; i++ )
829 for ( char synced_other = bounds[2*i]; synced_other <= bounds[2*i+1]; synced_other++ )
832 dir << "Airports/" << synced_other;
833 WaitingTile w(dir.str(),false);
834 _svnThread->request( w );
837 WaitingTile w("Models",false);
838 _svnThread->request( w );
842 void SGTerraSync::syncArea( int lat, int lon )
844 if ( lat < -90 || lat > 90 || lon < -180 || lon > 180 )
847 int baselat, baselon;
850 int base = (int)(lat / 10);
851 if ( lat == base * 10 ) {
854 baselat = (base - 1) * 10;
858 baselat = (int)(lat / 10) * 10;
862 int base = (int)(lon / 10);
863 if ( lon == base * 10 ) {
866 baselon = (base - 1) * 10;
870 baselon = (int)(lon / 10) * 10;
874 const char* terrainobjects[3] = { "Terrain", "Objects", 0 };
876 for (const char** tree = &terrainobjects[0]; *tree; tree++)
879 dir << *tree << "/" << setfill('0')
880 << EW << setw(3) << abs(baselon) << NS << setw(2) << abs(baselat) << "/"
881 << EW << setw(3) << abs(lon) << NS << setw(2) << abs(lat);
882 WaitingTile w(dir.str(),refresh);
883 _svnThread->request( w );
889 void SGTerraSync::syncAreas( int lat, int lon, int lat_dir, int lon_dir )
891 if ( lat_dir == 0 && lon_dir == 0 ) {
892 // do surrounding 8 1x1 degree areas.
893 for ( int i = lat - 1; i <= lat + 1; ++i ) {
894 for ( int j = lon - 1; j <= lon + 1; ++j ) {
895 if ( i != lat || j != lon ) {
901 if ( lat_dir != 0 ) {
902 syncArea( lat + lat_dir, lon - 1 );
903 syncArea( lat + lat_dir, lon + 1 );
904 syncArea( lat + lat_dir, lon );
906 if ( lon_dir != 0 ) {
907 syncArea( lat - 1, lon + lon_dir );
908 syncArea( lat + 1, lon + lon_dir );
909 syncArea( lat, lon + lon_dir );
913 // do current 1x1 degree area first
914 syncArea( lat, lon );
918 bool SGTerraSync::schedulePosition(int lat, int lon)
922 // Ignore messages where the location does not change
923 if ( lat != last_lat || lon != last_lon )
925 if (_svnThread->_running)
927 SG_LOG(SG_TERRAIN,SG_DEBUG, "Requesting scenery update for position " <<
931 if ( last_lat != NOWHERE && last_lon != NOWHERE )
933 int dist = lat - last_lat;
936 lat_dir = dist / abs(dist);
942 dist = lon - last_lon;
945 lon_dir = dist / abs(dist);
952 SG_LOG(SG_TERRAIN,SG_DEBUG, "Scenery update for " <<
953 "lat = " << lat << ", lon = " << lon <<
954 ", lat_dir = " << lat_dir << ", " <<
955 "lon_dir = " << lon_dir);
957 syncAreas( lat, lon, lat_dir, lon_dir );